From 496db82294b43994fe5b045b100495daaca04ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Tue, 18 Jun 2024 14:18:16 +0200 Subject: [PATCH] Enable Chrome runtime in MobileBrowser demo --- .../MobileBrowser/MobileBrowser.dpr | 25 ++++++------------- .../MobileBrowser/uMobileBrowser.pas | 19 ++++++++++++++ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/demos/Delphi_VCL/MobileBrowser/MobileBrowser.dpr b/demos/Delphi_VCL/MobileBrowser/MobileBrowser.dpr index ba883868..e1ee56f2 100644 --- a/demos/Delphi_VCL/MobileBrowser/MobileBrowser.dpr +++ b/demos/Delphi_VCL/MobileBrowser/MobileBrowser.dpr @@ -8,30 +8,20 @@ uses {$ELSE} Forms, {$ENDIF } - uCEFApplication, uCEFConstants, + uCEFApplication, uMobileBrowser in 'uMobileBrowser.pas' {Form1}; {$R *.res} +{$IFDEF WIN32} const IMAGE_FILE_LARGE_ADDRESS_AWARE = $0020; - -// CEF needs to set the LARGEADDRESSAWARE ($20) flag which allows 32-bit processes to use up to 3GB of RAM. -{$IFDEF WIN32}{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}{$ENDIF} + // CEF needs to set the LARGEADDRESSAWARE ($20) flag which allows 32-bit processes to use up to 3GB of RAM. + {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} +{$ENDIF} begin - GlobalCEFApp := TCefApplication.Create; - - // In case you want to use custom directories for the CEF3 binaries, cache and user data. - // If you don't set a cache directory the browser will use in-memory cache. -{ - GlobalCEFApp.FrameworkDirPath := 'c:\cef'; - GlobalCEFApp.ResourcesDirPath := 'c:\cef'; - GlobalCEFApp.LocalesDirPath := 'c:\cef\locales'; - GlobalCEFApp.EnableGPU := True; // Enable hardware acceleration - GlobalCEFApp.cache := 'c:\cef\cache'; - GlobalCEFApp.UserDataPath := 'c:\cef\User Data'; -} + CreateGlobalCEFApp; // You *MUST* call GlobalCEFApp.StartMainProcess in a if..then clause // with the Application initialization inside the begin..end. @@ -46,6 +36,5 @@ begin Application.Run; end; - GlobalCEFApp.Free; - GlobalCEFApp := nil; + DestroyGlobalCEFApp; end. diff --git a/demos/Delphi_VCL/MobileBrowser/uMobileBrowser.pas b/demos/Delphi_VCL/MobileBrowser/uMobileBrowser.pas index 0b36e5a9..14c37fb1 100644 --- a/demos/Delphi_VCL/MobileBrowser/uMobileBrowser.pas +++ b/demos/Delphi_VCL/MobileBrowser/uMobileBrowser.pas @@ -97,6 +97,8 @@ type var Form1: TForm1; +procedure CreateGlobalCEFApp; + implementation {$R *.dfm} @@ -122,6 +124,19 @@ const DEVTOOLS_CLEARDEVICEMETRICSOVERRIDE_MSGID = 4; DEVTOOLS_SETDEVICEMETRICSOVERRIDE_MSGID = 5; +procedure CreateGlobalCEFApp; +begin + GlobalCEFApp := TCefApplication.Create; + GlobalCEFApp.cache := 'cache'; + GlobalCEFApp.EnablePrintPreview := True; + GlobalCEFApp.EnableGPU := True; + GlobalCEFApp.ChromeRuntime := True; + {$IFDEF DEBUG} + GlobalCEFApp.LogFile := 'debug.log'; + GlobalCEFApp.LogSeverity := LOGSEVERITY_INFO; + {$ENDIF} +end; + procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose := FCanClose; @@ -131,6 +146,10 @@ begin FClosing := True; Visible := False; Chromium1.CloseBrowser(True); + + // Workaround for the missing TChormium.OnClose event when "Chrome runtime" is enabled. + if GlobalCEFApp.ChromeRuntime then + CEFWindowParent1.Free; end; end;