From eae6172ef37fe019797687f938382796e025692a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Wed, 4 Apr 2018 15:55:57 +0200 Subject: [PATCH] Added the TCefApplication.MustFreeLibrary property --- source/uCEFApplication.pas | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/source/uCEFApplication.pas b/source/uCEFApplication.pas index 8c3238df..f726e35e 100644 --- a/source/uCEFApplication.pas +++ b/source/uCEFApplication.pas @@ -136,6 +136,7 @@ type FProcessType : TCefProcessType; FShutdownWaitTime : cardinal; FWidevinePath : string; + FMustFreeLibrary : boolean; FMustCreateResourceBundleHandler : boolean; FMustCreateBrowserProcessHandler : boolean; @@ -224,6 +225,7 @@ type function Load_cef_trace_event_internal_h : boolean; procedure ShutDown; + procedure FreeLibcefLibrary; function ExecuteProcess(const aApp : ICefApp) : integer; procedure InitializeSettings(var aSettings : TCefSettings); function InitializeLibrary(const aApp : ICefApp) : boolean; @@ -342,6 +344,7 @@ type property MissingLibFiles : string read FMissingLibFiles; property ShutdownWaitTime : cardinal read FShutdownWaitTime write FShutdownWaitTime; property WidevinePath : string read FWidevinePath write FWidevinePath; + property MustFreeLibrary : boolean read FMustFreeLibrary write FMustFreeLibrary; property ChildProcessesCount : integer read GetChildProcessesCount; property OnRegCustomSchemes : TOnRegisterCustomSchemes read FOnRegisterCustomSchemes write FOnRegisterCustomSchemes; @@ -452,6 +455,7 @@ begin FProcessType := ParseProcessType; FShutdownWaitTime := 0; FWidevinePath := ''; + FMustFreeLibrary := True; FMustCreateResourceBundleHandler := False; FMustCreateBrowserProcessHandler := True; @@ -509,14 +513,7 @@ begin ShutDown; end; - if (FLibHandle <> 0) then - begin - FreeLibrary(FLibHandle); - FLibHandle := 0; - FLibLoaded := False; - end; - - FStatus := asUnloaded; + FreeLibcefLibrary; if (FCustomCommandLines <> nil) then FreeAndNil(FCustomCommandLines); if (FCustomCommandLineValues <> nil) then FreeAndNil(FCustomCommandLineValues); @@ -782,6 +779,22 @@ begin end; end; +procedure TCefApplication.FreeLibcefLibrary; +begin + try + try + if FMustFreeLibrary and (FLibHandle <> 0) then FreeLibrary(FLibHandle); + except + on e : exception do + if CustomExceptionHandler('TCefApplication.FreeLibcefLibrary', e) then raise; + end; + finally + FLibHandle := 0; + FLibLoaded := False; + FStatus := asUnloaded; + end; +end; + function TCefApplication.ExecuteProcess(const aApp : ICefApp) : integer; var TempArgs : TCefMainArgs; @@ -1306,6 +1319,15 @@ var begin Result := False; + if (FStatus <> asLoading) or FLibLoaded or (FLibHandle <> 0) then + begin + FStatus := asErrorLoadingLibrary; + TempString := 'GlobalCEFApp can only be initialized once per process.'; + + ShowErrorMessageDlg(TempString); + exit; + end; + if FSetCurrentDir then begin TempOldDir := GetCurrentDir;