mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-06-02 21:57:37 +02:00
Added two optional properties to GlobalCEFApp to wait for the child processes before shutting down.
Added GlobalCEFApp.WaitForChildProcesses and GlobalCEFApp.WaitTime.
This commit is contained in:
parent
63748c2639
commit
28bf09272d
Binary file not shown.
@ -72,6 +72,8 @@ type
|
|||||||
TCefApplication = class
|
TCefApplication = class
|
||||||
protected
|
protected
|
||||||
FMustShutDown : boolean;
|
FMustShutDown : boolean;
|
||||||
|
FWaitForChildProcesses : boolean;
|
||||||
|
FWaitTime : cardinal;
|
||||||
FCache : ustring;
|
FCache : ustring;
|
||||||
FCookies : ustring;
|
FCookies : ustring;
|
||||||
FUserDataPath : ustring;
|
FUserDataPath : ustring;
|
||||||
@ -162,6 +164,10 @@ type
|
|||||||
FOnFocusedNodeChanged : TOnFocusedNodeChangedEvent;
|
FOnFocusedNodeChanged : TOnFocusedNodeChangedEvent;
|
||||||
FOnProcessMessageReceived : TOnProcessMessageReceivedEvent;
|
FOnProcessMessageReceived : TOnProcessMessageReceivedEvent;
|
||||||
|
|
||||||
|
procedure DestroyResourceBundleHandler;
|
||||||
|
procedure DestroyBrowserProcessHandler;
|
||||||
|
procedure DestroyRenderProcessHandler;
|
||||||
|
|
||||||
procedure SetFrameworkDirPath(const aValue : ustring);
|
procedure SetFrameworkDirPath(const aValue : ustring);
|
||||||
procedure SetResourcesDirPath(const aValue : ustring);
|
procedure SetResourcesDirPath(const aValue : ustring);
|
||||||
procedure SetLocalesDirPath(const aValue : ustring);
|
procedure SetLocalesDirPath(const aValue : ustring);
|
||||||
@ -232,13 +238,14 @@ type
|
|||||||
function FindFlashDLL(var aFileName : string) : boolean;
|
function FindFlashDLL(var aFileName : string) : boolean;
|
||||||
procedure ShowErrorMessageDlg(const aError : string); virtual;
|
procedure ShowErrorMessageDlg(const aError : string); virtual;
|
||||||
function ParseProcessType : TCefProcessType;
|
function ParseProcessType : TCefProcessType;
|
||||||
procedure RemoveAppReferences;
|
|
||||||
procedure CreateAppHandlers;
|
procedure CreateAppHandlers;
|
||||||
|
procedure EnumerateAndWaitForChildProcesses;
|
||||||
|
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure AfterConstruction; override;
|
procedure AfterConstruction; override;
|
||||||
|
procedure BeforeDestruction; override;
|
||||||
procedure AddCustomCommandLine(const aCommandLine : string; const aValue : string = '');
|
procedure AddCustomCommandLine(const aCommandLine : string; const aValue : string = '');
|
||||||
function StartMainProcess : boolean;
|
function StartMainProcess : boolean;
|
||||||
function StartSubProcess : boolean;
|
function StartSubProcess : boolean;
|
||||||
@ -348,6 +355,8 @@ type
|
|||||||
property OsmodalLoop : boolean write SetOsmodalLoop;
|
property OsmodalLoop : boolean write SetOsmodalLoop;
|
||||||
property Status : TCefAplicationStatus read FStatus;
|
property Status : TCefAplicationStatus read FStatus;
|
||||||
property MissingLibFiles : string read FMissingLibFiles;
|
property MissingLibFiles : string read FMissingLibFiles;
|
||||||
|
property WaitForChildProcesses : boolean read FWaitForChildProcesses write FWaitForChildProcesses;
|
||||||
|
property WaitTime : cardinal read FWaitTime write FWaitTime;
|
||||||
|
|
||||||
property OnRegCustomSchemes : TOnRegisterCustomSchemes read FOnRegisterCustomSchemes write FOnRegisterCustomSchemes;
|
property OnRegCustomSchemes : TOnRegisterCustomSchemes read FOnRegisterCustomSchemes write FOnRegisterCustomSchemes;
|
||||||
|
|
||||||
@ -382,9 +391,9 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
{$IFDEF DELPHI16_UP}
|
{$IFDEF DELPHI16_UP}
|
||||||
System.Math, System.IOUtils, System.SysUtils,
|
System.Math, System.IOUtils, System.SysUtils, {$IFDEF MSWINDOWS}WinApi.TlHelp32,{$ENDIF}
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Math, {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} SysUtils,
|
Math, {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} SysUtils, {$IFDEF MSWINDOWS}TlHelp32,{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
uCEFLibFunctions, uCEFMiscFunctions, uCEFCommandLine, uCEFConstants,
|
uCEFLibFunctions, uCEFMiscFunctions, uCEFCommandLine, uCEFConstants,
|
||||||
uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp,
|
uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp,
|
||||||
@ -398,6 +407,8 @@ begin
|
|||||||
FMissingLibFiles := '';
|
FMissingLibFiles := '';
|
||||||
FLibHandle := 0;
|
FLibHandle := 0;
|
||||||
FMustShutDown := False;
|
FMustShutDown := False;
|
||||||
|
FWaitForChildProcesses := True;
|
||||||
|
FWaitTime := 5000;
|
||||||
FCache := '';
|
FCache := '';
|
||||||
FCookies := '';
|
FCookies := '';
|
||||||
FUserDataPath := '';
|
FUserDataPath := '';
|
||||||
@ -501,9 +512,11 @@ end;
|
|||||||
|
|
||||||
destructor TCefApplication.Destroy;
|
destructor TCefApplication.Destroy;
|
||||||
begin
|
begin
|
||||||
if FMustShutDown then ShutDown;
|
if FMustShutDown then
|
||||||
|
begin
|
||||||
RemoveAppReferences;
|
if FWaitForChildProcesses then EnumerateAndWaitForChildProcesses;
|
||||||
|
ShutDown;
|
||||||
|
end;
|
||||||
|
|
||||||
if (FLibHandle <> 0) then
|
if (FLibHandle <> 0) then
|
||||||
begin
|
begin
|
||||||
@ -520,18 +533,6 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCefApplication.RemoveAppReferences;
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
if (FResourceBundleHandler <> nil) then FResourceBundleHandler.RemoveReferences;
|
|
||||||
if (FBrowserProcessHandler <> nil) then FBrowserProcessHandler.RemoveReferences;
|
|
||||||
if (FRenderProcessHandler <> nil) then FRenderProcessHandler.RemoveReferences;
|
|
||||||
except
|
|
||||||
on e : exception do
|
|
||||||
if CustomExceptionHandler('TCefApplication.RemoveAppReferences', e) then raise;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCefApplication.AfterConstruction;
|
procedure TCefApplication.AfterConstruction;
|
||||||
begin
|
begin
|
||||||
inherited AfterConstruction;
|
inherited AfterConstruction;
|
||||||
@ -540,6 +541,57 @@ begin
|
|||||||
FCustomCommandLineValues := TStringList.Create;
|
FCustomCommandLineValues := TStringList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCefApplication.BeforeDestruction;
|
||||||
|
begin
|
||||||
|
DestroyResourceBundleHandler;
|
||||||
|
DestroyBrowserProcessHandler;
|
||||||
|
DestroyRenderProcessHandler;
|
||||||
|
|
||||||
|
inherited BeforeDestruction;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCefApplication.DestroyResourceBundleHandler;
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
if (FResourceBundleHandler <> nil) then
|
||||||
|
begin
|
||||||
|
FResourceBundleHandler.RemoveReferences;
|
||||||
|
FResourceBundleHandler := nil;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
if CustomExceptionHandler('TCefApplication.DestroyResourceBundleHandler', e) then raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCefApplication.DestroyBrowserProcessHandler;
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
if (FBrowserProcessHandler <> nil) then
|
||||||
|
begin
|
||||||
|
FBrowserProcessHandler.RemoveReferences;
|
||||||
|
FBrowserProcessHandler := nil;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
if CustomExceptionHandler('TCefApplication.DestroyBrowserProcessHandler', e) then raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCefApplication.DestroyRenderProcessHandler;
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
if (FRenderProcessHandler <> nil) then
|
||||||
|
begin
|
||||||
|
FRenderProcessHandler.RemoveReferences;
|
||||||
|
FRenderProcessHandler := nil;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
if CustomExceptionHandler('TCefApplication.DestroyRenderProcessHandler', e) then raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCefApplication.AddCustomCommandLine(const aCommandLine, aValue : string);
|
procedure TCefApplication.AddCustomCommandLine(const aCommandLine, aValue : string);
|
||||||
begin
|
begin
|
||||||
if (FCustomCommandLines <> nil) then FCustomCommandLines.Add(aCommandLine);
|
if (FCustomCommandLines <> nil) then FCustomCommandLines.Add(aCommandLine);
|
||||||
@ -1015,6 +1067,52 @@ begin
|
|||||||
FRenderProcessHandler := TCefCustomRenderProcessHandler.Create(self);
|
FRenderProcessHandler := TCefCustomRenderProcessHandler.Create(self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCefApplication.EnumerateAndWaitForChildProcesses;
|
||||||
|
{$IFDEF MSWINDOWS}
|
||||||
|
var
|
||||||
|
TempHandle : THandle;
|
||||||
|
TempProcess : TProcessEntry32;
|
||||||
|
TempArray : array [0 .. pred(MAXIMUM_WAIT_OBJECTS)] of THandle;
|
||||||
|
TempPID : DWORD;
|
||||||
|
i : integer;
|
||||||
|
TempMain, TempSubProc, TempName : string;
|
||||||
|
{$ENDIF}
|
||||||
|
begin
|
||||||
|
{$IFDEF MSWINDOWS}
|
||||||
|
for i := 0 to pred(MAXIMUM_WAIT_OBJECTS) do TempArray[i] := 0;
|
||||||
|
|
||||||
|
TempHandle := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
|
||||||
|
TempProcess.dwSize := Sizeof(TProcessEntry32);
|
||||||
|
TempPID := GetCurrentProcessID;
|
||||||
|
TempMain := ExtractFileName(paramstr(0));
|
||||||
|
TempSubProc := ExtractFileName(FBrowserSubprocessPath);
|
||||||
|
|
||||||
|
Process32First(TempHandle, TempProcess);
|
||||||
|
|
||||||
|
i := 0;
|
||||||
|
repeat
|
||||||
|
if (TempProcess.th32ProcessID <> TempPID) and
|
||||||
|
(TempProcess.th32ParentProcessID = TempPID) then
|
||||||
|
begin
|
||||||
|
TempName := TempProcess.szExeFile;
|
||||||
|
TempName := ExtractFileName(TempName);
|
||||||
|
|
||||||
|
if (CompareText(TempName, TempMain) = 0) or
|
||||||
|
((length(TempSubProc) > 0) and (CompareText(TempName, TempSubProc) = 0)) then
|
||||||
|
begin
|
||||||
|
TempArray[i] := TempProcess.th32ProcessID;
|
||||||
|
inc(i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
until not(Process32Next(TempHandle, TempProcess)) or (i = MAXIMUM_WAIT_OBJECTS);
|
||||||
|
|
||||||
|
CloseHandle(TempHandle);
|
||||||
|
|
||||||
|
if (i > 0) then
|
||||||
|
WaitForMultipleObjects(i, @TempArray, True, FWaitTime);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCefApplication.Internal_OnContextInitialized;
|
procedure TCefApplication.Internal_OnContextInitialized;
|
||||||
begin
|
begin
|
||||||
InitializeCookies;
|
InitializeCookies;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user