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

@ -60,16 +60,6 @@ begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnProcessMessageReceived := JSEvalFrm.RenderProcessHandler_OnProcessMessageReceivedEvent;
// In case you want to use custom directories for the CEF3 binaries, cache, cookies and user data.
{
GlobalCEFApp.FrameworkDirPath := 'cef';
GlobalCEFApp.ResourcesDirPath := 'cef';
GlobalCEFApp.LocalesDirPath := 'cef\locales';
GlobalCEFApp.cache := 'cef\cache';
GlobalCEFApp.cookies := 'cef\cookies';
GlobalCEFApp.UserDataPath := 'cef\User Data';
}
if GlobalCEFApp.StartMainProcess then
begin
Application.Initialize;

View File

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

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

View File

@ -41,21 +41,13 @@ program JSExtension;
uses
{$IFDEF DELPHI16_UP}
WinApi.Windows,
Vcl.Forms,
System.SysUtils,
WinApi.Windows,
{$ELSE}
Forms,
Windows,
SysUtils,
{$ENDIF }
uCEFApplication,
uCEFMiscFunctions,
uCEFConstants,
uCEFRenderProcessHandler,
uCEFInterfaces,
uCEFv8Handler,
uCEFTypes,
uJSExtension in 'uJSExtension.pas' {JSExtensionFrm},
uTestExtensionHandler in 'uTestExtensionHandler.pas',
uSimpleTextViewer in 'uSimpleTextViewer.pas' {SimpleTextViewerFrm};
@ -65,34 +57,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_OnWebKitInitialized;
var
TempExtensionCode : string;
TempHandler : ICefv8Handler;
begin
// This is a JS extension example with 2 functions and several parameters.
// Please, read the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempExtensionCode := 'var myextension;' +
'if (!myextension)' +
' myextension = {};' +
'(function() {' +
' myextension.mouseover = function(a) {' +
' native function mouseover();' +
' mouseover(a);' +
' };' +
' myextension.sendresulttobrowser = function(b,c) {' +
' native function sendresulttobrowser();' +
' sendresulttobrowser(b,c);' +
' };' +
'})();';
TempHandler := TTestExtensionHandler.Create;
CefRegisterExtension('myextension', TempExtensionCode, TempHandler);
end;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitialized;

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

@ -97,12 +97,14 @@ type
var
JSExtensionFrm: TJSExtensionFrm;
procedure GlobalCEFApp_OnWebKitInitialized;
implementation
{$R *.dfm}
uses
uSimpleTextViewer, uCEFMiscFunctions;
uSimpleTextViewer, uCEFMiscFunctions, uTestExtensionHandler;
// The CEF3 document describing extensions is here :
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
@ -122,6 +124,34 @@ uses
// Even if you create several TChromium objects you should have no problem because each of them will have its own
// TChromium.OnProcessMessageReceived event to receive the messages from the extension.
procedure GlobalCEFApp_OnWebKitInitialized;
var
TempExtensionCode : string;
TempHandler : ICefv8Handler;
begin
// This is a JS extension example with 2 functions and several parameters.
// Please, read the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempExtensionCode := 'var myextension;' +
'if (!myextension)' +
' myextension = {};' +
'(function() {' +
' myextension.mouseover = function(a) {' +
' native function mouseover();' +
' mouseover(a);' +
' };' +
' myextension.sendresulttobrowser = function(b,c) {' +
' native function sendresulttobrowser();' +
' sendresulttobrowser(b,c);' +
' };' +
'})();';
TempHandler := TTestExtensionHandler.Create;
CefRegisterExtension('myextension', TempExtensionCode, TempHandler);
end;
procedure TJSExtensionFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -41,17 +41,13 @@ program JSExtensionWithFunction;
uses
{$IFDEF DELPHI16_UP}
WinApi.Windows,
Vcl.Forms,
System.SysUtils,
WinApi.Windows,
{$ELSE}
Forms,
Windows,
SysUtils,
{$ENDIF }
uCEFApplication,
uCEFMiscFunctions,
uCEFInterfaces,
uJSExtensionWithFunction in 'uJSExtensionWithFunction.pas' {JSExtensionWithFunctionFrm},
uMyV8Handler in 'uMyV8Handler.pas';
@ -60,29 +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_OnWebKitInitializedEvent;
var
TempExtensionCode : string;
TempHandler : ICefv8Handler;
begin
// This is the JS extension example with a function in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempExtensionCode := 'var test;' +
'if (!test)' +
' test = {};' +
'(function() {' +
' test.myfunc = function() {' +
' native function myfunc();' +
' return myfunc();' +
' };' +
'})();';
TempHandler := TMyV8Handler.Create;
CefRegisterExtension('v8/test', TempExtensionCode, TempHandler);
end;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;

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

@ -74,16 +74,44 @@ type
var
JSExtensionWithFunctionFrm: TJSExtensionWithFunctionFrm;
procedure GlobalCEFApp_OnWebKitInitializedEvent;
implementation
{$R *.dfm}
uses
uCEFMiscFunctions, uMyV8Handler;
// The CEF3 document describing JavaScript integration is here :
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
// The HTML file in this demo has a button that shows the contents of 'test.myfunc()'
// which was registered in the GlobalCEFApp.OnWebKitInitialized event.
procedure GlobalCEFApp_OnWebKitInitializedEvent;
var
TempExtensionCode : string;
TempHandler : ICefv8Handler;
begin
// This is the JS extension example with a function in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempExtensionCode := 'var test;' +
'if (!test)' +
' test = {};' +
'(function() {' +
' test.myfunc = function() {' +
' native function myfunc();' +
' return myfunc();' +
' };' +
'})();';
TempHandler := TMyV8Handler.Create;
CefRegisterExtension('v8/test', TempExtensionCode, TempHandler);
end;
procedure TJSExtensionWithFunctionFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -41,17 +41,13 @@ program JSExtensionWithObjectParameter;
uses
{$IFDEF DELPHI16_UP}
WinApi.Windows,
Vcl.Forms,
System.SysUtils,
WinApi.Windows,
{$ELSE}
Forms,
Windows,
SysUtils,
{$ENDIF }
uCEFApplication,
uCEFMiscFunctions,
uCEFInterfaces,
uJSExtensionWithObjectParameter in 'uJSExtensionWithObjectParameter.pas' {JSExtensionWithObjectParameterFrm},
uMyV8Handler in 'uMyV8Handler.pas';
@ -60,33 +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_OnWebKitInitializedEvent;
var
TempExtensionCode : string;
TempHandler : ICefv8Handler;
begin
// This is the JS extension example with a function in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempExtensionCode := 'var test;' +
'if (!test)' +
' test = {};' +
'(function() {' +
' test.__defineGetter__(' + quotedstr('myparam') + ', function() {' +
' native function GetMyParam();' +
' return GetMyParam();' +
' });' +
' test.__defineSetter__(' + quotedstr('myparam') + ', function(b) {' +
' native function SetMyParam();' +
' if(b) SetMyParam(b);' +
' });' +
'})();';
TempHandler := TMyV8Handler.Create;
CefRegisterExtension('v8/test', TempExtensionCode, TempHandler);
end;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;
@ -98,7 +67,7 @@ begin
Application.MainFormOnTaskbar := True;
{$ENDIF}
Application.CreateForm(TJSExtensionWithObjectParameterFrm, JSExtensionWithObjectParameterFrm);
Application.Run;
Application.Run;
end;
GlobalCEFApp.Free;

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

@ -74,10 +74,15 @@ type
var
JSExtensionWithObjectParameterFrm: TJSExtensionWithObjectParameterFrm;
procedure GlobalCEFApp_OnWebKitInitializedEvent;
implementation
{$R *.dfm}
uses
uCEFMiscFunctions, uMyV8Handler;
// The CEF3 document describing JavaScript integration is here :
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
@ -87,6 +92,33 @@ implementation
// This demo is based in the code comments for the cef_register_extension function in the file
// /include/capi/cef_v8_capi.h
procedure GlobalCEFApp_OnWebKitInitializedEvent;
var
TempExtensionCode : string;
TempHandler : ICefv8Handler;
begin
// This is the JS extension example with a function in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempExtensionCode := 'var test;' +
'if (!test)' +
' test = {};' +
'(function() {' +
' test.__defineGetter__(' + quotedstr('myparam') + ', function() {' +
' native function GetMyParam();' +
' return GetMyParam();' +
' });' +
' test.__defineSetter__(' + quotedstr('myparam') + ', function(b) {' +
' native function SetMyParam();' +
' if(b) SetMyParam(b);' +
' });' +
'})();';
TempHandler := TMyV8Handler.Create;
CefRegisterExtension('v8/test', TempExtensionCode, TempHandler);
end;
procedure TJSExtensionWithObjectParameterFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -41,17 +41,13 @@ program JSSimpleExtension;
uses
{$IFDEF DELPHI16_UP}
WinApi.Windows,
Vcl.Forms,
System.SysUtils,
WinApi.Windows,
{$ELSE}
Forms,
Windows,
SysUtils,
{$ENDIF }
uCEFApplication,
uCEFMiscFunctions,
uCEFTypes,
uJSSimpleExtension in 'uJSSimpleExtension.pas' {JSSimpleExtensionFrm};
{$R *.res}
@ -59,23 +55,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_OnWebKitInitializedEvent;
var
TempExtensionCode : string;
begin
// This is the first JS extension example in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempExtensionCode := 'var test;' +
'if (!test)' +
' test = {};' +
'(function() {' +
' test.myval = ' + quotedstr('My Value!') + ';' +
'})();';
CefRegisterExtension('v8/test', TempExtensionCode, nil);
end;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;

View File

@ -45,6 +45,17 @@
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug with optimization' or '$(Cfg_3)'!=''">
<Cfg_3>true</Cfg_3>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_3)'=='true') or '$(Cfg_3_Win32)'!=''">
<Cfg_3_Win32>true</Cfg_3_Win32>
<CfgParent>Cfg_3</CfgParent>
<Cfg_3>true</Cfg_3>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<VerInfo_Locale>3082</VerInfo_Locale>
<Icon_MainIcon>$(BDS)\bin\delphi_PROJECTICON.ico</Icon_MainIcon>
@ -100,6 +111,18 @@
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<AppEnableHighDPI>true</AppEnableHighDPI>
<BT_BuildType>Debug</BT_BuildType>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_3_Win32)'!=''">
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
<DCC_DebugDCUs>true</DCC_DebugDCUs>
<DCC_DebugInfoInExe>true</DCC_DebugInfoInExe>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
@ -108,17 +131,21 @@
<DCCReference Include="uJSSimpleExtension.pas">
<Form>JSSimpleExtensionFrm</Form>
</DCCReference>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Debug">
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Debug with optimization">
<Key>Cfg_3</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>

View File

@ -74,16 +74,38 @@ type
var
JSSimpleExtensionFrm: TJSSimpleExtensionFrm;
procedure GlobalCEFApp_OnWebKitInitializedEvent;
implementation
{$R *.dfm}
uses
uCEFMiscFunctions;
// The CEF3 document describing JavaScript integration is here :
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
// The HTML file in this demo has a button that shows the contents of 'test.myval'
// which was registered in the GlobalCEFApp.OnWebKitInitialized event.
procedure GlobalCEFApp_OnWebKitInitializedEvent;
var
TempExtensionCode : string;
begin
// This is the first JS extension example in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempExtensionCode := 'var test;' +
'if (!test)' +
' test = {};' +
'(function() {' +
' test.myval = ' + quotedstr('My Value!') + ';' +
'})();';
CefRegisterExtension('v8/test', TempExtensionCode, nil);
end;
procedure TJSSimpleExtensionFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -41,18 +41,13 @@ program JSSimpleWindowBinding;
uses
{$IFDEF DELPHI16_UP}
WinApi.Windows,
Vcl.Forms,
System.SysUtils,
WinApi.Windows,
{$ELSE}
Forms,
Windows,
SysUtils,
{$ENDIF }
uCEFApplication,
uCEFInterfaces,
uCEFv8Value,
uCEFConstants,
uJSSimpleWindowBinding in 'uJSSimpleWindowBinding.pas' {JSSimpleWindowBindingFrm};
{$R *.res}
@ -60,14 +55,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);
begin
// This is the first JS Window Binding example in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
context.Global.SetValueByKey('myval', TCefv8ValueRef.NewString('My Value!'), V8_PROPERTY_ATTRIBUTE_NONE);;
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;
type
TJSSimpleWindowBindingFrm = class(TForm)
@ -74,6 +75,8 @@ type
var
JSSimpleWindowBindingFrm: TJSSimpleWindowBindingFrm;
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
implementation
{$R *.dfm}
@ -84,6 +87,18 @@ implementation
// The HTML file in this demo has a button that shows the contents of 'window.myval'
// which was set in the GlobalCEFApp.OnContextCreated event.
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
var
TempValue : ICEFv8Value;
begin
// This is the first JS Window Binding example in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempValue := TCefv8ValueRef.NewString('My Value!');
context.Global.SetValueByKey('myval', TempValue, V8_PROPERTY_ATTRIBUTE_NONE);
end;
procedure TJSSimpleWindowBindingFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -41,18 +41,13 @@ program JSWindowBindingWithFunction;
uses
{$IFDEF DELPHI16_UP}
WinApi.Windows,
Vcl.Forms,
System.SysUtils,
WinApi.Windows,
{$ELSE}
Forms,
Windows,
SysUtils,
{$ENDIF }
uCEFApplication,
uCEFInterfaces,
uCEFv8Value,
uCEFConstants,
uJSWindowBindingWithFunction in 'uJSWindowBindingWithFunction.pas' {JSWindowBindingWithFunctionFrm},
uMyV8Handler in 'uMyV8Handler.pas';
@ -61,18 +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
// This is the JS Window Binding example with a function in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempHandler := TMyV8Handler.Create;
context.Global.SetValueByKey('myfunc', TCefv8ValueRef.NewFunction('myfunc', TempHandler), V8_PROPERTY_ATTRIBUTE_NONE);
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

@ -74,16 +74,35 @@ type
var
JSWindowBindingWithFunctionFrm: TJSWindowBindingWithFunctionFrm;
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
implementation
{$R *.dfm}
uses
uCEFv8Value, uMyV8Handler;
// The CEF3 document describing JavaScript integration is here :
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
// The HTML file in this demo has a button that shows the result of 'window.myfunc()'
// which was set in the GlobalCEFApp.OnContextCreated event.
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
var
TempHandler : ICefv8Handler;
TempFunction : ICefv8Value;
begin
// This is the JS Window Binding example with a function in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempHandler := TMyV8Handler.Create;
TempFunction := TCefv8ValueRef.NewFunction('myfunc', TempHandler);
context.Global.SetValueByKey('myfunc', TempFunction, V8_PROPERTY_ATTRIBUTE_NONE);
end;
procedure TJSWindowBindingWithFunctionFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -41,18 +41,13 @@ program JSWindowBindingWithObject;
uses
{$IFDEF DELPHI16_UP}
WinApi.Windows,
Vcl.Forms,
System.SysUtils,
WinApi.Windows,
{$ELSE}
Forms,
Windows,
SysUtils,
{$ENDIF }
uCEFApplication,
uCEFInterfaces,
uCEFv8Value,
uCEFConstants,
uJSWindowBindingWithObject in 'uJSWindowBindingWithObject.pas' {JSWindowBindingWithObjectFrm},
uMyV8Accessor in 'uMyV8Accessor.pas';
@ -61,21 +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
TempAccessor : ICefV8Accessor;
TempObject : ICefv8Value;
begin
// This is the first JS Window Binding example in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempAccessor := TMyV8Accessor.Create;
TempObject := TCefv8ValueRef.NewObject(TempAccessor, nil);
TempObject.SetValueByKey('myval', TCefv8ValueRef.NewString('My Value!'), V8_PROPERTY_ATTRIBUTE_NONE);
context.Global.SetValueByKey('myobj', TempObject, V8_PROPERTY_ATTRIBUTE_NONE);
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

@ -74,16 +74,36 @@ type
var
JSWindowBindingWithObjectFrm: TJSWindowBindingWithObjectFrm;
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
implementation
{$R *.dfm}
uses
uCEFv8Value, uMyV8Accessor;
// The CEF3 document describing JavaScript integration is here :
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
// The HTML file in this demo has a button that shows the contents of 'window.myobj.myval'
// which was set in the GlobalCEFApp.OnContextCreated event.
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
var
TempAccessor : ICefV8Accessor;
TempObject : ICefv8Value;
begin
// This is the first JS Window Binding example in the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempAccessor := TMyV8Accessor.Create;
TempObject := TCefv8ValueRef.NewObject(TempAccessor, nil);
TempObject.SetValueByKey('myval', TCefv8ValueRef.NewString('My Value!'), V8_PROPERTY_ATTRIBUTE_NONE);
context.Global.SetValueByKey('myobj', TempObject, V8_PROPERTY_ATTRIBUTE_NONE);
end;
procedure TJSWindowBindingWithObjectFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);