2017-01-27 16:37:51 +01:00
|
|
|
unit uCEFLoadHandler;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2019-11-08 23:15:53 +01:00
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFApplicationCore;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
type
|
2017-03-16 19:09:42 +01:00
|
|
|
TCefLoadHandlerOwn = class(TCefBaseRefCountedOwn, ICefLoadHandler)
|
2017-01-27 16:37:51 +01:00
|
|
|
protected
|
|
|
|
procedure OnLoadingStateChange(const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean); virtual;
|
|
|
|
procedure OnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: TCefTransitionType); virtual;
|
|
|
|
procedure OnLoadEnd(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer); virtual;
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: TCefErrorCode; const errorText, failedUrl: ustring); 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;
|
|
|
|
|
|
|
|
TCustomLoadHandler = class(TCefLoadHandlerOwn)
|
|
|
|
protected
|
2018-02-03 17:52:48 +01:00
|
|
|
FEvents : Pointer;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
procedure OnLoadingStateChange(const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean); override;
|
|
|
|
procedure OnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: TCefTransitionType); override;
|
|
|
|
procedure OnLoadEnd(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer); override;
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: TCefErrorCode; const errorText, failedUrl: ustring); override;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
2018-02-03 17:52:48 +01:00
|
|
|
procedure RemoveReferences; 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;
|
2017-06-11 17:48:20 +02:00
|
|
|
destructor Destroy; override;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-11-15 19:08:16 +01:00
|
|
|
TCustomRenderLoadHandler = class(TCefLoadHandlerOwn)
|
|
|
|
protected
|
2019-11-08 23:15:53 +01:00
|
|
|
FCefApp : TCefApplicationCore;
|
2018-11-15 19:08:16 +01:00
|
|
|
|
|
|
|
procedure OnLoadingStateChange(const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean); override;
|
|
|
|
procedure OnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: TCefTransitionType); override;
|
|
|
|
procedure OnLoadEnd(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer); override;
|
|
|
|
procedure OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: TCefErrorCode; const errorText, failedUrl: ustring); override;
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
procedure RemoveReferences; override;
|
|
|
|
|
2018-11-15 19:08:16 +01:00
|
|
|
public
|
2019-11-08 23:15:53 +01:00
|
|
|
constructor Create(const aCefApp : TCefApplicationCore); reintroduce; virtual;
|
2018-11-15 19:08:16 +01:00
|
|
|
destructor Destroy; override;
|
|
|
|
end;
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2018-02-03 17:52:48 +01:00
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
System.SysUtils,
|
|
|
|
{$ELSE}
|
|
|
|
SysUtils,
|
|
|
|
{$ENDIF}
|
2017-01-27 16:37:51 +01:00
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFFrame;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_load_handler_on_loading_state_change(self : PCefLoadHandler;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
isLoading : integer;
|
|
|
|
canGoBack : integer;
|
|
|
|
canGoForward : Integer); 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 TCefLoadHandlerOwn) then
|
|
|
|
TCefLoadHandlerOwn(TempObject).OnLoadingStateChange(TCefBrowserRef.UnWrap(browser),
|
|
|
|
isLoading <> 0,
|
|
|
|
canGoBack <> 0,
|
|
|
|
canGoForward <> 0);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_load_handler_on_load_start(self : PCefLoadHandler;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
frame : PCefFrame;
|
|
|
|
transition_type : TCefTransitionType); 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 TCefLoadHandlerOwn) then
|
|
|
|
TCefLoadHandlerOwn(TempObject).OnLoadStart(TCefBrowserRef.UnWrap(browser),
|
|
|
|
TCefFrameRef.UnWrap(frame),
|
|
|
|
transition_type);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_load_handler_on_load_end(self : PCefLoadHandler;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
frame : PCefFrame;
|
|
|
|
httpStatusCode : Integer); 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 TCefLoadHandlerOwn) then
|
|
|
|
TCefLoadHandlerOwn(TempObject).OnLoadEnd(TCefBrowserRef.UnWrap(browser),
|
|
|
|
TCefFrameRef.UnWrap(frame),
|
|
|
|
httpStatusCode);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_load_handler_on_load_error( self : PCefLoadHandler;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
frame : PCefFrame;
|
|
|
|
errorCode : TCefErrorCode;
|
|
|
|
const errorText : PCefString;
|
|
|
|
const failedUrl : 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 TCefLoadHandlerOwn) then
|
|
|
|
TCefLoadHandlerOwn(TempObject).OnLoadError(TCefBrowserRef.UnWrap(browser),
|
|
|
|
TCefFrameRef.UnWrap(frame),
|
|
|
|
errorCode,
|
|
|
|
CefString(errorText),
|
|
|
|
CefString(failedUrl));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TCefLoadHandlerOwn.Create;
|
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefLoadHandler));
|
|
|
|
|
|
|
|
with PCefLoadHandler(FData)^ do
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
on_loading_state_change := {$IFDEF FPC}@{$ENDIF}cef_load_handler_on_loading_state_change;
|
|
|
|
on_load_start := {$IFDEF FPC}@{$ENDIF}cef_load_handler_on_load_start;
|
|
|
|
on_load_end := {$IFDEF FPC}@{$ENDIF}cef_load_handler_on_load_end;
|
|
|
|
on_load_error := {$IFDEF FPC}@{$ENDIF}cef_load_handler_on_load_error;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefLoadHandlerOwn.OnLoadEnd(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer);
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefLoadHandlerOwn.OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: TCefErrorCode; const errorText, failedUrl: ustring);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefLoadHandlerOwn.OnLoadingStateChange(const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean);
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefLoadHandlerOwn.OnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: TCefTransitionType);
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
2018-02-03 17:52:48 +01:00
|
|
|
procedure TCefLoadHandlerOwn.RemoveReferences;
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
// TCustomLoadHandler
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
constructor TCustomLoadHandler.Create(const events : IChromiumEvents);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
FEvents := Pointer(events);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2017-06-11 17:48:20 +02:00
|
|
|
destructor TCustomLoadHandler.Destroy;
|
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
RemoveReferences;
|
2017-06-11 17:48:20 +02:00
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2018-02-03 17:52:48 +01:00
|
|
|
procedure TCustomLoadHandler.RemoveReferences;
|
|
|
|
begin
|
|
|
|
FEvents := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomLoadHandler.OnLoadEnd(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
httpStatusCode : Integer);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnLoadEnd(browser, frame, httpStatusCode);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-02-03 17:52:48 +01:00
|
|
|
procedure TCustomLoadHandler.OnLoadError(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
2018-03-29 20:02:04 +02:00
|
|
|
errorCode : TCefErrorCode;
|
2018-02-03 17:52:48 +01:00
|
|
|
const errorText : ustring;
|
|
|
|
const failedUrl : ustring);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnLoadError(browser, frame, errorCode, errorText, failedUrl);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-02-03 17:52:48 +01:00
|
|
|
procedure TCustomLoadHandler.OnLoadingStateChange(const browser : ICefBrowser;
|
|
|
|
isLoading : Boolean;
|
|
|
|
canGoBack : Boolean;
|
|
|
|
canGoForward : Boolean);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnLoadingStateChange(browser, isLoading, canGoBack, canGoForward);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-02-03 17:52:48 +01:00
|
|
|
procedure TCustomLoadHandler.OnLoadStart(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
transitionType : TCefTransitionType);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-02-03 17:52:48 +01:00
|
|
|
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnLoadStart(browser, frame, transitionType);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-11-15 19:08:16 +01:00
|
|
|
|
|
|
|
// TCustomRenderLoadHandler
|
|
|
|
|
2019-11-08 23:15:53 +01:00
|
|
|
constructor TCustomRenderLoadHandler.Create(const aCefApp : TCefApplicationCore);
|
2018-11-15 19:08:16 +01:00
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
FCefApp := aCefApp;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TCustomRenderLoadHandler.Destroy;
|
|
|
|
begin
|
2020-11-10 15:02:49 +01:00
|
|
|
RemoveReferences;
|
2018-11-15 19:08:16 +01:00
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
procedure TCustomRenderLoadHandler.RemoveReferences;
|
|
|
|
begin
|
|
|
|
FCefApp := nil;
|
|
|
|
end;
|
|
|
|
|
2023-08-03 15:50:13 +02:00
|
|
|
procedure TCustomRenderLoadHandler.OnLoadingStateChange(const browser : ICefBrowser;
|
|
|
|
isLoading : Boolean;
|
|
|
|
canGoBack : Boolean;
|
|
|
|
canGoForward : Boolean);
|
2018-11-15 19:08:16 +01:00
|
|
|
begin
|
|
|
|
try
|
2023-08-03 15:50:13 +02:00
|
|
|
if (FCefApp <> nil) then
|
2023-08-03 15:58:57 +02:00
|
|
|
IApplicationCoreEvents(FCefApp).doOnLoadingStateChange(browser, isLoading, canGoBack, canGoForward);
|
2018-11-15 19:08:16 +01:00
|
|
|
except
|
|
|
|
on e : exception do
|
2023-08-03 15:50:13 +02:00
|
|
|
if CustomExceptionHandler('TCustomRenderLoadHandler.OnLoadingStateChange', e) then raise;
|
2018-11-15 19:08:16 +01:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2023-08-03 15:50:13 +02:00
|
|
|
procedure TCustomRenderLoadHandler.OnLoadStart(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
transitionType : TCefTransitionType);
|
2018-11-15 19:08:16 +01:00
|
|
|
begin
|
|
|
|
try
|
2023-08-03 15:50:13 +02:00
|
|
|
if (FCefApp <> nil) then
|
2023-08-03 15:58:57 +02:00
|
|
|
IApplicationCoreEvents(FCefApp).doOnLoadStart(browser, frame, transitionType);
|
2018-11-15 19:08:16 +01:00
|
|
|
except
|
|
|
|
on e : exception do
|
2023-08-03 15:50:13 +02:00
|
|
|
if CustomExceptionHandler('TCustomRenderLoadHandler.OnLoadStart', e) then raise;
|
2018-11-15 19:08:16 +01:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2023-08-03 15:50:13 +02:00
|
|
|
procedure TCustomRenderLoadHandler.OnLoadEnd(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
httpStatusCode : Integer);
|
2018-11-15 19:08:16 +01:00
|
|
|
begin
|
|
|
|
try
|
2023-08-03 15:50:13 +02:00
|
|
|
if (FCefApp <> nil) then
|
2023-08-03 15:58:57 +02:00
|
|
|
IApplicationCoreEvents(FCefApp).doOnLoadEnd(browser, frame, httpStatusCode);
|
2018-11-15 19:08:16 +01:00
|
|
|
except
|
|
|
|
on e : exception do
|
2023-08-03 15:50:13 +02:00
|
|
|
if CustomExceptionHandler('TCustomRenderLoadHandler.OnLoadEnd', e) then raise;
|
2018-11-15 19:08:16 +01:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2023-08-03 15:50:13 +02:00
|
|
|
procedure TCustomRenderLoadHandler.OnLoadError(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
errorCode : TCefErrorCode;
|
|
|
|
const errorText : ustring;
|
|
|
|
const failedUrl : ustring);
|
2018-11-15 19:08:16 +01:00
|
|
|
begin
|
|
|
|
try
|
2023-08-03 15:50:13 +02:00
|
|
|
if (FCefApp <> nil) then
|
2023-08-03 15:58:57 +02:00
|
|
|
IApplicationCoreEvents(FCefApp).doOnLoadError(browser, frame, errorCode, errorText, failedUrl);
|
2018-11-15 19:08:16 +01:00
|
|
|
except
|
|
|
|
on e : exception do
|
2023-08-03 15:50:13 +02:00
|
|
|
if CustomExceptionHandler('TCustomRenderLoadHandler.OnLoadError', e) then raise;
|
2018-11-15 19:08:16 +01:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
end.
|