2017-01-27 17:29:37 +01:00
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
//
|
2019-10-19 10:58:34 +02:00
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
|
2017-01-27 17:29:37 +01:00
|
|
|
|
// browser in Delphi applications.
|
|
|
|
|
//
|
|
|
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
|
|
|
//
|
|
|
|
|
// For more information about CEF4Delphi visit :
|
|
|
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
|
|
|
//
|
2021-01-01 11:11:30 +01:00
|
|
|
|
// Copyright <20> 2021 Salvador Diaz Fau. All rights reserved.
|
2017-01-27 17:29:37 +01:00
|
|
|
|
//
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
(*
|
|
|
|
|
* Delphi Chromium Embedded 3
|
|
|
|
|
*
|
|
|
|
|
* Usage allowed under the restrictions of the Lesser GNU General Public License
|
|
|
|
|
* or alternatively the restrictions of the Mozilla Public License 1.1
|
|
|
|
|
*
|
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
|
|
|
* the specific language governing rights and limitations under the License.
|
|
|
|
|
*
|
|
|
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
|
|
|
* Web site : http://www.progdigy.com
|
|
|
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
|
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
|
|
|
*
|
|
|
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
|
|
|
* this source code without explicit permission.
|
|
|
|
|
*
|
|
|
|
|
*)
|
|
|
|
|
|
|
|
|
|
unit uCEFBrowserProcessHandler;
|
2018-05-12 14:50:54 +02:00
|
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
|
{$ENDIF}
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
2018-11-22 15:02:21 +01:00
|
|
|
|
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
|
|
|
|
|
{$MINENUMSIZE 4}
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2020-11-19 18:55:17 +01:00
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
|
System.Classes,
|
|
|
|
|
{$ELSE}
|
|
|
|
|
Classes,
|
|
|
|
|
{$ENDIF}
|
2019-11-08 23:15:53 +01:00
|
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFApplicationCore;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
type
|
2017-03-16 19:09:42 +01:00
|
|
|
|
TCefBrowserProcessHandlerOwn = class(TCefBaseRefCountedOwn, ICefBrowserProcessHandler)
|
2017-10-28 10:53:51 +02:00
|
|
|
|
protected
|
2020-11-19 18:55:17 +01:00
|
|
|
|
procedure GetCookieableSchemes(var schemes: TStringList; var include_defaults : boolean); virtual; abstract;
|
2017-11-25 19:04:15 +01:00
|
|
|
|
procedure OnContextInitialized; virtual; abstract;
|
|
|
|
|
procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); virtual; abstract;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
procedure GetPrintHandler(var aHandler : ICefPrintHandler); virtual;
|
2017-11-25 19:04:15 +01:00
|
|
|
|
procedure OnScheduleMessagePumpWork(const delayMs: Int64); virtual; abstract;
|
2020-11-19 18:55:17 +01:00
|
|
|
|
procedure GetDefaultClient(var aClient : ICefClient); virtual;
|
2017-10-28 10:53:51 +02:00
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
|
procedure RemoveReferences; virtual; abstract;
|
|
|
|
|
|
2017-10-28 10:53:51 +02:00
|
|
|
|
public
|
|
|
|
|
constructor Create; virtual;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-11-25 19:04:15 +01:00
|
|
|
|
TCefCustomBrowserProcessHandler = class(TCefBrowserProcessHandlerOwn)
|
2017-12-27 14:05:33 +01:00
|
|
|
|
protected
|
2021-01-01 17:51:09 +01:00
|
|
|
|
FCefApp : TCefApplicationCore;
|
|
|
|
|
FPrintHandler : ICefPrintHandler;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
|
2020-11-19 18:55:17 +01:00
|
|
|
|
procedure GetCookieableSchemes(var schemes: TStringList; var include_defaults : boolean); override;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
procedure OnContextInitialized; override;
|
|
|
|
|
procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); override;
|
2021-01-01 17:51:09 +01:00
|
|
|
|
procedure GetPrintHandler(var aHandler : ICefPrintHandler); override;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
procedure OnScheduleMessagePumpWork(const delayMs: Int64); override;
|
2020-11-19 18:55:17 +01:00
|
|
|
|
procedure GetDefaultClient(var aClient : ICefClient); override;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
|
procedure RemoveReferences; override;
|
|
|
|
|
|
2017-12-27 14:05:33 +01:00
|
|
|
|
public
|
2019-11-08 23:15:53 +01:00
|
|
|
|
constructor Create(const aCefApp : TCefApplicationCore); reintroduce;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
end;
|
2017-11-25 19:04:15 +01:00
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
2018-03-29 20:02:04 +02:00
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
|
System.SysUtils,
|
|
|
|
|
{$ELSE}
|
|
|
|
|
SysUtils,
|
|
|
|
|
{$ENDIF}
|
2021-01-01 17:51:09 +01:00
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFCommandLine, uCEFListValue, uCEFConstants, uCEFStringList,
|
|
|
|
|
uCEFPrintHandler;
|
2020-11-19 18:55:17 +01:00
|
|
|
|
|
|
|
|
|
procedure cef_browser_process_handler_get_cookieable_schemes(self : PCefBrowserProcessHandler;
|
|
|
|
|
schemes : TCefStringList;
|
|
|
|
|
include_defaults : PInteger); stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempSL : TStringList;
|
|
|
|
|
TempCefSL : ICefStringList;
|
|
|
|
|
TempObject : TObject;
|
|
|
|
|
TempIncDef : boolean;
|
|
|
|
|
begin
|
|
|
|
|
TempSL := nil;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
try
|
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (schemes <> nil) and (TempObject <> nil) and (TempObject is TCefBrowserProcessHandlerOwn) then
|
|
|
|
|
begin
|
|
|
|
|
TempIncDef := (include_defaults^ <> 0);
|
|
|
|
|
TempSL := TStringList.Create;
|
|
|
|
|
TempCefSL := TCefStringListRef.Create(schemes);
|
|
|
|
|
TempCefSL.CopyToStrings(TempSL);
|
|
|
|
|
|
|
|
|
|
TCefBrowserProcessHandlerOwn(TempObject).GetCookieableSchemes(TempSL, TempIncDef);
|
|
|
|
|
|
|
|
|
|
TempCefSL.Clear;
|
|
|
|
|
TempCefSL.AddStrings(TempSL);
|
|
|
|
|
|
|
|
|
|
include_defaults^ := ord(TempIncDef);
|
|
|
|
|
end;
|
|
|
|
|
except
|
|
|
|
|
on e : exception do
|
|
|
|
|
if CustomExceptionHandler('cef_browser_process_handler_get_cookieable_schemes', e) then raise;
|
|
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
if (TempSL <> nil) then FreeAndNil(TempSL);
|
|
|
|
|
TempCefSL := nil;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
procedure cef_browser_process_handler_on_context_initialized(self: PCefBrowserProcessHandler); stdcall;
|
2017-11-25 19:04:15 +01:00
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2017-12-27 14:05:33 +01:00
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
|
if (TempObject <> nil) and
|
|
|
|
|
(TempObject is TCefBrowserProcessHandlerOwn) then
|
2017-11-25 19:04:15 +01:00
|
|
|
|
TCefBrowserProcessHandlerOwn(TempObject).OnContextInitialized;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure cef_browser_process_handler_on_before_child_process_launch(self : PCefBrowserProcessHandler;
|
|
|
|
|
command_line : PCefCommandLine); stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
|
|
|
|
begin
|
2017-12-27 14:05:33 +01:00
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
|
if (TempObject <> nil) and
|
|
|
|
|
(TempObject is TCefBrowserProcessHandlerOwn) then
|
2017-11-25 19:04:15 +01:00
|
|
|
|
TCefBrowserProcessHandlerOwn(TempObject).OnBeforeChildProcessLaunch(TCefCommandLineRef.UnWrap(command_line));
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-11-25 19:04:15 +01:00
|
|
|
|
function cef_browser_process_handler_get_print_handler(self: PCefBrowserProcessHandler): PCefPrintHandler; stdcall;
|
|
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
|
TempObject : TObject;
|
|
|
|
|
TempHandler : ICefPrintHandler;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
Result := nil;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
|
if (TempObject <> nil) and
|
|
|
|
|
(TempObject is TCefBrowserProcessHandlerOwn) then
|
2018-03-29 20:02:04 +02:00
|
|
|
|
try
|
2020-11-19 18:55:17 +01:00
|
|
|
|
TempHandler := nil;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
TCefBrowserProcessHandlerOwn(TempObject).GetPrintHandler(TempHandler);
|
|
|
|
|
if (TempHandler <> nil) then Result := TempHandler.Wrap;
|
|
|
|
|
finally
|
|
|
|
|
TempHandler := nil;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
2017-11-25 19:04:15 +01:00
|
|
|
|
procedure cef_browser_process_handler_on_schedule_message_pump_work(self : PCefBrowserProcessHandler;
|
|
|
|
|
delay_ms : Int64); stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:24:27 +01:00
|
|
|
|
begin
|
2017-12-27 14:05:33 +01:00
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
|
if (TempObject <> nil) and
|
|
|
|
|
(TempObject is TCefBrowserProcessHandlerOwn) then
|
2017-11-25 19:04:15 +01:00
|
|
|
|
TCefBrowserProcessHandlerOwn(TempObject).OnScheduleMessagePumpWork(delay_ms);
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-11-19 18:55:17 +01:00
|
|
|
|
function cef_browser_process_handler_get_default_client(self: PCefBrowserProcessHandler): PCefClient; stdcall;
|
|
|
|
|
var
|
|
|
|
|
TempObject : TObject;
|
|
|
|
|
TempClient : ICefClient;
|
|
|
|
|
begin
|
|
|
|
|
Result := nil;
|
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
|
|
if (TempObject <> nil) and
|
|
|
|
|
(TempObject is TCefBrowserProcessHandlerOwn) then
|
|
|
|
|
try
|
|
|
|
|
TempClient := nil;
|
|
|
|
|
TCefBrowserProcessHandlerOwn(TempObject).GetDefaultClient(TempClient);
|
|
|
|
|
if (TempClient <> nil) then Result := TempClient.Wrap;
|
|
|
|
|
finally
|
|
|
|
|
TempClient := nil;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
constructor TCefBrowserProcessHandlerOwn.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited CreateData(SizeOf(TCefBrowserProcessHandler));
|
|
|
|
|
|
|
|
|
|
with PCefBrowserProcessHandler(FData)^ do
|
|
|
|
|
begin
|
2020-11-19 18:55:17 +01:00
|
|
|
|
get_cookieable_schemes := {$IFDEF FPC}@{$ENDIF}cef_browser_process_handler_get_cookieable_schemes;
|
2018-05-12 14:50:54 +02:00
|
|
|
|
on_context_initialized := {$IFDEF FPC}@{$ENDIF}cef_browser_process_handler_on_context_initialized;
|
|
|
|
|
on_before_child_process_launch := {$IFDEF FPC}@{$ENDIF}cef_browser_process_handler_on_before_child_process_launch;
|
|
|
|
|
get_print_handler := {$IFDEF FPC}@{$ENDIF}cef_browser_process_handler_get_print_handler;
|
|
|
|
|
on_schedule_message_pump_work := {$IFDEF FPC}@{$ENDIF}cef_browser_process_handler_on_schedule_message_pump_work;
|
2020-11-19 18:55:17 +01:00
|
|
|
|
get_default_client := {$IFDEF FPC}@{$ENDIF}cef_browser_process_handler_get_default_client;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
procedure TCefBrowserProcessHandlerOwn.GetPrintHandler(var aHandler : ICefPrintHandler);
|
2017-11-25 19:04:15 +01:00
|
|
|
|
begin
|
2021-01-01 17:51:09 +01:00
|
|
|
|
aHandler := nil;
|
2017-11-25 19:04:15 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-11-19 18:55:17 +01:00
|
|
|
|
procedure TCefBrowserProcessHandlerOwn.GetDefaultClient(var aClient : ICefClient);
|
|
|
|
|
begin
|
|
|
|
|
aClient := nil;
|
|
|
|
|
end;
|
2017-11-25 19:04:15 +01:00
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
|
|
2017-11-25 19:04:15 +01:00
|
|
|
|
// TCefCustomBrowserProcessHandler
|
2017-12-27 14:05:33 +01:00
|
|
|
|
|
|
|
|
|
|
2019-11-08 23:15:53 +01:00
|
|
|
|
constructor TCefCustomBrowserProcessHandler.Create(const aCefApp : TCefApplicationCore);
|
2017-12-27 14:05:33 +01:00
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
|
|
FCefApp := aCefApp;
|
2021-01-01 17:51:09 +01:00
|
|
|
|
|
|
|
|
|
if (FCefApp <> nil) and FCefApp.MustCreatePrintHandler then
|
|
|
|
|
FPrintHandler := TCustomPrintHandler.Create(FCefApp)
|
|
|
|
|
else
|
|
|
|
|
FPrintHandler := nil;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TCefCustomBrowserProcessHandler.Destroy;
|
|
|
|
|
begin
|
2020-11-10 15:02:49 +01:00
|
|
|
|
RemoveReferences;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
|
|
|
|
|
inherited Destroy;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
|
procedure TCefCustomBrowserProcessHandler.RemoveReferences;
|
|
|
|
|
begin
|
2021-01-01 17:51:09 +01:00
|
|
|
|
if (FPrintHandler <> nil) then
|
|
|
|
|
FPrintHandler.RemoveReferences;
|
|
|
|
|
|
|
|
|
|
FCefApp := nil;
|
|
|
|
|
FPrintHandler := nil;
|
2020-11-10 15:02:49 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-11-19 18:55:17 +01:00
|
|
|
|
procedure TCefCustomBrowserProcessHandler.GetCookieableSchemes(var schemes : TStringList;
|
|
|
|
|
var include_defaults : boolean);
|
|
|
|
|
begin
|
|
|
|
|
try
|
|
|
|
|
if (FCefApp <> nil) then FCefApp.Internal_GetCookieableSchemes(schemes, include_defaults);
|
|
|
|
|
except
|
|
|
|
|
on e : exception do
|
|
|
|
|
if CustomExceptionHandler('TCefCustomBrowserProcessHandler.GetCookieableSchemes', e) then raise;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
|
procedure TCefCustomBrowserProcessHandler.OnContextInitialized;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
try
|
|
|
|
|
if (FCefApp <> nil) then FCefApp.Internal_OnContextInitialized;
|
|
|
|
|
except
|
|
|
|
|
on e : exception do
|
|
|
|
|
if CustomExceptionHandler('TCefCustomBrowserProcessHandler.OnContextInitialized', e) then raise;
|
|
|
|
|
end;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefCustomBrowserProcessHandler.OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine);
|
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
try
|
|
|
|
|
if (FCefApp <> nil) then FCefApp.Internal_OnBeforeChildProcessLaunch(commandLine);
|
|
|
|
|
except
|
|
|
|
|
on e : exception do
|
|
|
|
|
if CustomExceptionHandler('TCefCustomBrowserProcessHandler.OnBeforeChildProcessLaunch', e) then raise;
|
|
|
|
|
end;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
end;
|
2021-01-01 17:51:09 +01:00
|
|
|
|
|
|
|
|
|
procedure TCefCustomBrowserProcessHandler.GetPrintHandler(var aHandler : ICefPrintHandler);
|
|
|
|
|
begin
|
|
|
|
|
if (FPrintHandler <> nil) then
|
|
|
|
|
aHandler := FPrintHandler
|
|
|
|
|
else
|
|
|
|
|
inherited GetPrintHandler(aHandler);
|
|
|
|
|
end;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
|
|
|
|
|
procedure TCefCustomBrowserProcessHandler.OnScheduleMessagePumpWork(const delayMs: Int64);
|
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
|
try
|
|
|
|
|
if (FCefApp <> nil) then FCefApp.Internal_OnScheduleMessagePumpWork(delayMs);
|
|
|
|
|
except
|
|
|
|
|
on e : exception do
|
|
|
|
|
if CustomExceptionHandler('TCefCustomBrowserProcessHandler.OnScheduleMessagePumpWork', e) then raise;
|
|
|
|
|
end;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-11-19 18:55:17 +01:00
|
|
|
|
procedure TCefCustomBrowserProcessHandler.GetDefaultClient(var aClient : ICefClient);
|
|
|
|
|
begin
|
|
|
|
|
try
|
|
|
|
|
if (FCefApp <> nil) then FCefApp.Internal_GetDefaultClient(aClient);
|
|
|
|
|
except
|
|
|
|
|
on e : exception do
|
|
|
|
|
if CustomExceptionHandler('TCefCustomBrowserProcessHandler.GetDefaultClient', e) then raise;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end.
|