2017-01-27 17:37:51 +02:00
|
|
|
unit uCEFLifeSpanHandler;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2022-02-19 19:56:41 +02:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
2018-11-22 16:02:21 +02:00
|
|
|
{$MINENUMSIZE 4}
|
2017-01-27 17:37:51 +02:00
|
|
|
|
2017-02-05 21:56:46 +02:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-03-16 20:09:42 +02:00
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
|
|
|
type
|
2017-03-16 20:09:42 +02:00
|
|
|
TCefLifeSpanHandlerOwn = class(TCefBaseRefCountedOwn, ICefLifeSpanHandler)
|
2017-01-27 17:37:51 +02:00
|
|
|
protected
|
2019-06-16 10:31:13 +02:00
|
|
|
function OnBeforePopup(const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean): Boolean; virtual;
|
2023-11-16 17:58:47 +02:00
|
|
|
procedure OnBeforeDevToolsPopup(const browser: ICefBrowser; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var use_default_window: boolean); virtual;
|
2017-01-27 17:37:51 +02:00
|
|
|
procedure OnAfterCreated(const browser: ICefBrowser); virtual;
|
|
|
|
function DoClose(const browser: ICefBrowser): Boolean; virtual;
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure OnBeforeClose(const browser: ICefBrowser); virtual;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
2018-02-03 18:52:48 +02:00
|
|
|
procedure RemoveReferences; virtual;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
public
|
|
|
|
constructor Create; virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TCustomLifeSpanHandler = class(TCefLifeSpanHandlerOwn)
|
|
|
|
protected
|
2018-02-03 18:52:48 +02:00
|
|
|
FEvents : Pointer;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
2019-06-16 10:31:13 +02:00
|
|
|
function OnBeforePopup(const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean): Boolean; override;
|
2023-11-16 17:58:47 +02:00
|
|
|
procedure OnBeforeDevToolsPopup(const browser: ICefBrowser; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var use_default_window: boolean); override;
|
2017-01-27 17:37:51 +02:00
|
|
|
procedure OnAfterCreated(const browser: ICefBrowser); override;
|
|
|
|
function DoClose(const browser: ICefBrowser): Boolean; override;
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure OnBeforeClose(const browser: ICefBrowser); override;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
2018-02-03 18:52:48 +02:00
|
|
|
procedure RemoveReferences; override;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
public
|
2019-06-19 16:53:26 +02:00
|
|
|
constructor Create(const events : IChromiumEvents); reintroduce; virtual;
|
2017-06-11 17:48:20 +02:00
|
|
|
destructor Destroy; override;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2018-02-03 18:52:48 +02:00
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
System.SysUtils,
|
|
|
|
{$ELSE}
|
|
|
|
SysUtils,
|
|
|
|
{$ENDIF}
|
2019-06-16 10:31:13 +02:00
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFClient, uCEFBrowser, uCEFFrame, uCEFDictionaryValue;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
2017-06-11 17:48:20 +02:00
|
|
|
function cef_life_span_handler_on_before_popup( self : PCefLifeSpanHandler;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
frame : PCefFrame;
|
|
|
|
const target_url : PCefString;
|
|
|
|
const target_frame_name : PCefString;
|
|
|
|
target_disposition : TCefWindowOpenDisposition;
|
|
|
|
user_gesture : Integer;
|
|
|
|
const popupFeatures : PCefPopupFeatures;
|
|
|
|
windowInfo : PCefWindowInfo;
|
|
|
|
var client : PCefClient;
|
|
|
|
settings : PCefBrowserSettings;
|
2019-06-16 10:31:13 +02:00
|
|
|
var extra_info : PCefDictionaryValue;
|
2017-06-11 17:48:20 +02:00
|
|
|
no_javascript_access : PInteger): Integer; stdcall;
|
2017-01-27 17:37:51 +02:00
|
|
|
var
|
2019-06-16 10:31:13 +02:00
|
|
|
TempClient : ICefClient;
|
|
|
|
TempExtraInfo : ICefDictionaryValue;
|
|
|
|
TempNoJS : boolean;
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
try
|
|
|
|
Result := Ord(False);
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefLifeSpanHandlerOwn) then
|
|
|
|
begin
|
2019-06-16 10:31:13 +02:00
|
|
|
TempNoJS := (no_javascript_access^ <> 0);
|
|
|
|
TempClient := TCefClientRef.UnWrap(client);
|
|
|
|
TempExtraInfo := TCefDictionaryValueRef.UnWrap(extra_info);
|
|
|
|
|
|
|
|
Result := Ord(TCefLifeSpanHandlerOwn(TempObject).OnBeforePopup(TCefBrowserRef.UnWrap(browser),
|
|
|
|
TCefFrameRef.UnWrap(frame),
|
|
|
|
CefString(target_url),
|
|
|
|
CefString(target_frame_name),
|
|
|
|
target_disposition,
|
|
|
|
user_gesture <> 0,
|
|
|
|
popupFeatures^,
|
|
|
|
windowInfo^,
|
|
|
|
TempClient,
|
|
|
|
settings^,
|
|
|
|
TempExtraInfo,
|
|
|
|
TempNoJS));
|
2018-03-29 20:02:04 +02:00
|
|
|
|
|
|
|
no_javascript_access^ := Ord(TempNoJS);
|
|
|
|
|
|
|
|
if (TempClient = nil) then
|
|
|
|
client := nil
|
|
|
|
else
|
|
|
|
if not(TempClient.SameAs(client)) then
|
|
|
|
client := TempClient.Wrap;
|
2019-06-16 10:31:13 +02:00
|
|
|
|
|
|
|
if (TempExtraInfo = nil) then
|
|
|
|
extra_info := nil
|
|
|
|
else
|
|
|
|
if not(TempExtraInfo.SameAs(extra_info)) then
|
|
|
|
extra_info := TempExtraInfo.Wrap;
|
2018-03-29 20:02:04 +02:00
|
|
|
end;
|
|
|
|
finally
|
2019-06-16 10:31:13 +02:00
|
|
|
TempClient := nil;
|
|
|
|
TempExtraInfo := nil;
|
2018-03-29 20:02:04 +02:00
|
|
|
end;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2023-11-16 17:58:47 +02:00
|
|
|
procedure cef_life_span_handler_on_before_dev_tools_popup( self : PCefLifeSpanHandler;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
windowInfo : PCefWindowInfo;
|
|
|
|
var client : PCefClient;
|
|
|
|
settings : PCefBrowserSettings;
|
|
|
|
var extra_info : PCefDictionaryValue;
|
|
|
|
use_default_window : PInteger); stdcall;
|
|
|
|
var
|
|
|
|
TempClient : ICefClient;
|
|
|
|
TempExtraInfo : ICefDictionaryValue;
|
|
|
|
TempUseDefWindow : boolean;
|
|
|
|
TempObject : TObject;
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefLifeSpanHandlerOwn) then
|
|
|
|
begin
|
|
|
|
TempUseDefWindow := (use_default_window^ <> 0);
|
|
|
|
TempClient := TCefClientRef.UnWrap(client);
|
|
|
|
TempExtraInfo := TCefDictionaryValueRef.UnWrap(extra_info);
|
|
|
|
|
|
|
|
TCefLifeSpanHandlerOwn(TempObject).OnBeforeDevToolsPopup(TCefBrowserRef.UnWrap(browser),
|
|
|
|
windowInfo^,
|
|
|
|
TempClient,
|
|
|
|
settings^,
|
|
|
|
TempExtraInfo,
|
|
|
|
TempUseDefWindow);
|
|
|
|
|
|
|
|
use_default_window^ := Ord(TempUseDefWindow);
|
|
|
|
|
|
|
|
if (TempClient = nil) then
|
|
|
|
client := nil
|
|
|
|
else
|
|
|
|
if not(TempClient.SameAs(client)) then
|
|
|
|
client := TempClient.Wrap;
|
|
|
|
|
|
|
|
if (TempExtraInfo = nil) then
|
|
|
|
extra_info := nil
|
|
|
|
else
|
|
|
|
if not(TempExtraInfo.SameAs(extra_info)) then
|
|
|
|
extra_info := TempExtraInfo.Wrap;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
TempClient := nil;
|
|
|
|
TempExtraInfo := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_life_span_handler_on_after_created(self : PCefLifeSpanHandler;
|
|
|
|
browser : PCefBrowser); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefLifeSpanHandlerOwn) then
|
|
|
|
TCefLifeSpanHandlerOwn(TempObject).OnAfterCreated(TCefBrowserRef.UnWrap(browser));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_life_span_handler_on_before_close(self : PCefLifeSpanHandler;
|
|
|
|
browser : PCefBrowser); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefLifeSpanHandlerOwn) then
|
|
|
|
TCefLifeSpanHandlerOwn(TempObject).OnBeforeClose(TCefBrowserRef.UnWrap(browser));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_life_span_handler_do_close(self : PCefLifeSpanHandler;
|
|
|
|
browser : PCefBrowser): Integer; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(False);
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefLifeSpanHandlerOwn) then
|
|
|
|
Result := Ord(TCefLifeSpanHandlerOwn(TempObject).DoClose(TCefBrowserRef.UnWrap(browser)));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TCefLifeSpanHandlerOwn.Create;
|
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefLifeSpanHandler));
|
2017-06-11 17:48:20 +02:00
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
with PCefLifeSpanHandler(FData)^ do
|
2017-06-11 17:48:20 +02:00
|
|
|
begin
|
2023-11-16 17:58:47 +02:00
|
|
|
on_before_popup := {$IFDEF FPC}@{$ENDIF}cef_life_span_handler_on_before_popup;
|
|
|
|
on_before_dev_tools_popup := {$IFDEF FPC}@{$ENDIF}cef_life_span_handler_on_before_dev_tools_popup;
|
|
|
|
on_after_created := {$IFDEF FPC}@{$ENDIF}cef_life_span_handler_on_after_created;
|
|
|
|
do_close := {$IFDEF FPC}@{$ENDIF}cef_life_span_handler_do_close;
|
|
|
|
on_before_close := {$IFDEF FPC}@{$ENDIF}cef_life_span_handler_on_before_close;
|
2017-06-11 17:48:20 +02:00
|
|
|
end;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefLifeSpanHandlerOwn.OnAfterCreated(const browser: ICefBrowser);
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
//
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefLifeSpanHandlerOwn.OnBeforeClose(const browser: ICefBrowser);
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
//
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-02-24 10:38:25 +02:00
|
|
|
function TCefLifeSpanHandlerOwn.OnBeforePopup(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
const targetUrl : ustring;
|
|
|
|
const targetFrameName : ustring;
|
|
|
|
targetDisposition : TCefWindowOpenDisposition;
|
|
|
|
userGesture : Boolean;
|
2018-03-29 20:02:04 +02:00
|
|
|
const popupFeatures : TCefPopupFeatures;
|
2018-02-24 10:38:25 +02:00
|
|
|
var windowInfo : TCefWindowInfo;
|
|
|
|
var client : ICefClient;
|
|
|
|
var settings : TCefBrowserSettings;
|
2019-06-16 10:31:13 +02:00
|
|
|
var extra_info : ICefDictionaryValue;
|
2018-02-24 10:38:25 +02:00
|
|
|
var noJavascriptAccess : Boolean): Boolean;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
2023-11-16 17:58:47 +02:00
|
|
|
procedure TCefLifeSpanHandlerOwn.OnBeforeDevToolsPopup(const browser : ICefBrowser;
|
|
|
|
var windowInfo : TCefWindowInfo;
|
|
|
|
var client : ICefClient;
|
|
|
|
var settings : TCefBrowserSettings;
|
|
|
|
var extra_info : ICefDictionaryValue;
|
|
|
|
var use_default_window : boolean);
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
function TCefLifeSpanHandlerOwn.DoClose(const browser: ICefBrowser): Boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
2018-02-03 18:52:48 +02:00
|
|
|
procedure TCefLifeSpanHandlerOwn.RemoveReferences;
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
// TCustomLifeSpanHandler
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
constructor TCustomLifeSpanHandler.Create(const events : IChromiumEvents);
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
|
|
|
inherited Create;
|
2017-06-11 17:48:20 +02:00
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
FEvents := Pointer(events);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2017-06-11 17:48:20 +02:00
|
|
|
destructor TCustomLifeSpanHandler.Destroy;
|
|
|
|
begin
|
2018-02-03 18:52:48 +02:00
|
|
|
RemoveReferences;
|
2017-06-11 17:48:20 +02:00
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2018-02-03 18:52:48 +02:00
|
|
|
procedure TCustomLifeSpanHandler.RemoveReferences;
|
|
|
|
begin
|
|
|
|
FEvents := nil;
|
|
|
|
end;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
function TCustomLifeSpanHandler.DoClose(const browser: ICefBrowser): Boolean;
|
|
|
|
begin
|
2018-02-03 18:52:48 +02:00
|
|
|
if (FEvents <> nil) then
|
|
|
|
Result := IChromiumEvents(FEvents).doOnClose(browser)
|
2017-06-11 17:48:20 +02:00
|
|
|
else
|
2017-06-11 20:36:14 +02:00
|
|
|
Result := inherited DoClose(browser);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomLifeSpanHandler.OnAfterCreated(const browser: ICefBrowser);
|
|
|
|
begin
|
2018-02-03 18:52:48 +02:00
|
|
|
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnAfterCreated(browser);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomLifeSpanHandler.OnBeforeClose(const browser: ICefBrowser);
|
|
|
|
begin
|
2018-02-03 18:52:48 +02:00
|
|
|
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnBeforeClose(browser);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2017-06-11 20:36:14 +02:00
|
|
|
function TCustomLifeSpanHandler.OnBeforePopup(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
const targetUrl : ustring;
|
|
|
|
const targetFrameName : ustring;
|
|
|
|
targetDisposition : TCefWindowOpenDisposition;
|
|
|
|
userGesture : Boolean;
|
2018-03-29 20:02:04 +02:00
|
|
|
const popupFeatures : TCefPopupFeatures;
|
2017-06-11 20:36:14 +02:00
|
|
|
var windowInfo : TCefWindowInfo;
|
|
|
|
var client : ICefClient;
|
|
|
|
var settings : TCefBrowserSettings;
|
2019-06-16 10:31:13 +02:00
|
|
|
var extra_info : ICefDictionaryValue;
|
2017-06-11 20:36:14 +02:00
|
|
|
var noJavascriptAccess : Boolean): Boolean;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-02-03 18:52:48 +02:00
|
|
|
if (FEvents <> nil) then
|
|
|
|
Result := IChromiumEvents(FEvents).doOnBeforePopup(browser, frame, targetUrl, targetFrameName,
|
|
|
|
targetDisposition, userGesture, popupFeatures,
|
2019-06-16 10:31:13 +02:00
|
|
|
windowInfo, client, settings, extra_info, noJavascriptAccess)
|
2017-06-11 17:48:20 +02:00
|
|
|
else
|
2017-06-11 20:36:14 +02:00
|
|
|
Result := inherited OnBeforePopup(browser, frame, targetUrl, targetFrameName,
|
|
|
|
targetDisposition, userGesture, popupFeatures,
|
2019-06-16 10:31:13 +02:00
|
|
|
windowInfo, client, settings, extra_info, noJavascriptAccess);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2023-11-16 17:58:47 +02:00
|
|
|
procedure TCustomLifeSpanHandler.OnBeforeDevToolsPopup(const browser : ICefBrowser;
|
|
|
|
var windowInfo : TCefWindowInfo;
|
|
|
|
var client : ICefClient;
|
|
|
|
var settings : TCefBrowserSettings;
|
|
|
|
var extra_info : ICefDictionaryValue;
|
|
|
|
var use_default_window : boolean);
|
|
|
|
begin
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
IChromiumEvents(FEvents).doOnBeforeDevToolsPopup(browser, windowInfo, client, settings, extra_info, use_default_window)
|
|
|
|
else
|
|
|
|
inherited OnBeforeDevToolsPopup(browser, windowInfo, client, settings, extra_info, use_default_window);
|
|
|
|
end;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
end.
|