From b0b39f2e9d3e0b69aaae243b5debb4bfa4cbc0e9 Mon Sep 17 00:00:00 2001 From: Salvador Diaz Fau Date: Fri, 27 Jan 2017 16:24:27 +0100 Subject: [PATCH] Add files via upload --- uCEFApplication.pas | 513 +++++++++++++++++++++++++++ uCEFAuthCallback.pas | 86 +++++ uCEFBase.pas | 172 +++++++++ uCEFBeforeDownloadCallback.pas | 81 +++++ uCEFBinaryValue.pas | 119 +++++++ uCEFBrowser.pas | 626 +++++++++++++++++++++++++++++++++ uCEFBrowserProcessHandler.pas | 125 +++++++ 7 files changed, 1722 insertions(+) create mode 100644 uCEFApplication.pas create mode 100644 uCEFAuthCallback.pas create mode 100644 uCEFBase.pas create mode 100644 uCEFBeforeDownloadCallback.pas create mode 100644 uCEFBinaryValue.pas create mode 100644 uCEFBrowser.pas create mode 100644 uCEFBrowserProcessHandler.pas diff --git a/uCEFApplication.pas b/uCEFApplication.pas new file mode 100644 index 00000000..7e277fdb --- /dev/null +++ b/uCEFApplication.pas @@ -0,0 +1,513 @@ +// ************************************************************************ +// ***************************** CEF4Delphi ******************************* +// ************************************************************************ +// +// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based +// 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 +// +// Copyright © 2017 Salvador Díaz Fau. All rights reserved. +// +// ************************************************************************ +// ************ 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 + * 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 uCEFApplication; + +{$IFNDEF CPUX64} + {$ALIGN ON} + {$MINENUMSIZE 4} +{$ENDIF} + +interface + +uses + WinApi.Windows, + uCEFTypes, uCEFInterfaces, uCEFBase; + +type + TInternalApp = class; + + TCefApplication = class + protected + FLoaded : boolean; + FMustShutDown : boolean; + FCache : ustring; + FCookies : ustring; + FUserDataPath : ustring; + FUserAgent : ustring; + FProductVersion : ustring; + FLocale : ustring; + FLogFile : ustring; + FBrowserSubprocessPath : ustring; + FLogSeverity : TCefLogSeverity; + FJavaScriptFlags : ustring; + FResourcesDirPath : ustring; + FLocalesDirPath : ustring; + FSingleProcess : Boolean; + FNoSandbox : Boolean; + FCommandLineArgsDisabled : Boolean; + FPackLoadingDisabled : Boolean; + FRemoteDebuggingPort : Integer; + FUncaughtExceptionStackSize : Integer; + FContextSafetyImplementation : Integer; + FPersistSessionCookies : Boolean; + FPersistUserPreferences : boolean; + FIgnoreCertificateErrors : Boolean; + FEnableNetSecurityExpiration : boolean; + FBackgroundColor : TCefColor; + FAcceptLanguageList : ustring; + FWindowsSandboxInfo : Pointer; + FWindowlessRenderingEnabled : Boolean; + FMultiThreadedMessageLoop : boolean; + FExternalMessagePump : boolean; + FDeleteCache : boolean; + FDeleteCookies : boolean; + FApp : TInternalApp; + FAppIntf : ICefApp; + FCustomCommandLine : ustring; + FFlashEnabled : boolean; + + procedure ShutDown; + function ExecuteProcess : integer; + procedure InitializeSettings(var aSettings : TCefSettings); + function InitializeLibrary : boolean; + function CreateInternalApp : boolean; + function MultiExeProcessing : boolean; + function SingleExeProcessing : boolean; + + procedure App_OnBeforeCommandLineProc(const processType: ustring; const commandLine: ICefCommandLine); + + public + constructor Create; + destructor Destroy; override; + function StartMainProcess : boolean; + function StartSubProcess : boolean; + + property Cache : ustring read FCache write FCache; + property Cookies : ustring read FCookies write FCookies; + property UserDataPath : ustring read FUserDataPath write FUserDataPath; + property UserAgent : ustring read FUserAgent write FUserAgent; + property ProductVersion : ustring read FProductVersion write FProductVersion; + property Locale : ustring read FLocale write FLocale; + property LogFile : ustring read FLogFile write FLogFile; + property BrowserSubprocessPath : ustring read FBrowserSubprocessPath write FBrowserSubprocessPath; + property LogSeverity : TCefLogSeverity read FLogSeverity write FLogSeverity; + property JavaScriptFlags : ustring read FJavaScriptFlags write FJavaScriptFlags; + property ResourcesDirPath : ustring read FResourcesDirPath write FResourcesDirPath; + property LocalesDirPath : ustring read FLocalesDirPath write FLocalesDirPath; + property SingleProcess : Boolean read FSingleProcess write FSingleProcess; + property NoSandbox : Boolean read FNoSandbox write FNoSandbox; + property CommandLineArgsDisabled : Boolean read FCommandLineArgsDisabled write FCommandLineArgsDisabled; + property PackLoadingDisabled : Boolean read FPackLoadingDisabled write FPackLoadingDisabled; + property RemoteDebuggingPort : Integer read FRemoteDebuggingPort write FRemoteDebuggingPort; + property UncaughtExceptionStackSize : Integer read FUncaughtExceptionStackSize write FUncaughtExceptionStackSize; + property ContextSafetyImplementation : Integer read FContextSafetyImplementation write FContextSafetyImplementation; + property PersistSessionCookies : Boolean read FPersistSessionCookies write FPersistSessionCookies; + property PersistUserPreferences : Boolean read FPersistUserPreferences write FPersistUserPreferences; + property IgnoreCertificateErrors : Boolean read FIgnoreCertificateErrors write FIgnoreCertificateErrors; + property EnableNetSecurityExpiration : boolean read FEnableNetSecurityExpiration write FEnableNetSecurityExpiration; + property BackgroundColor : TCefColor read FBackgroundColor write FBackgroundColor; + property AcceptLanguageList : ustring read FAcceptLanguageList write FAcceptLanguageList; + property WindowsSandboxInfo : Pointer read FWindowsSandboxInfo write FWindowsSandboxInfo; + property WindowlessRenderingEnabled : Boolean read FWindowlessRenderingEnabled write FWindowlessRenderingEnabled; + property MultiThreadedMessageLoop : boolean read FMultiThreadedMessageLoop write FMultiThreadedMessageLoop; + property ExternalMessagePump : boolean read FExternalMessagePump write FExternalMessagePump; + property DeleteCache : boolean read FDeleteCache write FDeleteCache; + property DeleteCookies : boolean read FDeleteCookies write FDeleteCookies; + property CustomCommandLine : ustring read FCustomCommandLine write FCustomCommandLine; + property FlashEnabled : boolean read FFlashEnabled write FFlashEnabled; + end; + + TCefAppOwn = class(TCefBaseOwn, ICefApp) + protected + procedure OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); virtual; abstract; + procedure OnRegisterCustomSchemes(const registrar: ICefSchemeRegistrar); virtual; abstract; + function GetResourceBundleHandler: ICefResourceBundleHandler; virtual; abstract; + function GetBrowserProcessHandler: ICefBrowserProcessHandler; virtual; abstract; + function GetRenderProcessHandler: ICefRenderProcessHandler; virtual; abstract; + + public + constructor Create; virtual; + end; + + TInternalApp = class(TCefAppOwn) + protected + FResourceBundleHandler : ICefResourceBundleHandler; + FBrowserProcessHandler : ICefBrowserProcessHandler; + FRenderProcessHandler : ICefRenderProcessHandler; + FOnBeforeCommandLineProcessing : TOnBeforeCommandLineProcessing; + FOnRegisterCustomSchemes : TOnRegisterCustomSchemes; + + procedure OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); override; + procedure OnRegisterCustomSchemes(const registrar: ICefSchemeRegistrar); override; + function GetResourceBundleHandler: ICefResourceBundleHandler; override; + function GetBrowserProcessHandler: ICefBrowserProcessHandler; override; + function GetRenderProcessHandler: ICefRenderProcessHandler; override; + + public + constructor Create; override; + + property ResourceBundleHandler : ICefResourceBundleHandler read FResourceBundleHandler write FResourceBundleHandler; + property BrowserProcessHandler : ICefBrowserProcessHandler read FBrowserProcessHandler write FBrowserProcessHandler; + property RenderProcessHandler : ICefRenderProcessHandler read FRenderProcessHandler write FRenderProcessHandler; + property OnBeforeCommandLineProc : TOnBeforeCommandLineProcessing read FOnBeforeCommandLineProcessing write FOnBeforeCommandLineProcessing; + property OnRegCustomSchemes : TOnRegisterCustomSchemes read FOnRegisterCustomSchemes write FOnRegisterCustomSchemes; + end; + +var + GlobalCEFApp : TCefApplication; + +implementation + +uses + System.Math, System.IOUtils, System.SysUtils, + uCEFLibFunctions, uCEFMiscFunctions, uCEFSchemeRegistrar, uCEFCommandLine; + +constructor TCefApplication.Create; +begin + inherited Create; + + FLoaded := False; + FMustShutDown := False; + FCache := ''; + FCookies := ''; + FUserDataPath := ''; + FUserAgent := ''; + FProductVersion := ''; + FLocale := ''; + FLogFile := ''; + FBrowserSubprocessPath := ''; + FLogSeverity := LOGSEVERITY_DISABLE; + FJavaScriptFlags := ''; + FResourcesDirPath := ''; + FLocalesDirPath := ''; + FSingleProcess := False; + FNoSandbox := False; + FCommandLineArgsDisabled := False; + FPackLoadingDisabled := False; + FRemoteDebuggingPort := 0; + FUncaughtExceptionStackSize := 0; + FContextSafetyImplementation := 0; + FPersistSessionCookies := False; + FPersistUserPreferences := False; + FIgnoreCertificateErrors := False; + FEnableNetSecurityExpiration := False; + FBackgroundColor := 0; + FAcceptLanguageList := ''; + FWindowsSandboxInfo := nil; + FWindowlessRenderingEnabled := False; + FMultiThreadedMessageLoop := True; + FExternalMessagePump := False; + FDeleteCache := False; + FDeleteCookies := False; + FApp := nil; + FAppIntf := nil; + FFlashEnabled := True; + FCustomCommandLine := ''; + + IsMultiThread := True; + + SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); +end; + +destructor TCefApplication.Destroy; +begin + if FLoaded then ShutDown; + + FAppIntf := nil; + FApp := nil; + + inherited Destroy; +end; + +function TCefApplication.CreateInternalApp : boolean; +begin + Result := False; + + try + if (FApp = nil) then + begin + FApp := TInternalApp.Create; + FApp.OnBeforeCommandLineProc := App_OnBeforeCommandLineProc; + FAppIntf := FApp as ICefApp; + Result := (FAppIntf <> nil); + end; + except + on e : exception do + begin + {$IFDEF DEBUG} + OutputDebugString(PWideChar('TCefApplication.CreateInternalApp error: ' + e.Message + chr(0))); + {$ENDIF} + end; + end; +end; + +function TCefApplication.MultiExeProcessing : boolean; +begin + Result := False; + + try + FLoaded := True; + FMustShutDown := True; + Result := CreateInternalApp and InitializeLibrary; + except + on e : exception do + begin + {$IFDEF DEBUG} + OutputDebugString(PWideChar('TCefApplication.MultiExeProcessing error: ' + e.Message + chr(0))); + {$ENDIF} + end; + end; +end; + +function TCefApplication.SingleExeProcessing : boolean; +begin + Result := False; + + try + FLoaded := True; + + if CreateInternalApp and (ExecuteProcess < 0) then + begin + FMustShutDown := True; + Result := InitializeLibrary; + end; + except + on e : exception do + begin + {$IFDEF DEBUG} + OutputDebugString(PWideChar('TCefApplication.SingleExeProcessing error: ' + e.Message + chr(0))); + {$ENDIF} + end; + end; +end; + +function TCefApplication.StartMainProcess : boolean; +begin + if not(FSingleProcess) and (length(FBrowserSubprocessPath) > 0) then + Result := MultiExeProcessing + else + Result := SingleExeProcessing; +end; + +function TCefApplication.StartSubProcess : boolean; +begin + Result := False; + + try + if not(FSingleProcess) then + begin + FLoaded := True; + Result := CreateInternalApp and (ExecuteProcess >= 0); + end; + except + on e : exception do + begin + {$IFDEF DEBUG} + OutputDebugString(PWideChar('TCefApplication.StartSubProcess error: ' + e.Message + chr(0))); + {$ENDIF} + end; + end; +end; + +procedure TCefApplication.ShutDown; +begin + try + if FMustShutDown then cef_shutdown; + except + on e : exception do + begin + {$IFDEF DEBUG} + OutputDebugString(PWideChar('TCefApplication.ShutDown error: ' + e.Message + chr(0))); + {$ENDIF} + end; + end; +end; + +function TCefApplication.ExecuteProcess : integer; +var + TempArgs : TCefMainArgs; +begin + TempArgs.instance := HINSTANCE; + Result := cef_execute_process(@TempArgs, CefGetData(FAppIntf), FWindowsSandboxInfo); +end; + +procedure TCefApplication.InitializeSettings(var aSettings : TCefSettings); +begin + aSettings.size := SizeOf(TCefSettings); + aSettings.single_process := Ord(FSingleProcess); + aSettings.no_sandbox := Ord(FNoSandbox); + aSettings.multi_threaded_message_loop := Ord(FMultiThreadedMessageLoop); + aSettings.external_message_pump := Ord(FExternalMessagePump); + aSettings.windowless_rendering_enabled := Ord(FWindowlessRenderingEnabled); + aSettings.cache_path := CefString(FCache); + aSettings.user_data_path := CefString(FUserDataPath); + aSettings.persist_session_cookies := Ord(FPersistSessionCookies); + aSettings.persist_user_preferences := Ord(FPersistUserPreferences); + aSettings.browser_subprocess_path := CefString(FBrowserSubprocessPath); + aSettings.command_line_args_disabled := Ord(FCommandLineArgsDisabled); + aSettings.user_agent := CefString(FUserAgent); + aSettings.product_version := CefString(FProductVersion); + aSettings.locale := CefString(FLocale); + aSettings.log_file := CefString(FLogFile); + aSettings.log_severity := FLogSeverity; + aSettings.javascript_flags := CefString(FJavaScriptFlags); + aSettings.resources_dir_path := CefString(FResourcesDirPath); + aSettings.locales_dir_path := CefString(FLocalesDirPath); + aSettings.pack_loading_disabled := Ord(FPackLoadingDisabled); + aSettings.remote_debugging_port := FRemoteDebuggingPort; + aSettings.uncaught_exception_stack_size := FUncaughtExceptionStackSize; + aSettings.context_safety_implementation := FContextSafetyImplementation; + aSettings.ignore_certificate_errors := Ord(FIgnoreCertificateErrors); + aSettings.enable_net_security_expiration := Ord(FEnableNetSecurityExpiration); + aSettings.background_color := FBackgroundColor; + aSettings.accept_language_list := CefString(FAcceptLanguageList); +end; + +function TCefApplication.InitializeLibrary : boolean; +var + TempSettings : TCefSettings; +begin + Result := False; + + try + if FDeleteCache and (length(FCache) > 0) then TDirectory.Delete(FCache, True); + if FDeleteCookies and (length(FCookies) > 0) then TDirectory.Delete(FCookies, True); + + InitializeSettings(TempSettings); + Result := (cef_initialize(@HInstance, @TempSettings, CefGetData(FAppIntf), FWindowsSandboxInfo) <> 0); + except + on e : exception do + begin + {$IFDEF DEBUG} + OutputDebugString(PWideChar('TCefApplication.InitializeLibrary error: ' + e.Message + chr(0))); + {$ENDIF} + end; + end; +end; + +procedure TCefApplication.App_OnBeforeCommandLineProc(const processType : ustring; + const commandLine : ICefCommandLine); +begin + if (commandLine <> nil) then + begin + if FFlashEnabled then + begin + commandLine.AppendSwitch('--enable-gpu-plugin'); + commandLine.AppendSwitch('--enable-accelerated-plugins'); + commandLine.AppendSwitch('--enable-system-flash'); + end; + + if (length(FCustomCommandLine) > 0) then commandLine.AppendSwitch(FCustomCommandLine); + end; +end; + +// TCefAppOwn + +procedure cef_app_on_before_command_line_processing(self: PCefApp; + const process_type: PCefString; command_line: PCefCommandLine); stdcall; +begin + with TCefAppOwn(CefGetObject(self)) do + OnBeforeCommandLineProcessing(CefString(process_type), TCefCommandLineRef.UnWrap(command_line)); +end; + +procedure cef_app_on_register_custom_schemes(self: PCefApp; registrar: PCefSchemeRegistrar); stdcall; +begin + with TCefAppOwn(CefGetObject(self)) do + OnRegisterCustomSchemes(TCefSchemeRegistrarRef.UnWrap(registrar)); +end; + +function cef_app_get_resource_bundle_handler(self: PCefApp): PCefResourceBundleHandler; stdcall; +begin + Result := CefGetData(TCefAppOwn(CefGetObject(self)).GetResourceBundleHandler()); +end; + +function cef_app_get_browser_process_handler(self: PCefApp): PCefBrowserProcessHandler; stdcall; +begin + Result := CefGetData(TCefAppOwn(CefGetObject(self)).GetBrowserProcessHandler()); +end; + +function cef_app_get_render_process_handler(self: PCefApp): PCefRenderProcessHandler; stdcall; +begin + Result := CefGetData(TCefAppOwn(CefGetObject(self)).GetRenderProcessHandler()); +end; + + +constructor TCefAppOwn.Create; +begin + inherited CreateData(SizeOf(TCefApp)); + + with PCefApp(FData)^ do + begin + on_before_command_line_processing := cef_app_on_before_command_line_processing; + on_register_custom_schemes := cef_app_on_register_custom_schemes; + get_resource_bundle_handler := cef_app_get_resource_bundle_handler; + get_browser_process_handler := cef_app_get_browser_process_handler; + get_render_process_handler := cef_app_get_render_process_handler; + end; +end; + +// TInternalApp + +procedure TInternalApp.OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); +begin + if Assigned(FOnBeforeCommandLineProcessing) then FOnBeforeCommandLineProcessing(processType, commandLine); +end; + +procedure TInternalApp.OnRegisterCustomSchemes(const registrar: ICefSchemeRegistrar); +begin + + if Assigned(FOnRegisterCustomSchemes) then FOnRegisterCustomSchemes(registrar); +end; + +function TInternalApp.GetResourceBundleHandler: ICefResourceBundleHandler; +begin + Result := FResourceBundleHandler; +end; + +function TInternalApp.GetBrowserProcessHandler: ICefBrowserProcessHandler; +begin + Result := FBrowserProcessHandler; +end; + +function TInternalApp.GetRenderProcessHandler: ICefRenderProcessHandler; +begin + Result := FRenderProcessHandler; +end; + +constructor TInternalApp.Create; +begin + inherited Create; + + FResourceBundleHandler := nil; + FBrowserProcessHandler := nil; + FRenderProcessHandler := nil; + FOnBeforeCommandLineProcessing := nil; + FOnRegisterCustomSchemes := nil; +end; + +end. diff --git a/uCEFAuthCallback.pas b/uCEFAuthCallback.pas new file mode 100644 index 00000000..3d8cf268 --- /dev/null +++ b/uCEFAuthCallback.pas @@ -0,0 +1,86 @@ +// ************************************************************************ +// ***************************** CEF4Delphi ******************************* +// ************************************************************************ +// +// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based +// 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 +// +// Copyright © 2017 Salvador Díaz Fau. All rights reserved. +// +// ************************************************************************ +// ************ 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 + * 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 uCEFAuthCallback; + +{$IFNDEF CPUX64} + {$ALIGN ON} + {$MINENUMSIZE 4} +{$ENDIF} + +interface + +uses + uCEFBase, uCEFInterfaces, uCEFTypes; + +type + TCefAuthCallbackRef = class(TCefBaseRef, ICefAuthCallback) + protected + procedure Cont(const username, password: ustring); + procedure Cancel; + + public + class function UnWrap(data: Pointer): ICefAuthCallback; + end; + +implementation + +uses + uCEFMiscFunctions, uCEFLibFunctions; + +procedure TCefAuthCallbackRef.Cancel; +begin + PCefAuthCallback(FData).cancel(PCefAuthCallback(FData)); +end; + +procedure TCefAuthCallbackRef.Cont(const username, password: ustring); +var + u, p: TCefString; +begin + u := CefString(username); + p := CefString(password); + PCefAuthCallback(FData).cont(PCefAuthCallback(FData), @u, @p); +end; + +class function TCefAuthCallbackRef.UnWrap(data: Pointer): ICefAuthCallback; +begin + if data <> nil then + Result := Create(data) as ICefAuthCallback else + Result := nil; +end; + +end. diff --git a/uCEFBase.pas b/uCEFBase.pas new file mode 100644 index 00000000..ae56e4b3 --- /dev/null +++ b/uCEFBase.pas @@ -0,0 +1,172 @@ +// ************************************************************************ +// ***************************** CEF4Delphi ******************************* +// ************************************************************************ +// +// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based +// 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 +// +// Copyright © 2017 Salvador Díaz Fau. All rights reserved. +// +// ************************************************************************ +// ************ 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 + * 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 uCEFBase; + +{$IFNDEF CPUX64} + {$ALIGN ON} + {$MINENUMSIZE 4} +{$ENDIF} + +interface + +uses + uCEFInterfaces; + +type + TCefBaseOwn = class(TInterfacedObject, ICefBase) + protected + FData: Pointer; + + public + constructor CreateData(size: Cardinal; owned: Boolean = False); virtual; + destructor Destroy; override; + function Wrap: Pointer; + end; + + TCefBaseRef = class(TInterfacedObject, ICefBase) + protected + FData: Pointer; + + public + constructor Create(data: Pointer); virtual; + destructor Destroy; override; + function Wrap: Pointer; + class function UnWrap(data: Pointer): ICefBase; + end; + +implementation + +uses + uCEFTypes, uCEFMiscFunctions; + +procedure cef_base_add_ref(self: PCefBase); stdcall; +begin + TCefBaseOwn(CefGetObject(self))._AddRef; +end; + +function cef_base_release(self: PCefBase): Integer; stdcall; +begin + Result := TCefBaseOwn(CefGetObject(self))._Release; +end; + +function cef_base_has_one_ref(self: PCefBase): Integer; stdcall; +begin + Result := Ord(TCefBaseOwn(CefGetObject(self)).FRefCount = 1); +end; + +procedure cef_base_add_ref_owned(self: PCefBase); stdcall; +begin + // +end; + +function cef_base_release_owned(self: PCefBase): Integer; stdcall; +begin + Result := 1; +end; + +function cef_base_has_one_ref_owned(self: PCefBase): Integer; stdcall; +begin + Result := 1; +end; + +constructor TCefBaseOwn.CreateData(size: Cardinal; owned: Boolean); +begin + GetMem(FData, size + SizeOf(Pointer)); + PPointer(FData)^ := Self; + Inc(PByte(FData), SizeOf(Pointer)); + FillChar(FData^, size, 0); + PCefBase(FData)^.size := size; + + if owned then + begin + PCefBase(FData)^.add_ref := cef_base_add_ref_owned; + PCefBase(FData)^.release := cef_base_release_owned; + PCefBase(FData)^.has_one_ref := cef_base_has_one_ref_owned; + end + else + begin + PCefBase(FData)^.add_ref := cef_base_add_ref; + PCefBase(FData)^.release := cef_base_release; + PCefBase(FData)^.has_one_ref := cef_base_has_one_ref; + end; +end; + +destructor TCefBaseOwn.Destroy; +begin + Dec(PByte(FData), SizeOf(Pointer)); + FreeMem(FData); + inherited; +end; + +function TCefBaseOwn.Wrap: Pointer; +begin + Result := FData; + if Assigned(PCefBase(FData)^.add_ref) then + PCefBase(FData)^.add_ref(PCefBase(FData)); +end; + +// TCefBaseRef + +constructor TCefBaseRef.Create(data: Pointer); +begin + Assert(data <> nil); + FData := data; +end; + +destructor TCefBaseRef.Destroy; +begin + if (FData <> nil) and Assigned(PCefBase(FData)^.release) then PCefBase(FData)^.release(PCefBase(FData)); + + inherited Destroy; +end; + +class function TCefBaseRef.UnWrap(data: Pointer): ICefBase; +begin + if data <> nil then + Result := Create(data) as ICefBase else + Result := nil; +end; + +function TCefBaseRef.Wrap: Pointer; +begin + Result := FData; + if Assigned(PCefBase(FData)^.add_ref) then + PCefBase(FData)^.add_ref(PCefBase(FData)); +end; + +end. diff --git a/uCEFBeforeDownloadCallback.pas b/uCEFBeforeDownloadCallback.pas new file mode 100644 index 00000000..83b85814 --- /dev/null +++ b/uCEFBeforeDownloadCallback.pas @@ -0,0 +1,81 @@ +// ************************************************************************ +// ***************************** CEF4Delphi ******************************* +// ************************************************************************ +// +// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based +// 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 +// +// Copyright © 2017 Salvador Díaz Fau. All rights reserved. +// +// ************************************************************************ +// ************ 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 + * 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 uCEFBeforeDownloadCallback; + +{$IFNDEF CPUX64} + {$ALIGN ON} + {$MINENUMSIZE 4} +{$ENDIF} + +interface + +uses + uCEFBase, uCEFInterfaces, uCEFTypes; + +type + TCefBeforeDownloadCallbackRef = class(TCefBaseRef, ICefBeforeDownloadCallback) + protected + procedure Cont(const downloadPath: ustring; showDialog: Boolean); + + public + class function UnWrap(data: Pointer): ICefBeforeDownloadCallback; + end; + +implementation + +uses + uCEFMiscFunctions, uCEFLibFunctions; + +procedure TCefBeforeDownloadCallbackRef.Cont(const downloadPath: ustring; + showDialog: Boolean); +var + dp: TCefString; +begin + dp := CefString(downloadPath); + PCefBeforeDownloadCallback(FData).cont(PCefBeforeDownloadCallback(FData), @dp, Ord(showDialog)); +end; + +class function TCefBeforeDownloadCallbackRef.UnWrap( + data: Pointer): ICefBeforeDownloadCallback; +begin + if data <> nil then + Result := Create(data) as ICefBeforeDownloadCallback else + Result := nil; +end; + +end. diff --git a/uCEFBinaryValue.pas b/uCEFBinaryValue.pas new file mode 100644 index 00000000..6e23eeda --- /dev/null +++ b/uCEFBinaryValue.pas @@ -0,0 +1,119 @@ +// ************************************************************************ +// ***************************** CEF4Delphi ******************************* +// ************************************************************************ +// +// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based +// 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 +// +// Copyright © 2017 Salvador Díaz Fau. All rights reserved. +// +// ************************************************************************ +// ************ 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 + * 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 uCEFBinaryValue; + +{$IFNDEF CPUX64} + {$ALIGN ON} + {$MINENUMSIZE 4} +{$ENDIF} + +interface + +uses + uCEFBase, uCEFInterfaces; + +type + TCefBinaryValueRef = class(TCefBaseRef, ICefBinaryValue) + protected + function IsValid: Boolean; + function IsOwned: Boolean; + function IsSame(const that: ICefBinaryValue): Boolean; + function IsEqual(const that: ICefBinaryValue): Boolean; + function Copy: ICefBinaryValue; + function GetSize: NativeUInt; + function GetData(buffer: Pointer; bufferSize, dataOffset: NativeUInt): NativeUInt; + + public + class function UnWrap(data: Pointer): ICefBinaryValue; + class function New(const data: Pointer; dataSize: NativeUInt): ICefBinaryValue; + end; + +implementation + +uses + uCEFMiscFunctions, uCEFLibFunctions, uCEFTypes; + +function TCefBinaryValueRef.Copy: ICefBinaryValue; +begin + Result := UnWrap(PCefBinaryValue(FData).copy(PCefBinaryValue(FData))); +end; + +function TCefBinaryValueRef.GetData(buffer: Pointer; bufferSize, + dataOffset: NativeUInt): NativeUInt; +begin + Result := PCefBinaryValue(FData).get_data(PCefBinaryValue(FData), buffer, bufferSize, dataOffset); +end; + +function TCefBinaryValueRef.GetSize: NativeUInt; +begin + Result := PCefBinaryValue(FData).get_size(PCefBinaryValue(FData)); +end; + +function TCefBinaryValueRef.IsEqual(const that: ICefBinaryValue): Boolean; +begin + Result := PCefBinaryValue(FData).is_equal(PCefBinaryValue(FData), CefGetData(that)) <> 0; +end; + +function TCefBinaryValueRef.IsOwned: Boolean; +begin + Result := PCefBinaryValue(FData).is_owned(PCefBinaryValue(FData)) <> 0; +end; + +function TCefBinaryValueRef.IsSame(const that: ICefBinaryValue): Boolean; +begin + Result := PCefBinaryValue(FData).is_same(PCefBinaryValue(FData), CefGetData(that)) <> 0; +end; + +function TCefBinaryValueRef.IsValid: Boolean; +begin + Result := PCefBinaryValue(FData).is_valid(PCefBinaryValue(FData)) <> 0; +end; + +class function TCefBinaryValueRef.New(const data: Pointer; dataSize: NativeUInt): ICefBinaryValue; +begin + Result := UnWrap(cef_binary_value_create(data, dataSize)); +end; + +class function TCefBinaryValueRef.UnWrap(data: Pointer): ICefBinaryValue; +begin + if data <> nil then + Result := Create(data) as ICefBinaryValue else + Result := nil; +end; + +end. diff --git a/uCEFBrowser.pas b/uCEFBrowser.pas new file mode 100644 index 00000000..891b046e --- /dev/null +++ b/uCEFBrowser.pas @@ -0,0 +1,626 @@ +// ************************************************************************ +// ***************************** CEF4Delphi ******************************* +// ************************************************************************ +// +// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based +// 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 +// +// Copyright © 2017 Salvador Díaz Fau. All rights reserved. +// +// ************************************************************************ +// ************ 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 + * 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 uCEFBrowser; + +{$IFNDEF CPUX64} + {$ALIGN ON} + {$MINENUMSIZE 4} +{$ENDIF} + +interface + +uses + System.Classes, + uCEFBase, uCEFInterfaces, uCEFTypes; + +type + TCefBrowserRef = class(TCefBaseRef, ICefBrowser) + protected + function GetHost: ICefBrowserHost; + function CanGoBack: Boolean; + procedure GoBack; + function CanGoForward: Boolean; + procedure GoForward; + function IsLoading: Boolean; + procedure Reload; + procedure ReloadIgnoreCache; + procedure StopLoad; + function GetIdentifier: Integer; + function IsSame(const that: ICefBrowser): Boolean; + function IsPopup: Boolean; + function HasDocument: Boolean; + function GetMainFrame: ICefFrame; + function GetFocusedFrame: ICefFrame; + function GetFrameByident(identifier: Int64): ICefFrame; + function GetFrame(const name: ustring): ICefFrame; + function GetFrameCount: NativeUInt; + procedure GetFrameIdentifiers(count: PNativeUInt; identifiers: PInt64); + procedure GetFrameNames(names: TStrings); + function SendProcessMessage(targetProcess: TCefProcessId; message: ICefProcessMessage): Boolean; + + public + class function UnWrap(data: Pointer): ICefBrowser; + end; + + TCefBrowserHostRef = class(TCefBaseRef, ICefBrowserHost) + protected + function GetBrowser: ICefBrowser; + procedure CloseBrowser(forceClose: Boolean); + function TryCloseBrowser: Boolean; + procedure SetFocus(focus: Boolean); + function GetWindowHandle: TCefWindowHandle; + function GetOpenerWindowHandle: TCefWindowHandle; + function HasView: Boolean; + function GetRequestContext: ICefRequestContext; + function GetZoomLevel: Double; + procedure SetZoomLevel(zoomLevel: Double); + procedure RunFileDialog(mode: TCefFileDialogMode; const title, defaultFilePath: ustring; acceptFilters: TStrings; selectedAcceptFilter: Integer; const callback: ICefRunFileDialogCallback); + procedure RunFileDialogProc(mode: TCefFileDialogMode; const title, defaultFilePath: ustring; acceptFilters: TStrings; selectedAcceptFilter: Integer; const callback: TCefRunFileDialogCallbackProc); + procedure StartDownload(const url: ustring); + procedure DownloadImage(const imageUrl: ustring; isFavicon: Boolean; maxImageSize: Cardinal; bypassCache: Boolean; const callback: ICefDownloadImageCallback); + procedure DownloadImageProc(const imageUrl: ustring; isFavicon: Boolean; maxImageSize: Cardinal; bypassCache: Boolean; const callback: TOnDownloadImageFinishedProc); + procedure Print; + procedure PrintToPdf(const path: ustring; settings: PCefPdfPrintSettings; const callback: ICefPdfPrintCallback); + procedure PrintToPdfProc(const path: ustring; settings: PCefPdfPrintSettings; const callback: TOnPdfPrintFinishedProc); + procedure Find(identifier: Integer; const searchText: ustring; forward, matchCase, findNext: Boolean); + procedure StopFinding(clearSelection: Boolean); + procedure ShowDevTools(const windowInfo: PCefWindowInfo; const client: ICefClient; const settings: PCefBrowserSettings; inspectElementAt: PCefPoint); + procedure CloseDevTools; + function HasDevTools: Boolean; + procedure GetNavigationEntries(const visitor: ICefNavigationEntryVisitor; currentOnly: Boolean); + procedure GetNavigationEntriesProc(const proc: TCefNavigationEntryVisitorProc; currentOnly: Boolean); + procedure SetMouseCursorChangeDisabled(disabled: Boolean); + function IsMouseCursorChangeDisabled: Boolean; + procedure ReplaceMisspelling(const word: ustring); + procedure AddWordToDictionary(const word: ustring); + function IsWindowRenderingDisabled: Boolean; + procedure WasResized; + procedure NotifyScreenInfoChanged; + procedure WasHidden(hidden: Boolean); + procedure Invalidate(kind: TCefPaintElementType); + procedure SendKeyEvent(const event: PCefKeyEvent); + procedure SendMouseClickEvent(const event: PCefMouseEvent; kind: TCefMouseButtonType; mouseUp: Boolean; clickCount: Integer); + procedure SendMouseMoveEvent(const event: PCefMouseEvent; mouseLeave: Boolean); + procedure SendMouseWheelEvent(const event: PCefMouseEvent; deltaX, deltaY: Integer); + procedure SendFocusEvent(setFocus: Boolean); + procedure SendCaptureLostEvent; + procedure NotifyMoveOrResizeStarted; + function GetWindowlessFrameRate(): Integer; + procedure SetWindowlessFrameRate(frameRate: Integer); + procedure IMESetComposition(const text: ustring; underlinesCount : NativeUInt; const underlines : PCefCompositionUnderline; const replacement_range, selection_range : PCefRange); + procedure IMECommitText(const text: ustring; const replacement_range : PCefRange; relative_cursor_pos : integer); + procedure IMEFinishComposingText(keep_selection : boolean); + procedure IMECancelComposition; + procedure DragTargetDragEnter(const dragData: ICefDragData; const event: PCefMouseEvent; allowedOps: TCefDragOperations); + procedure DragTargetDragOver(const event: PCefMouseEvent; allowedOps: TCefDragOperations); + procedure DragTargetDragLeave; + procedure DragTargetDrop(event: PCefMouseEvent); + procedure DragSourceEndedAt(x, y: Integer; op: TCefDragOperation); + procedure DragSourceSystemDragEnded; + function GetVisibleNavigationEntry : ICefNavigationEntry; + + public + class function UnWrap(data: Pointer): ICefBrowserHost; + end; + +implementation + +uses + uCEFMiscFunctions, uCEFLibFunctions, uCEFDownloadImageCallBack, uCEFFrame, uCEFPDFPrintCallback, + uCEFRunFileDialogCallback, uCEFRequestContext, uCEFNavigationEntryVisitor, uCEFNavigationEntry; + +function TCefBrowserRef.GetHost: ICefBrowserHost; +begin + Result := TCefBrowserHostRef.UnWrap(PCefBrowser(FData)^.get_host(PCefBrowser(FData))); +end; + +function TCefBrowserRef.CanGoBack: Boolean; +begin + Result := PCefBrowser(FData)^.can_go_back(PCefBrowser(FData)) <> 0; +end; + +function TCefBrowserRef.CanGoForward: Boolean; +begin + Result := PCefBrowser(FData)^.can_go_forward(PCefBrowser(FData)) <> 0; +end; + +function TCefBrowserRef.GetFocusedFrame: ICefFrame; +begin + Result := TCefFrameRef.UnWrap(PCefBrowser(FData)^.get_focused_frame(PCefBrowser(FData))); +end; + +function TCefBrowserRef.GetFrameByident(identifier: Int64): ICefFrame; +begin + Result := TCefFrameRef.UnWrap(PCefBrowser(FData)^.get_frame_byident(PCefBrowser(FData), identifier)); +end; + +function TCefBrowserRef.GetFrame(const name: ustring): ICefFrame; +var + n: TCefString; +begin + n := CefString(name); + Result := TCefFrameRef.UnWrap(PCefBrowser(FData)^.get_frame(PCefBrowser(FData), @n)); +end; + +function TCefBrowserRef.GetFrameCount: NativeUInt; +begin + Result := PCefBrowser(FData)^.get_frame_count(PCefBrowser(FData)); +end; + +procedure TCefBrowserRef.GetFrameIdentifiers(count: PNativeUInt; identifiers: PInt64); +begin + PCefBrowser(FData)^.get_frame_identifiers(PCefBrowser(FData), count, identifiers); +end; + +procedure TCefBrowserRef.GetFrameNames(names: TStrings); +var + list: TCefStringList; + i: Integer; + str: TCefString; +begin + list := cef_string_list_alloc; + try + PCefBrowser(FData)^.get_frame_names(PCefBrowser(FData), list); + FillChar(str, SizeOf(str), 0); + for i := 0 to cef_string_list_size(list) - 1 do + begin + FillChar(str, SizeOf(str), 0); + cef_string_list_value(list, i, @str); + names.Add(CefStringClearAndGet(str)); + end; + finally + cef_string_list_free(list); + end; +end; + +function TCefBrowserRef.SendProcessMessage(targetProcess: TCefProcessId; + message: ICefProcessMessage): Boolean; +begin + Result := PCefBrowser(FData)^.send_process_message(PCefBrowser(FData), targetProcess, CefGetData(message)) <> 0; +end; + +function TCefBrowserRef.GetMainFrame: ICefFrame; +begin + Result := TCefFrameRef.UnWrap(PCefBrowser(FData)^.get_main_frame(PCefBrowser(FData))) +end; + +procedure TCefBrowserRef.GoBack; +begin + PCefBrowser(FData)^.go_back(PCefBrowser(FData)); +end; + +procedure TCefBrowserRef.GoForward; +begin + PCefBrowser(FData)^.go_forward(PCefBrowser(FData)); +end; + +function TCefBrowserRef.IsLoading: Boolean; +begin + Result := PCefBrowser(FData)^.is_loading(PCefBrowser(FData)) <> 0; +end; + +function TCefBrowserRef.HasDocument: Boolean; +begin + Result := PCefBrowser(FData)^.has_document(PCefBrowser(FData)) <> 0; +end; + +function TCefBrowserRef.IsPopup: Boolean; +begin + Result := PCefBrowser(FData)^.is_popup(PCefBrowser(FData)) <> 0; +end; + +function TCefBrowserRef.IsSame(const that: ICefBrowser): Boolean; +begin + Result := PCefBrowser(FData)^.is_same(PCefBrowser(FData), CefGetData(that)) <> 0; +end; + +procedure TCefBrowserRef.Reload; +begin + PCefBrowser(FData)^.reload(PCefBrowser(FData)); +end; + +procedure TCefBrowserRef.ReloadIgnoreCache; +begin + PCefBrowser(FData)^.reload_ignore_cache(PCefBrowser(FData)); +end; + +procedure TCefBrowserRef.StopLoad; +begin + PCefBrowser(FData)^.stop_load(PCefBrowser(FData)); +end; + +function TCefBrowserRef.GetIdentifier: Integer; +begin + Result := PCefBrowser(FData)^.get_identifier(PCefBrowser(FData)); +end; + +class function TCefBrowserRef.UnWrap(data: Pointer): ICefBrowser; +begin + if (data <> nil) then + Result := Create(data) as ICefBrowser + else + Result := nil; +end; + +// TCefBrowserHostRef + +procedure TCefBrowserHostRef.CloseDevTools; +begin + PCefBrowserHost(FData).close_dev_tools(FData); +end; + +procedure TCefBrowserHostRef.DownloadImage(const imageUrl: ustring; + isFavicon: Boolean; maxImageSize: Cardinal; bypassCache: Boolean; + const callback: ICefDownloadImageCallback); +var + url: TCefString; +begin + url := CefString(imageUrl); + PCefBrowserHost(FData).download_image(FData, @url, Ord(isFavicon), maxImageSize, + Ord(bypassCache), CefGetData(callback)); +end; + +procedure TCefBrowserHostRef.DownloadImageProc(const imageUrl: ustring; + isFavicon: Boolean; maxImageSize: Cardinal; bypassCache: Boolean; + const callback: TOnDownloadImageFinishedProc); +begin + DownloadImage(imageUrl, isFavicon, maxImageSize, bypassCache, + TCefFastDownloadImageCallback.Create(callback)); +end; + +procedure TCefBrowserHostRef.DragSourceEndedAt(x, y: Integer; op: TCefDragOperation); +begin + PCefBrowserHost(FData).drag_source_ended_at(FData, x, y, op); +end; + +procedure TCefBrowserHostRef.DragSourceSystemDragEnded; +begin + PCefBrowserHost(FData).drag_source_system_drag_ended(FData); +end; + +function TCefBrowserHostRef.GetVisibleNavigationEntry : ICefNavigationEntry; +begin + Result := TCefNavigationEntryRef.UnWrap(PCefBrowserHost(FData).get_visible_navigation_entry(PCefBrowserHost(FData))); +end; + +procedure TCefBrowserHostRef.DragTargetDragEnter(const dragData: ICefDragData; + const event: PCefMouseEvent; allowedOps: TCefDragOperations); +begin + PCefBrowserHost(FData).drag_target_drag_enter(FData, CefGetData(dragData), event, allowedOps); +end; + +procedure TCefBrowserHostRef.DragTargetDragLeave; +begin + PCefBrowserHost(FData).drag_target_drag_leave(FData); +end; + +procedure TCefBrowserHostRef.DragTargetDragOver(const event: PCefMouseEvent; + allowedOps: TCefDragOperations); +begin + PCefBrowserHost(FData).drag_target_drag_over(FData, event, allowedOps); +end; + +procedure TCefBrowserHostRef.DragTargetDrop(event: PCefMouseEvent); +begin + PCefBrowserHost(FData).drag_target_drop(FData, event); +end; + +procedure TCefBrowserHostRef.Find(identifier: Integer; + const searchText: ustring; forward, matchCase, findNext: Boolean); +var + s: TCefString; +begin + s := CefString(searchText); + PCefBrowserHost(FData).find(FData, identifier, @s, Ord(forward), Ord(matchCase), Ord(findNext)); +end; + +function TCefBrowserHostRef.GetBrowser: ICefBrowser; +begin + Result := TCefBrowserRef.UnWrap(PCefBrowserHost(FData).get_browser(PCefBrowserHost(FData))); +end; + +procedure TCefBrowserHostRef.Print; +begin + PCefBrowserHost(FData).print(FData); +end; + +procedure TCefBrowserHostRef.PrintToPdf(const path: ustring; + settings: PCefPdfPrintSettings; const callback: ICefPdfPrintCallback); +var + str: TCefString; +begin + str := CefString(path); + PCefBrowserHost(FData).print_to_pdf(FData, @str, settings, CefGetData(callback)); +end; + +procedure TCefBrowserHostRef.PrintToPdfProc(const path: ustring; + settings: PCefPdfPrintSettings; const callback: TOnPdfPrintFinishedProc); +begin + PrintToPdf(path, settings, TCefFastPdfPrintCallback.Create(callback)); +end; + +procedure TCefBrowserHostRef.ReplaceMisspelling(const word: ustring); +var + str: TCefString; +begin + str := CefString(word); + PCefBrowserHost(FData).replace_misspelling(FData, @str); +end; + +procedure TCefBrowserHostRef.RunFileDialog(mode: TCefFileDialogMode; + const title, defaultFilePath: ustring; acceptFilters: TStrings; + selectedAcceptFilter: Integer; const callback: ICefRunFileDialogCallback); +var + t, f: TCefString; + list: TCefStringList; + item: TCefString; + i: Integer; +begin + t := CefString(title); + f := CefString(defaultFilePath); + list := cef_string_list_alloc(); + try + for i := 0 to acceptFilters.Count - 1 do + begin + item := CefString(acceptFilters[i]); + cef_string_list_append(list, @item); + end; + PCefBrowserHost(FData).run_file_dialog(PCefBrowserHost(FData), mode, @t, @f, + list, selectedAcceptFilter, CefGetData(callback)); + finally + cef_string_list_free(list); + end; +end; + +procedure TCefBrowserHostRef.RunFileDialogProc(mode: TCefFileDialogMode; + const title, defaultFilePath: ustring; acceptFilters: TStrings; + selectedAcceptFilter: Integer; const callback: TCefRunFileDialogCallbackProc); +begin + RunFileDialog(mode, title, defaultFilePath, acceptFilters, selectedAcceptFilter, + TCefFastRunFileDialogCallback.Create(callback)); +end; + +procedure TCefBrowserHostRef.AddWordToDictionary(const word: ustring); +var + str: TCefString; +begin + str := CefString(word); + PCefBrowserHost(FData).add_word_to_dictionary(FData, @str); +end; + +procedure TCefBrowserHostRef.CloseBrowser(forceClose: Boolean); +begin + PCefBrowserHost(FData).close_browser(PCefBrowserHost(FData), Ord(forceClose)); +end; + +procedure TCefBrowserHostRef.SendCaptureLostEvent; +begin + PCefBrowserHost(FData).send_capture_lost_event(FData); +end; + +procedure TCefBrowserHostRef.SendFocusEvent(setFocus: Boolean); +begin + PCefBrowserHost(FData).send_focus_event(FData, Ord(setFocus)); +end; + +procedure TCefBrowserHostRef.SendKeyEvent(const event: PCefKeyEvent); +begin + PCefBrowserHost(FData).send_key_event(FData, event); +end; + +procedure TCefBrowserHostRef.SendMouseClickEvent(const event: PCefMouseEvent; + kind: TCefMouseButtonType; mouseUp: Boolean; clickCount: Integer); +begin + PCefBrowserHost(FData).send_mouse_click_event(FData, event, kind, Ord(mouseUp), clickCount); +end; + +procedure TCefBrowserHostRef.SendMouseMoveEvent(const event: PCefMouseEvent; + mouseLeave: Boolean); +begin + PCefBrowserHost(FData).send_mouse_move_event(FData, event, Ord(mouseLeave)); +end; + +procedure TCefBrowserHostRef.SendMouseWheelEvent(const event: PCefMouseEvent; + deltaX, deltaY: Integer); +begin + PCefBrowserHost(FData).send_mouse_wheel_event(FData, event, deltaX, deltaY); +end; + +procedure TCefBrowserHostRef.SetFocus(focus: Boolean); +begin + PCefBrowserHost(FData).set_focus(PCefBrowserHost(FData), Ord(focus)); +end; + +procedure TCefBrowserHostRef.SetMouseCursorChangeDisabled(disabled: Boolean); +begin + PCefBrowserHost(FData).set_mouse_cursor_change_disabled(PCefBrowserHost(FData), Ord(disabled)); +end; + +procedure TCefBrowserHostRef.SetWindowlessFrameRate(frameRate: Integer); +begin + PCefBrowserHost(FData).set_windowless_frame_rate(PCefBrowserHost(FData), frameRate); +end; + +function TCefBrowserHostRef.GetWindowHandle: TCefWindowHandle; +begin + Result := PCefBrowserHost(FData).get_window_handle(PCefBrowserHost(FData)) +end; + +function TCefBrowserHostRef.GetWindowlessFrameRate: Integer; +begin + Result := PCefBrowserHost(FData).get_windowless_frame_rate(PCefBrowserHost(FData)); +end; + +function TCefBrowserHostRef.GetOpenerWindowHandle: TCefWindowHandle; +begin + Result := PCefBrowserHost(FData).get_opener_window_handle(PCefBrowserHost(FData)); +end; + +function TCefBrowserHostRef.GetRequestContext: ICefRequestContext; +begin + Result := TCefRequestContextRef.UnWrap(PCefBrowserHost(FData).get_request_context(FData)); +end; + +procedure TCefBrowserHostRef.GetNavigationEntries( + const visitor: ICefNavigationEntryVisitor; currentOnly: Boolean); +begin + PCefBrowserHost(FData).get_navigation_entries(FData, CefGetData(visitor), Ord(currentOnly)); +end; + +procedure TCefBrowserHostRef.GetNavigationEntriesProc( + const proc: TCefNavigationEntryVisitorProc; currentOnly: Boolean); +begin + GetNavigationEntries(TCefFastNavigationEntryVisitor.Create(proc), currentOnly); +end; + +function TCefBrowserHostRef.GetZoomLevel: Double; +begin + Result := PCefBrowserHost(FData).get_zoom_level(PCefBrowserHost(FData)); +end; + +procedure TCefBrowserHostRef.IMESetComposition(const text: ustring; underlinesCount : NativeUInt; const underlines : PCefCompositionUnderline; const replacement_range, selection_range : PCefRange); +var + TempString : TCefString; +begin + TempString := CefString(text); + PCefBrowserHost(FData).ime_set_composition(PCefBrowserHost(FData), @TempString, underlinesCount, underlines, replacement_range, selection_range); +end; + +procedure TCefBrowserHostRef.IMECommitText(const text: ustring; const replacement_range : PCefRange; relative_cursor_pos : integer); +var + TempString : TCefString; +begin + TempString := CefString(text); + PCefBrowserHost(FData).ime_commit_text(PCefBrowserHost(FData), @TempString, replacement_range, relative_cursor_pos); +end; + +procedure TCefBrowserHostRef.IMEFinishComposingText(keep_selection : boolean); +begin + PCefBrowserHost(FData).ime_finish_composing_text(PCefBrowserHost(FData), ord(keep_selection)); +end; + +procedure TCefBrowserHostRef.IMECancelComposition; +begin + PCefBrowserHost(FData).ime_cancel_composition(PCefBrowserHost(FData)); +end; + +function TCefBrowserHostRef.HasDevTools: Boolean; +begin + Result := PCefBrowserHost(FData).has_dev_tools(FData) <> 0; +end; + +function TCefBrowserHostRef.HasView: Boolean; +begin + Result := PCefBrowserHost(FData).has_view(FData) <> 0; +end; + +procedure TCefBrowserHostRef.Invalidate(kind: TCefPaintElementType); +begin + PCefBrowserHost(FData).invalidate(FData, kind); +end; + +function TCefBrowserHostRef.IsMouseCursorChangeDisabled: Boolean; +begin + Result := PCefBrowserHost(FData).is_mouse_cursor_change_disabled(FData) <> 0 +end; + +function TCefBrowserHostRef.IsWindowRenderingDisabled: Boolean; +begin + Result := PCefBrowserHost(FData).is_window_rendering_disabled(FData) <> 0 +end; + +procedure TCefBrowserHostRef.NotifyMoveOrResizeStarted; +begin + PCefBrowserHost(FData).notify_move_or_resize_started(PCefBrowserHost(FData)); +end; + +procedure TCefBrowserHostRef.NotifyScreenInfoChanged; +begin + PCefBrowserHost(FData).notify_screen_info_changed(PCefBrowserHost(FData)); +end; + +procedure TCefBrowserHostRef.SetZoomLevel(zoomLevel: Double); +begin + PCefBrowserHost(FData).set_zoom_level(PCefBrowserHost(FData), zoomLevel); +end; + +procedure TCefBrowserHostRef.ShowDevTools(const windowInfo: PCefWindowInfo; + const client: ICefClient; const settings: PCefBrowserSettings; + inspectElementAt: PCefPoint); +begin + PCefBrowserHost(FData).show_dev_tools(FData, windowInfo, CefGetData(client), + settings, inspectElementAt); +end; + +procedure TCefBrowserHostRef.StartDownload(const url: ustring); +var + u: TCefString; +begin + u := CefString(url); + PCefBrowserHost(FData).start_download(PCefBrowserHost(FData), @u); +end; + +procedure TCefBrowserHostRef.StopFinding(clearSelection: Boolean); +begin + PCefBrowserHost(FData).stop_finding(FData, Ord(clearSelection)); +end; + +function TCefBrowserHostRef.TryCloseBrowser: Boolean; +begin + Result := PCefBrowserHost(FData).try_close_browser(FData) <> 0; +end; + +class function TCefBrowserHostRef.UnWrap(data: Pointer): ICefBrowserHost; +begin + if data <> nil then + Result := Create(data) as ICefBrowserHost else + Result := nil; +end; + +procedure TCefBrowserHostRef.WasHidden(hidden: Boolean); +begin + PCefBrowserHost(FData).was_hidden(FData, Ord(hidden)); +end; + +procedure TCefBrowserHostRef.WasResized; +begin + PCefBrowserHost(FData).was_resized(FData); +end; + + +end. diff --git a/uCEFBrowserProcessHandler.pas b/uCEFBrowserProcessHandler.pas new file mode 100644 index 00000000..56530cf2 --- /dev/null +++ b/uCEFBrowserProcessHandler.pas @@ -0,0 +1,125 @@ +// ************************************************************************ +// ***************************** CEF4Delphi ******************************* +// ************************************************************************ +// +// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based +// 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 +// +// Copyright © 2017 Salvador Díaz Fau. All rights reserved. +// +// ************************************************************************ +// ************ 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 + * 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; + +{$IFNDEF CPUX64} + {$ALIGN ON} + {$MINENUMSIZE 4} +{$ENDIF} + +interface + +uses + uCEFBase, uCEFInterfaces, uCEFTypes; + +type + TCefBrowserProcessHandlerOwn = class(TCefBaseOwn, ICefBrowserProcessHandler) + protected + procedure OnContextInitialized; virtual; + procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); virtual; + procedure OnRenderProcessThreadCreated(const extraInfo: ICefListValue); virtual; + procedure OnScheduleMessagePumpWork(delayMs: Int64); virtual; + public + constructor Create; virtual; + end; + +implementation + +uses + uCEFMiscFunctions, uCEFLibFunctions, uCEFCommandLine, uCEFListValue; + +procedure cef_browser_process_handler_on_context_initialized(self: PCefBrowserProcessHandler); stdcall; +begin + with TCefBrowserProcessHandlerOwn(CefGetObject(self)) do + OnContextInitialized; +end; + +procedure cef_browser_process_handler_on_before_child_process_launch( + self: PCefBrowserProcessHandler; command_line: PCefCommandLine); stdcall; +begin + with TCefBrowserProcessHandlerOwn(CefGetObject(self)) do + OnBeforeChildProcessLaunch(TCefCommandLineRef.UnWrap(command_line)); +end; + +procedure cef_browser_process_handler_on_render_process_thread_created( + self: PCefBrowserProcessHandler; extra_info: PCefListValue); stdcall; +begin + with TCefBrowserProcessHandlerOwn(CefGetObject(self)) do + OnRenderProcessThreadCreated(TCefListValueRef.UnWrap(extra_info)); +end; + +procedure cef_browser_process_handler_on_schedule_message_pump_work(self: PCefBrowserProcessHandler; delay_ms: Int64); stdcall; +begin + TCefBrowserProcessHandlerOwn(CefGetObject(self)).OnScheduleMessagePumpWork(delay_ms); +end; + +constructor TCefBrowserProcessHandlerOwn.Create; +begin + inherited CreateData(SizeOf(TCefBrowserProcessHandler)); + + with PCefBrowserProcessHandler(FData)^ do + begin + on_context_initialized := cef_browser_process_handler_on_context_initialized; + on_before_child_process_launch := cef_browser_process_handler_on_before_child_process_launch; + on_render_process_thread_created := cef_browser_process_handler_on_render_process_thread_created; + get_print_handler := nil; // linux + on_schedule_message_pump_work := cef_browser_process_handler_on_schedule_message_pump_work; + end; +end; + +procedure TCefBrowserProcessHandlerOwn.OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); +begin + +end; + +procedure TCefBrowserProcessHandlerOwn.OnContextInitialized; +begin + +end; + +procedure TCefBrowserProcessHandlerOwn.OnRenderProcessThreadCreated(const extraInfo: ICefListValue); +begin + +end; + +procedure TCefBrowserProcessHandlerOwn.OnScheduleMessagePumpWork(delayMs: Int64); +begin + +end; + +end.