1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-06-12 22:07:39 +02:00
This commit is contained in:
Salvador Díaz Fau
2017-11-25 19:04:15 +01:00
parent b54a2861c4
commit f5f1a767c9
47 changed files with 1114 additions and 851 deletions

View File

@ -41,19 +41,13 @@ program JSExecutingFunctions;
uses
{$IFDEF DELPHI16_UP}
WinApi.Windows,
Vcl.Forms,
System.SysUtils,
WinApi.Windows,
{$ELSE}
Forms,
Windows,
SysUtils,
{$ENDIF }
uCEFApplication,
uCEFInterfaces,
uCEFv8Value,
uCEFConstants,
uCEFTypes,
uJSExecutingFunctions in 'uJSExecutingFunctions.pas' {JSExecutingFunctionsFrm},
uMyV8Handler in 'uMyV8Handler.pas';
@ -62,32 +56,6 @@ uses
// CEF3 needs to set the LARGEADDRESSAWARE flag which allows 32-bit processes to use up to 3GB of RAM.
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
var
TempHandler : ICefv8Handler;
begin
TempHandler := TMyV8Handler.Create;
context.Global.SetValueByKey('register', TCefv8ValueRef.NewFunction('register', TempHandler), V8_PROPERTY_ATTRIBUTE_NONE);
end;
procedure GlobalCEFApp_OnProcessMessageReceived(const browser : ICefBrowser;
sourceProcess : TCefProcessId;
const message : ICefProcessMessage;
var aHandled : boolean);
var
arguments: TCefv8ValueArray;
begin
if (message.name = EXECFUNCTION_MSGNAME) then
begin
if (GlobalCallbackFunc <> nil) then
GlobalCallbackFunc.ExecuteFunctionWithContext(GlobalCallbackContext, nil, arguments);
aHandled := True;
end
else
aHandled := False;
end;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnContextCreated := GlobalCEFApp_OnContextCreated;

View File

@ -100,6 +100,7 @@
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<AppEnableHighDPI>true</AppEnableHighDPI>
<BT_BuildType>Debug</BT_BuildType>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">

View File

@ -49,7 +49,8 @@ uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
{$ENDIF}
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFApplication, uCEFTypes, uCEFConstants;
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFApplication, uCEFTypes,
uCEFConstants, uCEFv8Value;
const
JSDEMO_CONTEXTMENU_EXECFUNCTION = MENU_ID_USER_FIRST + 1;
@ -88,6 +89,12 @@ var
GlobalCallbackFunc : ICefv8Value = nil;
GlobalCallbackContext : ICefv8Context = nil;
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
procedure GlobalCEFApp_OnProcessMessageReceived(const browser : ICefBrowser;
sourceProcess : TCefProcessId;
const aMessage : ICefProcessMessage;
var aHandled : boolean);
implementation
{$R *.dfm}
@ -106,7 +113,36 @@ implementation
// be executed.
uses
uCEFProcessMessage;
uCEFProcessMessage, uMyV8Handler;
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
var
TempHandler : ICefv8Handler;
TempFunction : ICefv8Value;
begin
TempHandler := TMyV8Handler.Create;
TempFunction := TCefv8ValueRef.NewFunction('register', TempHandler);
context.Global.SetValueByKey('register', TempFunction, V8_PROPERTY_ATTRIBUTE_NONE);
end;
procedure GlobalCEFApp_OnProcessMessageReceived(const browser : ICefBrowser;
sourceProcess : TCefProcessId;
const aMessage : ICefProcessMessage;
var aHandled : boolean);
var
arguments: TCefv8ValueArray;
begin
if (aMessage.name = EXECFUNCTION_MSGNAME) then
begin
if (GlobalCallbackFunc <> nil) then
GlobalCallbackFunc.ExecuteFunctionWithContext(GlobalCallbackContext, nil, arguments);
aHandled := True;
end
else
aHandled := False;
end;
procedure TJSExecutingFunctionsFrm.GoBtnClick(Sender: TObject);
begin