2017-01-27 16:37:51 +01:00
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
//
|
2019-10-19 10:58:34 +02:00
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
|
2017-01-27 16:37:51 +01:00
|
|
|
|
// browser in Delphi applications.
|
|
|
|
|
//
|
|
|
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
|
|
|
//
|
|
|
|
|
// For more information about CEF4Delphi visit :
|
|
|
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
|
|
|
//
|
2020-01-01 12:48:10 +01:00
|
|
|
|
// Copyright <20> 2020 Salvador Diaz Fau. All rights reserved.
|
2017-01-27 16:37:51 +01:00
|
|
|
|
//
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
(*
|
|
|
|
|
* Delphi Chromium Embedded 3
|
|
|
|
|
*
|
|
|
|
|
* Usage allowed under the restrictions of the Lesser GNU General Public License
|
|
|
|
|
* or alternatively the restrictions of the Mozilla Public License 1.1
|
|
|
|
|
*
|
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
|
|
|
* the specific language governing rights and limitations under the License.
|
|
|
|
|
*
|
|
|
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
|
|
|
* Web site : http://www.progdigy.com
|
|
|
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
|
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
|
|
|
*
|
|
|
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
|
|
|
* this source code without explicit permission.
|
|
|
|
|
*
|
|
|
|
|
*)
|
|
|
|
|
|
|
|
|
|
unit uCEFRequestHandler;
|
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
|
{$IFDEF FPC}
|
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
2018-11-22 15:02:21 +01:00
|
|
|
|
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
|
|
|
|
|
{$MINENUMSIZE 4}
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2017-03-16 19:09:42 +01:00
|
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
|
|
type
|
2017-03-16 19:09:42 +01:00
|
|
|
|
TCefRequestHandlerOwn = class(TCefBaseRefCountedOwn, ICefRequestHandler)
|
2017-01-27 16:37:51 +01:00
|
|
|
|
protected
|
2018-04-30 14:44:09 +02:00
|
|
|
|
function OnBeforeBrowse(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; user_gesture, isRedirect: Boolean): Boolean; virtual;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
function OnOpenUrlFromTab(const browser: ICefBrowser; const frame: ICefFrame; const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean): Boolean; virtual;
|
2019-06-16 10:31:13 +02:00
|
|
|
|
procedure GetResourceRequestHandler(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; is_navigation, is_download: boolean; const request_initiator: ustring; var disable_default_handling: boolean; var aResourceRequestHandler : ICefResourceRequestHandler); virtual;
|
2019-07-18 11:48:11 +02:00
|
|
|
|
function GetAuthCredentials(const browser: ICefBrowser; const originUrl: ustring; isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring; const callback: ICefAuthCallback): Boolean; virtual;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
function OnQuotaRequest(const browser: ICefBrowser; const originUrl: ustring; newSize: Int64; const callback: ICefRequestCallback): Boolean; virtual;
|
|
|
|
|
function OnCertificateError(const browser: ICefBrowser; certError: TCefErrorcode; const requestUrl: ustring; const sslInfo: ICefSslInfo; const callback: ICefRequestCallback): Boolean; virtual;
|
|
|
|
|
function OnSelectClientCertificate(const browser: ICefBrowser; isProxy: boolean; const host: ustring; port: integer; certificatesCount: NativeUInt; const certificates: TCefX509CertificateArray; const callback: ICefSelectClientCertificateCallback): boolean; virtual;
|
|
|
|
|
procedure OnPluginCrashed(const browser: ICefBrowser; const pluginPath: ustring); virtual;
|
|
|
|
|
procedure OnRenderViewReady(const browser: ICefBrowser); virtual;
|
|
|
|
|
procedure OnRenderProcessTerminated(const browser: ICefBrowser; status: TCefTerminationStatus); virtual;
|
2020-06-21 21:27:55 +02:00
|
|
|
|
procedure OnDocumentAvailableInMainFrame(const browser: ICefBrowser); virtual;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
2018-02-03 17:52:48 +01:00
|
|
|
|
procedure RemoveReferences; virtual;
|
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
|
public
|
|
|
|
|
constructor Create; virtual;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TCustomRequestHandler = class(TCefRequestHandlerOwn)
|
|
|
|
|
protected
|
2019-11-08 14:32:03 +01:00
|
|
|
|
FEvents : Pointer;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
2018-04-30 14:44:09 +02:00
|
|
|
|
function OnBeforeBrowse(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; user_gesture, isRedirect: Boolean): Boolean; override;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
function OnOpenUrlFromTab(const browser: ICefBrowser; const frame: ICefFrame; const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean): Boolean; override;
|
2019-06-16 10:31:13 +02:00
|
|
|
|
procedure GetResourceRequestHandler(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; is_navigation, is_download: boolean; const request_initiator: ustring; var disable_default_handling: boolean; var aResourceRequestHandler : ICefResourceRequestHandler); override;
|
2019-07-18 11:48:11 +02:00
|
|
|
|
function GetAuthCredentials(const browser: ICefBrowser; const originUrl: ustring; isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring; const callback: ICefAuthCallback): Boolean; override;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
function OnQuotaRequest(const browser: ICefBrowser; const originUrl: ustring; newSize: Int64; const callback: ICefRequestCallback): Boolean; override;
|
|
|
|
|
function OnCertificateError(const browser: ICefBrowser; certError: TCefErrorcode; const requestUrl: ustring; const sslInfo: ICefSslInfo; const callback: ICefRequestCallback): Boolean; override;
|
|
|
|
|
function OnSelectClientCertificate(const browser: ICefBrowser; isProxy: boolean; const host: ustring; port: integer; certificatesCount: NativeUInt; const certificates: TCefX509CertificateArray; const callback: ICefSelectClientCertificateCallback): boolean; override;
|
|
|
|
|
procedure OnPluginCrashed(const browser: ICefBrowser; const pluginPath: ustring); override;
|
|
|
|
|
procedure OnRenderViewReady(const browser: ICefBrowser); override;
|
|
|
|
|
procedure OnRenderProcessTerminated(const browser: ICefBrowser; status: TCefTerminationStatus); override;
|
2020-06-21 21:27:55 +02:00
|
|
|
|
procedure OnDocumentAvailableInMainFrame(const browser: ICefBrowser); override;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
|
|
public
|
2019-06-19 16:53:26 +02:00
|
|
|
|
constructor Create(const events : IChromiumEvents); reintroduce; virtual;
|
2019-06-16 10:31:13 +02:00
|
|
|
|
procedure BeforeDestruction; override;
|
|
|
|
|
procedure RemoveReferences; override;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$IFDEF DELPHI16_UP}
|
2018-06-03 17:18:54 +02:00
|
|
|
|
{$IFDEF MSWINDOWS}WinApi.Windows,{$ENDIF} System.SysUtils,
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$ELSE}
|
2018-06-03 17:18:54 +02:00
|
|
|
|
{$IFDEF MSWINDOWS}Windows,{$ENDIF} SysUtils,
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$ENDIF}
|
2017-01-27 16:37:51 +01:00
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFFrame, uCEFRequest, uCEFRequestCallback,
|
2017-02-12 19:53:06 +01:00
|
|
|
|
uCEFResponse, uCEFAuthCallback, uCEFSslInfo, uCEFSelectClientCertificateCallback, uCEFX509Certificate,
|
2019-11-08 23:15:53 +01:00
|
|
|
|
uCEFApplicationCore;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
2018-04-30 14:44:09 +02:00
|
|
|
|
function cef_request_handler_on_before_browse(self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser;
|
|
|
|
|
frame : PCefFrame;
|
|
|
|
|
request : PCefRequest;
|
|
|
|
|
user_gesture : Integer;
|
|
|
|
|
isRedirect : Integer): Integer; stdcall;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
Result := Ord(False);
|
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
|
|
|
|
Result := Ord(TCefRequestHandlerOwn(TempObject).OnBeforeBrowse(TCefBrowserRef.UnWrap(browser),
|
|
|
|
|
TCefFrameRef.UnWrap(frame),
|
|
|
|
|
TCefRequestRef.UnWrap(request),
|
2018-04-30 14:44:09 +02:00
|
|
|
|
user_gesture <> 0,
|
2018-03-29 20:02:04 +02:00
|
|
|
|
isRedirect <> 0));
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
function cef_request_handler_on_open_urlfrom_tab( self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser;
|
|
|
|
|
frame : PCefFrame;
|
|
|
|
|
const target_url : PCefString;
|
|
|
|
|
target_disposition : TCefWindowOpenDisposition;
|
|
|
|
|
user_gesture : Integer): Integer; stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
Result := Ord(False);
|
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
|
|
|
|
Result := Ord(TCefRequestHandlerOwn(TempObject).OnOpenUrlFromTab(TCefBrowserRef.UnWrap(browser),
|
|
|
|
|
TCefFrameRef.UnWrap(frame),
|
|
|
|
|
CefString(target_url),
|
|
|
|
|
target_disposition,
|
|
|
|
|
user_gesture <> 0));
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2019-06-16 10:31:13 +02:00
|
|
|
|
function cef_request_handler_get_resource_request_handler( self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser;
|
|
|
|
|
frame : PCefFrame;
|
|
|
|
|
request : PCefRequest;
|
|
|
|
|
is_navigation : Integer;
|
|
|
|
|
is_download : Integer;
|
|
|
|
|
const request_initiator : PCefString;
|
|
|
|
|
disable_default_handling : PInteger): PCefResourceRequestHandler; stdcall;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2019-06-16 10:31:13 +02:00
|
|
|
|
TempDisableDefHandling : boolean;
|
|
|
|
|
TempResourceRequestHandler : ICefResourceRequestHandler;
|
|
|
|
|
begin
|
|
|
|
|
Result := nil;
|
|
|
|
|
TempResourceRequestHandler := nil;
|
|
|
|
|
TempObject := CefGetObject(self);
|
2019-10-13 18:50:23 +02:00
|
|
|
|
TempDisableDefHandling := disable_default_handling^ <> 0;
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
2019-06-16 10:31:13 +02:00
|
|
|
|
try
|
|
|
|
|
TCefRequestHandlerOwn(TempObject).GetResourceRequestHandler(TCefBrowserRef.UnWrap(browser),
|
|
|
|
|
TCefFrameRef.UnWrap(frame),
|
|
|
|
|
TCefRequestRef.UnWrap(request),
|
|
|
|
|
is_navigation <> 0,
|
|
|
|
|
is_download <> 0,
|
|
|
|
|
CefString(request_initiator),
|
|
|
|
|
TempDisableDefHandling,
|
|
|
|
|
TempResourceRequestHandler);
|
|
|
|
|
|
|
|
|
|
Result := CefGetData(TempResourceRequestHandler);
|
|
|
|
|
disable_default_handling^ := Ord(TempDisableDefHandling);
|
|
|
|
|
finally
|
|
|
|
|
TempResourceRequestHandler := nil;
|
|
|
|
|
end;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2019-07-18 11:48:11 +02:00
|
|
|
|
function cef_request_handler_get_auth_credentials( self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser;
|
|
|
|
|
const origin_url : PCefString;
|
|
|
|
|
isProxy : Integer;
|
|
|
|
|
const host : PCefString;
|
|
|
|
|
port : Integer;
|
|
|
|
|
const realm : PCefString;
|
|
|
|
|
const scheme : PCefString;
|
|
|
|
|
callback : PCefAuthCallback): Integer; stdcall;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
Result := Ord(False);
|
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
|
|
|
|
Result := Ord(TCefRequestHandlerOwn(TempObject).GetAuthCredentials(TCefBrowserRef.UnWrap(browser),
|
2019-07-18 11:48:11 +02:00
|
|
|
|
CefString(origin_url),
|
2018-03-29 20:02:04 +02:00
|
|
|
|
isProxy <> 0,
|
|
|
|
|
CefString(host),
|
|
|
|
|
port,
|
|
|
|
|
CefString(realm),
|
|
|
|
|
CefString(scheme),
|
|
|
|
|
TCefAuthCallbackRef.UnWrap(callback)));
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
function cef_request_handler_on_quota_request( self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser;
|
|
|
|
|
const origin_url : PCefString;
|
|
|
|
|
new_size : Int64;
|
|
|
|
|
callback : PCefRequestCallback): Integer; stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
Result := Ord(False);
|
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
|
|
|
|
Result := Ord(TCefRequestHandlerOwn(TempObject).OnQuotaRequest(TCefBrowserRef.UnWrap(browser),
|
|
|
|
|
CefString(origin_url),
|
|
|
|
|
new_size,
|
|
|
|
|
TCefRequestCallbackRef.UnWrap(callback)));
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
function cef_request_handler_on_certificate_error( self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser;
|
|
|
|
|
cert_error : TCefErrorcode;
|
|
|
|
|
const request_url : PCefString;
|
|
|
|
|
ssl_info : PCefSslInfo;
|
|
|
|
|
callback : PCefRequestCallback): Integer; stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
Result := Ord(False);
|
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
|
|
|
|
Result := Ord(TCefRequestHandlerOwn(TempObject).OnCertificateError(TCefBrowserRef.UnWrap(browser),
|
|
|
|
|
cert_error,
|
|
|
|
|
CefString(request_url),
|
|
|
|
|
TCefSslInfoRef.UnWrap(ssl_info),
|
|
|
|
|
TCefRequestCallbackRef.UnWrap(callback)));
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
procedure cef_request_handler_on_plugin_crashed( self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser;
|
|
|
|
|
const plugin_path : PCefString); stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
|
|
|
|
TCefRequestHandlerOwn(TempObject).OnPluginCrashed(TCefBrowserRef.UnWrap(browser),
|
|
|
|
|
CefString(plugin_path));
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
procedure cef_request_handler_on_render_view_ready(self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser); stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
|
|
|
|
TCefRequestHandlerOwn(TempObject).OnRenderViewReady(TCefBrowserRef.UnWrap(browser));
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
procedure cef_request_handler_on_render_process_terminated(self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser;
|
|
|
|
|
status : TCefTerminationStatus); stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
|
|
|
|
TCefRequestHandlerOwn(TempObject).OnRenderProcessTerminated(TCefBrowserRef.UnWrap(browser),
|
|
|
|
|
status);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-06-21 21:27:55 +02:00
|
|
|
|
procedure cef_request_handler_on_document_available_in_main_frame(self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser); stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
|
|
|
|
begin
|
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
|
|
|
|
TCefRequestHandlerOwn(TempObject).OnDocumentAvailableInMainFrame(TCefBrowserRef.UnWrap(browser));
|
|
|
|
|
end;
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
function cef_request_handler_on_select_client_certificate( self : PCefRequestHandler;
|
|
|
|
|
browser : PCefBrowser;
|
|
|
|
|
isProxy : integer;
|
|
|
|
|
const host : PCefString;
|
|
|
|
|
port : integer;
|
|
|
|
|
certificatesCount : NativeUInt;
|
|
|
|
|
const certificates : PPCefX509Certificate;
|
|
|
|
|
callback : PCefSelectClientCertificateCallback): integer; stdcall;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
var
|
|
|
|
|
TempCertArray : TCefX509CertificateArray;
|
|
|
|
|
i : NativeUInt;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
|
|
|
|
TempCertArray := nil;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
Result := Ord(False);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
try
|
|
|
|
|
if (certificatesCount > 0) and (certificates <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
SetLength(TempCertArray, certificatesCount);
|
|
|
|
|
|
|
|
|
|
i := 0;
|
|
|
|
|
while (i < certificatesCount) do
|
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
|
TempCertArray[i] := TCEFX509CertificateRef.UnWrap(PPointerArray(certificates)^[i]);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
inc(i);
|
|
|
|
|
end;
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestHandlerOwn) then
|
|
|
|
|
Result := Ord(TCefRequestHandlerOwn(TempObject).OnSelectClientCertificate(TCefBrowserRef.UnWrap(browser),
|
|
|
|
|
(isProxy <> 0),
|
|
|
|
|
CefString(host),
|
|
|
|
|
port,
|
|
|
|
|
certificatesCount,
|
|
|
|
|
TempCertArray,
|
|
|
|
|
TCefSelectClientCertificateCallbackRef.UnWrap(callback)));
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
|
|
i := 0;
|
|
|
|
|
while (i < certificatesCount) do
|
|
|
|
|
begin
|
|
|
|
|
TempCertArray[i] := nil;
|
|
|
|
|
inc(i);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
except
|
|
|
|
|
on e : exception do
|
2017-05-07 18:04:05 +02:00
|
|
|
|
if CustomExceptionHandler('uCEFRequestHandler.cef_request_handler_on_select_client_certificate', e) then raise;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
if (TempCertArray <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
Finalize(TempCertArray);
|
|
|
|
|
TempCertArray := nil;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TCefRequestHandlerOwn.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited CreateData(SizeOf(TCefRequestHandler));
|
2018-02-03 17:52:48 +01:00
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
|
with PCefRequestHandler(FData)^ do
|
2018-02-03 17:52:48 +01:00
|
|
|
|
begin
|
2020-06-21 21:27:55 +02:00
|
|
|
|
on_before_browse := {$IFDEF FPC}@{$ENDIF}cef_request_handler_on_before_browse;
|
|
|
|
|
on_open_urlfrom_tab := {$IFDEF FPC}@{$ENDIF}cef_request_handler_on_open_urlfrom_tab;
|
|
|
|
|
get_resource_request_handler := {$IFDEF FPC}@{$ENDIF}cef_request_handler_get_resource_request_handler;
|
|
|
|
|
get_auth_credentials := {$IFDEF FPC}@{$ENDIF}cef_request_handler_get_auth_credentials;
|
|
|
|
|
on_quota_request := {$IFDEF FPC}@{$ENDIF}cef_request_handler_on_quota_request;
|
|
|
|
|
on_certificate_error := {$IFDEF FPC}@{$ENDIF}cef_request_handler_on_certificate_error;
|
|
|
|
|
on_select_client_certificate := {$IFDEF FPC}@{$ENDIF}cef_request_handler_on_select_client_certificate;
|
|
|
|
|
on_plugin_crashed := {$IFDEF FPC}@{$ENDIF}cef_request_handler_on_plugin_crashed;
|
|
|
|
|
on_render_view_ready := {$IFDEF FPC}@{$ENDIF}cef_request_handler_on_render_view_ready;
|
|
|
|
|
on_render_process_terminated := {$IFDEF FPC}@{$ENDIF}cef_request_handler_on_render_process_terminated;
|
|
|
|
|
on_document_available_in_main_frame := {$IFDEF FPC}@{$ENDIF}cef_request_handler_on_document_available_in_main_frame;
|
2018-02-03 17:52:48 +01:00
|
|
|
|
end;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2019-07-18 11:48:11 +02:00
|
|
|
|
function TCefRequestHandlerOwn.GetAuthCredentials(const browser : ICefBrowser;
|
|
|
|
|
const originUrl : ustring;
|
|
|
|
|
isProxy : Boolean;
|
|
|
|
|
const host : ustring;
|
|
|
|
|
port : Integer;
|
|
|
|
|
const realm : ustring;
|
|
|
|
|
const scheme : ustring;
|
|
|
|
|
const callback : ICefAuthCallback): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-04-30 14:44:09 +02:00
|
|
|
|
function TCefRequestHandlerOwn.OnBeforeBrowse(const browser : ICefBrowser;
|
|
|
|
|
const frame : ICefFrame;
|
|
|
|
|
const request : ICefRequest;
|
|
|
|
|
user_gesture : Boolean;
|
|
|
|
|
isRedirect : Boolean): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-04-30 14:44:09 +02:00
|
|
|
|
function TCefRequestHandlerOwn.OnCertificateError(const browser : ICefBrowser;
|
|
|
|
|
certError : TCefErrorcode;
|
|
|
|
|
const requestUrl : ustring;
|
|
|
|
|
const sslInfo : ICefSslInfo;
|
|
|
|
|
const callback : ICefRequestCallback): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefRequestHandlerOwn.OnSelectClientCertificate(const browser : ICefBrowser;
|
|
|
|
|
isProxy : boolean;
|
|
|
|
|
const host : ustring;
|
|
|
|
|
port : integer;
|
|
|
|
|
certificatesCount : NativeUInt;
|
|
|
|
|
const certificates : TCefX509CertificateArray;
|
|
|
|
|
const callback : ICefSelectClientCertificateCallback): boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-04-30 14:44:09 +02:00
|
|
|
|
function TCefRequestHandlerOwn.OnOpenUrlFromTab(const browser : ICefBrowser;
|
|
|
|
|
const frame : ICefFrame;
|
|
|
|
|
const targetUrl : ustring;
|
|
|
|
|
targetDisposition : TCefWindowOpenDisposition;
|
|
|
|
|
userGesture : Boolean): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
2019-06-16 10:31:13 +02:00
|
|
|
|
procedure TCefRequestHandlerOwn.GetResourceRequestHandler(const browser : ICefBrowser;
|
|
|
|
|
const frame : ICefFrame;
|
|
|
|
|
const request : ICefRequest;
|
|
|
|
|
is_navigation : boolean;
|
|
|
|
|
is_download : boolean;
|
|
|
|
|
const request_initiator : ustring;
|
|
|
|
|
var disable_default_handling : boolean;
|
|
|
|
|
var aResourceRequestHandler : ICefResourceRequestHandler);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2019-06-16 10:31:13 +02:00
|
|
|
|
aResourceRequestHandler := nil;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-04-30 14:44:09 +02:00
|
|
|
|
procedure TCefRequestHandlerOwn.OnPluginCrashed(const browser : ICefBrowser;
|
|
|
|
|
const pluginPath : ustring);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-04-30 14:44:09 +02:00
|
|
|
|
//
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-04-30 14:44:09 +02:00
|
|
|
|
function TCefRequestHandlerOwn.OnQuotaRequest(const browser : ICefBrowser;
|
|
|
|
|
const originUrl : ustring;
|
|
|
|
|
newSize : Int64;
|
|
|
|
|
const callback : ICefRequestCallback): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-04-30 14:44:09 +02:00
|
|
|
|
procedure TCefRequestHandlerOwn.OnRenderProcessTerminated(const browser : ICefBrowser;
|
|
|
|
|
status : TCefTerminationStatus);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-04-30 14:44:09 +02:00
|
|
|
|
//
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-06-21 21:27:55 +02:00
|
|
|
|
procedure TCefRequestHandlerOwn.OnDocumentAvailableInMainFrame(const browser: ICefBrowser);
|
|
|
|
|
begin
|
|
|
|
|
//
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
|
procedure TCefRequestHandlerOwn.OnRenderViewReady(const browser: ICefBrowser);
|
|
|
|
|
begin
|
2018-04-30 14:44:09 +02:00
|
|
|
|
//
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-03 17:52:48 +01:00
|
|
|
|
procedure TCefRequestHandlerOwn.RemoveReferences;
|
|
|
|
|
begin
|
|
|
|
|
//
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
|
// TCustomRequestHandler
|
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
|
constructor TCustomRequestHandler.Create(const events : IChromiumEvents);
|
2017-01-27 16:37:51 +01: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 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2019-06-16 10:31:13 +02:00
|
|
|
|
procedure TCustomRequestHandler.BeforeDestruction;
|
2017-06-11 17:48:20 +02:00
|
|
|
|
begin
|
2019-11-08 14:32:03 +01:00
|
|
|
|
FEvents := nil;
|
2017-06-11 17:48:20 +02:00
|
|
|
|
|
2019-06-16 10:31:13 +02:00
|
|
|
|
inherited BeforeDestruction;
|
2017-06-11 17:48:20 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-03 17:52:48 +01:00
|
|
|
|
procedure TCustomRequestHandler.RemoveReferences;
|
|
|
|
|
begin
|
|
|
|
|
FEvents := nil;
|
|
|
|
|
end;
|
|
|
|
|
|
2019-07-18 11:48:11 +02:00
|
|
|
|
function TCustomRequestHandler.GetAuthCredentials(const browser : ICefBrowser;
|
|
|
|
|
const originUrl : ustring;
|
|
|
|
|
isProxy : Boolean;
|
|
|
|
|
const host : ustring;
|
|
|
|
|
port : Integer;
|
2019-10-06 22:30:36 +02:00
|
|
|
|
const realm : ustring;
|
2019-07-18 11:48:11 +02:00
|
|
|
|
const scheme : ustring;
|
|
|
|
|
const callback : ICefAuthCallback): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
|
if (FEvents <> nil) then
|
2019-07-18 11:48:11 +02:00
|
|
|
|
Result := IChromiumEvents(FEvents).doOnGetAuthCredentials(browser, originUrl, isProxy, host, port, realm, scheme, callback)
|
2017-06-11 17:48:20 +02:00
|
|
|
|
else
|
2019-07-18 11:48:11 +02:00
|
|
|
|
Result := inherited GetAuthCredentials(browser, originUrl, isProxy, host, port, realm, scheme, callback);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-04-30 14:44:09 +02:00
|
|
|
|
function TCustomRequestHandler.OnBeforeBrowse(const browser : ICefBrowser;
|
|
|
|
|
const frame : ICefFrame;
|
|
|
|
|
const request : ICefRequest;
|
|
|
|
|
user_gesture : Boolean;
|
|
|
|
|
isRedirect : Boolean): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
|
if (FEvents <> nil) then
|
2018-04-30 14:44:09 +02:00
|
|
|
|
Result := IChromiumEvents(FEvents).doOnBeforeBrowse(browser, frame, request, user_gesture, isRedirect)
|
2018-02-03 17:52:48 +01:00
|
|
|
|
else
|
2018-04-30 14:44:09 +02:00
|
|
|
|
Result := inherited OnBeforeBrowse(browser, frame, request, user_gesture, isRedirect);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-06-11 20:36:14 +02:00
|
|
|
|
function TCustomRequestHandler.OnCertificateError(const browser : ICefBrowser;
|
|
|
|
|
certError : TCefErrorcode;
|
|
|
|
|
const requestUrl : ustring;
|
|
|
|
|
const sslInfo : ICefSslInfo;
|
|
|
|
|
const callback : ICefRequestCallback): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
|
Result := IChromiumEvents(FEvents).doOnCertificateError(browser, certError, requestUrl, sslInfo, callback)
|
2017-06-11 17:48:20 +02:00
|
|
|
|
else
|
2017-06-11 20:36:14 +02:00
|
|
|
|
Result := inherited OnCertificateError(browser, certError, requestUrl, sslInfo, callback);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-06-11 20:36:14 +02:00
|
|
|
|
function TCustomRequestHandler.OnOpenUrlFromTab(const browser : ICefBrowser;
|
|
|
|
|
const frame : ICefFrame;
|
|
|
|
|
const targetUrl : ustring;
|
|
|
|
|
targetDisposition : TCefWindowOpenDisposition;
|
|
|
|
|
userGesture : Boolean): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
|
Result := IChromiumEvents(FEvents).doOnOpenUrlFromTab(browser, frame, targetUrl, targetDisposition, userGesture)
|
2017-06-11 17:48:20 +02:00
|
|
|
|
else
|
2017-06-11 20:36:14 +02:00
|
|
|
|
Result := inherited OnOpenUrlFromTab(browser, frame, targetUrl, targetDisposition, userGesture);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2019-06-16 10:31:13 +02:00
|
|
|
|
procedure TCustomRequestHandler.GetResourceRequestHandler(const browser : ICefBrowser;
|
|
|
|
|
const frame : ICefFrame;
|
|
|
|
|
const request : ICefRequest;
|
|
|
|
|
is_navigation : boolean;
|
|
|
|
|
is_download : boolean;
|
|
|
|
|
const request_initiator : ustring;
|
|
|
|
|
var disable_default_handling : boolean;
|
|
|
|
|
var aResourceRequestHandler : ICefResourceRequestHandler);
|
|
|
|
|
begin
|
|
|
|
|
if (FEvents <> nil) then
|
2019-11-08 14:32:03 +01:00
|
|
|
|
IChromiumEvents(FEvents).doGetResourceRequestHandler_ReqHdlr(browser,
|
|
|
|
|
frame,
|
|
|
|
|
request,
|
|
|
|
|
is_navigation,
|
|
|
|
|
is_download,
|
|
|
|
|
request_initiator,
|
|
|
|
|
disable_default_handling,
|
|
|
|
|
aResourceRequestHandler)
|
2019-10-13 18:50:23 +02:00
|
|
|
|
else
|
2019-11-08 14:32:03 +01:00
|
|
|
|
inherited GetResourceRequestHandler(browser,
|
|
|
|
|
frame,
|
|
|
|
|
request,
|
|
|
|
|
is_navigation,
|
|
|
|
|
is_download,
|
2019-06-16 10:31:13 +02:00
|
|
|
|
request_initiator,
|
|
|
|
|
disable_default_handling,
|
|
|
|
|
aResourceRequestHandler);
|
|
|
|
|
end;
|
2019-10-13 18:50:23 +02:00
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
|
function TCustomRequestHandler.OnSelectClientCertificate(const browser : ICefBrowser;
|
|
|
|
|
isProxy : boolean;
|
|
|
|
|
const host : ustring;
|
|
|
|
|
port : integer;
|
|
|
|
|
certificatesCount : NativeUInt;
|
|
|
|
|
const certificates : TCefX509CertificateArray;
|
|
|
|
|
const callback : ICefSelectClientCertificateCallback): boolean;
|
|
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
|
Result := IChromiumEvents(FEvents).doOnSelectClientCertificate(browser, isProxy, host, port, certificatesCount, certificates, callback)
|
2017-06-11 17:48:20 +02:00
|
|
|
|
else
|
2017-06-11 20:36:14 +02:00
|
|
|
|
Result := inherited OnSelectClientCertificate(browser, isProxy, host, port, certificatesCount, certificates, callback);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-06-11 17:48:20 +02:00
|
|
|
|
procedure TCustomRequestHandler.OnPluginCrashed(const browser: ICefBrowser; const pluginPath: ustring);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
|
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnPluginCrashed(browser, pluginPath);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-06-11 20:36:14 +02:00
|
|
|
|
function TCustomRequestHandler.OnQuotaRequest(const browser : ICefBrowser;
|
|
|
|
|
const originUrl : ustring;
|
|
|
|
|
newSize : Int64;
|
|
|
|
|
const callback : ICefRequestCallback): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
|
Result := IChromiumEvents(FEvents).doOnQuotaRequest(browser, originUrl, newSize, callback)
|
2017-06-11 17:48:20 +02:00
|
|
|
|
else
|
2017-06-11 20:36:14 +02:00
|
|
|
|
Result := inherited OnQuotaRequest(browser, originUrl, newSize, callback);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-06-11 20:36:14 +02:00
|
|
|
|
procedure TCustomRequestHandler.OnRenderProcessTerminated(const browser: ICefBrowser; status: TCefTerminationStatus);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2020-06-21 21:27:55 +02:00
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
|
IChromiumEvents(FEvents).doOnRenderProcessTerminated(browser, status);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomRequestHandler.OnDocumentAvailableInMainFrame(const browser: ICefBrowser);
|
|
|
|
|
begin
|
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
|
IChromiumEvents(FEvents).doOnDocumentAvailableInMainFrame(browser);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomRequestHandler.OnRenderViewReady(const browser: ICefBrowser);
|
|
|
|
|
begin
|
2020-06-21 21:27:55 +02:00
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
|
IChromiumEvents(FEvents).doOnRenderViewReady(browser);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end.
|