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

Added GlobalCEFWorkScheduler and GlobalFMXWorkScheduler global variables

This commit is contained in:
Salvador Díaz Fau 2018-04-07 20:24:55 +02:00
parent eae6172ef3
commit 62580730d2
18 changed files with 45 additions and 54 deletions

View File

@ -68,7 +68,6 @@ begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.FlashEnabled := False;
GlobalCEFApp.FastUnload := True;
GlobalCEFApp.ExternalMessagePump := True;
GlobalCEFApp.MultiThreadedMessageLoop := False;
GlobalCEFApp.OnScheduleMessagePumpWork := GlobalCEFApp_OnScheduleMessagePumpWork;

View File

@ -95,7 +95,6 @@ type
var
ExternalPumpBrowserFrm : TExternalPumpBrowserFrm;
GlobalCEFWorkScheduler : TCEFWorkScheduler = nil;
procedure GlobalCEFApp_OnScheduleMessagePumpWork(const aDelayMS : int64);

View File

@ -59,20 +59,18 @@ uses
{$ENDIF}
begin
// TCEFWorkScheduler will call cef_do_message_loop_work when
// TFMXWorkScheduler will call cef_do_message_loop_work when
// it's told in the GlobalCEFApp.OnScheduleMessagePumpWork event.
// GlobalCEFWorkScheduler needs to be created before the
// GlobalFMXWorkScheduler needs to be created before the
// GlobalCEFApp.StartMainProcess call.
GlobalCEFWorkScheduler := TFMXWorkScheduler.Create(nil);
GlobalFMXWorkScheduler := TFMXWorkScheduler.Create(nil);
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.WindowlessRenderingEnabled := True;
GlobalCEFApp.EnableHighDPISupport := True;
GlobalCEFApp.FastUnload := True;
GlobalCEFApp.FlashEnabled := False;
GlobalCEFApp.ExternalMessagePump := True;
GlobalCEFApp.MultiThreadedMessageLoop := False;
GlobalCEFApp.SitePerProcess := False;
GlobalCEFApp.OnScheduleMessagePumpWork := GlobalCEFApp_OnScheduleMessagePumpWork;
if GlobalCEFApp.StartMainProcess then
@ -84,9 +82,9 @@ begin
// The form needs to be destroyed *BEFORE* stopping the scheduler.
FMXExternalPumpBrowserFrm.Free;
GlobalCEFWorkScheduler.StopScheduler;
GlobalFMXWorkScheduler.StopScheduler;
end;
FreeAndNil(GlobalCEFApp);
FreeAndNil(GlobalCEFWorkScheduler);
FreeAndNil(GlobalFMXWorkScheduler);
end.

View File

@ -77,6 +77,7 @@ implementation
uses
FMX.Forms,
uFMXExternalPumpBrowser,
uFMXWorkScheduler,
{$IFDEF MSWINDOWS}
Winapi.Messages, Winapi.Windows,
{$ENDIF}
@ -135,7 +136,11 @@ end;
function TFMXApplicationService.Running: Boolean;
begin
{$IFDEF DELPHI24_UP}
Result := OldFMXApplicationService.Running;
{$ELSE}
Result := True;
{$ENDIF}
end;
function TFMXApplicationService.HandleMessage: Boolean;
@ -179,12 +184,6 @@ begin
(Application.MainForm is TFMXExternalPumpBrowserFrm) then
TFMXExternalPumpBrowserFrm(Application.MainForm).HandleSYSKEYUP(TempMsg);
CEF_AFTERCREATED :
if not(Application.Terminated) and
(Application.MainForm <> nil) and
(Application.MainForm is TFMXExternalPumpBrowserFrm) then
TFMXExternalPumpBrowserFrm(Application.MainForm).DoBrowserCreated;
CEF_PENDINGRESIZE :
if not(Application.Terminated) and
(Application.MainForm <> nil) and
@ -193,8 +192,8 @@ begin
CEF_PUMPHAVEWORK :
if not(Application.Terminated) and
(GlobalCEFWorkScheduler <> nil) then
GlobalCEFWorkScheduler.ScheduleWork(TempMsg.lParam);
(GlobalFMXWorkScheduler <> nil) then
GlobalFMXWorkScheduler.ScheduleWork(TempMsg.lParam);
end;
{$ENDIF}

View File

@ -107,7 +107,6 @@ object FMXExternalPumpBrowserFrm: TFMXExternalPumpBrowserFrm
object chrmosr: TFMXChromium
OnTooltip = chrmosrTooltip
OnBeforePopup = chrmosrBeforePopup
OnAfterCreated = chrmosrAfterCreated
OnBeforeClose = chrmosrBeforeClose
OnClose = chrmosrClose
OnGetViewRect = chrmosrGetViewRect

View File

@ -94,7 +94,6 @@ type
procedure chrmosrGetScreenInfo(Sender: TObject; const browser: ICefBrowser; var screenInfo: TCefScreenInfo; out Result: Boolean);
procedure chrmosrPopupShow(Sender: TObject; const browser: ICefBrowser; show: Boolean);
procedure chrmosrPopupSize(Sender: TObject; const browser: ICefBrowser; const rect: PCefRect);
procedure chrmosrAfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure chrmosrClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
procedure chrmosrBeforeClose(Sender: TObject; const browser: ICefBrowser);
procedure chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; var text: ustring; out Result: Boolean);
@ -142,7 +141,6 @@ type
var
FMXExternalPumpBrowserFrm : TFMXExternalPumpBrowserFrm;
GlobalCEFWorkScheduler : TFMXWorkScheduler = nil;
// This is a simple browser using FireMonkey components in OSR mode (off-screen rendering)
// and a external message pump.
@ -154,7 +152,7 @@ var
// uFMXApplicationService.pas to intercept some windows messages needed to make a CEF browser work.
// The TFMXApplicationService.HandleMessages function receives many of the messages that the
// OSRExternalPumpBrowser demo hadled in the main form or in the GlobalCEFWorkScheduler.
// OSRExternalPumpBrowser demo hadled in the main form or in the GlobalFMXWorkScheduler.
// It was necessary to destroy the browser following the destruction sequence described in
// the MDIBrowser demo but in OSR mode there are some modifications.
@ -178,7 +176,7 @@ uses
procedure GlobalCEFApp_OnScheduleMessagePumpWork(const aDelayMS : int64);
begin
if (GlobalCEFWorkScheduler <> nil) then GlobalCEFWorkScheduler.ScheduleMessagePumpWork(aDelayMS);
if (GlobalFMXWorkScheduler <> nil) then GlobalFMXWorkScheduler.ScheduleMessagePumpWork(aDelayMS);
end;
procedure TFMXExternalPumpBrowserFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
@ -238,7 +236,10 @@ begin
// opaque white background color
chrmosr.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
if not(chrmosr.CreateBrowser) then Timer1.Enabled := True;
if chrmosr.CreateBrowser then
DoBrowserCreated
else
Timer1.Enabled := True;
end;
end;
@ -459,7 +460,11 @@ procedure TFMXExternalPumpBrowserFrm.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
if not(chrmosr.CreateBrowser) and not(chrmosr.Initialized) then Timer1.Enabled := True;
if chrmosr.CreateBrowser then
DoBrowserCreated
else
if not(chrmosr.Initialized) then
Timer1.Enabled := True;
end;
procedure TFMXExternalPumpBrowserFrm.AddressEdtEnter(Sender: TObject);
@ -467,11 +472,6 @@ begin
chrmosr.SendFocusEvent(False);
end;
procedure TFMXExternalPumpBrowserFrm.chrmosrAfterCreated(Sender: TObject; const browser: ICefBrowser);
begin
SendCompMessage(CEF_AFTERCREATED);
end;
procedure TFMXExternalPumpBrowserFrm.chrmosrBeforeClose(Sender: TObject; const browser: ICefBrowser);
begin
FCanClose := True;

View File

@ -57,7 +57,6 @@ uses
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.FlashEnabled := False;
GlobalCEFApp.FastUnload := True;
if GlobalCEFApp.StartMainProcess then
begin

View File

@ -67,7 +67,6 @@ begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.FlashEnabled := False;
GlobalCEFApp.FastUnload := True;
GlobalCEFApp.ExternalMessagePump := True;
GlobalCEFApp.MultiThreadedMessageLoop := False;
GlobalCEFApp.OnScheduleMessagePumpWork := GlobalCEFApp_OnScheduleMessagePumpWork;

View File

@ -89,8 +89,7 @@ type
end;
var
MainForm : TMainForm;
GlobalCEFWorkScheduler : TCEFWorkScheduler = nil;
MainForm : TMainForm;
procedure GlobalCEFApp_OnContextInitialized;
procedure GlobalCEFApp_OnScheduleMessagePumpWork(const aDelayMS : int64);

View File

@ -68,11 +68,9 @@ begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.WindowlessRenderingEnabled := True;
GlobalCEFApp.EnableHighDPISupport := True;
GlobalCEFApp.FastUnload := True;
GlobalCEFApp.FlashEnabled := False;
GlobalCEFApp.ExternalMessagePump := True;
GlobalCEFApp.MultiThreadedMessageLoop := False;
GlobalCEFApp.SitePerProcess := False;
GlobalCEFApp.OnScheduleMessagePumpWork := GlobalCEFApp_OnScheduleMessagePumpWork;
if GlobalCEFApp.StartMainProcess then

View File

@ -139,7 +139,6 @@ type
var
OSRExternalPumpBrowserFrm : TOSRExternalPumpBrowserFrm;
GlobalCEFWorkScheduler : TCEFWorkScheduler = nil;
// This is a simple browser in OSR mode (off-screen rendering).
// It was necessary to destroy the browser following the destruction sequence described in

View File

@ -62,7 +62,6 @@ begin
GlobalCEFApp.FlashEnabled := False;
GlobalCEFApp.WindowlessRenderingEnabled := True;
GlobalCEFApp.EnableHighDPISupport := True;
GlobalCEFApp.FastUnload := True;
GlobalCEFApp.SitePerProcess := False;
if GlobalCEFApp.StartMainProcess then

View File

@ -68,7 +68,6 @@ begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.FlashEnabled := False;
GlobalCEFApp.FastUnload := True;
GlobalCEFApp.ExternalMessagePump := True;
GlobalCEFApp.MultiThreadedMessageLoop := False;
GlobalCEFApp.OnScheduleMessagePumpWork := GlobalCEFApp_OnScheduleMessagePumpWork;

View File

@ -85,7 +85,6 @@ type
var
SimpleExternalPumpBrowserFrm : TSimpleExternalPumpBrowserFrm;
GlobalCEFWorkScheduler : TCEFWorkScheduler = nil;
procedure GlobalCEFApp_OnScheduleMessagePumpWork(const aDelayMS : int64);

View File

@ -58,7 +58,6 @@ begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.WindowlessRenderingEnabled := True;
GlobalCEFApp.EnableHighDPISupport := True;
GlobalCEFApp.FastUnload := True;
GlobalCEFApp.SitePerProcess := False;
if GlobalCEFApp.StartMainProcess then

View File

@ -522,8 +522,8 @@ type
FILE_DIALOG_OPEN_FOLDER,
FILE_DIALOG_SAVE,
FILE_DIALOG_TYPE_MASK = $FF,
FILE_DIALOG_OVERWRITEPROMPT_FLAG = $01000000,
FILE_DIALOG_HIDEREADONLY_FLAG = $02000000
FILE_DIALOG_OVERWRITEPROMPT_FLAG = $01000000,
FILE_DIALOG_HIDEREADONLY_FLAG = $02000000
);
// /include/internal/cef_types.h (cef_focus_source_t)
@ -1074,7 +1074,7 @@ type
end;
TCookie = record
name : ustring;
name : ustring;
value : ustring;
domain : ustring;
path : ustring;
@ -1282,14 +1282,15 @@ type
// /include/capi/cef_extension_handler_capi.h (cef_get_extension_resource_callback_t)
TCefGetExtensionResourceCallback = record
base : TCefBaseRefCounted;
cont : procedure(self: PCefGetExtensionResourceCallback; stream: PCefStreamReader); stdcall;
cancel : procedure(self: PCefGetExtensionResourceCallback); stdcall;
cont : procedure(self: PCefGetExtensionResourceCallback; stream: PCefStreamReader); stdcall;
cancel : procedure(self: PCefGetExtensionResourceCallback); stdcall;
end;
// /include/capi/cef_extension_handler_capi.h (cef_extension_handler_t)
TCefExtensionHandler = record
base : TCefBaseRefCounted;
on_extension_load_failed : procedure(self: PCefExtensionHandler; result: TCefErrorcode); stdcall;
on_extension_load_failed : procedure(self: PCefExtensionHandler; result: TCefErrorcode); stdcall;
on_extension_loaded : procedure(self: PCefExtensionHandler; extension: PCefExtension); stdcall;
on_extension_unloaded : procedure(self: PCefExtensionHandler; extension: PCefExtension); stdcall;
on_before_background_browser : function(self: PCefExtensionHandler; extension: PCefExtension; const url: PCefString; var client: PCefClient; settings: PCefBrowserSettings) : Integer; stdcall;
@ -1302,14 +1303,14 @@ type
// /include/capi/cef_extension_capi.h (cef_extension_t)
TCefExtension = record
base : TCefBaseRefCounted;
get_identifier : function(self: PCefExtension) : PCefStringUserFree; stdcall;
get_path : function(self: PCefExtension) : PCefStringUserFree; stdcall;
get_manifest : function(self: PCefExtension) : PCefDictionaryValue; stdcall;
is_same : function(self, that: PCefExtension) : Integer; stdcall;
get_handler : function(self: PCefExtension) : PCefExtensionHandler; stdcall;
get_loader_context : function(self: PCefExtension) : PCefRequestContext; stdcall;
is_loaded : function(self: PCefExtension) : Integer; stdcall;
unload : procedure(self: PCefExtension); stdcall;
get_identifier : function(self: PCefExtension) : PCefStringUserFree; stdcall;
get_path : function(self: PCefExtension) : PCefStringUserFree; stdcall;
get_manifest : function(self: PCefExtension) : PCefDictionaryValue; stdcall;
is_same : function(self, that: PCefExtension) : Integer; stdcall;
get_handler : function(self: PCefExtension) : PCefExtensionHandler; stdcall;
get_loader_context : function(self: PCefExtension) : PCefRequestContext; stdcall;
is_loaded : function(self: PCefExtension) : Integer; stdcall;
unload : procedure(self: PCefExtension); stdcall;
end;
// /include/capi/cef_load_handler_capi.h (cef_load_handler_t)

View File

@ -106,6 +106,9 @@ type
property DepleteWorkDelay : cardinal read FDepleteWorkDelay write FDepleteWorkDelay default CEF_TIMER_DEPLETEWORK_DELAY;
end;
var
GlobalCEFWorkScheduler : TCEFWorkScheduler = nil;
implementation
uses

View File

@ -101,6 +101,9 @@ type
property DepleteWorkDelay : cardinal read FDepleteWorkDelay write FDepleteWorkDelay default CEF_TIMER_DEPLETEWORK_DELAY;
end;
var
GlobalFMXWorkScheduler : TFMXWorkScheduler = nil;
implementation
uses