Fixed TChromium.OnDevToolsEvent declaration

Added more parameter checks to CefString.
Added TChromium.DestroyAllHandlersAndObservers which includes DestroyDevToolsMsgObserver to fix issue #288.
This commit is contained in:
Salvador Díaz Fau 2020-07-14 15:50:23 +02:00
parent 5bfeb8de3f
commit 51658e03f2
7 changed files with 80 additions and 72 deletions

View File

@ -385,6 +385,7 @@ type
procedure DestroyResourceRequestHandler;
procedure DestroyMediaObserver;
procedure DestroyDevToolsMsgObserver;
procedure DestroyAllHandlersAndObservers;
procedure CreateReqContextHandler;
procedure CreateResourceRequestHandler;
@ -582,7 +583,7 @@ type
// ICefDevToolsMessageObserver
procedure doOnDevToolsMessage(const browser: ICefBrowser; const message_: ICefValue; var aHandled: boolean); virtual;
procedure doOnDevToolsMethodResult(const browser: ICefBrowser; message_id: integer; success: boolean; const result: ICefValue); virtual;
procedure doOnDevToolsEvent(const method: ustring; const params: ICefValue); virtual;
procedure doOnDevToolsEvent(const browser: ICefBrowser; const method: ustring; const params: ICefValue); virtual;
procedure doOnDevToolsAgentAttached(const browser: ICefBrowser); virtual;
procedure doOnDevToolsAgentDetached(const browser: ICefBrowser); virtual;
@ -1244,24 +1245,22 @@ end;
procedure TChromiumCore.BeforeDestruction;
begin
{$IFDEF MSWINDOWS}
RestoreCompWndProc(FBrowserCompHWND, 0, FOldBrowserCompWndPrc);
FreeAndNilStub(FBrowserCompStub);
try
{$IFDEF MSWINDOWS}
RestoreCompWndProc(FBrowserCompHWND, 0, FOldBrowserCompWndPrc);
FreeAndNilStub(FBrowserCompStub);
RestoreCompWndProc(FWidgetCompHWND, 0, FOldWidgetCompWndPrc);
FreeAndNilStub(FWidgetCompStub);
RestoreCompWndProc(FWidgetCompHWND, 0, FOldWidgetCompWndPrc);
FreeAndNilStub(FWidgetCompStub);
RestoreCompWndProc(FRenderCompHWND, 0, FOldRenderCompWndPrc);
FreeAndNilStub(FRenderCompStub);
{$ENDIF}
RestoreCompWndProc(FRenderCompHWND, 0, FOldRenderCompWndPrc);
FreeAndNilStub(FRenderCompStub);
{$ENDIF}
DestroyClientHandler;
DestroyReqContextHandler;
DestroyResourceRequestHandler;
DestroyMediaObserver;
DestroyDevToolsMsgObserver;
inherited BeforeDestruction;
DestroyAllHandlersAndObservers;
finally
inherited BeforeDestruction;
end;
end;
{$IFDEF MSWINDOWS}
@ -1414,39 +1413,6 @@ begin
end;
end;
procedure TChromiumCore.CreateReqContextHandler;
begin
if MustCreateRequestContextHandler and
(FReqContextHandler = nil) then
FReqContextHandler := TCustomRequestContextHandler.Create(self);
end;
procedure TChromiumCore.DestroyMediaObserver;
begin
FMediaObserverReg := nil;
FMediaObserver := nil;
end;
procedure TChromiumCore.CreateMediaObserver;
begin
if MustCreateMediaObserver and
(FMediaObserver = nil) then
FMediaObserver := TCustomMediaObserver.Create(self);
end;
procedure TChromiumCore.DestroyDevToolsMsgObserver;
begin
FDevToolsMsgObserverReg := nil;
FDevToolsMsgObserver := nil;
end;
procedure TChromiumCore.CreateDevToolsMsgObserver;
begin
if MustCreateDevToolsMessageObserver and
(FDevToolsMsgObserver = nil) then
FDevToolsMsgObserver := TCustomDevToolsMessageObserver.Create(self);
end;
procedure TChromiumCore.DestroyResourceRequestHandler;
begin
try
@ -1461,6 +1427,48 @@ begin
end;
end;
procedure TChromiumCore.DestroyMediaObserver;
begin
FMediaObserverReg := nil;
FMediaObserver := nil;
end;
procedure TChromiumCore.DestroyDevToolsMsgObserver;
begin
FDevToolsMsgObserverReg := nil;
FDevToolsMsgObserver := nil;
end;
procedure TChromiumCore.DestroyAllHandlersAndObservers;
begin
DestroyDevToolsMsgObserver;
DestroyMediaObserver;
DestroyResourceRequestHandler;
DestroyReqContextHandler;
DestroyClientHandler;
end;
procedure TChromiumCore.CreateReqContextHandler;
begin
if MustCreateRequestContextHandler and
(FReqContextHandler = nil) then
FReqContextHandler := TCustomRequestContextHandler.Create(self);
end;
procedure TChromiumCore.CreateMediaObserver;
begin
if MustCreateMediaObserver and
(FMediaObserver = nil) then
FMediaObserver := TCustomMediaObserver.Create(self);
end;
procedure TChromiumCore.CreateDevToolsMsgObserver;
begin
if MustCreateDevToolsMessageObserver and
(FDevToolsMsgObserver = nil) then
FDevToolsMsgObserver := TCustomDevToolsMessageObserver.Create(self);
end;
procedure TChromiumCore.CreateResourceRequestHandler;
begin
if MustCreateResourceRequestHandler and
@ -5122,12 +5130,7 @@ begin
RemoveBrowser(browser);
if (BrowserCount = 0) then
begin
DestroyMediaObserver;
DestroyResourceRequestHandler;
DestroyReqContextHandler;
DestroyClientHandler;
end;
DestroyAllHandlersAndObservers;
if assigned(FOnBeforeClose) then
FOnBeforeClose(Self, browser);
@ -5511,11 +5514,12 @@ begin
FOnDevToolsMethodResult(self, browser, message_id, success, result);
end;
procedure TChromiumCore.doOnDevToolsEvent(const method : ustring;
const params : ICefValue);
procedure TChromiumCore.doOnDevToolsEvent(const browser : ICefBrowser;
const method : ustring;
const params : ICefValue);
begin
if assigned(FOnDevToolsEvent) then
FOnDevToolsEvent(self, method, params);
FOnDevToolsEvent(self, browser, method, params);
end;
procedure TChromiumCore.doOnDevToolsAgentAttached(const browser: ICefBrowser);

View File

@ -183,7 +183,7 @@ type
// ICefDevToolsMessageObserver
TOnDevToolsMessageEvent = procedure(Sender: TObject; const browser: ICefBrowser; const message_: ICefValue; var aHandled: boolean) of object;
TOnDevToolsMethodResultEvent = procedure(Sender: TObject; const browser: ICefBrowser; message_id: integer; success: boolean; const result: ICefValue) of object;
TOnDevToolsEventEvent = procedure(Sender: TObject; const method: ustring; const params: ICefValue) of object;
TOnDevToolsEventEvent = procedure(Sender: TObject; const browser: ICefBrowser; const method: ustring; const params: ICefValue) of object;
TOnDevToolsAgentAttachedEvent = procedure(Sender: TObject; const browser: ICefBrowser) of object;
TOnDevToolsAgentDetachedEvent = procedure(Sender: TObject; const browser: ICefBrowser) of object;

View File

@ -56,7 +56,7 @@ type
protected
procedure OnDevToolsMessage(const browser: ICefBrowser; const message_: ICefValue; var aHandled: boolean); virtual;
procedure OnDevToolsMethodResult(const browser: ICefBrowser; message_id: integer; success: boolean; const result: ICefValue); virtual;
procedure OnDevToolsEvent(const method: ustring; const params: ICefValue); virtual;
procedure OnDevToolsEvent(const browser: ICefBrowser; const method: ustring; const params: ICefValue); virtual;
procedure OnDevToolsAgentAttached(const browser: ICefBrowser); virtual;
procedure OnDevToolsAgentDetached(const browser: ICefBrowser); virtual;
@ -70,7 +70,7 @@ type
procedure OnDevToolsMessage(const browser: ICefBrowser; const message_: ICefValue; var aHandled: boolean); override;
procedure OnDevToolsMethodResult(const browser: ICefBrowser; message_id: integer; success: boolean; const result: ICefValue); override;
procedure OnDevToolsEvent(const method: ustring; const params: ICefValue); override;
procedure OnDevToolsEvent(const browser: ICefBrowser; const method: ustring; const params: ICefValue); override;
procedure OnDevToolsAgentAttached(const browser: ICefBrowser); override;
procedure OnDevToolsAgentDetached(const browser: ICefBrowser); override;
@ -144,6 +144,7 @@ begin
end;
procedure cef_on_dev_tools_event( self : PCefDevToolsMessageObserver;
browser : PCefBrowser;
const method : PCefString;
const params : Pointer;
params_size : NativeUInt); stdcall;
@ -156,7 +157,8 @@ begin
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
try
TempValue := CefParseJson(params, params_size);
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsEvent(CefString(method),
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsEvent(TCefBrowserRef.UnWrap(browser),
CefString(method),
TempValue);
finally
TempValue := nil;
@ -214,8 +216,9 @@ begin
//
end;
procedure TCEFDevToolsMessageObserverOwn.OnDevToolsEvent(const method : ustring;
const params : ICefValue);
procedure TCEFDevToolsMessageObserverOwn.OnDevToolsEvent(const browser : ICefBrowser;
const method : ustring;
const params : ICefValue);
begin
//
end;
@ -276,12 +279,13 @@ begin
end;
end;
procedure TCustomDevToolsMessageObserver.OnDevToolsEvent(const method : ustring;
const params : ICefValue);
procedure TCustomDevToolsMessageObserver.OnDevToolsEvent(const browser : ICefBrowser;
const method : ustring;
const params : ICefValue);
begin
try
if (FEvents <> nil) then
IChromiumEvents(FEvents).doOnDevToolsEvent(method, params);
IChromiumEvents(FEvents).doOnDevToolsEvent(browser, method, params);
except
on e : exception do
if CustomExceptionHandler('TCustomDevToolsMessageObserver.OnDevToolsEvent', e) then raise;

View File

@ -435,7 +435,7 @@ type
// ICefDevToolsMessageObserver
procedure doOnDevToolsMessage(const browser: ICefBrowser; const message_: ICefValue; var aHandled: boolean);
procedure doOnDevToolsMethodResult(const browser: ICefBrowser; message_id: integer; success: boolean; const result: ICefValue);
procedure doOnDevToolsEvent(const method: ustring; const params: ICefValue);
procedure doOnDevToolsEvent(const browser: ICefBrowser; const method: ustring; const params: ICefValue);
procedure doOnDevToolsAgentAttached(const browser: ICefBrowser);
procedure doOnDevToolsAgentDetached(const browser: ICefBrowser);
@ -1310,7 +1310,7 @@ type
['{76E5BB2B-7F69-4BC9-94C7-B55C61CE630F}']
procedure OnDevToolsMessage(const browser: ICefBrowser; const message_: ICefValue; var aHandled: boolean);
procedure OnDevToolsMethodResult(const browser: ICefBrowser; message_id: integer; success: boolean; const result: ICefValue);
procedure OnDevToolsEvent(const method: ustring; const params: ICefValue);
procedure OnDevToolsEvent(const browser: ICefBrowser; const method: ustring; const params: ICefValue);
procedure OnDevToolsAgentAttached(const browser: ICefBrowser);
procedure OnDevToolsAgentDetached(const browser: ICefBrowser);
end;

View File

@ -381,7 +381,7 @@ end;
function CefString(const str: PCefString): ustring;
begin
if (str <> nil) then
if (str <> nil) and (str^.str <> nil) and (str^.length > 0) and (str^.length < nativeuint(high(integer))) then
SetString(Result, str^.str, str^.length)
else
Result := '';

View File

@ -1601,7 +1601,7 @@ type
base : TCefBaseRefCounted;
on_dev_tools_message : function(self: PCefDevToolsMessageObserver; browser: PCefBrowser; const message_: Pointer; message_size: NativeUInt): Integer; stdcall;
on_dev_tools_method_result : procedure(self: PCefDevToolsMessageObserver; browser: PCefBrowser; message_id, success: Integer; const result: Pointer; result_size: NativeUInt); stdcall;
on_dev_tools_event : procedure(self: PCefDevToolsMessageObserver; const method: PCefString; const params: Pointer; params_size: NativeUInt); stdcall;
on_dev_tools_event : procedure(self: PCefDevToolsMessageObserver; browser: PCefBrowser; const method: PCefString; const params: Pointer; params_size: NativeUInt); stdcall;
on_dev_tools_agent_attached : procedure(self: PCefDevToolsMessageObserver; browser: PCefBrowser); stdcall;
on_dev_tools_agent_detached : procedure(self: PCefDevToolsMessageObserver; browser: PCefBrowser); stdcall;
end;

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 159,
"InternalVersion" : 160,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "83.4.2.0"
}