From f5f1a767c9573cab324f6a94f975017a6e724079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Sat, 25 Nov 2017 19:04:15 +0100 Subject: [PATCH] bug fix #68 --- demos/JavaScript/JSEval/JSEval.dpr | 10 - demos/JavaScript/JSEval/JSEval.dproj | 1 + .../JSExecutingFunctions.dpr | 34 +- .../JSExecutingFunctions.dproj | 1 + .../uJSExecutingFunctions.pas | 40 +- demos/JavaScript/JSExtension/JSExtension.dpr | 38 +- .../JavaScript/JSExtension/JSExtension.dproj | 1 + demos/JavaScript/JSExtension/uJSExtension.pas | 32 +- .../JSExtensionWithFunction.dpr | 29 +- .../JSExtensionWithFunction.dproj | 1 + .../uJSExtensionWithFunction.pas | 28 + .../JSExtensionWithObjectParameter.dpr | 35 +- .../JSExtensionWithObjectParameter.dproj | 1 + .../uJSExtensionWithObjectParameter.pas | 32 + .../JSSimpleExtension/JSSimpleExtension.dpr | 23 +- .../JSSimpleExtension/JSSimpleExtension.dproj | 33 +- .../JSSimpleExtension/uJSSimpleExtension.pas | 22 + .../JSSimpleWindowBinding.dpr | 15 +- .../JSSimpleWindowBinding.dproj | 1 + .../uJSSimpleWindowBinding.pas | 17 +- .../JSWindowBindingWithFunction.dpr | 19 +- .../JSWindowBindingWithFunction.dproj | 1 + .../uJSWindowBindingWithFunction.pas | 19 + .../JSWindowBindingWithObject.dpr | 22 +- .../JSWindowBindingWithObject.dproj | 1 + .../uJSWindowBindingWithObject.pas | 20 + demos/MiniBrowser/MiniBrowser.dproj | 2 +- source/CEF4Delphi.dpk | 15 +- source/CEF4Delphi.dproj | 39 +- source/CEF4Delphi_D7.dpk | 3 +- source/uCEFApp.pas | 248 ++++++++ source/uCEFApplication.pas | 566 ++++-------------- source/uCEFBaseRefCounted.pas | 8 +- source/uCEFBrowserProcessHandler.pas | 118 +++- source/uCEFDragHandler.pas | 2 +- source/uCEFFindHandler.pas | 2 +- source/uCEFInterfaces.pas | 26 +- source/uCEFMenuModelDelegate.pas | 2 +- source/uCEFNavigationEntryVisitor.pas | 2 +- source/uCEFPDFPrintCallback.pas | 2 +- source/uCEFRenderHandler.pas | 2 +- source/uCEFRenderProcessHandler.pas | 346 +++++++---- source/uCEFRequestContextHandler.pas | 2 +- source/uCEFResolveCallback.pas | 2 +- source/uCEFResourceBundleHandler.pas | 98 ++- source/uCEFResponseFilter.pas | 2 +- source/uCEFTypes.pas | 2 +- 47 files changed, 1114 insertions(+), 851 deletions(-) create mode 100644 source/uCEFApp.pas diff --git a/demos/JavaScript/JSEval/JSEval.dpr b/demos/JavaScript/JSEval/JSEval.dpr index bcb92f09..ba4d931f 100644 --- a/demos/JavaScript/JSEval/JSEval.dpr +++ b/demos/JavaScript/JSEval/JSEval.dpr @@ -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; diff --git a/demos/JavaScript/JSEval/JSEval.dproj b/demos/JavaScript/JSEval/JSEval.dproj index fc5f36cf..72245d4f 100644 --- a/demos/JavaScript/JSEval/JSEval.dproj +++ b/demos/JavaScript/JSEval/JSEval.dproj @@ -100,6 +100,7 @@ true true + Debug diff --git a/demos/JavaScript/JSExecutingFunctions/JSExecutingFunctions.dpr b/demos/JavaScript/JSExecutingFunctions/JSExecutingFunctions.dpr index 36a535ed..91bfcb3e 100644 --- a/demos/JavaScript/JSExecutingFunctions/JSExecutingFunctions.dpr +++ b/demos/JavaScript/JSExecutingFunctions/JSExecutingFunctions.dpr @@ -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; diff --git a/demos/JavaScript/JSExecutingFunctions/JSExecutingFunctions.dproj b/demos/JavaScript/JSExecutingFunctions/JSExecutingFunctions.dproj index 115c735e..c13a7e80 100644 --- a/demos/JavaScript/JSExecutingFunctions/JSExecutingFunctions.dproj +++ b/demos/JavaScript/JSExecutingFunctions/JSExecutingFunctions.dproj @@ -100,6 +100,7 @@ true true + Debug diff --git a/demos/JavaScript/JSExecutingFunctions/uJSExecutingFunctions.pas b/demos/JavaScript/JSExecutingFunctions/uJSExecutingFunctions.pas index deaadd67..30d8b8c0 100644 --- a/demos/JavaScript/JSExecutingFunctions/uJSExecutingFunctions.pas +++ b/demos/JavaScript/JSExecutingFunctions/uJSExecutingFunctions.pas @@ -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 diff --git a/demos/JavaScript/JSExtension/JSExtension.dpr b/demos/JavaScript/JSExtension/JSExtension.dpr index d02b1052..1deae700 100644 --- a/demos/JavaScript/JSExtension/JSExtension.dpr +++ b/demos/JavaScript/JSExtension/JSExtension.dpr @@ -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; diff --git a/demos/JavaScript/JSExtension/JSExtension.dproj b/demos/JavaScript/JSExtension/JSExtension.dproj index 97c3419f..5e3b7313 100644 --- a/demos/JavaScript/JSExtension/JSExtension.dproj +++ b/demos/JavaScript/JSExtension/JSExtension.dproj @@ -100,6 +100,7 @@ true true + Debug diff --git a/demos/JavaScript/JSExtension/uJSExtension.pas b/demos/JavaScript/JSExtension/uJSExtension.pas index 1b5305b1..7d9fb6b7 100644 --- a/demos/JavaScript/JSExtension/uJSExtension.pas +++ b/demos/JavaScript/JSExtension/uJSExtension.pas @@ -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); diff --git a/demos/JavaScript/JSExtensionWithFunction/JSExtensionWithFunction.dpr b/demos/JavaScript/JSExtensionWithFunction/JSExtensionWithFunction.dpr index a45a2287..be73a08d 100644 --- a/demos/JavaScript/JSExtensionWithFunction/JSExtensionWithFunction.dpr +++ b/demos/JavaScript/JSExtensionWithFunction/JSExtensionWithFunction.dpr @@ -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; diff --git a/demos/JavaScript/JSExtensionWithFunction/JSExtensionWithFunction.dproj b/demos/JavaScript/JSExtensionWithFunction/JSExtensionWithFunction.dproj index ec677e8f..8f5499f0 100644 --- a/demos/JavaScript/JSExtensionWithFunction/JSExtensionWithFunction.dproj +++ b/demos/JavaScript/JSExtensionWithFunction/JSExtensionWithFunction.dproj @@ -100,6 +100,7 @@ true true + Debug diff --git a/demos/JavaScript/JSExtensionWithFunction/uJSExtensionWithFunction.pas b/demos/JavaScript/JSExtensionWithFunction/uJSExtensionWithFunction.pas index 22057290..14ab5f48 100644 --- a/demos/JavaScript/JSExtensionWithFunction/uJSExtensionWithFunction.pas +++ b/demos/JavaScript/JSExtensionWithFunction/uJSExtensionWithFunction.pas @@ -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); diff --git a/demos/JavaScript/JSExtensionWithObjectParameter/JSExtensionWithObjectParameter.dpr b/demos/JavaScript/JSExtensionWithObjectParameter/JSExtensionWithObjectParameter.dpr index 12cb4b7c..73d38aa5 100644 --- a/demos/JavaScript/JSExtensionWithObjectParameter/JSExtensionWithObjectParameter.dpr +++ b/demos/JavaScript/JSExtensionWithObjectParameter/JSExtensionWithObjectParameter.dpr @@ -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; diff --git a/demos/JavaScript/JSExtensionWithObjectParameter/JSExtensionWithObjectParameter.dproj b/demos/JavaScript/JSExtensionWithObjectParameter/JSExtensionWithObjectParameter.dproj index 7b44635a..10de11bd 100644 --- a/demos/JavaScript/JSExtensionWithObjectParameter/JSExtensionWithObjectParameter.dproj +++ b/demos/JavaScript/JSExtensionWithObjectParameter/JSExtensionWithObjectParameter.dproj @@ -100,6 +100,7 @@ true true + Debug diff --git a/demos/JavaScript/JSExtensionWithObjectParameter/uJSExtensionWithObjectParameter.pas b/demos/JavaScript/JSExtensionWithObjectParameter/uJSExtensionWithObjectParameter.pas index 5bc82668..d64dbce4 100644 --- a/demos/JavaScript/JSExtensionWithObjectParameter/uJSExtensionWithObjectParameter.pas +++ b/demos/JavaScript/JSExtensionWithObjectParameter/uJSExtensionWithObjectParameter.pas @@ -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); diff --git a/demos/JavaScript/JSSimpleExtension/JSSimpleExtension.dpr b/demos/JavaScript/JSSimpleExtension/JSSimpleExtension.dpr index 3916f5e3..cc1fc4f9 100644 --- a/demos/JavaScript/JSSimpleExtension/JSSimpleExtension.dpr +++ b/demos/JavaScript/JSSimpleExtension/JSSimpleExtension.dpr @@ -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; diff --git a/demos/JavaScript/JSSimpleExtension/JSSimpleExtension.dproj b/demos/JavaScript/JSSimpleExtension/JSSimpleExtension.dproj index c1b839fc..e8655902 100644 --- a/demos/JavaScript/JSSimpleExtension/JSSimpleExtension.dproj +++ b/demos/JavaScript/JSSimpleExtension/JSSimpleExtension.dproj @@ -45,6 +45,17 @@ true true + + true + Base + true + + + true + Cfg_3 + true + true + 3082 $(BDS)\bin\delphi_PROJECTICON.ico @@ -100,6 +111,18 @@ true true + Debug + true + 1033 + CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName) + + + true + 1033 + CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName) + true + true + true @@ -108,17 +131,21 @@
JSSimpleExtensionFrm
+ + Base + Cfg_2 Base - - Base - Cfg_1 Base + + Cfg_3 + Base +
Delphi.Personality.12 diff --git a/demos/JavaScript/JSSimpleExtension/uJSSimpleExtension.pas b/demos/JavaScript/JSSimpleExtension/uJSSimpleExtension.pas index 96d691f3..77295a3b 100644 --- a/demos/JavaScript/JSSimpleExtension/uJSSimpleExtension.pas +++ b/demos/JavaScript/JSSimpleExtension/uJSSimpleExtension.pas @@ -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); diff --git a/demos/JavaScript/JSSimpleWindowBinding/JSSimpleWindowBinding.dpr b/demos/JavaScript/JSSimpleWindowBinding/JSSimpleWindowBinding.dpr index 54165fc5..9ab50839 100644 --- a/demos/JavaScript/JSSimpleWindowBinding/JSSimpleWindowBinding.dpr +++ b/demos/JavaScript/JSSimpleWindowBinding/JSSimpleWindowBinding.dpr @@ -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; diff --git a/demos/JavaScript/JSSimpleWindowBinding/JSSimpleWindowBinding.dproj b/demos/JavaScript/JSSimpleWindowBinding/JSSimpleWindowBinding.dproj index 3ddf529f..95c39865 100644 --- a/demos/JavaScript/JSSimpleWindowBinding/JSSimpleWindowBinding.dproj +++ b/demos/JavaScript/JSSimpleWindowBinding/JSSimpleWindowBinding.dproj @@ -100,6 +100,7 @@ true true + Debug diff --git a/demos/JavaScript/JSSimpleWindowBinding/uJSSimpleWindowBinding.pas b/demos/JavaScript/JSSimpleWindowBinding/uJSSimpleWindowBinding.pas index dd2ab3b2..5d62479d 100644 --- a/demos/JavaScript/JSSimpleWindowBinding/uJSSimpleWindowBinding.pas +++ b/demos/JavaScript/JSSimpleWindowBinding/uJSSimpleWindowBinding.pas @@ -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); diff --git a/demos/JavaScript/JSWindowBindingWithFunction/JSWindowBindingWithFunction.dpr b/demos/JavaScript/JSWindowBindingWithFunction/JSWindowBindingWithFunction.dpr index c94c5802..01e57531 100644 --- a/demos/JavaScript/JSWindowBindingWithFunction/JSWindowBindingWithFunction.dpr +++ b/demos/JavaScript/JSWindowBindingWithFunction/JSWindowBindingWithFunction.dpr @@ -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; diff --git a/demos/JavaScript/JSWindowBindingWithFunction/JSWindowBindingWithFunction.dproj b/demos/JavaScript/JSWindowBindingWithFunction/JSWindowBindingWithFunction.dproj index 18a2ce90..06a0a861 100644 --- a/demos/JavaScript/JSWindowBindingWithFunction/JSWindowBindingWithFunction.dproj +++ b/demos/JavaScript/JSWindowBindingWithFunction/JSWindowBindingWithFunction.dproj @@ -100,6 +100,7 @@ true true + Debug diff --git a/demos/JavaScript/JSWindowBindingWithFunction/uJSWindowBindingWithFunction.pas b/demos/JavaScript/JSWindowBindingWithFunction/uJSWindowBindingWithFunction.pas index 2a7bbb64..d9db1ddd 100644 --- a/demos/JavaScript/JSWindowBindingWithFunction/uJSWindowBindingWithFunction.pas +++ b/demos/JavaScript/JSWindowBindingWithFunction/uJSWindowBindingWithFunction.pas @@ -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); diff --git a/demos/JavaScript/JSWindowBindingWithObject/JSWindowBindingWithObject.dpr b/demos/JavaScript/JSWindowBindingWithObject/JSWindowBindingWithObject.dpr index 5216d001..2368bc77 100644 --- a/demos/JavaScript/JSWindowBindingWithObject/JSWindowBindingWithObject.dpr +++ b/demos/JavaScript/JSWindowBindingWithObject/JSWindowBindingWithObject.dpr @@ -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; diff --git a/demos/JavaScript/JSWindowBindingWithObject/JSWindowBindingWithObject.dproj b/demos/JavaScript/JSWindowBindingWithObject/JSWindowBindingWithObject.dproj index 4aa37aa7..0697c181 100644 --- a/demos/JavaScript/JSWindowBindingWithObject/JSWindowBindingWithObject.dproj +++ b/demos/JavaScript/JSWindowBindingWithObject/JSWindowBindingWithObject.dproj @@ -100,6 +100,7 @@ true true + Debug diff --git a/demos/JavaScript/JSWindowBindingWithObject/uJSWindowBindingWithObject.pas b/demos/JavaScript/JSWindowBindingWithObject/uJSWindowBindingWithObject.pas index b8d45ea3..862a4974 100644 --- a/demos/JavaScript/JSWindowBindingWithObject/uJSWindowBindingWithObject.pas +++ b/demos/JavaScript/JSWindowBindingWithObject/uJSWindowBindingWithObject.pas @@ -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); diff --git a/demos/MiniBrowser/MiniBrowser.dproj b/demos/MiniBrowser/MiniBrowser.dproj index d3fa03ca..2c9790c3 100644 --- a/demos/MiniBrowser/MiniBrowser.dproj +++ b/demos/MiniBrowser/MiniBrowser.dproj @@ -5,7 +5,7 @@ VCL MiniBrowser.dpr True - Debug + Release Win32 1 Application diff --git a/source/CEF4Delphi.dpk b/source/CEF4Delphi.dpk index 4ab30459..fd565fe8 100644 --- a/source/CEF4Delphi.dpk +++ b/source/CEF4Delphi.dpk @@ -9,23 +9,22 @@ package CEF4Delphi; {$EXTENDEDSYNTAX ON} {$IMPORTEDDATA ON} {$IOCHECKS ON} -{$LOCALSYMBOLS ON} +{$LOCALSYMBOLS OFF} {$LONGSTRINGS ON} {$OPENSTRINGS ON} -{$OPTIMIZATION OFF} +{$OPTIMIZATION ON} {$OVERFLOWCHECKS OFF} {$RANGECHECKS OFF} -{$REFERENCEINFO ON} +{$REFERENCEINFO OFF} {$SAFEDIVIDE OFF} -{$STACKFRAMES ON} +{$STACKFRAMES OFF} {$TYPEDADDRESS OFF} {$VARSTRINGCHECKS ON} {$WRITEABLECONST OFF} {$MINENUMSIZE 1} {$IMAGEBASE $400000} -{$DEFINE DEBUG} +{$DEFINE RELEASE} {$ENDIF IMPLICITBUILDING} -{$DESCRIPTION 'CEF4Delphi'} {$IMPLICITBUILD OFF} requires @@ -157,6 +156,8 @@ contains uCEFGetExtensionResourceCallback in 'uCEFGetExtensionResourceCallback.pas', uCEFExtension in 'uCEFExtension.pas', uCEFExtensionHandler in 'uCEFExtensionHandler.pas', - uBufferPanel in 'uBufferPanel.pas'; + uBufferPanel in 'uBufferPanel.pas', + uCEFApp in 'uCEFApp.pas'; end. + diff --git a/source/CEF4Delphi.dproj b/source/CEF4Delphi.dproj index a0947c3d..43de140c 100644 --- a/source/CEF4Delphi.dproj +++ b/source/CEF4Delphi.dproj @@ -39,6 +39,23 @@ Base true
+ + true + Cfg_2 + true + true + + + true + Base + true + + + true + Cfg_3 + true + true + All true @@ -90,6 +107,17 @@ 0 0 + + true + 1033 + + + true + true + 1033 + true + true + MainSource @@ -221,17 +249,22 @@ + + + Base + Cfg_2 Base - - Base - Cfg_1 Base + + Cfg_3 + Base + Delphi.Personality.12 diff --git a/source/CEF4Delphi_D7.dpk b/source/CEF4Delphi_D7.dpk index 04f53347..37a515de 100644 --- a/source/CEF4Delphi_D7.dpk +++ b/source/CEF4Delphi_D7.dpk @@ -154,6 +154,7 @@ contains uCEFGetExtensionResourceCallback in 'uCEFGetExtensionResourceCallback.pas', uCEFExtension in 'uCEFExtension.pas', uCEFExtensionHandler in 'uCEFExtensionHandler.pas', - uBufferPanel in 'uBufferPanel.pas'; + uBufferPanel in 'uBufferPanel.pas', + uCEFApp in 'uCEFApp.pas'; end. diff --git a/source/uCEFApp.pas b/source/uCEFApp.pas new file mode 100644 index 00000000..1cfc2a8c --- /dev/null +++ b/source/uCEFApp.pas @@ -0,0 +1,248 @@ +// ************************************************************************ +// ***************************** CEF4Delphi ******************************* +// ************************************************************************ +// +// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based +// browser in Delphi applications. +// +// The original license of DCEF3 still applies to CEF4Delphi. +// +// For more information about CEF4Delphi visit : +// https://www.briskbard.com/index.php?lang=en&pageid=cef +// +// Copyright © 2017 Salvador Díaz Fau. All rights reserved. +// +// ************************************************************************ +// ************ vvvv Original license and comments below vvvv ************* +// ************************************************************************ +(* + * Delphi Chromium Embedded 3 + * + * Usage allowed under the restrictions of the Lesser GNU General Public License + * or alternatively the restrictions of the Mozilla Public License 1.1 + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for + * the specific language governing rights and limitations under the License. + * + * Unit owner : Henri Gourvest + * Web site : http://www.progdigy.com + * Repository : http://code.google.com/p/delphichromiumembedded/ + * Group : http://groups.google.com/group/delphichromiumembedded + * + * Embarcadero Technologies, Inc is not permitted to use or redistribute + * this source code without explicit permission. + * + *) + +unit uCEFApp; + +{$IFNDEF CPUX64} + {$ALIGN ON} + {$MINENUMSIZE 4} +{$ENDIF} + +{$I cef.inc} + +interface + +uses + {$IFDEF DELPHI16_UP} + WinApi.Windows, System.Classes, System.UITypes, + {$ELSE} + Windows, Classes, + {$ENDIF} + uCEFTypes, uCEFInterfaces, uCEFBaseRefCounted, uCEFSchemeRegistrar, uCEFApplication; + +type + TCefAppOwn = class(TCefBaseRefCountedOwn, ICefApp) + protected + procedure OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); virtual; abstract; + procedure OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef); virtual; abstract; + procedure GetResourceBundleHandler(var aHandler : ICefResourceBundleHandler); virtual; abstract; + procedure GetBrowserProcessHandler(var aHandler : ICefBrowserProcessHandler); virtual; abstract; + procedure GetRenderProcessHandler(var aHandler : ICefRenderProcessHandler); virtual; abstract; + + public + constructor Create; virtual; + end; + + TCustomCefApp = class(TCefAppOwn) + protected + FCefApp : TCefApplication; + + procedure OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); override; + procedure OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef); override; + procedure GetResourceBundleHandler(var aHandler : ICefResourceBundleHandler); override; + procedure GetBrowserProcessHandler(var aHandler : ICefBrowserProcessHandler); override; + procedure GetRenderProcessHandler(var aHandler : ICefRenderProcessHandler); override; + + public + constructor Create(const aCefApp : TCefApplication); reintroduce; + destructor Destroy; override; + end; + + +implementation + +uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} + uCEFLibFunctions, uCEFMiscFunctions, uCEFCommandLine, uCEFConstants; + + +// TCefAppOwn + +procedure cef_app_on_before_command_line_processing(self: PCefApp; + const process_type: PCefString; + command_line: PCefCommandLine); stdcall; +var + TempObject : TObject; +begin + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefAppOwn) then + TCefAppOwn(TempObject).OnBeforeCommandLineProcessing(CefString(process_type), TCefCommandLineRef.UnWrap(command_line)); +end; + +procedure cef_app_on_register_custom_schemes(self: PCefApp; registrar: PCefSchemeRegistrar); stdcall; +var + TempWrapper : TCefSchemeRegistrarRef; + TempObject : TObject; +begin + TempWrapper := nil; + + try + try + TempWrapper := TCefSchemeRegistrarRef.Create(registrar); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefAppOwn) then + TCefAppOwn(TempObject).OnRegisterCustomSchemes(TempWrapper); + except + on e : exception do + if CustomExceptionHandler('cef_app_on_register_custom_schemes', e) then raise; + end; + finally + if (TempWrapper <> nil) then FreeAndNil(TempWrapper); + end; +end; + +function cef_app_get_resource_bundle_handler(self: PCefApp): PCefResourceBundleHandler; stdcall; +var + TempObject : TObject; + TempHandler : ICefResourceBundleHandler; +begin + Result := nil; + TempHandler := nil; + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefAppOwn) then + begin + TCefAppOwn(TempObject).GetResourceBundleHandler(TempHandler); + Result := CefGetData(TempHandler); + end; +end; + +function cef_app_get_browser_process_handler(self: PCefApp): PCefBrowserProcessHandler; stdcall; +var + TempObject : TObject; + TempHandler : ICefBrowserProcessHandler; +begin + Result := nil; + TempHandler := nil; + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefAppOwn) then + begin + TCefAppOwn(TempObject).GetBrowserProcessHandler(TempHandler); + Result := CefGetData(TempHandler); + end; +end; + +function cef_app_get_render_process_handler(self: PCefApp): PCefRenderProcessHandler; stdcall; +var + TempObject : TObject; + TempHandler : ICefRenderProcessHandler; +begin + Result := nil; + TempHandler := nil; + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefAppOwn) then + begin + TCefAppOwn(TempObject).GetRenderProcessHandler(TempHandler); + Result := CefGetData(TempHandler); + end; +end; + +constructor TCefAppOwn.Create; +begin + inherited CreateData(SizeOf(TCefApp)); + + with PCefApp(FData)^ do + begin + on_before_command_line_processing := cef_app_on_before_command_line_processing; + on_register_custom_schemes := cef_app_on_register_custom_schemes; + get_resource_bundle_handler := cef_app_get_resource_bundle_handler; + get_browser_process_handler := cef_app_get_browser_process_handler; + get_render_process_handler := cef_app_get_render_process_handler; + end; +end; + + +// TCustomCefApp + + +constructor TCustomCefApp.Create(const aCefApp : TCefApplication); +begin + inherited Create; + + FCefApp := aCefApp; +end; + +destructor TCustomCefApp.Destroy; +begin + FCefApp := nil; + + inherited Destroy; +end; + +procedure TCustomCefApp.OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnBeforeCommandLineProcessing(processType, commandLine); +end; + +procedure TCustomCefApp.OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnRegisterCustomSchemes(registrar); +end; + +procedure TCustomCefApp.GetResourceBundleHandler(var aHandler : ICefResourceBundleHandler); +begin + if (FCefApp <> nil) then + FCefApp.Internal_CopyResourceBundleHandler(aHandler) + else + aHandler := nil; +end; + +procedure TCustomCefApp.GetBrowserProcessHandler(var aHandler : ICefBrowserProcessHandler); +begin + if (FCefApp <> nil) then + FCefApp.Internal_CopyBrowserProcessHandler(aHandler) + else + aHandler := nil; +end; + +procedure TCustomCefApp.GetRenderProcessHandler(var aHandler : ICefRenderProcessHandler); +begin + if (FCefApp <> nil) then + FCefApp.Internal_CopyRenderProcessHandler(aHandler) + else + aHandler := nil; +end; + +end. diff --git a/source/uCEFApplication.pas b/source/uCEFApplication.pas index fa72ee87..e3bb98eb 100644 --- a/source/uCEFApplication.pas +++ b/source/uCEFApplication.pas @@ -52,8 +52,7 @@ uses {$ELSE} Windows, Classes, {$ENDIF} - uCEFTypes, uCEFInterfaces, uCEFBaseRefCounted, uCEFSchemeRegistrar, - uCEFBrowserProcessHandler, uCEFResourceBundleHandler, uCEFRenderProcessHandler; + uCEFTypes, uCEFInterfaces, uCEFBaseRefCounted, uCEFSchemeRegistrar; const CEF_SUPPORTED_VERSION_MAJOR = 3; @@ -70,8 +69,6 @@ const CHROMEELF_DLL = 'chrome_elf.dll'; type - TInternalApp = class; - TCefApplication = class protected FMustShutDown : boolean; @@ -129,14 +126,14 @@ type FChromeVersionInfo : TFileVersionInfo; FLibHandle : THandle; FOnRegisterCustomSchemes : TOnRegisterCustomSchemes; - FResourceBundleHandler : ICefResourceBundleHandler; - FBrowserProcessHandler : ICefBrowserProcessHandler; - FRenderProcessHandler : ICefRenderProcessHandler; FAppSettings : TCefSettings; FDeviceScaleFactor : single; FCheckDevToolsResources : boolean; FDisableGPUCache : boolean; FProcessType : TCefProcessType; + FResourceBundleHandler : ICefResourceBundleHandler; + FBrowserProcessHandler : ICefBrowserProcessHandler; + FRenderProcessHandler : ICefRenderProcessHandler; // ICefBrowserProcessHandler FOnContextInitializedEvent : TOnContextInitializedEvent; @@ -168,6 +165,12 @@ type function GetChromeVersion : string; function GetLibCefPath : string; function GetChromeElfPath : string; + function GetMustCreateResourceBundleHandler : boolean; + function GetMustCreateBrowserProcessHandler : boolean; + function GetMustCreateRenderProcessHandler : boolean; + function GetHasResourceBundleHandler : boolean; + function GetHasBrowserProcessHandler : boolean; + function GetHasRenderProcessHandler : boolean; function LoadCEFlibrary : boolean; virtual; function Load_cef_app_capi_h : boolean; @@ -224,9 +227,6 @@ type procedure ShowErrorMessageDlg(const aError : string); virtual; function ParseProcessType : TCefProcessType; procedure CreateAppHandlers; - procedure CreateBrowserProcessHandler; - procedure CreateResourceBundleHandler; - procedure CreateRenderProcessHandler; public constructor Create; @@ -241,9 +241,9 @@ type // ICefResourceBundleHandler and ICefRenderProcessHandler should use them. procedure Internal_OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); procedure Internal_OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef); - procedure Internal_OnGetResourceBundleHandler(var aCefResourceBundleHandler : ICefResourceBundleHandler); - procedure Internal_OnGetBrowserProcessHandler(var aCefBrowserProcessHandler : ICefBrowserProcessHandler); - procedure Internal_OnGetRenderProcessHandler(var aCefRenderProcessHandler : ICefRenderProcessHandler); + procedure Internal_CopyRenderProcessHandler(var aHandler : ICefRenderProcessHandler); + procedure Internal_CopyResourceBundleHandler(var aHandler : ICefResourceBundleHandler); + procedure Internal_CopyBrowserProcessHandler(var aHandler : ICefBrowserProcessHandler); procedure Internal_OnContextInitialized; procedure Internal_OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); procedure Internal_OnRenderProcessThreadCreated(const extraInfo: ICefListValue); @@ -323,6 +323,15 @@ type property LocalesRequired : ustring read FLocalesRequired write FLocalesRequired; property CustomFlashPath : ustring read FCustomFlashPath write FCustomFlashPath; property ProcessType : TCefProcessType read FProcessType; + property MustCreateResourceBundleHandler : boolean read GetMustCreateResourceBundleHandler; + property MustCreateBrowserProcessHandler : boolean read GetMustCreateBrowserProcessHandler; + property MustCreateRenderProcessHandler : boolean read GetMustCreateRenderProcessHandler; + property HasResourceBundleHandler : boolean read GetHasResourceBundleHandler; + property HasBrowserProcessHandler : boolean read GetHasBrowserProcessHandler; + property HasRenderProcessHandler : boolean read GetHasRenderProcessHandler; + property ResourceBundleHandler : ICefResourceBundleHandler read FResourceBundleHandler write FResourceBundleHandler; + property BrowserProcessHandler : ICefBrowserProcessHandler read FBrowserProcessHandler write FBrowserProcessHandler; + property RenderProcessHandler : ICefRenderProcessHandler read FRenderProcessHandler write FRenderProcessHandler; property OnRegCustomSchemes : TOnRegisterCustomSchemes read FOnRegisterCustomSchemes write FOnRegisterCustomSchemes; @@ -350,80 +359,6 @@ type property OnProcessMessageReceived : TOnProcessMessageReceivedEvent read FOnProcessMessageReceived write FOnProcessMessageReceived; end; - TCefAppOwn = class(TCefBaseRefCountedOwn, ICefApp) - protected - procedure OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); virtual; abstract; - procedure OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef); virtual; abstract; - function GetResourceBundleHandler: ICefResourceBundleHandler; virtual; abstract; - function GetBrowserProcessHandler: ICefBrowserProcessHandler; virtual; abstract; - function GetRenderProcessHandler: ICefRenderProcessHandler; virtual; abstract; - - public - constructor Create; virtual; - end; - - TInternalApp = class(TCefAppOwn) - protected - FCefApp : TCefApplication; - - procedure OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); override; - procedure OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef); override; - function GetResourceBundleHandler: ICefResourceBundleHandler; override; - function GetBrowserProcessHandler: ICefBrowserProcessHandler; override; - function GetRenderProcessHandler: ICefRenderProcessHandler; override; - - public - constructor Create(const aCefApp : TCefApplication); reintroduce; - destructor Destroy; override; - end; - - TCefCustomBrowserProcessHandler = class(TCefBrowserProcessHandlerOwn) - protected - FCefApp : TCefApplication; - - procedure OnContextInitialized; override; - procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); override; - procedure OnRenderProcessThreadCreated(const extraInfo: ICefListValue); override; - procedure OnScheduleMessagePumpWork(const delayMs: Int64); override; - - public - constructor Create(const aCefApp : TCefApplication); reintroduce; - destructor Destroy; override; - end; - - TCefCustomResourceBundleHandler = class(TCefResourceBundleHandlerOwn) - protected - FCefApp : TCefApplication; - - function GetLocalizedString(stringid: Integer; var stringVal: ustring): Boolean; override; - function GetDataResource(resourceId: Integer; var data: Pointer; var dataSize: NativeUInt): Boolean; override; - function GetDataResourceForScale(resourceId: Integer; scaleFactor: TCefScaleFactor; var data: Pointer; var dataSize: NativeUInt): Boolean; override; - - public - constructor Create(const aCefApp : TCefApplication); reintroduce; - destructor Destroy; override; - end; - - TCefCustomRenderProcessHandler = class(TCefRenderProcessHandlerOwn) - protected - FCefApp : TCefApplication; - - procedure OnRenderThreadCreated(const extraInfo: ICefListValue); override; - procedure OnWebKitInitialized; override; - procedure OnBrowserCreated(const browser: ICefBrowser); override; - procedure OnBrowserDestroyed(const browser: ICefBrowser); override; - function OnBeforeNavigation(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; navigationType: TCefNavigationType; isRedirect: Boolean): Boolean; override; - procedure OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); override; - procedure OnContextReleased(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); override; - procedure OnUncaughtException(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context; const exception: ICefV8Exception; const stackTrace: ICefV8StackTrace); override; - procedure OnFocusedNodeChanged(const browser: ICefBrowser; const frame: ICefFrame; const node: ICefDomNode); override; - function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const aMessage : ICefProcessMessage): Boolean; override; - - public - constructor Create(const aCefApp : TCefApplication); reintroduce; - destructor Destroy; override; - end; - var GlobalCEFApp : TCefApplication = nil; @@ -436,7 +371,8 @@ uses Math, {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} SysUtils, Dialogs, {$ENDIF} uCEFLibFunctions, uCEFMiscFunctions, uCEFCommandLine, uCEFConstants, - uCEFSchemeHandlerFactory, uCEFCookieManager; + uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp, + uCEFBrowserProcessHandler, uCEFResourceBundleHandler, uCEFRenderProcessHandler; constructor TCefApplication.Create; begin @@ -488,9 +424,6 @@ begin FFastUnload := False; FDisableSafeBrowsing := False; FOnRegisterCustomSchemes := nil; - FResourceBundleHandler := nil; - FBrowserProcessHandler := nil; - FRenderProcessHandler := nil; FEnableHighDPISupport := False; FMuteAudio := False; FReRaiseExceptions := False; @@ -502,6 +435,9 @@ begin FDisableGPUCache := False; FLocalesRequired := ''; FProcessType := ParseProcessType; + FResourceBundleHandler := nil; + FBrowserProcessHandler := nil; + FRenderProcessHandler := nil; // ICefBrowserProcessHandler FOnContextInitializedEvent := nil; @@ -561,54 +497,6 @@ begin FCustomCommandLineValues := TStringList.Create; end; -procedure TCefApplication.CreateAppHandlers; -begin - if FSingleProcess then - begin - CreateBrowserProcessHandler; - CreateResourceBundleHandler; - CreateRenderProcessHandler; - end - else - case FProcessType of - ptBrowser : - begin - CreateBrowserProcessHandler; - CreateResourceBundleHandler; - end; - - ptRenderer : CreateRenderProcessHandler; - end; -end; - -procedure TCefApplication.CreateBrowserProcessHandler; -begin - FBrowserProcessHandler := TCefCustomBrowserProcessHandler.Create(self); -end; - -procedure TCefApplication.CreateResourceBundleHandler; -begin - if assigned(FOnGetLocalizedStringEvent) or - assigned(FOnGetDataResourceEvent) or - assigned(FOnGetDataResourceForScaleEvent) then - FResourceBundleHandler := TCefCustomResourceBundleHandler.Create(self); -end; - -procedure TCefApplication.CreateRenderProcessHandler; -begin - if assigned(FOnRenderThreadCreated) or - assigned(FOnWebKitInitialized) or - assigned(FOnBrowserCreated) or - assigned(FOnBrowserDestroyed) or - assigned(FOnBeforeNavigation) or - assigned(FOnContextCreated) or - assigned(FOnContextReleased) or - assigned(FOnUncaughtException) or - assigned(FOnFocusedNodeChanged) or - assigned(FOnProcessMessageReceived) then - FRenderProcessHandler := TCefCustomRenderProcessHandler.Create(self); -end; - procedure TCefApplication.AddCustomCommandLine(const aCommandLine, aValue : string); begin if (FCustomCommandLines <> nil) then FCustomCommandLines.Add(aCommandLine); @@ -628,7 +516,7 @@ begin if LoadCEFlibrary then begin - TempApp := TInternalApp.Create(self); + TempApp := TCustomCefApp.Create(self); Result := InitializeLibrary(TempApp); end; end; @@ -647,7 +535,7 @@ begin try if CheckCEFLibrary and LoadCEFlibrary then begin - TempApp := TInternalApp.Create(self); + TempApp := TCustomCefApp.Create(self); if (ExecuteProcess(TempApp) < 0) then begin @@ -819,7 +707,7 @@ begin try if not(FSingleProcess) and LoadCEFlibrary then begin - TempApp := TInternalApp.Create(self); + TempApp := TCustomCefApp.Create(self); Result := (ExecuteProcess(TempApp) >= 0); end; except @@ -1043,6 +931,18 @@ begin end; end; +procedure TCefApplication.CreateAppHandlers; +begin + if MustCreateBrowserProcessHandler then + FBrowserProcessHandler := TCefCustomBrowserProcessHandler.Create(self); + + if MustCreateResourceBundleHandler then + FResourceBundleHandler := TCefCustomResourceBundleHandler.Create(self); + + if MustCreateRenderProcessHandler then + FRenderProcessHandler := TCefCustomRenderProcessHandler.Create(self); +end; + procedure TCefApplication.Internal_OnContextInitialized; begin InitializeCookies; @@ -1109,7 +1009,10 @@ end; procedure TCefApplication.Internal_OnBeforeNavigation(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; navigationType: TCefNavigationType; isRedirect: Boolean; var aStopNavigation : boolean); begin - if assigned(FOnBeforeNavigation) then FOnBeforeNavigation(browser, frame, request, navigationType, isRedirect, aStopNavigation); + if assigned(FOnBeforeNavigation) then + FOnBeforeNavigation(browser, frame, request, navigationType, isRedirect, aStopNavigation) + else + aStopNavigation := False; end; procedure TCefApplication.Internal_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); @@ -1134,7 +1037,10 @@ end; procedure TCefApplication.Internal_OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const aMessage: ICefProcessMessage; var aHandled : boolean); begin - if assigned(FOnProcessMessageReceived) then FOnProcessMessageReceived(browser, sourceProcess, aMessage, aHandled); + if assigned(FOnProcessMessageReceived) then + FOnProcessMessageReceived(browser, sourceProcess, aMessage, aHandled) + else + aHandled := False; end; procedure TCefApplication.Internal_OnBeforeCommandLineProcessing(const processType : ustring; @@ -1220,19 +1126,76 @@ begin if assigned(FOnRegisterCustomSchemes) then FOnRegisterCustomSchemes(registrar); end; -procedure TCefApplication.Internal_OnGetResourceBundleHandler(var aCefResourceBundleHandler : ICefResourceBundleHandler); +procedure TCefApplication.Internal_CopyRenderProcessHandler(var aHandler : ICefRenderProcessHandler); begin - if (FResourceBundleHandler <> nil) then aCefResourceBundleHandler := FResourceBundleHandler; + if (FRenderProcessHandler <> nil) then + aHandler := FRenderProcessHandler + else + aHandler := nil; end; -procedure TCefApplication.Internal_OnGetBrowserProcessHandler(var aCefBrowserProcessHandler : ICefBrowserProcessHandler); +procedure TCefApplication.Internal_CopyResourceBundleHandler(var aHandler : ICefResourceBundleHandler); begin - if (FBrowserProcessHandler <> nil) then aCefBrowserProcessHandler := FBrowserProcessHandler; + if (FResourceBundleHandler <> nil) then + aHandler := FResourceBundleHandler + else + aHandler := nil; end; -procedure TCefApplication.Internal_OnGetRenderProcessHandler(var aCefRenderProcessHandler : ICefRenderProcessHandler); +procedure TCefApplication.Internal_CopyBrowserProcessHandler(var aHandler : ICefBrowserProcessHandler); begin - if (FRenderProcessHandler <> nil) then aCefRenderProcessHandler := FRenderProcessHandler; + if (FBrowserProcessHandler <> nil) then + aHandler := FBrowserProcessHandler + else + aHandler := nil; +end; + +function TCefApplication.GetMustCreateResourceBundleHandler : boolean; +begin + Result := not(HasResourceBundleHandler) and + (FSingleProcess or + ((FProcessType = ptBrowser) and + (assigned(FOnGetLocalizedStringEvent) or + assigned(FOnGetDataResourceEvent) or + assigned(FOnGetDataResourceForScaleEvent)))); +end; + +function TCefApplication.GetMustCreateBrowserProcessHandler : boolean; +begin + Result := not(HasBrowserProcessHandler) and + (FSingleProcess or (FProcessType = ptBrowser)); +end; + +function TCefApplication.GetMustCreateRenderProcessHandler : boolean; +begin + Result := not(HasRenderProcessHandler) and + (FSingleProcess or + ((FProcessType = ptRenderer) and + (assigned(FOnRenderThreadCreated) or + assigned(FOnWebKitInitialized) or + assigned(FOnBrowserCreated) or + assigned(FOnBrowserDestroyed) or + assigned(FOnBeforeNavigation) or + assigned(FOnContextCreated) or + assigned(FOnContextReleased) or + assigned(FOnUncaughtException) or + assigned(FOnFocusedNodeChanged) or + assigned(FOnProcessMessageReceived)))); +end; + +function TCefApplication.GetHasResourceBundleHandler : boolean; +begin + Result := (FResourceBundleHandler <> nil); +end; + +function TCefApplication.GetHasBrowserProcessHandler : boolean; +begin + Result := (FBrowserProcessHandler <> nil); +end; + +function TCefApplication.GetHasRenderProcessHandler : boolean; +begin + Result := (FRenderProcessHandler <> nil); end; function TCefApplication.LoadCEFlibrary : boolean; @@ -1844,307 +1807,4 @@ begin assigned(cef_trace_event_async_end); end; - -// TCefAppOwn - -procedure cef_app_on_before_command_line_processing(self: PCefApp; - const process_type: PCefString; - command_line: PCefCommandLine); stdcall; -var - TempObject : TObject; -begin - TempObject := CefGetObject(self); - - if (TempObject <> nil) and (TempObject is TCefAppOwn) then - TCefAppOwn(TempObject).OnBeforeCommandLineProcessing(CefString(process_type), TCefCommandLineRef.UnWrap(command_line)); -end; - -procedure cef_app_on_register_custom_schemes(self: PCefApp; registrar: PCefSchemeRegistrar); stdcall; -var - TempWrapper : TCefSchemeRegistrarRef; - TempObject : TObject; -begin - TempWrapper := nil; - - try - try - TempWrapper := TCefSchemeRegistrarRef.Create(registrar); - TempObject := CefGetObject(self); - - if (TempObject <> nil) and (TempObject is TCefAppOwn) then - TCefAppOwn(TempObject).OnRegisterCustomSchemes(TempWrapper); - except - on e : exception do - if CustomExceptionHandler('cef_app_on_register_custom_schemes', e) then raise; - end; - finally - if (TempWrapper <> nil) then FreeAndNil(TempWrapper); - end; -end; - -function cef_app_get_resource_bundle_handler(self: PCefApp): PCefResourceBundleHandler; stdcall; -var - TempObject : TObject; -begin - TempObject := CefGetObject(self); - - if (TempObject <> nil) and (TempObject is TCefAppOwn) then - Result := CefGetData(TCefAppOwn(TempObject).GetResourceBundleHandler) - else - Result := nil; -end; - -function cef_app_get_browser_process_handler(self: PCefApp): PCefBrowserProcessHandler; stdcall; -var - TempObject : TObject; -begin - TempObject := CefGetObject(self); - - if (TempObject <> nil) and (TempObject is TCefAppOwn) then - Result := CefGetData(TCefAppOwn(TempObject).GetBrowserProcessHandler) - else - Result := nil; -end; - -function cef_app_get_render_process_handler(self: PCefApp): PCefRenderProcessHandler; stdcall; -var - TempObject : TObject; -begin - TempObject := CefGetObject(self); - - if (TempObject <> nil) and (TempObject is TCefAppOwn) then - Result := CefGetData(TCefAppOwn(TempObject).GetRenderProcessHandler) - else - Result := nil; -end; - - -constructor TCefAppOwn.Create; -begin - inherited CreateData(SizeOf(TCefApp)); - - with PCefApp(FData)^ do - begin - on_before_command_line_processing := cef_app_on_before_command_line_processing; - on_register_custom_schemes := cef_app_on_register_custom_schemes; - get_resource_bundle_handler := cef_app_get_resource_bundle_handler; - get_browser_process_handler := cef_app_get_browser_process_handler; - get_render_process_handler := cef_app_get_render_process_handler; - end; -end; - -// TInternalApp - -procedure TInternalApp.OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnBeforeCommandLineProcessing(processType, commandLine); -end; - -procedure TInternalApp.OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnRegisterCustomSchemes(registrar); -end; - -function TInternalApp.GetResourceBundleHandler: ICefResourceBundleHandler; -begin - Result := nil; - if (FCefApp <> nil) then FCefApp.Internal_OnGetResourceBundleHandler(Result); -end; - -function TInternalApp.GetBrowserProcessHandler: ICefBrowserProcessHandler; -begin - Result := nil; - if (FCefApp <> nil) then FCefApp.Internal_OnGetBrowserProcessHandler(Result); -end; - -function TInternalApp.GetRenderProcessHandler: ICefRenderProcessHandler; -begin - Result := nil; - if (FCefApp <> nil) then FCefApp.Internal_OnGetRenderProcessHandler(Result); -end; - -constructor TInternalApp.Create(const aCefApp : TCefApplication); -begin - inherited Create; - - FCefApp := aCefApp; -end; - -destructor TInternalApp.Destroy; -begin - FCefApp := nil; - - inherited Destroy; -end; - -// TCefCustomBrowserProcessHandler - -constructor TCefCustomBrowserProcessHandler.Create(const aCefApp : TCefApplication); -begin - inherited Create; - - FCefApp := aCefApp; -end; - -destructor TCefCustomBrowserProcessHandler.Destroy; -begin - FCefApp := nil; - - inherited Destroy; -end; - -procedure TCefCustomBrowserProcessHandler.OnContextInitialized; -begin - if (FCefApp <> nil) then FCefApp.Internal_OnContextInitialized; -end; - -procedure TCefCustomBrowserProcessHandler.OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnBeforeChildProcessLaunch(commandLine); -end; - -procedure TCefCustomBrowserProcessHandler.OnRenderProcessThreadCreated(const extraInfo: ICefListValue); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnRenderProcessThreadCreated(extraInfo); -end; - -procedure TCefCustomBrowserProcessHandler.OnScheduleMessagePumpWork(const delayMs: Int64); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnScheduleMessagePumpWork(delayMs); -end; - -// TCefCustomResourceBundleHandler - -constructor TCefCustomResourceBundleHandler.Create(const aCefApp : TCefApplication); -begin - inherited Create; - - FCefApp := aCefApp; -end; - -destructor TCefCustomResourceBundleHandler.Destroy; -begin - FCefApp := nil; - - inherited Destroy; -end; - -function TCefCustomResourceBundleHandler.GetLocalizedString(stringid : Integer; - var stringVal : ustring): Boolean; -begin - if (FCefApp <> nil) then - Result := FCefApp.Internal_GetLocalizedString(stringid, stringVal) - else - Result := False; -end; - -function TCefCustomResourceBundleHandler.GetDataResource(resourceId : Integer; - var data : Pointer; - var dataSize : NativeUInt): Boolean; -begin - if (FCefApp <> nil) then - Result := FCefApp.Internal_GetDataResource(resourceId, data, dataSize) - else - Result := False; -end; - -function TCefCustomResourceBundleHandler.GetDataResourceForScale(resourceId : Integer; - scaleFactor : TCefScaleFactor; - var data : Pointer; - var dataSize : NativeUInt): Boolean; -begin - if (FCefApp <> nil) then - Result := FCefApp.Internal_GetDataResourceForScale(resourceId, scaleFactor, data, dataSize) - else - Result := False; -end; - -// TCefCustomRenderProcessHandler - -constructor TCefCustomRenderProcessHandler.Create(const aCefApp : TCefApplication); -begin - inherited Create; - - FCefApp := aCefApp; -end; - -destructor TCefCustomRenderProcessHandler.Destroy; -begin - FCefApp := nil; - - inherited Destroy; -end; - -procedure TCefCustomRenderProcessHandler.OnRenderThreadCreated(const extraInfo: ICefListValue); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnRenderThreadCreated(extraInfo); -end; - -procedure TCefCustomRenderProcessHandler.OnWebKitInitialized; -begin - if (FCefApp <> nil) then FCefApp.Internal_OnWebKitInitialized; -end; - -procedure TCefCustomRenderProcessHandler.OnBrowserCreated(const browser: ICefBrowser); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnBrowserCreated(browser); -end; - -procedure TCefCustomRenderProcessHandler.OnBrowserDestroyed(const browser: ICefBrowser); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnBrowserDestroyed(browser); -end; - -function TCefCustomRenderProcessHandler.OnBeforeNavigation(const browser : ICefBrowser; - const frame : ICefFrame; - const request : ICefRequest; - navigationType : TCefNavigationType; - isRedirect : Boolean): Boolean; -begin - if (FCefApp <> nil) then - FCefApp.Internal_OnBeforeNavigation(browser, frame, request, navigationType, isRedirect, Result) - else - Result := False; -end; - -procedure TCefCustomRenderProcessHandler.OnContextCreated(const browser : ICefBrowser; - const frame : ICefFrame; - const context : ICefv8Context); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnContextCreated(browser, frame, context); -end; - -procedure TCefCustomRenderProcessHandler.OnContextReleased(const browser : ICefBrowser; - const frame : ICefFrame; - const context : ICefv8Context); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnContextReleased(browser, frame, context); -end; - -procedure TCefCustomRenderProcessHandler.OnUncaughtException(const browser : ICefBrowser; - const frame : ICefFrame; - const context : ICefv8Context; - const exception : ICefV8Exception; - const stackTrace : ICefV8StackTrace); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnUncaughtException(browser, frame, context, exception, stackTrace); -end; - -procedure TCefCustomRenderProcessHandler.OnFocusedNodeChanged(const browser : ICefBrowser; - const frame : ICefFrame; - const node : ICefDomNode); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnFocusedNodeChanged(browser, frame, node); -end; - -function TCefCustomRenderProcessHandler.OnProcessMessageReceived(const browser : ICefBrowser; - sourceProcess : TCefProcessId; - const aMessage : ICefProcessMessage): Boolean; -begin - if (FCefApp <> nil) then - FCefApp.Internal_OnProcessMessageReceived(browser, sourceProcess, aMessage, Result) - else - Result := False; -end; - end. diff --git a/source/uCEFBaseRefCounted.pas b/source/uCEFBaseRefCounted.pas index c7caa0d8..96b65e7e 100644 --- a/source/uCEFBaseRefCounted.pas +++ b/source/uCEFBaseRefCounted.pas @@ -55,7 +55,7 @@ type FData: Pointer; public - constructor CreateData(size: Cardinal; owned: Boolean = False); virtual; + constructor CreateData(size: Cardinal; owned : boolean = False); virtual; destructor Destroy; override; function Wrap: Pointer; end; @@ -88,7 +88,7 @@ begin TCefBaseRefCountedOwn(TempObject)._AddRef; end; -function cef_base_release(self: PCefBaseRefCounted): Integer; stdcall; +function cef_base_release_ref(self: PCefBaseRefCounted): Integer; stdcall; var TempObject : TObject; begin @@ -127,7 +127,7 @@ begin Result := 1; end; -constructor TCefBaseRefCountedOwn.CreateData(size: Cardinal; owned: Boolean); +constructor TCefBaseRefCountedOwn.CreateData(size: Cardinal; owned : boolean); begin GetMem(FData, size + SizeOf(Pointer)); PPointer(FData)^ := Self; @@ -144,7 +144,7 @@ begin else begin PCefBaseRefCounted(FData)^.add_ref := cef_base_add_ref; - PCefBaseRefCounted(FData)^.release := cef_base_release; + PCefBaseRefCounted(FData)^.release := cef_base_release_ref; PCefBaseRefCounted(FData)^.has_one_ref := cef_base_has_one_ref; end; end; diff --git a/source/uCEFBrowserProcessHandler.pas b/source/uCEFBrowserProcessHandler.pas index 40add39f..a53099f3 100644 --- a/source/uCEFBrowserProcessHandler.pas +++ b/source/uCEFBrowserProcessHandler.pas @@ -47,48 +47,93 @@ unit uCEFBrowserProcessHandler; interface uses - uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes; + uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFApplication; type TCefBrowserProcessHandlerOwn = class(TCefBaseRefCountedOwn, ICefBrowserProcessHandler) protected - procedure OnContextInitialized; virtual; - procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); virtual; - procedure OnRenderProcessThreadCreated(const extraInfo: ICefListValue); virtual; - procedure OnScheduleMessagePumpWork(const delayMs: Int64); virtual; + procedure OnContextInitialized; virtual; abstract; + procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); virtual; abstract; + procedure OnRenderProcessThreadCreated(const extraInfo: ICefListValue); virtual; abstract; + function GetPrintHandler : ICefPrintHandler; virtual; + procedure OnScheduleMessagePumpWork(const delayMs: Int64); virtual; abstract; public constructor Create; virtual; end; + TCefCustomBrowserProcessHandler = class(TCefBrowserProcessHandlerOwn) + protected + FCefApp : TCefApplication; + + procedure OnContextInitialized; override; + procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); override; + procedure OnRenderProcessThreadCreated(const extraInfo: ICefListValue); override; + procedure OnScheduleMessagePumpWork(const delayMs: Int64); override; + + public + constructor Create(const aCefApp : TCefApplication); reintroduce; + destructor Destroy; override; + end; + implementation uses - uCEFMiscFunctions, uCEFLibFunctions, uCEFCommandLine, uCEFListValue; + uCEFMiscFunctions, uCEFLibFunctions, uCEFCommandLine, uCEFListValue, uCEFConstants; procedure cef_browser_process_handler_on_context_initialized(self: PCefBrowserProcessHandler); stdcall; +var + TempObject : TObject; begin - with TCefBrowserProcessHandlerOwn(CefGetObject(self)) do - OnContextInitialized; + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then + TCefBrowserProcessHandlerOwn(TempObject).OnContextInitialized; end; -procedure cef_browser_process_handler_on_before_child_process_launch( - self: PCefBrowserProcessHandler; command_line: PCefCommandLine); stdcall; +procedure cef_browser_process_handler_on_before_child_process_launch(self : PCefBrowserProcessHandler; + command_line : PCefCommandLine); stdcall; +var + TempObject : TObject; begin - with TCefBrowserProcessHandlerOwn(CefGetObject(self)) do - OnBeforeChildProcessLaunch(TCefCommandLineRef.UnWrap(command_line)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then + TCefBrowserProcessHandlerOwn(TempObject).OnBeforeChildProcessLaunch(TCefCommandLineRef.UnWrap(command_line)); end; -procedure cef_browser_process_handler_on_render_process_thread_created( - self: PCefBrowserProcessHandler; extra_info: PCefListValue); stdcall; +procedure cef_browser_process_handler_on_render_process_thread_created(self : PCefBrowserProcessHandler; + extra_info : PCefListValue); stdcall; +var + TempObject : TObject; begin - with TCefBrowserProcessHandlerOwn(CefGetObject(self)) do - OnRenderProcessThreadCreated(TCefListValueRef.UnWrap(extra_info)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then + TCefBrowserProcessHandlerOwn(TempObject).OnRenderProcessThreadCreated(TCefListValueRef.UnWrap(extra_info)); end; -procedure cef_browser_process_handler_on_schedule_message_pump_work(self: PCefBrowserProcessHandler; delay_ms: Int64); stdcall; +function cef_browser_process_handler_get_print_handler(self: PCefBrowserProcessHandler): PCefPrintHandler; stdcall; +var + TempObject : TObject; begin - TCefBrowserProcessHandlerOwn(CefGetObject(self)).OnScheduleMessagePumpWork(delay_ms); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then + Result := CefGetData(TCefBrowserProcessHandlerOwn(TempObject).GetPrintHandler) + else + Result := nil; +end; + +procedure cef_browser_process_handler_on_schedule_message_pump_work(self : PCefBrowserProcessHandler; + delay_ms : Int64); stdcall; +var + TempObject : TObject; +begin + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then + TCefBrowserProcessHandlerOwn(TempObject).OnScheduleMessagePumpWork(delay_ms); end; constructor TCefBrowserProcessHandlerOwn.Create; @@ -100,29 +145,52 @@ begin on_context_initialized := cef_browser_process_handler_on_context_initialized; on_before_child_process_launch := cef_browser_process_handler_on_before_child_process_launch; on_render_process_thread_created := cef_browser_process_handler_on_render_process_thread_created; - get_print_handler := nil; // linux + get_print_handler := cef_browser_process_handler_get_print_handler; on_schedule_message_pump_work := cef_browser_process_handler_on_schedule_message_pump_work; end; end; -procedure TCefBrowserProcessHandlerOwn.OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); +function TCefBrowserProcessHandlerOwn.GetPrintHandler : ICefPrintHandler; begin - + Result := nil; // only linux end; -procedure TCefBrowserProcessHandlerOwn.OnContextInitialized; -begin +// TCefCustomBrowserProcessHandler + + +constructor TCefCustomBrowserProcessHandler.Create(const aCefApp : TCefApplication); +begin + inherited Create; + + FCefApp := aCefApp; end; -procedure TCefBrowserProcessHandlerOwn.OnRenderProcessThreadCreated(const extraInfo: ICefListValue); +destructor TCefCustomBrowserProcessHandler.Destroy; begin + FCefApp := nil; + inherited Destroy; end; -procedure TCefBrowserProcessHandlerOwn.OnScheduleMessagePumpWork(const delayMs: Int64); +procedure TCefCustomBrowserProcessHandler.OnContextInitialized; begin + if (FCefApp <> nil) then FCefApp.Internal_OnContextInitialized; +end; +procedure TCefCustomBrowserProcessHandler.OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnBeforeChildProcessLaunch(commandLine); +end; + +procedure TCefCustomBrowserProcessHandler.OnRenderProcessThreadCreated(const extraInfo: ICefListValue); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnRenderProcessThreadCreated(extraInfo); +end; + +procedure TCefCustomBrowserProcessHandler.OnScheduleMessagePumpWork(const delayMs: Int64); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnScheduleMessagePumpWork(delayMs); end; end. diff --git a/source/uCEFDragHandler.pas b/source/uCEFDragHandler.pas index 10bf8def..051458ed 100644 --- a/source/uCEFDragHandler.pas +++ b/source/uCEFDragHandler.pas @@ -92,7 +92,7 @@ end; constructor TCefDragHandlerOwn.Create; begin - CreateData(SizeOf(TCefDragHandler), False); + CreateData(SizeOf(TCefDragHandler)); with PCefDragHandler(FData)^ do begin on_drag_enter := cef_drag_handler_on_drag_enter; diff --git a/source/uCEFFindHandler.pas b/source/uCEFFindHandler.pas index 4f7c10af..d1c99225 100644 --- a/source/uCEFFindHandler.pas +++ b/source/uCEFFindHandler.pas @@ -82,7 +82,7 @@ end; constructor TCefFindHandlerOwn.Create; begin - CreateData(SizeOf(TCefFindHandler), False); + CreateData(SizeOf(TCefFindHandler)); with PCefFindHandler(FData)^ do on_find_result := cef_find_handler_on_find_result; end; diff --git a/source/uCEFInterfaces.pas b/source/uCEFInterfaces.pas index 13c80935..916e5ed8 100644 --- a/source/uCEFInterfaces.pas +++ b/source/uCEFInterfaces.pas @@ -101,6 +101,7 @@ type ICefExtensionHandler = interface; ICefExtension = interface; ICefStreamReader = interface; + ICefLoadHandler = interface; TCefv8ValueArray = array of ICefv8Value; TCefX509CertificateArray = array of ICefX509Certificate; @@ -828,13 +829,6 @@ type count, total: Integer; out deleteCookie: Boolean): Boolean; end; - ICefResourceBundleHandler = interface(ICefBaseRefCounted) - ['{09C264FD-7E03-41E3-87B3-4234E82B5EA2}'] - function GetLocalizedString(stringId: Integer; var stringVal: ustring): Boolean; - function GetDataResource(resourceId: Integer; var data: Pointer; var dataSize: NativeUInt): Boolean; - function GetDataResourceForScale(resourceId: Integer; scaleFactor: TCefScaleFactor; var data: Pointer; var dataSize: NativeUInt): Boolean; - end; - ICefCommandLine = interface(ICefBaseRefCounted) ['{6B43D21B-0F2C-4B94-B4E6-4AF0D7669D8E}'] function IsValid: Boolean; @@ -860,11 +854,19 @@ type property CommandLineString: ustring read GetCommandLineString; end; + ICefResourceBundleHandler = interface(ICefBaseRefCounted) + ['{09C264FD-7E03-41E3-87B3-4234E82B5EA2}'] + function GetLocalizedString(stringId: Integer; var stringVal: ustring): Boolean; + function GetDataResource(resourceId: Integer; var data: Pointer; var dataSize: NativeUInt): Boolean; + function GetDataResourceForScale(resourceId: Integer; scaleFactor: TCefScaleFactor; var data: Pointer; var dataSize: NativeUInt): Boolean; + end; + ICefBrowserProcessHandler = interface(ICefBaseRefCounted) ['{27291B7A-C0AE-4EE0-9115-15C810E22F6C}'] procedure OnContextInitialized; procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); procedure OnRenderProcessThreadCreated(const extraInfo: ICefListValue); + function GetPrintHandler : ICefPrintHandler; procedure OnScheduleMessagePumpWork(const delayMs: Int64); end; @@ -874,20 +876,22 @@ type procedure OnWebKitInitialized; procedure OnBrowserCreated(const browser: ICefBrowser); procedure OnBrowserDestroyed(const browser: ICefBrowser); + function GetLoadHandler : ICefLoadHandler; + function OnBeforeNavigation(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; navigationType: TCefNavigationType; isRedirect: Boolean): Boolean; procedure OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); procedure OnContextReleased(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); procedure OnUncaughtException(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context; const exception: ICefV8Exception; const stackTrace: ICefV8StackTrace); procedure OnFocusedNodeChanged(const browser: ICefBrowser; const frame: ICefFrame; const node: ICefDomNode); - function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; + function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const aMessage: ICefProcessMessage): Boolean; end; ICefApp = interface(ICefBaseRefCounted) ['{970CA670-9070-4642-B188-7D8A22DAEED4}'] procedure OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); procedure OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef); - function GetResourceBundleHandler: ICefResourceBundleHandler; - function GetBrowserProcessHandler: ICefBrowserProcessHandler; - function GetRenderProcessHandler: ICefRenderProcessHandler; + procedure GetResourceBundleHandler(var aHandler : ICefResourceBundleHandler); + procedure GetBrowserProcessHandler(var aHandler : ICefBrowserProcessHandler); + procedure GetRenderProcessHandler(var aHandler : ICefRenderProcessHandler); end; TCefCookieVisitorProc = {$IFDEF DELPHI12_UP}reference to{$ENDIF} function( diff --git a/source/uCEFMenuModelDelegate.pas b/source/uCEFMenuModelDelegate.pas index 8c825418..c668ee59 100644 --- a/source/uCEFMenuModelDelegate.pas +++ b/source/uCEFMenuModelDelegate.pas @@ -119,7 +119,7 @@ end; constructor TCefMenuModelDelegateOwn.Create; begin - CreateData(SizeOf(TCefMenuModelDelegate), False); + CreateData(SizeOf(TCefMenuModelDelegate)); with PCefMenuModelDelegate(FData)^ do begin diff --git a/source/uCEFNavigationEntryVisitor.pas b/source/uCEFNavigationEntryVisitor.pas index 1970a937..be4c2037 100644 --- a/source/uCEFNavigationEntryVisitor.pas +++ b/source/uCEFNavigationEntryVisitor.pas @@ -83,7 +83,7 @@ end; constructor TCefNavigationEntryVisitorOwn.Create; begin - CreateData(SizeOf(TCefNavigationEntryVisitor), False); + CreateData(SizeOf(TCefNavigationEntryVisitor)); with PCefNavigationEntryVisitor(FData)^ do visit := cef_navigation_entry_visitor_visit; end; diff --git a/source/uCEFPDFPrintCallback.pas b/source/uCEFPDFPrintCallback.pas index 449aea86..c000a132 100644 --- a/source/uCEFPDFPrintCallback.pas +++ b/source/uCEFPDFPrintCallback.pas @@ -90,7 +90,7 @@ end; constructor TCefPdfPrintCallbackOwn.Create; begin - CreateData(SizeOf(TCefPdfPrintCallback), False); + CreateData(SizeOf(TCefPdfPrintCallback)); PCefPdfPrintCallback(FData).on_pdf_print_finished := cef_pdf_print_callback_on_pdf_print_finished; end; diff --git a/source/uCEFRenderHandler.pas b/source/uCEFRenderHandler.pas index 8392198b..032091a9 100644 --- a/source/uCEFRenderHandler.pas +++ b/source/uCEFRenderHandler.pas @@ -209,7 +209,7 @@ end; constructor TCefRenderHandlerOwn.Create; begin - CreateData(SizeOf(TCefRenderHandler), False); + CreateData(SizeOf(TCefRenderHandler)); with PCefRenderHandler(FData)^ do begin diff --git a/source/uCEFRenderProcessHandler.pas b/source/uCEFRenderProcessHandler.pas index ef3003f8..b8323c7f 100644 --- a/source/uCEFRenderProcessHandler.pas +++ b/source/uCEFRenderProcessHandler.pas @@ -53,111 +53,206 @@ uses Classes, {$ENDIF} uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFListValue, uCEFBrowser, uCEFFrame, uCEFRequest, - uCEFv8Context, uCEFv8Exception, uCEFv8StackTrace, uCEFDomNode, uCEFProcessMessage; + uCEFv8Context, uCEFv8Exception, uCEFv8StackTrace, uCEFDomNode, uCEFProcessMessage, uCEFApplication; type TCefRenderProcessHandlerOwn = class(TCefBaseRefCountedOwn, ICefRenderProcessHandler) protected - procedure OnRenderThreadCreated(const extraInfo: ICefListValue); virtual; - procedure OnWebKitInitialized; virtual; - procedure OnBrowserCreated(const browser: ICefBrowser); virtual; - procedure OnBrowserDestroyed(const browser: ICefBrowser); virtual; - function GetLoadHandler: PCefLoadHandler; virtual; + procedure OnRenderThreadCreated(const extraInfo: ICefListValue); virtual; abstract; + procedure OnWebKitInitialized; virtual; abstract; + procedure OnBrowserCreated(const browser: ICefBrowser); virtual; abstract; + procedure OnBrowserDestroyed(const browser: ICefBrowser); virtual; abstract; + function GetLoadHandler: ICefLoadHandler; virtual; function OnBeforeNavigation(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; navigationType: TCefNavigationType; isRedirect: Boolean): Boolean; virtual; - procedure OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); virtual; - procedure OnContextReleased(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); virtual; - procedure OnUncaughtException(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context; const exception: ICefV8Exception; const stackTrace: ICefV8StackTrace); virtual; - procedure OnFocusedNodeChanged(const browser: ICefBrowser; const frame: ICefFrame; const node: ICefDomNode); virtual; - function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; virtual; + procedure OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); virtual; abstract; + procedure OnContextReleased(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); virtual; abstract; + procedure OnUncaughtException(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context; const exception: ICefV8Exception; const stackTrace: ICefV8StackTrace); virtual; abstract; + procedure OnFocusedNodeChanged(const browser: ICefBrowser; const frame: ICefFrame; const node: ICefDomNode); virtual; abstract; + function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const aMessage: ICefProcessMessage): Boolean; virtual; public constructor Create; virtual; end; + TCefCustomRenderProcessHandler = class(TCefRenderProcessHandlerOwn) + protected + FCefApp : TCefApplication; + + procedure OnRenderThreadCreated(const extraInfo: ICefListValue); override; + procedure OnWebKitInitialized; override; + procedure OnBrowserCreated(const browser: ICefBrowser); override; + procedure OnBrowserDestroyed(const browser: ICefBrowser); override; + function OnBeforeNavigation(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; navigationType: TCefNavigationType; isRedirect: Boolean): Boolean; override; + procedure OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); override; + procedure OnContextReleased(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context); override; + procedure OnUncaughtException(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context; const exception: ICefV8Exception; const stackTrace: ICefV8StackTrace); override; + procedure OnFocusedNodeChanged(const browser: ICefBrowser; const frame: ICefFrame; const node: ICefDomNode); override; + function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const aMessage : ICefProcessMessage): Boolean; override; + + public + constructor Create(const aCefApp : TCefApplication); reintroduce; + destructor Destroy; override; + end; + implementation uses - uCEFMiscFunctions, uCEFLibFunctions; + uCEFMiscFunctions, uCEFLibFunctions, uCEFConstants; -procedure cef_render_process_handler_on_render_thread_created(self: PCefRenderProcessHandler; extra_info: PCefListValue); stdcall; +procedure cef_render_process_handler_on_render_thread_created(self : PCefRenderProcessHandler; + extra_info : PCefListValue); stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - OnRenderThreadCreated(TCefListValueRef.UnWrap(extra_info)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + TCefRenderProcessHandlerOwn(TempObject).OnRenderThreadCreated(TCefListValueRef.UnWrap(extra_info)); end; procedure cef_render_process_handler_on_web_kit_initialized(self: PCefRenderProcessHandler); stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - OnWebKitInitialized; + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + TCefRenderProcessHandlerOwn(TempObject).OnWebKitInitialized; end; -procedure cef_render_process_handler_on_browser_created(self: PCefRenderProcessHandler; browser: PCefBrowser); stdcall; +procedure cef_render_process_handler_on_browser_created(self : PCefRenderProcessHandler; + browser : PCefBrowser); stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - OnBrowserCreated(TCefBrowserRef.UnWrap(browser)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + TCefRenderProcessHandlerOwn(TempObject).OnBrowserCreated(TCefBrowserRef.UnWrap(browser)); end; -procedure cef_render_process_handler_on_browser_destroyed(self: PCefRenderProcessHandler; - browser: PCefBrowser); stdcall; +procedure cef_render_process_handler_on_browser_destroyed(self : PCefRenderProcessHandler; + browser : PCefBrowser); stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - OnBrowserDestroyed(TCefBrowserRef.UnWrap(browser)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + TCefRenderProcessHandlerOwn(TempObject).OnBrowserDestroyed(TCefBrowserRef.UnWrap(browser)); end; function cef_render_process_handler_get_load_handler(self: PCefRenderProcessHandler): PCefLoadHandler; stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - Result := GetLoadHandler(); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + Result := CefGetData(TCefRenderProcessHandlerOwn(TempObject).GetLoadHandler) + else + Result := nil; end; -function cef_render_process_handler_on_before_navigation(self: PCefRenderProcessHandler; - browser: PCefBrowser; frame: PCefFrame; request: PCefRequest; - navigation_type: TCefNavigationType; is_redirect: Integer): Integer; stdcall; +function cef_render_process_handler_on_before_navigation(self : PCefRenderProcessHandler; + browser : PCefBrowser; + frame : PCefFrame; + request : PCefRequest; + navigation_type : TCefNavigationType; + is_redirect : Integer): Integer; stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - Result := Ord(OnBeforeNavigation(TCefBrowserRef.UnWrap(browser), - TCefFrameRef.UnWrap(frame), TCefRequestRef.UnWrap(request), - navigation_type, is_redirect <> 0)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + Result := Ord(TCefRenderProcessHandlerOwn(TempObject).OnBeforeNavigation(TCefBrowserRef.UnWrap(browser), + TCefFrameRef.UnWrap(frame), + TCefRequestRef.UnWrap(request), + navigation_type, + is_redirect <> 0)) + else + Result := 0; end; -procedure cef_render_process_handler_on_context_created(self: PCefRenderProcessHandler; - browser: PCefBrowser; frame: PCefFrame; context: PCefv8Context); stdcall; +procedure cef_render_process_handler_on_context_created(self : PCefRenderProcessHandler; + browser : PCefBrowser; + frame : PCefFrame; + context : PCefv8Context); stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - OnContextCreated(TCefBrowserRef.UnWrap(browser), TCefFrameRef.UnWrap(frame), TCefv8ContextRef.UnWrap(context)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + TCefRenderProcessHandlerOwn(TempObject).OnContextCreated(TCefBrowserRef.UnWrap(browser), + TCefFrameRef.UnWrap(frame), + TCefv8ContextRef.UnWrap(context)); end; -procedure cef_render_process_handler_on_context_released(self: PCefRenderProcessHandler; - browser: PCefBrowser; frame: PCefFrame; context: PCefv8Context); stdcall; +procedure cef_render_process_handler_on_context_released(self : PCefRenderProcessHandler; + browser : PCefBrowser; + frame : PCefFrame; + context : PCefv8Context); stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - OnContextReleased(TCefBrowserRef.UnWrap(browser), TCefFrameRef.UnWrap(frame), TCefv8ContextRef.UnWrap(context)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + TCefRenderProcessHandlerOwn(TempObject).OnContextReleased(TCefBrowserRef.UnWrap(browser), + TCefFrameRef.UnWrap(frame), + TCefv8ContextRef.UnWrap(context)); end; -procedure cef_render_process_handler_on_uncaught_exception(self: PCefRenderProcessHandler; - browser: PCefBrowser; frame: PCefFrame; context: PCefv8Context; - exception: PCefV8Exception; stackTrace: PCefV8StackTrace); stdcall; +procedure cef_render_process_handler_on_uncaught_exception(self : PCefRenderProcessHandler; + browser : PCefBrowser; + frame : PCefFrame; + context : PCefv8Context; + exception : PCefV8Exception; + stackTrace : PCefV8StackTrace); stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - OnUncaughtException(TCefBrowserRef.UnWrap(browser), TCefFrameRef.UnWrap(frame), - TCefv8ContextRef.UnWrap(context), TCefV8ExceptionRef.UnWrap(exception), - TCefV8StackTraceRef.UnWrap(stackTrace)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + TCefRenderProcessHandlerOwn(TempObject).OnUncaughtException(TCefBrowserRef.UnWrap(browser), + TCefFrameRef.UnWrap(frame), + TCefv8ContextRef.UnWrap(context), + TCefV8ExceptionRef.UnWrap(exception), + TCefV8StackTraceRef.UnWrap(stackTrace)); end; -procedure cef_render_process_handler_on_focused_node_changed(self: PCefRenderProcessHandler; - browser: PCefBrowser; frame: PCefFrame; node: PCefDomNode); stdcall; +procedure cef_render_process_handler_on_focused_node_changed(self : PCefRenderProcessHandler; + browser : PCefBrowser; + frame : PCefFrame; + node : PCefDomNode); stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - OnFocusedNodeChanged(TCefBrowserRef.UnWrap(browser), TCefFrameRef.UnWrap(frame), - TCefDomNodeRef.UnWrap(node)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + TCefRenderProcessHandlerOwn(TempObject).OnFocusedNodeChanged(TCefBrowserRef.UnWrap(browser), + TCefFrameRef.UnWrap(frame), + TCefDomNodeRef.UnWrap(node)); end; -function cef_render_process_handler_on_process_message_received(self: PCefRenderProcessHandler; - browser: PCefBrowser; source_process: TCefProcessId; - message: PCefProcessMessage): Integer; stdcall; +function cef_render_process_handler_on_process_message_received(self : PCefRenderProcessHandler; + browser : PCefBrowser; + source_process : TCefProcessId; + message_ : PCefProcessMessage): Integer; stdcall; +var + TempObject : TObject; begin - with TCefRenderProcessHandlerOwn(CefGetObject(Self)) do - Result := Ord(OnProcessMessageReceived(TCefBrowserRef.UnWrap(browser), source_process, - TCefProcessMessageRef.UnWrap(message))); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefRenderProcessHandlerOwn) then + Result := Ord(TCefRenderProcessHandlerOwn(TempObject).OnProcessMessageReceived(TCefBrowserRef.UnWrap(browser), + source_process, + TCefProcessMessageRef.UnWrap(message_))) + else + Result := 0; end; @@ -184,74 +279,113 @@ begin end; end; -function TCefRenderProcessHandlerOwn.GetLoadHandler: PCefLoadHandler; +function TCefRenderProcessHandlerOwn.GetLoadHandler: ICefLoadHandler; begin Result := nil; end; -function TCefRenderProcessHandlerOwn.OnBeforeNavigation( - const browser: ICefBrowser; const frame: ICefFrame; - const request: ICefRequest; navigationType: TCefNavigationType; - isRedirect: Boolean): Boolean; +function TCefRenderProcessHandlerOwn.OnBeforeNavigation(const browser : ICefBrowser; + const frame : ICefFrame; + const request : ICefRequest; + navigationType : TCefNavigationType; + isRedirect : Boolean): Boolean; begin Result := False; end; -procedure TCefRenderProcessHandlerOwn.OnBrowserCreated( - const browser: ICefBrowser); -begin - -end; - -procedure TCefRenderProcessHandlerOwn.OnBrowserDestroyed( - const browser: ICefBrowser); -begin - -end; - -procedure TCefRenderProcessHandlerOwn.OnContextCreated( - const browser: ICefBrowser; const frame: ICefFrame; - const context: ICefv8Context); -begin - -end; - -procedure TCefRenderProcessHandlerOwn.OnContextReleased( - const browser: ICefBrowser; const frame: ICefFrame; - const context: ICefv8Context); -begin - -end; - -procedure TCefRenderProcessHandlerOwn.OnFocusedNodeChanged( - const browser: ICefBrowser; const frame: ICefFrame; const node: ICefDomNode); -begin - -end; - -function TCefRenderProcessHandlerOwn.OnProcessMessageReceived( - const browser: ICefBrowser; sourceProcess: TCefProcessId; - const message: ICefProcessMessage): Boolean; +function TCefRenderProcessHandlerOwn.OnProcessMessageReceived(const browser : ICefBrowser; + sourceProcess : TCefProcessId; + const aMessage : ICefProcessMessage): Boolean; begin Result := False; end; -procedure TCefRenderProcessHandlerOwn.OnRenderThreadCreated(const extraInfo: ICefListValue); -begin +// TCefCustomRenderProcessHandler + + +constructor TCefCustomRenderProcessHandler.Create(const aCefApp : TCefApplication); +begin + inherited Create; + + FCefApp := aCefApp; end; -procedure TCefRenderProcessHandlerOwn.OnUncaughtException( - const browser: ICefBrowser; const frame: ICefFrame; - const context: ICefv8Context; const exception: ICefV8Exception; - const stackTrace: ICefV8StackTrace); +destructor TCefCustomRenderProcessHandler.Destroy; begin + FCefApp := nil; + inherited Destroy; end; -procedure TCefRenderProcessHandlerOwn.OnWebKitInitialized; +procedure TCefCustomRenderProcessHandler.OnRenderThreadCreated(const extraInfo: ICefListValue); begin + if (FCefApp <> nil) then FCefApp.Internal_OnRenderThreadCreated(extraInfo); +end; +procedure TCefCustomRenderProcessHandler.OnWebKitInitialized; +begin + if (FCefApp <> nil) then FCefApp.Internal_OnWebKitInitialized; +end; + +procedure TCefCustomRenderProcessHandler.OnBrowserCreated(const browser: ICefBrowser); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnBrowserCreated(browser); +end; + +procedure TCefCustomRenderProcessHandler.OnBrowserDestroyed(const browser: ICefBrowser); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnBrowserDestroyed(browser); +end; + +function TCefCustomRenderProcessHandler.OnBeforeNavigation(const browser : ICefBrowser; + const frame : ICefFrame; + const request : ICefRequest; + navigationType : TCefNavigationType; + isRedirect : Boolean): Boolean; +begin + Result := inherited OnBeforeNavigation(browser, frame, request, navigationType, isRedirect); + + if (FCefApp <> nil) then FCefApp.Internal_OnBeforeNavigation(browser, frame, request, navigationType, isRedirect, Result); +end; + +procedure TCefCustomRenderProcessHandler.OnContextCreated(const browser : ICefBrowser; + const frame : ICefFrame; + const context : ICefv8Context); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnContextCreated(browser, frame, context); +end; + +procedure TCefCustomRenderProcessHandler.OnContextReleased(const browser : ICefBrowser; + const frame : ICefFrame; + const context : ICefv8Context); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnContextReleased(browser, frame, context); +end; + +procedure TCefCustomRenderProcessHandler.OnUncaughtException(const browser : ICefBrowser; + const frame : ICefFrame; + const context : ICefv8Context; + const exception : ICefV8Exception; + const stackTrace : ICefV8StackTrace); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnUncaughtException(browser, frame, context, exception, stackTrace); +end; + +procedure TCefCustomRenderProcessHandler.OnFocusedNodeChanged(const browser : ICefBrowser; + const frame : ICefFrame; + const node : ICefDomNode); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnFocusedNodeChanged(browser, frame, node); +end; + +function TCefCustomRenderProcessHandler.OnProcessMessageReceived(const browser : ICefBrowser; + sourceProcess : TCefProcessId; + const aMessage : ICefProcessMessage): Boolean; +begin + Result := inherited OnProcessMessageReceived(browser, sourceProcess, aMessage); + + if (FCefApp <> nil) then FCefApp.Internal_OnProcessMessageReceived(browser, sourceProcess, aMessage, Result); end; end. diff --git a/source/uCEFRequestContextHandler.pas b/source/uCEFRequestContextHandler.pas index 7cb649f6..8fcda561 100644 --- a/source/uCEFRequestContextHandler.pas +++ b/source/uCEFRequestContextHandler.pas @@ -117,7 +117,7 @@ end; constructor TCefRequestContextHandlerOwn.Create; begin - CreateData(SizeOf(TCefRequestContextHandler), False); + CreateData(SizeOf(TCefRequestContextHandler)); with PCefRequestContextHandler(FData)^ do begin diff --git a/source/uCEFResolveCallback.pas b/source/uCEFResolveCallback.pas index 92309e83..2dceb12d 100644 --- a/source/uCEFResolveCallback.pas +++ b/source/uCEFResolveCallback.pas @@ -114,7 +114,7 @@ end; constructor TCefResolveCallbackOwn.Create; begin - CreateData(SizeOf(TCefResolveCallback), False); + CreateData(SizeOf(TCefResolveCallback)); with PCefResolveCallback(FData)^ do on_resolve_completed := cef_resolve_callback_on_resolve_completed; diff --git a/source/uCEFResourceBundleHandler.pas b/source/uCEFResourceBundleHandler.pas index 9de8abe9..e2659f2a 100644 --- a/source/uCEFResourceBundleHandler.pas +++ b/source/uCEFResourceBundleHandler.pas @@ -47,7 +47,7 @@ unit uCEFResourceBundleHandler; interface uses - uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes; + uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFApplication; type TCefResourceBundleHandlerOwn = class(TCefBaseRefCountedOwn, ICefResourceBundleHandler) @@ -60,28 +60,57 @@ type constructor Create; virtual; end; + TCefCustomResourceBundleHandler = class(TCefResourceBundleHandlerOwn) + protected + FCefApp : TCefApplication; + + function GetLocalizedString(stringid: Integer; var stringVal: ustring): Boolean; override; + function GetDataResource(resourceId: Integer; var data: Pointer; var dataSize: NativeUInt): Boolean; override; + function GetDataResourceForScale(resourceId: Integer; scaleFactor: TCefScaleFactor; var data: Pointer; var dataSize: NativeUInt): Boolean; override; + + public + constructor Create(const aCefApp : TCefApplication); reintroduce; + destructor Destroy; override; + end; + implementation uses - uCEFMiscFunctions, uCEFLibFunctions; + uCEFMiscFunctions, uCEFLibFunctions, uCEFConstants; function cef_resource_bundle_handler_get_localized_string(self : PCefResourceBundleHandler; string_id : Integer; string_val : PCefString): Integer; stdcall; var - str: ustring; + TempString : ustring; + TempObject : TObject; begin - Result := Ord(TCefResourceBundleHandlerOwn(CefGetObject(self)).GetLocalizedString(string_id, str)); + TempObject := CefGetObject(self); - if (Result <> 0) then string_val^ := CefString(str); + if (TempObject <> nil) and (TempObject is TCefResourceBundleHandlerOwn) then + begin + TempString := ''; + Result := Ord(TCefResourceBundleHandlerOwn(TempObject).GetLocalizedString(string_id, TempString)); + + if (Result <> 0) then string_val^ := CefString(TempString); + end + else + Result := 0; end; function cef_resource_bundle_handler_get_data_resource(self : PCefResourceBundleHandler; resource_id : Integer; var data : Pointer; var data_size : NativeUInt): Integer; stdcall; +var + TempObject : TObject; begin - Result := Ord(TCefResourceBundleHandlerOwn(CefGetObject(self)).GetDataResource(resource_id, data, data_size)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefResourceBundleHandlerOwn) then + Result := Ord(TCefResourceBundleHandlerOwn(TempObject).GetDataResource(resource_id, data, data_size)) + else + Result := 0; end; function cef_resource_bundle_handler_get_data_resource_for_scale(self: PCefResourceBundleHandler; @@ -89,8 +118,15 @@ function cef_resource_bundle_handler_get_data_resource_for_scale(self: PCefResou scale_factor : TCefScaleFactor; var data : Pointer; var data_size : NativeUInt): Integer; stdcall; +var + TempObject : TObject; begin - Result := Ord(TCefResourceBundleHandlerOwn(CefGetObject(self)).GetDataResourceForScale(resource_id, scale_factor, data, data_size)); + TempObject := CefGetObject(self); + + if (TempObject <> nil) and (TempObject is TCefResourceBundleHandlerOwn) then + Result := Ord(TCefResourceBundleHandlerOwn(TempObject).GetDataResourceForScale(resource_id, scale_factor, data, data_size)) + else + Result := 0; end; constructor TCefResourceBundleHandlerOwn.Create; @@ -105,4 +141,52 @@ begin end; end; + +// TCefCustomResourceBundleHandler + + +constructor TCefCustomResourceBundleHandler.Create(const aCefApp : TCefApplication); +begin + inherited Create; + + FCefApp := aCefApp; +end; + +destructor TCefCustomResourceBundleHandler.Destroy; +begin + FCefApp := nil; + + inherited Destroy; +end; + +function TCefCustomResourceBundleHandler.GetLocalizedString(stringid : Integer; + var stringVal : ustring): Boolean; +begin + if (FCefApp <> nil) then + Result := FCefApp.Internal_GetLocalizedString(stringid, stringVal) + else + Result := False; +end; + +function TCefCustomResourceBundleHandler.GetDataResource(resourceId : Integer; + var data : Pointer; + var dataSize : NativeUInt): Boolean; +begin + if (FCefApp <> nil) then + Result := FCefApp.Internal_GetDataResource(resourceId, data, dataSize) + else + Result := False; +end; + +function TCefCustomResourceBundleHandler.GetDataResourceForScale(resourceId : Integer; + scaleFactor : TCefScaleFactor; + var data : Pointer; + var dataSize : NativeUInt): Boolean; +begin + if (FCefApp <> nil) then + Result := FCefApp.Internal_GetDataResourceForScale(resourceId, scaleFactor, data, dataSize) + else + Result := False; +end; + end. diff --git a/source/uCEFResponseFilter.pas b/source/uCEFResponseFilter.pas index 475122e6..a9ba3b0d 100644 --- a/source/uCEFResponseFilter.pas +++ b/source/uCEFResponseFilter.pas @@ -78,7 +78,7 @@ end; constructor TCefResponseFilterOwn.Create; begin - CreateData(SizeOf(TCefResponseFilter), False); + CreateData(SizeOf(TCefResponseFilter)); with PCefResponseFilter(FData)^ do begin init_filter := cef_response_filter_init_filter; diff --git a/source/uCEFTypes.pas b/source/uCEFTypes.pas index fb01b643..316ae360 100644 --- a/source/uCEFTypes.pas +++ b/source/uCEFTypes.pas @@ -1542,7 +1542,7 @@ type on_context_released: procedure(self: PCefRenderProcessHandler; browser: PCefBrowser; frame: PCefFrame; context: PCefv8Context); stdcall; on_uncaught_exception: procedure(self: PCefRenderProcessHandler; browser: PCefBrowser; frame: PCefFrame; context: PCefv8Context; exception: PCefV8Exception; stackTrace: PCefV8StackTrace); stdcall; on_focused_node_changed: procedure(self: PCefRenderProcessHandler; browser: PCefBrowser; frame: PCefFrame; node: PCefDomNode); stdcall; - on_process_message_received: function(self: PCefRenderProcessHandler; browser: PCefBrowser; source_process: TCefProcessId; message: PCefProcessMessage): Integer; stdcall; + on_process_message_received: function(self: PCefRenderProcessHandler; browser: PCefBrowser; source_process: TCefProcessId; message_: PCefProcessMessage): Integer; stdcall; end; // /include/capi/cef_request_handler_capi.h (cef_request_handler_t)