Enable Chrome runtime in MobileBrowser demo

This commit is contained in:
Salvador Díaz Fau 2024-06-18 14:18:16 +02:00
parent 16f76f39aa
commit 496db82294
2 changed files with 26 additions and 18 deletions

View File

@ -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.

View File

@ -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;