1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2024-11-24 08:02:15 +02:00

Merged LazApplication int CefApplication (IFDEF)

This commit is contained in:
martin 2021-03-21 01:15:00 +01:00
parent 74f4caf000
commit eb03146bb2
9 changed files with 67 additions and 105 deletions

View File

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

View File

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

View File

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

View File

@ -22,7 +22,7 @@
<Description Value="CEF4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC."/> <Description Value="CEF4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC."/>
<License Value="MPL 1.1"/> <License Value="MPL 1.1"/>
<Version Major="89" Release="7"/> <Version Major="89" Release="7"/>
<Files Count="202"> <Files Count="201">
<Item1> <Item1>
<Filename Value="..\source\uCEFAccessibilityHandler.pas"/> <Filename Value="..\source\uCEFAccessibilityHandler.pas"/>
<UnitName Value="uCEFAccessibilityHandler"/> <UnitName Value="uCEFAccessibilityHandler"/>
@ -841,14 +841,10 @@
<UnitName Value="uCEFBrowserWindow"/> <UnitName Value="uCEFBrowserWindow"/>
</Item200> </Item200>
<Item201> <Item201>
<Filename Value="..\source\uCEFLazApplication.pas"/>
<UnitName Value="uCEFLazApplication"/>
</Item201>
<Item202>
<Filename Value="..\source\uCEFOsrBrowserWindow.pas"/> <Filename Value="..\source\uCEFOsrBrowserWindow.pas"/>
<HasRegisterProc Value="True"/> <HasRegisterProc Value="True"/>
<UnitName Value="uCEFOsrBrowserWindow"/> <UnitName Value="uCEFOsrBrowserWindow"/>
</Item202> </Item201>
</Files> </Files>
<CompatibilityMode Value="True"/> <CompatibilityMode Value="True"/>
<RequiredPkgs Count="5"> <RequiredPkgs Count="5">

View File

@ -66,8 +66,7 @@ uses
uCEFPrintDialogCallback, uCEFPrintHandler, uCEFPrintJobCallback, uCEFPrintDialogCallback, uCEFPrintHandler, uCEFPrintJobCallback,
uCEFLinuxFunctions, uCEFLinuxTypes, uCEFLinuxConstants, uCEFLinuxFunctions, uCEFLinuxTypes, uCEFLinuxConstants,
uCEFWorkSchedulerQueueThread, uCEFLinkedWinControlBase, uCEFLazarusCocoa, uCEFWorkSchedulerQueueThread, uCEFLinkedWinControlBase, uCEFLazarusCocoa,
uCEFBrowserWindow, uCEFLazApplication, uCEFOsrBrowserWindow, uCEFBrowserWindow, uCEFOsrBrowserWindow, LazarusPackageIntf;
LazarusPackageIntf;
implementation implementation

View File

@ -60,7 +60,11 @@ uses
{$ENDIF} {$ENDIF}
System.Classes, System.UITypes, System.Classes, System.UITypes,
{$ELSE} {$ELSE}
{$IFDEF MSWINDOWS}Windows, Forms, ActiveX,{$ENDIF} Classes, Controls, {$IFDEF FPC}dynlibs,{$ENDIF} Forms,
{$IFDEF MSWINDOWS}Windows, ActiveX,{$ENDIF} Classes, Controls, {$IFDEF FPC}dynlibs,{$ENDIF}
{$ENDIF}
{$IFDEF FPC}
LCLProc,
{$ENDIF} {$ENDIF}
uCEFApplicationCore, uCEFTypes; uCEFApplicationCore, uCEFTypes;
@ -83,6 +87,12 @@ type
protected protected
FDestroyApplicationObject : boolean; FDestroyApplicationObject : boolean;
FDestroyAppWindows : boolean; FDestroyAppWindows : boolean;
{$IFDEF FPC}
FContextInitializedHandlers: TMethodList;
FContextInitializedDone: Boolean;
procedure CallContextInitializedHandlers(Data: PtrInt);
{$ENDIF}
procedure BeforeInitSubProcess; override; procedure BeforeInitSubProcess; override;
@ -93,6 +103,13 @@ type
property DestroyApplicationObject: boolean read FDestroyApplicationObject write FDestroyApplicationObject; property DestroyApplicationObject: boolean read FDestroyApplicationObject write FDestroyApplicationObject;
property DestroyAppWindows : boolean read FDestroyAppWindows write FDestroyAppWindows; property DestroyAppWindows : boolean read FDestroyAppWindows write FDestroyAppWindows;
{$IFDEF FPC}
procedure Internal_OnContextInitialized; override; // In UI thread
Procedure AddContextInitializedHandler(AHandler: TNotifyEvent);
Procedure RemoveContextInitializedHandler(AHandler: TNotifyEvent);
{$ENDIF}
end; end;
TCEFDirectoryDeleterThread = uCEFApplicationCore.TCEFDirectoryDeleterThread; TCEFDirectoryDeleterThread = uCEFApplicationCore.TCEFDirectoryDeleterThread;
@ -187,6 +204,10 @@ end;
constructor TCefApplication.Create; constructor TCefApplication.Create;
begin begin
{$IFDEF FPC}
FContextInitializedHandlers := TMethodList.Create;
{$ENDIF}
inherited Create; inherited Create;
if GlobalCEFApp = nil then if GlobalCEFApp = nil then
GlobalCEFApp := Self; GlobalCEFApp := Self;
@ -200,6 +221,10 @@ begin
if GlobalCEFApp = Self then if GlobalCEFApp = Self then
GlobalCEFApp := nil; GlobalCEFApp := nil;
inherited Destroy; inherited Destroy;
{$IFDEF FPC}
FContextInitializedHandlers.Free;
{$ENDIF}
end; end;
procedure TCefApplication.UpdateDeviceScaleFactor; procedure TCefApplication.UpdateDeviceScaleFactor;
@ -238,6 +263,34 @@ begin
{$ENDIF} {$ENDIF}
end; end;
{$IFDEF FPC}
procedure TCefApplication.Internal_OnContextInitialized;
begin
inherited Internal_OnContextInitialized;
Application.QueueAsyncCall(@CallContextInitializedHandlers, 0);
end;
procedure TCefApplication.AddContextInitializedHandler(AHandler: TNotifyEvent);
begin
FContextInitializedHandlers.Add(TMethod(AHandler));
if FContextInitializedDone then
AHandler(Self);
end;
procedure TCefApplication.RemoveContextInitializedHandler(AHandler: TNotifyEvent);
begin
FContextInitializedHandlers.Remove(TMethod(AHandler));
end;
{$ENDIF}
{$IFDEF FPC}
procedure TCefApplication.CallContextInitializedHandlers(Data: PtrInt);
begin
FContextInitializedHandlers.CallNotifyEvents(Self);
FContextInitializedDone := True;
end;
{$ENDIF}
procedure TCefApplication.BeforeInitSubProcess; procedure TCefApplication.BeforeInitSubProcess;
{$IFNDEF FPC} {$IFNDEF FPC}
{$IFNDEF FMX} {$IFNDEF FMX}

View File

@ -47,7 +47,7 @@ uses
LResources, PropEdits, LResources, PropEdits,
{$ENDIF} {$ENDIF}
uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium, uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium,
uCEFLinkedWinControlBase, uCEFLazApplication, uCEFBrowserViewComponent, uCEFLinkedWinControlBase, uCEFBrowserViewComponent,
uCEFChromiumEvents, Forms, ExtCtrls, Controls, Classes, sysutils; uCEFChromiumEvents, Forms, ExtCtrls, Controls, Classes, sysutils;
type type
@ -619,10 +619,7 @@ begin
But at least on Linux, we need to wait But at least on Linux, we need to wait
*) *)
if GlobalCEFApp is TCefLazApplication then GlobalCEFApp.AddContextInitializedHandler(@DoCreateBrowserAfterContext);
TCefLazApplication(GlobalCEFApp).AddContextInitializedHandler(@DoCreateBrowserAfterContext)
else
DoCreateBrowserAfterContext(nil);
end; end;
end; end;

View File

@ -1,80 +0,0 @@
unit uCEFLazApplication;
{$IFDEF FPC}
{$MODE OBJFPC}{$H+}
{$ENDIF}
{$I cef.inc}
interface
uses
{$IFDEF DELPHI16_UP}
{$ELSE}
Forms, LclProc, Classes, SysUtils,
{$ENDIF}
uCEFTypes, uCEFApplication;
type
{ TCefLazApplication }
TCefLazApplication = class(TCefApplication)
protected
FContextInitializedHandlers: TMethodList;
FContextInitializedDone: Boolean;
procedure CallContextInitializedHandlers(Data: PtrInt);
public
constructor Create;
destructor Destroy; override;
procedure Internal_OnContextInitialized; override; // In UI thread
Procedure AddContextInitializedHandler(AHandler: TNotifyEvent);
Procedure RemoveContextInitializedHandler(AHandler: TNotifyEvent);
end;
implementation
{ TCefLazApplication }
procedure TCefLazApplication.Internal_OnContextInitialized;
begin
inherited Internal_OnContextInitialized;
Application.QueueAsyncCall(@CallContextInitializedHandlers, 0);
//TThread.Queue(@CallContextInitializedHandlers);
end;
procedure TCefLazApplication.CallContextInitializedHandlers(Data: PtrInt);
begin
FContextInitializedHandlers.CallNotifyEvents(Self);
FContextInitializedDone := True;
end;
constructor TCefLazApplication.Create;
begin
FContextInitializedHandlers := TMethodList.Create;
inherited Create;
end;
destructor TCefLazApplication.Destroy;
begin
inherited Destroy;
FContextInitializedHandlers.Free;
end;
procedure TCefLazApplication.AddContextInitializedHandler(AHandler: TNotifyEvent);
begin
FContextInitializedHandlers.Add(TMethod(AHandler));
if FContextInitializedDone then
AHandler(Self);
end;
procedure TCefLazApplication.RemoveContextInitializedHandler(
AHandler: TNotifyEvent);
begin
FContextInitializedHandlers.Remove(TMethod(AHandler));
end;
end.

View File

@ -59,7 +59,7 @@ uses
LResources, PropEdits, LResources, PropEdits,
{$ENDIF} {$ENDIF}
uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium, uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium,
uCEFLinkedWinControlBase, uCEFLazApplication, uCEFBufferPanel, uCEFLinkedWinControlBase, uCEFBufferPanel,
uCEFBrowserWindow, uCEFBitmapBitBuffer, uCEFMiscFunctions, uCEFBrowserWindow, uCEFBitmapBitBuffer, uCEFMiscFunctions,
uCEFConstants, uCEFChromiumEvents, Forms, ExtCtrls, LCLType, Graphics, uCEFConstants, uCEFChromiumEvents, Forms, ExtCtrls, LCLType, Graphics,
Controls, syncobjs, Classes, sysutils, math; Controls, syncobjs, Classes, sysutils, math;
@ -605,10 +605,7 @@ procedure TOsrBrowserWindow.CreateHandle;
begin begin
inherited CreateHandle; inherited CreateHandle;
if not (csDesigning in ComponentState) then begin if not (csDesigning in ComponentState) then begin
if GlobalCEFApp is TCefLazApplication then GlobalCEFApp.AddContextInitializedHandler(@DoCreateBrowserAfterContext);
TCefLazApplication(GlobalCEFApp).AddContextInitializedHandler(@DoCreateBrowserAfterContext)
else
DoCreateBrowserAfterContext(nil);
end; end;
end; end;