From 9c9a9f59c7dad753ddb2b677f4c83ddc1cc9c73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Wed, 27 Dec 2017 14:05:33 +0100 Subject: [PATCH] Update to CEF 3.3239.1710.g85f637a Fixed an initialization bug in MDIBrowser, TabBrowser and ToolBoxBrowser Added several procedures to clear interface and class references before destruction --- .../JavaScript/JSDialog/uJSDialogBrowser.pas | 1 - demos/MDIBrowser/uMainForm.pas | 3 +- demos/TabbedBrowser/uMainForm.pas | 3 +- demos/ToolBoxBrowser/uMainForm.pas | 3 +- source/uBufferPanel.pas | 93 ++++++------- source/uCEFApplication.pas | 17 ++- source/uCEFBrowserProcessHandler.pas | 124 ++++++++++-------- source/uCEFChromium.pas | 78 +++++++++-- source/uCEFClient.pas | 23 +++- source/uCEFDeleteCookiesCallback.pas | 31 ++++- source/uCEFInterfaces.pas | 15 ++- source/uCEFPDFPrintCallback.pas | 32 ++++- source/uCEFRenderProcessHandler.pas | 11 +- source/uCEFResolveCallback.pas | 16 +++ source/uCEFResourceBundleHandler.pas | 10 +- source/uCEFStringVisitor.pas | 22 +++- 16 files changed, 352 insertions(+), 130 deletions(-) diff --git a/demos/JavaScript/JSDialog/uJSDialogBrowser.pas b/demos/JavaScript/JSDialog/uJSDialogBrowser.pas index 4173d250..28438701 100644 --- a/demos/JavaScript/JSDialog/uJSDialogBrowser.pas +++ b/demos/JavaScript/JSDialog/uJSDialogBrowser.pas @@ -183,7 +183,6 @@ procedure TJSDialogBrowserFrm.ChromiumBrowser_OnJsdialog(Sender : TObject; out Result : Boolean); begin // In this event we must store the dialog information and post a message to the main form to show the dialog - FJSDialogInfoCS.Acquire; if FPendingDlg then diff --git a/demos/MDIBrowser/uMainForm.pas b/demos/MDIBrowser/uMainForm.pas index de0e104e..16408d0c 100644 --- a/demos/MDIBrowser/uMainForm.pas +++ b/demos/MDIBrowser/uMainForm.pas @@ -106,7 +106,8 @@ uses procedure GlobalCEFApp_OnContextInitialized; begin - if (MainForm <> nil) then PostMessage(MainForm.Handle, CEFBROWSER_INITIALIZED, 0, 0); + if (MainForm <> nil) and MainForm.HandleAllocated then + PostMessage(MainForm.Handle, CEFBROWSER_INITIALIZED, 0, 0); end; procedure TMainForm.CreateMDIChild(const Name: string); diff --git a/demos/TabbedBrowser/uMainForm.pas b/demos/TabbedBrowser/uMainForm.pas index c33b5286..1361d9a0 100644 --- a/demos/TabbedBrowser/uMainForm.pas +++ b/demos/TabbedBrowser/uMainForm.pas @@ -135,7 +135,8 @@ implementation procedure GlobalCEFApp_OnContextInitialized; begin - if (MainForm <> nil) then PostMessage(MainForm.Handle, CEFBROWSER_INITIALIZED, 0, 0); + if (MainForm <> nil) and MainForm.HandleAllocated then + PostMessage(MainForm.Handle, CEFBROWSER_INITIALIZED, 0, 0); end; procedure TMainForm.AddTabBtnClick(Sender: TObject); diff --git a/demos/ToolBoxBrowser/uMainForm.pas b/demos/ToolBoxBrowser/uMainForm.pas index c50af557..b9b3c3f7 100644 --- a/demos/ToolBoxBrowser/uMainForm.pas +++ b/demos/ToolBoxBrowser/uMainForm.pas @@ -104,7 +104,8 @@ uses procedure GlobalCEFApp_OnContextInitialized; begin - if (MainForm <> nil) then PostMessage(MainForm.Handle, CEFBROWSER_INITIALIZED, 0, 0); + if (MainForm <> nil) and MainForm.HandleAllocated then + PostMessage(MainForm.Handle, CEFBROWSER_INITIALIZED, 0, 0); end; procedure TMainForm.CreateToolboxChild(const ChildCaption, URL: string); diff --git a/source/uBufferPanel.pas b/source/uBufferPanel.pas index 2d382f33..5332c013 100644 --- a/source/uBufferPanel.pas +++ b/source/uBufferPanel.pas @@ -57,15 +57,20 @@ type FBuffer : TBitmap; FScanlineSize : integer; + procedure CreateBufferMutex; + + procedure DestroyBufferMutex; + procedure DestroyBuffer; + function GetBufferBits : pointer; function GetBufferWidth : integer; function GetBufferHeight : integer; - function CopyBuffer(aDC : HDC; const aRect : TRect) : boolean; + function CopyBuffer : boolean; function SaveBufferToFile(const aFilename : string) : boolean; - procedure DestroyBuffer; - procedure WMPaint(var aMessage: TWMPaint); message WM_PAINT; + procedure Paint; override; + procedure WMEraseBkgnd(var aMessage : TWMEraseBkgnd); message WM_ERASEBKGND; public @@ -73,7 +78,7 @@ type destructor Destroy; override; procedure AfterConstruction; override; function SaveToFile(const aFilename : string) : boolean; - procedure InvalidatePanel; + function InvalidatePanel : boolean; function BeginBufferDraw : boolean; procedure EndBufferDraw; procedure BufferDraw(x, y : integer; const aBitmap : TBitmap); @@ -187,12 +192,7 @@ end; destructor TBufferPanel.Destroy; begin DestroyBuffer; - - if (FMutex <> 0) then - begin - CloseHandle(FMutex); - FMutex := 0; - end; + DestroyBufferMutex; inherited Destroy; end; @@ -201,9 +201,23 @@ procedure TBufferPanel.AfterConstruction; begin inherited AfterConstruction; + CreateBufferMutex; +end; + +procedure TBufferPanel.CreateBufferMutex; +begin FMutex := CreateMutex(nil, False, nil); end; +procedure TBufferPanel.DestroyBufferMutex; +begin + if (FMutex <> 0) then + begin + CloseHandle(FMutex); + FMutex := 0; + end; +end; + procedure TBufferPanel.DestroyBuffer; begin if BeginBufferDraw then @@ -231,18 +245,18 @@ end; function TBufferPanel.SaveToFile(const aFilename : string) : boolean; begin + Result := False; + if BeginBufferDraw then begin Result := SaveBufferToFile(aFilename); EndBufferDraw; - end - else - Result := False; + end; end; -procedure TBufferPanel.InvalidatePanel; +function TBufferPanel.InvalidatePanel : boolean; begin - PostMessage(Handle, CM_INVALIDATE, 0, 0); + Result := HandleAllocated and PostMessage(Handle, CM_INVALIDATE, 0, 0); end; function TBufferPanel.BeginBufferDraw : boolean; @@ -255,50 +269,39 @@ begin if (FMutex <> 0) then ReleaseMutex(FMutex); end; -function TBufferPanel.CopyBuffer(aDC : HDC; const aRect : TRect) : boolean; +function TBufferPanel.CopyBuffer : boolean; begin Result := False; if BeginBufferDraw then begin Result := (FBuffer <> nil) and - (aDC <> 0) and - BitBlt(aDC, aRect.Left, aRect.Top, aRect.Right - aRect.Left, aRect.Bottom - aRect.Top, - FBuffer.Canvas.Handle, aRect.Left, aRect.Top, + BitBlt(Canvas.Handle, 0, 0, Width, Height, + FBuffer.Canvas.Handle, 0, 0, SrcCopy); EndBufferDraw; end; end; -procedure TBufferPanel.WMPaint(var aMessage: TWMPaint); -var - TempPaintStruct : TPaintStruct; - TempDC : HDC; +procedure TBufferPanel.Paint; begin - try - TempDC := BeginPaint(Handle, TempPaintStruct); + if csDesigning in ComponentState then + begin + Canvas.Font.Assign(Font); + Canvas.Brush.Color := Color; + Canvas.Brush.Style := bsSolid; + Canvas.Pen.Style := psDash; - if csDesigning in ComponentState then + Canvas.Rectangle(0, 0, Width, Height); + end + else + if not(CopyBuffer) then begin - Canvas.Font.Assign(Font); Canvas.Brush.Color := Color; Canvas.Brush.Style := bsSolid; - Canvas.Pen.Style := psDash; - - Canvas.Rectangle(0, 0, Width, Height); - end - else - if not(CopyBuffer(TempDC, TempPaintStruct.rcPaint)) then - begin - Canvas.Brush.Color := Color; - Canvas.Brush.Style := bsSolid; - Canvas.FillRect(rect(0, 0, Width, Height)); - end; - finally - EndPaint(Handle, TempPaintStruct); - aMessage.Result := 1; - end; + Canvas.FillRect(rect(0, 0, Width, Height)); + end; end; procedure TBufferPanel.WMEraseBkgnd(var aMessage : TWMEraseBkgnd); @@ -337,6 +340,8 @@ end; function TBufferPanel.UpdateBufferDimensions(aWidth, aHeight : integer) : boolean; begin + Result := False; + if ((FBuffer = nil) or (FBuffer.Width <> aWidth) or (FBuffer.Height <> aHeight)) then @@ -350,9 +355,7 @@ begin FBuffer.Height := aHeight; FScanlineSize := FBuffer.Width * SizeOf(TRGBQuad); Result := True; - end - else - Result := False; + end; end; function TBufferPanel.BufferIsResized(aUseMutex : boolean) : boolean; diff --git a/source/uCEFApplication.pas b/source/uCEFApplication.pas index 8bea18a9..74f887ec 100644 --- a/source/uCEFApplication.pas +++ b/source/uCEFApplication.pas @@ -57,7 +57,7 @@ uses const CEF_SUPPORTED_VERSION_MAJOR = 3; CEF_SUPPORTED_VERSION_MINOR = 3239; - CEF_SUPPORTED_VERSION_RELEASE = 1709; + CEF_SUPPORTED_VERSION_RELEASE = 1710; CEF_SUPPORTED_VERSION_BUILD = 0; CEF_CHROMEELF_VERSION_MAJOR = 63; @@ -230,6 +230,7 @@ type function FindFlashDLL(var aFileName : string) : boolean; procedure ShowErrorMessageDlg(const aError : string); virtual; function ParseProcessType : TCefProcessType; + procedure RemoveAppReferences; procedure CreateAppHandlers; public @@ -496,6 +497,8 @@ destructor TCefApplication.Destroy; begin if FMustShutDown then ShutDown; + RemoveAppReferences; + if (FLibHandle <> 0) then begin FreeLibrary(FLibHandle); @@ -511,6 +514,18 @@ begin inherited Destroy; end; +procedure TCefApplication.RemoveAppReferences; +begin + try + if (FResourceBundleHandler <> nil) then FResourceBundleHandler.InitializeVars; + if (FBrowserProcessHandler <> nil) then FBrowserProcessHandler.InitializeVars; + if (FRenderProcessHandler <> nil) then FRenderProcessHandler.InitializeVars; + except + on e : exception do + if CustomExceptionHandler('TCefApplication.RemoveAppReferences', e) then raise; + end; +end; + procedure TCefApplication.AfterConstruction; begin inherited AfterConstruction; diff --git a/source/uCEFBrowserProcessHandler.pas b/source/uCEFBrowserProcessHandler.pas index a53099f3..c144047e 100644 --- a/source/uCEFBrowserProcessHandler.pas +++ b/source/uCEFBrowserProcessHandler.pas @@ -58,23 +58,26 @@ type function GetPrintHandler : ICefPrintHandler; virtual; procedure OnScheduleMessagePumpWork(const delayMs: Int64); virtual; abstract; + procedure InitializeVars; virtual; abstract; + public constructor Create; virtual; end; TCefCustomBrowserProcessHandler = class(TCefBrowserProcessHandlerOwn) - protected - FCefApp : TCefApplication; - - procedure OnContextInitialized; override; - procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); override; - procedure OnRenderProcessThreadCreated(const extraInfo: ICefListValue); override; - procedure OnScheduleMessagePumpWork(const delayMs: Int64); override; - - public - constructor Create(const aCefApp : TCefApplication); reintroduce; - destructor Destroy; override; - end; + protected + FCefApp : TCefApplication; + + procedure OnContextInitialized; override; + procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); override; + procedure OnRenderProcessThreadCreated(const extraInfo: ICefListValue); override; + procedure OnScheduleMessagePumpWork(const delayMs: Int64); override; + + public + constructor Create(const aCefApp : TCefApplication); reintroduce; + destructor Destroy; override; + procedure InitializeVars; override; + end; implementation @@ -85,8 +88,8 @@ procedure cef_browser_process_handler_on_context_initialized(self: PCefBrowserPr var TempObject : TObject; begin - TempObject := CefGetObject(self); - + TempObject := CefGetObject(self); + if (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then TCefBrowserProcessHandlerOwn(TempObject).OnContextInitialized; end; @@ -96,8 +99,8 @@ procedure cef_browser_process_handler_on_before_child_process_launch(self var TempObject : TObject; begin - TempObject := CefGetObject(self); - + TempObject := CefGetObject(self); + if (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then TCefBrowserProcessHandlerOwn(TempObject).OnBeforeChildProcessLaunch(TCefCommandLineRef.UnWrap(command_line)); end; @@ -107,8 +110,8 @@ procedure cef_browser_process_handler_on_render_process_thread_created(self var TempObject : TObject; begin - TempObject := CefGetObject(self); - + TempObject := CefGetObject(self); + if (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then TCefBrowserProcessHandlerOwn(TempObject).OnRenderProcessThreadCreated(TCefListValueRef.UnWrap(extra_info)); end; @@ -117,12 +120,12 @@ function cef_browser_process_handler_get_print_handler(self: PCefBrowserProcessH var TempObject : TObject; begin - TempObject := CefGetObject(self); - + TempObject := CefGetObject(self); + if (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then - Result := CefGetData(TCefBrowserProcessHandlerOwn(TempObject).GetPrintHandler) - else - Result := nil; + Result := CefGetData(TCefBrowserProcessHandlerOwn(TempObject).GetPrintHandler) + else + Result := nil; end; procedure cef_browser_process_handler_on_schedule_message_pump_work(self : PCefBrowserProcessHandler; @@ -130,8 +133,8 @@ procedure cef_browser_process_handler_on_schedule_message_pump_work(self : P var TempObject : TObject; begin - TempObject := CefGetObject(self); - + TempObject := CefGetObject(self); + if (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then TCefBrowserProcessHandlerOwn(TempObject).OnScheduleMessagePumpWork(delay_ms); end; @@ -152,45 +155,50 @@ end; function TCefBrowserProcessHandlerOwn.GetPrintHandler : ICefPrintHandler; begin - Result := nil; // only linux + Result := nil; // only linux end; // TCefCustomBrowserProcessHandler - - -constructor TCefCustomBrowserProcessHandler.Create(const aCefApp : TCefApplication); -begin - inherited Create; - - FCefApp := aCefApp; + + +constructor TCefCustomBrowserProcessHandler.Create(const aCefApp : TCefApplication); +begin + inherited Create; + + FCefApp := aCefApp; +end; + +destructor TCefCustomBrowserProcessHandler.Destroy; +begin + InitializeVars; + + inherited Destroy; end; - -destructor TCefCustomBrowserProcessHandler.Destroy; -begin - FCefApp := nil; - - inherited Destroy; + +procedure TCefCustomBrowserProcessHandler.InitializeVars; +begin + FCefApp := nil; end; - -procedure TCefCustomBrowserProcessHandler.OnContextInitialized; -begin - if (FCefApp <> nil) then FCefApp.Internal_OnContextInitialized; -end; - -procedure TCefCustomBrowserProcessHandler.OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnBeforeChildProcessLaunch(commandLine); -end; - -procedure TCefCustomBrowserProcessHandler.OnRenderProcessThreadCreated(const extraInfo: ICefListValue); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnRenderProcessThreadCreated(extraInfo); -end; - -procedure TCefCustomBrowserProcessHandler.OnScheduleMessagePumpWork(const delayMs: Int64); -begin - if (FCefApp <> nil) then FCefApp.Internal_OnScheduleMessagePumpWork(delayMs); + +procedure TCefCustomBrowserProcessHandler.OnContextInitialized; +begin + if (FCefApp <> nil) then FCefApp.Internal_OnContextInitialized; +end; + +procedure TCefCustomBrowserProcessHandler.OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnBeforeChildProcessLaunch(commandLine); +end; + +procedure TCefCustomBrowserProcessHandler.OnRenderProcessThreadCreated(const extraInfo: ICefListValue); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnRenderProcessThreadCreated(extraInfo); +end; + +procedure TCefCustomBrowserProcessHandler.OnScheduleMessagePumpWork(const delayMs: Int64); +begin + if (FCefApp <> nil) then FCefApp.Internal_OnScheduleMessagePumpWork(delayMs); end; end. diff --git a/source/uCEFChromium.pas b/source/uCEFChromium.pas index 35652be9..ab6cc070 100644 --- a/source/uCEFChromium.pas +++ b/source/uCEFChromium.pas @@ -261,6 +261,14 @@ type function CreateBrowserHost(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): Boolean; function CreateBrowserHostSync(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): ICefBrowser; + procedure DestroyClientHandler; + procedure DestroyVisitor; + procedure DestroyPDFPrintcb; + procedure DestroyResolveHostcb; + procedure DestroyCookiDeletercb; + + procedure ClearBrowserReference; + procedure InitializeEvents; procedure InitializeSettings(var aSettings : TCefBrowserSettings); @@ -758,13 +766,13 @@ begin FCompHandle := 0; end; - FBrowser := nil; - FBrowserId := 0; - FHandler := nil; - FVisitor := nil; - FPDFPrintcb := nil; - FResolveHostcb := nil; - FCookiDeletercb := nil; + ClearBrowserReference; + + DestroyClientHandler; + DestroyVisitor; + DestroyPDFPrintcb; + DestroyResolveHostcb; + DestroyCookiDeletercb; if (FFontOptions <> nil) then FreeAndNil(FFontOptions); if (FOptions <> nil) then FreeAndNil(FOptions); @@ -778,6 +786,57 @@ begin end; end; +procedure TChromium.ClearBrowserReference; +begin + FBrowser := nil; + FBrowserId := 0; +end; + +procedure TChromium.DestroyClientHandler; +begin + if (FHandler <> nil) then + begin + FHandler.InitializeVars; + FHandler := nil; + end; +end; + +procedure TChromium.DestroyVisitor; +begin + if (FVisitor <> nil) then + begin + FVisitor.InitializeVars; + FVisitor := nil; + end; +end; + +procedure TChromium.DestroyPDFPrintcb; +begin + if (FPDFPrintcb <> nil) then + begin + FPDFPrintcb.InitializeVars; + FPDFPrintcb := nil; + end; +end; + +procedure TChromium.DestroyResolveHostcb; +begin + if (FResolveHostcb <> nil) then + begin + FResolveHostcb.InitializeVars; + FResolveHostcb := nil; + end; +end; + +procedure TChromium.DestroyCookiDeletercb; +begin + if (FCookiDeletercb <> nil) then + begin + FCookiDeletercb.InitializeVars; + FCookiDeletercb := nil; + end; +end; + procedure TChromium.AfterConstruction; begin inherited AfterConstruction; @@ -2770,9 +2829,8 @@ begin if (browser <> nil) and (FBrowserId = browser.Identifier) then begin FInitialized := False; - FBrowser := nil; - FBrowserId := 0; - FHandler := nil; + ClearBrowserReference; + DestroyClientHandler; end; if Assigned(FOnBeforeClose) then FOnBeforeClose(Self, browser); diff --git a/source/uCEFClient.pas b/source/uCEFClient.pas index 2c67d876..9db92658 100644 --- a/source/uCEFClient.pas +++ b/source/uCEFClient.pas @@ -73,6 +73,8 @@ type function GetRequestHandler: ICefRequestHandler; virtual; function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; virtual; + procedure InitializeVars; virtual; + public class function UnWrap(data: Pointer): ICefClient; end; @@ -95,6 +97,8 @@ type function GetRequestHandler: ICefRequestHandler; virtual; function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; virtual; + procedure InitializeVars; virtual; + public constructor Create; virtual; end; @@ -133,8 +137,6 @@ type function GetRequestHandler: ICefRequestHandler; override; function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; override; - procedure InitializeInterfaces; - public constructor Create(const events: IChromiumEvents; aCreateLoadHandler, aCreateFocusHandler, aCreateContextMenuHandler, aCreateDialogHandler, @@ -142,6 +144,7 @@ type aCreateJsDialogHandler, aCreateLifeSpanHandler, aCreateRenderHandler, aCreateRequestHandler, aCreateDragHandler, aCreateFindHandler : boolean); reintroduce; virtual; destructor Destroy; override; + procedure InitializeVars; override; end; implementation @@ -246,6 +249,11 @@ begin Result := False; end; +procedure TCefClientRef.InitializeVars; +begin + // +end; + // ****************************************************** // ****************** TCefClientOwn ********************* @@ -442,6 +450,11 @@ begin Result := False; end; +procedure TCefClientOwn.InitializeVars; +begin + // +end; + // ****************************************************** // *************** TCustomClientHandler ***************** @@ -466,7 +479,7 @@ constructor TCustomClientHandler.Create(const events : IChro begin inherited Create; - InitializeInterfaces; + InitializeVars; FEvents := events; @@ -491,12 +504,12 @@ end; destructor TCustomClientHandler.Destroy; begin - InitializeInterfaces; + InitializeVars; inherited Destroy; end; -procedure TCustomClientHandler.InitializeInterfaces; +procedure TCustomClientHandler.InitializeVars; begin FLoadHandler := nil; FFocusHandler := nil; diff --git a/source/uCEFDeleteCookiesCallback.pas b/source/uCEFDeleteCookiesCallback.pas index ac990fcc..cb3c41e3 100644 --- a/source/uCEFDeleteCookiesCallback.pas +++ b/source/uCEFDeleteCookiesCallback.pas @@ -53,6 +53,7 @@ type TCefDeleteCookiesCallbackOwn = class(TCefBaseRefCountedOwn, ICefDeleteCookiesCallback) protected procedure OnComplete(numDeleted: Integer); virtual; abstract; + procedure InitializeVars; virtual; abstract; public constructor Create; virtual; @@ -66,6 +67,8 @@ type public constructor Create(const callback: TCefDeleteCookiesCallbackProc); reintroduce; + destructor Destroy; override; + procedure InitializeVars; override; end; TCefCustomDeleteCookiesCallback = class(TCefDeleteCookiesCallbackOwn) @@ -76,6 +79,8 @@ type public constructor Create(const aChromiumBrowser : TObject); reintroduce; + destructor Destroy; override; + procedure InitializeVars; override; end; implementation @@ -108,7 +113,19 @@ end; procedure TCefFastDeleteCookiesCallback.OnComplete(numDeleted: Integer); begin - FCallback(numDeleted) + if assigned(FCallback) then FCallback(numDeleted) +end; + +destructor TCefFastDeleteCookiesCallback.Destroy; +begin + InitializeVars; + + inherited Destroy; +end; + +procedure TCefFastDeleteCookiesCallback.InitializeVars; +begin + FCallback := nil; end; // TCefCustomDeleteCookiesCallback @@ -120,6 +137,18 @@ begin FChromiumBrowser := aChromiumBrowser; end; +destructor TCefCustomDeleteCookiesCallback.Destroy; +begin + InitializeVars; + + inherited Destroy; +end; + +procedure TCefCustomDeleteCookiesCallback.InitializeVars; +begin + FChromiumBrowser := nil; +end; + procedure TCefCustomDeleteCookiesCallback.OnComplete(numDeleted: Integer); begin if (FChromiumBrowser <> nil) and (FChromiumBrowser is TChromium) then diff --git a/source/uCEFInterfaces.pas b/source/uCEFInterfaces.pas index ba16b446..3163aaa3 100644 --- a/source/uCEFInterfaces.pas +++ b/source/uCEFInterfaces.pas @@ -166,6 +166,7 @@ type ICefPdfPrintCallback = interface(ICefBaseRefCounted) ['{F1CC58E9-2C30-4932-91AE-467C8D8EFB8E}'] procedure OnPdfPrintFinished(const path: ustring; ok: Boolean); + procedure InitializeVars; // custom procedure to clear all references end; TOnDownloadImageFinishedProc = {$IFDEF DELPHI12_UP}reference to{$ENDIF} @@ -383,6 +384,7 @@ type ICefStringVisitor = interface(ICefBaseRefCounted) ['{63ED4D6C-2FC8-4537-964B-B84C008F6158}'] procedure Visit(const str: ustring); + procedure InitializeVars; // custom procedure to clear all references end; ICefFrame = interface(ICefBaseRefCounted) @@ -859,6 +861,8 @@ type function GetLocalizedString(stringId: Integer; var stringVal: ustring): Boolean; function GetDataResource(resourceId: Integer; var data: Pointer; var dataSize: NativeUInt): Boolean; function GetDataResourceForScale(resourceId: Integer; scaleFactor: TCefScaleFactor; var data: Pointer; var dataSize: NativeUInt): Boolean; + + procedure InitializeVars; // custom procedure to clear all references end; ICefBrowserProcessHandler = interface(ICefBaseRefCounted) @@ -868,6 +872,8 @@ type procedure OnRenderProcessThreadCreated(const extraInfo: ICefListValue); function GetPrintHandler : ICefPrintHandler; procedure OnScheduleMessagePumpWork(const delayMs: Int64); + + procedure InitializeVars; // custom procedure to clear all references end; ICefRenderProcessHandler = interface(ICefBaseRefCounted) @@ -883,6 +889,8 @@ type procedure OnUncaughtException(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context; const exception: ICefV8Exception; const stackTrace: ICefV8StackTrace); procedure OnFocusedNodeChanged(const browser: ICefBrowser; const frame: ICefFrame; const node: ICefDomNode); function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const aMessage: ICefProcessMessage): Boolean; + + procedure InitializeVars; // custom procedure to clear all references end; ICefApp = interface(ICefBaseRefCounted) @@ -912,6 +920,7 @@ type ICefDeleteCookiesCallback = interface(ICefBaseRefCounted) ['{758B79A1-B9E8-4F0D-94A0-DCE5AFADE33D}'] procedure OnComplete(numDeleted: Integer); + procedure InitializeVars; // custom procedure to clear all references end; ICefCookieManager = Interface(ICefBaseRefCounted) @@ -1377,8 +1386,9 @@ type function GetLoadHandler: ICefLoadHandler; function GetRenderHandler: ICefRenderHandler; function GetRequestHandler: ICefRequestHandler; - function OnProcessMessageReceived(const browser: ICefBrowser; - sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; + function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; + + procedure InitializeVars; // custom procedure to clear all references end; ICefUrlRequest = interface(ICefBaseRefCounted) @@ -1482,6 +1492,7 @@ type ICefResolveCallback = interface(ICefBaseRefCounted) ['{0C0EA252-7968-4163-A1BE-A1453576DD06}'] procedure OnResolveCompleted(result: TCefErrorCode; const resolvedIps: TStrings); + procedure InitializeVars; // custom procedure to clear all references end; ICefRequestContext = interface(ICefBaseRefCounted) diff --git a/source/uCEFPDFPrintCallback.pas b/source/uCEFPDFPrintCallback.pas index c000a132..fea6e9f5 100644 --- a/source/uCEFPDFPrintCallback.pas +++ b/source/uCEFPDFPrintCallback.pas @@ -54,6 +54,8 @@ type protected procedure OnPdfPrintFinished(const path: ustring; ok: Boolean); virtual; abstract; + procedure InitializeVars; virtual; abstract; + public constructor Create; virtual; end; @@ -66,6 +68,8 @@ type public constructor Create(const proc: TOnPdfPrintFinishedProc); reintroduce; + destructor Destroy; override; + procedure InitializeVars; override; end; TCefCustomPDFPrintCallBack = class(TCefPdfPrintCallbackOwn) @@ -76,6 +80,8 @@ type public constructor Create(const aChromiumBrowser : TObject); reintroduce; + destructor Destroy; override; + procedure InitializeVars; override; end; implementation @@ -105,7 +111,19 @@ end; procedure TCefFastPdfPrintCallback.OnPdfPrintFinished(const path: ustring; ok: Boolean); begin - FProc(path, ok); + if assigned(FProc) then FProc(path, ok); +end; + +destructor TCefFastPdfPrintCallback.Destroy; +begin + InitializeVars; + + inherited Destroy; +end; + +procedure TCefFastPdfPrintCallback.InitializeVars; +begin + FProc := nil; end; // TCefCustomPDFPrintCallBack @@ -117,6 +135,18 @@ begin FChromiumBrowser := aChromiumBrowser; end; +destructor TCefCustomPDFPrintCallBack.Destroy; +begin + InitializeVars; + + inherited Destroy; +end; + +procedure TCefCustomPDFPrintCallBack.InitializeVars; +begin + FChromiumBrowser := nil; +end; + procedure TCefCustomPDFPrintCallBack.OnPdfPrintFinished(const path: ustring; aResultOK : Boolean); begin if (FChromiumBrowser <> nil) and (FChromiumBrowser is TChromium) then diff --git a/source/uCEFRenderProcessHandler.pas b/source/uCEFRenderProcessHandler.pas index b8323c7f..41768f92 100644 --- a/source/uCEFRenderProcessHandler.pas +++ b/source/uCEFRenderProcessHandler.pas @@ -69,6 +69,9 @@ type procedure OnUncaughtException(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context; const exception: ICefV8Exception; const stackTrace: ICefV8StackTrace); virtual; abstract; procedure OnFocusedNodeChanged(const browser: ICefBrowser; const frame: ICefFrame; const node: ICefDomNode); virtual; abstract; function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const aMessage: ICefProcessMessage): Boolean; virtual; + + procedure InitializeVars; virtual; abstract; + public constructor Create; virtual; end; @@ -91,6 +94,7 @@ type public constructor Create(const aCefApp : TCefApplication); reintroduce; destructor Destroy; override; + procedure InitializeVars; override; end; implementation @@ -313,11 +317,16 @@ end; destructor TCefCustomRenderProcessHandler.Destroy; begin - FCefApp := nil; + InitializeVars; inherited Destroy; end; +procedure TCefCustomRenderProcessHandler.InitializeVars; +begin + FCefApp := nil; +end; + procedure TCefCustomRenderProcessHandler.OnRenderThreadCreated(const extraInfo: ICefListValue); begin if (FCefApp <> nil) then FCefApp.Internal_OnRenderThreadCreated(extraInfo); diff --git a/source/uCEFResolveCallback.pas b/source/uCEFResolveCallback.pas index 2dceb12d..49eaf215 100644 --- a/source/uCEFResolveCallback.pas +++ b/source/uCEFResolveCallback.pas @@ -58,6 +58,8 @@ type TCefResolveCallbackOwn = class(TCefBaseRefCountedOwn, ICefResolveCallback) protected procedure OnResolveCompleted(result: TCefErrorCode; const resolvedIps: TStrings); virtual; abstract; + procedure InitializeVars; virtual; abstract; + public constructor Create; virtual; end; @@ -69,6 +71,8 @@ type public constructor Create(const aChromiumBrowser : TObject); reintroduce; + destructor Destroy; override; + procedure InitializeVars; override; end; implementation @@ -129,6 +133,18 @@ begin FChromiumBrowser := aChromiumBrowser; end; +destructor TCefCustomResolveCallback.Destroy; +begin + InitializeVars; + + inherited Destroy; +end; + +procedure TCefCustomResolveCallback.InitializeVars; +begin + FChromiumBrowser := nil; +end; + procedure TCefCustomResolveCallback.OnResolveCompleted(result: TCefErrorCode; const resolvedIps: TStrings); begin if (FChromiumBrowser <> nil) and (FChromiumBrowser is TChromium) then diff --git a/source/uCEFResourceBundleHandler.pas b/source/uCEFResourceBundleHandler.pas index e2659f2a..7e41060a 100644 --- a/source/uCEFResourceBundleHandler.pas +++ b/source/uCEFResourceBundleHandler.pas @@ -56,6 +56,8 @@ type function GetDataResource(resourceId: Integer; var data: Pointer; var dataSize: NativeUInt): Boolean; virtual; abstract; function GetDataResourceForScale(resourceId: Integer; scaleFactor: TCefScaleFactor; var data: Pointer; var dataSize: NativeUInt): Boolean; virtual; abstract; + procedure InitializeVars; virtual; abstract; + public constructor Create; virtual; end; @@ -71,6 +73,7 @@ type public constructor Create(const aCefApp : TCefApplication); reintroduce; destructor Destroy; override; + procedure InitializeVars; override; end; implementation @@ -154,11 +157,16 @@ end; destructor TCefCustomResourceBundleHandler.Destroy; begin - FCefApp := nil; + InitializeVars; inherited Destroy; end; +procedure TCefCustomResourceBundleHandler.InitializeVars; +begin + FCefApp := nil; +end; + function TCefCustomResourceBundleHandler.GetLocalizedString(stringid : Integer; var stringVal : ustring): Boolean; begin diff --git a/source/uCEFStringVisitor.pas b/source/uCEFStringVisitor.pas index c221027c..397ec772 100644 --- a/source/uCEFStringVisitor.pas +++ b/source/uCEFStringVisitor.pas @@ -53,12 +53,13 @@ type TCefStringVisitorOwn = class(TCefBaseRefCountedOwn, ICefStringVisitor) protected procedure Visit(const str: ustring); virtual; + procedure InitializeVars; virtual; public constructor Create; virtual; end; - TCefFastStringVisitor = class(TCefStringVisitorOwn, ICefStringVisitor) + TCefFastStringVisitor = class(TCefStringVisitorOwn) protected FVisit: TCefStringVisitorProc; @@ -76,6 +77,8 @@ type public constructor Create(const aChromiumBrowser : TObject); reintroduce; + destructor Destroy; override; + procedure InitializeVars; override; end; implementation @@ -102,6 +105,11 @@ begin // end; +procedure TCefStringVisitorOwn.InitializeVars; +begin + // +end; + // TCefFastStringVisitor constructor TCefFastStringVisitor.Create(const callback: TCefStringVisitorProc); @@ -125,6 +133,18 @@ begin FChromiumBrowser := aChromiumBrowser; end; +destructor TCustomCefStringVisitor.Destroy; +begin + InitializeVars; + + inherited Destroy; +end; + +procedure TCustomCefStringVisitor.InitializeVars; +begin + FChromiumBrowser := nil; +end; + procedure TCustomCefStringVisitor.Visit(const str: ustring); begin if (FChromiumBrowser <> nil) and (FChromiumBrowser is TChromium) then