1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-02-02 10:25:26 +02:00

Enable Chrome runtime in SimpleBrowser2 demo

This commit is contained in:
Salvador Díaz Fau 2024-06-17 11:44:07 +02:00
parent b2722c1dfa
commit 16f76f39aa
4 changed files with 35 additions and 35 deletions

View File

@ -8,30 +8,20 @@ uses
{$ELSE}
Forms,
{$ENDIF }
uCEFApplication, uCEFConstants,
uCEFApplication,
uSimpleBrowser2 in 'uSimpleBrowser2.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

@ -13,21 +13,14 @@ uses
// Manifest made by Wellington Torrejais da Silva
// https://gist.github.com/hotsoft-desenv2/5f722f1c44ed3abfc4f3d5d62ed644eb
// CEF3 needs to set the LARGEADDRESSAWARE flag which allows 32-bit processes to use up to 3GB of RAM.
{$SetPEFlags $20}
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.
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
// In case you want to use custom directories for the CEF3 binaries, cache and user data.
{
GlobalCEFApp.FrameworkDirPath := 'cef';
GlobalCEFApp.ResourcesDirPath := 'cef';
GlobalCEFApp.LocalesDirPath := 'cef\locales';
GlobalCEFApp.cache := 'cef\cache';
GlobalCEFApp.UserDataPath := 'cef\User Data';
}
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -35,7 +28,6 @@ begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
CreateGlobalCEFApp;
end.

View File

@ -58,6 +58,8 @@ type
var
Form1: TForm1;
procedure CreateGlobalCEFApp;
implementation
{$R *.dfm}
@ -85,6 +87,19 @@ uses
// 2. TChromium.OnClose sends a CEF_DESTROY message to destroy CEFWindowParent1 in the main thread, which triggers the TChromium.OnBeforeClose event.
// 3. TChromium.OnBeforeClose sets FCanClose := True and sends WM_CLOSE to the form.
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;
@ -94,6 +109,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;

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 616,
"InternalVersion" : 617,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "126.2.0"
}