1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-06-22 22:17:48 +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} {$ELSE}
Forms, Forms,
{$ENDIF } {$ENDIF }
uCEFApplication, uCEFConstants, uCEFApplication,
uSimpleBrowser2 in 'uSimpleBrowser2.pas' {Form1}; uSimpleBrowser2 in 'uSimpleBrowser2.pas' {Form1};
{$R *.res} {$R *.res}
{$IFDEF WIN32}
const const
IMAGE_FILE_LARGE_ADDRESS_AWARE = $0020; 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.
// 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}
{$IFDEF WIN32}{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}{$ENDIF} {$ENDIF}
begin begin
GlobalCEFApp := TCefApplication.Create; CreateGlobalCEFApp;
// 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';
}
// You *MUST* call GlobalCEFApp.StartMainProcess in a if..then clause // You *MUST* call GlobalCEFApp.StartMainProcess in a if..then clause
// with the Application initialization inside the begin..end. // with the Application initialization inside the begin..end.
@ -46,6 +36,5 @@ begin
Application.Run; Application.Run;
end; end;
GlobalCEFApp.Free; DestroyGlobalCEFApp;
GlobalCEFApp := nil;
end. end.

View File

@ -13,21 +13,14 @@ uses
// Manifest made by Wellington Torrejais da Silva // Manifest made by Wellington Torrejais da Silva
// https://gist.github.com/hotsoft-desenv2/5f722f1c44ed3abfc4f3d5d62ed644eb // 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. const
{$SetPEFlags $20} 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 begin
GlobalCEFApp := TCefApplication.Create; CreateGlobalCEFApp;
// 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';
}
if GlobalCEFApp.StartMainProcess then if GlobalCEFApp.StartMainProcess then
begin begin
@ -36,6 +29,5 @@ begin
Application.Run; Application.Run;
end; end;
GlobalCEFApp.Free; CreateGlobalCEFApp;
GlobalCEFApp := nil;
end. end.

View File

@ -58,6 +58,8 @@ type
var var
Form1: TForm1; Form1: TForm1;
procedure CreateGlobalCEFApp;
implementation implementation
{$R *.dfm} {$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. // 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. // 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); procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin begin
CanClose := FCanClose; CanClose := FCanClose;
@ -94,6 +109,10 @@ begin
FClosing := True; FClosing := True;
Visible := False; Visible := False;
Chromium1.CloseBrowser(True); Chromium1.CloseBrowser(True);
// Workaround for the missing TChormium.OnClose event when "Chrome runtime" is enabled.
if GlobalCEFApp.ChromeRuntime then
CEFWindowParent1.Free;
end; end;
end; end;

View File

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