2020-06-21 21:27:55 +02:00
|
|
|
unit uCEFDevToolsMessageObserver;
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2020-06-21 21:27:55 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
|
|
|
|
|
|
|
type
|
|
|
|
TCEFDevToolsMessageObserverOwn = class(TCefBaseRefCountedOwn, ICefDevToolsMessageObserver)
|
|
|
|
protected
|
2021-01-16 14:35:01 +01:00
|
|
|
procedure OnDevToolsMessage(const browser: ICefBrowser; const message_: Pointer; message_size: NativeUInt; var aHandled: boolean); virtual;
|
|
|
|
procedure OnDevToolsMethodResult(const browser: ICefBrowser; message_id: integer; success: boolean; const result: Pointer; result_size: NativeUInt); virtual;
|
|
|
|
procedure OnDevToolsEvent(const browser: ICefBrowser; const method: ustring; const params: Pointer; params_size: NativeUInt); virtual;
|
2020-06-21 21:27:55 +02:00
|
|
|
procedure OnDevToolsAgentAttached(const browser: ICefBrowser); virtual;
|
|
|
|
procedure OnDevToolsAgentDetached(const browser: ICefBrowser); virtual;
|
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create; virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TCustomDevToolsMessageObserver = class(TCEFDevToolsMessageObserverOwn)
|
|
|
|
protected
|
|
|
|
FEvents : Pointer;
|
|
|
|
|
2021-01-16 14:35:01 +01:00
|
|
|
procedure OnDevToolsMessage(const browser: ICefBrowser; const message_: Pointer; message_size: NativeUInt; var aHandled: boolean); override;
|
|
|
|
procedure OnDevToolsMethodResult(const browser: ICefBrowser; message_id: integer; success: boolean; const result: Pointer; result_size: NativeUInt); override;
|
|
|
|
procedure OnDevToolsEvent(const browser: ICefBrowser; const method: ustring; const params: Pointer; params_size: NativeUInt); override;
|
2020-06-21 21:27:55 +02:00
|
|
|
procedure OnDevToolsAgentAttached(const browser: ICefBrowser); override;
|
|
|
|
procedure OnDevToolsAgentDetached(const browser: ICefBrowser); override;
|
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create(const events: IChromiumEvents); reintroduce;
|
|
|
|
destructor Destroy; override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
System.SysUtils,
|
|
|
|
{$ELSE}
|
|
|
|
SysUtils,
|
|
|
|
{$ENDIF}
|
2020-07-17 12:56:43 +02:00
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFJson;
|
2020-06-21 21:27:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************
|
|
|
|
// ************** TCEFDevToolsMessageObserverOwn **************
|
|
|
|
// ************************************************************
|
|
|
|
|
|
|
|
function cef_on_dev_tools_message( self : PCefDevToolsMessageObserver;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
const message_ : Pointer;
|
|
|
|
message_size : NativeUInt): Integer; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
|
|
|
TempHandled : boolean;
|
|
|
|
begin
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
TempHandled := False;
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
2021-01-16 14:35:01 +01:00
|
|
|
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsMessage(TCefBrowserRef.UnWrap(browser),
|
|
|
|
message_,
|
|
|
|
message_size,
|
|
|
|
TempHandled);
|
2020-06-21 21:27:55 +02:00
|
|
|
|
|
|
|
Result := ord(TempHandled);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure cef_on_dev_tools_method_result( self : PCefDevToolsMessageObserver;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
message_id : Integer;
|
|
|
|
success : Integer;
|
|
|
|
const result : Pointer;
|
|
|
|
result_size : NativeUInt); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
|
|
|
begin
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
2021-01-16 14:35:01 +01:00
|
|
|
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsMethodResult(TCefBrowserRef.UnWrap(browser),
|
|
|
|
message_id,
|
|
|
|
success <> 0,
|
|
|
|
result,
|
|
|
|
result_size);
|
2020-06-21 21:27:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure cef_on_dev_tools_event( self : PCefDevToolsMessageObserver;
|
2020-07-14 15:50:23 +02:00
|
|
|
browser : PCefBrowser;
|
2020-06-21 21:27:55 +02:00
|
|
|
const method : PCefString;
|
|
|
|
const params : Pointer;
|
|
|
|
params_size : NativeUInt); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
|
|
|
begin
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
2021-01-16 14:35:01 +01:00
|
|
|
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsEvent(TCefBrowserRef.UnWrap(browser),
|
|
|
|
CefString(method),
|
|
|
|
params,
|
|
|
|
params_size);
|
2020-06-21 21:27:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure cef_on_dev_tools_agent_attached(self : PCefDevToolsMessageObserver;
|
|
|
|
browser : PCefBrowser); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
|
|
|
begin
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
|
|
|
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsAgentAttached(TCefBrowserRef.UnWrap(browser));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure cef_on_dev_tools_agent_detached(self : PCefDevToolsMessageObserver;
|
|
|
|
browser : PCefBrowser); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
|
|
|
begin
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
|
|
|
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsAgentDetached(TCefBrowserRef.UnWrap(browser));
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TCEFDevToolsMessageObserverOwn.Create;
|
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefDevToolsMessageObserver));
|
|
|
|
|
|
|
|
with PCefDevToolsMessageObserver(FData)^ do
|
|
|
|
begin
|
|
|
|
on_dev_tools_message := {$IFDEF FPC}@{$ENDIF}cef_on_dev_tools_message;
|
|
|
|
on_dev_tools_method_result := {$IFDEF FPC}@{$ENDIF}cef_on_dev_tools_method_result;
|
|
|
|
on_dev_tools_event := {$IFDEF FPC}@{$ENDIF}cef_on_dev_tools_event;
|
|
|
|
on_dev_tools_agent_attached := {$IFDEF FPC}@{$ENDIF}cef_on_dev_tools_agent_attached;
|
|
|
|
on_dev_tools_agent_detached := {$IFDEF FPC}@{$ENDIF}cef_on_dev_tools_agent_detached;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFDevToolsMessageObserverOwn.OnDevToolsMessage(const browser : ICefBrowser;
|
2021-01-16 14:35:01 +01:00
|
|
|
const message_ : Pointer;
|
|
|
|
message_size : NativeUInt;
|
2020-06-21 21:27:55 +02:00
|
|
|
var aHandled : boolean);
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFDevToolsMessageObserverOwn.OnDevToolsMethodResult(const browser : ICefBrowser;
|
|
|
|
message_id : integer;
|
|
|
|
success : boolean;
|
2021-01-16 14:35:01 +01:00
|
|
|
const result : Pointer;
|
|
|
|
result_size : NativeUInt);
|
2020-06-21 21:27:55 +02:00
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
2021-01-16 14:35:01 +01:00
|
|
|
procedure TCEFDevToolsMessageObserverOwn.OnDevToolsEvent(const browser : ICefBrowser;
|
|
|
|
const method : ustring;
|
|
|
|
const params : Pointer;
|
|
|
|
params_size : NativeUInt);
|
2020-06-21 21:27:55 +02:00
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFDevToolsMessageObserverOwn.OnDevToolsAgentAttached(const browser: ICefBrowser);
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFDevToolsMessageObserverOwn.OnDevToolsAgentDetached(const browser: ICefBrowser);
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************
|
|
|
|
// ************** TCustomDevToolsMessageObserver **************
|
|
|
|
// ************************************************************
|
|
|
|
|
|
|
|
constructor TCustomDevToolsMessageObserver.Create(const events: IChromiumEvents);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
FEvents := Pointer(events);
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TCustomDevToolsMessageObserver.Destroy;
|
|
|
|
begin
|
|
|
|
FEvents := nil;
|
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomDevToolsMessageObserver.OnDevToolsMessage(const browser : ICefBrowser;
|
2021-01-16 14:35:01 +01:00
|
|
|
const message_ : Pointer;
|
|
|
|
message_size : NativeUInt;
|
2020-06-21 21:27:55 +02:00
|
|
|
var aHandled : boolean);
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
if (FEvents <> nil) then
|
2021-01-16 14:35:01 +01:00
|
|
|
IChromiumEvents(FEvents).doOnDevToolsMessage(browser, message_, message_size, aHandled);
|
2020-06-21 21:27:55 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomDevToolsMessageObserver.OnDevToolsMessage', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomDevToolsMessageObserver.OnDevToolsMethodResult(const browser : ICefBrowser;
|
|
|
|
message_id : integer;
|
|
|
|
success : boolean;
|
2021-01-16 14:35:01 +01:00
|
|
|
const result : Pointer;
|
|
|
|
result_size : NativeUInt);
|
2020-06-21 21:27:55 +02:00
|
|
|
begin
|
|
|
|
try
|
|
|
|
if (FEvents <> nil) then
|
2021-01-16 14:35:01 +01:00
|
|
|
IChromiumEvents(FEvents).doOnDevToolsMethodResult(browser, message_id, success, result, result_size);
|
2020-06-21 21:27:55 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomDevToolsMessageObserver.OnDevToolsMethodResult', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2021-01-16 14:35:01 +01:00
|
|
|
procedure TCustomDevToolsMessageObserver.OnDevToolsEvent(const browser : ICefBrowser;
|
|
|
|
const method : ustring;
|
|
|
|
const params : Pointer;
|
|
|
|
params_size : NativeUInt);
|
2020-06-21 21:27:55 +02:00
|
|
|
begin
|
|
|
|
try
|
|
|
|
if (FEvents <> nil) then
|
2021-01-16 14:35:01 +01:00
|
|
|
IChromiumEvents(FEvents).doOnDevToolsEvent(browser, method, params, params_size);
|
2020-06-21 21:27:55 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomDevToolsMessageObserver.OnDevToolsEvent', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomDevToolsMessageObserver.OnDevToolsAgentAttached(const browser: ICefBrowser);
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
IChromiumEvents(FEvents).doOnDevToolsAgentAttached(browser);
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomDevToolsMessageObserver.OnDevToolsAgentAttached', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomDevToolsMessageObserver.OnDevToolsAgentDetached(const browser: ICefBrowser);
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
IChromiumEvents(FEvents).doOnDevToolsAgentDetached(browser);
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomDevToolsMessageObserver.OnDevToolsAgentDetached', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|