73 lines
2.2 KiB
C++
73 lines
2.2 KiB
C++
//---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#include "CommonV8Handler.h"
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
#pragma comment(lib, "CEF4DelphiVCLRTL")
|
|
//---------------------------------------------------------------------------
|
|
|
|
TV8Handler* u_pV8handler = NULL;
|
|
|
|
bool __fastcall TV8Handler::Execute(const ustring name, const _di_ICefv8Value obj,
|
|
const TCefv8ValueArray arguments, _di_ICefv8Value &retval, ustring &exception)
|
|
{
|
|
if( arguments.Length>0 ){
|
|
_di_ICefProcessMessage msg = TCefProcessMessageRef::New(name);
|
|
for( int i=0; i<arguments.Length; i++ ){
|
|
// if( arguments[i]->IsString() )
|
|
if( arguments[i]->IsInt() )
|
|
msg->ArgumentList->SetString(i, IntToStr(arguments[i]->GetIntValue()) );
|
|
else if( arguments[i]->IsDouble() )
|
|
msg->ArgumentList->SetString(i, FloatToStr(arguments[i]->GetDoubleValue()) );
|
|
else
|
|
msg->ArgumentList->SetString(i, arguments[i]->GetStringValue() );
|
|
}
|
|
|
|
TCefv8ContextRef::Current()->Browser->MainFrame->SendProcessMessage(PID_BROWSER, msg);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void __fastcall TWebKitInitializeEvent::Invoke()
|
|
{
|
|
String app_code =
|
|
"var cefApp;"
|
|
"if(!cefApp)"
|
|
"cefApp={};"
|
|
"(function(){"
|
|
"cefApp.ReturnJQValue = function(){"
|
|
"native function ReturnJQValue();"
|
|
"return ReturnJQValue.apply(null,arguments);"
|
|
"};"
|
|
"cefApp.GetUserInfo=function(){"
|
|
"native function GetUserInfo();"
|
|
"return GetUserInfo.apply(null,arguments);"
|
|
"};"
|
|
"cefApp.GetRegInfo=function(){"
|
|
"native function GetRegInfo();"
|
|
"return GetRegInfo.apply(null,arguments);"
|
|
"};"
|
|
"cefApp.GetPageCode=function(){"
|
|
"native function GetPageCode();"
|
|
"return GetPageCode.apply(null,arguments);"
|
|
"};"
|
|
"cefApp.OnJSMessage = function(){"
|
|
"native function OnJSMessage();"
|
|
"return OnJSMessage.apply(null,arguments);"
|
|
"};"
|
|
"})();";
|
|
|
|
if( !u_pV8handler )
|
|
u_pV8handler = new TV8Handler;
|
|
|
|
CefRegisterExtension("v8/cefApp", app_code, *u_pV8handler);
|
|
}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|