1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-05-13 21:46:53 +02:00

Changed Demo BrowserWindow (Lazarus_any_OS) to use ContextInitialized Handler

This commit is contained in:
martin 2021-03-01 20:05:39 +01:00
parent 605d31f8cf
commit d37e72c010
2 changed files with 27 additions and 8 deletions

View File

@ -51,7 +51,7 @@ unit GlobalCefApplication;
interface
uses
uCEFApplication, uCEFWorkScheduler, FileUtil;
uCEFApplication, uCEFWorkScheduler, uCEFLazApplication, FileUtil;
procedure CreateGlobalCEFApp;
@ -75,7 +75,8 @@ begin
GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil);
{$ENDIF}
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp := TCefLazApplication.Create;
GlobalCEFApp.CheckCEFFiles := False;
{$IFDEF USE_MULTI_THREAD_LOOP}
// On Windows/Linux CEF can use threads for the message-loop
GlobalCEFApp.MultiThreadedMessageLoop := True;

View File

@ -47,7 +47,7 @@ uses
LResources,
{$ENDIF}
uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium,
uCEFLinkedWinControlBase, Forms, ExtCtrls, Classes, sysutils;
uCEFLinkedWinControlBase, uCEFLazApplication, Forms, ExtCtrls, Classes, sysutils;
type
@ -112,6 +112,7 @@ type
FTimer : TTimer;
procedure DoCreateBrowser(Sender: TObject);
procedure DoCreateBrowserAfterContext(Sender: TObject);
protected
function GetChromium: TChromium; override;
procedure DestroyHandle; override;
@ -330,7 +331,8 @@ end;
procedure TLazarusBrowserWindow.DoCreateBrowser(Sender: TObject);
begin
FTimer.Enabled := False;
if FTimer <> nil then
FTimer.Enabled := False;
case FChromiumWrapper.FChromiumState of
csCreatingBrowser, csHasBrowser: begin
@ -351,11 +353,26 @@ begin
if GlobalCEFApp.ExternalMessagePump then
GlobalCEFApp.DoMessageLoopWork;
if FTimer = nil then
FTimer := TTimer.Create(Self);
FTimer.OnTimer := @DoCreateBrowser;
FTimer.Interval := 100;
FTimer.Enabled := True;
end;
end;
procedure TLazarusBrowserWindow.DoCreateBrowserAfterContext(Sender: TObject);
begin
{$IFDEF LINUX}
FTimer := TTimer.Create(Self);
FTimer.Interval := 20;
FTimer.OnTimer := @DoCreateBrowser;
FTimer.Enabled := True;
{$ELSE}
DoCreateBrowser(nil);
{$ENDIF}
end;
function TLazarusBrowserWindow.GetChromium: TChromium;
begin
Result := FChromiumWrapper.FChromium;
@ -368,10 +385,11 @@ begin
(* On Windows we can create the browser immediately.
But at least on Linux, we need to wait
*)
FTimer := TTimer.Create(Self);
FTimer.Interval := 20;
FTimer.OnTimer := @DoCreateBrowser;
FTimer.Enabled := True;
if GlobalCEFApp is TCefLazApplication then
TCefLazApplication(GlobalCEFApp).AddContextInitializedHandler(@DoCreateBrowserAfterContext)
else
DoCreateBrowserAfterContext(nil);
end;
end;