1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-10-30 23:07:52 +02:00

Update to CEF 121.3.13

This commit is contained in:
salvadordf
2024-02-17 09:46:42 +01:00
parent 024fb7ab58
commit 2f4ff1b1f6
10 changed files with 1641 additions and 12 deletions

View File

@@ -0,0 +1,18 @@
del /s /q *.dcu
del /s /q *.exe
del /s /q *.res
del /s /q *.rsm
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 Win64\Debug
rmdir Win64\Release
rmdir Win64
rmdir __history
rmdir __recovery

View File

@@ -0,0 +1,41 @@
program DualBrowser;
{$I ..\..\..\source\cef.inc}
uses
{$IFDEF DELPHI16_UP}
Vcl.Forms,
{$ELSE}
Forms,
{$ENDIF }
uCEFApplication,
uMainForm in 'uMainForm.pas' {MainForm};
{$R *.res}
{$IFDEF WIN32}
// CEF needs to set the LARGEADDRESSAWARE ($20) flag which allows 32-bit processes to use up to 3GB of RAM.
const
IMAGE_FILE_LARGE_ADDRESS_AWARE = $0020;
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
{$ENDIF}
begin
CreateGlobalCEFApp;
// You *MUST* call GlobalCEFApp.StartMainProcess in a if..then clause
// with the Application initialization inside the begin..end.
// Read this https://www.briskbard.com/index.php?lang=en&pageid=cef
if GlobalCEFApp.StartMainProcess then
begin
Application.Initialize;
{$IFDEF DELPHI11_UP}
Application.MainFormOnTaskbar := True;
{$ENDIF}
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end;
DestroyGlobalCEFApp;
end.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,158 @@
object MainForm: TMainForm
Left = 0
Top = 0
Caption = 'Dual Browser'
ClientHeight = 662
ClientWidth = 1075
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
Padding.Left = 5
Padding.Right = 5
Padding.Bottom = 5
Position = poScreenCenter
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
TextHeight = 13
object Splitter1: TSplitter
Left = 542
Top = 0
Width = 5
Height = 657
ExplicitLeft = 537
ExplicitHeight = 662
end
object CEFPnl: TPanel
Left = 5
Top = 0
Width = 537
Height = 657
Align = alLeft
BevelOuter = bvNone
TabOrder = 0
ExplicitHeight = 656
object CEFAddressPnl: TPanel
Left = 0
Top = 0
Width = 537
Height = 30
Align = alTop
BevelOuter = bvNone
Padding.Top = 5
Padding.Bottom = 5
TabOrder = 0
object CEFAddressEdt: TEdit
Left = 0
Top = 5
Width = 506
Height = 20
Margins.Right = 5
Align = alClient
TabOrder = 0
Text = 'http://www.google.com'
ExplicitHeight = 21
end
object CEFGoBtn: TButton
Left = 506
Top = 5
Width = 31
Height = 20
Margins.Left = 5
Align = alRight
Caption = 'Go'
TabOrder = 1
OnClick = CEFGoBtnClick
end
end
object CEFWindowParent1: TCEFWindowParent
Left = 0
Top = 30
Width = 537
Height = 627
Align = alClient
Color = clWhite
TabOrder = 1
ExplicitHeight = 626
end
end
object WVPnl: TPanel
Left = 547
Top = 0
Width = 523
Height = 657
Align = alClient
BevelOuter = bvNone
ParentBackground = False
TabOrder = 1
ExplicitWidth = 519
ExplicitHeight = 656
object WVAddressPnl: TPanel
Left = 0
Top = 0
Width = 523
Height = 30
Align = alTop
BevelOuter = bvNone
Padding.Top = 5
Padding.Bottom = 5
TabOrder = 0
ExplicitWidth = 519
object WVAddressEdt: TEdit
Left = 0
Top = 5
Width = 492
Height = 20
Margins.Right = 5
Align = alClient
TabOrder = 0
Text = 'http://www.bing.com'
ExplicitWidth = 488
ExplicitHeight = 21
end
object WVGoBtn: TButton
Left = 492
Top = 5
Width = 31
Height = 20
Margins.Left = 5
Align = alRight
Caption = 'Go'
TabOrder = 1
OnClick = WVGoBtnClick
ExplicitLeft = 488
end
end
object WVWindowParent1: TWVWindowParent
Left = 0
Top = 30
Width = 523
Height = 627
Align = alClient
Color = clWhite
TabStop = True
TabOrder = 1
Browser = WVBrowser1
ExplicitWidth = 519
ExplicitHeight = 626
end
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
OnBeforeClose = Chromium1BeforeClose
OnClose = Chromium1Close
OnOpenUrlFromTab = Chromium1OpenUrlFromTab
Left = 224
Top = 256
end
object WVBrowser1: TWVBrowser
TargetCompatibleBrowserVersion = '95.0.1020.44'
AllowSingleSignOnUsingOSPrimaryAccount = False
OnAfterCreated = WVBrowser1AfterCreated
Left = 808
Top = 264
end
end

View File

@@ -0,0 +1,268 @@
unit uMainForm;
{$I ..\..\..\source\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}
// CEF4Delphi units
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFConstants, uCEFTypes,
uCEFWinControl, uCEFChromiumCore,
// WebView4Delphi units
uWVBrowser, uWVWinControl, uWVWindowParent, uWVTypes, uWVConstants,
uWVTypeLibrary, uWVLibFunctions, uWVLoader, uWVInterfaces, uWVCoreWebView2Args,
uWVBrowserBase;
type
TMainForm = class(TForm)
CEFAddressPnl: TPanel;
CEFAddressEdt: TEdit;
CEFGoBtn: TButton;
Chromium1: TChromium;
CEFWindowParent1: TCEFWindowParent;
CEFPnl: TPanel;
Splitter1: TSplitter;
WVPnl: TPanel;
WVAddressPnl: TPanel;
WVAddressEdt: TEdit;
WVGoBtn: TButton;
WVWindowParent1: TWVWindowParent;
WVBrowser1: TWVBrowser;
procedure CEFGoBtnClick(Sender: TObject);
procedure WVGoBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser; var aAction : TCefCloseBrowserAction);
procedure Chromium1BeforeClose(Sender: TObject; const browser: ICefBrowser);
procedure Chromium1BeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess, Result: Boolean);
procedure Chromium1OpenUrlFromTab(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; out Result: Boolean);
procedure WVBrowser1AfterCreated(Sender: TObject);
protected
// Variables to control when can we destroy the form safely
FCanClose : boolean; // Set to True in TChromium.OnBeforeClose
FClosing : boolean; // Set to True in the CloseQuery event.
// 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;
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
procedure CreateGlobalCEFApp;
implementation
{$R *.dfm}
uses
uCEFApplication, uCefMiscFunctions;
// This is a demo with the simplest web browser you can build using CEF4Delphi and WebView4Delphi
// it doesn't show any sign of progress like other web browsers do.
// Remember that it may take a few seconds to load if Windows update, your antivirus or
// any other windows service is using your hard drive.
// Depending on your internet connection it may take longer than expected.
// This demo requires declaring two environment variables in Tools -> Options... -> IDE -> Environment Variables
// * CEF4DELPHI must point to the root directory where the CEF4Delphi project is located.
// For example, C:\Users\<my_username>\Documents\Embarcadero\Studio\Projects\CEF4Delphi
// * WEBVIEW4DELPHI must point to the root directory where the WebView4Delphi project is located.
// For example, C:\Users\<my_username>\Documents\Embarcadero\Studio\Projects\WebView4Delphi
//
// See that the Search path in the project options use CEF4DELPHI and WEBVIEW4DELPHI to locate the sources of those projects.
// Destruction steps
// =================
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose 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.
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.cache := 'cache';
GlobalCEFApp.EnablePrintPreview := True;
GlobalCEFApp.EnableGPU := True;
//GlobalCEFApp.LogFile := 'cefdebug.log';
//GlobalCEFApp.LogSeverity := LOGSEVERITY_INFO;
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if Chromium1.Initialized then
begin
CanClose := FCanClose;
if not(FClosing) then
begin
FClosing := True;
Visible := False;
Chromium1.CloseBrowser(True);
end;
end
else
CanClose := True;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
FCanClose := False;
FClosing := False;
GlobalWebView2Loader := TWVLoader.Create(nil);
GlobalWebView2Loader.UserDataFolder := ExtractFileDir(Application.ExeName) + '\CustomCache';
GlobalWebView2Loader.UseInternalLoader := True;
//GlobalWebView2Loader.DebugLog := dlEnabled;
//GlobalWebView2Loader.DebugLogLevel := dllInfo;
GlobalWebView2Loader.StartWebView2;
end;
procedure TMainForm.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
begin
// Now the browser is fully initialized we can send a message to the main form
// to load the initial web page.
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TMainForm.Chromium1BeforeClose(Sender: TObject;
const browser: ICefBrowser);
begin
FCanClose := True;
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
procedure TMainForm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; const popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue;
var noJavascriptAccess, Result: Boolean);
begin
// For simplicity, this demo blocks all popup windows and new tabs
Result := (targetDisposition in [CEF_WOD_NEW_FOREGROUND_TAB,
CEF_WOD_NEW_BACKGROUND_TAB,
CEF_WOD_NEW_POPUP,
CEF_WOD_NEW_WINDOW]);
end;
procedure TMainForm.Chromium1Close(Sender: TObject;
const browser: ICefBrowser; var aAction : TCefCloseBrowserAction);
begin
PostMessage(Handle, CEF_DESTROY, 0, 0);
aAction := cbaDelay;
end;
procedure TMainForm.Chromium1OpenUrlFromTab(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; out Result: Boolean);
begin
// For simplicity, this demo blocks all popup windows and new tabs
Result := (targetDisposition in [CEF_WOD_NEW_FOREGROUND_TAB,
CEF_WOD_NEW_BACKGROUND_TAB,
CEF_WOD_NEW_POPUP,
CEF_WOD_NEW_WINDOW]);
end;
procedure TMainForm.BrowserCreatedMsg(var aMessage : TMessage);
begin
CEFWindowParent1.UpdateSize;
end;
procedure TMainForm.BrowserDestroyMsg(var aMessage : TMessage);
begin
CEFWindowParent1.Free;
end;
procedure TMainForm.CEFGoBtnClick(Sender: TObject);
begin
if Chromium1.Initialized then
Chromium1.LoadURL(CEFAddressEdt.Text)
else
begin
Chromium1.DefaultUrl := CEFAddressEdt.Text;
Chromium1.CreateBrowser(CEFWindowParent1);
end;
end;
procedure TMainForm.WMMove(var aMessage : TWMMove);
begin
inherited;
if (Chromium1 <> nil) then
Chromium1.NotifyMoveOrResizeStarted;
if (WVBrowser1 <> nil) then
WVBrowser1.NotifyParentWindowPositionChanged;
end;
procedure TMainForm.WMMoving(var aMessage : TMessage);
begin
inherited;
if (Chromium1 <> nil) then
Chromium1.NotifyMoveOrResizeStarted;
if (WVBrowser1 <> nil) then
WVBrowser1.NotifyParentWindowPositionChanged;
end;
procedure TMainForm.WVBrowser1AfterCreated(Sender: TObject);
begin
WVWindowParent1.UpdateSize;
end;
procedure TMainForm.WVGoBtnClick(Sender: TObject);
begin
if WVBrowser1.Initialized then
WVBrowser1.Navigate(WVAddressEdt.Text)
else
begin
WVBrowser1.DefaultUrl := WVAddressEdt.Text;
WVBrowser1.CreateBrowser(WVWindowParent1.Handle);
end;
end;
procedure TMainForm.WMEnterMenuLoop(var aMessage: TMessage);
begin
inherited;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then
GlobalCEFApp.OsmodalLoop := True;
end;
procedure TMainForm.WMExitMenuLoop(var aMessage: TMessage);
begin
inherited;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then
GlobalCEFApp.OsmodalLoop := False;
end;
end.