mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-06-02 21:57:37 +02:00
Update to CEF 3.3325.1756.g6d8faa4
This commit is contained in:
parent
1ce74299cb
commit
2c4fa2c94f
@ -12,6 +12,7 @@ object CookieVisitorFrm: TCookieVisitorFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
OnShow = FormShow
|
||||
@ -70,6 +71,8 @@ object CookieVisitorFrm: TCookieVisitorFrm
|
||||
OnContextMenuCommand = Chromium1ContextMenuCommand
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -88,6 +88,11 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
|
||||
private
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
@ -95,11 +100,15 @@ type
|
||||
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;
|
||||
procedure ShowCookiesMsg(var aMessage : TMessage); message MINIBROWSER_SHOWCOOKIES;
|
||||
|
||||
protected
|
||||
FText : string;
|
||||
FVisitor : ICefCookieVisitor;
|
||||
// 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.
|
||||
|
||||
public
|
||||
procedure AddCookieInfo(const aCookie : TCookie);
|
||||
@ -122,6 +131,12 @@ uses
|
||||
// The cookie visitor will call CookieVisitorProc for each cookie and it'll save the information using the AddCookieInfo function.
|
||||
// When the last cookie arrives we show the information in a SimpleTextViewer form.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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.
|
||||
|
||||
// This function is called in the IO thread.
|
||||
function CookieVisitorProc(const name, value, domain, path: ustring;
|
||||
secure, httponly, hasExpires: Boolean;
|
||||
@ -170,6 +185,11 @@ begin
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TCookieVisitorFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
procedure TCookieVisitorFrm.ShowCookiesMsg(var aMessage : TMessage);
|
||||
begin
|
||||
SimpleTextViewerFrm.Memo1.Lines.Text := FText; // This should be protected by a mutex.
|
||||
@ -193,6 +213,12 @@ begin
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TCookieVisitorFrm.Chromium1BeforeClose(Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TCookieVisitorFrm.Chromium1BeforeContextMenu(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; const model: ICefMenuModel);
|
||||
@ -215,6 +241,13 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TCookieVisitorFrm.Chromium1Close(Sender: TObject;
|
||||
const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TCookieVisitorFrm.Chromium1ContextMenuCommand(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; commandId: Integer;
|
||||
@ -241,9 +274,23 @@ begin
|
||||
showmessage('Deleted cookies : ' + inttostr(numDeleted));
|
||||
end;
|
||||
|
||||
procedure TCookieVisitorFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCookieVisitorFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FVisitor := TCefFastCookieVisitor.Create(CookieVisitorProc);
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TCookieVisitorFrm.FormDestroy(Sender: TObject);
|
||||
|
@ -12,6 +12,8 @@ object MainForm: TMainForm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -22,6 +24,8 @@ object MainForm: TMainForm
|
||||
Height = 628
|
||||
Align = alClient
|
||||
TabOrder = 0
|
||||
OnClose = ChromiumWindow1Close
|
||||
OnBeforeClose = ChromiumWindow1BeforeClose
|
||||
end
|
||||
object AddressBarPnl: TPanel
|
||||
Left = 0
|
||||
|
@ -63,6 +63,10 @@ type
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure Timer1Timer(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure ChromiumWindow1Close(Sender: TObject);
|
||||
procedure ChromiumWindow1BeforeClose(Sender: TObject);
|
||||
|
||||
private
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
@ -71,6 +75,10 @@ type
|
||||
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
||||
|
||||
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.
|
||||
|
||||
procedure Chromium_OnAfterCreated(Sender: TObject);
|
||||
procedure Chromium_OnGetResourceHandler(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; out Result: ICefResourceHandler);
|
||||
procedure Chromium_OnBeforePopup(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 noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
@ -89,11 +97,35 @@ implementation
|
||||
uses
|
||||
uCEFMiscFunctions, uCEFApplication;
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. The FormCloseQuery event sets CanClose to False and calls TChromiumWindow.CloseBrowser, which triggers the TChromiumWindow.OnClose event.
|
||||
// 2. The TChromiumWindow.OnClose event calls TChromiumWindow.DestroyChildWindow which triggers the TChromiumWindow.OnBeforeClose event.
|
||||
// 3. TChromiumWindow.OnBeforeClose sets FCanClose to True and closes the form.
|
||||
|
||||
procedure TMainForm.Button1Click(Sender: TObject);
|
||||
begin
|
||||
ChromiumWindow1.LoadURL(Edit1.Text);
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
ChromiumWindow1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormShow(Sender: TObject);
|
||||
begin
|
||||
ChromiumWindow1.OnAfterCreated := Chromium_OnAfterCreated;
|
||||
@ -112,6 +144,22 @@ begin
|
||||
Timer1.Enabled := True;
|
||||
end;
|
||||
|
||||
procedure TMainForm.ChromiumWindow1BeforeClose(Sender: TObject);
|
||||
begin
|
||||
FCanClose := True;
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TMainForm.ChromiumWindow1Close(Sender: TObject);
|
||||
begin
|
||||
// DestroyChildWindow will destroy the child window created by CEF at the top of the Z order.
|
||||
if not(ChromiumWindow1.DestroyChildWindow) then
|
||||
begin
|
||||
FCanClose := True;
|
||||
Close;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.Chromium_OnAfterCreated(Sender: TObject);
|
||||
begin
|
||||
ChromiumWindow1.UpdateSize;
|
||||
|
@ -12,6 +12,8 @@ object DOMVisitorFrm: TDOMVisitorFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -96,6 +98,8 @@ object DOMVisitorFrm: TDOMVisitorFrm
|
||||
OnContextMenuCommand = Chromium1ContextMenuCommand
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 16
|
||||
Top = 40
|
||||
end
|
||||
|
@ -94,10 +94,21 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
private
|
||||
{ Private declarations }
|
||||
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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure VisitDOMMsg(var aMessage : TMessage); message MINIBROWSER_VISITDOM;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
@ -139,6 +150,12 @@ uses
|
||||
// The OnProcessMessageReceived event can recognize any number of messages identifying them
|
||||
// by message.name
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 SimpleDOMIteration(const aDocument: ICefDomDocument);
|
||||
var
|
||||
TempHead, TempChild : ICefDomNode;
|
||||
@ -253,6 +270,13 @@ begin
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TDOMVisitorFrm.Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TDOMVisitorFrm.Chromium1BeforeContextMenu(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; const model: ICefMenuModel);
|
||||
@ -272,6 +296,13 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TDOMVisitorFrm.Chromium1Close(Sender: TObject;
|
||||
const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TDOMVisitorFrm.Chromium1ContextMenuCommand(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; commandId: Integer;
|
||||
@ -301,6 +332,25 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDOMVisitorFrm.FormCloseQuery(Sender: TObject;
|
||||
var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDOMVisitorFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TDOMVisitorFrm.FormShow(Sender: TObject);
|
||||
begin
|
||||
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
|
||||
@ -320,6 +370,11 @@ begin
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TDOMVisitorFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
procedure TDOMVisitorFrm.VisitDOMBtnClick(Sender: TObject);
|
||||
begin
|
||||
PostMessage(Handle, MINIBROWSER_VISITDOM, 0, 0);
|
||||
|
@ -15,6 +15,8 @@ object MainForm: TMainForm
|
||||
FormStyle = fsStayOnTop
|
||||
OldCreateOrder = False
|
||||
WindowState = wsMaximized
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -31,6 +33,8 @@ object MainForm: TMainForm
|
||||
OnKeyEvent = Chromium1KeyEvent
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 208
|
||||
Top = 120
|
||||
end
|
||||
|
@ -73,14 +73,25 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
private
|
||||
{ Private declarations }
|
||||
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.
|
||||
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
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;
|
||||
|
||||
procedure HandleKeyUp(const aMsg : TMsg; var aHandled : boolean);
|
||||
procedure HandleKeyDown(const aMsg : TMsg; var aHandled : boolean);
|
||||
@ -141,6 +152,12 @@ begin
|
||||
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;
|
||||
@ -153,11 +170,22 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TMainForm.Chromium1Close(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TMainForm.BrowserCreatedMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.UpdateSize;
|
||||
end;
|
||||
|
||||
procedure TMainForm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
procedure TMainForm.Chromium1KeyEvent(Sender: TObject;
|
||||
const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: PMsg;
|
||||
out Result: Boolean);
|
||||
@ -196,6 +224,24 @@ begin
|
||||
isKeyboardShortcut := True;
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormShow(Sender: TObject);
|
||||
begin
|
||||
Chromium1.DefaultUrl := 'https://www.google.com';
|
||||
|
@ -12,6 +12,7 @@ object JSDialogBrowserFrm: TJSDialogBrowserFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
OnShow = FormShow
|
||||
@ -24,6 +25,8 @@ object JSDialogBrowserFrm: TJSDialogBrowserFrm
|
||||
Height = 594
|
||||
Align = alClient
|
||||
TabOrder = 0
|
||||
OnClose = ChromiumWindow1Close
|
||||
OnBeforeClose = ChromiumWindow1BeforeClose
|
||||
OnAfterCreated = ChromiumWindow1AfterCreated
|
||||
end
|
||||
object AddressPnl: TPanel
|
||||
|
@ -67,6 +67,9 @@ type
|
||||
procedure Timer1Timer(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure ChromiumWindow1Close(Sender: TObject);
|
||||
procedure ChromiumWindow1BeforeClose(Sender: TObject);
|
||||
|
||||
protected
|
||||
FJSDialogInfoCS : TCriticalSection;
|
||||
@ -77,6 +80,10 @@ type
|
||||
FDialogType : TCefJsDialogType;
|
||||
FCallback : ICefJsDialogCallback;
|
||||
|
||||
// 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.
|
||||
|
||||
procedure Chromium_OnJsdialog(Sender: TObject; const browser: ICefBrowser; const originUrl: ustring; dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring; const callback: ICefJsDialogCallback; out suppressMessage: Boolean; out Result: Boolean);
|
||||
procedure Chromium_OnBeforePopup(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 noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
|
||||
@ -100,6 +107,12 @@ uses
|
||||
|
||||
// This is a demo with custom JS dialogs
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. The FormCloseQuery event sets CanClose to False and calls TChromiumWindow.CloseBrowser, which triggers the TChromiumWindow.OnClose event.
|
||||
// 2. The TChromiumWindow.OnClose event calls TChromiumWindow.DestroyChildWindow which triggers the TChromiumWindow.OnBeforeClose event.
|
||||
// 3. TChromiumWindow.OnBeforeClose sets FCanClose to True and closes the form.
|
||||
|
||||
procedure TJSDialogBrowserFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FJSDialogInfoCS := TCriticalSection.Create;
|
||||
@ -109,6 +122,20 @@ begin
|
||||
FPendingDlg := False;
|
||||
FDialogType := JSDIALOGTYPE_ALERT;
|
||||
FCallback := nil;
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSDialogBrowserFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
ChromiumWindow1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSDialogBrowserFrm.FormDestroy(Sender: TObject);
|
||||
@ -209,6 +236,22 @@ begin
|
||||
FJSDialogInfoCS.Release;
|
||||
end;
|
||||
|
||||
procedure TJSDialogBrowserFrm.ChromiumWindow1BeforeClose(Sender: TObject);
|
||||
begin
|
||||
FCanClose := True;
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TJSDialogBrowserFrm.ChromiumWindow1Close(Sender: TObject);
|
||||
begin
|
||||
// DestroyChildWindow will destroy the child window created by CEF at the top of the Z order.
|
||||
if not(ChromiumWindow1.DestroyChildWindow) then
|
||||
begin
|
||||
FCanClose := True;
|
||||
Close;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSDialogBrowserFrm.Chromium_OnBeforePopup(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
|
||||
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
|
||||
|
@ -12,6 +12,7 @@ object JSEvalFrm: TJSEvalFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -67,6 +68,8 @@ object JSEvalFrm: TJSEvalFrm
|
||||
OnContextMenuCommand = Chromium1ContextMenuCommand
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 16
|
||||
Top = 40
|
||||
end
|
||||
|
@ -93,14 +93,23 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
|
||||
private
|
||||
{ Private declarations }
|
||||
|
||||
protected
|
||||
FText : string;
|
||||
// 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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure ShowTextViewerMsg(var aMessage : TMessage); message MINIBROWSER_SHOWTEXTVIEWER;
|
||||
procedure EvalJSCodeMsg(var aMessage : TMessage); message MINIBROWSER_EVALJSCODE;
|
||||
procedure EvalJSBinParamMsg(var aMessage : TMessage); message MINIBROWSER_JSBINPARAM;
|
||||
@ -164,12 +173,25 @@ uses
|
||||
// Compress the binary data if necessary!
|
||||
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 TJSEvalFrm.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSEvalFrm.Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSEvalFrm.Chromium1BeforeContextMenu(Sender : TObject;
|
||||
const browser : ICefBrowser;
|
||||
const frame : ICefFrame;
|
||||
@ -192,6 +214,13 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TJSEvalFrm.Chromium1Close(Sender: TObject;
|
||||
const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSEvalFrm.Chromium1ContextMenuCommand(Sender : TObject;
|
||||
const browser : ICefBrowser;
|
||||
const frame : ICefFrame;
|
||||
@ -208,6 +237,18 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSEvalFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSEvalFrm.FormShow(Sender: TObject);
|
||||
begin
|
||||
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
|
||||
@ -227,6 +268,11 @@ begin
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TJSEvalFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
procedure TJSEvalFrm.ShowTextViewerMsg(var aMessage : TMessage);
|
||||
begin
|
||||
SimpleTextViewerFrm.Memo1.Lines.Text := FText;
|
||||
|
@ -12,6 +12,8 @@ object JSExecutingFunctionsFrm: TJSExecutingFunctionsFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
@ -66,6 +68,8 @@ object JSExecutingFunctionsFrm: TJSExecutingFunctionsFrm
|
||||
OnContextMenuCommand = Chromium1ContextMenuCommand
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -84,8 +84,19 @@ type
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
@ -122,6 +133,12 @@ implementation
|
||||
// This will send a process message to the "render" where the function can
|
||||
// be executed.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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.
|
||||
|
||||
uses
|
||||
uCEFProcessMessage, uMyV8Handler;
|
||||
|
||||
@ -164,6 +181,13 @@ begin
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSExecutingFunctionsFrm.Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSExecutingFunctionsFrm.Chromium1BeforeContextMenu(
|
||||
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; const model: ICefMenuModel);
|
||||
@ -184,6 +208,12 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TJSExecutingFunctionsFrm.Chromium1Close(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSExecutingFunctionsFrm.Chromium1ContextMenuCommand(
|
||||
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; commandId: Integer;
|
||||
@ -202,6 +232,25 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSExecutingFunctionsFrm.FormCloseQuery(Sender: TObject;
|
||||
var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSExecutingFunctionsFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSExecutingFunctionsFrm.FormDestroy(Sender: TObject);
|
||||
begin
|
||||
GlobalCallbackFunc := nil;
|
||||
@ -258,4 +307,9 @@ begin
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TJSExecutingFunctionsFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -12,6 +12,8 @@ object JSExtensionFrm: TJSExtensionFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -76,6 +78,8 @@ object JSExtensionFrm: TJSExtensionFrm
|
||||
OnContextMenuCommand = Chromium1ContextMenuCommand
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -90,10 +90,20 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
protected
|
||||
FText : string;
|
||||
// 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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure ShowTextViewerMsg(var aMessage : TMessage); message MINIBROWSER_SHOWTEXTVIEWER;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
@ -133,6 +143,12 @@ uses
|
||||
// Even if you create several TChromium objects you should have no problem because each of them will have its own
|
||||
// TChromium.OnProcessMessageReceived event to receive the messages from the extension.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 GlobalCEFApp_OnWebKitInitialized;
|
||||
var
|
||||
TempExtensionCode : string;
|
||||
@ -171,6 +187,13 @@ begin
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSExtensionFrm.Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSExtensionFrm.Chromium1BeforeContextMenu(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; const model: ICefMenuModel);
|
||||
@ -193,6 +216,13 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TJSExtensionFrm.Chromium1Close(Sender: TObject;
|
||||
const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionFrm.Chromium1ContextMenuCommand(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; commandId: Integer;
|
||||
@ -255,6 +285,25 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionFrm.FormCloseQuery(Sender: TObject;
|
||||
var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionFrm.FormShow(Sender: TObject);
|
||||
begin
|
||||
StatusBar1.Panels[0].Text := 'Initializing browser. Please wait...';
|
||||
@ -314,4 +363,9 @@ begin
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -12,6 +12,8 @@ object JSExtensionWithFunctionFrm: TJSExtensionWithFunctionFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -74,6 +76,8 @@ object JSExtensionWithFunctionFrm: TJSExtensionWithFunctionFrm
|
||||
OnProcessMessageReceived = Chromium1ProcessMessageReceived
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -74,8 +74,19 @@ type
|
||||
procedure Chromium1ProcessMessageReceived(Sender: TObject;
|
||||
const browser: ICefBrowser; sourceProcess: TCefProcessId;
|
||||
const message: ICefProcessMessage; out Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
@ -102,6 +113,12 @@ uses
|
||||
// The HTML file in this demo has a button that shows the contents of 'test.myfunc()'
|
||||
// which was registered in the GlobalCEFApp.OnWebKitInitialized event.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
var
|
||||
TempExtensionCode : string;
|
||||
@ -135,6 +152,13 @@ begin
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithFunctionFrm.Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithFunctionFrm.Chromium1BeforePopup(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
|
||||
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
|
||||
@ -147,6 +171,13 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithFunctionFrm.Chromium1Close(Sender: TObject;
|
||||
const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithFunctionFrm.Chromium1ProcessMessageReceived(
|
||||
Sender: TObject; const browser: ICefBrowser;
|
||||
sourceProcess: TCefProcessId; const message: ICefProcessMessage;
|
||||
@ -159,6 +190,25 @@ begin
|
||||
end
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithFunctionFrm.FormCloseQuery(Sender: TObject;
|
||||
var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithFunctionFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithFunctionFrm.FormShow(Sender: TObject);
|
||||
begin
|
||||
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
|
||||
@ -209,4 +259,9 @@ begin
|
||||
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithFunctionFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -12,6 +12,8 @@ object JSExtensionWithObjectParameterFrm: TJSExtensionWithObjectParameterFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -63,6 +65,8 @@ object JSExtensionWithObjectParameterFrm: TJSExtensionWithObjectParameterFrm
|
||||
object Chromium1: TChromium
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -70,8 +70,19 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
@ -101,6 +112,12 @@ uses
|
||||
// This demo is based in the code comments for the cef_register_extension function in the file
|
||||
// /include/capi/cef_v8_capi.h
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
var
|
||||
TempExtensionCode : string;
|
||||
@ -138,6 +155,13 @@ begin
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithObjectParameterFrm.Chromium1BeforeClose(
|
||||
Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithObjectParameterFrm.Chromium1BeforePopup(
|
||||
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const targetUrl, targetFrameName: ustring;
|
||||
@ -150,6 +174,32 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithObjectParameterFrm.Chromium1Close(
|
||||
Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithObjectParameterFrm.FormCloseQuery(
|
||||
Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithObjectParameterFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithObjectParameterFrm.FormShow(Sender: TObject);
|
||||
begin
|
||||
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
|
||||
@ -200,4 +250,9 @@ begin
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithObjectParameterFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -12,6 +12,8 @@ object JSRTTIExtensionFrm: TJSRTTIExtensionFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -76,6 +78,8 @@ object JSRTTIExtensionFrm: TJSRTTIExtensionFrm
|
||||
OnContextMenuCommand = Chromium1ContextMenuCommand
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -90,10 +90,20 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
protected
|
||||
FText : string;
|
||||
// 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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure ShowTextViewerMsg(var aMessage : TMessage); message MINIBROWSER_SHOWTEXTVIEWER;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
@ -131,6 +141,12 @@ uses
|
||||
// Even if you create several TChromium objects you should have no problem because each of them will have its own
|
||||
// TChromium.OnProcessMessageReceived event to receive the messages from the extension.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 GlobalCEFApp_OnWebKitInitialized;
|
||||
begin
|
||||
{$IFDEF DELPHI14_UP}
|
||||
@ -279,4 +295,42 @@ begin
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TJSRTTIExtensionFrm.Chromium1BeforeClose(
|
||||
Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSRTTIExtensionFrm.Chromium1Close(
|
||||
Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSRTTIExtensionFrm.FormCloseQuery(
|
||||
Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSRTTIExtensionFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSRTTIExtensionFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -12,6 +12,8 @@ object JSSimpleExtensionFrm: TJSSimpleExtensionFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -63,6 +65,8 @@ object JSSimpleExtensionFrm: TJSSimpleExtensionFrm
|
||||
object Chromium1: TChromium
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -70,8 +70,19 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
@ -98,6 +109,12 @@ uses
|
||||
// The HTML file in this demo has a button that shows the contents of 'test.myval'
|
||||
// which was registered in the GlobalCEFApp.OnWebKitInitialized event.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
var
|
||||
TempExtensionCode : string;
|
||||
@ -187,4 +204,42 @@ begin
|
||||
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleExtensionFrm.Chromium1BeforeClose(
|
||||
Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSSimpleExtensionFrm.Chromium1Close(
|
||||
Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleExtensionFrm.FormCloseQuery(
|
||||
Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleExtensionFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleExtensionFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -12,6 +12,8 @@ object JSSimpleWindowBindingFrm: TJSSimpleWindowBindingFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -63,6 +65,8 @@ object JSSimpleWindowBindingFrm: TJSSimpleWindowBindingFrm
|
||||
object Chromium1: TChromium
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -71,8 +71,19 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
@ -96,6 +107,12 @@ implementation
|
||||
// The HTML file in this demo has a button that shows the contents of 'window.myval'
|
||||
// which was set in the GlobalCEFApp.OnContextCreated event.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
|
||||
var
|
||||
TempValue : ICEFv8Value;
|
||||
@ -180,4 +197,42 @@ begin
|
||||
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleWindowBindingFrm.Chromium1BeforeClose(
|
||||
Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSSimpleWindowBindingFrm.Chromium1Close(
|
||||
Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleWindowBindingFrm.FormCloseQuery(
|
||||
Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleWindowBindingFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleWindowBindingFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -12,6 +12,8 @@ object JSSimpleWindowBindingFrm: TJSSimpleWindowBindingFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -63,6 +65,8 @@ object JSSimpleWindowBindingFrm: TJSSimpleWindowBindingFrm
|
||||
object Chromium1: TChromium
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -71,8 +71,20 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
protected
|
||||
FText : string;
|
||||
// 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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
@ -94,6 +106,12 @@ implementation
|
||||
// The HTML file in this demo has a button that shows the contents of 'window.myval'
|
||||
// which was set in the GlobalCEFApp.OnContextCreated event.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 TJSSimpleWindowBindingFrm.GoBtnClick(Sender: TObject);
|
||||
begin
|
||||
Chromium1.LoadURL(Edit1.Text);
|
||||
@ -166,4 +184,42 @@ begin
|
||||
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleWindowBindingFrm.Chromium1BeforeClose(
|
||||
Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSSimpleWindowBindingFrm.Chromium1Close(
|
||||
Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleWindowBindingFrm.FormCloseQuery(
|
||||
Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleWindowBindingFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSSimpleWindowBindingFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -12,6 +12,8 @@ object JSWindowBindingWithFunctionFrm: TJSWindowBindingWithFunctionFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -63,6 +65,8 @@ object JSWindowBindingWithFunctionFrm: TJSWindowBindingWithFunctionFrm
|
||||
object Chromium1: TChromium
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -70,8 +70,19 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
@ -98,6 +109,12 @@ uses
|
||||
// The HTML file in this demo has a button that shows the result of 'window.myfunc()'
|
||||
// which was set in the GlobalCEFApp.OnContextCreated event.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
|
||||
var
|
||||
TempHandler : ICefv8Handler;
|
||||
@ -184,4 +201,42 @@ begin
|
||||
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
|
||||
end;
|
||||
|
||||
procedure TJSWindowBindingWithFunctionFrm.Chromium1BeforeClose(
|
||||
Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSWindowBindingWithFunctionFrm.Chromium1Close(
|
||||
Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSWindowBindingWithFunctionFrm.FormCloseQuery(
|
||||
Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSWindowBindingWithFunctionFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSWindowBindingWithFunctionFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -12,6 +12,8 @@ object JSWindowBindingWithObjectFrm: TJSWindowBindingWithObjectFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -63,6 +65,8 @@ object JSWindowBindingWithObjectFrm: TJSWindowBindingWithObjectFrm
|
||||
object Chromium1: TChromium
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 32
|
||||
Top = 224
|
||||
end
|
||||
|
@ -70,8 +70,19 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
@ -98,6 +109,12 @@ uses
|
||||
// The HTML file in this demo has a button that shows the contents of 'window.myobj.myval'
|
||||
// which was set in the GlobalCEFApp.OnContextCreated event.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
|
||||
var
|
||||
TempAccessor : ICefV8Accessor;
|
||||
@ -185,4 +202,42 @@ begin
|
||||
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
|
||||
end;
|
||||
|
||||
procedure TJSWindowBindingWithObjectFrm.Chromium1BeforeClose(
|
||||
Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TJSWindowBindingWithObjectFrm.Chromium1Close(
|
||||
Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJSWindowBindingWithObjectFrm.FormCloseQuery(
|
||||
Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSWindowBindingWithObjectFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TJSWindowBindingWithObjectFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -240,6 +240,12 @@ object MiniBrowserFrm: TMiniBrowserFrm
|
||||
end
|
||||
item
|
||||
Width = 500
|
||||
end
|
||||
item
|
||||
Width = 100
|
||||
end
|
||||
item
|
||||
Width = 100
|
||||
end>
|
||||
end
|
||||
object Chromium1: TChromium
|
||||
@ -247,6 +253,7 @@ object MiniBrowserFrm: TMiniBrowserFrm
|
||||
OnPdfPrintFinished = Chromium1PdfPrintFinished
|
||||
OnPrefsAvailable = Chromium1PrefsAvailable
|
||||
OnResolvedHostAvailable = Chromium1ResolvedHostAvailable
|
||||
OnRenderCompMsg = Chromium1RenderCompMsg
|
||||
OnLoadingStateChange = Chromium1LoadingStateChange
|
||||
OnBeforeContextMenu = Chromium1BeforeContextMenu
|
||||
OnContextMenuCommand = Chromium1ContextMenuCommand
|
||||
@ -259,6 +266,8 @@ object MiniBrowserFrm: TMiniBrowserFrm
|
||||
OnBeforeDownload = Chromium1BeforeDownload
|
||||
OnDownloadUpdated = Chromium1DownloadUpdated
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
OnBeforeResourceLoad = Chromium1BeforeResourceLoad
|
||||
OnResourceResponse = Chromium1ResourceResponse
|
||||
Left = 32
|
||||
|
@ -186,11 +186,18 @@ type
|
||||
const request: ICefRequest; const callback: ICefRequestCallback;
|
||||
out Result: TCefReturnValue);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
procedure Chromium1RenderCompMsg(var aMessage : TMessage; var aHandled: Boolean);
|
||||
|
||||
protected
|
||||
FResponse : TStringList;
|
||||
FRequest : TStringList;
|
||||
FClosing : boolean;
|
||||
// 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.
|
||||
|
||||
procedure AddURL(const aURL : string);
|
||||
|
||||
@ -205,6 +212,7 @@ type
|
||||
procedure InspectResponse(const aResponse : ICefResponse);
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure ShowDevToolsMsg(var aMessage : TMessage); message MINIBROWSER_SHOWDEVTOOLS;
|
||||
procedure HideDevToolsMsg(var aMessage : TMessage); message MINIBROWSER_HIDEDEVTOOLS;
|
||||
procedure CopyAllTextMsg(var aMessage : TMessage); message MINIBROWSER_COPYALLTEXT;
|
||||
@ -234,6 +242,12 @@ implementation
|
||||
uses
|
||||
uPreferences, uCefStringMultimap, uSimpleTextViewer;
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 TMiniBrowserFrm.BackBtnClick(Sender: TObject);
|
||||
begin
|
||||
Chromium1.GoBack;
|
||||
@ -276,7 +290,18 @@ end;
|
||||
procedure TMiniBrowserFrm.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
if Chromium1.IsSameBrowser(browser) then
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0)
|
||||
else
|
||||
SendMessage(browser.Host.WindowHandle, WM_SETICON, 1, application.Icon.Handle); // Use the same icon in the popup window
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.Chromium1BeforeClose(Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
if (Chromium1.BrowserId = 0) then // The main browser is being destroyed
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.Chromium1BeforeContextMenu(Sender: TObject;
|
||||
@ -369,6 +394,17 @@ begin
|
||||
InspectRequest(request);
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.Chromium1Close(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
if (browser <> nil) and (Chromium1.BrowserId = browser.Identifier) then
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end
|
||||
else
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.Chromium1ContextMenuCommand(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; commandId: Integer;
|
||||
@ -617,6 +653,15 @@ begin
|
||||
isKeyboardShortcut := True;
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.Chromium1RenderCompMsg(var aMessage : TMessage; var aHandled: Boolean);
|
||||
begin
|
||||
if not(FClosing) and (aMessage.Msg = WM_MOUSEMOVE) then
|
||||
begin
|
||||
StatusBar1.Panels[2].Text := 'x : ' + inttostr(aMessage.lParam and $FFFF);
|
||||
StatusBar1.Panels[3].Text := 'y : ' + inttostr((aMessage.lParam and $FFFF0000) shr 16);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.Chromium1ResolvedHostAvailable(Sender: TObject;
|
||||
result: Integer; const resolvedIps: TStrings);
|
||||
begin
|
||||
@ -720,12 +765,19 @@ end;
|
||||
|
||||
procedure TMiniBrowserFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
CanClose := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
FResponse := TStringList.Create;
|
||||
FRequest := TStringList.Create;
|
||||
@ -767,6 +819,11 @@ begin
|
||||
Chromium1.LoadURL(MINIBROWSER_HOMEPAGE);
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.AddURL(const aURL : string);
|
||||
begin
|
||||
if (URLCbx.Items.IndexOf(aURL) < 0) then URLCbx.Items.Add(aURL);
|
||||
|
@ -12,6 +12,7 @@ object ResponseFilterBrowserFrm: TResponseFilterBrowserFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
OnShow = FormShow
|
||||
@ -120,6 +121,8 @@ object ResponseFilterBrowserFrm: TResponseFilterBrowserFrm
|
||||
object Chromium1: TChromium
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
OnGetResourceResponseFilter = Chromium1GetResourceResponseFilter
|
||||
OnResourceLoadComplete = Chromium1ResourceLoadComplete
|
||||
Left = 56
|
||||
|
@ -82,18 +82,27 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
protected
|
||||
FFilter : ICefResponseFilter; // CEF Filter interface that receives the resource contents
|
||||
FStream : TMemoryStream; // TMemoryStream to hold the resource contents
|
||||
FStreamCS : TCriticalSection; // Critical section used to protect the memory stream
|
||||
FRscSize : int64; // size of the resource if the server sends the Content-Length header
|
||||
FRscCompleted : boolean; // This variable will be used to handle the results only once.
|
||||
// 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.
|
||||
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
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;
|
||||
procedure StreamCopyCompleteMsg(var aMessage : TMessage); message STREAM_COPY_COMPLETE;
|
||||
|
||||
procedure Filter_OnFilter(Sender: TObject; data_in: Pointer; data_in_size: NativeUInt; var data_in_read: NativeUInt; data_out: Pointer; data_out_size : NativeUInt; var data_out_written: NativeUInt; var aResult : TCefResponseFilterStatus);
|
||||
@ -124,6 +133,12 @@ uses
|
||||
// For more information read the CEF3 code comments here :
|
||||
// https://github.com/chromiumembedded/cef/blob/master/include/capi/cef_response_filter_capi.h
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 TResponseFilterBrowserFrm.Filter_OnFilter(Sender: TObject;
|
||||
data_in : Pointer;
|
||||
data_in_size : NativeUInt;
|
||||
@ -193,6 +208,18 @@ begin
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
procedure TResponseFilterBrowserFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TResponseFilterBrowserFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FRscCompleted := False;
|
||||
@ -201,6 +228,9 @@ begin
|
||||
FStreamCS := TCriticalSection.Create;
|
||||
FFilter := TCustomResponseFilter.Create;
|
||||
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
|
||||
// This event will receive the data
|
||||
TCustomResponseFilter(FFilter).OnFilter := Filter_OnFilter;
|
||||
end;
|
||||
@ -225,6 +255,13 @@ begin
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TResponseFilterBrowserFrm.Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TResponseFilterBrowserFrm.Chromium1BeforePopup(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
|
||||
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
|
||||
@ -237,6 +274,13 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TResponseFilterBrowserFrm.Chromium1Close(Sender: TObject;
|
||||
const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TResponseFilterBrowserFrm.Chromium1GetResourceResponseFilter(Sender : TObject;
|
||||
const browser : ICefBrowser;
|
||||
const frame : ICefFrame;
|
||||
@ -283,6 +327,11 @@ begin
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TResponseFilterBrowserFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
// This procedure handles the stream contents after it's fully downloaded
|
||||
procedure TResponseFilterBrowserFrm.StreamCopyCompleteMsg(var aMessage : TMessage);
|
||||
begin
|
||||
|
@ -12,6 +12,7 @@ object SchemeRegistrationBrowserFrm: TSchemeRegistrationBrowserFrm
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
@ -70,6 +71,8 @@ object SchemeRegistrationBrowserFrm: TSchemeRegistrationBrowserFrm
|
||||
OnContextMenuCommand = Chromium1ContextMenuCommand
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 16
|
||||
Top = 40
|
||||
end
|
||||
|
@ -85,10 +85,20 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
private
|
||||
{ Private declarations }
|
||||
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.
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
@ -109,6 +119,12 @@ implementation
|
||||
uses
|
||||
uCEFSchemeHandlerFactory, uCEFMiscFunctions, uHelloScheme;
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_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 GlobalCEFApp_OnRegCustomSchemes(const registrar: TCefSchemeRegistrarRef);
|
||||
begin
|
||||
registrar.AddCustomScheme('hello', True, True, False, False, False, False);
|
||||
@ -119,6 +135,13 @@ begin
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.Chromium1BeforeClose(
|
||||
Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.Chromium1BeforeContextMenu(
|
||||
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; const model: ICefMenuModel);
|
||||
@ -139,6 +162,13 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.Chromium1Close(Sender: TObject;
|
||||
const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.Chromium1ContextMenuCommand(
|
||||
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
|
||||
const params: ICefContextMenuParams; commandId: Integer;
|
||||
@ -171,6 +201,18 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
// You can register the Scheme Handler Factory here or later, for example in a context menu command.
|
||||
@ -203,6 +245,11 @@ begin
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.WMMove(var aMessage : TWMMove);
|
||||
begin
|
||||
inherited;
|
||||
|
@ -12,6 +12,8 @@ object Form1: TForm1
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -22,6 +24,8 @@ object Form1: TForm1
|
||||
Height = 594
|
||||
Align = alClient
|
||||
TabOrder = 0
|
||||
OnClose = ChromiumWindow1Close
|
||||
OnBeforeClose = ChromiumWindow1BeforeClose
|
||||
OnAfterCreated = ChromiumWindow1AfterCreated
|
||||
end
|
||||
object AddressPnl: TPanel
|
||||
|
@ -62,6 +62,10 @@ type
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure ChromiumWindow1AfterCreated(Sender: TObject);
|
||||
procedure Timer1Timer(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure ChromiumWindow1Close(Sender: TObject);
|
||||
procedure ChromiumWindow1BeforeClose(Sender: TObject);
|
||||
private
|
||||
// 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;
|
||||
@ -71,6 +75,10 @@ type
|
||||
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
||||
|
||||
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.
|
||||
|
||||
procedure Chromium_OnBeforePopup(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 noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
|
||||
public
|
||||
@ -99,6 +107,31 @@ uses
|
||||
// or the domain "google.com". If you don't live in the US, you'll be redirected to
|
||||
// another domain which will take a little time too.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. The FormCloseQuery event sets CanClose to False and calls TChromiumWindow.CloseBrowser, which triggers the TChromiumWindow.OnClose event.
|
||||
// 2. The TChromiumWindow.OnClose event calls TChromiumWindow.DestroyChildWindow which triggers the TChromiumWindow.OnBeforeClose event.
|
||||
// 3. TChromiumWindow.OnBeforeClose sets FCanClose to True and closes the form.
|
||||
|
||||
|
||||
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
ChromiumWindow1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormShow(Sender: TObject);
|
||||
begin
|
||||
// For simplicity, this demo blocks all popup windows and new tabs
|
||||
@ -113,6 +146,22 @@ begin
|
||||
if not(ChromiumWindow1.CreateBrowser) then Timer1.Enabled := True;
|
||||
end;
|
||||
|
||||
procedure TForm1.ChromiumWindow1BeforeClose(Sender: TObject);
|
||||
begin
|
||||
FCanClose := True;
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TForm1.ChromiumWindow1Close(Sender: TObject);
|
||||
begin
|
||||
// DestroyChildWindow will destroy the child window created by CEF at the top of the Z order.
|
||||
if not(ChromiumWindow1.DestroyChildWindow) then
|
||||
begin
|
||||
FCanClose := True;
|
||||
Close;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.Chromium_OnBeforePopup(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
|
||||
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
|
||||
|
@ -12,6 +12,8 @@ object Form1: TForm1
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -70,6 +72,8 @@ object Form1: TForm1
|
||||
object Chromium1: TChromium
|
||||
OnBeforePopup = Chromium1BeforePopup
|
||||
OnAfterCreated = Chromium1AfterCreated
|
||||
OnBeforeClose = Chromium1BeforeClose
|
||||
OnClose = Chromium1Close
|
||||
Left = 56
|
||||
Top = 152
|
||||
end
|
||||
|
@ -70,7 +70,17 @@ type
|
||||
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
|
||||
var client: ICefClient; var settings: TCefBrowserSettings;
|
||||
var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
private
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser;
|
||||
out Result: Boolean);
|
||||
procedure Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
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;
|
||||
@ -79,6 +89,7 @@ type
|
||||
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;
|
||||
@ -107,6 +118,24 @@ uses
|
||||
|
||||
// This demo uses a TChromium and a TCEFWindowParent
|
||||
|
||||
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
Chromium1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormShow(Sender: TObject);
|
||||
begin
|
||||
// You *MUST* call CreateBrowser to create and initialize the browser.
|
||||
@ -124,6 +153,13 @@ begin
|
||||
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TForm1.Chromium1BeforeClose(Sender: TObject;
|
||||
const browser: ICefBrowser);
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TForm1.Chromium1BeforePopup(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
|
||||
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
|
||||
@ -136,6 +172,13 @@ begin
|
||||
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||
end;
|
||||
|
||||
procedure TForm1.Chromium1Close(Sender: TObject;
|
||||
const browser: ICefBrowser; out Result: Boolean);
|
||||
begin
|
||||
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TForm1.BrowserCreatedMsg(var aMessage : TMessage);
|
||||
begin
|
||||
Caption := 'Simple Browser 2';
|
||||
@ -143,6 +186,11 @@ begin
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TForm1.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
begin
|
||||
CEFWindowParent1.Free;
|
||||
end;
|
||||
|
||||
procedure TForm1.GoBtnClick(Sender: TObject);
|
||||
begin
|
||||
// This will load the URL in the edit box
|
||||
|
@ -166,7 +166,11 @@ end;
|
||||
procedure TSimpleExternalPumpBrowserFrm.ChromiumWindow1Close(Sender: TObject);
|
||||
begin
|
||||
// DestroyChildWindow will destroy the child window created by CEF at the top of the Z order.
|
||||
ChromiumWindow1.DestroyChildWindow;
|
||||
if not(ChromiumWindow1.DestroyChildWindow) then
|
||||
begin
|
||||
FCanClose := True;
|
||||
Close;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSimpleExternalPumpBrowserFrm.GoBtnClick(Sender: TObject);
|
||||
|
@ -12,6 +12,7 @@ object Form1: TForm1
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
@ -22,6 +23,8 @@ object Form1: TForm1
|
||||
Height = 594
|
||||
Align = alClient
|
||||
TabOrder = 0
|
||||
OnClose = ChromiumWindow1Close
|
||||
OnBeforeClose = ChromiumWindow1BeforeClose
|
||||
OnAfterCreated = ChromiumWindow1AfterCreated
|
||||
end
|
||||
object AddressPnl: TPanel
|
||||
|
@ -62,6 +62,9 @@ type
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure ChromiumWindow1AfterCreated(Sender: TObject);
|
||||
procedure Timer1Timer(Sender: TObject);
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
procedure ChromiumWindow1Close(Sender: TObject);
|
||||
procedure ChromiumWindow1BeforeClose(Sender: TObject);
|
||||
private
|
||||
// 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;
|
||||
@ -70,6 +73,10 @@ type
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
||||
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.
|
||||
|
||||
procedure Chromium_OnBeforePopup(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 noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
|
||||
public
|
||||
@ -98,6 +105,24 @@ uses
|
||||
// or the domain "google.com". If you don't live in the US, you'll be redirected to
|
||||
// another domain which will take a little time too.
|
||||
|
||||
// Destruction steps
|
||||
// =================
|
||||
// 1. The FormCloseQuery event sets CanClose to False and calls TChromiumWindow.CloseBrowser, which triggers the TChromiumWindow.OnClose event.
|
||||
// 2. The TChromiumWindow.OnClose event calls TChromiumWindow.DestroyChildWindow which triggers the TChromiumWindow.OnBeforeClose event.
|
||||
// 3. TChromiumWindow.OnBeforeClose sets FCanClose to True and closes the form.
|
||||
|
||||
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
ChromiumWindow1.CloseBrowser(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormShow(Sender: TObject);
|
||||
begin
|
||||
Caption := 'Simple Browser - Initializing browser. Please wait...';
|
||||
@ -112,6 +137,22 @@ begin
|
||||
if not(ChromiumWindow1.CreateBrowser) then Timer1.Enabled := True;
|
||||
end;
|
||||
|
||||
procedure TForm1.ChromiumWindow1Close(Sender: TObject);
|
||||
begin
|
||||
// DestroyChildWindow will destroy the child window created by CEF at the top of the Z order.
|
||||
if not(ChromiumWindow1.DestroyChildWindow) then
|
||||
begin
|
||||
FCanClose := True;
|
||||
Close;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.ChromiumWindow1BeforeClose(Sender: TObject);
|
||||
begin
|
||||
FCanClose := True;
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TForm1.Chromium_OnBeforePopup(Sender: TObject;
|
||||
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
|
||||
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
|
||||
|
@ -13,6 +13,7 @@ object MainForm: TMainForm
|
||||
OldCreateOrder = False
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
|
@ -55,6 +55,7 @@ const
|
||||
CEFBROWSER_DESTROYWNDPARENT = WM_APP + $100;
|
||||
CEFBROWSER_DESTROYTAB = WM_APP + $101;
|
||||
CEFBROWSER_INITIALIZED = WM_APP + $102;
|
||||
CEFBROWSER_CHECKTAGGEDTABS = WM_APP + $103;
|
||||
|
||||
type
|
||||
TMainForm = class(TForm)
|
||||
@ -81,9 +82,12 @@ type
|
||||
procedure ReloadBtnClick(Sender: TObject);
|
||||
procedure StopBtnClick(Sender: TObject);
|
||||
procedure GoBtnClick(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
|
||||
protected
|
||||
FDestroying : boolean;
|
||||
FClosingTab : boolean;
|
||||
FCanClose : boolean;
|
||||
FClosing : boolean;
|
||||
|
||||
procedure Chromium_OnAfterCreated(Sender: TObject; const browser: ICefBrowser);
|
||||
procedure Chromium_OnAddressChange(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const url: ustring);
|
||||
@ -92,16 +96,18 @@ type
|
||||
procedure Chromium_OnBeforeClose(Sender: TObject; const browser: ICefBrowser);
|
||||
procedure Chromium_OnBeforePopup(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 noJavascriptAccess: Boolean; var Result: Boolean);
|
||||
|
||||
|
||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||
procedure BrowserDestroyWindowParentMsg(var aMessage : TMessage); message CEFBROWSER_DESTROYWNDPARENT;
|
||||
procedure BrowserDestroyTabMsg(var aMessage : TMessage); message CEFBROWSER_DESTROYTAB;
|
||||
procedure BrowserCheckTaggedTabsMsg(var aMessage : TMessage); message CEFBROWSER_CHECKTAGGEDTABS;
|
||||
procedure CEFInitializedMsg(var aMessage : TMessage); message CEFBROWSER_INITIALIZED;
|
||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
||||
|
||||
function AllTabSheetsAreTagged : boolean;
|
||||
procedure CloseAllBrowsers;
|
||||
function GetPageIndex(const aSender : TObject; var aPageIndex : integer) : boolean;
|
||||
procedure NotifyMoveOrResizeStarted;
|
||||
function SearchChromium(aPageIndex : integer; var aChromium : TChromium) : boolean;
|
||||
@ -130,11 +136,16 @@ implementation
|
||||
// For simplicity the Button panel and the PageControl are disabled while adding or removing tab sheets.
|
||||
// The Form can't be closed if it's destroying a tab.
|
||||
|
||||
// This is the destruction sequence when you remove a tab sheet:
|
||||
// This is the destruction sequence when a user closes a tab sheet:
|
||||
// 1. RemoveTabBtnClick calls TChromium.CloseBrowser of the selected tab which triggers a TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_DESTROYWNDPARENT message to destroy TCEFWindowParent in the main thread which triggers a TChromium.OnBeforeClose event.
|
||||
// 3. TChromium.OnBeforeClose sends a CEFBROWSER_DESTROYTAB message to destroy the tab in the main thread.
|
||||
|
||||
// This is the destruction sequence when the user closes the main form
|
||||
// 1. FormCloseQuery hides the form and calls CloseAllBrowsers which calls TChromium.CloseBrowser in all tabs and triggers the TChromium.OnClose event.
|
||||
// 2. TChromium.OnClose sends a CEFBROWSER_DESTROYWNDPARENT message to destroy TCEFWindowParent in the main thread which triggers a TChromium.OnBeforeClose event.
|
||||
// 3. TChromium.OnBeforeClose sends a CEFBROWSER_CHECKTAGGEDTABS message to set the TAG property to 1 in the TabSheet containing the TChromium. Then sends WM_CLOSE in case all tabsheets have a TAG = 1.
|
||||
|
||||
procedure GlobalCEFApp_OnContextInitialized;
|
||||
begin
|
||||
if (MainForm <> nil) and MainForm.HandleAllocated then
|
||||
@ -176,7 +187,7 @@ var
|
||||
begin
|
||||
if SearchChromium(PageControl1.TabIndex, TempChromium) then
|
||||
begin
|
||||
FDestroying := True;
|
||||
FClosingTab := True;
|
||||
ButtonPnl.Enabled := False;
|
||||
PageControl1.Enabled := False;
|
||||
TempChromium.CloseBrowser(True);
|
||||
@ -185,7 +196,60 @@ end;
|
||||
|
||||
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
begin
|
||||
CanClose := not(FDestroying);
|
||||
if FClosingTab then
|
||||
CanClose := False
|
||||
else
|
||||
begin
|
||||
CanClose := FCanClose;
|
||||
|
||||
if not(FClosing) then
|
||||
begin
|
||||
FClosing := True;
|
||||
Visible := False;
|
||||
|
||||
CloseAllBrowsers;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.CloseAllBrowsers;
|
||||
var
|
||||
i, j, k : integer;
|
||||
TempComponent : TComponent;
|
||||
TempSheet : TTabSheet;
|
||||
TempCtnue : boolean;
|
||||
begin
|
||||
k := pred(PageControl1.PageCount);
|
||||
|
||||
while (k >= 0) do
|
||||
begin
|
||||
TempSheet := PageControl1.Pages[k];
|
||||
TempCtnue := True;
|
||||
i := 0;
|
||||
j := TempSheet.ComponentCount;
|
||||
|
||||
while (i < j) and TempCtnue do
|
||||
begin
|
||||
TempComponent := TempSheet.Components[i];
|
||||
|
||||
if (TempComponent <> nil) and (TempComponent is TChromium) then
|
||||
begin
|
||||
TChromium(TempComponent).CloseBrowser(True);
|
||||
TempCtnue := False;
|
||||
end
|
||||
else
|
||||
inc(i);
|
||||
end;
|
||||
|
||||
dec(k);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FClosingTab := False;
|
||||
FCanClose := False;
|
||||
FClosing := False;
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormShow(Sender: TObject);
|
||||
@ -264,9 +328,38 @@ begin
|
||||
(aMessage.lParam < PageControl1.PageCount) then
|
||||
PageControl1.Pages[aMessage.lParam].Free;
|
||||
|
||||
FClosingTab := False;
|
||||
ButtonPnl.Enabled := True;
|
||||
PageControl1.Enabled := True;
|
||||
FDestroying := False;
|
||||
end;
|
||||
|
||||
procedure TMainForm.BrowserCheckTaggedTabsMsg(var aMessage : TMessage);
|
||||
begin
|
||||
if (aMessage.lParam >= 0) and
|
||||
(aMessage.lParam < PageControl1.PageCount) then
|
||||
begin
|
||||
PageControl1.Pages[aMessage.lParam].Tag := 1;
|
||||
|
||||
if AllTabSheetsAreTagged then
|
||||
begin
|
||||
FCanClose := True;
|
||||
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TMainForm.AllTabSheetsAreTagged : boolean;
|
||||
var
|
||||
i : integer;
|
||||
begin
|
||||
Result := True;
|
||||
i := pred(PageControl1.PageCount);
|
||||
|
||||
while (i >= 0) and Result do
|
||||
if (PageControl1.Pages[i].Tag <> 1) then
|
||||
Result := False
|
||||
else
|
||||
dec(i);
|
||||
end;
|
||||
|
||||
procedure TMainForm.Chromium_OnAfterCreated(Sender: TObject; const browser: ICefBrowser);
|
||||
@ -281,7 +374,8 @@ procedure TMainForm.Chromium_OnAddressChange(Sender: TObject; const browser: ICe
|
||||
var
|
||||
TempPageIndex : integer;
|
||||
begin
|
||||
if (PageControl1.TabIndex >= 0) and
|
||||
if not(FClosing) and
|
||||
(PageControl1.TabIndex >= 0) and
|
||||
GetPageIndex(Sender, TempPageIndex) and
|
||||
(PageControl1.TabIndex = TempPageIndex) then
|
||||
URLCbx.Text := url;
|
||||
@ -306,7 +400,7 @@ procedure TMainForm.Chromium_OnTitleChange(Sender: TObject; const browser: ICefB
|
||||
var
|
||||
TempPageIndex : integer;
|
||||
begin
|
||||
if GetPageIndex(Sender, TempPageIndex) then
|
||||
if not(FClosing) and GetPageIndex(Sender, TempPageIndex) then
|
||||
PageControl1.Pages[TempPageIndex].Caption := title;
|
||||
end;
|
||||
|
||||
@ -325,7 +419,12 @@ var
|
||||
TempPageIndex : integer;
|
||||
begin
|
||||
if GetPageIndex(Sender, TempPageIndex) then
|
||||
begin
|
||||
if FClosing then
|
||||
PostMessage(Handle, CEFBROWSER_CHECKTAGGEDTABS, 0, TempPageIndex)
|
||||
else
|
||||
PostMessage(Handle, CEFBROWSER_DESTROYTAB, 0, TempPageIndex);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.Chromium_OnBeforePopup(Sender: TObject;
|
||||
@ -405,7 +504,7 @@ var
|
||||
i, j : integer;
|
||||
TempChromium : TChromium;
|
||||
begin
|
||||
if not(showing) or (PageControl1 = nil) then exit;
|
||||
if not(showing) or (PageControl1 = nil) or FClosing then exit;
|
||||
|
||||
i := 0;
|
||||
j := PageControl1.PageCount;
|
||||
@ -436,14 +535,16 @@ procedure TMainForm.WMEnterMenuLoop(var aMessage: TMessage);
|
||||
begin
|
||||
inherited;
|
||||
|
||||
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True;
|
||||
if not(FClosing) and (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;
|
||||
if not(FClosing) and (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then
|
||||
GlobalCEFApp.OsmodalLoop := False;
|
||||
end;
|
||||
|
||||
procedure TMainForm.PageControl1Change(Sender: TObject);
|
||||
|
@ -57,7 +57,7 @@ uses
|
||||
const
|
||||
CEF_SUPPORTED_VERSION_MAJOR = 3;
|
||||
CEF_SUPPORTED_VERSION_MINOR = 3325;
|
||||
CEF_SUPPORTED_VERSION_RELEASE = 1755;
|
||||
CEF_SUPPORTED_VERSION_RELEASE = 1756;
|
||||
CEF_SUPPORTED_VERSION_BUILD = 0;
|
||||
|
||||
CEF_CHROMEELF_VERSION_MAJOR = 65;
|
||||
@ -135,6 +135,7 @@ type
|
||||
FMissingLibFiles : string;
|
||||
FProcessType : TCefProcessType;
|
||||
FShutdownWaitTime : cardinal;
|
||||
FWidevinePath : string;
|
||||
|
||||
FMustCreateResourceBundleHandler : boolean;
|
||||
FMustCreateBrowserProcessHandler : boolean;
|
||||
@ -162,6 +163,9 @@ type
|
||||
FOnFocusedNodeChanged : TOnFocusedNodeChangedEvent;
|
||||
FOnProcessMessageReceived : TOnProcessMessageReceivedEvent;
|
||||
|
||||
// ICefRegisterCDMCallback
|
||||
FOnCDMRegistrationComplete : TOnCDMRegistrationCompleteEvent;
|
||||
|
||||
procedure SetCache(const aValue : ustring);
|
||||
procedure SetFrameworkDirPath(const aValue : ustring);
|
||||
procedure SetResourcesDirPath(const aValue : ustring);
|
||||
@ -175,6 +179,7 @@ type
|
||||
function GetMustCreateBrowserProcessHandler : boolean;
|
||||
function GetMustCreateRenderProcessHandler : boolean;
|
||||
function GetGlobalContextInitialized : boolean;
|
||||
function GetChildProcessesCount : integer;
|
||||
|
||||
function LoadCEFlibrary : boolean; virtual;
|
||||
function Load_cef_app_capi_h : boolean;
|
||||
@ -227,6 +232,7 @@ type
|
||||
function SingleExeProcessing : boolean;
|
||||
function CheckCEFLibrary : boolean;
|
||||
procedure DeleteDirContents(const aDirectory : string);
|
||||
procedure RegisterWidevineCDM;
|
||||
function FindFlashDLL(var aFileName : string) : boolean;
|
||||
procedure ShowErrorMessageDlg(const aError : string); virtual;
|
||||
function ParseProcessType : TCefProcessType;
|
||||
@ -245,7 +251,8 @@ type
|
||||
procedure UpdateDeviceScaleFactor;
|
||||
|
||||
// Internal procedures. Only TInternalApp, TCefCustomBrowserProcessHandler,
|
||||
// ICefResourceBundleHandler and ICefRenderProcessHandler should use them.
|
||||
// ICefResourceBundleHandler, ICefRenderProcessHandler and ICefRegisterCDMCallback
|
||||
// should use them.
|
||||
procedure Internal_OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine);
|
||||
procedure Internal_OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef);
|
||||
procedure Internal_OnContextInitialized;
|
||||
@ -264,7 +271,7 @@ type
|
||||
procedure Internal_OnUncaughtException(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context; const exception: ICefV8Exception; const stackTrace: ICefV8StackTrace);
|
||||
procedure Internal_OnFocusedNodeChanged(const browser: ICefBrowser; const frame: ICefFrame; const node: ICefDomNode);
|
||||
procedure Internal_OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const aMessage: ICefProcessMessage; var aHandled : boolean);
|
||||
|
||||
procedure Internal_OnCDMRegistrationComplete(result : TCefCDMRegistrationError; const error_message : ustring);
|
||||
|
||||
property Cache : ustring read FCache write SetCache;
|
||||
property Cookies : ustring read FCookies write FCookies;
|
||||
@ -334,6 +341,8 @@ type
|
||||
property Status : TCefAplicationStatus read FStatus;
|
||||
property MissingLibFiles : string read FMissingLibFiles;
|
||||
property ShutdownWaitTime : cardinal read FShutdownWaitTime write FShutdownWaitTime;
|
||||
property WidevinePath : string read FWidevinePath write FWidevinePath;
|
||||
property ChildProcessesCount : integer read GetChildProcessesCount;
|
||||
|
||||
property OnRegCustomSchemes : TOnRegisterCustomSchemes read FOnRegisterCustomSchemes write FOnRegisterCustomSchemes;
|
||||
|
||||
@ -358,6 +367,9 @@ type
|
||||
property OnUncaughtException : TOnUncaughtExceptionEvent read FOnUncaughtException write FOnUncaughtException;
|
||||
property OnFocusedNodeChanged : TOnFocusedNodeChangedEvent read FOnFocusedNodeChanged write FOnFocusedNodeChanged;
|
||||
property OnProcessMessageReceived : TOnProcessMessageReceivedEvent read FOnProcessMessageReceived write FOnProcessMessageReceived;
|
||||
|
||||
// ICefRegisterCDMCallback
|
||||
property OnCDMRegistrationComplete : TOnCDMRegistrationCompleteEvent read FOnCDMRegistrationComplete write FOnCDMRegistrationComplete;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -372,7 +384,7 @@ uses
|
||||
Math, {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} SysUtils, {$IFDEF MSWINDOWS}TlHelp32,{$ENDIF}
|
||||
{$ENDIF}
|
||||
uCEFLibFunctions, uCEFMiscFunctions, uCEFCommandLine, uCEFConstants,
|
||||
uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp;
|
||||
uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp, uCEFRegisterCDMCallback;
|
||||
|
||||
constructor TCefApplication.Create;
|
||||
begin
|
||||
@ -439,6 +451,7 @@ begin
|
||||
FLocalesRequired := '';
|
||||
FProcessType := ParseProcessType;
|
||||
FShutdownWaitTime := 0;
|
||||
FWidevinePath := '';
|
||||
|
||||
FMustCreateResourceBundleHandler := False;
|
||||
FMustCreateBrowserProcessHandler := True;
|
||||
@ -466,6 +479,9 @@ begin
|
||||
FOnFocusedNodeChanged := nil;
|
||||
FOnProcessMessageReceived := nil;
|
||||
|
||||
// ICefRegisterCDMCallback
|
||||
FOnCDMRegistrationComplete := nil;
|
||||
|
||||
UpdateDeviceScaleFactor;
|
||||
|
||||
FAppSettings.size := SizeOf(TCefSettings);
|
||||
@ -489,6 +505,7 @@ begin
|
||||
if (FProcessType = ptBrowser) then
|
||||
begin
|
||||
if (FShutdownWaitTime > 0) then sleep(FShutdownWaitTime);
|
||||
|
||||
ShutDown;
|
||||
end;
|
||||
|
||||
@ -830,6 +847,8 @@ begin
|
||||
if FDeleteCache then DeleteDirContents(FCache);
|
||||
if FDeleteCookies then DeleteDirContents(FCookies);
|
||||
|
||||
RegisterWidevineCDM;
|
||||
|
||||
InitializeSettings(FAppSettings);
|
||||
|
||||
TempArgs.instance := HINSTANCE;
|
||||
@ -910,6 +929,29 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCefApplication.RegisterWidevineCDM;
|
||||
var
|
||||
TempPath : TCefString;
|
||||
TempCallback : ICefRegisterCDMCallback;
|
||||
begin
|
||||
try
|
||||
try
|
||||
if FLibLoaded and (length(FWidevinePath) > 0) and DirectoryExists(FWidevinePath) then
|
||||
begin
|
||||
TempPath := CefString(FWidevinePath);
|
||||
TempCallback := TCefCustomRegisterCDMCallback.Create(self);
|
||||
|
||||
cef_register_widevine_cdm(@TempPath, TempCallback.Wrap);
|
||||
end;
|
||||
except
|
||||
on e : exception do
|
||||
if CustomExceptionHandler('TCefApplication.RegisterWidevineCDM', e) then raise;
|
||||
end;
|
||||
finally
|
||||
TempCallback := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCefApplication.FindFlashDLL(var aFileName : string) : boolean;
|
||||
var
|
||||
TempSearchRec : TSearchRec;
|
||||
@ -1083,6 +1125,11 @@ begin
|
||||
aHandled := False;
|
||||
end;
|
||||
|
||||
procedure TCefApplication.Internal_OnCDMRegistrationComplete(result : TCefCDMRegistrationError; const error_message : ustring);
|
||||
begin
|
||||
if assigned(FOnCDMRegistrationComplete) then FOnCDMRegistrationComplete(result, error_message);
|
||||
end;
|
||||
|
||||
procedure TCefApplication.Internal_OnBeforeCommandLineProcessing(const processType : ustring;
|
||||
const commandLine : ICefCommandLine);
|
||||
var
|
||||
@ -1216,6 +1263,43 @@ begin
|
||||
Result := FGlobalContextInitialized or not(MustCreateBrowserProcessHandler);
|
||||
end;
|
||||
|
||||
function TCefApplication.GetChildProcessesCount : integer;
|
||||
{$IFDEF MSWINDOWS}
|
||||
var
|
||||
TempHandle : THandle;
|
||||
TempProcess : TProcessEntry32;
|
||||
TempPID : DWORD;
|
||||
TempMain, TempSubProc, TempName : string;
|
||||
{$ENDIF}
|
||||
begin
|
||||
Result := 0;
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
TempHandle := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
|
||||
TempProcess.dwSize := Sizeof(TProcessEntry32);
|
||||
TempPID := GetCurrentProcessID;
|
||||
TempMain := ExtractFileName(paramstr(0));
|
||||
TempSubProc := ExtractFileName(FBrowserSubprocessPath);
|
||||
|
||||
Process32First(TempHandle, TempProcess);
|
||||
|
||||
repeat
|
||||
if (TempProcess.th32ProcessID <> TempPID) and
|
||||
(TempProcess.th32ParentProcessID = TempPID) then
|
||||
begin
|
||||
TempName := TempProcess.szExeFile;
|
||||
TempName := ExtractFileName(TempName);
|
||||
|
||||
if (CompareText(TempName, TempMain) = 0) or
|
||||
((length(TempSubProc) > 0) and (CompareText(TempName, TempSubProc) = 0)) then
|
||||
inc(Result);
|
||||
end;
|
||||
until not(Process32Next(TempHandle, TempProcess));
|
||||
|
||||
CloseHandle(TempHandle);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function TCefApplication.LoadCEFlibrary : boolean;
|
||||
var
|
||||
TempOldDir, TempString : string;
|
||||
|
@ -105,6 +105,15 @@ type
|
||||
FWebRTCIPHandlingPolicy : TCefWebRTCHandlingPolicy;
|
||||
FWebRTCMultipleRoutes : TCefState;
|
||||
FWebRTCNonProxiedUDP : TCefState;
|
||||
FOldBrowserCompWndPrc : Pointer;
|
||||
FOldWidgetCompWndPrc : Pointer;
|
||||
FOldRenderCompWndPrc : Pointer;
|
||||
FBrowserCompHWND : THandle;
|
||||
FWidgetCompHWND : THandle;
|
||||
FRenderCompHWND : THandle;
|
||||
FBrowserCompStub : Pointer;
|
||||
FWidgetCompStub : Pointer;
|
||||
FRenderCompStub : Pointer;
|
||||
|
||||
// ICefClient
|
||||
FOnProcessMessageReceived : TOnProcessMessageReceived;
|
||||
@ -207,6 +216,9 @@ type
|
||||
FOnPrefsAvailable : TOnPrefsAvailableEvent;
|
||||
FOnCookiesDeleted : TOnCookiesDeletedEvent;
|
||||
FOnResolvedHostAvailable : TOnResolvedIPsAvailableEvent;
|
||||
FOnBrowserCompMsg : TOnCompMsgEvent;
|
||||
FOnWidgetCompMsg : TOnCompMsgEvent;
|
||||
FOnRenderCompMsg : TOnCompMsgEvent;
|
||||
|
||||
function GetIsLoading : boolean;
|
||||
function GetMultithreadApp : boolean;
|
||||
@ -305,6 +317,10 @@ type
|
||||
procedure ToMouseEvent(grfKeyState : Longint; pt : TPoint; var aMouseEvent : TCefMouseEvent);
|
||||
procedure WndProc(var aMessage: TMessage);
|
||||
|
||||
procedure BrowserCompWndProc(var aMessage: TMessage);
|
||||
procedure WidgetCompWndProc(var aMessage: TMessage);
|
||||
procedure RenderCompWndProc(var aMessage: TMessage);
|
||||
|
||||
procedure DragDropManager_OnDragEnter(Sender: TObject; const aDragData : ICefDragData; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint);
|
||||
procedure DragDropManager_OnDragOver(Sender: TObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint);
|
||||
procedure DragDropManager_OnDragLeave(Sender: TObject);
|
||||
@ -576,6 +592,9 @@ type
|
||||
property OnPrefsAvailable : TOnPrefsAvailableEvent read FOnPrefsAvailable write FOnPrefsAvailable;
|
||||
property OnCookiesDeleted : TOnCookiesDeletedEvent read FOnCookiesDeleted write FOnCookiesDeleted;
|
||||
property OnResolvedHostAvailable : TOnResolvedIPsAvailableEvent read FOnResolvedHostAvailable write FOnResolvedHostAvailable;
|
||||
property OnBrowserCompMsg : TOnCompMsgEvent read FOnBrowserCompMsg write FOnBrowserCompMsg;
|
||||
property OnWidgetCompMsg : TOnCompMsgEvent read FOnWidgetCompMsg write FOnWidgetCompMsg;
|
||||
property OnRenderCompMsg : TOnCompMsgEvent read FOnRenderCompMsg write FOnRenderCompMsg;
|
||||
|
||||
// ICefClient
|
||||
property OnProcessMessageReceived : TOnProcessMessageReceived read FOnProcessMessageReceived write FOnProcessMessageReceived;
|
||||
@ -715,6 +734,15 @@ begin
|
||||
FImagesPrefs := CEF_CONTENT_SETTING_ALLOW;
|
||||
FZoomStep := ZOOM_STEP_DEF;
|
||||
FWindowName := '';
|
||||
FOldBrowserCompWndPrc := nil;
|
||||
FOldWidgetCompWndPrc := nil;
|
||||
FOldRenderCompWndPrc := nil;
|
||||
FBrowserCompHWND := 0;
|
||||
FWidgetCompHWND := 0;
|
||||
FRenderCompHWND := 0;
|
||||
FBrowserCompStub := nil;
|
||||
FWidgetCompStub := nil;
|
||||
FRenderCompStub := nil;
|
||||
|
||||
FDragOperations := DRAG_OPERATION_NONE;
|
||||
FDragDropManager := nil;
|
||||
@ -773,6 +801,30 @@ end;
|
||||
|
||||
procedure TChromium.BeforeDestruction;
|
||||
begin
|
||||
if (FBrowserCompHWND <> 0) and (FOldBrowserCompWndPrc <> nil) then
|
||||
begin
|
||||
SetWindowLongPtr(FBrowserCompHWND, GWL_WNDPROC, NativeInt(FOldBrowserCompWndPrc));
|
||||
FreeObjectInstance(FBrowserCompStub);
|
||||
FOldBrowserCompWndPrc := nil;
|
||||
FBrowserCompStub := nil;
|
||||
end;
|
||||
|
||||
if (FWidgetCompHWND <> 0) and (FOldWidgetCompWndPrc <> nil) then
|
||||
begin
|
||||
SetWindowLongPtr(FWidgetCompHWND, GWL_WNDPROC, NativeInt(FOldWidgetCompWndPrc));
|
||||
FreeObjectInstance(FWidgetCompStub);
|
||||
FOldWidgetCompWndPrc := nil;
|
||||
FWidgetCompStub := nil;
|
||||
end;
|
||||
|
||||
if (FRenderCompHWND <> 0) and (FOldRenderCompWndPrc <> nil) then
|
||||
begin
|
||||
SetWindowLongPtr(FRenderCompHWND, GWL_WNDPROC, NativeInt(FOldRenderCompWndPrc));
|
||||
FreeObjectInstance(FRenderCompStub);
|
||||
FOldRenderCompWndPrc := nil;
|
||||
FRenderCompStub := nil;
|
||||
end;
|
||||
|
||||
DestroyClientHandler;
|
||||
|
||||
inherited BeforeDestruction;
|
||||
@ -961,6 +1013,9 @@ begin
|
||||
FOnPrefsAvailable := nil;
|
||||
FOnCookiesDeleted := nil;
|
||||
FOnResolvedHostAvailable := nil;
|
||||
FOnBrowserCompMsg := nil;
|
||||
FOnWidgetCompMsg := nil;
|
||||
FOnRenderCompMsg := nil;
|
||||
end;
|
||||
|
||||
function TChromium.CreateBrowser(const aBrowserParent : TWinControl;
|
||||
@ -986,7 +1041,7 @@ begin
|
||||
Result := CreateBrowser(TempHandle, TempRect, aWindowName, aContext, aCookiesPath, aPersistSessionCookies);
|
||||
end;
|
||||
|
||||
function TChromium.CreateBrowser(aParentHandle : HWND;
|
||||
function TChromium.CreateBrowser( aParentHandle : HWND;
|
||||
aParentRect : TRect;
|
||||
const aWindowName : string;
|
||||
const aContext : ICefRequestContext;
|
||||
@ -2779,6 +2834,63 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TChromium.BrowserCompWndProc(var aMessage: TMessage);
|
||||
var
|
||||
TempHandled : boolean;
|
||||
begin
|
||||
TempHandled := False;
|
||||
|
||||
if assigned(FOnBrowserCompMsg) then
|
||||
FOnBrowserCompMsg(aMessage, TempHandled);
|
||||
|
||||
if not(TempHandled) and
|
||||
(FOldBrowserCompWndPrc <> nil) and
|
||||
(FBrowserCompHWND <> 0) then
|
||||
aMessage.Result := CallWindowProc(FOldBrowserCompWndPrc,
|
||||
FBrowserCompHWND,
|
||||
aMessage.Msg,
|
||||
aMessage.wParam,
|
||||
aMessage.lParam);
|
||||
end;
|
||||
|
||||
procedure TChromium.WidgetCompWndProc(var aMessage: TMessage);
|
||||
var
|
||||
TempHandled : boolean;
|
||||
begin
|
||||
TempHandled := False;
|
||||
|
||||
if assigned(FOnWidgetCompMsg) then
|
||||
FOnWidgetCompMsg(aMessage, TempHandled);
|
||||
|
||||
if not(TempHandled) and
|
||||
(FOldWidgetCompWndPrc <> nil) and
|
||||
(FWidgetCompHWND <> 0) then
|
||||
aMessage.Result := CallWindowProc(FOldWidgetCompWndPrc,
|
||||
FWidgetCompHWND,
|
||||
aMessage.Msg,
|
||||
aMessage.wParam,
|
||||
aMessage.lParam);
|
||||
end;
|
||||
|
||||
procedure TChromium.RenderCompWndProc(var aMessage: TMessage);
|
||||
var
|
||||
TempHandled : boolean;
|
||||
begin
|
||||
TempHandled := False;
|
||||
|
||||
if assigned(FOnRenderCompMsg) then
|
||||
FOnRenderCompMsg(aMessage, TempHandled);
|
||||
|
||||
if not(TempHandled) and
|
||||
(FOldRenderCompWndPrc <> nil) and
|
||||
(FRenderCompHWND <> 0) then
|
||||
aMessage.Result := CallWindowProc(FOldRenderCompWndPrc,
|
||||
FRenderCompHWND,
|
||||
aMessage.Msg,
|
||||
aMessage.wParam,
|
||||
aMessage.lParam);
|
||||
end;
|
||||
|
||||
function TChromium.doOnClose(const browser: ICefBrowser): Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
@ -3276,6 +3388,42 @@ end;
|
||||
|
||||
procedure TChromium.doOnRenderViewReady(const browser: ICefBrowser);
|
||||
begin
|
||||
if (browser <> nil) and
|
||||
(browser.Host <> nil) then
|
||||
begin
|
||||
FBrowserCompHWND := browser.Host.WindowHandle;
|
||||
|
||||
if (FBrowserCompHWND <> 0) then
|
||||
FWidgetCompHWND := FindWindowEx(FBrowserCompHWND, 0, 'Chrome_WidgetWin_0', '');
|
||||
|
||||
if (FWidgetCompHWND <> 0) then
|
||||
FRenderCompHWND := FindWindowEx(FWidgetCompHWND, 0, 'Chrome_RenderWidgetHostHWND', 'Chrome Legacy Window');
|
||||
|
||||
if assigned(FOnBrowserCompMsg) and (FBrowserCompHWND <> 0) then
|
||||
begin
|
||||
FBrowserCompStub := MakeObjectInstance(BrowserCompWndProc);
|
||||
FOldBrowserCompWndPrc := Pointer(SetWindowLongPtr(FBrowserCompHWND,
|
||||
GWL_WNDPROC,
|
||||
NativeInt(FBrowserCompStub)));
|
||||
end;
|
||||
|
||||
if assigned(FOnWidgetCompMsg) and (FWidgetCompHWND <> 0) then
|
||||
begin
|
||||
FWidgetCompStub := MakeObjectInstance(WidgetCompWndProc);
|
||||
FOldWidgetCompWndPrc := Pointer(SetWindowLongPtr(FWidgetCompHWND,
|
||||
GWL_WNDPROC,
|
||||
NativeInt(FWidgetCompStub)));
|
||||
end;
|
||||
|
||||
if assigned(FOnRenderCompMsg) and (FRenderCompHWND <> 0) then
|
||||
begin
|
||||
FRenderCompStub := MakeObjectInstance(RenderCompWndProc);
|
||||
FOldRenderCompWndPrc := Pointer(SetWindowLongPtr(FRenderCompHWND,
|
||||
GWL_WNDPROC,
|
||||
NativeInt(FRenderCompStub)));
|
||||
end;
|
||||
end;
|
||||
|
||||
if Assigned(FOnRenderViewReady) then FOnRenderViewReady(Self, browser);
|
||||
end;
|
||||
|
||||
|
@ -48,9 +48,9 @@ interface
|
||||
|
||||
uses
|
||||
{$IFDEF DELPHI16_UP}
|
||||
System.Classes,
|
||||
System.Classes, {$IFDEF MSWINDOWS}WinApi.Messages,{$ENDIF}
|
||||
{$ELSE}
|
||||
Classes,
|
||||
Classes, {$IFDEF MSWINDOWS}Messages,{$ENDIF}
|
||||
{$ENDIF}
|
||||
uCEFTypes, uCEFInterfaces;
|
||||
|
||||
@ -156,6 +156,9 @@ type
|
||||
TOnPrefsAvailableEvent = procedure(Sender: TObject; aResultOK : boolean) of object;
|
||||
TOnCookiesDeletedEvent = procedure(Sender: TObject; numDeleted : integer) of object;
|
||||
TOnResolvedIPsAvailableEvent = procedure(Sender: TObject; result: TCefErrorCode; const resolvedIps: TStrings) of object;
|
||||
{$IFDEF MSWINDOWS}
|
||||
TOnCompMsgEvent = procedure (var aMessage: TMessage; var aHandled: Boolean) of object;
|
||||
{$ENDIF}
|
||||
|
||||
implementation
|
||||
|
||||
|
@ -127,7 +127,7 @@ begin
|
||||
if (FChromium <> nil) then
|
||||
Result := FChromium.WindowHandle
|
||||
else
|
||||
Result := 0;
|
||||
Result := inherited GetChildWindowHandle;
|
||||
end;
|
||||
|
||||
function TChromiumWindow.GetBrowserInitialized : boolean;
|
||||
|
@ -167,7 +167,7 @@ const
|
||||
UR_FLAG_NONE = 0;
|
||||
UR_FLAG_SKIP_CACHE = 1 shl 0;
|
||||
UR_FLAG_ONLY_FROM_CACHE = 1 shl 1;
|
||||
UR_FLAG_ALLOW_CACHED_CREDENTIALS = 1 shl 2;
|
||||
UR_FLAG_ALLOW_STORED_CREDENTIALS = 1 shl 2;
|
||||
UR_FLAG_REPORT_UPLOAD_PROGRESS = 1 shl 3;
|
||||
UR_FLAG_NO_DOWNLOAD_DATA = 1 shl 4;
|
||||
UR_FLAG_NO_RETRY_ON_5XX = 1 shl 5;
|
||||
|
@ -149,7 +149,7 @@ type
|
||||
TOnGetDataResourceEvent = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(resourceId: Integer; out data: Pointer; out dataSize: NativeUInt; var aResult : Boolean) {$IFNDEF DELPHI12_UP}of object{$ENDIF};
|
||||
TOnGetLocalizedStringEvent = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(stringId: Integer; out stringVal: ustring; var aResult : Boolean) {$IFNDEF DELPHI12_UP}of object{$ENDIF};
|
||||
TOnGetDataResourceForScaleEvent = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(resourceId: Integer; scaleFactor: TCefScaleFactor; out data: Pointer; out dataSize: NativeUInt; var aResult : Boolean) {$IFNDEF DELPHI12_UP}of object{$ENDIF};
|
||||
|
||||
TOnCDMRegistrationCompleteEvent = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(result : TCefCDMRegistrationError; const error_message : ustring) {$IFNDEF DELPHI12_UP}of object{$ENDIF};
|
||||
|
||||
|
||||
// *******************************************
|
||||
|
@ -109,6 +109,16 @@ function SystemTimeToTzSpecificLocalTime(lpTimeZoneInformation: PTimeZoneInforma
|
||||
|
||||
function PathIsRelativeAnsi(pszPath: LPCSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathIsRelativeA';
|
||||
function PathIsRelativeUnicode(pszPath: LPCWSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathIsRelativeW';
|
||||
|
||||
{$IFNDEF DELPHI12_UP}
|
||||
function SetWindowLongPtr(hWnd: HWND; nIndex: Integer; dwNewLong: Longint): Longint; stdcall;
|
||||
{$IFDEF WIN64}
|
||||
function SetWindowLongPtr; external user32 name 'SetWindowLongPtrW';
|
||||
{$ELSE}
|
||||
function SetWindowLongPtr; external user32 name 'SetWindowLongW';
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
function CustomPathIsRelative(const aPath : string) : boolean;
|
||||
function GetModulePath : string;
|
||||
|
||||
@ -190,9 +200,6 @@ procedure LogicalToDevice(var aRect : TCEFRect; const aDeviceScaleFactor : doubl
|
||||
function GetScreenDPI : integer;
|
||||
function GetDeviceScaleFactor : single;
|
||||
|
||||
procedure CefRegisterWidevineCdm(const path: ustring; const callback: ICefRegisterCdmCallback);
|
||||
procedure CefFastRegisterWidevineCdm(const path: ustring; const callback: TCefRegisterCDMProc);
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
@ -778,7 +785,6 @@ begin
|
||||
TempList.Add(TempDir + 'swiftshader\libEGL.dll');
|
||||
TempList.Add(TempDir + 'swiftshader\libGLESv2.dll');
|
||||
TempList.Add(TempDir + 'icudtl.dat');
|
||||
TempList.Add(TempDir + 'widevinecdmadapter.dll');
|
||||
|
||||
if TempExists then
|
||||
Result := CheckFilesExist(TempList, aMissingFiles)
|
||||
@ -1418,17 +1424,4 @@ begin
|
||||
Result := GetScreenDPI / 96;
|
||||
end;
|
||||
|
||||
procedure CefRegisterWidevineCdm(const path: ustring; const callback: ICefRegisterCdmCallback);
|
||||
var
|
||||
str: TCefString;
|
||||
begin
|
||||
str := CefString(path);
|
||||
cef_register_widevine_cdm(@str, CefGetData(callback));
|
||||
end;
|
||||
|
||||
procedure CefFastRegisterWidevineCdm(const path: ustring; const callback: TCefRegisterCDMProc);
|
||||
begin
|
||||
CefRegisterWidevineCdm(path, TCefFastRegisterCdmCallback.Create(callback) as ICefRegisterCdmCallback);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -47,7 +47,7 @@ unit uCEFRegisterCDMCallback;
|
||||
interface
|
||||
|
||||
uses
|
||||
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
||||
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFApplication;
|
||||
|
||||
type
|
||||
TCefRegisterCDMProc = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(result: TCefCDMRegistrationError; const error_message: ustring);
|
||||
@ -70,11 +70,33 @@ type
|
||||
constructor Create(const callback: TCefRegisterCDMProc); reintroduce;
|
||||
end;
|
||||
|
||||
TCefCustomRegisterCDMCallback = class(TCefRegisterCDMCallbackOwn)
|
||||
protected
|
||||
FCefApp : TCefApplication;
|
||||
|
||||
procedure OnCDMRegistrationComplete(result: TCefCDMRegistrationError; const error_message: ustring); override;
|
||||
|
||||
public
|
||||
constructor Create(const aCefApp : TCefApplication); reintroduce;
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
{$IFDEF DELPHI16_UP}
|
||||
System.SysUtils,
|
||||
{$ELSE}
|
||||
SysUtils,
|
||||
{$ENDIF}
|
||||
uCEFMiscFunctions, uCEFLibFunctions;
|
||||
|
||||
|
||||
// ************************************************
|
||||
// ********** TCefRegisterCDMCallbackOwn **********
|
||||
// ************************************************
|
||||
|
||||
|
||||
procedure cef_register_cdm_callback_on_cdm_registration_complete( self : PCefRegisterCDMCallback;
|
||||
result : TCefCDMRegistrationError;
|
||||
const error_message : PCefString); stdcall;
|
||||
@ -88,8 +110,6 @@ begin
|
||||
CefString(error_message));
|
||||
end;
|
||||
|
||||
// TCefRegisterCDMCallbackOwn
|
||||
|
||||
constructor TCefRegisterCDMCallbackOwn.Create;
|
||||
begin
|
||||
inherited CreateData(SizeOf(TCefRegisterCDMCallback));
|
||||
@ -103,7 +123,11 @@ begin
|
||||
//
|
||||
end;
|
||||
|
||||
// TCefFastRegisterCDMCallback
|
||||
|
||||
// ************************************************
|
||||
// ********** TCefFastRegisterCDMCallback *********
|
||||
// ************************************************
|
||||
|
||||
|
||||
constructor TCefFastRegisterCDMCallback.Create(const callback: TCefRegisterCDMProc);
|
||||
begin
|
||||
@ -117,4 +141,35 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
// ************************************************
|
||||
// ******** TCefCustomRegisterCDMCallback *********
|
||||
// ************************************************
|
||||
|
||||
|
||||
constructor TCefCustomRegisterCDMCallback.Create(const aCefApp : TCefApplication);
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
FCefApp := aCefApp;
|
||||
end;
|
||||
|
||||
destructor TCefCustomRegisterCDMCallback.Destroy;
|
||||
begin
|
||||
FCefApp := nil;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TCefCustomRegisterCDMCallback.OnCDMRegistrationComplete( result : TCefCDMRegistrationError;
|
||||
const error_message : ustring);
|
||||
begin
|
||||
try
|
||||
if (FCefApp <> nil) then FCefApp.Internal_OnCDMRegistrationComplete(result, error_message);
|
||||
except
|
||||
on e : exception do
|
||||
if CustomExceptionHandler('TCefCustomRegisterCDMCallback.OnCDMRegistrationComplete', e) then raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
@ -182,7 +182,7 @@ function TCEFWindowParent.DestroyChildWindow : boolean;
|
||||
var
|
||||
TempHWND : HWND;
|
||||
begin
|
||||
TempHWND := GetWindow(Handle, GW_CHILD);
|
||||
TempHWND := ChildWindowHandle;
|
||||
Result := (TempHWND <> 0) and DestroyWindow(TempHWND);
|
||||
end;
|
||||
|
||||
|
@ -48,6 +48,9 @@ interface
|
||||
|
||||
uses
|
||||
System.Classes, System.Types,
|
||||
{$IFDEF MSWINDOWS}
|
||||
WinApi.Windows, WinApi.Messages,
|
||||
{$ENDIF}
|
||||
FMX.Types, FMX.Platform, FMX.Controls, FMX.Forms,
|
||||
uCEFTypes, uCEFInterfaces, uCEFLibFunctions, uCEFMiscFunctions, uCEFClient,
|
||||
uCEFConstants, uCEFTask, uCEFChromiumEvents, uCEFChromiumOptions, uCEFChromiumFontOptions,
|
||||
@ -98,6 +101,17 @@ type
|
||||
FWebRTCIPHandlingPolicy : TCefWebRTCHandlingPolicy;
|
||||
FWebRTCMultipleRoutes : TCefState;
|
||||
FWebRTCNonProxiedUDP : TCefState;
|
||||
{$IFDEF MSWINDOWS}
|
||||
FOldBrowserCompWndPrc : Pointer;
|
||||
FOldWidgetCompWndPrc : Pointer;
|
||||
FOldRenderCompWndPrc : Pointer;
|
||||
FBrowserCompHWND : THandle;
|
||||
FWidgetCompHWND : THandle;
|
||||
FRenderCompHWND : THandle;
|
||||
FBrowserCompStub : Pointer;
|
||||
FWidgetCompStub : Pointer;
|
||||
FRenderCompStub : Pointer;
|
||||
{$ENDIF}
|
||||
|
||||
// ICefClient
|
||||
FOnProcessMessageReceived : TOnProcessMessageReceived;
|
||||
@ -197,6 +211,11 @@ type
|
||||
FOnPdfPrintFinished : TOnPdfPrintFinishedEvent;
|
||||
FOnCookiesDeleted : TOnCookiesDeletedEvent;
|
||||
FOnResolvedHostAvailable : TOnResolvedIPsAvailableEvent;
|
||||
{$IFDEF MSWINDOWS}
|
||||
FOnBrowserCompMsg : TOnCompMsgEvent;
|
||||
FOnWidgetCompMsg : TOnCompMsgEvent;
|
||||
FOnRenderCompMsg : TOnCompMsgEvent;
|
||||
{$ENDIF}
|
||||
|
||||
function GetIsLoading : boolean;
|
||||
function GetMultithreadApp : boolean;
|
||||
@ -290,6 +309,12 @@ type
|
||||
procedure ApplyZoomStep;
|
||||
function GetParentForm : TCustomForm;
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
procedure BrowserCompWndProc(var aMessage: TMessage);
|
||||
procedure WidgetCompWndProc(var aMessage: TMessage);
|
||||
procedure RenderCompWndProc(var aMessage: TMessage);
|
||||
{$ENDIF}
|
||||
|
||||
// IChromiumEvents
|
||||
procedure GetSettings(var aSettings : TCefBrowserSettings);
|
||||
|
||||
@ -547,6 +572,11 @@ type
|
||||
property OnPdfPrintFinished : TOnPdfPrintFinishedEvent read FOnPdfPrintFinished write FOnPdfPrintFinished;
|
||||
property OnCookiesDeleted : TOnCookiesDeletedEvent read FOnCookiesDeleted write FOnCookiesDeleted;
|
||||
property OnResolvedHostAvailable : TOnResolvedIPsAvailableEvent read FOnResolvedHostAvailable write FOnResolvedHostAvailable;
|
||||
{$IFDEF MSWINDOWS}
|
||||
property OnBrowserCompMsg : TOnCompMsgEvent read FOnBrowserCompMsg write FOnBrowserCompMsg;
|
||||
property OnWidgetCompMsg : TOnCompMsgEvent read FOnWidgetCompMsg write FOnWidgetCompMsg;
|
||||
property OnRenderCompMsg : TOnCompMsgEvent read FOnRenderCompMsg write FOnRenderCompMsg;
|
||||
{$ENDIF}
|
||||
|
||||
// ICefClient
|
||||
property OnProcessMessageReceived : TOnProcessMessageReceived read FOnProcessMessageReceived write FOnProcessMessageReceived;
|
||||
@ -679,6 +709,18 @@ begin
|
||||
FZoomStep := ZOOM_STEP_DEF;
|
||||
FWindowName := '';
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
FOldBrowserCompWndPrc := nil;
|
||||
FOldWidgetCompWndPrc := nil;
|
||||
FOldRenderCompWndPrc := nil;
|
||||
FBrowserCompHWND := 0;
|
||||
FWidgetCompHWND := 0;
|
||||
FRenderCompHWND := 0;
|
||||
FBrowserCompStub := nil;
|
||||
FWidgetCompStub := nil;
|
||||
FRenderCompStub := nil;
|
||||
{$ENDIF}
|
||||
|
||||
FDragOperations := DRAG_OPERATION_NONE;
|
||||
FDragAndDropInitialized := False;
|
||||
|
||||
@ -726,6 +768,32 @@ end;
|
||||
|
||||
procedure TFMXChromium.BeforeDestruction;
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
if (FBrowserCompHWND <> 0) and (FOldBrowserCompWndPrc <> nil) then
|
||||
begin
|
||||
SetWindowLongPtr(FBrowserCompHWND, GWL_WNDPROC, NativeInt(FOldBrowserCompWndPrc));
|
||||
FreeObjectInstance(FBrowserCompStub);
|
||||
FOldBrowserCompWndPrc := nil;
|
||||
FBrowserCompStub := nil;
|
||||
end;
|
||||
|
||||
if (FWidgetCompHWND <> 0) and (FOldWidgetCompWndPrc <> nil) then
|
||||
begin
|
||||
SetWindowLongPtr(FWidgetCompHWND, GWL_WNDPROC, NativeInt(FOldWidgetCompWndPrc));
|
||||
FreeObjectInstance(FWidgetCompStub);
|
||||
FOldWidgetCompWndPrc := nil;
|
||||
FWidgetCompStub := nil;
|
||||
end;
|
||||
|
||||
if (FRenderCompHWND <> 0) and (FOldRenderCompWndPrc <> nil) then
|
||||
begin
|
||||
SetWindowLongPtr(FRenderCompHWND, GWL_WNDPROC, NativeInt(FOldRenderCompWndPrc));
|
||||
FreeObjectInstance(FRenderCompStub);
|
||||
FOldRenderCompWndPrc := nil;
|
||||
FRenderCompStub := nil;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
DestroyClientHandler;
|
||||
|
||||
inherited BeforeDestruction;
|
||||
@ -2978,6 +3046,44 @@ end;
|
||||
|
||||
procedure TFMXChromium.doOnRenderViewReady(const browser: ICefBrowser);
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
if (browser <> nil) and
|
||||
(browser.Host <> nil) then
|
||||
begin
|
||||
FBrowserCompHWND := browser.Host.WindowHandle;
|
||||
|
||||
if (FBrowserCompHWND <> 0) then
|
||||
FWidgetCompHWND := FindWindowEx(FBrowserCompHWND, 0, 'Chrome_WidgetWin_0', '');
|
||||
|
||||
if (FWidgetCompHWND <> 0) then
|
||||
FRenderCompHWND := FindWindowEx(FWidgetCompHWND, 0, 'Chrome_RenderWidgetHostHWND', 'Chrome Legacy Window');
|
||||
|
||||
if assigned(FOnBrowserCompMsg) and (FBrowserCompHWND <> 0) then
|
||||
begin
|
||||
FBrowserCompStub := MakeObjectInstance(BrowserCompWndProc);
|
||||
FOldBrowserCompWndPrc := Pointer(SetWindowLongPtr(FBrowserCompHWND,
|
||||
GWL_WNDPROC,
|
||||
NativeInt(FBrowserCompStub)));
|
||||
end;
|
||||
|
||||
if assigned(FOnWidgetCompMsg) and (FWidgetCompHWND <> 0) then
|
||||
begin
|
||||
FWidgetCompStub := MakeObjectInstance(WidgetCompWndProc);
|
||||
FOldWidgetCompWndPrc := Pointer(SetWindowLongPtr(FWidgetCompHWND,
|
||||
GWL_WNDPROC,
|
||||
NativeInt(FWidgetCompStub)));
|
||||
end;
|
||||
|
||||
if assigned(FOnRenderCompMsg) and (FRenderCompHWND <> 0) then
|
||||
begin
|
||||
FRenderCompStub := MakeObjectInstance(RenderCompWndProc);
|
||||
FOldRenderCompWndPrc := Pointer(SetWindowLongPtr(FRenderCompHWND,
|
||||
GWL_WNDPROC,
|
||||
NativeInt(FRenderCompStub)));
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
if Assigned(FOnRenderViewReady) then FOnRenderViewReady(Self, browser);
|
||||
end;
|
||||
|
||||
@ -3100,6 +3206,65 @@ begin
|
||||
TempComp := TempComp.owner;
|
||||
end;
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
procedure TFMXChromium.BrowserCompWndProc(var aMessage: TMessage);
|
||||
var
|
||||
TempHandled : boolean;
|
||||
begin
|
||||
TempHandled := False;
|
||||
|
||||
if assigned(FOnBrowserCompMsg) then
|
||||
FOnBrowserCompMsg(aMessage, TempHandled);
|
||||
|
||||
if not(TempHandled) and
|
||||
(FOldBrowserCompWndPrc <> nil) and
|
||||
(FBrowserCompHWND <> 0) then
|
||||
aMessage.Result := CallWindowProc(FOldBrowserCompWndPrc,
|
||||
FBrowserCompHWND,
|
||||
aMessage.Msg,
|
||||
aMessage.wParam,
|
||||
aMessage.lParam);
|
||||
end;
|
||||
|
||||
procedure TFMXChromium.WidgetCompWndProc(var aMessage: TMessage);
|
||||
var
|
||||
TempHandled : boolean;
|
||||
begin
|
||||
TempHandled := False;
|
||||
|
||||
if assigned(FOnWidgetCompMsg) then
|
||||
FOnWidgetCompMsg(aMessage, TempHandled);
|
||||
|
||||
if not(TempHandled) and
|
||||
(FOldWidgetCompWndPrc <> nil) and
|
||||
(FWidgetCompHWND <> 0) then
|
||||
aMessage.Result := CallWindowProc(FOldWidgetCompWndPrc,
|
||||
FWidgetCompHWND,
|
||||
aMessage.Msg,
|
||||
aMessage.wParam,
|
||||
aMessage.lParam);
|
||||
end;
|
||||
|
||||
procedure TFMXChromium.RenderCompWndProc(var aMessage: TMessage);
|
||||
var
|
||||
TempHandled : boolean;
|
||||
begin
|
||||
TempHandled := False;
|
||||
|
||||
if assigned(FOnRenderCompMsg) then
|
||||
FOnRenderCompMsg(aMessage, TempHandled);
|
||||
|
||||
if not(TempHandled) and
|
||||
(FOldRenderCompWndPrc <> nil) and
|
||||
(FRenderCompHWND <> 0) then
|
||||
aMessage.Result := CallWindowProc(FOldRenderCompWndPrc,
|
||||
FRenderCompHWND,
|
||||
aMessage.Msg,
|
||||
aMessage.wParam,
|
||||
aMessage.lParam);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TFMXChromium.MoveFormTo(const x, y: Integer);
|
||||
var
|
||||
TempForm : TCustomForm;
|
||||
|
Loading…
x
Reference in New Issue
Block a user