2017-01-27 17:37:51 +02:00
unit uCEFRequestContext;
2018-05-12 14:50:54 +02:00
{$IFDEF FPC}
{$MODE OBJFPC} {$H+}
{$ENDIF}
2017-02-05 21:56:46 +02:00
{$I cef.inc}
2022-02-19 19:56:41 +02:00
{$IFNDEF TARGET_64BITS} {$ALIGN ON} {$ENDIF}
{$MINENUMSIZE 4}
2017-01-27 17:37:51 +02:00
interface
uses
2017-02-05 21:56:46 +02:00
{$IFDEF DELPHI16_UP}
2018-02-26 19:40:51 +02:00
System. Classes, System. SysUtils,
2017-02-05 21:56:46 +02:00
{$ELSE}
2018-02-26 19:40:51 +02:00
Classes, SysUtils,
2017-02-05 21:56:46 +02:00
{$ENDIF}
2022-12-16 12:29:15 +02:00
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFCompletionCallback, uCEFPreferenceManager;
2017-01-27 17:37:51 +02:00
type
2023-07-30 18:47:35 +02:00
/// <summary>
/// A request context provides request handling for a set of related browser or
/// URL request objects. A request context can be specified when creating a new
/// browser via the cef_browser_host_t static factory functions or when creating
/// a new URL request via the cef_urlrequest_t static factory functions. Browser
/// objects with different request contexts will never be hosted in the same
/// render process. Browser objects with the same request context may or may not
/// be hosted in the same render process depending on the process model. Browser
/// objects created indirectly via the JavaScript window.open function or
/// targeted links will share the same render process and the same request
/// context as the source browser. When running in single-process mode there is
/// only a single render process (the main process) and so all browsers created
/// in single-process mode will share the same request context. This will be the
/// first request context passed into a cef_browser_host_t static factory
/// function and all other request context objects will be ignored.
/// </summary>
2022-12-16 12:29:15 +02:00
TCefRequestContextRef = class( TCefPreferenceManagerRef, ICefRequestContext)
2017-01-27 17:37:51 +02:00
protected
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns true (1) if this object is pointing to the same context as |that|
/// object.
/// </summary>
2017-10-26 13:23:13 +02:00
function IsSame( const other: ICefRequestContext) : Boolean ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns true (1) if this object is sharing the same storage as |that|
/// object.
/// </summary>
2017-10-26 13:23:13 +02:00
function IsSharingWith( const other: ICefRequestContext) : Boolean ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns true (1) if this object is the global context. The global context
/// is used by default when creating a browser or URL request with a NULL
/// context argument.
/// </summary>
2017-10-26 13:23:13 +02:00
function IsGlobal: Boolean ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns the handler for this context if any.
/// </summary>
2017-10-26 13:23:13 +02:00
function GetHandler: ICefRequestContextHandler;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns the cache path for this object. If NULL an "incognito mode" in-
/// memory cache is being used.
/// </summary>
2017-10-26 13:23:13 +02:00
function GetCachePath: ustring;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns the cookie manager for this object. If |callback| is non-NULL it
/// will be executed asnychronously on the UI thread after the manager's
/// storage has been initialized.
/// </summary>
2019-06-16 10:31:13 +02:00
function GetCookieManager( const callback: ICefCompletionCallback) : ICefCookieManager;
function GetCookieManagerProc( const callback: TCefCompletionCallbackProc) : ICefCookieManager;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Register a scheme handler factory for the specified |scheme_name| and
/// optional |domain_name|. An NULL |domain_name| value for a standard scheme
/// will cause the factory to match all domain names. The |domain_name| value
/// will be ignored for non-standard schemes. If |scheme_name| is a built-in
/// scheme and no handler is returned by |factory| then the built-in scheme
/// handler factory will be called. If |scheme_name| is a custom scheme then
/// you must also implement the cef_app_t::on_register_custom_schemes()
/// function in all processes. This function may be called multiple times to
/// change or remove the factory that matches the specified |scheme_name| and
/// optional |domain_name|. Returns false (0) if an error occurs. This
/// function may be called on any thread in the browser process.
/// </summary>
2017-10-26 13:23:13 +02:00
function RegisterSchemeHandlerFactory( const schemeName, domainName: ustring; const factory: ICefSchemeHandlerFactory) : Boolean ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Clear all registered scheme handler factories. Returns false (0) on error.
/// This function may be called on any thread in the browser process.
/// </summary>
2017-10-26 13:23:13 +02:00
function ClearSchemeHandlerFactories: Boolean ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Clears all certificate exceptions that were added as part of handling
/// cef_request_handler_t::on_certificate_error(). If you call this it is
/// recommended that you also call close_all_connections() or you risk not
/// being prompted again for server certificates if you reconnect quickly. If
/// |callback| is non-NULL it will be executed on the UI thread after
/// completion.
/// </summary>
2017-01-27 17:37:51 +02:00
procedure ClearCertificateExceptions( const callback: ICefCompletionCallback) ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Clears all HTTP authentication credentials that were added as part of
/// handling GetAuthCredentials. If |callback| is non-NULL it will be executed
/// on the UI thread after completion.
/// </summary>
2019-07-18 11:48:11 +02:00
procedure ClearHttpAuthCredentials( const callback: ICefCompletionCallback) ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Clears all active and idle connections that Chromium currently has. This
/// is only recommended if you have released all other CEF objects but don't
/// yet want to call cef_shutdown(). If |callback| is non-NULL it will be
/// executed on the UI thread after completion.
/// </summary>
2017-01-27 17:37:51 +02:00
procedure CloseAllConnections( const callback: ICefCompletionCallback) ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Attempts to resolve |origin| to a list of associated IP addresses.
/// |callback| will be executed on the UI thread after completion.
/// </summary>
2017-01-27 17:37:51 +02:00
procedure ResolveHost( const origin: ustring; const callback: ICefResolveCallback) ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Load an extension.
///
/// If extension resources will be read from disk using the default load
/// implementation then |root_directory| should be the absolute path to the
/// extension resources directory and |manifest| should be NULL. If extension
/// resources will be provided by the client (e.g. via cef_request_handler_t
/// and/or cef_extension_handler_t) then |root_directory| should be a path
/// component unique to the extension (if not absolute this will be internally
/// prefixed with the PK_DIR_RESOURCES path) and |manifest| should contain the
/// contents that would otherwise be read from the "manifest.json" file on
/// disk.
///
/// The loaded extension will be accessible in all contexts sharing the same
/// storage (HasExtension returns true (1)). However, only the context on
/// which this function was called is considered the loader (DidLoadExtension
/// returns true (1)) and only the loader will receive
/// cef_request_context_handler_t callbacks for the extension.
///
/// cef_extension_handler_t::OnExtensionLoaded will be called on load success
/// or cef_extension_handler_t::OnExtensionLoadFailed will be called on load
/// failure.
///
/// If the extension specifies a background script via the "background"
/// manifest key then cef_extension_handler_t::OnBeforeBackgroundBrowser will
/// be called to create the background browser. See that function for
/// additional information about background scripts.
///
/// For visible extension views the client application should evaluate the
/// manifest to determine the correct extension URL to load and then pass that
/// URL to the cef_browser_host_t::CreateBrowser* function after the extension
/// has loaded. For example, the client can look for the "browser_action"
/// manifest key as documented at
/// https://developer.chrome.com/extensions/browserAction. Extension URLs take
/// the form "chrome-extension://<extension_id>/<path>".
///
/// Browsers that host extensions differ from normal browsers as follows:
/// - Can access chrome.* JavaScript APIs if allowed by the manifest. Visit
/// chrome://extensions-support for the list of extension APIs currently
/// supported by CEF.
/// - Main frame navigation to non-extension content is blocked.
/// - Pinch-zooming is disabled.
/// - CefBrowserHost::GetExtension returns the hosted extension.
/// - CefBrowserHost::IsBackgroundHost returns true for background hosts.
///
/// See https://developer.chrome.com/extensions for extension implementation
/// and usage documentation.
/// </summary>
2017-10-26 13:23:13 +02:00
procedure LoadExtension( const root_directory: ustring; const manifest: ICefDictionaryValue; const handler: ICefExtensionHandler) ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns true (1) if this context was used to load the extension identified
/// by |extension_id|. Other contexts sharing the same storage will also have
/// access to the extension (see HasExtension). This function must be called
/// on the browser process UI thread.
/// </summary>
2017-10-26 13:23:13 +02:00
function DidLoadExtension( const extension_id: ustring) : boolean ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns true (1) if this context has access to the extension identified by
/// |extension_id|. This may not be the context that was used to load the
/// extension (see DidLoadExtension). This function must be called on the
/// browser process UI thread.
/// </summary>
2017-10-26 13:23:13 +02:00
function HasExtension( const extension_id: ustring) : boolean ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Retrieve the list of all extensions that this context has access to (see
/// HasExtension). |extension_ids| will be populated with the list of
/// extension ID values. Returns true (1) on success. This function must be
/// called on the browser process UI thread.
/// </summary>
2017-10-26 13:23:13 +02:00
function GetExtensions( const extension_ids: TStringList) : boolean ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns the extension matching |extension_id| or NULL if no matching
/// extension is accessible in this context (see HasExtension). This function
/// must be called on the browser process UI thread.
2023-09-24 11:21:05 +02:00
/// </summary>
2017-10-26 13:23:13 +02:00
function GetExtension( const extension_id: ustring) : ICefExtension;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns the MediaRouter object associated with this context. If
/// |callback| is non-NULL it will be executed asnychronously on the UI thread
/// after the manager's context has been initialized.
/// </summary>
2021-04-18 19:36:20 +02:00
function GetMediaRouter( const callback: ICefCompletionCallback) : ICefMediaRouter;
2017-01-27 17:37:51 +02:00
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns the current value for |content_type| that applies for the
/// specified URLs. If both URLs are NULL the default value will be returned.
/// Returns nullptr if no value is configured. Must be called on the browser
/// process UI thread.
/// </summary>
function GetWebsiteSetting( const requesting_url, top_level_url: ustring; content_type: TCefContentSettingTypes) : ICefValue;
/// <summary>
/// Sets the current value for |content_type| for the specified URLs in the
/// default scope. If both URLs are NULL, and the context is not incognito,
/// the default value will be set. Pass nullptr for |value| to remove the
/// default value for this content type.
///
/// WARNING: Incorrect usage of this function may cause instability or
/// security issues in Chromium. Make sure that you first understand the
/// potential impact of any changes to |content_type| by reviewing the related
/// source code in Chromium. For example, if you plan to modify
/// CEF_CONTENT_SETTING_TYPE_POPUPS, first review and understand the usage of
/// ContentSettingsType::POPUPS in Chromium:
/// https://source.chromium.org/search?q=ContentSettingsType::POPUPS
/// </summary>
procedure SetWebsiteSetting( const requesting_url, top_level_url: ustring; content_type: TCefContentSettingTypes; const value: ICefValue) ;
/// <summary>
/// Returns the current value for |content_type| that applies for the
/// specified URLs. If both URLs are NULL the default value will be returned.
/// Returns CEF_CONTENT_SETTING_VALUE_DEFAULT if no value is configured. Must
/// be called on the browser process UI thread.
/// </summary>
function GetContentSetting( const requesting_url, top_level_url: ustring; content_type: TCefContentSettingTypes) : TCefContentSettingValues;
/// <summary>
/// Sets the current value for |content_type| for the specified URLs in the
/// default scope. If both URLs are NULL, and the context is not incognito,
/// the default value will be set. Pass CEF_CONTENT_SETTING_VALUE_DEFAULT for
/// |value| to use the default value for this content type.
///
/// WARNING: Incorrect usage of this function may cause instability or
/// security issues in Chromium. Make sure that you first understand the
/// potential impact of any changes to |content_type| by reviewing the related
/// source code in Chromium. For example, if you plan to modify
/// CEF_CONTENT_SETTING_TYPE_POPUPS, first review and understand the usage of
/// ContentSettingsType::POPUPS in Chromium:
/// https://source.chromium.org/search?q=ContentSettingsType::POPUPS
/// </summary>
procedure SetContentSetting( const requesting_url, top_level_url: ustring; content_type: TCefContentSettingTypes; value: TCefContentSettingValues) ;
2017-01-27 17:37:51 +02:00
public
2022-12-16 12:29:15 +02:00
class function UnWrap( data: Pointer ) : ICefRequestContext; reintroduce ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Returns the global context object.
/// </summary>
2022-12-16 12:29:15 +02:00
class function Global: ICefRequestContext; reintroduce ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Creates a new context object with the specified |settings| and optional
/// |handler|.
/// </summary>
2023-12-15 19:06:46 +02:00
/// <param name="settings">Pointer to TCefRequestContextSettings.</param>
/// <param name="handler">Optional handler for the request context.</param>
2017-09-29 18:42:12 +02:00
class function New( const settings: PCefRequestContextSettings; const handler: ICefRequestContextHandler = nil ) : ICefRequestContext; overload ;
2023-12-15 19:06:46 +02:00
/// <summary>
/// Creates a new context object with the specified settings and optional
/// |handler|.
/// </summary>
/// <param name="aCache">The directory where cache data for this request context will be stored on disk. See TCefRequestContextSettings.cache_path for more information.</param>
/// <param name="aAcceptLanguageList">Comma delimited ordered list of language codes without any whitespace that will be used in the "Accept-Language" HTTP header. See TCefRequestContextSettings.accept_language_list for more information.</param>
/// <param name="aCookieableSchemesList">Comma delimited list of schemes supported by the associated ICefCookieManager. See TCefRequestContextSettings.cookieable_schemes_list for more information.</param>
/// <param name="aCookieableSchemesExcludeDefaults">Setting this parameter to true will disable all loading and saving of cookies. See TCefRequestContextSettings.cookieable_schemes_list for more information.</param>
/// <param name="aPersistSessionCookies">To persist session cookies (cookies without an expiry date or validity interval) by default when using the global cookie manager set this value to true. See TCefRequestContextSettings.persist_session_cookies for more information.</param>
/// <param name="aPersistUserPreferences">To persist user preferences as a JSON file in the cache path directory set this value to true. See TCefRequestContextSettings.persist_user_preferences for more information.</param>
/// <param name="handler">Optional handler for the request context.</param>
2021-10-22 19:19:57 +02:00
class function New( const aCache, aAcceptLanguageList, aCookieableSchemesList : ustring; aCookieableSchemesExcludeDefaults, aPersistSessionCookies, aPersistUserPreferences : boolean ; const handler: ICefRequestContextHandler = nil ) : ICefRequestContext; overload ;
2023-07-30 18:47:35 +02:00
/// <summary>
/// Creates a new context object that shares storage with |other| and uses an
/// optional |handler|.
/// </summary>
2023-12-15 19:06:46 +02:00
/// <param name="other">Another ICefRequestContext instance that will share storage with the new ICefRequestContext instance.</param>
/// <param name="handler">Optional handler for the request context.</param>
2017-01-27 17:37:51 +02:00
class function Shared( const other: ICefRequestContext; const handler: ICefRequestContextHandler) : ICefRequestContext;
end ;
2019-10-08 15:03:22 +02:00
TCefClearCertificateExceptionsCompletionCallback = class( TCefCustomCompletionCallback)
protected
procedure OnComplete; override ;
end ;
TCefClearHttpAuthCredentialsCompletionCallback = class( TCefCustomCompletionCallback)
protected
procedure OnComplete; override ;
end ;
TCefCloseAllConnectionsCompletionCallback = class( TCefCustomCompletionCallback)
protected
procedure OnComplete; override ;
end ;
2017-01-27 17:37:51 +02:00
implementation
uses
2022-12-16 12:29:15 +02:00
uCEFMiscFunctions, uCEFLibFunctions, uCEFCookieManager, uCEFRequestContextHandler,
2023-07-30 18:47:35 +02:00
uCEFExtension, uCEFStringList, uCEFMediaRouter, uCEFValue;
2017-01-27 17:37:51 +02:00
function TCefRequestContextRef. ClearSchemeHandlerFactories: Boolean ;
begin
2018-05-12 14:50:54 +02:00
Result : = PCefRequestContext( FData) ^ . clear_scheme_handler_factories( PCefRequestContext( FData) ) < > 0 ;
2017-01-27 17:37:51 +02:00
end ;
function TCefRequestContextRef. GetCachePath: ustring;
begin
2018-05-12 14:50:54 +02:00
Result : = CefStringFreeAndGet( PCefRequestContext( FData) ^ . get_cache_path( PCefRequestContext( FData) ) ) ;
2017-01-27 17:37:51 +02:00
end ;
2019-06-16 10:31:13 +02:00
function TCefRequestContextRef. GetCookieManager( const callback: ICefCompletionCallback) : ICefCookieManager;
2017-01-27 17:37:51 +02:00
begin
2019-06-16 10:31:13 +02:00
Result : = TCefCookieManagerRef. UnWrap( PCefRequestContext( FData) ^ . get_cookie_manager( PCefRequestContext( FData) , CefGetData( callback) ) ) ;
2017-01-27 17:37:51 +02:00
end ;
2019-06-16 10:31:13 +02:00
function TCefRequestContextRef. GetCookieManagerProc( const callback: TCefCompletionCallbackProc) : ICefCookieManager;
2017-01-27 17:37:51 +02:00
begin
2019-06-16 10:31:13 +02:00
Result : = GetCookieManager( TCefFastCompletionCallback. Create( callback) ) ;
2017-01-27 17:37:51 +02:00
end ;
function TCefRequestContextRef. GetHandler: ICefRequestContextHandler;
2019-11-24 19:19:49 +02:00
var
TempHandler : PCefRequestContextHandler;
2017-01-27 17:37:51 +02:00
begin
2019-11-24 19:19:49 +02:00
TempHandler : = PCefRequestContext( FData) ^ . get_handler( PCefRequestContext( FData) ) ;
if ( TempHandler < > nil ) then
Result : = TCefRequestContextHandlerRef. UnWrap( TempHandler)
else
Result : = nil ;
2017-01-27 17:37:51 +02:00
end ;
class function TCefRequestContextRef. Global: ICefRequestContext;
begin
2017-10-26 13:23:13 +02:00
Result : = UnWrap( cef_request_context_get_global_context( ) ) ;
2017-01-27 17:37:51 +02:00
end ;
function TCefRequestContextRef. IsGlobal: Boolean ;
begin
2018-05-12 14:50:54 +02:00
Result : = PCefRequestContext( FData) ^ . is_global( PCefRequestContext( FData) ) < > 0 ;
2017-01-27 17:37:51 +02:00
end ;
function TCefRequestContextRef. IsSame( const other: ICefRequestContext) : Boolean ;
begin
2018-05-12 14:50:54 +02:00
Result : = PCefRequestContext( FData) ^ . is_same( PCefRequestContext( FData) , CefGetData( other) ) < > 0 ;
2017-01-27 17:37:51 +02:00
end ;
2017-10-26 13:23:13 +02:00
function TCefRequestContextRef. IsSharingWith( const other: ICefRequestContext) : Boolean ;
2017-01-27 17:37:51 +02:00
begin
2018-05-12 14:50:54 +02:00
Result : = PCefRequestContext( FData) ^ . is_sharing_with( PCefRequestContext( FData) , CefGetData( other) ) < > 0 ;
2017-01-27 17:37:51 +02:00
end ;
2019-09-10 13:09:14 +02:00
class function TCefRequestContextRef. New( const settings : PCefRequestContextSettings;
const handler : ICefRequestContextHandler) : ICefRequestContext;
2017-01-27 17:37:51 +02:00
begin
Result : = UnWrap( cef_request_context_create_context( settings, CefGetData( handler) ) ) ;
end ;
2021-04-18 19:36:20 +02:00
class function TCefRequestContextRef. New( const aCache : ustring;
const aAcceptLanguageList : ustring;
const aCookieableSchemesList : ustring;
aCookieableSchemesExcludeDefaults : boolean ;
aPersistSessionCookies : boolean ;
aPersistUserPreferences : boolean ;
const handler : ICefRequestContextHandler) : ICefRequestContext;
2017-09-29 18:42:12 +02:00
var
TempSettings : TCefRequestContextSettings;
begin
2021-04-18 19:36:20 +02:00
TempSettings. size : = SizeOf( TCefRequestContextSettings) ;
TempSettings. cache_path : = CefString( aCache) ;
TempSettings. persist_session_cookies : = Ord( aPersistSessionCookies) ;
TempSettings. persist_user_preferences : = Ord( aPersistUserPreferences) ;
TempSettings. accept_language_list : = CefString( aAcceptLanguageList) ;
TempSettings. cookieable_schemes_list : = CefString( aCookieableSchemesList) ;
TempSettings. cookieable_schemes_exclude_defaults : = Ord( aCookieableSchemesExcludeDefaults) ;
2017-09-29 18:42:12 +02:00
Result : = UnWrap( cef_request_context_create_context( @ TempSettings, CefGetData( handler) ) ) ;
end ;
2017-01-27 17:37:51 +02:00
procedure TCefRequestContextRef. ClearCertificateExceptions( const callback: ICefCompletionCallback) ;
begin
2018-05-12 14:50:54 +02:00
PCefRequestContext( FData) ^ . clear_certificate_exceptions( PCefRequestContext( FData) , CefGetData( callback) ) ;
2017-01-27 17:37:51 +02:00
end ;
2019-07-18 11:48:11 +02:00
procedure TCefRequestContextRef. ClearHttpAuthCredentials( const callback: ICefCompletionCallback) ;
begin
PCefRequestContext( FData) ^ . clear_http_auth_credentials( PCefRequestContext( FData) , CefGetData( callback) ) ;
end ;
2017-01-27 17:37:51 +02:00
procedure TCefRequestContextRef. CloseAllConnections( const callback: ICefCompletionCallback) ;
begin
2018-05-12 14:50:54 +02:00
PCefRequestContext( FData) ^ . close_all_connections( PCefRequestContext( FData) , CefGetData( callback) ) ;
2017-01-27 17:37:51 +02:00
end ;
2017-10-26 13:23:13 +02:00
procedure TCefRequestContextRef. ResolveHost( const origin : ustring;
const callback : ICefResolveCallback) ;
2017-01-27 17:37:51 +02:00
var
2018-05-12 14:50:54 +02:00
TempOrigin : TCefString;
2017-01-27 17:37:51 +02:00
begin
2018-05-12 14:50:54 +02:00
TempOrigin : = CefString( origin) ;
PCefRequestContext( FData) ^ . resolve_host( PCefRequestContext( FData) , @ TempOrigin, CefGetData( callback) ) ;
2017-01-27 17:37:51 +02:00
end ;
2017-10-26 13:23:13 +02:00
procedure TCefRequestContextRef. LoadExtension( const root_directory: ustring; const manifest: ICefDictionaryValue; const handler: ICefExtensionHandler) ;
var
TempDir : TCefString;
begin
TempDir : = CefString( root_directory) ;
2018-05-12 14:50:54 +02:00
PCefRequestContext( FData) ^ . load_extension( PCefRequestContext( FData) , @ TempDir, CefGetData( manifest) , CefGetData( handler) ) ;
2017-10-26 13:23:13 +02:00
end ;
function TCefRequestContextRef. DidLoadExtension( const extension_id: ustring) : boolean ;
var
TempID : TCefString;
begin
TempID : = CefString( extension_id) ;
2018-05-12 14:50:54 +02:00
Result : = PCefRequestContext( FData) ^ . did_load_extension( PCefRequestContext( FData) , @ TempID) < > 0 ;
2017-10-26 13:23:13 +02:00
end ;
function TCefRequestContextRef. HasExtension( const extension_id: ustring) : boolean ;
var
TempID : TCefString;
begin
TempID : = CefString( extension_id) ;
2018-05-12 14:50:54 +02:00
Result : = PCefRequestContext( FData) ^ . has_extension( PCefRequestContext( FData) , @ TempID) < > 0 ;
2017-10-26 13:23:13 +02:00
end ;
function TCefRequestContextRef. GetExtensions( const extension_ids: TStringList) : boolean ;
var
2018-03-29 20:02:04 +02:00
TempSL : ICefStringList;
2017-10-26 13:23:13 +02:00
begin
2018-03-29 20:02:04 +02:00
Result : = False ;
TempSL : = TCefStringListOwn. Create;
2018-05-12 14:50:54 +02:00
if ( PCefRequestContext( FData) ^ . get_extensions( PCefRequestContext( FData) , TempSL. Handle) < > 0 ) then
2018-03-29 20:02:04 +02:00
begin
TempSL. CopyToStrings( extension_ids) ;
Result : = True ;
2018-02-26 19:40:51 +02:00
end ;
2017-01-27 17:37:51 +02:00
end ;
2017-10-26 13:23:13 +02:00
function TCefRequestContextRef. GetExtension( const extension_id: ustring) : ICefExtension;
var
TempID : TCefString;
begin
TempID : = CefString( extension_id) ;
2018-05-12 14:50:54 +02:00
Result : = TCefExtensionRef. UnWrap( PCefRequestContext( FData) ^ . get_extension( PCefRequestContext( FData) , @ TempID) ) ;
2017-10-26 13:23:13 +02:00
end ;
2021-04-18 19:36:20 +02:00
function TCefRequestContextRef. GetMediaRouter( const callback: ICefCompletionCallback) : ICefMediaRouter;
2020-03-29 17:31:42 +02:00
begin
2021-04-18 19:36:20 +02:00
Result : = TCefMediaRouterRef. UnWrap( PCefRequestContext( FData) ^ . get_media_router( PCefRequestContext( FData) , CefGetData( callback) ) ) ;
2020-03-29 17:31:42 +02:00
end ;
2023-07-30 18:47:35 +02:00
function TCefRequestContextRef. GetWebsiteSetting( const requesting_url, top_level_url: ustring; content_type: TCefContentSettingTypes) : ICefValue;
var
TempRequestingURL, TempTopLevelURL : TCefString;
begin
TempRequestingURL : = CefString( requesting_url) ;
TempTopLevelURL : = CefString( top_level_url) ;
Result : = TCefValueRef. UnWrap( PCefRequestContext( FData) ^ . get_website_setting( PCefRequestContext( FData) , @ TempRequestingURL, @ TempTopLevelURL, content_type) ) ;
end ;
procedure TCefRequestContextRef. SetWebsiteSetting( const requesting_url, top_level_url: ustring; content_type: TCefContentSettingTypes; const value: ICefValue) ;
var
TempRequestingURL, TempTopLevelURL : TCefString;
begin
TempRequestingURL : = CefString( requesting_url) ;
TempTopLevelURL : = CefString( top_level_url) ;
PCefRequestContext( FData) ^ . set_website_setting( PCefRequestContext( FData) , @ TempRequestingURL, @ TempTopLevelURL, content_type, CefGetData( value) ) ;
end ;
function TCefRequestContextRef. GetContentSetting( const requesting_url, top_level_url: ustring; content_type: TCefContentSettingTypes) : TCefContentSettingValues;
var
TempRequestingURL, TempTopLevelURL : TCefString;
begin
TempRequestingURL : = CefString( requesting_url) ;
TempTopLevelURL : = CefString( top_level_url) ;
Result : = PCefRequestContext( FData) ^ . get_content_setting( PCefRequestContext( FData) , @ TempRequestingURL, @ TempTopLevelURL, content_type) ;
end ;
procedure TCefRequestContextRef. SetContentSetting( const requesting_url, top_level_url: ustring; content_type: TCefContentSettingTypes; value: TCefContentSettingValues) ;
var
TempRequestingURL, TempTopLevelURL : TCefString;
begin
TempRequestingURL : = CefString( requesting_url) ;
TempTopLevelURL : = CefString( top_level_url) ;
PCefRequestContext( FData) ^ . set_content_setting( PCefRequestContext( FData) , @ TempRequestingURL, @ TempTopLevelURL, content_type, value) ;
end ;
2017-10-26 13:23:13 +02:00
function TCefRequestContextRef. RegisterSchemeHandlerFactory( const schemeName : ustring;
const domainName : ustring;
const factory : ICefSchemeHandlerFactory) : Boolean ;
2017-01-27 17:37:51 +02:00
var
2018-05-12 14:50:54 +02:00
TempScheme, TempDomain : TCefString;
2017-01-27 17:37:51 +02:00
begin
2018-05-12 14:50:54 +02:00
TempScheme : = CefString( schemeName) ;
TempDomain : = CefString( domainName) ;
Result : = PCefRequestContext( FData) ^ . register_scheme_handler_factory( PCefRequestContext( FData) ,
@ TempScheme,
@ TempDomain,
CefGetData( factory) ) < > 0 ;
2017-01-27 17:37:51 +02:00
end ;
2017-10-26 13:23:13 +02:00
class function TCefRequestContextRef. Shared( const other : ICefRequestContext;
const handler : ICefRequestContextHandler) : ICefRequestContext;
2017-01-27 17:37:51 +02:00
begin
Result : = UnWrap( cef_create_context_shared( CefGetData( other) , CefGetData( handler) ) ) ;
end ;
class function TCefRequestContextRef. UnWrap( data: Pointer ) : ICefRequestContext;
begin
2017-10-26 13:23:13 +02:00
if ( data < > nil ) then
Result : = Create( data) as ICefRequestContext
else
2017-01-27 17:37:51 +02:00
Result : = nil ;
end ;
2019-10-08 15:03:22 +02:00
// TCefClearCertificateExceptionsCompletionCallback
procedure TCefClearCertificateExceptionsCompletionCallback. OnComplete;
begin
try
try
if ( FEvents < > nil ) then IChromiumEvents( FEvents) . doCertificateExceptionsCleared;
except
on e : exception do
if CustomExceptionHandler( 'TCefClearCertificateExceptionsCompletionCallback.OnComplete' , e) then raise ;
end ;
finally
FEvents : = nil ;
end ;
end ;
// TCefClearHttpAuthCredentialsCompletionCallback
procedure TCefClearHttpAuthCredentialsCompletionCallback. OnComplete;
begin
try
try
if ( FEvents < > nil ) then IChromiumEvents( FEvents) . doHttpAuthCredentialsCleared;
except
on e : exception do
if CustomExceptionHandler( 'TCefClearHttpAuthCredentialsCompletionCallback.OnComplete' , e) then raise ;
end ;
finally
FEvents : = nil ;
end ;
end ;
// TCefCloseAllConnectionsCompletionCallback
procedure TCefCloseAllConnectionsCompletionCallback. OnComplete;
begin
try
try
if ( FEvents < > nil ) then IChromiumEvents( FEvents) . doAllConnectionsClosed;
except
on e : exception do
if CustomExceptionHandler( 'TCefCloseAllConnectionsCompletionCallback.OnComplete' , e) then raise ;
end ;
finally
FEvents : = nil ;
end ;
end ;
2017-01-27 17:37:51 +02:00
end .