1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-02-12 10:26:05 +02:00

Added CefLazApplication: Provide RegisterHandler for ContextInitialized

This commit is contained in:
martin 2021-03-01 20:04:33 +01:00
parent b9c57057b8
commit 605d31f8cf
4 changed files with 88 additions and 4 deletions

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."/>
<License Value="MPL 1.1"/>
<Version Major="89" Release="6"/>
<Files Count="200">
<Files Count="201">
<Item1>
<Filename Value="..\source\uCEFAccessibilityHandler.pas"/>
<UnitName Value="uCEFAccessibilityHandler"/>
@ -840,6 +840,10 @@
<HasRegisterProc Value="True"/>
<UnitName Value="uceflazarusbrowserwindow"/>
</Item200>
<Item201>
<Filename Value="..\source\uCEFLazApplication.pas"/>
<UnitName Value="uCEFLazApplication"/>
</Item201>
</Files>
<RequiredPkgs Count="4">
<Item1>

View File

@ -65,8 +65,8 @@ uses
uCEFMediaSinkDeviceInfoCallback, uCEFJson, uCEFBitmapBitBuffer,
uCEFPrintDialogCallback, uCEFPrintHandler, uCEFPrintJobCallback,
uCEFLinuxFunctions, uCEFLinuxTypes, uCEFLinuxConstants,
uCEFWorkSchedulerQueueThread, uCEFLinkedWinControlBase, uCEFLazarusCocoa,
uCEFLazarusBrowserWindow, LazarusPackageIntf;
uCEFWorkSchedulerQueueThread, uCEFLinkedWinControlBase, uCEFLazarusCocoa,
uCEFLazarusBrowserWindow, uCEFLazApplication, LazarusPackageIntf;
implementation

View File

@ -391,7 +391,7 @@ type
// ICefLoadHandler and ICefPrintHandler should use them.
procedure Internal_OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine);
procedure Internal_OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef);
procedure Internal_OnContextInitialized;
procedure Internal_OnContextInitialized; virtual;
procedure Internal_OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine);
procedure Internal_OnScheduleMessagePumpWork(const delayMs: Int64);
function Internal_GetLocalizedString(stringId: Integer; var stringVal: ustring) : boolean;

View File

@ -0,0 +1,80 @@
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.