diff --git a/demos/CookieVisitor/uCookieVisitor.pas b/demos/CookieVisitor/uCookieVisitor.pas index 92723028..e0211cba 100644 --- a/demos/CookieVisitor/uCookieVisitor.pas +++ b/demos/CookieVisitor/uCookieVisitor.pas @@ -141,7 +141,9 @@ begin if (count = pred(total)) then begin - PostMessage(CookieVisitorFrm.Handle, MINIBROWSER_SHOWCOOKIES, 0, 0); + if (CookieVisitorFrm <> nil) and CookieVisitorFrm.HandleAllocated then + PostMessage(CookieVisitorFrm.Handle, MINIBROWSER_SHOWCOOKIES, 0, 0); + Result := False; end else diff --git a/demos/DOMVisitor/uDOMVisitor.pas b/demos/DOMVisitor/uDOMVisitor.pas index 7243d3d9..41127d00 100644 --- a/demos/DOMVisitor/uDOMVisitor.pas +++ b/demos/DOMVisitor/uDOMVisitor.pas @@ -121,7 +121,7 @@ uses // To send a message from the browser process you must use the TChromium.SendProcessMessage // procedure with a PID_RENDERER parameter. The render process receives those messages in -// the GlobalCEFApp.OnProcessMessageReceived event +// the GlobalCEFApp.OnProcessMessageReceived event. // To send messages from the render process you must use the browser.SendProcessMessage // procedure with a PID_BROWSER parameter. The browser process receives those messages in diff --git a/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.fmx b/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.fmx index 1c00d950..97635e70 100644 --- a/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.fmx +++ b/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.fmx @@ -105,6 +105,7 @@ object FMXExternalPumpBrowserFrm: TFMXExternalPumpBrowserFrm Top = 201 end object chrmosr: TFMXChromium + OnTooltip = chrmosrTooltip OnAfterCreated = chrmosrAfterCreated OnBeforeClose = chrmosrBeforeClose OnClose = chrmosrClose diff --git a/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.pas b/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.pas index 37537a76..7700c5a9 100644 --- a/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.pas +++ b/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.pas @@ -102,6 +102,8 @@ type procedure AddressEdtEnter(Sender: TObject); procedure SnapshotBtnClick(Sender: TObject); procedure SnapshotBtnEnter(Sender: TObject); + procedure chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; + var text: ustring; out Result: Boolean); protected FPopUpBitmap : TBitmap; @@ -693,6 +695,13 @@ begin end; end; +procedure TFMXExternalPumpBrowserFrm.chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; var text: ustring; out Result: Boolean); +begin + Panel1.Hint := text; + Panel1.ShowHint := (length(text) > 0); + Result := True; +end; + procedure TFMXExternalPumpBrowserFrm.DoResize; begin try diff --git a/demos/JavaScript/JSRTTIExtension/00-DeleteDCUs.bat b/demos/JavaScript/JSRTTIExtension/00-DeleteDCUs.bat new file mode 100644 index 00000000..dbd008bc --- /dev/null +++ b/demos/JavaScript/JSRTTIExtension/00-DeleteDCUs.bat @@ -0,0 +1,14 @@ +del /s /q *.dcu +del /s /q *.exe +del /s /q *.res +del /s /q *.log +del /s /q *.dsk +del /s /q *.identcache +del /s /q *.stat +del /s /q *.local +del /s /q *.~* +rmdir Win32\Debug +rmdir Win32\Release +rmdir Win32 +rmdir __history +rmdir __recovery diff --git a/demos/JavaScript/JSRTTIExtension/JSRTTIExtension.dpr b/demos/JavaScript/JSRTTIExtension/JSRTTIExtension.dpr new file mode 100644 index 00000000..c53b4ec8 --- /dev/null +++ b/demos/JavaScript/JSRTTIExtension/JSRTTIExtension.dpr @@ -0,0 +1,77 @@ +// ************************************************************************ +// ***************************** 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. + * + *) + +program JSRTTIExtension; + +{$I cef.inc} + +uses + {$IFDEF DELPHI16_UP} + Vcl.Forms, + WinApi.Windows, + {$ELSE} + Forms, + Windows, + {$ENDIF } + uCEFApplication, + uJSRTTIExtension in 'uJSRTTIExtension.pas' {JSRTTIExtensionFrm}, + uTestExtension in 'uTestExtension.pas', + uSimpleTextViewer in 'uSimpleTextViewer.pas' {SimpleTextViewerFrm}; + +{$R *.res} + +// 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} + +begin + GlobalCEFApp := TCefApplication.Create; + GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitialized; + + + if GlobalCEFApp.StartMainProcess then + begin + Application.Initialize; + {$IFDEF DELPHI11_UP} + Application.MainFormOnTaskbar := True; + {$ENDIF} + Application.CreateForm(TJSRTTIExtensionFrm, JSRTTIExtensionFrm); + Application.CreateForm(TSimpleTextViewerFrm, SimpleTextViewerFrm); + Application.Run; + end; + + GlobalCEFApp.Free; +end. diff --git a/demos/JavaScript/JSRTTIExtension/JSRTTIExtension.dproj b/demos/JavaScript/JSRTTIExtension/JSRTTIExtension.dproj new file mode 100644 index 00000000..4d036284 --- /dev/null +++ b/demos/JavaScript/JSRTTIExtension/JSRTTIExtension.dproj @@ -0,0 +1,575 @@ + + + {7AA32B92-A408-42CB-A571-383721053FFA} + 18.2 + VCL + JSRTTIExtension.dpr + True + Debug + Win32 + 1 + Application + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + 3082 + $(BDS)\bin\delphi_PROJECTICON.ico + JSRTTIExtension + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + .\$(Platform)\$(Config) + false + false + false + false + false + + + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + DBXSqliteDriver;RESTComponents;DataSnapServerMidas;DBXDb2Driver;DBXInterBaseDriver;vclactnband;frxe23;vclFireDAC;emsclientfiredac;DataSnapFireDAC;svnui;tethering;FireDACADSDriver;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;svn;Intraweb;DBXOracleDriver;inetdb;CEF4Delphi;FmxTeeUI;FireDACIBDriver;fmx;fmxdae;vclib;FireDACDBXDriver;dbexpress;IndyProtocols230;vclx;dsnap;DataSnapCommon;emsclient;FireDACCommon;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;frxTee23;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;CloudService;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonDriver;DataSnapClient;inet;bindcompdbx;vcl;DBXSybaseASEDriver;FireDACDb2Driver;GR32_DSGN_RSXE5;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;FireDAC;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;soaprtl;DbxCommonDriver;ibxpress;Tee;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;GR32_RSXE5;bindcomp;appanalytics;DBXInformixDriver;bindcompvcl;frxDB23;TeeUI;IndyCore230;vclribbon;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;IndySystem230;dsnapxml;DataSnapProviderClient;dbrtl;inetdbxpress;FireDACMongoDBDriver;frx23;fmxase;$(DCC_UsePackage) + 1033 + $(BDS)\bin\default_app.manifest + 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 + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + ..\..\..\bin + + + DBXSqliteDriver;RESTComponents;DataSnapServerMidas;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;emsclientfiredac;DataSnapFireDAC;tethering;FireDACADSDriver;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;Intraweb;DBXOracleDriver;inetdb;FmxTeeUI;FireDACIBDriver;fmx;fmxdae;vclib;FireDACDBXDriver;dbexpress;IndyProtocols230;vclx;dsnap;DataSnapCommon;emsclient;FireDACCommon;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;CloudService;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonDriver;DataSnapClient;inet;bindcompdbx;vcl;DBXSybaseASEDriver;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;FireDAC;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;soaprtl;DbxCommonDriver;ibxpress;Tee;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;bindcomp;appanalytics;DBXInformixDriver;bindcompvcl;TeeUI;IndyCore230;vclribbon;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;IndySystem230;dsnapxml;DataSnapProviderClient;dbrtl;inetdbxpress;FireDACMongoDBDriver;fmxase;$(DCC_UsePackage) + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + + + DEBUG;$(DCC_Define) + true + false + true + true + true + + + true + true + 1033 + true + false + Debug + CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName) + + + false + RELEASE;$(DCC_Define) + 0 + 0 + + + true + true + + + + MainSource + + +
JSRTTIExtensionFrm
+
+ + +
SimpleTextViewerFrm
+
+ + Cfg_2 + Base + + + Base + + + Cfg_1 + Base + +
+ + Delphi.Personality.12 + Application + + + + JSRTTIExtension.dpr + + + IP Abstraction Indy Implementation Design Time + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + + + + + + JSRTTIExtension.exe + true + + + + + + 1 + + + Contents\MacOS + 1 + + + Contents\MacOS + 0 + + + + + classes + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\armeabi + 1 + + + + + library\lib\mips + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + res\drawable + 1 + + + + + res\values + 1 + + + + + res\drawable + 1 + + + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-ldpi + 1 + + + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + + + res\drawable-small + 1 + + + + + res\drawable-normal + 1 + + + + + res\drawable-large + 1 + + + + + res\drawable-xlarge + 1 + + + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + Contents\MacOS + 1 + .framework + + + 0 + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .dll;.bpl + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .bpl + + + + + 0 + + + 0 + + + 0 + + + 0 + + + Contents\Resources\StartUp\ + 0 + + + 0 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + 1 + + + 1 + + + + + ..\ + 1 + + + ..\ + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\ + 1 + + + + + Contents + 1 + + + + + Contents\Resources + 1 + + + + + library\lib\armeabi-v7a + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + 1 + + + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + + + + + + + + + True + False + + + 12 + + + + +
diff --git a/demos/JavaScript/JSRTTIExtension/cef.inc b/demos/JavaScript/JSRTTIExtension/cef.inc new file mode 100644 index 00000000..984ae795 --- /dev/null +++ b/demos/JavaScript/JSRTTIExtension/cef.inc @@ -0,0 +1,384 @@ +// ************************************************************************ +// ***************************** 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. + * + *) + + // The complete list of compiler versions is here : + // http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Compiler_Versions + +{$DEFINE DELPHI_VERSION_UNKNOW} + +{$IFDEF FPC} + {$DEFINE CEF_MULTI_THREADED_MESSAGE_LOOP} + {$DEFINE SUPPORTS_INLINE} +{$ENDIF} + +// Delphi 5 +{$IFDEF VER130} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} +{$ENDIF} + +// Delphi 6 +{$IFDEF VER140} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} +{$ENDIF} + +// Delphi 7 +{$IFDEF VER150} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} +{$ENDIF} + +// Delphi 8 +{$IFDEF VER160} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} +{$ENDIF} + +// Delphi 2005 +{$IFDEF VER170} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} +{$ENDIF} + +{$IFDEF VER180} + {$UNDEF DELPHI_VERSION_UNKNOW} + // Delphi 2007 + {$IFDEF VER185} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + // Delphi 2006 + {$ELSE} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$ENDIF} +{$ENDIF} + +// Delphi 2009 +{$IFDEF VER200} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} +{$ENDIF} + +//Delphi 2010 +{$IFDEF VER210} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} +{$ENDIF} + +// Delphi XE +{$IFDEF VER220} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} +{$ENDIF} + +// Delphi XE2 +{$IFDEF VER230} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} +{$ENDIF} + +// Delphi XE3 +{$IFDEF VER240} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} +{$ENDIF} + +// Delphi XE4 +{$IFDEF VER250} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} +{$ENDIF} + +// Delphi XE5 +{$IFDEF VER260} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} +{$ENDIF} + +// Delphi XE6 +{$IFDEF VER270} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} +{$ENDIF} + +// Delphi XE7 +{$IFDEF VER280} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} +{$ENDIF} + +// Delphi XE8 +{$IFDEF VER290} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} + {$DEFINE DELPHI22_UP} +{$ENDIF VER290} + +// Rad Studio 10 - Delphi Seattle +{$IFDEF VER300} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} + {$DEFINE DELPHI22_UP} + {$DEFINE DELPHI23_UP} +{$ENDIF} + +// Rad Studio 10.1 - Delphi Berlin +{$IFDEF VER310} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} + {$DEFINE DELPHI22_UP} + {$DEFINE DELPHI23_UP} + {$DEFINE DELPHI24_UP} +{$ENDIF} + +// Rad Studio 10.2 - Delphi Tokyo +{$IFDEF VER320} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} + {$DEFINE DELPHI22_UP} + {$DEFINE DELPHI23_UP} + {$DEFINE DELPHI24_UP} + {$DEFINE DELPHI25_UP} +{$ENDIF} + + +{$IFDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} + {$DEFINE DELPHI22_UP} + {$DEFINE DELPHI23_UP} + {$DEFINE DELPHI24_UP} + {$DEFINE DELPHI25_UP} +{$ENDIF} + +{$IFDEF DELPHI9_UP} + {$DEFINE SUPPORTS_INLINE} +{$ENDIF} + diff --git a/demos/JavaScript/JSRTTIExtension/uJSRTTIExtension.dfm b/demos/JavaScript/JSRTTIExtension/uJSRTTIExtension.dfm new file mode 100644 index 00000000..66dd40fb --- /dev/null +++ b/demos/JavaScript/JSRTTIExtension/uJSRTTIExtension.dfm @@ -0,0 +1,88 @@ +object JSRTTIExtensionFrm: TJSRTTIExtensionFrm + Left = 0 + Top = 0 + Caption = 'JSRTTIExtension' + ClientHeight = 589 + ClientWidth = 978 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + OldCreateOrder = False + Position = poScreenCenter + OnShow = FormShow + PixelsPerInch = 96 + TextHeight = 13 + object NavControlPnl: TPanel + Left = 0 + Top = 0 + Width = 978 + Height = 30 + Align = alTop + BevelOuter = bvNone + Enabled = False + Padding.Left = 5 + Padding.Top = 5 + Padding.Right = 5 + Padding.Bottom = 5 + ShowCaption = False + TabOrder = 0 + object Edit1: TEdit + Left = 5 + Top = 5 + Width = 937 + Height = 20 + Margins.Right = 5 + Align = alClient + TabOrder = 0 + Text = 'http://www.google.com' + ExplicitHeight = 21 + end + object GoBtn: TButton + Left = 942 + Top = 5 + Width = 31 + Height = 20 + Margins.Left = 5 + Align = alRight + Caption = 'Go' + TabOrder = 1 + OnClick = GoBtnClick + end + end + object StatusBar1: TStatusBar + Left = 0 + Top = 570 + Width = 978 + Height = 19 + Panels = < + item + Width = 50 + end> + end + object CEFWindowParent1: TCEFWindowParent + Left = 0 + Top = 30 + Width = 978 + Height = 540 + Align = alClient + TabOrder = 2 + end + object Chromium1: TChromium + OnProcessMessageReceived = Chromium1ProcessMessageReceived + OnBeforeContextMenu = Chromium1BeforeContextMenu + OnContextMenuCommand = Chromium1ContextMenuCommand + OnAfterCreated = Chromium1AfterCreated + Left = 32 + Top = 224 + end + object Timer1: TTimer + Enabled = False + Interval = 300 + OnTimer = Timer1Timer + Left = 32 + Top = 288 + end +end diff --git a/demos/JavaScript/JSRTTIExtension/uJSRTTIExtension.pas b/demos/JavaScript/JSRTTIExtension/uJSRTTIExtension.pas new file mode 100644 index 00000000..69ba273a --- /dev/null +++ b/demos/JavaScript/JSRTTIExtension/uJSRTTIExtension.pas @@ -0,0 +1,263 @@ +// ************************************************************************ +// ***************************** 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 uJSRTTIExtension; + +{$I cef.inc} + +interface + +uses + {$IFDEF DELPHI16_UP} + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ComCtrls, + {$ELSE} + Windows, Messages, SysUtils, Variants, Classes, Graphics, + Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, + {$ENDIF} + uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFApplication, uCEFTypes, uCEFConstants; + +const + MINIBROWSER_SHOWTEXTVIEWER = WM_APP + $100; + + MINIBROWSER_CONTEXTMENU_SETJSEVENT = MENU_ID_USER_FIRST + 1; + MINIBROWSER_CONTEXTMENU_JSVISITDOM = MENU_ID_USER_FIRST + 2; + + MOUSEOVER_MESSAGE_NAME = 'mouseover'; + CUSTOMNAME_MESSAGE_NAME = 'customname'; + +type + TJSRTTIExtensionFrm = class(TForm) + NavControlPnl: TPanel; + Edit1: TEdit; + GoBtn: TButton; + StatusBar1: TStatusBar; + CEFWindowParent1: TCEFWindowParent; + Chromium1: TChromium; + Timer1: TTimer; + procedure FormShow(Sender: TObject); + procedure GoBtnClick(Sender: TObject); + procedure Chromium1BeforeContextMenu(Sender: TObject; + const browser: ICefBrowser; const frame: ICefFrame; + const params: ICefContextMenuParams; const model: ICefMenuModel); + procedure Chromium1ContextMenuCommand(Sender: TObject; + const browser: ICefBrowser; const frame: ICefFrame; + const params: ICefContextMenuParams; commandId: Integer; + eventFlags: Cardinal; out Result: Boolean); + procedure Chromium1ProcessMessageReceived(Sender: TObject; + const browser: ICefBrowser; sourceProcess: TCefProcessId; + const message: ICefProcessMessage; out Result: Boolean); + procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser); + procedure Timer1Timer(Sender: TObject); + protected + FText : string; + + procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED; + procedure ShowTextViewerMsg(var aMessage : TMessage); message MINIBROWSER_SHOWTEXTVIEWER; + procedure WMMove(var aMessage : TWMMove); message WM_MOVE; + procedure WMMoving(var aMessage : TMessage); message WM_MOVING; + public + { Public declarations } + end; + +var + JSRTTIExtensionFrm: TJSRTTIExtensionFrm; + +procedure GlobalCEFApp_OnWebKitInitialized; + +implementation + +{$R *.dfm} + +uses + uSimpleTextViewer, uCEFv8Handler, uTestExtension, uCEFMiscFunctions; + +// The CEF3 document describing extensions is here : +// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md + +// This demo has a TTestExtension class that is registered in the +// GlobalCEFApp.OnWebKitInitialized event when the application is initializing. + +// TTestExtension can send information back to the browser with a process message. +// The TTestExtension.mouseover function do this by calling +// TCefv8ContextRef.Current.Browser.SendProcessMessage(PID_BROWSER, msg); + +// TCefv8ContextRef.Current returns the v8 context for the frame that is currently executing JS, +// TCefv8ContextRef.Current.Browser.SendProcessMessage should send a message to the right browser even +// if you have created several browsers in one app. + +// That message is received in the TChromium.OnProcessMessageReceived event. +// 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; +begin +{$IFDEF DELPHI14_UP} + // Registering the extension. Read this document for more details : + // https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md + TCefRTTIExtension.Register('myextension', TTestExtension); +{$ENDIF} +end; + +procedure TJSRTTIExtensionFrm.GoBtnClick(Sender: TObject); +begin + Chromium1.LoadURL(Edit1.Text); +end; + +procedure TJSRTTIExtensionFrm.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser); +begin + PostMessage(Handle, CEF_AFTERCREATED, 0, 0); +end; + +procedure TJSRTTIExtensionFrm.Chromium1BeforeContextMenu(Sender: TObject; + const browser: ICefBrowser; const frame: ICefFrame; + const params: ICefContextMenuParams; const model: ICefMenuModel); +begin + // Adding some custom context menu entries + model.AddSeparator; + model.AddItem(MINIBROWSER_CONTEXTMENU_SETJSEVENT, 'Set mouseover event'); + model.AddItem(MINIBROWSER_CONTEXTMENU_JSVISITDOM, 'Visit DOM in JavaScript'); +end; + +procedure TJSRTTIExtensionFrm.Chromium1ContextMenuCommand(Sender: TObject; + const browser: ICefBrowser; const frame: ICefFrame; + const params: ICefContextMenuParams; commandId: Integer; + eventFlags: Cardinal; out Result: Boolean); +begin + Result := False; + + // Here is the code executed for each custom context menu entry + + case commandId of + MINIBROWSER_CONTEXTMENU_SETJSEVENT : + if (browser <> nil) and (browser.MainFrame <> nil) then + browser.MainFrame.ExecuteJavaScript( + 'document.body.addEventListener("mouseover", function(evt){'+ + 'function getpath(n){'+ + 'var ret = "<" + n.nodeName + ">";'+ + 'if (n.parentNode){return getpath(n.parentNode) + ret} else '+ + 'return ret'+ + '};'+ + 'myextension.mouseover(getpath(evt.target))}'+ // This is the call from JavaScript to the extension with DELPHI code in uTestExtension.pas + ')', 'about:blank', 0); + + MINIBROWSER_CONTEXTMENU_JSVISITDOM : + if (browser <> nil) and (browser.MainFrame <> nil) then + browser.MainFrame.ExecuteJavaScript( + 'var testhtml = document.body.innerHTML;' + + 'myextension.sendresulttobrowser(testhtml, ' + quotedstr(CUSTOMNAME_MESSAGE_NAME) + ');', // This is the call from JavaScript to the extension with DELPHI code in uTestExtension.pas + 'about:blank', 0); + end; +end; + +procedure TJSRTTIExtensionFrm.Chromium1ProcessMessageReceived(Sender: TObject; + const browser: ICefBrowser; sourceProcess: TCefProcessId; + const message: ICefProcessMessage; out Result: Boolean); +begin + Result := False; + + if (message = nil) or (message.ArgumentList = nil) then exit; + + // This function receives the messages with the JavaScript results + + // Many of these events are received in different threads and the VCL + // doesn't like to create and destroy components in different threads. + + // It's safer to store the results and send a message to the main thread to show them. + + // The message names are defined in the extension or in JS code. + + if (message.Name = MOUSEOVER_MESSAGE_NAME) then + begin + StatusBar1.Panels[0].Text := message.ArgumentList.GetString(0); // this doesn't create/destroy components + Result := True; + end + else + if (message.Name = CUSTOMNAME_MESSAGE_NAME) then + begin + FText := message.ArgumentList.GetString(0); + PostMessage(Handle, MINIBROWSER_SHOWTEXTVIEWER, 0, 0); + Result := True; + end; +end; + +procedure TJSRTTIExtensionFrm.FormShow(Sender: TObject); +begin + StatusBar1.Panels[0].Text := 'Initializing browser. Please wait...'; + + // GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser + // If it's not initialized yet, we use a simple timer to create the browser later. + if not(Chromium1.CreateBrowser(CEFWindowParent1, '')) then Timer1.Enabled := True; +end; + +procedure TJSRTTIExtensionFrm.WMMove(var aMessage : TWMMove); +begin + inherited; + + if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted; +end; + +procedure TJSRTTIExtensionFrm.WMMoving(var aMessage : TMessage); +begin + inherited; + + if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted; +end; + +procedure TJSRTTIExtensionFrm.ShowTextViewerMsg(var aMessage : TMessage); +begin + // This form will show the HTML received from JavaScript + SimpleTextViewerFrm.Memo1.Lines.Text := FText; + SimpleTextViewerFrm.ShowModal; +end; + +procedure TJSRTTIExtensionFrm.Timer1Timer(Sender: TObject); +begin + Timer1.Enabled := False; + if not(Chromium1.CreateBrowser(CEFWindowParent1, '')) and not(Chromium1.Initialized) then + Timer1.Enabled := True; +end; + +procedure TJSRTTIExtensionFrm.BrowserCreatedMsg(var aMessage : TMessage); +begin + StatusBar1.Panels[0].Text := ''; + CEFWindowParent1.UpdateSize; + NavControlPnl.Enabled := True; + GoBtn.Click; +end; + +end. diff --git a/demos/JavaScript/JSRTTIExtension/uSimpleTextViewer.dfm b/demos/JavaScript/JSRTTIExtension/uSimpleTextViewer.dfm new file mode 100644 index 00000000..50ff2fe7 --- /dev/null +++ b/demos/JavaScript/JSRTTIExtension/uSimpleTextViewer.dfm @@ -0,0 +1,29 @@ +object SimpleTextViewerFrm: TSimpleTextViewerFrm + Left = 0 + Top = 0 + BorderIcons = [biSystemMenu] + BorderStyle = bsSingle + Caption = 'Simple text viewer' + ClientHeight = 572 + ClientWidth = 694 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + OldCreateOrder = False + Position = poScreenCenter + PixelsPerInch = 96 + TextHeight = 13 + object Memo1: TMemo + Left = 0 + Top = 0 + Width = 694 + Height = 572 + Align = alClient + ReadOnly = True + ScrollBars = ssBoth + TabOrder = 0 + end +end diff --git a/demos/JavaScript/JSRTTIExtension/uSimpleTextViewer.pas b/demos/JavaScript/JSRTTIExtension/uSimpleTextViewer.pas new file mode 100644 index 00000000..35ff5c5e --- /dev/null +++ b/demos/JavaScript/JSRTTIExtension/uSimpleTextViewer.pas @@ -0,0 +1,31 @@ +unit uSimpleTextViewer; + +interface + +uses + {$IFDEF DELPHI16_UP} + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; + {$ELSE} + Windows, Messages, SysUtils, Variants, Classes, Graphics, + Controls, Forms, Dialogs, StdCtrls; + {$ENDIF} + + +type + TSimpleTextViewerFrm = class(TForm) + Memo1: TMemo; + private + { Private declarations } + public + { Public declarations } + end; + +var + SimpleTextViewerFrm: TSimpleTextViewerFrm; + +implementation + +{$R *.dfm} + +end. diff --git a/demos/JavaScript/JSRTTIExtension/uTestExtension.pas b/demos/JavaScript/JSRTTIExtension/uTestExtension.pas new file mode 100644 index 00000000..3242aba2 --- /dev/null +++ b/demos/JavaScript/JSRTTIExtension/uTestExtension.pas @@ -0,0 +1,86 @@ +// ************************************************************************ +// ***************************** 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 uTestExtension; + +{$I cef.inc} + +interface + +uses + {$IFDEF DELPHI16_UP} + Winapi.Windows, + {$ELSE} + Windows, + {$ENDIF} + uCEFRenderProcessHandler, uCEFBrowserProcessHandler, uCEFInterfaces, uCEFProcessMessage, + uCEFv8Context, uCEFTypes, uCEFv8Handler; + +type + TTestExtension = class + class procedure mouseover(const data: string); + class procedure sendresulttobrowser(const msgtext, msgname : string); + end; + +implementation + +uses + uCEFMiscFunctions, uCEFConstants, uJSRTTIExtension; + +class procedure TTestExtension.mouseover(const data: string); +var + msg: ICefProcessMessage; +begin + msg := TCefProcessMessageRef.New(MOUSEOVER_MESSAGE_NAME); + msg.ArgumentList.SetString(0, data); + + // Sending a message back to the browser. It'll be received in the TChromium.OnProcessMessageReceived event. + // TCefv8ContextRef.Current returns the v8 context for the frame that is currently executing Javascript. + TCefv8ContextRef.Current.Browser.SendProcessMessage(PID_BROWSER, msg); +end; + +class procedure TTestExtension.sendresulttobrowser(const msgtext, msgname : string); +var + msg: ICefProcessMessage; +begin + msg := TCefProcessMessageRef.New(msgname); + msg.ArgumentList.SetString(0, msgtext); + + TCefv8ContextRef.Current.Browser.SendProcessMessage(PID_BROWSER, msg); +end; + +end. diff --git a/demos/ResponseFilterBrowser/00-DeleteDCUs.bat b/demos/ResponseFilterBrowser/00-DeleteDCUs.bat new file mode 100644 index 00000000..dbd008bc --- /dev/null +++ b/demos/ResponseFilterBrowser/00-DeleteDCUs.bat @@ -0,0 +1,14 @@ +del /s /q *.dcu +del /s /q *.exe +del /s /q *.res +del /s /q *.log +del /s /q *.dsk +del /s /q *.identcache +del /s /q *.stat +del /s /q *.local +del /s /q *.~* +rmdir Win32\Debug +rmdir Win32\Release +rmdir Win32 +rmdir __history +rmdir __recovery diff --git a/demos/ResponseFilterBrowser/ResponseFilterBrowser.dpr b/demos/ResponseFilterBrowser/ResponseFilterBrowser.dpr new file mode 100644 index 00000000..0002ded9 --- /dev/null +++ b/demos/ResponseFilterBrowser/ResponseFilterBrowser.dpr @@ -0,0 +1,72 @@ +// ************************************************************************ +// ***************************** 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 © 2018 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. + * + *) + +program ResponseFilterBrowser; + +{$I cef.inc} + +uses + {$IFDEF DELPHI16_UP} + Vcl.Forms, + WinApi.Windows, + {$ELSE} + Forms, + Windows, + {$ENDIF } + uCEFApplication, + uResopnseFilterBrowser in 'uResopnseFilterBrowser.pas' {ResponseFilterBrowserFrm}; + +{$R *.res} + +// 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} + +begin + GlobalCEFApp := TCefApplication.Create; + + if GlobalCEFApp.StartMainProcess then + begin + Application.Initialize; + {$IFDEF DELPHI11_UP} + Application.MainFormOnTaskbar := True; + {$ENDIF} + Application.CreateForm(TResponseFilterBrowserFrm, ResponseFilterBrowserFrm); + Application.Run; + end; + + GlobalCEFApp.Free; +end. diff --git a/demos/ResponseFilterBrowser/ResponseFilterBrowser.dproj b/demos/ResponseFilterBrowser/ResponseFilterBrowser.dproj new file mode 100644 index 00000000..4c185083 --- /dev/null +++ b/demos/ResponseFilterBrowser/ResponseFilterBrowser.dproj @@ -0,0 +1,597 @@ + + + {55E00327-9D98-4DA3-A4E1-844942A01C6B} + 18.2 + VCL + ResponseFilterBrowser.dpr + True + Debug + Win32 + 1 + Application + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + true + Cfg_2 + true + true + + + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + 3082 + ResponseFilterBrowser + $(BDS)\bin\delphi_PROJECTICON.ico + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + .\$(Platform)\$(Config) + false + false + false + false + false + + + DBXSqliteDriver;RESTComponents;DataSnapServerMidas;DBXDb2Driver;DBXInterBaseDriver;vclactnband;frxe23;vclFireDAC;emsclientfiredac;DataSnapFireDAC;svnui;tethering;Componentes;FireDACADSDriver;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;svn;Intraweb;DBXOracleDriver;inetdb;Componentes_Int;CEF4Delphi;FmxTeeUI;FireDACIBDriver;fmx;fmxdae;vclib;FireDACDBXDriver;dbexpress;IndyProtocols230;vclx;dsnap;DataSnapCommon;emsclient;FireDACCommon;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;frxTee23;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;CloudService;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonDriver;DataSnapClient;inet;bindcompdbx;vcl;DBXSybaseASEDriver;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;Componentes_UI;TeeDB;FireDAC;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;soaprtl;DbxCommonDriver;Componentes_Misc;ibxpress;Tee;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;bindcomp;appanalytics;Componentes_RTF;DBXInformixDriver;bindcompvcl;frxDB23;Componentes_vCard;TeeUI;IndyCore230;vclribbon;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;IndySystem230;dsnapxml;DataSnapProviderClient;dbrtl;inetdbxpress;FireDACMongoDBDriver;frx23;fmxase;$(DCC_UsePackage) + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + true + $(BDS)\bin\default_app.manifest + 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) + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + ..\..\bin + + + DBXSqliteDriver;RESTComponents;DataSnapServerMidas;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;emsclientfiredac;DataSnapFireDAC;tethering;FireDACADSDriver;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;Intraweb;DBXOracleDriver;inetdb;FmxTeeUI;FireDACIBDriver;fmx;fmxdae;vclib;FireDACDBXDriver;dbexpress;IndyProtocols230;vclx;dsnap;DataSnapCommon;emsclient;FireDACCommon;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;CloudService;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonDriver;DataSnapClient;inet;bindcompdbx;vcl;DBXSybaseASEDriver;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;FireDAC;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;soaprtl;DbxCommonDriver;ibxpress;Tee;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;bindcomp;appanalytics;DBXInformixDriver;bindcompvcl;TeeUI;IndyCore230;vclribbon;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;IndySystem230;dsnapxml;DataSnapProviderClient;dbrtl;inetdbxpress;FireDACMongoDBDriver;fmxase;$(DCC_UsePackage) + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace) + Debug + true + CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= + 1033 + $(BDS)\bin\default_app.manifest + + + DEBUG;$(DCC_Define) + true + false + true + true + true + + + true + 1033 + true + true + false + Debug + 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 + + + false + RELEASE;$(DCC_Define) + 0 + 0 + + + true + true + + + true + true + + + + MainSource + + +
ResponseFilterBrowserFrm
+
+ + Cfg_2 + Base + + + Base + + + Cfg_1 + Base + +
+ + Delphi.Personality.12 + Application + + + + ResponseFilterBrowser.dpr + + + IP Abstraction Indy Implementation Design Time + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + + + + + + + ResponseFilterBrowser.exe + true + + + + + 1 + + + Contents\MacOS + 1 + + + Contents\MacOS + 0 + + + + + classes + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\armeabi + 1 + + + + + library\lib\mips + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + res\drawable + 1 + + + + + res\values + 1 + + + + + res\drawable + 1 + + + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-ldpi + 1 + + + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + + + res\drawable-small + 1 + + + + + res\drawable-normal + 1 + + + + + res\drawable-large + 1 + + + + + res\drawable-xlarge + 1 + + + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + Contents\MacOS + 1 + .framework + + + 0 + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .dll;.bpl + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .bpl + + + + + 0 + + + 0 + + + 0 + + + 0 + + + Contents\Resources\StartUp\ + 0 + + + 0 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + 1 + + + 1 + + + + + ..\ + 1 + + + ..\ + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\ + 1 + + + + + Contents + 1 + + + + + Contents\Resources + 1 + + + + + library\lib\armeabi-v7a + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + 1 + + + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + + + + + + + + + True + False + + + 12 + + + + +
diff --git a/demos/ResponseFilterBrowser/cef.inc b/demos/ResponseFilterBrowser/cef.inc new file mode 100644 index 00000000..984ae795 --- /dev/null +++ b/demos/ResponseFilterBrowser/cef.inc @@ -0,0 +1,384 @@ +// ************************************************************************ +// ***************************** 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. + * + *) + + // The complete list of compiler versions is here : + // http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Compiler_Versions + +{$DEFINE DELPHI_VERSION_UNKNOW} + +{$IFDEF FPC} + {$DEFINE CEF_MULTI_THREADED_MESSAGE_LOOP} + {$DEFINE SUPPORTS_INLINE} +{$ENDIF} + +// Delphi 5 +{$IFDEF VER130} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} +{$ENDIF} + +// Delphi 6 +{$IFDEF VER140} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} +{$ENDIF} + +// Delphi 7 +{$IFDEF VER150} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} +{$ENDIF} + +// Delphi 8 +{$IFDEF VER160} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} +{$ENDIF} + +// Delphi 2005 +{$IFDEF VER170} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} +{$ENDIF} + +{$IFDEF VER180} + {$UNDEF DELPHI_VERSION_UNKNOW} + // Delphi 2007 + {$IFDEF VER185} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + // Delphi 2006 + {$ELSE} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$ENDIF} +{$ENDIF} + +// Delphi 2009 +{$IFDEF VER200} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} +{$ENDIF} + +//Delphi 2010 +{$IFDEF VER210} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} +{$ENDIF} + +// Delphi XE +{$IFDEF VER220} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} +{$ENDIF} + +// Delphi XE2 +{$IFDEF VER230} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} +{$ENDIF} + +// Delphi XE3 +{$IFDEF VER240} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} +{$ENDIF} + +// Delphi XE4 +{$IFDEF VER250} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} +{$ENDIF} + +// Delphi XE5 +{$IFDEF VER260} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} +{$ENDIF} + +// Delphi XE6 +{$IFDEF VER270} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} +{$ENDIF} + +// Delphi XE7 +{$IFDEF VER280} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} +{$ENDIF} + +// Delphi XE8 +{$IFDEF VER290} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} + {$DEFINE DELPHI22_UP} +{$ENDIF VER290} + +// Rad Studio 10 - Delphi Seattle +{$IFDEF VER300} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} + {$DEFINE DELPHI22_UP} + {$DEFINE DELPHI23_UP} +{$ENDIF} + +// Rad Studio 10.1 - Delphi Berlin +{$IFDEF VER310} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} + {$DEFINE DELPHI22_UP} + {$DEFINE DELPHI23_UP} + {$DEFINE DELPHI24_UP} +{$ENDIF} + +// Rad Studio 10.2 - Delphi Tokyo +{$IFDEF VER320} + {$UNDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} + {$DEFINE DELPHI22_UP} + {$DEFINE DELPHI23_UP} + {$DEFINE DELPHI24_UP} + {$DEFINE DELPHI25_UP} +{$ENDIF} + + +{$IFDEF DELPHI_VERSION_UNKNOW} + {$DEFINE DELPHI5_UP} + {$DEFINE DELPHI6_UP} + {$DEFINE DELPHI7_UP} + {$DEFINE DELPHI8_UP} + {$DEFINE DELPHI9_UP} + {$DEFINE DELPHI10_UP} + {$DEFINE DELPHI11_UP} + {$DEFINE DELPHI12_UP} + {$DEFINE DELPHI14_UP} + {$DEFINE DELPHI15_UP} + {$DEFINE DELPHI16_UP} + {$DEFINE DELPHI17_UP} + {$DEFINE DELPHI18_UP} + {$DEFINE DELPHI19_UP} + {$DEFINE DELPHI20_UP} + {$DEFINE DELPHI21_UP} + {$DEFINE DELPHI22_UP} + {$DEFINE DELPHI23_UP} + {$DEFINE DELPHI24_UP} + {$DEFINE DELPHI25_UP} +{$ENDIF} + +{$IFDEF DELPHI9_UP} + {$DEFINE SUPPORTS_INLINE} +{$ENDIF} + diff --git a/demos/ResponseFilterBrowser/uResopnseFilterBrowser.dfm b/demos/ResponseFilterBrowser/uResopnseFilterBrowser.dfm new file mode 100644 index 00000000..9b025ea4 --- /dev/null +++ b/demos/ResponseFilterBrowser/uResopnseFilterBrowser.dfm @@ -0,0 +1,98 @@ +object ResponseFilterBrowserFrm: TResponseFilterBrowserFrm + Left = 0 + Top = 0 + Caption = 'Initializing browser. Please wait...' + ClientHeight = 624 + ClientWidth = 1038 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + OldCreateOrder = False + Position = poScreenCenter + OnCreate = FormCreate + OnDestroy = FormDestroy + OnShow = FormShow + PixelsPerInch = 96 + TextHeight = 13 + object Splitter1: TSplitter + Left = 0 + Top = 532 + Width = 1038 + Height = 3 + Cursor = crVSplit + Align = alBottom + ExplicitTop = 30 + ExplicitWidth = 505 + end + object AddressPnl: TPanel + Left = 0 + Top = 0 + Width = 1038 + Height = 30 + Align = alTop + BevelOuter = bvNone + Enabled = False + Padding.Left = 5 + Padding.Top = 5 + Padding.Right = 5 + Padding.Bottom = 5 + ShowCaption = False + TabOrder = 0 + object AddressEdt: TEdit + Left = 5 + Top = 5 + Width = 997 + Height = 20 + Margins.Right = 5 + Align = alClient + TabOrder = 0 + Text = 'https://www.wikipedia.org' + ExplicitHeight = 21 + end + object GoBtn: TButton + Left = 1002 + Top = 5 + Width = 31 + Height = 20 + Margins.Left = 5 + Align = alRight + Caption = 'Go' + TabOrder = 1 + OnClick = GoBtnClick + end + end + object CEFWindowParent1: TCEFWindowParent + Left = 0 + Top = 30 + Width = 1038 + Height = 502 + Align = alClient + TabOrder = 1 + end + object Memo1: TMemo + Left = 0 + Top = 535 + Width = 1038 + Height = 89 + Align = alBottom + ReadOnly = True + ScrollBars = ssBoth + TabOrder = 2 + end + object Timer1: TTimer + Enabled = False + Interval = 300 + OnTimer = Timer1Timer + Left = 56 + Top = 88 + end + object Chromium1: TChromium + OnAfterCreated = Chromium1AfterCreated + OnGetResourceResponseFilter = Chromium1GetResourceResponseFilter + Left = 56 + Top = 160 + end +end diff --git a/demos/ResponseFilterBrowser/uResopnseFilterBrowser.pas b/demos/ResponseFilterBrowser/uResopnseFilterBrowser.pas new file mode 100644 index 00000000..20cb7b7a --- /dev/null +++ b/demos/ResponseFilterBrowser/uResopnseFilterBrowser.pas @@ -0,0 +1,262 @@ +// ************************************************************************ +// ***************************** 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 © 2018 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 uResopnseFilterBrowser; + +{$I cef.inc} + +interface + +uses + {$IFDEF DELPHI16_UP} + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, System.SyncObjs, + {$ELSE} + Windows, Messages, SysUtils, Variants, Classes, Graphics, + Controls, Forms, Dialogs, StdCtrls, ExtCtrls, SyncObjs, + {$ENDIF} + uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFConstants, uCEFTypes, uCEFResponseFilter; + +const + STREAM_COPY_COMPLETE = WM_APP + $B00; + +type + TResponseFilterBrowserFrm = class(TForm) + AddressPnl: TPanel; + AddressEdt: TEdit; + GoBtn: TButton; + Timer1: TTimer; + Chromium1: TChromium; + CEFWindowParent1: TCEFWindowParent; + Splitter1: TSplitter; + Memo1: TMemo; + procedure GoBtnClick(Sender: TObject); + procedure FormShow(Sender: TObject); + procedure Timer1Timer(Sender: TObject); + procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser); + procedure Chromium1GetResourceResponseFilter(Sender: TObject; + const browser: ICefBrowser; const frame: ICefFrame; + const request: ICefRequest; const response: ICefResponse; + out Result: ICefResponseFilter); + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); + protected + FFilter : ICefResponseFilter; + FStream : TMemoryStream; + FStreamCS : TCriticalSection; + FLoading : boolean; + + procedure WMMove(var aMessage : TWMMove); message WM_MOVE; + procedure WMMoving(var aMessage : TMessage); message WM_MOVING; + procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP; + procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP; + procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED; + procedure StreamCopyCompleteMsg(var aMessage : TMessage); message STREAM_COPY_COMPLETE; + + procedure Filter_OnFilter(Sender: TObject; data_in: Pointer; data_in_size: NativeUInt; var data_in_read: NativeUInt; data_out: Pointer; data_out_size : NativeUInt; var data_out_written: NativeUInt; var aResult : TCefResponseFilterStatus); + public + { Public declarations } + end; + +var + ResponseFilterBrowserFrm: TResponseFilterBrowserFrm; + +implementation + +{$R *.dfm} + +uses + {$IFDEF DELPHI16_UP} + System.Math, + {$ELSE} + Math, + {$ENDIF} + uCEFApplication; + +// This demo uses a TCustomResponseFilter to read the contents from a JavaScript file in wikipedia.org into a TMemoryStream. +// The stream is shown in the TMemo when it's finished. + +// For more information read the CEF3 code comments here : +// https://github.com/chromiumembedded/cef/blob/master/include/capi/cef_response_filter_capi.h + +procedure TResponseFilterBrowserFrm.Filter_OnFilter(Sender: TObject; + data_in : Pointer; + data_in_size : NativeUInt; + var data_in_read : NativeUInt; + data_out : Pointer; + data_out_size : NativeUInt; + var data_out_written : NativeUInt; + var aResult : TCefResponseFilterStatus); +begin + try + // This event will be called repeatedly until the input buffer has been fully read. + FStreamCS.Acquire; + + aResult := RESPONSE_FILTER_DONE; + + if (data_in = nil) then + begin + data_in_read := 0; + data_out_written := 0; + end + else + begin + data_in_read := data_in_size; + + if (data_out <> nil) then + begin + data_out_written := min(data_in_read, data_out_size); + Move(data_in^, data_out^, data_out_written); + end; + + FStream.WriteBuffer(data_in^, data_in_size); + PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0); + end; + finally + FStreamCS.Release; + end; +end; + +procedure TResponseFilterBrowserFrm.FormCreate(Sender: TObject); +begin + FLoading := False; + FStream := TMemoryStream.Create; + FStreamCS := TCriticalSection.Create; + FFilter := TCustomResponseFilter.Create; + + // This event will receive the data + TCustomResponseFilter(FFilter).OnFilter := Filter_OnFilter; +end; + +procedure TResponseFilterBrowserFrm.FormDestroy(Sender: TObject); +begin + FFilter := nil; + FStream.Free; + FStreamCS.Free; +end; + +procedure TResponseFilterBrowserFrm.FormShow(Sender: TObject); +begin + // GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser + // If it's not initialized yet, we use a simple timer to create the browser later. + if not(Chromium1.CreateBrowser(CEFWindowParent1)) then Timer1.Enabled := True; +end; + +procedure TResponseFilterBrowserFrm.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser); +begin + // Now the browser is fully initialized we can send a message to the main form to load the initial web page. + PostMessage(Handle, CEF_AFTERCREATED, 0, 0); +end; + +procedure TResponseFilterBrowserFrm.Chromium1GetResourceResponseFilter(Sender : TObject; + const browser : ICefBrowser; + const frame : ICefFrame; + const request : ICefRequest; + const response : ICefResponse; + out Result : ICefResponseFilter); +begin + // All resources can be filtered but for this demo we will select a JS file in wikipedia.org called 'index-47f5f07682.js' + if (request <> nil) and + (pos('index', request.URL) > 0) and // the file contains the word 'index' + (pos('.js', request.URL) > 0) then // the file contains the extension '.js' + Result := FFilter + else + Result := nil; +end; + +procedure TResponseFilterBrowserFrm.BrowserCreatedMsg(var aMessage : TMessage); +begin + Caption := 'Response Filter Browser'; + AddressPnl.Enabled := True; + GoBtn.Click; +end; + +procedure TResponseFilterBrowserFrm.StreamCopyCompleteMsg(var aMessage : TMessage); +begin + try + FStreamCS.Acquire; + FStream.Seek(0, soBeginning); + Memo1.Lines.Clear; + Memo1.Lines.LoadFromStream(FStream); + FStream.Clear; + finally + FStreamCS.Release; + end; +end; + +procedure TResponseFilterBrowserFrm.GoBtnClick(Sender: TObject); +begin + FLoading := True; + Chromium1.LoadURL(AddressEdt.Text); +end; + +procedure TResponseFilterBrowserFrm.Timer1Timer(Sender: TObject); +begin + Timer1.Enabled := False; + if not(Chromium1.CreateBrowser(CEFWindowParent1)) and not(Chromium1.Initialized) then + Timer1.Enabled := True; +end; + +procedure TResponseFilterBrowserFrm.WMMove(var aMessage : TWMMove); +begin + inherited; + + if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted; +end; + +procedure TResponseFilterBrowserFrm.WMMoving(var aMessage : TMessage); +begin + inherited; + + if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted; +end; + +procedure TResponseFilterBrowserFrm.WMEnterMenuLoop(var aMessage: TMessage); +begin + inherited; + + if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True; +end; + +procedure TResponseFilterBrowserFrm.WMExitMenuLoop(var aMessage: TMessage); +begin + inherited; + + if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False; +end; + +end. diff --git a/source/uCEFApplication.pas b/source/uCEFApplication.pas index a24c16ae..8910a8f6 100644 --- a/source/uCEFApplication.pas +++ b/source/uCEFApplication.pas @@ -56,14 +56,14 @@ uses const CEF_SUPPORTED_VERSION_MAJOR = 3; - CEF_SUPPORTED_VERSION_MINOR = 3239; - CEF_SUPPORTED_VERSION_RELEASE = 1723; + CEF_SUPPORTED_VERSION_MINOR = 3282; + CEF_SUPPORTED_VERSION_RELEASE = 1731; CEF_SUPPORTED_VERSION_BUILD = 0; - CEF_CHROMEELF_VERSION_MAJOR = 63; + CEF_CHROMEELF_VERSION_MAJOR = 64; CEF_CHROMEELF_VERSION_MINOR = 0; - CEF_CHROMEELF_VERSION_RELEASE = 3239; - CEF_CHROMEELF_VERSION_BUILD = 109; + CEF_CHROMEELF_VERSION_RELEASE = 3282; + CEF_CHROMEELF_VERSION_BUILD = 119; LIBCEF_DLL = 'libcef.dll'; CHROMEELF_DLL = 'chrome_elf.dll'; @@ -523,9 +523,9 @@ end; procedure TCefApplication.RemoveAppReferences; begin try - if (FResourceBundleHandler <> nil) then FResourceBundleHandler.InitializeVars; - if (FBrowserProcessHandler <> nil) then FBrowserProcessHandler.InitializeVars; - if (FRenderProcessHandler <> nil) then FRenderProcessHandler.InitializeVars; + if (FResourceBundleHandler <> nil) then FResourceBundleHandler.RemoveReferences; + if (FBrowserProcessHandler <> nil) then FBrowserProcessHandler.RemoveReferences; + if (FRenderProcessHandler <> nil) then FRenderProcessHandler.RemoveReferences; except on e : exception do if CustomExceptionHandler('TCefApplication.RemoveAppReferences', e) then raise; diff --git a/source/uCEFBrowserProcessHandler.pas b/source/uCEFBrowserProcessHandler.pas index 0b3d475c..dd9b4b7e 100644 --- a/source/uCEFBrowserProcessHandler.pas +++ b/source/uCEFBrowserProcessHandler.pas @@ -58,7 +58,7 @@ type function GetPrintHandler : ICefPrintHandler; virtual; procedure OnScheduleMessagePumpWork(const delayMs: Int64); virtual; abstract; - procedure InitializeVars; virtual; abstract; + procedure RemoveReferences; virtual; abstract; public constructor Create; virtual; @@ -76,7 +76,7 @@ type public constructor Create(const aCefApp : TCefApplication); reintroduce; destructor Destroy; override; - procedure InitializeVars; override; + procedure RemoveReferences; override; end; implementation @@ -171,12 +171,12 @@ end; destructor TCefCustomBrowserProcessHandler.Destroy; begin - InitializeVars; + RemoveReferences; inherited Destroy; end; -procedure TCefCustomBrowserProcessHandler.InitializeVars; +procedure TCefCustomBrowserProcessHandler.RemoveReferences; begin FCefApp := nil; end; diff --git a/source/uCEFChromium.pas b/source/uCEFChromium.pas index c9104112..4f81aef3 100644 --- a/source/uCEFChromium.pas +++ b/source/uCEFChromium.pas @@ -53,19 +53,13 @@ uses Windows, Messages, Classes, Controls, Graphics, Forms, ActiveX, {$ENDIF} uCEFTypes, uCEFInterfaces, uCEFLibFunctions, uCEFMiscFunctions, uCEFClient, - uCEFPDFPrintCallback, uCEFStringVisitor, uCEFConstants, uCEFTask, - uCEFDeleteCookiesCallback, uCEFDomVisitor, uCEFChromiumEvents, - uCEFChromiumOptions, uCEFChromiumFontOptions, uCEFPDFPrintOptions, - uCEFDragAndDropMgr; + uCEFConstants, uCEFTask, uCEFDomVisitor, uCEFChromiumEvents, + uCEFChromiumOptions, uCEFChromiumFontOptions, uCEFPDFPrintOptions, uCEFDragAndDropMgr; type TChromium = class(TComponent, IChromiumEvents) protected FCompHandle : HWND; - FVisitor : ICefStringVisitor; - FPDFPrintcb : ICefPdfPrintCallback; - FResolveHostcb : ICefResolveCallback; - FCookiDeletercb : ICefDeleteCookiesCallback; FHandler : ICefClient; FBrowser : ICefBrowser; FBrowserId : Integer; @@ -264,10 +258,6 @@ type function CreateBrowserHostSync(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): ICefBrowser; procedure DestroyClientHandler; - procedure DestroyVisitor; - procedure DestroyPDFPrintcb; - procedure DestroyResolveHostcb; - procedure DestroyCookiDeletercb; procedure ClearBrowserReference; @@ -351,7 +341,7 @@ type procedure doOnFullScreenModeChange(const browser: ICefBrowser; fullscreen: Boolean); virtual; function doOnTooltip(const browser: ICefBrowser; var text: ustring): Boolean; virtual; procedure doOnStatusMessage(const browser: ICefBrowser; const value: ustring); virtual; - function doOnConsoleMessage(const browser: ICefBrowser; const aMessage, source: ustring; line: Integer): Boolean; virtual; + function doOnConsoleMessage(const browser: ICefBrowser; level: TCefLogSeverity; const aMessage, source: ustring; line: Integer): Boolean; virtual; function doOnAutoResize(const browser: ICefBrowser; const new_size: PCefSize): Boolean; virtual; // ICefDownloadHandler @@ -419,12 +409,6 @@ type // Custom procedure doCookiesDeleted(numDeleted : integer); virtual; - procedure doGetHTML(const aFrameName : ustring); overload; - procedure doGetHTML(const aFrame : ICefFrame); overload; - procedure doGetHTML(const aFrameIdentifier : int64); overload; - procedure doGetText(const aFrameName : ustring); overload; - procedure doGetText(const aFrame : ICefFrame); overload; - procedure doGetText(const aFrameIdentifier : int64); overload; procedure doPdfPrintFinished(aResultOK : boolean); virtual; procedure doTextResultAvailable(const aText : string); virtual; procedure doUpdatePreferences; virtual; @@ -445,6 +429,8 @@ type procedure InitializeDragAndDrop(const aDropTargetCtrl : TWinControl); procedure ShutdownDragAndDrop; + + procedure LoadURL(const aURL : ustring); procedure LoadString(const aString : ustring; const aURL : ustring = ''); procedure LoadRequest(const aRequest: ICefRequest); @@ -695,8 +681,8 @@ uses SysUtils, Math, {$ENDIF} uCEFBrowser, uCEFValue, uCEFDictionaryValue, uCEFStringMultimap, uCEFFrame, - uCEFApplication, uCEFProcessMessage, uOLEDragAndDrop, uCEFRequestContext, - uCEFResolveCallback; + uCEFApplication, uCEFProcessMessage, uCEFRequestContext, uOLEDragAndDrop, + uCEFPDFPrintCallback, uCEFResolveCallback, uCEFDeleteCookiesCallback, uCEFStringVisitor; constructor TChromium.Create(AOwner: TComponent); begin @@ -711,10 +697,6 @@ begin FOptions := nil; FFontOptions := nil; FDefaultEncoding := ''; - FVisitor := nil; - FPDFPrintcb := nil; - FResolveHostcb := nil; - FCookiDeletercb := nil; FPDFPrintOptions := nil; FUpdatePreferences := False; FCustomHeaderName := ''; @@ -787,10 +769,6 @@ end; procedure TChromium.BeforeDestruction; begin DestroyClientHandler; - DestroyVisitor; - DestroyPDFPrintcb; - DestroyResolveHostcb; - DestroyCookiDeletercb; inherited BeforeDestruction; end; @@ -806,7 +784,7 @@ begin try if (FHandler <> nil) then begin - FHandler.InitializeVars; + FHandler.RemoveReferences; FHandler := nil; end; except @@ -815,62 +793,6 @@ begin end; end; -procedure TChromium.DestroyVisitor; -begin - try - if (FVisitor <> nil) then - begin - FVisitor.InitializeVars; - FVisitor := nil; - end; - except - on e : exception do - if CustomExceptionHandler('TChromium.DestroyVisitor', e) then raise; - end; -end; - -procedure TChromium.DestroyPDFPrintcb; -begin - try - if (FPDFPrintcb <> nil) then - begin - FPDFPrintcb.InitializeVars; - FPDFPrintcb := nil; - end; - except - on e : exception do - if CustomExceptionHandler('TChromium.DestroyPDFPrintcb', e) then raise; - end; -end; - -procedure TChromium.DestroyResolveHostcb; -begin - try - if (FResolveHostcb <> nil) then - begin - FResolveHostcb.InitializeVars; - FResolveHostcb := nil; - end; - except - on e : exception do - if CustomExceptionHandler('TChromium.DestroyResolveHostcb', e) then raise; - end; -end; - -procedure TChromium.DestroyCookiDeletercb; -begin - try - if (FCookiDeletercb <> nil) then - begin - FCookiDeletercb.InitializeVars; - FCookiDeletercb := nil; - end; - except - on e : exception do - if CustomExceptionHandler('TChromium.DestroyCookiDeletercb', e) then raise; - end; -end; - procedure TChromium.AfterConstruction; begin inherited AfterConstruction; @@ -1290,12 +1212,13 @@ end; procedure TChromium.PrintToPDF(const aFilePath, aTitle, aURL : ustring); var TempSettings : TCefPdfPrintSettings; + TempCallback : ICefPdfPrintCallback; begin if Initialized then begin GetPrintPDFSettings(TempSettings, aTitle, aURL); - if (FPDFPrintcb = nil) then FPDFPrintcb := TCefCustomPDFPrintCallBack.Create(self); - FBrowser.Host.PrintToPdf(aFilePath, @TempSettings, FPDFPrintcb); + TempCallback := TCefCustomPDFPrintCallBack.Create(self); + FBrowser.Host.PrintToPdf(aFilePath, @TempSettings, TempCallback); end; end; @@ -1925,103 +1848,10 @@ begin end; end; -procedure TChromium.doGetHTML(const aFrameName : ustring); -var - TempFrame : ICefFrame; -begin - if Initialized then - begin - if (length(aFrameName) > 0) then - TempFrame := FBrowser.GetFrame(aFrameName) - else - TempFrame := FBrowser.MainFrame; - - if (TempFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - TempFrame.GetSource(FVisitor); - end; - end; -end; - -procedure TChromium.doGetHTML(const aFrame : ICefFrame); -begin - if Initialized and (aFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - aFrame.GetSource(FVisitor); - end; -end; - -procedure TChromium.doGetHTML(const aFrameIdentifier : int64); -var - TempFrame : ICefFrame; -begin - if Initialized then - begin - if (aFrameIdentifier <> 0) then - TempFrame := FBrowser.GetFrameByident(aFrameIdentifier) - else - TempFrame := FBrowser.MainFrame; - - if (TempFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - TempFrame.GetSource(FVisitor); - end; - end; -end; - -procedure TChromium.doGetText(const aFrameName : ustring); -var - TempFrame : ICefFrame; -begin - if Initialized then - begin - if (length(aFrameName) > 0) then - TempFrame := FBrowser.GetFrame(aFrameName) - else - TempFrame := FBrowser.MainFrame; - - if (TempFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - TempFrame.GetText(FVisitor); - end; - end; -end; - -procedure TChromium.doGetText(const aFrame : ICefFrame); -begin - if Initialized and (aFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - aFrame.GetText(FVisitor); - end; -end; - -procedure TChromium.doGetText(const aFrameIdentifier : int64); -var - TempFrame : ICefFrame; -begin - if Initialized then - begin - if (aFrameIdentifier <> 0) then - TempFrame := FBrowser.GetFrameByident(aFrameIdentifier) - else - TempFrame := FBrowser.MainFrame; - - if (TempFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - TempFrame.GetText(FVisitor); - end; - end; -end; - function TChromium.DeleteCookies : boolean; var - TempManager : ICefCookieManager; + TempManager : ICefCookieManager; + TempCallback : ICefDeleteCookiesCallback; begin Result := False; @@ -2031,9 +1861,8 @@ begin if (TempManager <> nil) then begin - if (FCookiDeletercb = nil) then FCookiDeletercb := TCefCustomDeleteCookiesCallback.Create(self); - - Result := TempManager.DeleteCookies('', '', FCookiDeletercb); + TempCallback := TCefCustomDeleteCookiesCallback.Create(self); + Result := TempManager.DeleteCookies('', '', TempCallback); end; end; end; @@ -2041,74 +1870,104 @@ end; // Leave aFrameName empty to get the HTML source from the main frame procedure TChromium.RetrieveHTML(const aFrameName : ustring); var - TempTask: ICefTask; + TempFrame : ICefFrame; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class if Initialized then begin - TempTask := TCefGetHTMLTask.Create(self, aFrameName); - CefPostTask(TID_UI, TempTask); + if (length(aFrameName) > 0) then + TempFrame := FBrowser.GetFrame(aFrameName) + else + TempFrame := FBrowser.MainFrame; + + if (TempFrame <> nil) then + begin + TempVisitor := TCustomCefStringVisitor.Create(self); + TempFrame.GetSource(TempVisitor); + end; end; end; procedure TChromium.RetrieveHTML(const aFrame : ICefFrame); var - TempTask: ICefTask; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class - if Initialized then + if Initialized and (aFrame <> nil) then begin - TempTask := TCefGetHTMLTask.Create(self, aFrame); - CefPostTask(TID_UI, TempTask); + TempVisitor := TCustomCefStringVisitor.Create(self); + aFrame.GetSource(TempVisitor); end; end; procedure TChromium.RetrieveHTML(const aFrameIdentifier : int64); var - TempTask: ICefTask; + TempFrame : ICefFrame; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class if Initialized then begin - TempTask := TCefGetHTMLTask.Create(self, aFrameIdentifier); - CefPostTask(TID_UI, TempTask); + if (aFrameIdentifier <> 0) then + TempFrame := FBrowser.GetFrameByident(aFrameIdentifier) + else + TempFrame := FBrowser.MainFrame; + + if (TempFrame <> nil) then + begin + TempVisitor := TCustomCefStringVisitor.Create(self); + TempFrame.GetSource(TempVisitor); + end; end; end; // Leave aFrameName empty to get the HTML source from the main frame procedure TChromium.RetrieveText(const aFrameName : ustring); var - TempTask: ICefTask; + TempFrame : ICefFrame; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class if Initialized then begin - TempTask := TCefGetTextTask.Create(self, aFrameName); - CefPostTask(TID_UI, TempTask); + if (length(aFrameName) > 0) then + TempFrame := FBrowser.GetFrame(aFrameName) + else + TempFrame := FBrowser.MainFrame; + + if (TempFrame <> nil) then + begin + TempVisitor := TCustomCefStringVisitor.Create(self); + TempFrame.GetText(TempVisitor); + end; end; end; procedure TChromium.RetrieveText(const aFrame : ICefFrame); var - TempTask: ICefTask; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class - if Initialized then + if Initialized and (aFrame <> nil) then begin - TempTask := TCefGetTextTask.Create(self, aFrame); - CefPostTask(TID_UI, TempTask); + TempVisitor := TCustomCefStringVisitor.Create(self); + aFrame.GetText(TempVisitor); end; end; procedure TChromium.RetrieveText(const aFrameIdentifier : int64); var - TempTask: ICefTask; + TempFrame : ICefFrame; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class if Initialized then begin - TempTask := TCefGetTextTask.Create(self, aFrameIdentifier); - CefPostTask(TID_UI, TempTask); + if (aFrameIdentifier <> 0) then + TempFrame := FBrowser.GetFrameByident(aFrameIdentifier) + else + TempFrame := FBrowser.MainFrame; + + if (TempFrame <> nil) then + begin + TempVisitor := TCustomCefStringVisitor.Create(self); + TempFrame.GetText(TempVisitor); + end; end; end; @@ -2159,12 +2018,14 @@ begin end; procedure TChromium.ResolveHost(const aURL : ustring); +var + TempCallback : ICefResolveCallback; begin // Results will be received in the OnResolvedHostAvailable event of this class if Initialized and (length(aURL) > 0) then begin - if (FResolveHostcb = nil) then FResolveHostcb := TCefCustomResolveCallback.Create(self); - FBrowser.Host.RequestContext.ResolveHost(aURL, FResolveHostcb); + TempCallback := TCefCustomResolveCallback.Create(self); + FBrowser.Host.RequestContext.ResolveHost(aURL, TempCallback); end; end; @@ -3030,13 +2891,14 @@ begin end; function TChromium.doOnConsoleMessage(const browser : ICefBrowser; + level : TCefLogSeverity; const aMessage : ustring; const source : ustring; line : Integer): Boolean; begin Result := False; - if Assigned(FOnConsoleMessage) then FOnConsoleMessage(Self, browser, aMessage, source, line, Result); + if Assigned(FOnConsoleMessage) then FOnConsoleMessage(Self, browser, level, aMessage, source, line, Result); end; function TChromium.doOnAutoResize(const browser : ICefBrowser; diff --git a/source/uCEFChromiumEvents.pas b/source/uCEFChromiumEvents.pas index 3d7795e4..f4deb4ab 100644 --- a/source/uCEFChromiumEvents.pas +++ b/source/uCEFChromiumEvents.pas @@ -86,7 +86,7 @@ type TOnFullScreenModeChange = procedure(Sender: TObject; const browser: ICefBrowser; fullscreen: Boolean) of object; TOnTooltip = procedure(Sender: TObject; const browser: ICefBrowser; var text: ustring; out Result: Boolean) of object; TOnStatusMessage = procedure(Sender: TObject; const browser: ICefBrowser; const value: ustring) of object; - TOnConsoleMessage = procedure(Sender: TObject; const browser: ICefBrowser; const message, source: ustring; line: Integer; out Result: Boolean) of object; + TOnConsoleMessage = procedure(Sender: TObject; const browser: ICefBrowser; level: TCefLogSeverity; const message, source: ustring; line: Integer; out Result: Boolean) of object; TOnAutoResize = procedure(Sender: TObject; const browser: ICefBrowser; const new_size: PCefSize; out Result: Boolean) of object; // ICefDownloadHandler diff --git a/source/uCEFClient.pas b/source/uCEFClient.pas index 5a2f6d43..42577aa9 100644 --- a/source/uCEFClient.pas +++ b/source/uCEFClient.pas @@ -73,7 +73,7 @@ type function GetRequestHandler: ICefRequestHandler; virtual; function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; virtual; - procedure InitializeVars; virtual; + procedure RemoveReferences; virtual; public class function UnWrap(data: Pointer): ICefClient; @@ -97,7 +97,7 @@ type function GetRequestHandler: ICefRequestHandler; virtual; function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; virtual; - procedure InitializeVars; virtual; + procedure RemoveReferences; virtual; public constructor Create; virtual; @@ -105,7 +105,7 @@ type TCustomClientHandler = class(TCefClientOwn) protected - FEvents : IChromiumEvents; + FEvents : Pointer; FLoadHandler : ICefLoadHandler; FFocusHandler : ICefFocusHandler; FContextMenuHandler : ICefContextMenuHandler; @@ -121,6 +121,7 @@ type FDragHandler : ICefDragHandler; FFindHandler : ICefFindHandler; + function GetContextMenuHandler: ICefContextMenuHandler; override; function GetDialogHandler: ICefDialogHandler; override; function GetDisplayHandler: ICefDisplayHandler; override; @@ -137,14 +138,16 @@ type function GetRequestHandler: ICefRequestHandler; override; function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; override; + procedure InitializeVars; + public constructor Create(const events: IChromiumEvents; aCreateLoadHandler, aCreateFocusHandler, aCreateContextMenuHandler, aCreateDialogHandler, aCreateKeyboardHandler, aCreateDisplayHandler, aCreateDownloadHandler, aCreateGeolocationHandler, aCreateJsDialogHandler, aCreateLifeSpanHandler, aCreateRenderHandler, aCreateRequestHandler, aCreateDragHandler, aCreateFindHandler : boolean); reintroduce; virtual; - destructor Destroy; override; - procedure InitializeVars; override; + procedure BeforeDestruction; override; + procedure RemoveReferences; override; end; implementation @@ -249,7 +252,7 @@ begin Result := False; end; -procedure TCefClientRef.InitializeVars; +procedure TCefClientRef.RemoveReferences; begin // end; @@ -450,7 +453,7 @@ begin Result := False; end; -procedure TCefClientOwn.InitializeVars; +procedure TCefClientOwn.RemoveReferences; begin // end; @@ -481,7 +484,7 @@ begin InitializeVars; - FEvents := events; + FEvents := Pointer(events); if (FEvents <> nil) then begin @@ -502,11 +505,31 @@ begin end; end; -destructor TCustomClientHandler.Destroy; +procedure TCustomClientHandler.BeforeDestruction; begin InitializeVars; - inherited Destroy; + inherited BeforeDestruction; +end; + +procedure TCustomClientHandler.RemoveReferences; +begin + FEvents := nil; + + if (FLoadHandler <> nil) then FLoadHandler.RemoveReferences; + if (FFocusHandler <> nil) then FFocusHandler.RemoveReferences; + if (FContextMenuHandler <> nil) then FContextMenuHandler.RemoveReferences; + if (FDialogHandler <> nil) then FDialogHandler.RemoveReferences; + if (FKeyboardHandler <> nil) then FKeyboardHandler.RemoveReferences; + if (FDisplayHandler <> nil) then FDisplayHandler.RemoveReferences; + if (FDownloadHandler <> nil) then FDownloadHandler.RemoveReferences; + if (FGeolocationHandler <> nil) then FGeolocationHandler.RemoveReferences; + if (FJsDialogHandler <> nil) then FJsDialogHandler.RemoveReferences; + if (FLifeSpanHandler <> nil) then FLifeSpanHandler.RemoveReferences; + if (FRequestHandler <> nil) then FRequestHandler.RemoveReferences; + if (FRenderHandler <> nil) then FRenderHandler.RemoveReferences; + if (FDragHandler <> nil) then FDragHandler.RemoveReferences; + if (FFindHandler <> nil) then FFindHandler.RemoveReferences; end; procedure TCustomClientHandler.InitializeVars; @@ -598,12 +621,14 @@ begin Result := FRequestHandler; end; -function TCustomClientHandler.OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; +function TCustomClientHandler.OnProcessMessageReceived(const browser : ICefBrowser; + sourceProcess : TCefProcessId; + const message : ICefProcessMessage): Boolean; begin if (FEvents <> nil) then - Result := FEvents.doOnProcessMessageReceived(browser, sourceProcess, message) + Result := IChromiumEvents(FEvents).doOnProcessMessageReceived(browser, sourceProcess, message) else - Result := False; + Result := inherited OnProcessMessageReceived(browser, sourceProcess, message); end; end. diff --git a/source/uCEFConstants.pas b/source/uCEFConstants.pas index b846460d..9f0962a7 100644 --- a/source/uCEFConstants.pas +++ b/source/uCEFConstants.pas @@ -312,6 +312,15 @@ const JSON_WRITER_OMIT_DOUBLE_TYPE_PRESERVATION = 1 shl 1; JSON_WRITER_PRETTY_PRINT = 1 shl 2; + // /include/internal/cef_types.h (cef_log_severity_t) + LOGSEVERITY_DEFAULT = 0; + LOGSEVERITY_VERBOSE = 1; + LOGSEVERITY_DEBUG = LOGSEVERITY_VERBOSE; + LOGSEVERITY_INFO = 2; + LOGSEVERITY_WARNING = 3; + LOGSEVERITY_ERROR = 4; + LOGSEVERITY_DISABLE = 99; + //****************************************************** //****************** OTHER CONSTANTS ******************* @@ -332,7 +341,7 @@ const CEF_CONTENT_SETTING_SESSION_ONLY = 4; CEF_CONTENT_SETTING_NUM_SETTINGS = 5; - // Used in the severity parameter of cef_log + // Used in the severity parameter in the 'cef_log' function, also known as 'CefLog' in CEF4Delphi. CEF_LOG_SEVERITY_INFO = 0; CEF_LOG_SEVERITY_WARNING = 1; CEF_LOG_SEVERITY_ERROR = 2; diff --git a/source/uCEFContextMenuHandler.pas b/source/uCEFContextMenuHandler.pas index 418f227c..b5a2471e 100644 --- a/source/uCEFContextMenuHandler.pas +++ b/source/uCEFContextMenuHandler.pas @@ -57,27 +57,36 @@ type function OnContextMenuCommand(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; commandId: Integer; eventFlags: TCefEventFlags): Boolean; virtual; procedure OnContextMenuDismissed(const browser: ICefBrowser; const frame: ICefFrame); virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomContextMenuHandler = class(TCefContextMenuHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; procedure OnBeforeContextMenu(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel); override; function RunContextMenu(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel; const callback: ICefRunContextMenuCallback): Boolean; override; function OnContextMenuCommand(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; commandId: Integer; eventFlags: TCefEventFlags): Boolean; override; procedure OnContextMenuDismissed(const browser: ICefBrowser; const frame: ICefFrame); override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFFrame, uCEFContextMenuParams, uCEFMenuModel, uCEFRunContextMenuCallback; @@ -119,66 +128,80 @@ end; constructor TCefContextMenuHandlerOwn.Create; begin inherited CreateData(SizeOf(TCefContextMenuHandler)); + with PCefContextMenuHandler(FData)^ do - begin - on_before_context_menu := cef_context_menu_handler_on_before_context_menu; - run_context_menu := cef_context_menu_handler_run_context_menu; - on_context_menu_command := cef_context_menu_handler_on_context_menu_command; - on_context_menu_dismissed := cef_context_menu_handler_on_context_menu_dismissed; - end; + begin + on_before_context_menu := cef_context_menu_handler_on_before_context_menu; + run_context_menu := cef_context_menu_handler_run_context_menu; + on_context_menu_command := cef_context_menu_handler_on_context_menu_command; + on_context_menu_dismissed := cef_context_menu_handler_on_context_menu_dismissed; + end; end; -procedure TCefContextMenuHandlerOwn.OnBeforeContextMenu( - const browser: ICefBrowser; const frame: ICefFrame; - const params: ICefContextMenuParams; const model: ICefMenuModel); +procedure TCefContextMenuHandlerOwn.OnBeforeContextMenu(const browser : ICefBrowser; + const frame : ICefFrame; + const params : ICefContextMenuParams; + const model : ICefMenuModel); begin - + // end; -function TCefContextMenuHandlerOwn.OnContextMenuCommand( - const browser: ICefBrowser; const frame: ICefFrame; - const params: ICefContextMenuParams; commandId: Integer; - eventFlags: TCefEventFlags): Boolean; +function TCefContextMenuHandlerOwn.OnContextMenuCommand(const browser : ICefBrowser; + const frame : ICefFrame; + const params : ICefContextMenuParams; + commandId : Integer; + eventFlags : TCefEventFlags): Boolean; begin Result := False; end; -procedure TCefContextMenuHandlerOwn.OnContextMenuDismissed( - const browser: ICefBrowser; const frame: ICefFrame); +procedure TCefContextMenuHandlerOwn.OnContextMenuDismissed(const browser : ICefBrowser; + const frame : ICefFrame); begin - + // end; -function TCefContextMenuHandlerOwn.RunContextMenu(const browser: ICefBrowser; - const frame: ICefFrame; const params: ICefContextMenuParams; - const model: ICefMenuModel; - const callback: ICefRunContextMenuCallback): Boolean; +function TCefContextMenuHandlerOwn.RunContextMenu(const browser : ICefBrowser; + const frame : ICefFrame; + const params : ICefContextMenuParams; + const model : ICefMenuModel; + const callback : ICefRunContextMenuCallback): Boolean; begin Result := False; end; +procedure TCefContextMenuHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomContextMenuHandler -constructor TCustomContextMenuHandler.Create(const events: IChromiumEvents); +constructor TCustomContextMenuHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomContextMenuHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; +procedure TCustomContextMenuHandler.RemoveReferences; +begin + FEvents := nil; +end; + procedure TCustomContextMenuHandler.OnBeforeContextMenu(const browser : ICefBrowser; const frame : ICefFrame; const params : ICefContextMenuParams; const model : ICefMenuModel); begin - if (FEvent <> nil) then FEvent.doOnBeforeContextMenu(browser, frame, params, model); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnBeforeContextMenu(browser, frame, params, model); end; function TCustomContextMenuHandler.RunContextMenu(const browser : ICefBrowser; @@ -187,8 +210,8 @@ function TCustomContextMenuHandler.RunContextMenu(const browser : ICefBrowser; const model : ICefMenuModel; const callback : ICefRunContextMenuCallback): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doRunContextMenu(browser, frame, params, model, callback) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doRunContextMenu(browser, frame, params, model, callback) else Result := inherited RunContextMenu(browser, frame, params, model, callback); end; @@ -199,15 +222,16 @@ function TCustomContextMenuHandler.OnContextMenuCommand(const browser : ICefB commandId : Integer; eventFlags : TCefEventFlags): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnContextMenuCommand(browser, frame, params, commandId, eventFlags) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnContextMenuCommand(browser, frame, params, commandId, eventFlags) else Result := inherited OnContextMenuCommand(browser, frame, params, commandId, eventFlags); end; -procedure TCustomContextMenuHandler.OnContextMenuDismissed(const browser: ICefBrowser; const frame: ICefFrame); +procedure TCustomContextMenuHandler.OnContextMenuDismissed(const browser : ICefBrowser; + const frame : ICefFrame); begin - if (FEvent <> nil) then FEvent.doOnContextMenuDismissed(browser, frame); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnContextMenuDismissed(browser, frame); end; end. diff --git a/source/uCEFDeleteCookiesCallback.pas b/source/uCEFDeleteCookiesCallback.pas index d08e64a2..7e92bf96 100644 --- a/source/uCEFDeleteCookiesCallback.pas +++ b/source/uCEFDeleteCookiesCallback.pas @@ -53,7 +53,6 @@ type TCefDeleteCookiesCallbackOwn = class(TCefBaseRefCountedOwn, ICefDeleteCookiesCallback) protected procedure OnComplete(numDeleted: Integer); virtual; abstract; - procedure InitializeVars; virtual; abstract; public constructor Create; virtual; @@ -68,24 +67,27 @@ type public constructor Create(const callback: TCefDeleteCookiesCallbackProc); reintroduce; destructor Destroy; override; - procedure InitializeVars; override; end; TCefCustomDeleteCookiesCallback = class(TCefDeleteCookiesCallbackOwn) protected - FChromiumBrowser : IChromiumEvents; + FEvents : Pointer; procedure OnComplete(numDeleted: Integer); override; public - constructor Create(const aChromiumBrowser : IChromiumEvents); reintroduce; + constructor Create(const aEvents : IChromiumEvents); reintroduce; destructor Destroy; override; - procedure InitializeVars; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions; procedure cef_delete_cookie_callback_on_complete(self: PCefDeleteCookiesCallback; num_deleted: Integer); stdcall; @@ -118,40 +120,39 @@ end; destructor TCefFastDeleteCookiesCallback.Destroy; begin - InitializeVars; + FCallback := nil; inherited Destroy; end; -procedure TCefFastDeleteCookiesCallback.InitializeVars; -begin - FCallback := nil; -end; - // TCefCustomDeleteCookiesCallback -constructor TCefCustomDeleteCookiesCallback.Create(const aChromiumBrowser : IChromiumEvents); +constructor TCefCustomDeleteCookiesCallback.Create(const aEvents : IChromiumEvents); begin inherited Create; - FChromiumBrowser := aChromiumBrowser; + FEvents := Pointer(aEvents); end; destructor TCefCustomDeleteCookiesCallback.Destroy; begin - InitializeVars; + FEvents := nil; inherited Destroy; end; -procedure TCefCustomDeleteCookiesCallback.InitializeVars; -begin - FChromiumBrowser := nil; -end; - procedure TCefCustomDeleteCookiesCallback.OnComplete(numDeleted: Integer); begin - if (FChromiumBrowser <> nil) then FChromiumBrowser.doCookiesDeleted(numDeleted); + try + try + if (FEvents <> nil) then IChromiumEvents(FEvents).doCookiesDeleted(numDeleted); + except + on e : exception do + if CustomExceptionHandler('TCefCustomDeleteCookiesCallback.OnComplete', e) then raise; + end; + finally + FEvents := nil; + end; end; end. diff --git a/source/uCEFDialogHandler.pas b/source/uCEFDialogHandler.pas index 40615517..2238cbd6 100644 --- a/source/uCEFDialogHandler.pas +++ b/source/uCEFDialogHandler.pas @@ -57,7 +57,9 @@ uses type TCefDialogHandlerOwn = class(TCefBaseRefCountedOwn, ICefDialogHandler) protected - function OnFileDialog(const browser: ICefBrowser; mode: TCefFileDialogMode; const title, defaultFilePath: ustring; acceptFilters: TStrings; selectedAcceptFilter: Integer; const callback: ICefFileDialogCallback): Boolean; virtual; + function OnFileDialog(const browser: ICefBrowser; mode: TCefFileDialogMode; const title, defaultFilePath: ustring; acceptFilters: TStrings; selectedAcceptFilter: Integer; const callback: ICefFileDialogCallback): Boolean; virtual; + + procedure RemoveReferences; virtual; public constructor Create; virtual; @@ -65,18 +67,25 @@ type TCustomDialogHandler = class(TCefDialogHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; - function OnFileDialog(const browser: ICefBrowser; mode: TCefFileDialogMode; const title: ustring; const defaultFilePath: ustring; acceptFilters: TStrings; selectedAcceptFilter: Integer; const callback: ICefFileDialogCallback): Boolean; override; + function OnFileDialog(const browser: ICefBrowser; mode: TCefFileDialogMode; const title: ustring; const defaultFilePath: ustring; acceptFilters: TStrings; selectedAcceptFilter: Integer; const callback: ICefFileDialogCallback): Boolean; override; + + procedure RemoveReferences; override; public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFFileDialogCallback; function cef_dialog_handler_on_file_dialog(self: PCefDialogHandler; browser: PCefBrowser; @@ -119,22 +128,32 @@ begin Result := False; end; +procedure TCefDialogHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomDialogHandler -constructor TCustomDialogHandler.Create(const events: IChromiumEvents); +constructor TCustomDialogHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomDialogHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; +procedure TCustomDialogHandler.RemoveReferences; +begin + FEvents := nil; +end; + function TCustomDialogHandler.OnFileDialog(const browser : ICefBrowser; mode : TCefFileDialogMode; const title : ustring; @@ -143,10 +162,12 @@ function TCustomDialogHandler.OnFileDialog(const browser : ICefBrow selectedAcceptFilter : Integer; const callback : ICefFileDialogCallback): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnFileDialog(browser, mode, title, defaultFilePath, acceptFilters, selectedAcceptFilter, callback) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnFileDialog(browser, mode, title, defaultFilePath, + acceptFilters, selectedAcceptFilter, callback) else - Result := inherited OnFileDialog(browser, mode, title, defaultFilePath, acceptFilters, selectedAcceptFilter, callback); + Result := inherited OnFileDialog(browser, mode, title, defaultFilePath, + acceptFilters, selectedAcceptFilter, callback); end; end. diff --git a/source/uCEFDisplayHandler.pas b/source/uCEFDisplayHandler.pas index e6ec110e..2d4ea0b6 100644 --- a/source/uCEFDisplayHandler.pas +++ b/source/uCEFDisplayHandler.pas @@ -63,16 +63,18 @@ type procedure OnFullScreenModeChange(const browser: ICefBrowser; fullscreen: Boolean); virtual; function OnTooltip(const browser: ICefBrowser; var text: ustring): Boolean; virtual; procedure OnStatusMessage(const browser: ICefBrowser; const value: ustring); virtual; - function OnConsoleMessage(const browser: ICefBrowser; const message, source: ustring; line: Integer): Boolean; virtual; + function OnConsoleMessage(const browser: ICefBrowser; level: TCefLogSeverity; const message, source: ustring; line: Integer): Boolean; virtual; function OnAutoResize(const browser: ICefBrowser; const new_size: PCefSize): Boolean; virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomDisplayHandler = class(TCefDisplayHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; procedure OnAddressChange(const browser: ICefBrowser; const frame: ICefFrame; const url: ustring); override; procedure OnTitleChange(const browser: ICefBrowser; const title: ustring); override; @@ -80,22 +82,31 @@ type procedure OnFullScreenModeChange(const browser: ICefBrowser; fullscreen: Boolean); override; function OnTooltip(const browser: ICefBrowser; var text: ustring): Boolean; override; procedure OnStatusMessage(const browser: ICefBrowser; const value: ustring); override; - function OnConsoleMessage(const browser: ICefBrowser; const message, source: ustring; line: Integer): Boolean; override; + function OnConsoleMessage(const browser: ICefBrowser; level: TCefLogSeverity; const message, source: ustring; line: Integer): Boolean; override; function OnAutoResize(const browser: ICefBrowser; const new_size: PCefSize): Boolean; override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFFrame; procedure cef_display_handler_on_address_change(self: PCefDisplayHandler; - browser: PCefBrowser; frame: PCefFrame; const url: PCefString); stdcall; + browser: PCefBrowser; + frame: PCefFrame; + const url: PCefString); stdcall; begin with TCefDisplayHandlerOwn(CefGetObject(self)) do OnAddressChange( @@ -105,14 +116,16 @@ begin end; procedure cef_display_handler_on_title_change(self: PCefDisplayHandler; - browser: PCefBrowser; const title: PCefString); stdcall; + browser: PCefBrowser; + const title: PCefString); stdcall; begin with TCefDisplayHandlerOwn(CefGetObject(self)) do OnTitleChange(TCefBrowserRef.UnWrap(browser), CefString(title)); end; procedure cef_display_handler_on_favicon_urlchange(self: PCefDisplayHandler; - browser: PCefBrowser; icon_urls: TCefStringList); stdcall; + browser: PCefBrowser; + icon_urls: TCefStringList); stdcall; var list: TStringList; i: Integer; @@ -134,14 +147,16 @@ begin end; procedure cef_display_handler_on_fullscreen_mode_change(self: PCefDisplayHandler; - browser: PCefBrowser; fullscreen: Integer); stdcall; + browser: PCefBrowser; + fullscreen: Integer); stdcall; begin with TCefDisplayHandlerOwn(CefGetObject(self)) do OnFullScreenModeChange(TCefBrowserRef.UnWrap(browser), fullscreen <> 0); end; function cef_display_handler_on_tooltip(self: PCefDisplayHandler; - browser: PCefBrowser; text: PCefString): Integer; stdcall; + browser: PCefBrowser; + text: PCefString): Integer; stdcall; var t: ustring; begin @@ -153,22 +168,27 @@ begin end; procedure cef_display_handler_on_status_message(self: PCefDisplayHandler; - browser: PCefBrowser; const value: PCefString); stdcall; + browser: PCefBrowser; + const value: PCefString); stdcall; begin with TCefDisplayHandlerOwn(CefGetObject(self)) do OnStatusMessage(TCefBrowserRef.UnWrap(browser), CefString(value)); end; function cef_display_handler_on_console_message(self: PCefDisplayHandler; - browser: PCefBrowser; const message: PCefString; - const source: PCefString; line: Integer): Integer; stdcall; + browser: PCefBrowser; + level: TCefLogSeverity; + const message: PCefString; + const source: PCefString; + line: Integer): Integer; stdcall; begin with TCefDisplayHandlerOwn(CefGetObject(self)) do - Result := Ord(OnConsoleMessage(TCefBrowserRef.UnWrap(browser), - CefString(message), CefString(source), line)); + Result := Ord(OnConsoleMessage(TCefBrowserRef.UnWrap(browser), level, CefString(message), CefString(source), line)); end; -function cef_display_handler_on_auto_resize(self: PCefDisplayHandler; browser: PCefBrowser; const new_size: PCefSize): Integer; stdcall; +function cef_display_handler_on_auto_resize(self: PCefDisplayHandler; + browser: PCefBrowser; + const new_size: PCefSize): Integer; stdcall; begin Result := Ord(TCefDisplayHandlerOwn(CefGetObject(self)).OnAutoResize(TCefBrowserRef.UnWrap(browser), new_size)); end; @@ -196,7 +216,7 @@ begin end; -function TCefDisplayHandlerOwn.OnConsoleMessage(const browser: ICefBrowser; const message, source: ustring; line: Integer): Boolean; +function TCefDisplayHandlerOwn.OnConsoleMessage(const browser: ICefBrowser; level: TCefLogSeverity; const message, source: ustring; line: Integer): Boolean; begin Result := False; end; @@ -232,72 +252,83 @@ begin Result := False; end; +procedure TCefDisplayHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomDisplayHandler -constructor TCustomDisplayHandler.Create(const events: IChromiumEvents); +constructor TCustomDisplayHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomDisplayHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; +procedure TCustomDisplayHandler.RemoveReferences; +begin + FEvents := nil; +end; + procedure TCustomDisplayHandler.OnAddressChange(const browser : ICefBrowser; const frame : ICefFrame; const url : ustring); begin - if (FEvent <> nil) then FEvent.doOnAddressChange(browser, frame, url); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnAddressChange(browser, frame, url); end; function TCustomDisplayHandler.OnConsoleMessage(const browser : ICefBrowser; + level : TCefLogSeverity; const message : ustring; const source : ustring; line : Integer): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnConsoleMessage(browser, message, source, line) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnConsoleMessage(browser, level, message, source, line) else - Result := inherited OnConsoleMessage(browser, message, source, line); + Result := inherited OnConsoleMessage(browser, level, message, source, line); end; function TCustomDisplayHandler.OnAutoResize(const browser: ICefBrowser; const new_size: PCefSize): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnAutoResize(browser, new_size) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnAutoResize(browser, new_size) else Result := inherited OnAutoResize(browser, new_size); end; procedure TCustomDisplayHandler.OnFaviconUrlChange(const browser: ICefBrowser; iconUrls: TStrings); begin - if (FEvent <> nil) then FEvent.doOnFaviconUrlChange(browser, iconUrls); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnFaviconUrlChange(browser, iconUrls); end; procedure TCustomDisplayHandler.OnFullScreenModeChange(const browser: ICefBrowser; fullscreen: Boolean); begin - if (FEvent <> nil) then FEvent.doOnFullScreenModeChange(browser, fullscreen); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnFullScreenModeChange(browser, fullscreen); end; procedure TCustomDisplayHandler.OnStatusMessage(const browser: ICefBrowser; const value: ustring); begin - if (FEvent <> nil) then FEvent.doOnStatusMessage(browser, value); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnStatusMessage(browser, value); end; procedure TCustomDisplayHandler.OnTitleChange(const browser: ICefBrowser; const title: ustring); begin - if (FEvent <> nil) then FEvent.doOnTitleChange(browser, title); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnTitleChange(browser, title); end; function TCustomDisplayHandler.OnTooltip(const browser: ICefBrowser; var text: ustring): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnTooltip(browser, text) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnTooltip(browser, text) else Result := inherited OnTooltip(browser, text); end; diff --git a/source/uCEFDownloadHandler.pas b/source/uCEFDownloadHandler.pas index fa9c9880..0673f4b5 100644 --- a/source/uCEFDownloadHandler.pas +++ b/source/uCEFDownloadHandler.pas @@ -55,19 +55,23 @@ type procedure OnBeforeDownload(const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const suggestedName: ustring; const callback: ICefBeforeDownloadCallback); virtual; procedure OnDownloadUpdated(const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const callback: ICefDownloadItemCallback); virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomDownloadHandler = class(TCefDownloadHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; procedure OnBeforeDownload(const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const suggestedName: ustring; const callback: ICefBeforeDownloadCallback); override; procedure OnDownloadUpdated(const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const callback: ICefDownloadItemCallback); override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; @@ -99,11 +103,12 @@ end; constructor TCefDownloadHandlerOwn.Create; begin inherited CreateData(SizeOf(TCefDownloadHandler)); + with PCefDownloadHandler(FData)^ do - begin - on_before_download := cef_download_handler_on_before_download; - on_download_updated := cef_download_handler_on_download_updated; - end; + begin + on_before_download := cef_download_handler_on_before_download; + on_download_updated := cef_download_handler_on_download_updated; + end; end; procedure TCefDownloadHandlerOwn.OnBeforeDownload(const browser: ICefBrowser; @@ -120,36 +125,45 @@ begin end; +procedure TCefDownloadHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomDownloadHandler -constructor TCustomDownloadHandler.Create(const events: IChromiumEvents); +constructor TCustomDownloadHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomDownloadHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; -procedure TCustomDownloadHandler.OnBeforeDownload(const browser: ICefBrowser; - const downloadItem: ICefDownloadItem; const suggestedName: ustring; - const callback: ICefBeforeDownloadCallback); +procedure TCustomDownloadHandler.RemoveReferences; begin - if (FEvent <> nil) then - FEvent.doOnBeforeDownload(browser, downloadItem, suggestedName, callback); + FEvents := nil; end; -procedure TCustomDownloadHandler.OnDownloadUpdated(const browser: ICefBrowser; - const downloadItem: ICefDownloadItem; - const callback: ICefDownloadItemCallback); +procedure TCustomDownloadHandler.OnBeforeDownload(const browser : ICefBrowser; + const downloadItem : ICefDownloadItem; + const suggestedName : ustring; + const callback : ICefBeforeDownloadCallback); begin - if (FEvent <> nil) then - FEvent.doOnDownloadUpdated(browser, downloadItem, callback); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnBeforeDownload(browser, downloadItem, suggestedName, callback); +end; + +procedure TCustomDownloadHandler.OnDownloadUpdated(const browser : ICefBrowser; + const downloadItem : ICefDownloadItem; + const callback : ICefDownloadItemCallback); +begin + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnDownloadUpdated(browser, downloadItem, callback); end; end. diff --git a/source/uCEFDragHandler.pas b/source/uCEFDragHandler.pas index f69ba6ab..d1d291ae 100644 --- a/source/uCEFDragHandler.pas +++ b/source/uCEFDragHandler.pas @@ -52,28 +52,37 @@ uses type TCefDragHandlerOwn = class(TCefBaseRefCountedOwn, ICefDragHandler) protected - function OnDragEnter(const browser: ICefBrowser; const dragData: ICefDragData; mask: TCefDragOperations): Boolean; virtual; + function OnDragEnter(const browser: ICefBrowser; const dragData: ICefDragData; mask: TCefDragOperations): Boolean; virtual; procedure OnDraggableRegionsChanged(const browser: ICefBrowser; regionsCount: NativeUInt; regions: PCefDraggableRegionArray); virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomDragHandler = class(TCefDragHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; function OnDragEnter(const browser: ICefBrowser; const dragData: ICefDragData; mask: TCefDragOperations): Boolean; override; procedure OnDraggableRegionsChanged(const browser: ICefBrowser; regionsCount: NativeUInt; regions: PCefDraggableRegionArray); override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFDragData; function cef_drag_handler_on_drag_enter(self: PCefDragHandler; browser: PCefBrowser; @@ -113,34 +122,47 @@ begin end; +procedure TCefDragHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomDragHandler -constructor TCustomDragHandler.Create(const events: IChromiumEvents); +constructor TCustomDragHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomDragHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; -function TCustomDragHandler.OnDragEnter(const browser: ICefBrowser; const dragData: ICefDragData; mask: TCefDragOperations): Boolean; +procedure TCustomDragHandler.RemoveReferences; begin - if (FEvent <> nil) then - Result := FEvent.doOnDragEnter(browser, dragData, mask) + FEvents := nil; +end; + +function TCustomDragHandler.OnDragEnter(const browser : ICefBrowser; + const dragData : ICefDragData; + mask : TCefDragOperations): Boolean; +begin + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnDragEnter(browser, dragData, mask) else Result := inherited OnDragEnter(browser, dragData, mask); end; -procedure TCustomDragHandler.OnDraggableRegionsChanged(const browser: ICefBrowser; regionsCount: NativeUInt; regions: PCefDraggableRegionArray); +procedure TCustomDragHandler.OnDraggableRegionsChanged(const browser : ICefBrowser; + regionsCount : NativeUInt; + regions : PCefDraggableRegionArray); begin - if (FEvent <> nil) then - FEvent.doOnDraggableRegionsChanged(browser, regionsCount, regions); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnDraggableRegionsChanged(browser, regionsCount, regions); end; end. diff --git a/source/uCEFFindHandler.pas b/source/uCEFFindHandler.pas index 24cc0784..5a9bb6a7 100644 --- a/source/uCEFFindHandler.pas +++ b/source/uCEFFindHandler.pas @@ -54,24 +54,33 @@ type protected procedure OnFindResult(const browser: ICefBrowser; identifier, count: Integer; const selectionRect: PCefRect; activeMatchOrdinal: Integer; finalUpdate: Boolean); virtual; abstract; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomFindHandler = class(TCefFindHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; procedure OnFindResult(const browser: ICefBrowser; identifier, count: Integer; const selectionRect: PCefRect; activeMatchOrdinal: Integer; finalUpdate: Boolean); override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser; procedure cef_find_handler_on_find_result(self: PCefFindHandler; browser: PCefBrowser; identifier, count: Integer; const selection_rect: PCefRect; active_match_ordinal, final_update: Integer); stdcall; @@ -87,26 +96,40 @@ begin with PCefFindHandler(FData)^ do on_find_result := cef_find_handler_on_find_result; end; +procedure TCefFindHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomFindHandler -constructor TCustomFindHandler.Create(const events: IChromiumEvents); +constructor TCustomFindHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomFindHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; -procedure TCustomFindHandler.OnFindResult(const browser: ICefBrowser; identifier, count: Integer; const selectionRect: PCefRect; activeMatchOrdinal: Integer; finalUpdate: Boolean); +procedure TCustomFindHandler.RemoveReferences; begin - if (FEvent <> nil) then - FEvent.doOnFindResult(browser, identifier, count, selectionRect, activeMatchOrdinal, finalUpdate); + FEvents := nil; +end; + +procedure TCustomFindHandler.OnFindResult(const browser : ICefBrowser; + identifier : Integer; + count : Integer; + const selectionRect : PCefRect; + activeMatchOrdinal : Integer; + finalUpdate : Boolean); +begin + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnFindResult(browser, identifier, count, selectionRect, activeMatchOrdinal, finalUpdate); end; end. diff --git a/source/uCEFFocusHandler.pas b/source/uCEFFocusHandler.pas index 20c9ac78..09e81f6f 100644 --- a/source/uCEFFocusHandler.pas +++ b/source/uCEFFocusHandler.pas @@ -53,29 +53,38 @@ type TCefFocusHandlerOwn = class(TCefBaseRefCountedOwn, ICefFocusHandler) protected procedure OnTakeFocus(const browser: ICefBrowser; next: Boolean); virtual; - function OnSetFocus(const browser: ICefBrowser; source: TCefFocusSource): Boolean; virtual; + function OnSetFocus(const browser: ICefBrowser; source: TCefFocusSource): Boolean; virtual; procedure OnGotFocus(const browser: ICefBrowser); virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomFocusHandler = class(TCefFocusHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; procedure OnTakeFocus(const browser: ICefBrowser; next: Boolean); override; - function OnSetFocus(const browser: ICefBrowser; source: TCefFocusSource): Boolean; override; + function OnSetFocus(const browser: ICefBrowser; source: TCefFocusSource): Boolean; override; procedure OnGotFocus(const browser: ICefBrowser); override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events : Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser; procedure cef_focus_handler_on_take_focus(self: PCefFocusHandler; browser: PCefBrowser; next: Integer); stdcall; @@ -99,12 +108,13 @@ end; constructor TCefFocusHandlerOwn.Create; begin inherited CreateData(SizeOf(TCefFocusHandler)); + with PCefFocusHandler(FData)^ do - begin - on_take_focus := cef_focus_handler_on_take_focus; - on_set_focus := cef_focus_handler_on_set_focus; - on_got_focus := cef_focus_handler_on_got_focus; - end; + begin + on_take_focus := cef_focus_handler_on_take_focus; + on_set_focus := cef_focus_handler_on_set_focus; + on_got_focus := cef_focus_handler_on_got_focus; + end; end; function TCefFocusHandlerOwn.OnSetFocus(const browser: ICefBrowser; source: TCefFocusSource): Boolean; @@ -122,41 +132,49 @@ begin // end; +procedure TCefFocusHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomFocusHandler -constructor TCustomFocusHandler.Create(const events: IChromiumEvents); +constructor TCustomFocusHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomFocusHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; +procedure TCustomFocusHandler.RemoveReferences; +begin + FEvents := nil; +end; + procedure TCustomFocusHandler.OnGotFocus(const browser: ICefBrowser); begin - if (FEvent <> nil) then FEvent.doOnGotFocus(browser); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnGotFocus(browser); end; function TCustomFocusHandler.OnSetFocus(const browser: ICefBrowser; source: TCefFocusSource): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnSetFocus(browser, source) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnSetFocus(browser, source) else Result := inherited OnSetFocus(browser, source); end; procedure TCustomFocusHandler.OnTakeFocus(const browser: ICefBrowser; next: Boolean); begin - if (FEvent <> nil) then FEvent.doOnTakeFocus(browser, next); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnTakeFocus(browser, next); end; - - end. diff --git a/source/uCEFGeolocationHandler.pas b/source/uCEFGeolocationHandler.pas index 19afb53d..d602399b 100644 --- a/source/uCEFGeolocationHandler.pas +++ b/source/uCEFGeolocationHandler.pas @@ -52,28 +52,37 @@ uses type TCefGeolocationHandlerOwn = class(TCefBaseRefCountedOwn, ICefGeolocationHandler) protected - function OnRequestGeolocationPermission(const browser: ICefBrowser; const requestingUrl: ustring; requestId: Integer; const callback: ICefGeolocationCallback): Boolean; virtual; + function OnRequestGeolocationPermission(const browser: ICefBrowser; const requestingUrl: ustring; requestId: Integer; const callback: ICefGeolocationCallback): Boolean; virtual; procedure OnCancelGeolocationPermission(const browser: ICefBrowser; requestId: Integer); virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomGeolocationHandler = class(TCefGeolocationHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; function OnRequestGeolocationPermission(const browser: ICefBrowser; const requestingUrl: ustring; requestId: Integer; const callback: ICefGeolocationCallback): Boolean; override; procedure OnCancelGeolocationPermission(const browser: ICefBrowser; requestId: Integer); override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFGeolocationCallback; function cef_geolocation_handler_on_request_geolocation_permission(self: PCefGeolocationHandler; @@ -118,26 +127,35 @@ begin end; +procedure TCefGeolocationHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomGeolocationHandler -constructor TCustomGeolocationHandler.Create(const events: IChromiumEvents); +constructor TCustomGeolocationHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomGeolocationHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; +procedure TCustomGeolocationHandler.RemoveReferences; +begin + FEvents := nil; +end; + procedure TCustomGeolocationHandler.OnCancelGeolocationPermission(const browser: ICefBrowser; requestId: Integer); begin - if (FEvent <> nil) then - FEvent.doOnCancelGeolocationPermission(browser, requestId); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnCancelGeolocationPermission(browser, requestId); end; function TCustomGeolocationHandler.OnRequestGeolocationPermission(const browser : ICefBrowser; @@ -145,8 +163,8 @@ function TCustomGeolocationHandler.OnRequestGeolocationPermission(const browser requestId : Integer; const callback : ICefGeolocationCallback): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnRequestGeolocationPermission(browser, requestingUrl, requestId, callback) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnRequestGeolocationPermission(browser, requestingUrl, requestId, callback) else Result := inherited OnRequestGeolocationPermission(browser, requestingUrl, requestId, callback); end; diff --git a/source/uCEFInterfaces.pas b/source/uCEFInterfaces.pas index ba37d5de..59e4b6d2 100644 --- a/source/uCEFInterfaces.pas +++ b/source/uCEFInterfaces.pas @@ -166,7 +166,6 @@ type ICefPdfPrintCallback = interface(ICefBaseRefCounted) ['{F1CC58E9-2C30-4932-91AE-467C8D8EFB8E}'] procedure OnPdfPrintFinished(const path: ustring; ok: Boolean); - procedure InitializeVars; // custom procedure to clear all references end; TOnDownloadImageFinishedProc = {$IFDEF DELPHI12_UP}reference to{$ENDIF} @@ -384,7 +383,6 @@ type ICefStringVisitor = interface(ICefBaseRefCounted) ['{63ED4D6C-2FC8-4537-964B-B84C008F6158}'] procedure Visit(const str: ustring); - procedure InitializeVars; // custom procedure to clear all references end; ICefFrame = interface(ICefBaseRefCounted) @@ -530,6 +528,8 @@ type ['{3137F90A-5DC5-43C1-858D-A269F28EF4F1}'] procedure OnBeforeDownload(const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const suggestedName: ustring; const callback: ICefBeforeDownloadCallback); procedure OnDownloadUpdated(const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const callback: ICefDownloadItemCallback); + + procedure RemoveReferences; // custom procedure to clear all references end; ICefV8Exception = interface(ICefBaseRefCounted) @@ -862,7 +862,7 @@ type function GetDataResource(resourceId: Integer; var data: Pointer; var dataSize: NativeUInt): Boolean; function GetDataResourceForScale(resourceId: Integer; scaleFactor: TCefScaleFactor; var data: Pointer; var dataSize: NativeUInt): Boolean; - procedure InitializeVars; // custom procedure to clear all references + procedure RemoveReferences; // custom procedure to clear all references end; ICefBrowserProcessHandler = interface(ICefBaseRefCounted) @@ -873,7 +873,7 @@ type function GetPrintHandler : ICefPrintHandler; procedure OnScheduleMessagePumpWork(const delayMs: Int64); - procedure InitializeVars; // custom procedure to clear all references + procedure RemoveReferences; // custom procedure to clear all references end; ICefRenderProcessHandler = interface(ICefBaseRefCounted) @@ -890,7 +890,7 @@ type procedure OnFocusedNodeChanged(const browser: ICefBrowser; const frame: ICefFrame; const node: ICefDomNode); function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const aMessage: ICefProcessMessage): Boolean; - procedure InitializeVars; // custom procedure to clear all references + procedure RemoveReferences; // custom procedure to clear all references end; ICefApp = interface(ICefBaseRefCounted) @@ -920,7 +920,6 @@ type ICefDeleteCookiesCallback = interface(ICefBaseRefCounted) ['{758B79A1-B9E8-4F0D-94A0-DCE5AFADE33D}'] procedure OnComplete(numDeleted: Integer); - procedure InitializeVars; // custom procedure to clear all references end; ICefCookieManager = Interface(ICefBaseRefCounted) @@ -1208,6 +1207,8 @@ type procedure OnAfterCreated(const browser: ICefBrowser); procedure OnBeforeClose(const browser: ICefBrowser); function DoClose(const browser: ICefBrowser): Boolean; + + procedure RemoveReferences; // custom procedure to clear all references end; @@ -1253,6 +1254,8 @@ type procedure OnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: TCefTransitionType); procedure OnLoadEnd(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer); procedure OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring); + + procedure RemoveReferences; // custom procedure to clear all references end; ICefRequestCallback = interface(ICefBaseRefCounted) @@ -1264,7 +1267,7 @@ type ICefResponseFilter = interface(ICefBaseRefCounted) ['{5013BC3C-F1AE-407A-A571-A4C6B1D6831E}'] function InitFilter: Boolean; - function Filter(dataIn: Pointer; dataInSize : NativeUInt; dataInRead: PNativeUInt; dataOut: Pointer; dataOutSize : NativeUInt; dataOutWritten: PNativeUInt): TCefResponseFilterStatus; + function Filter(data_in: Pointer; data_in_size: NativeUInt; var data_in_read: NativeUInt; data_out: Pointer; data_out_size : NativeUInt; var data_out_written: NativeUInt): TCefResponseFilterStatus; end; ICefRequestHandler = interface(ICefBaseRefCounted) @@ -1285,6 +1288,8 @@ type procedure OnPluginCrashed(const browser: ICefBrowser; const pluginPath: ustring); procedure OnRenderViewReady(const browser: ICefBrowser); procedure OnRenderProcessTerminated(const browser: ICefBrowser; status: TCefTerminationStatus); + + procedure RemoveReferences; // custom procedure to clear all references end; ICefDisplayHandler = interface(ICefBaseRefCounted) @@ -1295,8 +1300,10 @@ type procedure OnFullScreenModeChange(const browser: ICefBrowser; fullscreen: Boolean); function OnTooltip(const browser: ICefBrowser; var text: ustring): Boolean; procedure OnStatusMessage(const browser: ICefBrowser; const value: ustring); - function OnConsoleMessage(const browser: ICefBrowser; const message, source: ustring; line: Integer): Boolean; + function OnConsoleMessage(const browser: ICefBrowser; level: TCefLogSeverity; const message, source: ustring; line: Integer): Boolean; function OnAutoResize(const browser: ICefBrowser; const new_size: PCefSize): Boolean; + + procedure RemoveReferences; // custom procedure to clear all references end; ICefFocusHandler = interface(ICefBaseRefCounted) @@ -1304,12 +1311,16 @@ type procedure OnTakeFocus(const browser: ICefBrowser; next: Boolean); function OnSetFocus(const browser: ICefBrowser; source: TCefFocusSource): Boolean; procedure OnGotFocus(const browser: ICefBrowser); + + procedure RemoveReferences; // custom procedure to clear all references end; ICefKeyboardHandler = interface(ICefBaseRefCounted) ['{0512F4EC-ED88-44C9-90D3-5C6D03D3B146}'] function OnPreKeyEvent(const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: TCefEventHandle; out isKeyboardShortcut: Boolean): Boolean; function OnKeyEvent(const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: TCefEventHandle): Boolean; + + procedure RemoveReferences; // custom procedure to clear all references end; ICefJsDialogHandler = interface(ICefBaseRefCounted) @@ -1318,6 +1329,8 @@ type function OnBeforeUnloadDialog(const browser: ICefBrowser; const messageText: ustring; isReload: Boolean; const callback: ICefJsDialogCallback): Boolean; procedure OnResetDialogState(const browser: ICefBrowser); procedure OnDialogClosed(const browser: ICefBrowser); + + procedure RemoveReferences; // custom procedure to clear all references end; ICefRunContextMenuCallback = interface(ICefBaseRefCounted) @@ -1332,6 +1345,8 @@ type function RunContextMenu(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel; const callback: ICefRunContextMenuCallback): Boolean; function OnContextMenuCommand(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; commandId: Integer; eventFlags: TCefEventFlags): Boolean; procedure OnContextMenuDismissed(const browser: ICefBrowser; const frame: ICefFrame); + + procedure RemoveReferences; // custom procedure to clear all references end; ICefAccessibilityHandler = interface(ICefBaseRefCounted) @@ -1343,6 +1358,8 @@ type ICefDialogHandler = interface(ICefBaseRefCounted) ['{7763F4B2-8BE1-4E80-AC43-8B825850DC67}'] function OnFileDialog(const browser: ICefBrowser; mode: TCefFileDialogMode; const title, defaultFilePath: ustring; acceptFilters: TStrings; selectedAcceptFilter: Integer; const callback: ICefFileDialogCallback): Boolean; + + procedure RemoveReferences; // custom procedure to clear all references end; ICefGeolocationCallback = interface(ICefBaseRefCounted) @@ -1354,6 +1371,8 @@ type ['{1178EE62-BAE7-4E44-932B-EAAC7A18191C}'] function OnRequestGeolocationPermission(const browser: ICefBrowser; const requestingUrl: ustring; requestId: Integer; const callback: ICefGeolocationCallback): Boolean; procedure OnCancelGeolocationPermission(const browser: ICefBrowser; requestId: Integer); + + procedure RemoveReferences; // custom procedure to clear all references end; ICefRenderHandler = interface(ICefBaseRefCounted) @@ -1371,6 +1390,8 @@ type procedure OnUpdateDragCursor(const browser: ICefBrowser; operation: TCefDragOperation); procedure OnScrollOffsetChanged(const browser: ICefBrowser; x, y: Double); procedure OnIMECompositionRangeChanged(const browser: ICefBrowser; const selected_range: PCefRange; character_boundsCount: NativeUInt; const character_bounds: PCefRect); + + procedure RemoveReferences; // custom procedure to clear all references end; ICefClient = interface(ICefBaseRefCounted) @@ -1388,7 +1409,7 @@ type function GetRequestHandler: ICefRequestHandler; function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; - procedure InitializeVars; // custom procedure to clear all references + procedure RemoveReferences; // custom procedure to clear all references end; ICefUrlRequest = interface(ICefBaseRefCounted) @@ -1481,11 +1502,15 @@ type ['{59A89579-5B18-489F-A25C-5CC25FF831FC}'] function OnDragEnter(const browser: ICefBrowser; const dragData: ICefDragData; mask: TCefDragOperations): Boolean; procedure OnDraggableRegionsChanged(const browser: ICefBrowser; regionsCount: NativeUInt; regions: PCefDraggableRegionArray); + + procedure RemoveReferences; // custom procedure to clear all references end; ICefFindHandler = interface(ICefBaseRefCounted) ['{F20DF234-BD43-42B3-A80B-D354A9E5B787}'] procedure OnFindResult(const browser: ICefBrowser; identifier, count: Integer; const selectionRect: PCefRect; activeMatchOrdinal: Integer; finalUpdate: Boolean); + + procedure RemoveReferences; // custom procedure to clear all references end; ICefRequestContextHandler = interface(ICefBaseRefCounted) @@ -1499,7 +1524,6 @@ type ICefResolveCallback = interface(ICefBaseRefCounted) ['{0C0EA252-7968-4163-A1BE-A1453576DD06}'] procedure OnResolveCompleted(result: TCefErrorCode; const resolvedIps: TStrings); - procedure InitializeVars; // custom procedure to clear all references end; ICefRequestContext = interface(ICefBaseRefCounted) @@ -1744,7 +1768,7 @@ type procedure doOnFullScreenModeChange(const browser: ICefBrowser; fullscreen: Boolean); function doOnTooltip(const browser: ICefBrowser; var text: ustring): Boolean; procedure doOnStatusMessage(const browser: ICefBrowser; const value: ustring); - function doOnConsoleMessage(const browser: ICefBrowser; const message, source: ustring; line: Integer): Boolean; + function doOnConsoleMessage(const browser: ICefBrowser; level: TCefLogSeverity; const message, source: ustring; line: Integer): Boolean; function doOnAutoResize(const browser: ICefBrowser; const new_size: PCefSize): Boolean; // ICefDownloadHandler @@ -1812,12 +1836,6 @@ type // Custom procedure doCookiesDeleted(numDeleted : integer); - procedure doGetHTML(const aFrameName : ustring); overload; - procedure doGetHTML(const aFrame : ICefFrame); overload; - procedure doGetHTML(const aFrameIdentifier : int64); overload; - procedure doGetText(const aFrameName : ustring); overload; - procedure doGetText(const aFrame : ICefFrame); overload; - procedure doGetText(const aFrameIdentifier : int64); overload; procedure doPdfPrintFinished(aResultOK : boolean); procedure doTextResultAvailable(const aText : string); procedure doUpdatePreferences; diff --git a/source/uCEFJsDialogHandler.pas b/source/uCEFJsDialogHandler.pas index 968a69b0..83af1e1d 100644 --- a/source/uCEFJsDialogHandler.pas +++ b/source/uCEFJsDialogHandler.pas @@ -57,27 +57,36 @@ type procedure OnResetDialogState(const browser: ICefBrowser); virtual; procedure OnDialogClosed(const browser: ICefBrowser); virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomJsDialogHandler = class(TCefJsDialogHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; function OnJsdialog(const browser: ICefBrowser; const originUrl: ustring; dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring; const callback: ICefJsDialogCallback; out suppressMessage: Boolean): Boolean; override; function OnBeforeUnloadDialog(const browser: ICefBrowser; const messageText: ustring; isReload: Boolean; const callback: ICefJsDialogCallback): Boolean; override; procedure OnResetDialogState(const browser: ICefBrowser); override; procedure OnDialogClosed(const browser: ICefBrowser); override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFJsDialogCallback; function cef_jsdialog_handler_on_jsdialog(self : PCefJsDialogHandler; @@ -168,36 +177,46 @@ begin end; +procedure TCefJsDialogHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomJsDialogHandler -constructor TCustomJsDialogHandler.Create(const events: IChromiumEvents); +constructor TCustomJsDialogHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomJsDialogHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; +procedure TCustomJsDialogHandler.RemoveReferences; +begin + FEvents := nil; +end; + function TCustomJsDialogHandler.OnBeforeUnloadDialog(const browser : ICefBrowser; const messageText : ustring; isReload : Boolean; const callback : ICefJsDialogCallback): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnBeforeUnloadDialog(browser, messageText, isReload, callback) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnBeforeUnloadDialog(browser, messageText, isReload, callback) else Result := inherited OnBeforeUnloadDialog(browser, messageText, isReload, callback); end; procedure TCustomJsDialogHandler.OnDialogClosed(const browser: ICefBrowser); begin - if (FEvent <> nil) then FEvent.doOnDialogClosed(browser); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnDialogClosed(browser); end; function TCustomJsDialogHandler.OnJsdialog(const browser : ICefBrowser; @@ -210,15 +229,15 @@ function TCustomJsDialogHandler.OnJsdialog(const browser : ICefBrowser begin suppressMessage := False; - if (FEvent <> nil) then - Result := FEvent.doOnJsdialog(browser, originUrl, dialogType, messageText, defaultPromptText, callback, suppressMessage) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnJsdialog(browser, originUrl, dialogType, messageText, defaultPromptText, callback, suppressMessage) else Result := inherited OnJsdialog(browser, originUrl, dialogType, messageText, defaultPromptText, callback, suppressMessage); end; procedure TCustomJsDialogHandler.OnResetDialogState(const browser: ICefBrowser); begin - if (FEvent <> nil) then FEvent.doOnResetDialogState(browser); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnResetDialogState(browser); end; end. diff --git a/source/uCEFKeyboardHandler.pas b/source/uCEFKeyboardHandler.pas index a0da53fd..f98d83d5 100644 --- a/source/uCEFKeyboardHandler.pas +++ b/source/uCEFKeyboardHandler.pas @@ -55,25 +55,34 @@ type function OnPreKeyEvent(const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: TCefEventHandle; out isKeyboardShortcut: Boolean): Boolean; virtual; function OnKeyEvent(const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: TCefEventHandle): Boolean; virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomKeyboardHandler = class(TCefKeyboardHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; function OnPreKeyEvent(const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: TCefEventHandle; out isKeyboardShortcut: Boolean): Boolean; override; function OnKeyEvent(const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: TCefEventHandle): Boolean; override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser; function cef_keyboard_handler_on_pre_key_event(self: PCefKeyboardHandler; @@ -116,28 +125,38 @@ begin Result := False; end; +procedure TCefKeyboardHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomKeyboardHandler -constructor TCustomKeyboardHandler.Create(const events: IChromiumEvents); +constructor TCustomKeyboardHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomKeyboardHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; +procedure TCustomKeyboardHandler.RemoveReferences; +begin + FEvents := nil; +end; + function TCustomKeyboardHandler.OnKeyEvent(const browser : ICefBrowser; const event : PCefKeyEvent; osEvent : TCefEventHandle): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnKeyEvent(browser, event, osEvent) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnKeyEvent(browser, event, osEvent) else Result := inherited OnKeyEvent(browser, event, osEvent); end; @@ -147,8 +166,8 @@ function TCustomKeyboardHandler.OnPreKeyEvent(const browser : ICefBro osEvent : TCefEventHandle; out isKeyboardShortcut : Boolean): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnPreKeyEvent(browser, event, osEvent, isKeyboardShortcut) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnPreKeyEvent(browser, event, osEvent, isKeyboardShortcut) else Result := inherited OnPreKeyEvent(browser, event, osEvent, isKeyboardShortcut); end; diff --git a/source/uCEFLifeSpanHandler.pas b/source/uCEFLifeSpanHandler.pas index fc1e9c18..ff2d7261 100644 --- a/source/uCEFLifeSpanHandler.pas +++ b/source/uCEFLifeSpanHandler.pas @@ -57,27 +57,36 @@ type procedure OnBeforeClose(const browser: ICefBrowser); virtual; function DoClose(const browser: ICefBrowser): Boolean; virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomLifeSpanHandler = class(TCefLifeSpanHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; function OnBeforePopup(const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean): Boolean; override; procedure OnAfterCreated(const browser: ICefBrowser); override; procedure OnBeforeClose(const browser: ICefBrowser); override; function DoClose(const browser: ICefBrowser): Boolean; override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFClient, uCEFBrowser, uCEFFrame; function cef_life_span_handler_on_before_popup( self : PCefLifeSpanHandler; @@ -186,38 +195,48 @@ begin Result := False; end; +procedure TCefLifeSpanHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomLifeSpanHandler -constructor TCustomLifeSpanHandler.Create(const events: IChromiumEvents); +constructor TCustomLifeSpanHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomLifeSpanHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; +procedure TCustomLifeSpanHandler.RemoveReferences; +begin + FEvents := nil; +end; + function TCustomLifeSpanHandler.DoClose(const browser: ICefBrowser): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnClose(browser) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnClose(browser) else Result := inherited DoClose(browser); end; procedure TCustomLifeSpanHandler.OnAfterCreated(const browser: ICefBrowser); begin - if (FEvent <> nil) then FEvent.doOnAfterCreated(browser); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnAfterCreated(browser); end; procedure TCustomLifeSpanHandler.OnBeforeClose(const browser: ICefBrowser); begin - if (FEvent <> nil) then FEvent.doOnBeforeClose(browser); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnBeforeClose(browser); end; function TCustomLifeSpanHandler.OnBeforePopup(const browser : ICefBrowser; @@ -232,10 +251,10 @@ function TCustomLifeSpanHandler.OnBeforePopup(const browser : ICefBro var settings : TCefBrowserSettings; var noJavascriptAccess : Boolean): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnBeforePopup(browser, frame, targetUrl, targetFrameName, - targetDisposition, userGesture, popupFeatures, - windowInfo, client, settings, noJavascriptAccess) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnBeforePopup(browser, frame, targetUrl, targetFrameName, + targetDisposition, userGesture, popupFeatures, + windowInfo, client, settings, noJavascriptAccess) else Result := inherited OnBeforePopup(browser, frame, targetUrl, targetFrameName, targetDisposition, userGesture, popupFeatures, diff --git a/source/uCEFLoadHandler.pas b/source/uCEFLoadHandler.pas index 8c644fc9..50c61f40 100644 --- a/source/uCEFLoadHandler.pas +++ b/source/uCEFLoadHandler.pas @@ -57,27 +57,36 @@ type procedure OnLoadEnd(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer); virtual; procedure OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring); virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomLoadHandler = class(TCefLoadHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; procedure OnLoadingStateChange(const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean); override; procedure OnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: TCefTransitionType); override; procedure OnLoadEnd(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer); override; procedure OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring); override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFFrame; procedure cef_load_handler_on_loading_state_change(self: PCefLoadHandler; browser: PCefBrowser; isLoading, canGoBack, canGoForward: Integer); stdcall; @@ -137,40 +146,61 @@ begin // end; +procedure TCefLoadHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomLoadHandler -constructor TCustomLoadHandler.Create(const events: IChromiumEvents); +constructor TCustomLoadHandler.Create(const events : Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomLoadHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; -procedure TCustomLoadHandler.OnLoadEnd(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer); +procedure TCustomLoadHandler.RemoveReferences; begin - if (FEvent <> nil) then FEvent.doOnLoadEnd(browser, frame, httpStatusCode); + FEvents := nil; end; -procedure TCustomLoadHandler.OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring); +procedure TCustomLoadHandler.OnLoadEnd(const browser : ICefBrowser; + const frame : ICefFrame; + httpStatusCode : Integer); begin - if (FEvent <> nil) then FEvent.doOnLoadError(browser, frame, errorCode, errorText, failedUrl); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnLoadEnd(browser, frame, httpStatusCode); end; -procedure TCustomLoadHandler.OnLoadingStateChange(const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean); +procedure TCustomLoadHandler.OnLoadError(const browser : ICefBrowser; + const frame : ICefFrame; + errorCode : Integer; + const errorText : ustring; + const failedUrl : ustring); begin - if (FEvent <> nil) then FEvent.doOnLoadingStateChange(browser, isLoading, canGoBack, canGoForward); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnLoadError(browser, frame, errorCode, errorText, failedUrl); end; -procedure TCustomLoadHandler.OnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: TCefTransitionType); +procedure TCustomLoadHandler.OnLoadingStateChange(const browser : ICefBrowser; + isLoading : Boolean; + canGoBack : Boolean; + canGoForward : Boolean); begin - if (FEvent <> nil) then FEvent.doOnLoadStart(browser, frame, transitionType); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnLoadingStateChange(browser, isLoading, canGoBack, canGoForward); +end; + +procedure TCustomLoadHandler.OnLoadStart(const browser : ICefBrowser; + const frame : ICefFrame; + transitionType : TCefTransitionType); +begin + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnLoadStart(browser, frame, transitionType); end; end. diff --git a/source/uCEFPDFPrintCallback.pas b/source/uCEFPDFPrintCallback.pas index 735421b9..77487a85 100644 --- a/source/uCEFPDFPrintCallback.pas +++ b/source/uCEFPDFPrintCallback.pas @@ -54,8 +54,6 @@ type protected procedure OnPdfPrintFinished(const path: ustring; ok: Boolean); virtual; abstract; - procedure InitializeVars; virtual; abstract; - public constructor Create; virtual; end; @@ -69,24 +67,27 @@ type public constructor Create(const proc: TOnPdfPrintFinishedProc); reintroduce; destructor Destroy; override; - procedure InitializeVars; override; end; TCefCustomPDFPrintCallBack = class(TCefPdfPrintCallbackOwn) protected - FChromiumBrowser : IChromiumEvents; + FEvents : Pointer; procedure OnPdfPrintFinished(const path: ustring; aResultOK : Boolean); override; public - constructor Create(const aChromiumBrowser : IChromiumEvents); reintroduce; + constructor Create(const aEvents : IChromiumEvents); reintroduce; destructor Destroy; override; - procedure InitializeVars; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions; procedure cef_pdf_print_callback_on_pdf_print_finished(self: PCefPdfPrintCallback; const path: PCefString; ok: Integer); stdcall; @@ -116,40 +117,39 @@ end; destructor TCefFastPdfPrintCallback.Destroy; begin - InitializeVars; + FProc := nil; inherited Destroy; end; -procedure TCefFastPdfPrintCallback.InitializeVars; -begin - FProc := nil; -end; - // TCefCustomPDFPrintCallBack -constructor TCefCustomPDFPrintCallBack.Create(const aChromiumBrowser : IChromiumEvents); +constructor TCefCustomPDFPrintCallBack.Create(const aEvents : IChromiumEvents); begin inherited Create; - FChromiumBrowser := aChromiumBrowser; + FEvents := Pointer(aEvents); end; destructor TCefCustomPDFPrintCallBack.Destroy; begin - InitializeVars; + FEvents := nil; inherited Destroy; end; -procedure TCefCustomPDFPrintCallBack.InitializeVars; -begin - FChromiumBrowser := nil; -end; - procedure TCefCustomPDFPrintCallBack.OnPdfPrintFinished(const path: ustring; aResultOK : Boolean); begin - if (FChromiumBrowser <> nil) then FChromiumBrowser.doPdfPrintFinished(aResultOK); + try + try + if (FEvents <> nil) then IChromiumEvents(FEvents).doPdfPrintFinished(aResultOK); + except + on e : exception do + if CustomExceptionHandler('TCefCustomPDFPrintCallBack.OnPdfPrintFinished', e) then raise; + end; + finally + FEvents := nil; + end; end; end. diff --git a/source/uCEFRenderHandler.pas b/source/uCEFRenderHandler.pas index 9704c06a..bca3de9a 100644 --- a/source/uCEFRenderHandler.pas +++ b/source/uCEFRenderHandler.pas @@ -66,13 +66,15 @@ type procedure OnScrollOffsetChanged(const browser: ICefBrowser; x, y: Double); virtual; procedure OnIMECompositionRangeChanged(const browser: ICefBrowser; const selected_range: PCefRange; character_boundsCount: NativeUInt; const character_bounds: PCefRect); virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomRenderHandler = class(TCefRenderHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; procedure GetAccessibilityHandler(var aAccessibilityHandler : ICefAccessibilityHandler); override; function GetRootScreenRect(const browser: ICefBrowser; var rect: TCefRect): Boolean; override; @@ -88,14 +90,21 @@ type procedure OnScrollOffsetChanged(const browser: ICefBrowser; x, y: Double); override; procedure OnIMECompositionRangeChanged(const browser: ICefBrowser; const selected_range: PCefRange; character_boundsCount: NativeUInt; const character_bounds: PCefRect); override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFDragData; @@ -308,55 +317,65 @@ begin end; +procedure TCefRenderHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomRenderHandler -constructor TCustomRenderHandler.Create(const events: IChromiumEvents); +constructor TCustomRenderHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomRenderHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; +procedure TCustomRenderHandler.RemoveReferences; +begin + FEvents := nil; +end; + procedure TCustomRenderHandler.GetAccessibilityHandler(var aAccessibilityHandler : ICefAccessibilityHandler); begin - if (FEvent <> nil) then FEvent.doOnGetAccessibilityHandler(aAccessibilityHandler); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnGetAccessibilityHandler(aAccessibilityHandler); end; function TCustomRenderHandler.GetRootScreenRect(const browser: ICefBrowser; var rect: TCefRect): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnGetRootScreenRect(browser, rect) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnGetRootScreenRect(browser, rect) else Result := inherited GetRootScreenRect(browser, rect); end; function TCustomRenderHandler.GetScreenInfo(const browser: ICefBrowser; var screenInfo: TCefScreenInfo): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnGetScreenInfo(browser, screenInfo) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnGetScreenInfo(browser, screenInfo) else Result := inherited GetScreenInfo(browser, screenInfo); end; function TCustomRenderHandler.GetScreenPoint(const browser: ICefBrowser; viewX, viewY: Integer; var screenX, screenY: Integer): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnGetScreenPoint(browser, viewX, viewY, screenX, screenY) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnGetScreenPoint(browser, viewX, viewY, screenX, screenY) else Result := inherited GetScreenPoint(browser, viewX, viewY, screenX, screenY); end; function TCustomRenderHandler.GetViewRect(const browser: ICefBrowser; var rect: TCefRect): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnGetViewRect(browser, rect) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnGetViewRect(browser, rect) else Result := inherited GetViewRect(browser, rect); end; @@ -366,8 +385,7 @@ procedure TCustomRenderHandler.OnCursorChange(const browser : ICefBrows cursorType : TCefCursorType; const customCursorInfo : PCefCursorInfo); begin - if (FEvent <> nil) then - FEvent.doOnCursorChange(browser, cursor, cursorType, customCursorInfo); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnCursorChange(browser, cursor, cursorType, customCursorInfo); end; procedure TCustomRenderHandler.OnPaint(const browser : ICefBrowser; @@ -378,23 +396,22 @@ procedure TCustomRenderHandler.OnPaint(const browser : ICefBrowser; width : Integer; height : Integer); begin - if (FEvent <> nil) then - FEvent.doOnPaint(browser, kind, dirtyRectsCount, dirtyRects, buffer, width, height); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnPaint(browser, kind, dirtyRectsCount, dirtyRects, buffer, width, height); end; procedure TCustomRenderHandler.OnPopupShow(const browser: ICefBrowser; show: Boolean); begin - if (FEvent <> nil) then FEvent.doOnPopupShow(browser, show); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnPopupShow(browser, show); end; procedure TCustomRenderHandler.OnPopupSize(const browser: ICefBrowser; const rect: PCefRect); begin - if (FEvent <> nil) then FEvent.doOnPopupSize(browser, rect); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnPopupSize(browser, rect); end; procedure TCustomRenderHandler.OnScrollOffsetChanged(const browser: ICefBrowser; x, y: Double); begin - if (FEvent <> nil) then FEvent.doOnScrollOffsetChanged(browser, x, y); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnScrollOffsetChanged(browser, x, y); end; procedure TCustomRenderHandler.OnIMECompositionRangeChanged(const browser : ICefBrowser; @@ -402,8 +419,7 @@ procedure TCustomRenderHandler.OnIMECompositionRangeChanged(const browser character_boundsCount : NativeUInt; const character_bounds : PCefRect); begin - if (FEvent <> nil) then - FEvent.doOnIMECompositionRangeChanged(browser, selected_range, character_boundsCount, character_bounds); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnIMECompositionRangeChanged(browser, selected_range, character_boundsCount, character_bounds); end; function TCustomRenderHandler.OnStartDragging(const browser : ICefBrowser; @@ -412,15 +428,15 @@ function TCustomRenderHandler.OnStartDragging(const browser : ICefBrowser; x : Integer; y : Integer): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnStartDragging(browser, dragData, allowedOps, x, y) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnStartDragging(browser, dragData, allowedOps, x, y) else Result := inherited OnStartDragging(browser, dragData, allowedOps, x, y); end; procedure TCustomRenderHandler.OnUpdateDragCursor(const browser: ICefBrowser; operation: TCefDragOperation); begin - if (FEvent <> nil) then FEvent.doOnUpdateDragCursor(browser, operation); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnUpdateDragCursor(browser, operation); end; end. diff --git a/source/uCEFRenderProcessHandler.pas b/source/uCEFRenderProcessHandler.pas index 9bd34540..56382fef 100644 --- a/source/uCEFRenderProcessHandler.pas +++ b/source/uCEFRenderProcessHandler.pas @@ -70,7 +70,7 @@ type 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; - procedure InitializeVars; virtual; abstract; + procedure RemoveReferences; virtual; abstract; public constructor Create; virtual; @@ -94,7 +94,7 @@ type public constructor Create(const aCefApp : TCefApplication); reintroduce; destructor Destroy; override; - procedure InitializeVars; override; + procedure RemoveReferences; override; end; implementation @@ -317,12 +317,12 @@ end; destructor TCefCustomRenderProcessHandler.Destroy; begin - InitializeVars; + RemoveReferences; inherited Destroy; end; -procedure TCefCustomRenderProcessHandler.InitializeVars; +procedure TCefCustomRenderProcessHandler.RemoveReferences; begin FCefApp := nil; end; diff --git a/source/uCEFRequestHandler.pas b/source/uCEFRequestHandler.pas index d67c750e..c512df6f 100644 --- a/source/uCEFRequestHandler.pas +++ b/source/uCEFRequestHandler.pas @@ -70,13 +70,15 @@ type procedure OnRenderViewReady(const browser: ICefBrowser); virtual; procedure OnRenderProcessTerminated(const browser: ICefBrowser; status: TCefTerminationStatus); virtual; + procedure RemoveReferences; virtual; + public constructor Create; virtual; end; TCustomRequestHandler = class(TCefRequestHandlerOwn) protected - FEvent: IChromiumEvents; + FEvents : Pointer; function OnBeforeBrowse(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; isRedirect: Boolean): Boolean; override; function OnOpenUrlFromTab(const browser: ICefBrowser; const frame: ICefFrame; const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean): Boolean; override; @@ -95,8 +97,10 @@ type procedure OnRenderViewReady(const browser: ICefBrowser); override; procedure OnRenderProcessTerminated(const browser: ICefBrowser; status: TCefTerminationStatus); override; + procedure RemoveReferences; override; + public - constructor Create(const events: IChromiumEvents); reintroduce; virtual; + constructor Create(const events: Pointer); reintroduce; virtual; destructor Destroy; override; end; @@ -312,25 +316,26 @@ end; constructor TCefRequestHandlerOwn.Create; begin inherited CreateData(SizeOf(TCefRequestHandler)); + with PCefRequestHandler(FData)^ do - begin - on_before_browse := cef_request_handler_on_before_browse; - on_open_urlfrom_tab := cef_request_handler_on_open_urlfrom_tab; - on_before_resource_load := cef_request_handler_on_before_resource_load; - get_resource_handler := cef_request_handler_get_resource_handler; - on_resource_redirect := cef_request_handler_on_resource_redirect; - on_resource_response := cef_request_handler_on_resource_response; - get_resource_response_filter := cef_request_handler_get_resource_response_filter; - on_resource_load_complete := cef_request_handler_on_resource_load_complete; - get_auth_credentials := cef_request_handler_get_auth_credentials; - on_quota_request := cef_request_handler_on_quota_request; - on_protocol_execution := cef_request_handler_on_protocol_execution; - on_certificate_error := cef_request_handler_on_certificate_error; - on_select_client_certificate := cef_request_handler_on_select_client_certificate; - on_plugin_crashed := cef_request_handler_on_plugin_crashed; - on_render_view_ready := cef_request_handler_on_render_view_ready; - on_render_process_terminated := cef_request_handler_on_render_process_terminated; - end; + begin + on_before_browse := cef_request_handler_on_before_browse; + on_open_urlfrom_tab := cef_request_handler_on_open_urlfrom_tab; + on_before_resource_load := cef_request_handler_on_before_resource_load; + get_resource_handler := cef_request_handler_get_resource_handler; + on_resource_redirect := cef_request_handler_on_resource_redirect; + on_resource_response := cef_request_handler_on_resource_response; + get_resource_response_filter := cef_request_handler_get_resource_response_filter; + on_resource_load_complete := cef_request_handler_on_resource_load_complete; + get_auth_credentials := cef_request_handler_get_auth_credentials; + on_quota_request := cef_request_handler_on_quota_request; + on_protocol_execution := cef_request_handler_on_protocol_execution; + on_certificate_error := cef_request_handler_on_certificate_error; + on_select_client_certificate := cef_request_handler_on_select_client_certificate; + on_plugin_crashed := cef_request_handler_on_plugin_crashed; + on_render_view_ready := cef_request_handler_on_render_view_ready; + on_render_process_terminated := cef_request_handler_on_render_process_terminated; + end; end; function TCefRequestHandlerOwn.GetAuthCredentials(const browser: ICefBrowser; const frame: ICefFrame; @@ -449,22 +454,32 @@ begin end; +procedure TCefRequestHandlerOwn.RemoveReferences; +begin + // +end; + // TCustomRequestHandler -constructor TCustomRequestHandler.Create(const events: IChromiumEvents); +constructor TCustomRequestHandler.Create(const events: Pointer); begin inherited Create; - FEvent := events; + FEvents := events; end; destructor TCustomRequestHandler.Destroy; begin - FEvent := nil; + RemoveReferences; inherited Destroy; end; +procedure TCustomRequestHandler.RemoveReferences; +begin + FEvents := nil; +end; + function TCustomRequestHandler.GetAuthCredentials(const browser : ICefBrowser; const frame : ICefFrame; isProxy : Boolean; @@ -474,8 +489,8 @@ function TCustomRequestHandler.GetAuthCredentials(const browser : ICefBrowser; const scheme : ustring; const callback : ICefAuthCallback): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnGetAuthCredentials(browser, frame, isProxy, host, port, realm, scheme, callback) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnGetAuthCredentials(browser, frame, isProxy, host, port, realm, scheme, callback) else Result := inherited GetAuthCredentials(browser, frame, isProxy, host, port, realm, scheme, callback); end; @@ -484,8 +499,8 @@ function TCustomRequestHandler.GetResourceHandler(const browser : ICefBrowser; const frame : ICefFrame; const request : ICefRequest): ICefResourceHandler; begin - if (FEvent <> nil) then - Result := FEvent.doOnGetResourceHandler(browser, frame, request) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnGetResourceHandler(browser, frame, request) else Result := inherited GetResourceHandler(browser, frame, request); end; @@ -495,7 +510,10 @@ function TCustomRequestHandler.OnBeforeBrowse(const browser : ICefBrowser; const request : ICefRequest; isRedirect : Boolean): Boolean; begin - Result := FEvent.doOnBeforeBrowse(browser, frame, request, isRedirect); + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnBeforeBrowse(browser, frame, request, isRedirect) + else + Result := inherited OnBeforeBrowse(browser, frame, request, isRedirect); end; function TCustomRequestHandler.OnBeforeResourceLoad(const browser : ICefBrowser; @@ -503,8 +521,8 @@ function TCustomRequestHandler.OnBeforeResourceLoad(const browser : ICefBrowser const request : ICefRequest; const callback : ICefRequestCallback): TCefReturnValue; begin - if (FEvent <> nil) then - Result := FEvent.doOnBeforeResourceLoad(browser, frame, request, callback) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnBeforeResourceLoad(browser, frame, request, callback) else Result := inherited OnBeforeResourceLoad(browser, frame, request, callback); end; @@ -515,8 +533,8 @@ function TCustomRequestHandler.OnCertificateError(const browser : ICefBrowser const sslInfo : ICefSslInfo; const callback : ICefRequestCallback): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnCertificateError(browser, certError, requestUrl, sslInfo, callback) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnCertificateError(browser, certError, requestUrl, sslInfo, callback) else Result := inherited OnCertificateError(browser, certError, requestUrl, sslInfo, callback); end; @@ -527,8 +545,8 @@ function TCustomRequestHandler.OnOpenUrlFromTab(const browser : ICefBr targetDisposition : TCefWindowOpenDisposition; userGesture : Boolean): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnOpenUrlFromTab(browser, frame, targetUrl, targetDisposition, userGesture) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnOpenUrlFromTab(browser, frame, targetUrl, targetDisposition, userGesture) else Result := inherited OnOpenUrlFromTab(browser, frame, targetUrl, targetDisposition, userGesture); end; @@ -541,22 +559,22 @@ function TCustomRequestHandler.OnSelectClientCertificate(const browser const certificates : TCefX509CertificateArray; const callback : ICefSelectClientCertificateCallback): boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnSelectClientCertificate(browser, isProxy, host, port, certificatesCount, certificates, callback) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnSelectClientCertificate(browser, isProxy, host, port, certificatesCount, certificates, callback) else Result := inherited OnSelectClientCertificate(browser, isProxy, host, port, certificatesCount, certificates, callback); end; procedure TCustomRequestHandler.OnPluginCrashed(const browser: ICefBrowser; const pluginPath: ustring); begin - if (FEvent <> nil) then FEvent.doOnPluginCrashed(browser, pluginPath); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnPluginCrashed(browser, pluginPath); end; procedure TCustomRequestHandler.OnProtocolExecution(const browser : ICefBrowser; const url : ustring; out allowOsExecution : Boolean); begin - if (FEvent <> nil) then FEvent.doOnProtocolExecution(browser, url, allowOsExecution); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnProtocolExecution(browser, url, allowOsExecution); end; function TCustomRequestHandler.OnQuotaRequest(const browser : ICefBrowser; @@ -564,20 +582,20 @@ function TCustomRequestHandler.OnQuotaRequest(const browser : ICefBrowser; newSize : Int64; const callback : ICefRequestCallback): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnQuotaRequest(browser, originUrl, newSize, callback) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnQuotaRequest(browser, originUrl, newSize, callback) else Result := inherited OnQuotaRequest(browser, originUrl, newSize, callback); end; procedure TCustomRequestHandler.OnRenderProcessTerminated(const browser: ICefBrowser; status: TCefTerminationStatus); begin - if (FEvent <> nil) then FEvent.doOnRenderProcessTerminated(browser, status); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnRenderProcessTerminated(browser, status); end; procedure TCustomRequestHandler.OnRenderViewReady(const browser: ICefBrowser); begin - if (FEvent <> nil) then FEvent.doOnRenderViewReady(browser); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnRenderViewReady(browser); end; procedure TCustomRequestHandler.OnResourceRedirect(const browser : ICefBrowser; @@ -586,7 +604,7 @@ procedure TCustomRequestHandler.OnResourceRedirect(const browser : ICefBrowser; const response : ICefResponse; var newUrl : ustring); begin - if (FEvent <> nil) then FEvent.doOnResourceRedirect(browser, frame, request, response, newUrl); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnResourceRedirect(browser, frame, request, response, newUrl); end; function TCustomRequestHandler.OnResourceResponse(const browser : ICefBrowser; @@ -594,8 +612,8 @@ function TCustomRequestHandler.OnResourceResponse(const browser : ICefBrowser; const request : ICefRequest; const response : ICefResponse): Boolean; begin - if (FEvent <> nil) then - Result := FEvent.doOnResourceResponse(browser, frame, request, response) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnResourceResponse(browser, frame, request, response) else Result := inherited OnResourceResponse(browser, frame, request, response); end; @@ -605,8 +623,8 @@ function TCustomRequestHandler.GetResourceResponseFilter(const browser: ICefBrow const request: ICefRequest; const response: ICefResponse): ICefResponseFilter; begin - if (FEvent <> nil) then - Result := FEvent.doOnGetResourceResponseFilter(browser, frame, request, response) + if (FEvents <> nil) then + Result := IChromiumEvents(FEvents).doOnGetResourceResponseFilter(browser, frame, request, response) else Result := inherited GetResourceResponseFilter(browser, frame, request, response); end; @@ -618,8 +636,7 @@ procedure TCustomRequestHandler.OnResourceLoadComplete(const browser status : TCefUrlRequestStatus; receivedContentLength : Int64); begin - if (FEvent <> nil) then - FEvent.doOnResourceLoadComplete(browser, frame, request, response, status, receivedContentLength); + if (FEvents <> nil) then IChromiumEvents(FEvents).doOnResourceLoadComplete(browser, frame, request, response, status, receivedContentLength); end; end. diff --git a/source/uCEFResolveCallback.pas b/source/uCEFResolveCallback.pas index 5e1c1945..400d9d9f 100644 --- a/source/uCEFResolveCallback.pas +++ b/source/uCEFResolveCallback.pas @@ -58,7 +58,6 @@ type TCefResolveCallbackOwn = class(TCefBaseRefCountedOwn, ICefResolveCallback) protected procedure OnResolveCompleted(result: TCefErrorCode; const resolvedIps: TStrings); virtual; abstract; - procedure InitializeVars; virtual; abstract; public constructor Create; virtual; @@ -66,13 +65,13 @@ type TCefCustomResolveCallback = class(TCefResolveCallbackOwn) protected - FChromiumBrowser : IChromiumEvents; + FEvents : Pointer; + procedure OnResolveCompleted(result: TCefErrorCode; const resolvedIps: TStrings); override; public - constructor Create(const aChromiumBrowser : IChromiumEvents); reintroduce; + constructor Create(const aEvents : IChromiumEvents); reintroduce; destructor Destroy; override; - procedure InitializeVars; override; end; implementation @@ -126,28 +125,32 @@ end; // TCefCustomResolveCallback -constructor TCefCustomResolveCallback.Create(const aChromiumBrowser : IChromiumEvents); +constructor TCefCustomResolveCallback.Create(const aEvents : IChromiumEvents); begin inherited Create; - FChromiumBrowser := aChromiumBrowser; + FEvents := Pointer(aEvents); end; destructor TCefCustomResolveCallback.Destroy; begin - InitializeVars; + FEvents := nil; inherited Destroy; end; -procedure TCefCustomResolveCallback.InitializeVars; -begin - FChromiumBrowser := nil; -end; - procedure TCefCustomResolveCallback.OnResolveCompleted(result: TCefErrorCode; const resolvedIps: TStrings); begin - if (FChromiumBrowser <> nil) then FChromiumBrowser.doResolvedHostAvailable(result, resolvedIps); + try + try + if (FEvents <> nil) then IChromiumEvents(FEvents).doResolvedHostAvailable(result, resolvedIps); + except + on e : exception do + if CustomExceptionHandler('TCefCustomResolveCallback.OnResolveCompleted', e) then raise; + end; + finally + FEvents := nil; + end; end; end. diff --git a/source/uCEFResourceBundleHandler.pas b/source/uCEFResourceBundleHandler.pas index 6f6fc5ab..2052d03a 100644 --- a/source/uCEFResourceBundleHandler.pas +++ b/source/uCEFResourceBundleHandler.pas @@ -56,7 +56,7 @@ type function GetDataResource(resourceId: Integer; var data: Pointer; var dataSize: NativeUInt): Boolean; virtual; abstract; function GetDataResourceForScale(resourceId: Integer; scaleFactor: TCefScaleFactor; var data: Pointer; var dataSize: NativeUInt): Boolean; virtual; abstract; - procedure InitializeVars; virtual; abstract; + procedure RemoveReferences; virtual; abstract; public constructor Create; virtual; @@ -73,7 +73,7 @@ type public constructor Create(const aCefApp : TCefApplication); reintroduce; destructor Destroy; override; - procedure InitializeVars; override; + procedure RemoveReferences; override; end; implementation @@ -157,12 +157,12 @@ end; destructor TCefCustomResourceBundleHandler.Destroy; begin - InitializeVars; + RemoveReferences; inherited Destroy; end; -procedure TCefCustomResourceBundleHandler.InitializeVars; +procedure TCefCustomResourceBundleHandler.RemoveReferences; begin FCefApp := nil; end; diff --git a/source/uCEFResponseFilter.pas b/source/uCEFResponseFilter.pas index bb23c88f..cf1d6310 100644 --- a/source/uCEFResponseFilter.pas +++ b/source/uCEFResponseFilter.pas @@ -50,12 +50,32 @@ uses uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes; type + TOnFilterEvent = procedure(Sender: TObject; data_in: Pointer; data_in_size: NativeUInt; var data_in_read: NativeUInt; data_out: Pointer; data_out_size : NativeUInt; var data_out_written: NativeUInt; var aResult : TCefResponseFilterStatus) of object; + TOnInitFilterEvent = procedure(Sender: TObject; var aResult : boolean) of object; + + TCefResponseFilterOwn = class(TCefBaseRefCountedOwn, ICefResponseFilter) - protected - function InitFilter: Boolean; virtual; abstract; - function Filter(dataIn: Pointer; dataInSize : NativeUInt; dataInRead: PNativeUInt; dataOut: Pointer; dataOutSize : NativeUInt; dataOutWritten: PNativeUInt): TCefResponseFilterStatus; virtual; abstract; - public - constructor Create; virtual; + protected + function InitFilter: Boolean; virtual; abstract; + function Filter(data_in: Pointer; data_in_size: NativeUInt; var data_in_read: NativeUInt; data_out: Pointer; data_out_size : NativeUInt; var data_out_written: NativeUInt): TCefResponseFilterStatus; virtual; abstract; + + public + constructor Create; virtual; + end; + + TCustomResponseFilter = class(TCefResponseFilterOwn) + protected + FOnFilter : TOnFilterEvent; + FOnInitFilter : TOnInitFilterEvent; + + function InitFilter: Boolean; override; + function Filter(data_in: Pointer; data_in_size: NativeUInt; var data_in_read: NativeUInt; data_out: Pointer; data_out_size : NativeUInt; var data_out_written: NativeUInt): TCefResponseFilterStatus; override; + + public + constructor Create; override; + + property OnFilter : TOnFilterEvent read FOnFilter write FOnFilter; + property OnInitFilter : TOnInitFilterEvent read FOnInitFilter write FOnInitFilter; end; implementation @@ -63,27 +83,70 @@ implementation uses uCEFMiscFunctions, uCEFLibFunctions; +// TCefResponseFilterOwn + function cef_response_filter_init_filter(self: PCefResponseFilter): Integer; stdcall; begin - with TCefResponseFilterOwn(CefGetObject(self)) do - Result := Ord(InitFilter()); + with TCefResponseFilterOwn(CefGetObject(self)) do Result := Ord(InitFilter()); end; -function cef_response_filter_filter(self: PCefResponseFilter; data_in: Pointer; data_in_size : NativeUInt; var data_in_read: NativeUInt; - data_out: Pointer; data_out_size: NativeUInt; var data_out_written: NativeUInt): TCefResponseFilterStatus; stdcall; +function cef_response_filter_filter(self: PCefResponseFilter; + data_in: Pointer; + data_in_size : NativeUInt; + var data_in_read: NativeUInt; + data_out: Pointer; + data_out_size: NativeUInt; + var data_out_written: NativeUInt): TCefResponseFilterStatus; stdcall; begin with TCefResponseFilterOwn(CefGetObject(self)) do - Result := Filter(data_in, data_in_size, @data_in_read, data_out, data_out_size, @data_out_written); + Result := Filter(data_in, data_in_size, data_in_read, + data_out, data_out_size, data_out_written); end; constructor TCefResponseFilterOwn.Create; begin CreateData(SizeOf(TCefResponseFilter)); + with PCefResponseFilter(FData)^ do - begin - init_filter := cef_response_filter_init_filter; - filter := cef_response_filter_filter; - end; + begin + init_filter := cef_response_filter_init_filter; + filter := cef_response_filter_filter; + end; end; + +// TCustomResponseFilter + + +constructor TCustomResponseFilter.Create; +begin + inherited Create; + + FOnFilter := nil; + FOnInitFilter := nil; +end; + +function TCustomResponseFilter.InitFilter: Boolean; +begin + Result := True; + if assigned(FOnInitFilter) then FOnInitFilter(self, Result); +end; + +function TCustomResponseFilter.Filter( data_in : Pointer; + data_in_size : NativeUInt; + var data_in_read : NativeUInt; + data_out : Pointer; + data_out_size : NativeUInt; + var data_out_written : NativeUInt) : TCefResponseFilterStatus; +begin + Result := RESPONSE_FILTER_DONE; + + if assigned(FOnFilter) then + FOnFilter(self, + data_in, data_in_size, data_in_read, + data_out, data_out_size, data_out_written, + Result); +end; + + end. diff --git a/source/uCEFServerHandler.pas b/source/uCEFServerHandler.pas index 536eb58b..dd4c7fbf 100644 --- a/source/uCEFServerHandler.pas +++ b/source/uCEFServerHandler.pas @@ -86,6 +86,11 @@ type implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFServer, uCEFRequest, uCEFCallback; // ************************************************************** @@ -248,42 +253,82 @@ end; procedure TCustomServerHandler.OnServerCreated(const server: ICefServer); begin - if (FEvents <> nil) then FEvents.doOnServerCreated(server); + try + if (FEvents <> nil) then FEvents.doOnServerCreated(server); + except + on e : exception do + if CustomExceptionHandler('TCustomServerHandler.OnServerCreated', e) then raise; + end; end; procedure TCustomServerHandler.OnServerDestroyed(const server: ICefServer); begin - if (FEvents <> nil) then FEvents.doOnServerDestroyed(server); + try + if (FEvents <> nil) then FEvents.doOnServerDestroyed(server); + except + on e : exception do + if CustomExceptionHandler('TCustomServerHandler.OnServerDestroyed', e) then raise; + end; end; procedure TCustomServerHandler.OnClientConnected(const server: ICefServer; connection_id: Integer); begin - if (FEvents <> nil) then FEvents.doOnClientConnected(server, connection_id); + try + if (FEvents <> nil) then FEvents.doOnClientConnected(server, connection_id); + except + on e : exception do + if CustomExceptionHandler('TCustomServerHandler.OnClientConnected', e) then raise; + end; end; procedure TCustomServerHandler.OnClientDisconnected(const server: ICefServer; connection_id: Integer); begin - if (FEvents <> nil) then FEvents.doOnClientDisconnected(server, connection_id); + try + if (FEvents <> nil) then FEvents.doOnClientDisconnected(server, connection_id); + except + on e : exception do + if CustomExceptionHandler('TCustomServerHandler.OnClientDisconnected', e) then raise; + end; end; procedure TCustomServerHandler.OnHttpRequest(const server: ICefServer; connection_id: Integer; const client_address: ustring; const request: ICefRequest); begin - if (FEvents <> nil) then FEvents.doOnHttpRequest(server, connection_id, client_address, request); + try + if (FEvents <> nil) then FEvents.doOnHttpRequest(server, connection_id, client_address, request); + except + on e : exception do + if CustomExceptionHandler('TCustomServerHandler.OnHttpRequest', e) then raise; + end; end; procedure TCustomServerHandler.OnWebSocketRequest(const server: ICefServer; connection_id: Integer; const client_address: ustring; const request: ICefRequest; const callback: ICefCallback); begin - if (FEvents <> nil) then FEvents.doOnWebSocketRequest(server, connection_id, client_address, request, callback); + try + if (FEvents <> nil) then FEvents.doOnWebSocketRequest(server, connection_id, client_address, request, callback); + except + on e : exception do + if CustomExceptionHandler('TCustomServerHandler.OnWebSocketRequest', e) then raise; + end; end; procedure TCustomServerHandler.OnWebSocketConnected(const server: ICefServer; connection_id: Integer); begin + try if (FEvents <> nil) then FEvents.doOnWebSocketConnected(server, connection_id); + except + on e : exception do + if CustomExceptionHandler('TCustomServerHandler.OnWebSocketConnected', e) then raise; + end; end; procedure TCustomServerHandler.OnWebSocketMessage(const server: ICefServer; connection_id: Integer; const data: Pointer; data_size: NativeUInt); begin - if (FEvents <> nil) then FEvents.doOnWebSocketMessage(server, connection_id, data, data_size); + try + if (FEvents <> nil) then FEvents.doOnWebSocketMessage(server, connection_id, data, data_size); + except + on e : exception do + if CustomExceptionHandler('TCustomServerHandler.OnWebSocketMessage', e) then raise; + end; end; end. diff --git a/source/uCEFStringVisitor.pas b/source/uCEFStringVisitor.pas index 992061cc..461f4bd5 100644 --- a/source/uCEFStringVisitor.pas +++ b/source/uCEFStringVisitor.pas @@ -53,7 +53,7 @@ type TCefStringVisitorOwn = class(TCefBaseRefCountedOwn, ICefStringVisitor) protected procedure Visit(const str: ustring); virtual; - procedure InitializeVars; virtual; + procedure RemoveReferences; virtual; public constructor Create; virtual; @@ -71,19 +71,23 @@ type TCustomCefStringVisitor = class(TCefStringVisitorOwn) protected - FChromiumBrowser : IChromiumEvents; + FEvents : Pointer; procedure Visit(const str: ustring); override; public - constructor Create(const aChromiumBrowser : IChromiumEvents); reintroduce; + constructor Create(const aEvents : IChromiumEvents); reintroduce; destructor Destroy; override; - procedure InitializeVars; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions; procedure cef_string_visitor_visit(self: PCefStringVisitor; const str: PCefString); stdcall; @@ -105,7 +109,7 @@ begin // end; -procedure TCefStringVisitorOwn.InitializeVars; +procedure TCefStringVisitorOwn.RemoveReferences; begin // end; @@ -126,28 +130,32 @@ end; // TCustomCefStringVisitor -constructor TCustomCefStringVisitor.Create(const aChromiumBrowser : IChromiumEvents); +constructor TCustomCefStringVisitor.Create(const aEvents : IChromiumEvents); begin inherited Create; - FChromiumBrowser := aChromiumBrowser; + FEvents := Pointer(aEvents); end; destructor TCustomCefStringVisitor.Destroy; begin - InitializeVars; + FEvents := nil; inherited Destroy; end; -procedure TCustomCefStringVisitor.InitializeVars; -begin - FChromiumBrowser := nil; -end; - procedure TCustomCefStringVisitor.Visit(const str: ustring); begin - if (FChromiumBrowser <> nil) then FChromiumBrowser.doTextResultAvailable(str); + try + try + if (FEvents <> nil) then IChromiumEvents(FEvents).doTextResultAvailable(str); + except + on e : exception do + if CustomExceptionHandler('TCustomCefStringVisitor.Visit', e) then raise; + end; + finally + FEvents := nil; + end; end; end. diff --git a/source/uCEFTask.pas b/source/uCEFTask.pas index d2d3eb52..ac42de70 100644 --- a/source/uCEFTask.pas +++ b/source/uCEFTask.pas @@ -80,52 +80,36 @@ type constructor Create(const method: TCefFastTaskProc); reintroduce; end; - TCefGetTextTask = class(TCefTaskOwn) - protected - FChromiumBrowser : IChromiumEvents; - FFrameName : ustring; - FFrame : ICefFrame; - FFrameIdentifier : int64; - - procedure Execute; override; - - public - constructor Create(const aChromiumBrowser : IChromiumEvents; const aFrameName : ustring); reintroduce; overload; - constructor Create(const aChromiumBrowser : IChromiumEvents; const aFrame : ICefFrame); reintroduce; overload; - constructor Create(const aChromiumBrowser : IChromiumEvents; const aFrameIdentifier : int64); reintroduce; overload; - destructor Destroy; override; - end; - - TCefGetHTMLTask = class(TCefGetTextTask) - protected - procedure Execute; override; - end; - TCefUpdatePrefsTask = class(TCefTaskOwn) protected - FChromiumBrowser : IChromiumEvents; + FEvents : Pointer; procedure Execute; override; public - constructor Create(const aChromiumBrowser : IChromiumEvents); reintroduce; + constructor Create(const aEvents : IChromiumEvents); reintroduce; destructor Destroy; override; end; TCefSavePrefsTask = class(TCefTaskOwn) protected - FChromiumBrowser : IChromiumEvents; + FEvents : Pointer; procedure Execute; override; public - constructor Create(const aChromiumBrowser : IChromiumEvents); reintroduce; + constructor Create(const aEvents : IChromiumEvents); reintroduce; destructor Destroy; override; end; implementation uses + {$IFDEF DELPHI16_UP} + System.SysUtils, + {$ELSE} + SysUtils, + {$ENDIF} uCEFMiscFunctions, uCEFLibFunctions, uCEFCookieManager; procedure cef_task_execute(self: PCefTask); stdcall; @@ -156,7 +140,7 @@ end; class function TCefTaskRef.UnWrap(data: Pointer): ICefTask; begin - if data <> nil then + if (data <> nil) then Result := Create(data) as ICefTask else Result := nil; @@ -188,122 +172,68 @@ begin CefPostDelayedTask(threadId, Create(method), Delay); end; -// TCefGetTextTask - - -constructor TCefGetTextTask.Create(const aChromiumBrowser : IChromiumEvents; const aFrameName : ustring); -begin - inherited Create; - - FChromiumBrowser := aChromiumBrowser; - FFrameName := aFrameName; - FFrame := nil; - FFrameIdentifier := 0; -end; - -constructor TCefGetTextTask.Create(const aChromiumBrowser : IChromiumEvents; const aFrame : ICefFrame); -begin - inherited Create; - - FChromiumBrowser := aChromiumBrowser; - FFrameName := ''; - FFrame := aFrame; - FFrameIdentifier := 0; -end; - -constructor TCefGetTextTask.Create(const aChromiumBrowser : IChromiumEvents; const aFrameIdentifier : int64); -begin - inherited Create; - - FChromiumBrowser := aChromiumBrowser; - FFrameName := ''; - FFrame := nil; - FFrameIdentifier := aFrameIdentifier; -end; - -destructor TCefGetTextTask.Destroy; -begin - FChromiumBrowser := nil; - FFrame := nil; - - inherited Destroy; -end; - -procedure TCefGetTextTask.Execute; -begin - if (FChromiumBrowser <> nil) then - begin - if (FFrame <> nil) then - FChromiumBrowser.doGetText(FFrame) - else - if (FFrameIdentifier <> 0) then - FChromiumBrowser.doGetText(FFrameIdentifier) - else - FChromiumBrowser.doGetText(FFrameName); - end; -end; - - -// TCefGetHTMLTask - -procedure TCefGetHTMLTask.Execute; -begin - if (FChromiumBrowser <> nil) then - begin - if (FFrame <> nil) then - FChromiumBrowser.doGetHTML(FFrame) - else - if (FFrameIdentifier <> 0) then - FChromiumBrowser.doGetHTML(FFrameIdentifier) - else - FChromiumBrowser.doGetHTML(FFrameName); - end; -end; - // TCefUpdatePrefsTask -constructor TCefUpdatePrefsTask.Create(const aChromiumBrowser : IChromiumEvents); +constructor TCefUpdatePrefsTask.Create(const aEvents : IChromiumEvents); begin inherited Create; - FChromiumBrowser := aChromiumBrowser; + FEvents := Pointer(aEvents); end; destructor TCefUpdatePrefsTask.Destroy; begin - FChromiumBrowser := nil; + FEvents := nil; inherited Destroy; end; procedure TCefUpdatePrefsTask.Execute; begin - if (FChromiumBrowser <> nil) then FChromiumBrowser.doUpdatePreferences; + try + try + if (FEvents <> nil) then IChromiumEvents(FEvents).doUpdatePreferences; + except + on e : exception do + if CustomExceptionHandler('TCefUpdatePrefsTask.Execute', e) then raise; + end; + finally + FEvents := nil; + end; end; // TCefSavePrefsTask -constructor TCefSavePrefsTask.Create(const aChromiumBrowser : IChromiumEvents); +constructor TCefSavePrefsTask.Create(const aEvents : IChromiumEvents); begin inherited Create; - FChromiumBrowser := aChromiumBrowser; + FEvents := Pointer(aEvents); end; destructor TCefSavePrefsTask.Destroy; begin - FChromiumBrowser := nil; + FEvents := nil; inherited Destroy; end; procedure TCefSavePrefsTask.Execute; begin - if (FChromiumBrowser <> nil) then FChromiumBrowser.doSavePreferences; + try + try + if (FEvents <> nil) then IChromiumEvents(FEvents).doSavePreferences; + except + on e : exception do + if CustomExceptionHandler('TCefSavePrefsTask.Execute', e) then raise; + end; + finally + FEvents := nil; + end; end; end. diff --git a/source/uCEFTypes.pas b/source/uCEFTypes.pas index 85fc8acd..0737caa1 100644 --- a/source/uCEFTypes.pas +++ b/source/uCEFTypes.pas @@ -231,6 +231,7 @@ type TCefContextMenuEditStateFlags = Cardinal; // /include/internal/cef_types.h (cef_context_menu_edit_state_flags_t) TCefJsonWriterOptions = Cardinal; // /include/internal/cef_types.h (cef_json_writer_options_t) TCefSSLContentStatus = Cardinal; // /include/internal/cef_types.h (cef_ssl_content_status_t) + TCefLogSeverity = Cardinal; // /include/internal/cef_types.h (cef_log_severity_t) {$IFNDEF DELPHI12_UP} NativeUInt = Cardinal; @@ -403,16 +404,6 @@ type STATE_DISABLED ); - // /include/internal/cef_types.h (cef_log_severity_t) - TCefLogSeverity = ( - LOGSEVERITY_DEFAULT, - LOGSEVERITY_VERBOSE, - LOGSEVERITY_INFO, - LOGSEVERITY_WARNING, - LOGSEVERITY_ERROR, - LOGSEVERITY_DISABLE = 99 - ); - // /include/internal/cef_types.h (cef_scale_factor_t) TCefScaleFactor = ( SCALE_FACTOR_NONE = 0, @@ -1088,7 +1079,7 @@ type on_fullscreen_mode_change: procedure(self: PCefDisplayHandler; browser: PCefBrowser; fullscreen: Integer); stdcall; on_tooltip: function(self: PCefDisplayHandler; browser: PCefBrowser; text: PCefString): Integer; stdcall; on_status_message: procedure(self: PCefDisplayHandler; browser: PCefBrowser; const value: PCefString); stdcall; - on_console_message: function(self: PCefDisplayHandler; browser: PCefBrowser; const message: PCefString; const source: PCefString; line: Integer): Integer; stdcall; + on_console_message: function(self: PCefDisplayHandler; browser: PCefBrowser; level: TCefLogSeverity; const message: PCefString; const source: PCefString; line: Integer): Integer; stdcall; on_auto_resize: function(self: PCefDisplayHandler; browser: PCefBrowser; const new_size: PCefSize): Integer; stdcall; end; diff --git a/source/uCEFv8Handler.pas b/source/uCEFv8Handler.pas index 01a3b5f1..0c9857e5 100644 --- a/source/uCEFv8Handler.pas +++ b/source/uCEFv8Handler.pas @@ -718,10 +718,16 @@ begin end; class procedure TCefRTTIExtension.Register(const name: string; const value: TValue; SyncMainThread: Boolean); +var + TempCode : ustring; + TempHandler : ICefv8Handler; begin - CefRegisterExtension(name, - format('__defineSetter__(''%s'', function(v){native function $s();$s(v)});__defineGetter__(''%0:s'', function(){native function $g();return $g()});', [name]), - TCefRTTIExtension.Create(value, SyncMainThread) as ICefv8Handler); + TempHandler := TCefRTTIExtension.Create(value, SyncMainThread); + TempCode := format('this.__defineSetter__(''%s'', function(v){native function $s();$s(v)});' + + 'this.__defineGetter__(''%0:s'', function(){native function $g();return $g()});', + [name]); + + CefRegisterExtension(name, TempCode, TempHandler); end; {$IFDEF CPUX64} diff --git a/source/uFMXChromium.pas b/source/uFMXChromium.pas index 70babc7a..7e2c2116 100644 --- a/source/uFMXChromium.pas +++ b/source/uFMXChromium.pas @@ -50,17 +50,12 @@ uses System.Classes, System.Types, FMX.Types, FMX.Platform, FMX.Controls, FMX.Forms, uCEFTypes, uCEFInterfaces, uCEFLibFunctions, uCEFMiscFunctions, uCEFClient, - uCEFPDFPrintCallback, uCEFStringVisitor, uCEFConstants, uCEFTask, - uCEFDeleteCookiesCallback, uCEFDomVisitor, uCEFChromiumEvents, - uCEFChromiumOptions, uCEFChromiumFontOptions, uCEFPDFPrintOptions; + uCEFConstants, uCEFTask, uCEFChromiumEvents, uCEFChromiumOptions, uCEFChromiumFontOptions, + uCEFPDFPrintOptions; type TFMXChromium = class(TComponent, IChromiumEvents) protected - FVisitor : ICefStringVisitor; - FPDFPrintcb : ICefPdfPrintCallback; - FResolveHostcb : ICefResolveCallback; - FCookiDeletercb : ICefDeleteCookiesCallback; FHandler : ICefClient; FBrowser : ICefBrowser; FBrowserId : Integer; @@ -253,10 +248,6 @@ type function CreateBrowserHostSync(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): ICefBrowser; procedure DestroyClientHandler; - procedure DestroyVisitor; - procedure DestroyPDFPrintcb; - procedure DestroyResolveHostcb; - procedure DestroyCookiDeletercb; procedure ClearBrowserReference; @@ -330,7 +321,7 @@ type procedure doOnFullScreenModeChange(const browser: ICefBrowser; fullscreen: Boolean); virtual; function doOnTooltip(const browser: ICefBrowser; var text: ustring): Boolean; virtual; procedure doOnStatusMessage(const browser: ICefBrowser; const value: ustring); virtual; - function doOnConsoleMessage(const browser: ICefBrowser; const aMessage, source: ustring; line: Integer): Boolean; virtual; + function doOnConsoleMessage(const browser: ICefBrowser; level: TCefLogSeverity; const aMessage, source: ustring; line: Integer): Boolean; virtual; function doOnAutoResize(const browser: ICefBrowser; const new_size: PCefSize): Boolean; virtual; // ICefDownloadHandler @@ -398,12 +389,6 @@ type // Custom procedure doCookiesDeleted(numDeleted : integer); virtual; - procedure doGetHTML(const aFrameName : ustring); overload; - procedure doGetHTML(const aFrame : ICefFrame); overload; - procedure doGetHTML(const aFrameIdentifier : int64); overload; - procedure doGetText(const aFrameName : ustring); overload; - procedure doGetText(const aFrame : ICefFrame); overload; - procedure doGetText(const aFrameIdentifier : int64); overload; procedure doPdfPrintFinished(aResultOK : boolean); virtual; procedure doTextResultAvailable(const aText : string); virtual; procedure doUpdatePreferences; virtual; @@ -659,8 +644,8 @@ implementation uses System.SysUtils, System.Math, uCEFBrowser, uCEFValue, uCEFDictionaryValue, uCEFStringMultimap, uCEFFrame, - uCEFApplication, uCEFProcessMessage, uOLEDragAndDrop, uCEFRequestContext, - uCEFResolveCallback; + uCEFApplication, uCEFProcessMessage, uCEFRequestContext, + uCEFPDFPrintCallback, uCEFResolveCallback, uCEFDeleteCookiesCallback, uCEFStringVisitor; constructor TFMXChromium.Create(AOwner: TComponent); begin @@ -673,10 +658,6 @@ begin FOptions := nil; FFontOptions := nil; FDefaultEncoding := ''; - FVisitor := nil; - FPDFPrintcb := nil; - FResolveHostcb := nil; - FCookiDeletercb := nil; FPDFPrintOptions := nil; FUpdatePreferences := False; FCustomHeaderName := ''; @@ -739,10 +720,6 @@ end; procedure TFMXChromium.BeforeDestruction; begin DestroyClientHandler; - DestroyVisitor; - DestroyPDFPrintcb; - DestroyResolveHostcb; - DestroyCookiDeletercb; inherited BeforeDestruction; end; @@ -758,7 +735,7 @@ begin try if (FHandler <> nil) then begin - FHandler.InitializeVars; + FHandler.RemoveReferences; FHandler := nil; end; except @@ -767,62 +744,6 @@ begin end; end; -procedure TFMXChromium.DestroyVisitor; -begin - try - if (FVisitor <> nil) then - begin - FVisitor.InitializeVars; - FVisitor := nil; - end; - except - on e : exception do - if CustomExceptionHandler('TFMXChromium.DestroyVisitor', e) then raise; - end; -end; - -procedure TFMXChromium.DestroyPDFPrintcb; -begin - try - if (FPDFPrintcb <> nil) then - begin - FPDFPrintcb.InitializeVars; - FPDFPrintcb := nil; - end; - except - on e : exception do - if CustomExceptionHandler('TFMXChromium.DestroyPDFPrintcb', e) then raise; - end; -end; - -procedure TFMXChromium.DestroyResolveHostcb; -begin - try - if (FResolveHostcb <> nil) then - begin - FResolveHostcb.InitializeVars; - FResolveHostcb := nil; - end; - except - on e : exception do - if CustomExceptionHandler('TFMXChromium.DestroyResolveHostcb', e) then raise; - end; -end; - -procedure TFMXChromium.DestroyCookiDeletercb; -begin - try - if (FCookiDeletercb <> nil) then - begin - FCookiDeletercb.InitializeVars; - FCookiDeletercb := nil; - end; - except - on e : exception do - if CustomExceptionHandler('TFMXChromium.DestroyCookiDeletercb', e) then raise; - end; -end; - procedure TFMXChromium.AfterConstruction; begin inherited AfterConstruction; @@ -1104,12 +1025,13 @@ end; procedure TFMXChromium.PrintToPDF(const aFilePath, aTitle, aURL : ustring); var TempSettings : TCefPdfPrintSettings; + TempCallback : ICefPdfPrintCallback; begin if Initialized then begin GetPrintPDFSettings(TempSettings, aTitle, aURL); - if (FPDFPrintcb = nil) then FPDFPrintcb := TCefCustomPDFPrintCallBack.Create(self); - FBrowser.Host.PrintToPdf(aFilePath, @TempSettings, FPDFPrintcb); + TempCallback := TCefCustomPDFPrintCallBack.Create(self); + FBrowser.Host.PrintToPdf(aFilePath, @TempSettings, TempCallback); end; end; @@ -1739,103 +1661,10 @@ begin end; end; -procedure TFMXChromium.doGetHTML(const aFrameName : ustring); -var - TempFrame : ICefFrame; -begin - if Initialized then - begin - if (length(aFrameName) > 0) then - TempFrame := FBrowser.GetFrame(aFrameName) - else - TempFrame := FBrowser.MainFrame; - - if (TempFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - TempFrame.GetSource(FVisitor); - end; - end; -end; - -procedure TFMXChromium.doGetHTML(const aFrame : ICefFrame); -begin - if Initialized and (aFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - aFrame.GetSource(FVisitor); - end; -end; - -procedure TFMXChromium.doGetHTML(const aFrameIdentifier : int64); -var - TempFrame : ICefFrame; -begin - if Initialized then - begin - if (aFrameIdentifier <> 0) then - TempFrame := FBrowser.GetFrameByident(aFrameIdentifier) - else - TempFrame := FBrowser.MainFrame; - - if (TempFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - TempFrame.GetSource(FVisitor); - end; - end; -end; - -procedure TFMXChromium.doGetText(const aFrameName : ustring); -var - TempFrame : ICefFrame; -begin - if Initialized then - begin - if (length(aFrameName) > 0) then - TempFrame := FBrowser.GetFrame(aFrameName) - else - TempFrame := FBrowser.MainFrame; - - if (TempFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - TempFrame.GetText(FVisitor); - end; - end; -end; - -procedure TFMXChromium.doGetText(const aFrame : ICefFrame); -begin - if Initialized and (aFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - aFrame.GetText(FVisitor); - end; -end; - -procedure TFMXChromium.doGetText(const aFrameIdentifier : int64); -var - TempFrame : ICefFrame; -begin - if Initialized then - begin - if (aFrameIdentifier <> 0) then - TempFrame := FBrowser.GetFrameByident(aFrameIdentifier) - else - TempFrame := FBrowser.MainFrame; - - if (TempFrame <> nil) then - begin - if (FVisitor = nil) then FVisitor := TCustomCefStringVisitor.Create(self); - TempFrame.GetText(FVisitor); - end; - end; -end; - function TFMXChromium.DeleteCookies : boolean; var - TempManager : ICefCookieManager; + TempManager : ICefCookieManager; + TempCallback : ICefDeleteCookiesCallback; begin Result := False; @@ -1845,9 +1674,8 @@ begin if (TempManager <> nil) then begin - if (FCookiDeletercb = nil) then FCookiDeletercb := TCefCustomDeleteCookiesCallback.Create(self); - - Result := TempManager.DeleteCookies('', '', FCookiDeletercb); + TempCallback := TCefCustomDeleteCookiesCallback.Create(self); + Result := TempManager.DeleteCookies('', '', TempCallback); end; end; end; @@ -1855,74 +1683,104 @@ end; // Leave aFrameName empty to get the HTML source from the main frame procedure TFMXChromium.RetrieveHTML(const aFrameName : ustring); var - TempTask: ICefTask; + TempFrame : ICefFrame; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class if Initialized then begin - TempTask := TCefGetHTMLTask.Create(self, aFrameName); - CefPostTask(TID_UI, TempTask); + if (length(aFrameName) > 0) then + TempFrame := FBrowser.GetFrame(aFrameName) + else + TempFrame := FBrowser.MainFrame; + + if (TempFrame <> nil) then + begin + TempVisitor := TCustomCefStringVisitor.Create(self); + TempFrame.GetSource(TempVisitor); + end; end; end; procedure TFMXChromium.RetrieveHTML(const aFrame : ICefFrame); var - TempTask: ICefTask; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class - if Initialized then + if Initialized and (aFrame <> nil) then begin - TempTask := TCefGetHTMLTask.Create(self, aFrame); - CefPostTask(TID_UI, TempTask); + TempVisitor := TCustomCefStringVisitor.Create(self); + aFrame.GetSource(TempVisitor); end; end; procedure TFMXChromium.RetrieveHTML(const aFrameIdentifier : int64); var - TempTask: ICefTask; + TempFrame : ICefFrame; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class if Initialized then begin - TempTask := TCefGetHTMLTask.Create(self, aFrameIdentifier); - CefPostTask(TID_UI, TempTask); + if (aFrameIdentifier <> 0) then + TempFrame := FBrowser.GetFrameByident(aFrameIdentifier) + else + TempFrame := FBrowser.MainFrame; + + if (TempFrame <> nil) then + begin + TempVisitor := TCustomCefStringVisitor.Create(self); + TempFrame.GetSource(TempVisitor); + end; end; end; // Leave aFrameName empty to get the HTML source from the main frame procedure TFMXChromium.RetrieveText(const aFrameName : ustring); var - TempTask: ICefTask; + TempFrame : ICefFrame; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class if Initialized then begin - TempTask := TCefGetTextTask.Create(self, aFrameName); - CefPostTask(TID_UI, TempTask); + if (length(aFrameName) > 0) then + TempFrame := FBrowser.GetFrame(aFrameName) + else + TempFrame := FBrowser.MainFrame; + + if (TempFrame <> nil) then + begin + TempVisitor := TCustomCefStringVisitor.Create(self); + TempFrame.GetText(TempVisitor); + end; end; end; procedure TFMXChromium.RetrieveText(const aFrame : ICefFrame); var - TempTask: ICefTask; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class - if Initialized then + if Initialized and (aFrame <> nil) then begin - TempTask := TCefGetTextTask.Create(self, aFrame); - CefPostTask(TID_UI, TempTask); + TempVisitor := TCustomCefStringVisitor.Create(self); + aFrame.GetText(TempVisitor); end; end; procedure TFMXChromium.RetrieveText(const aFrameIdentifier : int64); var - TempTask: ICefTask; + TempFrame : ICefFrame; + TempVisitor : ICefStringVisitor; begin - // Results will be received in the OnTextResultAvailable event of this class if Initialized then begin - TempTask := TCefGetTextTask.Create(self, aFrameIdentifier); - CefPostTask(TID_UI, TempTask); + if (aFrameIdentifier <> 0) then + TempFrame := FBrowser.GetFrameByident(aFrameIdentifier) + else + TempFrame := FBrowser.MainFrame; + + if (TempFrame <> nil) then + begin + TempVisitor := TCustomCefStringVisitor.Create(self); + TempFrame.GetText(TempVisitor); + end; end; end; @@ -1960,12 +1818,14 @@ begin end; procedure TFMXChromium.ResolveHost(const aURL : ustring); +var + TempCallback : ICefResolveCallback; begin // Results will be received in the OnResolvedHostAvailable event of this class if Initialized and (length(aURL) > 0) then begin - if (FResolveHostcb = nil) then FResolveHostcb := TCefCustomResolveCallback.Create(self); - FBrowser.Host.RequestContext.ResolveHost(aURL, FResolveHostcb); + TempCallback := TCefCustomResolveCallback.Create(self); + FBrowser.Host.RequestContext.ResolveHost(aURL, TempCallback); end; end; @@ -2731,13 +2591,14 @@ begin end; function TFMXChromium.doOnConsoleMessage(const browser : ICefBrowser; + level : TCefLogSeverity; const aMessage : ustring; const source : ustring; line : Integer): Boolean; begin Result := False; - if Assigned(FOnConsoleMessage) then FOnConsoleMessage(Self, browser, aMessage, source, line, Result); + if Assigned(FOnConsoleMessage) then FOnConsoleMessage(Self, browser, level, aMessage, source, line, Result); end; function TFMXChromium.doOnAutoResize(const browser : ICefBrowser;