From 14425b01ae2512947329969e4b2d55863b7d2cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Thu, 7 Dec 2017 10:49:51 +0100 Subject: [PATCH] Update to CEF 3.3202.1693.g6adf855 --- .../uExternalPumpBrowser.pas | 23 +- demos/MiniBrowser/uMiniBrowser.pas | 16 + demos/SimpleBrowser/uSimpleBrowser.dfm | 2 +- demos/SimpleBrowser/uSimpleBrowser.pas | 30 +- .../00-DeleteDCUs.bat | 14 + .../SimpleExternalPumpBrowser.dpr | 93 +++ .../SimpleExternalPumpBrowser.dproj | 597 ++++++++++++++++++ demos/SimpleExternalPumpBrowser/cef.inc | 384 +++++++++++ .../uSimpleExternalPumpBrowser.dfm | 98 +++ .../uSimpleExternalPumpBrowser.pas | 196 ++++++ demos/SubProcess/SubProcess.dpr | 2 +- source/uCEFApplication.pas | 11 +- source/uCEFChromiumWindow.pas | 22 + source/uCEFConstants.pas | 1 + source/uCEFInterfaces.pas | 31 + source/uCEFLibFunctions.pas | 3 + source/uCEFTypes.pas | 33 + source/uCEFWindowParent.pas | 9 + 18 files changed, 1552 insertions(+), 13 deletions(-) create mode 100644 demos/SimpleExternalPumpBrowser/00-DeleteDCUs.bat create mode 100644 demos/SimpleExternalPumpBrowser/SimpleExternalPumpBrowser.dpr create mode 100644 demos/SimpleExternalPumpBrowser/SimpleExternalPumpBrowser.dproj create mode 100644 demos/SimpleExternalPumpBrowser/cef.inc create mode 100644 demos/SimpleExternalPumpBrowser/uSimpleExternalPumpBrowser.dfm create mode 100644 demos/SimpleExternalPumpBrowser/uSimpleExternalPumpBrowser.pas diff --git a/demos/ExternalPumpBrowser/uExternalPumpBrowser.pas b/demos/ExternalPumpBrowser/uExternalPumpBrowser.pas index 23140682..f62f1e55 100644 --- a/demos/ExternalPumpBrowser/uExternalPumpBrowser.pas +++ b/demos/ExternalPumpBrowser/uExternalPumpBrowser.pas @@ -79,6 +79,8 @@ type procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY; 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; public @@ -94,6 +96,9 @@ implementation {$R *.dfm} +uses + uCEFApplication; + // This demo has a simple browser with a TChromium + TCEFWindowParent combination // It was necessary to destroy the browser following the destruction sequence described in the MDIBrowser demo. @@ -112,10 +117,10 @@ procedure TExternalPumpBrowserFrm.FormCloseQuery(Sender: TObject; var CanClose: begin CanClose := FCanClose; - if not(FClosing) and AddressPnl.Enabled then + if not(FClosing) then begin - Visible := False; FClosing := True; + Visible := False; AddressPnl.Enabled := False; Chromium1.CloseBrowser(True); end; @@ -184,4 +189,18 @@ begin if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted; end; +procedure TExternalPumpBrowserFrm.WMEnterMenuLoop(var aMessage: TMessage); +begin + inherited; + + if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True; +end; + +procedure TExternalPumpBrowserFrm.WMExitMenuLoop(var aMessage: TMessage); +begin + inherited; + + if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False; +end; + end. diff --git a/demos/MiniBrowser/uMiniBrowser.pas b/demos/MiniBrowser/uMiniBrowser.pas index ba43e761..3812e09b 100644 --- a/demos/MiniBrowser/uMiniBrowser.pas +++ b/demos/MiniBrowser/uMiniBrowser.pas @@ -204,6 +204,8 @@ type procedure TakeSnapshotMsg(var aMessage : TMessage); message MINIBROWSER_TAKESNAPSHOT; 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; public procedure ShowStatusText(const aText : string); @@ -821,6 +823,20 @@ begin if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted; end; +procedure TMiniBrowserFrm.WMEnterMenuLoop(var aMessage: TMessage); +begin + inherited; + + if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True; +end; + +procedure TMiniBrowserFrm.WMExitMenuLoop(var aMessage: TMessage); +begin + inherited; + + if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False; +end; + procedure TMiniBrowserFrm.Deczoom1Click(Sender: TObject); begin Chromium1.DecZoomStep; diff --git a/demos/SimpleBrowser/uSimpleBrowser.dfm b/demos/SimpleBrowser/uSimpleBrowser.dfm index dec26328..8dc86143 100644 --- a/demos/SimpleBrowser/uSimpleBrowser.dfm +++ b/demos/SimpleBrowser/uSimpleBrowser.dfm @@ -1,7 +1,7 @@ object Form1: TForm1 Left = 0 Top = 0 - Caption = 'Simple Browser' + Caption = 'Initializing browser. Please wait...' ClientHeight = 624 ClientWidth = 1038 Color = clBtnFace diff --git a/demos/SimpleBrowser/uSimpleBrowser.pas b/demos/SimpleBrowser/uSimpleBrowser.pas index 8d30473f..77c2cca2 100644 --- a/demos/SimpleBrowser/uSimpleBrowser.pas +++ b/demos/SimpleBrowser/uSimpleBrowser.pas @@ -66,6 +66,9 @@ type // You have to handle this two messages to call NotifyMoveOrResizeStarted or some page elements will be misaligned. procedure WMMove(var aMessage : TWMMove); message WM_MOVE; procedure WMMoving(var aMessage : TMessage); message WM_MOVING; + // You also have to handle these two messages to set GlobalCEFApp.OsmodalLoop + procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP; + procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP; public { Public declarations } end; @@ -77,6 +80,9 @@ implementation {$R *.dfm} +uses + uCEFApplication; + // This is a demo with the simplest web browser you can build using CEF4Delphi and // it doesn't show any sign of progress like other web browsers do. @@ -91,8 +97,6 @@ implementation procedure TForm1.FormShow(Sender: TObject); begin - Caption := 'Simple Browser - Initializing browser. Please wait...'; - // You *MUST* call CreateBrowser to create and initialize the browser. // This will trigger the AfterCreated event when the browser is fully // initialized and ready to receive commands. @@ -127,18 +131,28 @@ procedure TForm1.WMMove(var aMessage : TWMMove); begin inherited; - if (ChromiumWindow1 <> nil) and - (ChromiumWindow1.ChromiumBrowser <> nil) then - ChromiumWindow1.ChromiumBrowser.NotifyMoveOrResizeStarted; + if (ChromiumWindow1 <> nil) then ChromiumWindow1.NotifyMoveOrResizeStarted; end; procedure TForm1.WMMoving(var aMessage : TMessage); begin inherited; - if (ChromiumWindow1 <> nil) and - (ChromiumWindow1.ChromiumBrowser <> nil) then - ChromiumWindow1.ChromiumBrowser.NotifyMoveOrResizeStarted; + if (ChromiumWindow1 <> nil) then ChromiumWindow1.NotifyMoveOrResizeStarted; +end; + +procedure TForm1.WMEnterMenuLoop(var aMessage: TMessage); +begin + inherited; + + if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True; +end; + +procedure TForm1.WMExitMenuLoop(var aMessage: TMessage); +begin + inherited; + + if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False; end; end. diff --git a/demos/SimpleExternalPumpBrowser/00-DeleteDCUs.bat b/demos/SimpleExternalPumpBrowser/00-DeleteDCUs.bat new file mode 100644 index 00000000..dbd008bc --- /dev/null +++ b/demos/SimpleExternalPumpBrowser/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/SimpleExternalPumpBrowser/SimpleExternalPumpBrowser.dpr b/demos/SimpleExternalPumpBrowser/SimpleExternalPumpBrowser.dpr new file mode 100644 index 00000000..34ae6703 --- /dev/null +++ b/demos/SimpleExternalPumpBrowser/SimpleExternalPumpBrowser.dpr @@ -0,0 +1,93 @@ +// ************************************************************************ +// ***************************** 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 SimpleExternalPumpBrowser; + +{$I cef.inc} + +uses + {$IFDEF DELPHI16_UP} + Vcl.Forms, + WinApi.Windows, + System.SysUtils, + {$ELSE} + Forms, + Windows, + SysUtils, + {$ENDIF } + uCEFApplication, + uCEFWorkScheduler, + uSimpleExternalPumpBrowser in 'uSimpleExternalPumpBrowser.pas' {SimpleExternalPumpBrowserFrm}; + +{$R *.res} + +// CEF3 needs to set the LARGEADDRESSAWARE flag which allows 32-bit processes to use up to 3GB of RAM. +// If you don't add this flag the rederer process will crash when you try to load large images. +{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} + +begin + // TCEFWorkScheduler will call cef_do_message_loop_work when + // it's told in the GlobalCEFApp.OnScheduleMessagePumpWork event. + // GlobalCEFWorkScheduler needs to be created before the + // GlobalCEFApp.StartMainProcess call. + GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil); + + GlobalCEFApp := TCefApplication.Create; + GlobalCEFApp.FlashEnabled := False; + GlobalCEFApp.FastUnload := True; + GlobalCEFApp.ExternalMessagePump := True; + GlobalCEFApp.MultiThreadedMessageLoop := False; + GlobalCEFApp.OnScheduleMessagePumpWork := GlobalCEFApp_OnScheduleMessagePumpWork; + + if GlobalCEFApp.StartMainProcess then + begin + Application.Initialize; + {$IFDEF DELPHI11_UP} + Application.MainFormOnTaskbar := True; + {$ENDIF} + Application.CreateForm(TSimpleExternalPumpBrowserFrm, SimpleExternalPumpBrowserFrm); + Application.Run; + + // The form needs to be destroyed *BEFORE* stopping the scheduler. + SimpleExternalPumpBrowserFrm.Free; + + GlobalCEFWorkScheduler.StopScheduler; + end; + + FreeAndNil(GlobalCEFApp); + FreeAndNil(GlobalCEFWorkScheduler); +end. diff --git a/demos/SimpleExternalPumpBrowser/SimpleExternalPumpBrowser.dproj b/demos/SimpleExternalPumpBrowser/SimpleExternalPumpBrowser.dproj new file mode 100644 index 00000000..21a94460 --- /dev/null +++ b/demos/SimpleExternalPumpBrowser/SimpleExternalPumpBrowser.dproj @@ -0,0 +1,597 @@ + + + {55E00327-9D98-4DA3-A4E1-844942A01C6B} + 18.2 + VCL + SimpleExternalPumpBrowser.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 + SimpleExternalPumpBrowser + $(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 + + +
SimpleExternalPumpBrowserFrm
+
+ + Cfg_2 + Base + + + Base + + + Cfg_1 + Base + +
+ + Delphi.Personality.12 + Application + + + + SimpleExternalPumpBrowser.dpr + + + IP Abstraction Indy Implementation Design Time + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + + + + + + SimpleExternalPumpBrowser.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/SimpleExternalPumpBrowser/cef.inc b/demos/SimpleExternalPumpBrowser/cef.inc new file mode 100644 index 00000000..984ae795 --- /dev/null +++ b/demos/SimpleExternalPumpBrowser/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/SimpleExternalPumpBrowser/uSimpleExternalPumpBrowser.dfm b/demos/SimpleExternalPumpBrowser/uSimpleExternalPumpBrowser.dfm new file mode 100644 index 00000000..46fbbeb4 --- /dev/null +++ b/demos/SimpleExternalPumpBrowser/uSimpleExternalPumpBrowser.dfm @@ -0,0 +1,98 @@ +object SimpleExternalPumpBrowserFrm: TSimpleExternalPumpBrowserFrm + 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 + OnCloseQuery = FormCloseQuery + OnCreate = FormCreate + OnShow = FormShow + PixelsPerInch = 96 + TextHeight = 13 + 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 GoBtn: TButton + Left = 1002 + Top = 5 + Width = 31 + Height = 20 + Margins.Left = 5 + Align = alRight + Caption = 'Go' + TabOrder = 0 + OnClick = GoBtnClick + end + object URLCbx: TComboBox + Left = 5 + Top = 5 + Width = 997 + Height = 21 + Align = alClient + ItemIndex = 0 + TabOrder = 1 + Text = 'https://www.google.com' + Items.Strings = ( + 'https://www.google.com' + + 'https://www.whatismybrowser.com/detect/what-http-headers-is-my-b' + + 'rowser-sending' + 'https://www.w3schools.com/js/tryit.asp?filename=tryjs_win_close' + 'https://www.w3schools.com/html/html5_video.asp' + 'http://www.adobe.com/software/flash/about/' + 'http://isflashinstalled.com/' + 'chrome://version/' + 'http://html5test.com/' + 'https://www.w3schools.com/' + 'http://webglsamples.org/' + 'https://get.webgl.org/' + 'https://www.youtube.com' + 'https://html5demos.com/drag/' + + 'https://developers.google.com/maps/documentation/javascript/exam' + + 'ples/streetview-embed?hl=fr' + + 'https://www.w3schools.com/Tags/tryit.asp?filename=tryhtml_iframe' + + '_name' + 'https://www.browserleaks.com/webrtc' + 'https://frames-per-second.appspot.com/') + end + end + object ChromiumWindow1: TChromiumWindow + Left = 0 + Top = 30 + Width = 1038 + Height = 594 + Align = alClient + TabOrder = 1 + OnClose = ChromiumWindow1Close + OnBeforeClose = ChromiumWindow1BeforeClose + OnAfterCreated = ChromiumWindow1AfterCreated + end + object Timer1: TTimer + Enabled = False + Interval = 300 + OnTimer = Timer1Timer + Left = 56 + Top = 88 + end +end diff --git a/demos/SimpleExternalPumpBrowser/uSimpleExternalPumpBrowser.pas b/demos/SimpleExternalPumpBrowser/uSimpleExternalPumpBrowser.pas new file mode 100644 index 00000000..cc592c6c --- /dev/null +++ b/demos/SimpleExternalPumpBrowser/uSimpleExternalPumpBrowser.pas @@ -0,0 +1,196 @@ +// ************************************************************************ +// ***************************** 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 uSimpleExternalPumpBrowser; + +{$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, + {$ELSE} + Windows, Messages, SysUtils, Variants, Classes, Graphics, + Controls, Forms, Dialogs, StdCtrls, ExtCtrls, + {$ENDIF} + uCEFChromium, uCEFWindowParent, uCEFTypes, uCEFConstants, uCEFInterfaces, uCEFWorkScheduler, + uCEFChromiumWindow; + +type + TSimpleExternalPumpBrowserFrm = class(TForm) + AddressPnl: TPanel; + GoBtn: TButton; + Timer1: TTimer; + URLCbx: TComboBox; + ChromiumWindow1: TChromiumWindow; + + procedure GoBtnClick(Sender: TObject); + procedure FormShow(Sender: TObject); + procedure Timer1Timer(Sender: TObject); + + procedure FormCreate(Sender: TObject); + procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); + + // These 3 TChromiumWindow events are called in the main app thread, so you can do whatever you want with the GUI. + procedure ChromiumWindow1AfterCreated(Sender: TObject); + procedure ChromiumWindow1BeforeClose(Sender: TObject); + procedure ChromiumWindow1Close(Sender: TObject); + + protected + FCanClose : boolean; + FClosing : 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; + end; + +var + SimpleExternalPumpBrowserFrm : TSimpleExternalPumpBrowserFrm; + GlobalCEFWorkScheduler : TCEFWorkScheduler = nil; + +procedure GlobalCEFApp_OnScheduleMessagePumpWork(const aDelayMS : int64); + +implementation + +{$R *.dfm} + +uses + uCEFApplication; + +// This demo has a simple browser with a TChromiumWindow using the "External message pump" mode +// to schedule the cef_do_message_loop_work calls thanks to the TCEFWorkScheduler class. + +// It was necessary to destroy the browser with the following destruction sequence : +// 1. The FormCloseQuery event sets CanClose to False and calls TChromiumWindow.CloseBrowser, which triggers the TChromiumWindow.OnClose event. +// 2. The TChromiumWindow.OnClose event calls TChromiumWindow.DestroyChildWindow which triggers the TChromiumWindow.OnBeforeClose event. +// 3. TChromiumWindow.OnBeforeClose sets FCanClose to True and closes the form. + +procedure GlobalCEFApp_OnScheduleMessagePumpWork(const aDelayMS : int64); +begin + if (GlobalCEFWorkScheduler <> nil) then GlobalCEFWorkScheduler.ScheduleMessagePumpWork(aDelayMS); +end; + +procedure TSimpleExternalPumpBrowserFrm.FormCreate(Sender: TObject); +begin + FCanClose := False; + FClosing := False; +end; + +procedure TSimpleExternalPumpBrowserFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean); +begin + CanClose := FCanClose; + + if not(FClosing) then + begin + FClosing := True; + Visible := False; + AddressPnl.Enabled := False; + ChromiumWindow1.CloseBrowser(True); + end; +end; + +procedure TSimpleExternalPumpBrowserFrm.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(ChromiumWindow1.CreateBrowser) then Timer1.Enabled := True; +end; + +procedure TSimpleExternalPumpBrowserFrm.ChromiumWindow1AfterCreated(Sender: TObject); +begin + Caption := 'Simple External Pump Browser'; + AddressPnl.Enabled := True; + GoBtn.Click; +end; + +procedure TSimpleExternalPumpBrowserFrm.ChromiumWindow1BeforeClose(Sender: TObject); +begin + FCanClose := True; + Close; +end; + +procedure TSimpleExternalPumpBrowserFrm.ChromiumWindow1Close(Sender: TObject); +begin + // DestroyChildWindow will destroy the child window created by CEF at the top of the Z order. + ChromiumWindow1.DestroyChildWindow; +end; + +procedure TSimpleExternalPumpBrowserFrm.GoBtnClick(Sender: TObject); +begin + ChromiumWindow1.LoadURL(URLCbx.Text); +end; + +procedure TSimpleExternalPumpBrowserFrm.Timer1Timer(Sender: TObject); +begin + Timer1.Enabled := False; + if not(ChromiumWindow1.CreateBrowser) and not(ChromiumWindow1.Initialized) then + Timer1.Enabled := True; +end; + +procedure TSimpleExternalPumpBrowserFrm.WMMove(var aMessage : TWMMove); +begin + inherited; + + if (ChromiumWindow1 <> nil) then ChromiumWindow1.NotifyMoveOrResizeStarted; +end; + +procedure TSimpleExternalPumpBrowserFrm.WMMoving(var aMessage : TMessage); +begin + inherited; + + if (ChromiumWindow1 <> nil) then ChromiumWindow1.NotifyMoveOrResizeStarted; +end; + +procedure TSimpleExternalPumpBrowserFrm.WMEnterMenuLoop(var aMessage: TMessage); +begin + inherited; + + if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True; +end; + +procedure TSimpleExternalPumpBrowserFrm.WMExitMenuLoop(var aMessage: TMessage); +begin + inherited; + + if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False; +end; + +end. diff --git a/demos/SubProcess/SubProcess.dpr b/demos/SubProcess/SubProcess.dpr index ee86ce75..4d755a8a 100644 --- a/demos/SubProcess/SubProcess.dpr +++ b/demos/SubProcess/SubProcess.dpr @@ -57,7 +57,7 @@ begin // LocalesDirPath, cache, cookies and UserDataPath paths // The demos are compiled into the BIN directory. Make sure the crash_reporter.cfg file is in that - // directory too or this demos won't work. + // directory too or this demo won't work. // In case you want to use custom directories for the CEF3 binaries, cache, cookies and user data. { diff --git a/source/uCEFApplication.pas b/source/uCEFApplication.pas index 095714df..3f1860d6 100644 --- a/source/uCEFApplication.pas +++ b/source/uCEFApplication.pas @@ -57,7 +57,7 @@ uses const CEF_SUPPORTED_VERSION_MAJOR = 3; CEF_SUPPORTED_VERSION_MINOR = 3202; - CEF_SUPPORTED_VERSION_RELEASE = 1690; + CEF_SUPPORTED_VERSION_RELEASE = 1693; CEF_SUPPORTED_VERSION_BUILD = 0; CEF_CHROMEELF_VERSION_MAJOR = 62; @@ -194,6 +194,7 @@ type function Load_cef_request_context_capi_h : boolean; function Load_cef_resource_bundle_capi_h : boolean; function Load_cef_response_capi_h : boolean; + function Load_cef_server_capi_h : boolean; function Load_cef_scheme_capi_h : boolean; function Load_cef_ssl_info_capi_h : boolean; function Load_cef_stream_capi_h : boolean; @@ -1288,6 +1289,7 @@ begin Load_cef_request_context_capi_h and Load_cef_resource_bundle_capi_h and Load_cef_response_capi_h and + // Load_cef_server_capi_h and Load_cef_scheme_capi_h and Load_cef_ssl_info_capi_h and Load_cef_stream_capi_h and @@ -1535,6 +1537,13 @@ begin Result := assigned(cef_response_create); end; +function TCefApplication.Load_cef_server_capi_h : boolean; +begin + cef_server_create := GetProcAddress(FLibHandle, 'cef_server_create'); + + Result := assigned(cef_server_create); +end; + function TCefApplication.Load_cef_scheme_capi_h : boolean; begin cef_register_scheme_handler_factory := GetProcAddress(FLibHandle, 'cef_register_scheme_handler_factory'); diff --git a/source/uCEFChromiumWindow.pas b/source/uCEFChromiumWindow.pas index dbf6d532..e0ae37af 100644 --- a/source/uCEFChromiumWindow.pas +++ b/source/uCEFChromiumWindow.pas @@ -59,15 +59,18 @@ type protected FChromium : TChromium; FOnClose : TNotifyEvent; + FOnBeforeClose : TNotifyEvent; FOnAfterCreated : TNotifyEvent; function GetChildWindowHandle : THandle; override; function GetBrowserInitialized : boolean; procedure OnCloseMsg(var aMessage : TMessage); message CEF_DOONCLOSE; + procedure OnBeforeCloseMsg(var aMessage : TMessage); message CEF_DOONBEFORECLOSE; procedure OnAfterCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED; procedure WebBrowser_OnClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean); + procedure WebBrowser_OnBeforeClose(Sender: TObject; const browser: ICefBrowser); procedure WebBrowser_OnAfterCreated(Sender: TObject; const browser: ICefBrowser); public @@ -76,12 +79,14 @@ type function CreateBrowser : boolean; procedure CloseBrowser(aForceClose : boolean); procedure LoadURL(const aURL : string); + procedure NotifyMoveOrResizeStarted; property ChromiumBrowser : TChromium read FChromium; property Initialized : boolean read GetBrowserInitialized; published property OnClose : TNotifyEvent read FOnClose write FOnClose; + property OnBeforeClose : TNotifyEvent read FOnBeforeClose write FOnBeforeClose; property OnAfterCreated : TNotifyEvent read FOnAfterCreated write FOnAfterCreated; end; @@ -100,6 +105,7 @@ begin FChromium := nil; FOnClose := nil; + FOnBeforeClose := nil; FOnAfterCreated := nil; end; @@ -111,6 +117,7 @@ begin begin FChromium := TChromium.Create(self); FChromium.OnClose := WebBrowser_OnClose; + FChromium.OnBeforeClose := WebBrowser_OnBeforeClose; FChromium.OnAfterCreated := WebBrowser_OnAfterCreated; end; end; @@ -139,6 +146,11 @@ begin Result := False; end; +procedure TChromiumWindow.WebBrowser_OnBeforeClose(Sender: TObject; const browser: ICefBrowser); +begin + if assigned(FOnBeforeClose) then PostMessage(Handle, CEF_DOONBEFORECLOSE, 0, 0); +end; + procedure TChromiumWindow.WebBrowser_OnAfterCreated(Sender: TObject; const browser: ICefBrowser); begin PostMessage(Handle, CEF_AFTERCREATED, 0, 0); @@ -149,6 +161,11 @@ begin if assigned(FOnClose) then FOnClose(self); end; +procedure TChromiumWindow.OnBeforeCloseMsg(var aMessage : TMessage); +begin + if assigned(FOnBeforeClose) then FOnBeforeClose(self); +end; + procedure TChromiumWindow.OnAfterCreatedMsg(var aMessage : TMessage); begin UpdateSize; @@ -173,4 +190,9 @@ begin FChromium.LoadURL(aURL); end; +procedure TChromiumWindow.NotifyMoveOrResizeStarted; +begin + if (FChromium <> nil) then FChromium.NotifyMoveOrResizeStarted; +end; + end. diff --git a/source/uCEFConstants.pas b/source/uCEFConstants.pas index 3f55086b..32bcc251 100644 --- a/source/uCEFConstants.pas +++ b/source/uCEFConstants.pas @@ -363,6 +363,7 @@ const CEF_PENDINGRESIZE = WM_APP + $A04; CEF_PUMPHAVEWORK = WM_APP + $A05; CEF_DESTROY = WM_APP + $A06; + CEF_DOONBEFORECLOSE = WM_APP + $A07; CEF_TIMER_MINIMUM = $0000000A; CEF_TIMER_MAXIMUM = $7FFFFFFF; diff --git a/source/uCEFInterfaces.pas b/source/uCEFInterfaces.pas index 3085c8fd..86466f0e 100644 --- a/source/uCEFInterfaces.pas +++ b/source/uCEFInterfaces.pas @@ -102,6 +102,8 @@ type ICefExtension = interface; ICefStreamReader = interface; ICefLoadHandler = interface; + ICefServer = interface; + ICefServerHandler = interface; TCefv8ValueArray = array of ICefv8Value; TCefX509CertificateArray = array of ICefX509Certificate; @@ -1844,6 +1846,35 @@ type const selectionRect: PCefRect; activeMatchOrdinal: Integer; finalUpdate: Boolean); end; + ICefServer = interface(ICefBaseRefCounted) + ['{41D41764-A74B-4552-B166-C77E70549047}'] + function GetTaskRunner : ICefTaskRunner; + procedure Shutdown; + function IsRunning : boolean; + function GetAddress : ustring; + function HasConnection : boolean; + function IsValidConnection(connection_id: Integer) : boolean; + procedure SendHttp200response(connection_id: Integer; const content_type: ustring; const data: Pointer; data_size: NativeUInt); + procedure SendHttp404response(connection_id: Integer); + procedure SendHttp500response(connection_id: Integer; const error_message: ustring); + procedure SendHttpResponse(connection_id, response_code: Integer; const content_type: ustring; content_length: int64; headerMap: TCefStringMultimap); + procedure SendRawData(connection_id: Integer; const data: Pointer; data_size: NativeUInt); + procedure CloseConnection(connection_id: Integer); + procedure SendWebSocketMessage(connection_id: Integer; const data: Pointer; data_size: NativeUInt); + end; + + ICefServerHandler = interface(ICefBaseRefCounted) + ['{AFB64A63-44C9-44CD-959B-D8E20F549879}'] + procedure OnServerCreated(const server: ICefServer); + procedure OnServerDestroyed(const server: ICefServer); + procedure OnClientConnected(const server: ICefServer; connection_id: Integer); + procedure OnClientDisconnected(const server: ICefServer; connection_id: Integer); + procedure OnHttpRequest(const server: ICefServer; connection_id: Integer; const client_address: ustring; const request: ICefRequest); + procedure OnWebSocketRequest(const server: ICefServer; connection_id: Integer; const client_address: ustring; const request: ICefRequest; const callback: ICefCallback); + procedure OnWebSocketConnected(const server: ICefServer; connection_id: Integer); + procedure OnWebSocketMessage(const server: ICefServer; connection_id: Integer; const data: Pointer; data_size: NativeUInt); + end; + implementation end. diff --git a/source/uCEFLibFunctions.pas b/source/uCEFLibFunctions.pas index cc2b2fb6..88b50f09 100644 --- a/source/uCEFLibFunctions.pas +++ b/source/uCEFLibFunctions.pas @@ -154,6 +154,9 @@ var cef_register_scheme_handler_factory : function(const scheme_name, domain_name: PCefString; factory: PCefSchemeHandlerFactory): Integer; {$IFDEF CPUX64}stdcall{$ELSE}cdecl{$ENDIF}; cef_clear_scheme_handler_factories : function : Integer; {$IFDEF CPUX64}stdcall{$ELSE}cdecl{$ENDIF}; + // /include/capi/cef_server_capi.h + cef_server_create : procedure(const address: PCefString; port: uint16; backlog: Integer; handler: PCefServerHandler); {$IFDEF CPUX64}stdcall{$ELSE}cdecl{$ENDIF}; + // /include/capi/cef_ssl_info_capi.h cef_is_cert_status_error : function(status : TCefCertStatus) : integer; {$IFDEF CPUX64}stdcall{$ELSE}cdecl{$ENDIF}; cef_is_cert_status_minor_error : function(status : TCefCertStatus) : integer; {$IFDEF CPUX64}stdcall{$ELSE}cdecl{$ENDIF}; diff --git a/source/uCEFTypes.pas b/source/uCEFTypes.pas index 316ae360..82e58836 100644 --- a/source/uCEFTypes.pas +++ b/source/uCEFTypes.pas @@ -82,6 +82,8 @@ type PCefAccessibilityHandler = ^TCefAccessibilityHandler; PCefFrame = ^TCefFrame; PCefApp = ^TCefApp; + PCefServer = ^TCefServer; + PCefServerHandler = ^TCefServerHandler; PCefStringVisitor = ^TCefStringVisitor; PCefRequest = ^TCefRequest; PCefPostData = ^TCefPostData; @@ -2565,6 +2567,37 @@ type get_render_process_handler: function(self: PCefApp): PCefRenderProcessHandler; stdcall; end; + // /include/capi/cef_server_capi.h (cef_server_t) + TCefServer = record + base: TCefBaseRefCounted; + get_task_runner: function(self: PCefServer): PCefTaskRunner; stdcall; + shutdown: procedure(self: PCefServer); stdcall; + is_running: function(self: PCefServer): Integer; stdcall; + get_address: function(self: PCefServer): PCefStringUserFree; stdcall; + has_connection: function(self: PCefServer): Integer; stdcall; + is_valid_connection: function(self: PCefServer; connection_id: Integer): Integer; stdcall; + send_http200response: procedure(self: PCefServer; connection_id: Integer; const content_type: PCefString; const data: Pointer; data_size: NativeUInt); stdcall; + send_http404response: procedure(self: PCefServer; connection_id: Integer); stdcall; + send_http500response: procedure(self: PCefServer; connection_id: Integer; const error_message: PCefString); stdcall; + send_http_response: procedure(self: PCefServer; connection_id, response_code: Integer; const content_type: PCefString; content_length: int64; headerMap: TCefStringMultimap); stdcall; + send_raw_data: procedure(self: PCefServer; connection_id: Integer; const data: Pointer; data_size: NativeUInt); stdcall; + close_connection: procedure(self: PCefServer; connection_id: Integer); stdcall; + send_web_socket_message: procedure(self: PCefServer; connection_id: Integer; const data: Pointer; data_size: NativeUInt); stdcall; + end; + + // /include/capi/cef_server_capi.h (cef_server_handler_t) + TCefServerHandler = record + base: TCefBaseRefCounted; + on_server_created: procedure(self: PCefServerHandler; server: PCefServer); stdcall; + on_server_destroyed: procedure(self: PCefServerHandler; server: PCefServer); stdcall; + on_client_connected: procedure(self: PCefServerHandler; server: PCefServer; connection_id: Integer); stdcall; + on_client_disconnected: procedure(self: PCefServerHandler; server: PCefServer; connection_id: Integer); stdcall; + on_http_request: procedure(self: PCefServerHandler; server: PCefServer; connection_id: Integer; const client_address: PCefString; request: PCefRequest); stdcall; + on_web_socket_request: procedure(self: PCefServerHandler; server: PCefServer; connection_id: Integer; const client_address: PCefString; request: PCefRequest; callback: PCefCallback); stdcall; + on_web_socket_connected: procedure(self: PCefServerHandler; server: PCefServer; connection_id: Integer); stdcall; + on_web_socket_message: procedure(self: PCefServerHandler; server: PCefServer; connection_id: Integer; const data: Pointer; data_size: NativeUInt); stdcall; + end; + implementation end. diff --git a/source/uCEFWindowParent.pas b/source/uCEFWindowParent.pas index 9e187a6c..d5cfcc0b 100644 --- a/source/uCEFWindowParent.pas +++ b/source/uCEFWindowParent.pas @@ -65,6 +65,7 @@ type public procedure UpdateSize; function TakeSnapshot(var aBitmap : TBitmap) : boolean; + function DestroyChildWindow : boolean; property ChildWindowHandle : THandle read GetChildWindowHandle; @@ -175,4 +176,12 @@ begin end; end; +function TCEFWindowParent.DestroyChildWindow : boolean; +var + TempHWND : HWND; +begin + TempHWND := GetWindow(Handle, GW_CHILD); + Result := (TempHWND <> 0) and DestroyWindow(TempHWND); +end; + end.