mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-02-02 10:25:26 +02:00
Moved cookie path initialization to a thread
- Moved cookie path initialization to a thread. That thread uses a waitableevent and a callback to wait until the cookiemanager is initialized before setting the storage path. - Added TCefEventCompletionCallback - Changed TCefWaitableEventRef.New parameters to boolean
This commit is contained in:
parent
43bcdf725f
commit
90b870fc78
@ -249,7 +249,6 @@ type
|
||||
function ExecuteProcess(const aApp : ICefApp) : integer;
|
||||
procedure InitializeSettings(var aSettings : TCefSettings);
|
||||
function InitializeLibrary(const aApp : ICefApp) : boolean;
|
||||
function InitializeCookies : boolean;
|
||||
function MultiExeProcessing : boolean;
|
||||
function SingleExeProcessing : boolean;
|
||||
function CheckCEFLibrary : boolean;
|
||||
@ -395,6 +394,17 @@ type
|
||||
property OnCDMRegistrationComplete : TOnCDMRegistrationCompleteEvent read FOnCDMRegistrationComplete write FOnCDMRegistrationComplete;
|
||||
end;
|
||||
|
||||
TCEFCookieInitializerThread = class(TThread)
|
||||
protected
|
||||
FCookies : string;
|
||||
FPersistSessionCookies : boolean;
|
||||
|
||||
procedure Execute; override;
|
||||
|
||||
public
|
||||
constructor Create(const aCookies : string; aPersistSessionCookies : boolean);
|
||||
end;
|
||||
|
||||
var
|
||||
GlobalCEFApp : TCefApplication = nil;
|
||||
|
||||
@ -414,7 +424,8 @@ uses
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
uCEFLibFunctions, uCEFMiscFunctions, uCEFCommandLine, uCEFConstants,
|
||||
uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp, uCEFRegisterCDMCallback;
|
||||
uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp, uCEFRegisterCDMCallback,
|
||||
uCEFCompletionCallback, uCEFWaitableEvent;
|
||||
|
||||
procedure DestroyGlobalCEFApp;
|
||||
begin
|
||||
@ -1006,31 +1017,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCefApplication.InitializeCookies : boolean;
|
||||
var
|
||||
TempCookieManager : ICefCookieManager;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
try
|
||||
if (length(FCookies) > 0) then
|
||||
begin
|
||||
TempCookieManager := TCefCookieManagerRef.Global(nil);
|
||||
|
||||
if (TempCookieManager <> nil) and
|
||||
TempCookieManager.SetStoragePath(FCookies, FPersistSessionCookies, nil) then
|
||||
Result := True
|
||||
else
|
||||
OutputDebugMessage('TCefApplication.InitializeCookies error : cookies cannot be accessed');
|
||||
end
|
||||
else
|
||||
Result := True;
|
||||
except
|
||||
on e : exception do
|
||||
if CustomExceptionHandler('TCefApplication.InitializeCookies', e) then raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCefApplication.DeleteDirContents(const aDirectory : string);
|
||||
{$IFNDEF DELPHI14_UP}
|
||||
var
|
||||
@ -1172,10 +1158,21 @@ begin
|
||||
end;
|
||||
|
||||
procedure TCefApplication.Internal_OnContextInitialized;
|
||||
var
|
||||
TempThread : TCEFCookieInitializerThread;
|
||||
begin
|
||||
InitializeCookies;
|
||||
FGlobalContextInitialized := True;
|
||||
|
||||
if (length(FCookies) > 0) then
|
||||
begin
|
||||
TempThread := TCEFCookieInitializerThread.Create(FCookies, FPersistSessionCookies);
|
||||
{$IFDEF DELPHI14_UP}
|
||||
TempThread.Start;
|
||||
{$ELSE}
|
||||
TempThread.Resume;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
if assigned(FOnContextInitialized) then FOnContextInitialized();
|
||||
end;
|
||||
|
||||
@ -2173,4 +2170,44 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
||||
// TCEFCookieInitializerThread
|
||||
|
||||
constructor TCEFCookieInitializerThread.Create(const aCookies : string; aPersistSessionCookies : boolean);
|
||||
begin
|
||||
inherited Create(True);
|
||||
|
||||
FCookies := aCookies;
|
||||
FPersistSessionCookies := aPersistSessionCookies;
|
||||
FreeOnTerminate := True;
|
||||
end;
|
||||
|
||||
procedure TCEFCookieInitializerThread.Execute;
|
||||
var
|
||||
TempCookieManager : ICefCookieManager;
|
||||
TempCallBack : ICefCompletionCallback;
|
||||
TempEvent : ICefWaitableEvent;
|
||||
begin
|
||||
try
|
||||
try
|
||||
if (length(FCookies) > 0) then
|
||||
begin
|
||||
TempEvent := TCefWaitableEventRef.New(True, False);
|
||||
TempCallBack := TCefEventCompletionCallback.Create(TempEvent);
|
||||
TempCookieManager := TCefCookieManagerRef.Global(TempCallBack);
|
||||
|
||||
if TempEvent.TimedWait(5000) and (TempCookieManager <> nil) then
|
||||
TempCookieManager.SetStoragePath(FCookies, FPersistSessionCookies, nil);
|
||||
end;
|
||||
except
|
||||
on e : exception do
|
||||
if CustomExceptionHandler('TCEFCookieInitializerThread.Execute', e) then raise;
|
||||
end;
|
||||
finally
|
||||
TempCookieManager := nil;
|
||||
TempCallBack := nil;
|
||||
TempEvent := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -51,7 +51,7 @@ unit uCEFCompletionCallback;
|
||||
interface
|
||||
|
||||
uses
|
||||
uCEFBaseRefCounted, uCEFInterfaces;
|
||||
uCEFBaseRefCounted, uCEFInterfaces, uCEFWaitableEvent;
|
||||
|
||||
type
|
||||
TCefCompletionCallbackOwn = class(TCefBaseRefCountedOwn, ICefCompletionCallback)
|
||||
@ -72,6 +72,17 @@ type
|
||||
constructor Create(const proc: TCefCompletionCallbackProc); reintroduce;
|
||||
end;
|
||||
|
||||
TCefEventCompletionCallback = class(TCefCompletionCallbackOwn)
|
||||
protected
|
||||
FEvent : ICefWaitableEvent;
|
||||
|
||||
procedure OnComplete; override;
|
||||
|
||||
public
|
||||
constructor Create(const event : ICefWaitableEvent); reintroduce;
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
@ -115,4 +126,28 @@ begin
|
||||
FProc();
|
||||
end;
|
||||
|
||||
|
||||
// TCefEventCompletionCallback
|
||||
|
||||
|
||||
constructor TCefEventCompletionCallback.Create(const event : ICefWaitableEvent);
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
FEvent := event;
|
||||
end;
|
||||
|
||||
destructor TCefEventCompletionCallback.Destroy;
|
||||
begin
|
||||
FEvent := nil;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TCefEventCompletionCallback.OnComplete;
|
||||
begin
|
||||
if (FEvent <> nil) then FEvent.Signal;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
@ -64,7 +64,7 @@ type
|
||||
|
||||
public
|
||||
class function UnWrap(data: Pointer): ICefWaitableEvent;
|
||||
class function New(automatic_reset, initially_signaled : integer): ICefWaitableEvent;
|
||||
class function New(automatic_reset, initially_signaled : boolean): ICefWaitableEvent;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -105,9 +105,9 @@ begin
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
class function TCefWaitableEventRef.New(automatic_reset, initially_signaled : integer): ICefWaitableEvent;
|
||||
class function TCefWaitableEventRef.New(automatic_reset, initially_signaled : boolean): ICefWaitableEvent;
|
||||
begin
|
||||
Result := UnWrap(cef_waitable_event_create(automatic_reset, initially_signaled));
|
||||
Result := UnWrap(cef_waitable_event_create(Ord(automatic_reset), Ord(initially_signaled)));
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
x
Reference in New Issue
Block a user