You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-07-12 22:30:17 +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:
@ -249,7 +249,6 @@ type
|
|||||||
function ExecuteProcess(const aApp : ICefApp) : integer;
|
function ExecuteProcess(const aApp : ICefApp) : integer;
|
||||||
procedure InitializeSettings(var aSettings : TCefSettings);
|
procedure InitializeSettings(var aSettings : TCefSettings);
|
||||||
function InitializeLibrary(const aApp : ICefApp) : boolean;
|
function InitializeLibrary(const aApp : ICefApp) : boolean;
|
||||||
function InitializeCookies : boolean;
|
|
||||||
function MultiExeProcessing : boolean;
|
function MultiExeProcessing : boolean;
|
||||||
function SingleExeProcessing : boolean;
|
function SingleExeProcessing : boolean;
|
||||||
function CheckCEFLibrary : boolean;
|
function CheckCEFLibrary : boolean;
|
||||||
@ -395,6 +394,17 @@ type
|
|||||||
property OnCDMRegistrationComplete : TOnCDMRegistrationCompleteEvent read FOnCDMRegistrationComplete write FOnCDMRegistrationComplete;
|
property OnCDMRegistrationComplete : TOnCDMRegistrationCompleteEvent read FOnCDMRegistrationComplete write FOnCDMRegistrationComplete;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TCEFCookieInitializerThread = class(TThread)
|
||||||
|
protected
|
||||||
|
FCookies : string;
|
||||||
|
FPersistSessionCookies : boolean;
|
||||||
|
|
||||||
|
procedure Execute; override;
|
||||||
|
|
||||||
|
public
|
||||||
|
constructor Create(const aCookies : string; aPersistSessionCookies : boolean);
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
GlobalCEFApp : TCefApplication = nil;
|
GlobalCEFApp : TCefApplication = nil;
|
||||||
|
|
||||||
@ -414,7 +424,8 @@ uses
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
uCEFLibFunctions, uCEFMiscFunctions, uCEFCommandLine, uCEFConstants,
|
uCEFLibFunctions, uCEFMiscFunctions, uCEFCommandLine, uCEFConstants,
|
||||||
uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp, uCEFRegisterCDMCallback;
|
uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp, uCEFRegisterCDMCallback,
|
||||||
|
uCEFCompletionCallback, uCEFWaitableEvent;
|
||||||
|
|
||||||
procedure DestroyGlobalCEFApp;
|
procedure DestroyGlobalCEFApp;
|
||||||
begin
|
begin
|
||||||
@ -1006,31 +1017,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
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);
|
procedure TCefApplication.DeleteDirContents(const aDirectory : string);
|
||||||
{$IFNDEF DELPHI14_UP}
|
{$IFNDEF DELPHI14_UP}
|
||||||
var
|
var
|
||||||
@ -1172,10 +1158,21 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCefApplication.Internal_OnContextInitialized;
|
procedure TCefApplication.Internal_OnContextInitialized;
|
||||||
|
var
|
||||||
|
TempThread : TCEFCookieInitializerThread;
|
||||||
begin
|
begin
|
||||||
InitializeCookies;
|
|
||||||
FGlobalContextInitialized := True;
|
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();
|
if assigned(FOnContextInitialized) then FOnContextInitialized();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2173,4 +2170,44 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
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.
|
end.
|
||||||
|
@ -51,7 +51,7 @@ unit uCEFCompletionCallback;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
uCEFBaseRefCounted, uCEFInterfaces;
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFWaitableEvent;
|
||||||
|
|
||||||
type
|
type
|
||||||
TCefCompletionCallbackOwn = class(TCefBaseRefCountedOwn, ICefCompletionCallback)
|
TCefCompletionCallbackOwn = class(TCefBaseRefCountedOwn, ICefCompletionCallback)
|
||||||
@ -72,6 +72,17 @@ type
|
|||||||
constructor Create(const proc: TCefCompletionCallbackProc); reintroduce;
|
constructor Create(const proc: TCefCompletionCallbackProc); reintroduce;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TCefEventCompletionCallback = class(TCefCompletionCallbackOwn)
|
||||||
|
protected
|
||||||
|
FEvent : ICefWaitableEvent;
|
||||||
|
|
||||||
|
procedure OnComplete; override;
|
||||||
|
|
||||||
|
public
|
||||||
|
constructor Create(const event : ICefWaitableEvent); reintroduce;
|
||||||
|
destructor Destroy; override;
|
||||||
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -115,4 +126,28 @@ begin
|
|||||||
FProc();
|
FProc();
|
||||||
end;
|
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.
|
end.
|
||||||
|
@ -64,7 +64,7 @@ type
|
|||||||
|
|
||||||
public
|
public
|
||||||
class function UnWrap(data: Pointer): ICefWaitableEvent;
|
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;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -105,9 +105,9 @@ begin
|
|||||||
Result := nil;
|
Result := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCefWaitableEventRef.New(automatic_reset, initially_signaled : integer): ICefWaitableEvent;
|
class function TCefWaitableEventRef.New(automatic_reset, initially_signaled : boolean): ICefWaitableEvent;
|
||||||
begin
|
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;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Reference in New Issue
Block a user