WebKit2.WebContext

g GObject.Object GObject.Object WebKit2.WebContext WebKit2.WebContext GObject.Object->WebKit2.WebContext

Subclasses:None

Methods

Inherited:GObject.Object (37)
Structs:GObject.ObjectClass (5)
class get_default ()
class new ()
class new_ephemeral ()
class new_with_website_data_manager (manager)
  add_path_to_sandbox (path, read_only)
  allow_tls_certificate_for_host (certificate, host)
  clear_cache ()
  download_uri (uri)
  get_cache_model ()
  get_cookie_manager ()
  get_favicon_database ()
  get_favicon_database_directory ()
  get_geolocation_manager ()
  get_plugins (cancellable, callback, *user_data)
  get_plugins_finish (result)
  get_process_model ()
  get_sandbox_enabled ()
  get_security_manager ()
  get_spell_checking_enabled ()
  get_spell_checking_languages ()
  get_tls_errors_policy ()
  get_use_system_appearance_for_scrollbars ()
  get_web_process_count_limit ()
  get_website_data_manager ()
  initialize_notification_permissions (allowed_origins, disallowed_origins)
  is_automation_allowed ()
  is_ephemeral ()
  prefetch_dns (hostname)
  register_uri_scheme (scheme, callback, *user_data)
  send_message_to_all_extensions (message)
  set_additional_plugins_directory (directory)
  set_automation_allowed (allowed)
  set_cache_model (cache_model)
  set_disk_cache_directory (directory)
  set_favicon_database_directory (path)
  set_network_proxy_settings (proxy_mode, proxy_settings)
  set_preferred_languages (languages)
  set_process_model (process_model)
  set_sandbox_enabled (enabled)
  set_spell_checking_enabled (enabled)
  set_spell_checking_languages (languages)
  set_tls_errors_policy (policy)
  set_use_system_appearance_for_scrollbars (enabled)
  set_web_extensions_directory (directory)
  set_web_extensions_initialization_user_data (user_data)
  set_web_process_count_limit (limit)

Properties

Name Type Flags Short Description
local-storage-directory str r/w/co The directory where local storage data will be saved deprecated
process-swap-on-cross-site-navigation-enabled bool r/w/co Whether swap Web processes on cross-site navigations is enabled
use-system-appearance-for-scrollbars bool r/w/c Whether to use system appearance for rendering scrollbars
website-data-manager WebKit2.WebsiteDataManager r/w/co The WebKit2.WebsiteDataManager associated with this context

Signals

Inherited:GObject.Object (1)
Name Short Description
automation-started This signal is emitted when a new automation request is made.
download-started This signal is emitted when a new download request is made.
initialize-notification-permissions This signal is emitted when a WebKit2.WebContext needs to set initial notification permissions for a web process.
initialize-web-extensions This signal is emitted when a new web process is about to be launched.
user-message-received This signal is emitted when a WebKit2.UserMessage is received from a #WebKitWebExtension.

Fields

Inherited:GObject.Object (1)
Name Type Access Description
parent GObject.Object r  

Class Details

class WebKit2.WebContext(**kwargs)
Bases:GObject.Object
Abstract:No
Structure:WebKit2.WebContextClass
classmethod get_default()
Returns:a WebKit2.WebContext
Return type:WebKit2.WebContext

Gets the default web context

classmethod new()
Returns:a newly created WebKit2.WebContext
Return type:WebKit2.WebContext

Create a new WebKit2.WebContext

New in version 2.8.

classmethod new_ephemeral()
Returns:a new ephemeral WebKit2.WebContext.
Return type:WebKit2.WebContext

Create a new ephemeral WebKit2.WebContext. An ephemeral WebKit2.WebContext is a context created with an ephemeral WebKit2.WebsiteDataManager. This is just a convenient method to create ephemeral contexts without having to create your own WebKit2.WebsiteDataManager. All WebKit2.WebView s associated with this context will also be ephemeral. Websites will not store any data in the client storage. This is normally used to implement private instances.

New in version 2.16.

classmethod new_with_website_data_manager(manager)
Parameters:manager (WebKit2.WebsiteDataManager) – a WebKit2.WebsiteDataManager
Returns:a newly created WebKit2.WebContext
Return type:WebKit2.WebContext

Create a new WebKit2.WebContext with a WebKit2.WebsiteDataManager.

New in version 2.10.

add_path_to_sandbox(path, read_only)
Parameters:
  • path (str) – an absolute path to mount in the sandbox
  • read_only (bool) – if True the path will be read-only

Adds a path to be mounted in the sandbox. path must exist before any web process has been created otherwise it will be silently ignored. It is a fatal error to add paths after a web process has been spawned.

Paths in directories such as /sys, /proc, and /dev or all of / are not valid.

See also WebKit2.WebContext.set_sandbox_enabled()

New in version 2.26.

allow_tls_certificate_for_host(certificate, host)
Parameters:

Ignore further TLS errors on the host for the certificate present in info.

New in version 2.6.

clear_cache()

Clears all resources currently cached. See also WebKit2.WebContext.set_cache_model().

download_uri(uri)
Parameters:uri (str) – the URI to download
Returns:a new WebKit2.Download representing the download operation.
Return type:WebKit2.Download

Requests downloading of the specified URI string. The download operation will not be associated to any WebKit2.WebView, if you are interested in starting a download from a particular WebKit2.WebView use WebKit2.WebView.download_uri() instead.

get_cache_model()
Returns:the current WebKit2.CacheModel
Return type:WebKit2.CacheModel

Returns the current cache model. For more information about this value check the documentation of the function WebKit2.WebContext.set_cache_model().

Returns:the WebKit2.CookieManager of self.
Return type:WebKit2.CookieManager

Get the WebKit2.CookieManager of the self’s WebKit2.WebsiteDataManager.

get_favicon_database()
Returns:the WebKit2.FaviconDatabase of self.
Return type:WebKit2.FaviconDatabase

Get the WebKit2.FaviconDatabase associated with self.

To initialize the database you need to call WebKit2.WebContext.set_favicon_database_directory().

get_favicon_database_directory()
Returns:the path of the directory of the favicons database associated with self, or None.
Return type:str

Get the directory path being used to store the favicons database for self, or None if WebKit2.WebContext.set_favicon_database_directory() hasn’t been called yet.

This function will always return the same path after having called WebKit2.WebContext.set_favicon_database_directory() for the first time.

get_geolocation_manager()
Returns:the WebKit2.GeolocationManager of self.
Return type:WebKit2.GeolocationManager

Get the WebKit2.GeolocationManager of self.

New in version 2.26.

get_plugins(cancellable, callback, *user_data)
Parameters:

Asynchronously get the list of installed plugins.

When the operation is finished, callback will be called. You can then call WebKit2.WebContext.get_plugins_finish() to get the result of the operation.

Deprecated since version 2.32.

get_plugins_finish(result)
Parameters:result (Gio.AsyncResult) – a Gio.AsyncResult
Raises:GLib.Error
Returns:a GLib.List of WebKit2.Plugin. You must free the GLib.List with g_list_free() and unref the WebKit2.Plugin s with GObject.Object.unref() when you’re done with them.
Return type:[WebKit2.Plugin]

Finish an asynchronous operation started with WebKit2.WebContext.get_plugins.

Deprecated since version 2.32.

get_process_model()
Returns:the current WebKit2.ProcessModel
Return type:WebKit2.ProcessModel

Returns the current process model. For more information about this value see WebKit2.WebContext.set_process_model().

New in version 2.4.

get_sandbox_enabled()
Returns:True if sandboxing is enabled, or False otherwise.
Return type:bool

Get whether sandboxing is currently enabled.

New in version 2.26.

get_security_manager()
Returns:the WebKit2.SecurityManager of self.
Return type:WebKit2.SecurityManager

Get the WebKit2.SecurityManager of self.

get_spell_checking_enabled()
Returns:True If spell checking is enabled, or False otherwise.
Return type:bool

Get whether spell checking feature is currently enabled.

get_spell_checking_languages()
Returns:A None-terminated array of languages if available, or None otherwise.
Return type:[str]

Get the the list of spell checking languages associated with self, or None if no languages have been previously set.

See WebKit2.WebContext.set_spell_checking_languages() for more details on the format of the languages in the list.

get_tls_errors_policy()
Returns:a WebKit2.TLSErrorsPolicy
Return type:WebKit2.TLSErrorsPolicy

Get the TLS errors policy of self

Deprecated since version 2.32.: Use WebKit2.WebsiteDataManager.get_tls_errors_policy() instead.

get_use_system_appearance_for_scrollbars()
Returns:True if scrollbars are rendering using the system appearance, or False otherwise
Return type:bool

Get the WebKit2.WebContext :use-system-appearance-for-scrollbars property.

New in version 2.30.

get_web_process_count_limit()
Returns:the maximum limit of web processes, or 0 if there isn’t a limit.
Return type:int

Gets the maximum number of web processes that can be created at the same time for the self.

This function is now deprecated and always returns 0 (no limit). See also WebKit2.WebContext.set_web_process_count_limit().

New in version 2.10.

Deprecated since version 2.26.

get_website_data_manager()
Returns:a WebKit2.WebsiteDataManager
Return type:WebKit2.WebsiteDataManager

Get the WebKit2.WebsiteDataManager of self.

New in version 2.10.

initialize_notification_permissions(allowed_origins, disallowed_origins)
Parameters:

Sets initial desktop notification permissions for the self. allowed_origins and disallowed_origins must each be GLib.List of WebKit2.SecurityOrigin objects representing origins that will, respectively, either always or never have permission to show desktop notifications. No WebKit2.NotificationPermissionRequest will ever be generated for any of the security origins represented in allowed_origins or disallowed_origins. This function is necessary because some webpages proactively check whether they have permission to display notifications without ever creating a permission request.

This function only affects web processes that have not already been created. The best time to call it is when handling WebKit2.WebContext ::initialize-notification-permissions so as to ensure that new web processes receive the most recent set of permissions.

New in version 2.16.

is_automation_allowed()
Returns:True if automation is allowed or False otherwise.
Return type:bool

Get whether automation is allowed in self. See also WebKit2.WebContext.set_automation_allowed().

New in version 2.18.

is_ephemeral()
Returns:True if self is ephemeral or False otherwise.
Return type:bool

Get whether a WebKit2.WebContext is ephemeral.

New in version 2.16.

prefetch_dns(hostname)
Parameters:hostname (str) – a hostname to be resolved

Resolve the domain name of the given hostname in advance, so that if a URI of hostname is requested the load will be performed more quickly.

register_uri_scheme(scheme, callback, *user_data)
Parameters:

Register scheme in self, so that when an URI request with scheme is made in the WebKit2.WebContext, the WebKit2.URISchemeRequestCallback registered will be called with a WebKit2.URISchemeRequest. It is possible to handle URI scheme requests asynchronously, by calling GObject.Object.ref() on the WebKit2.URISchemeRequest and calling WebKit2.URISchemeRequest.finish() later when the data of the request is available or WebKit2.URISchemeRequest.finish_error() in case of error.

static void
about_uri_scheme_request_cb (WebKitURISchemeRequest *request,
                             gpointer                user_data)
{
    GInputStream *stream;
    gsize         stream_length;
    const gchar  *path;

    path = webkit_uri_scheme_request_get_path (request);
    if (!g_strcmp0 (path, "memory")) {
        /* Create a GInputStream with the contents of memory about page, and set its length to stream_length */
    } else if (!g_strcmp0 (path, "applications")) {
        /* Create a GInputStream with the contents of applications about page, and set its length to stream_length */
    } else if (!g_strcmp0 (path, "example")) {
        gchar *contents;

        contents = g_strdup_printf ("<html><body><p>Example about page</p></body></html>");
        stream_length = strlen (contents);
        stream = g_memory_input_stream_new_from_data (contents, stream_length, g_free);
    } else {
        GError *error;

        error = g_error_new (ABOUT_HANDLER_ERROR, ABOUT_HANDLER_ERROR_INVALID, "Invalid about:%s page.", path);
        webkit_uri_scheme_request_finish_error (request, error);
        g_error_free (error);
        return;
    }
    webkit_uri_scheme_request_finish (request, stream, stream_length, "text/html");
    g_object_unref (stream);
}
send_message_to_all_extensions(message)
Parameters:message (WebKit2.UserMessage) – a WebKit2.UserMessage

Send message to all #WebKitWebExtension s associated to self. If message is floating, it’s consumed.

New in version 2.28.

set_additional_plugins_directory(directory)
Parameters:directory (str) – the directory to add

Set an additional directory where WebKit will look for plugins.

Deprecated since version 2.32.

set_automation_allowed(allowed)
Parameters:allowed (bool) – value to set

Set whether automation is allowed in self. When automation is enabled the browser could be controlled by another process by requesting an automation session. When a new automation session is requested the signal WebKit2.WebContext ::automation-started is emitted. Automation is disabled by default, so you need to explicitly call this method passing True to enable it.

Note that only one WebKit2.WebContext can have automation enabled, so this will do nothing if there’s another WebKit2.WebContext with automation already enabled.

New in version 2.18.

set_cache_model(cache_model)
Parameters:cache_model (WebKit2.CacheModel) – a WebKit2.CacheModel

Specifies a usage model for WebViews, which WebKit will use to determine its caching behavior. All web views follow the cache model. This cache model determines the RAM and disk space to use for caching previously viewed content .

Research indicates that users tend to browse within clusters of documents that hold resources in common, and to revisit previously visited documents. WebKit and the frameworks below it include built-in caches that take advantage of these patterns, substantially improving document load speed in browsing situations. The WebKit cache model controls the behaviors of all of these caches, including various WebCore caches.

Browsers can improve document load speed substantially by specifying WebKit2.CacheModel.WEB_BROWSER. Applications without a browsing interface can reduce memory usage substantially by specifying WebKit2.CacheModel.DOCUMENT_VIEWER. The default value is WebKit2.CacheModel.WEB_BROWSER.

set_disk_cache_directory(directory)
Parameters:directory (str) – the directory to set

Set the directory where disk cache files will be stored This method must be called before loading anything in this context, otherwise it will not have any effect.

Note that this method overrides the directory set in the WebKit2.WebsiteDataManager, but it doesn’t change the value returned by WebKit2.WebsiteDataManager.get_disk_cache_directory() since the WebKit2.WebsiteDataManager is immutable.

Deprecated since version 2.10.: Use WebKit2.WebContext.new_with_website_data_manager() instead.

set_favicon_database_directory(path)
Parameters:path (str or None) – an absolute path to the icon database directory or None to use the defaults

Set the directory path to be used to store the favicons database for self on disk. Passing None as path means using the default directory for the platform (see GLib.get_user_cache_dir()).

Calling this method also means enabling the favicons database for its use from the applications, so that’s why it’s expected to be called only once. Further calls for the same instance of WebKit2.WebContext won’t cause any effect.

set_network_proxy_settings(proxy_mode, proxy_settings)
Parameters:

Set the network proxy settings to be used by connections started in self. By default WebKit2.NetworkProxyMode.DEFAULT is used, which means that the system settings will be used (Gio.ProxyResolver.get_default()). If you want to override the system default settings, you can either use WebKit2.NetworkProxyMode.NO_PROXY to make sure no proxies are used at all, or WebKit2.NetworkProxyMode.CUSTOM to provide your own proxy settings. When proxy_mode is WebKit2.NetworkProxyMode.CUSTOM proxy_settings must be a valid WebKit2.NetworkProxySettings; otherwise, proxy_settings must be None.

New in version 2.16.

Deprecated since version 2.32.: Use WebKit2.WebsiteDataManager.set_network_proxy_settings() instead.

set_preferred_languages(languages)
Parameters:languages ([str] or None) – a None-terminated list of language identifiers

Set the list of preferred languages, sorted from most desirable to least desirable. The list will be used to build the “Accept-Language” header that will be included in the network requests started by the WebKit2.WebContext.

set_process_model(process_model)
Parameters:process_model (WebKit2.ProcessModel) – a WebKit2.ProcessModel

Specifies a process model for WebViews, which WebKit will use to determine how auxiliary processes are handled.

WebKit2.ProcessModel.MULTIPLE_SECONDARY_PROCESSES will use one process per view most of the time, while still allowing for web views to share a process when needed (for example when different views interact with each other). Using this model, when a process hangs or crashes, only the WebViews using it stop working, while the rest of the WebViews in the application will still function normally.

WebKit2.ProcessModel.SHARED_SECONDARY_PROCESS is deprecated since 2.26, using it has no effect for security reasons.

This method **must be called before any web process has been created**, as early as possible in your application. Calling it later will make your application crash.

New in version 2.4.

set_sandbox_enabled(enabled)
Parameters:enabled (bool) – if True enable sandboxing

Set whether WebKit subprocesses will be sandboxed, limiting access to the system.

This method **must be called before any web process has been created**, as early as possible in your application. Calling it later is a fatal error.

This is only implemented on Linux and is a no-op otherwise.

New in version 2.26.

set_spell_checking_enabled(enabled)
Parameters:enabled (bool) – Value to be set

Enable or disable the spell checking feature.

set_spell_checking_languages(languages)
Parameters:languages ([str]) – a None-terminated list of spell checking languages

Set the list of spell checking languages to be used for spell checking.

The locale string typically is in the form lang_COUNTRY, where lang is an ISO-639 language code, and COUNTRY is an ISO-3166 country code. For instance, sv_FI for Swedish as written in Finland or pt_BR for Portuguese as written in Brazil.

You need to call this function with a valid list of languages at least once in order to properly enable the spell checking feature in WebKit.

set_tls_errors_policy(policy)
Parameters:policy (WebKit2.TLSErrorsPolicy) – a WebKit2.TLSErrorsPolicy

Set the TLS errors policy of self as policy

Deprecated since version 2.32.: Use WebKit2.WebsiteDataManager.set_tls_errors_policy() instead.

set_use_system_appearance_for_scrollbars(enabled)
Parameters:enabled (bool) – value to set

Set the WebKit2.WebContext :use-system-appearance-for-scrollbars property.

New in version 2.30.

set_web_extensions_directory(directory)
Parameters:directory (str) – the directory to add

Set the directory where WebKit will look for Web Extensions. This method must be called before loading anything in this context, otherwise it will not have any effect. You can connect to WebKit2.WebContext ::initialize-web-extensions to call this method before anything is loaded.

set_web_extensions_initialization_user_data(user_data)
Parameters:user_data (GLib.Variant) – a GLib.Variant

Set user data to be passed to Web Extensions on initialization. The data will be passed to the #WebKitWebExtensionInitializeWithUserDataFunction. This method must be called before loading anything in this context, otherwise it will not have any effect. You can connect to WebKit2.WebContext ::initialize-web-extensions to call this method before anything is loaded.

New in version 2.4.

set_web_process_count_limit(limit)
Parameters:limit (int) – the maximum number of web processes

Sets the maximum number of web processes that can be created at the same time for the self. The default value is 0 and means no limit.

This function is now deprecated and does nothing for security reasons.

New in version 2.10.

Deprecated since version 2.26.

do_automation_started(session) virtual
Parameters:session (WebKit2.AutomationSession) –
do_download_started(download) virtual
Parameters:download (WebKit2.Download) –
do_initialize_notification_permissions() virtual
do_initialize_web_extensions() virtual
do_user_message_received(message) virtual
Parameters:message (WebKit2.UserMessage) –
Return type:bool

Signal Details

WebKit2.WebContext.signals.automation_started(web_context, session)
Signal Name:

automation-started

Flags:

RUN_LAST

Parameters:

This signal is emitted when a new automation request is made. Note that it will never be emitted if automation is not enabled in context, see WebKit2.WebContext.set_automation_allowed() for more details.

New in version 2.18.

WebKit2.WebContext.signals.download_started(web_context, download)
Signal Name:

download-started

Flags:

RUN_LAST

Parameters:

This signal is emitted when a new download request is made.

WebKit2.WebContext.signals.initialize_notification_permissions(web_context)
Signal Name:initialize-notification-permissions
Flags:RUN_LAST
Parameters:web_context (WebKit2.WebContext) – The object which received the signal

This signal is emitted when a WebKit2.WebContext needs to set initial notification permissions for a web process. It is emitted when a new web process is about to be launched, and signals the most appropriate moment to use WebKit2.WebContext.initialize_notification_permissions(). If no notification permissions have changed since the last time this signal was emitted, then there is no need to call WebKit2.WebContext.initialize_notification_permissions() again.

New in version 2.16.

WebKit2.WebContext.signals.initialize_web_extensions(web_context)
Signal Name:initialize-web-extensions
Flags:RUN_LAST
Parameters:web_context (WebKit2.WebContext) – The object which received the signal

This signal is emitted when a new web process is about to be launched. It signals the most appropriate moment to use WebKit2.WebContext.set_web_extensions_initialization_user_data() and WebKit2.WebContext.set_web_extensions_directory().

New in version 2.4.

WebKit2.WebContext.signals.user_message_received(web_context, message)
Signal Name:

user-message-received

Flags:

RUN_LAST

Parameters:
Returns:

True if the message was handled, or False otherwise.

Return type:

bool

This signal is emitted when a WebKit2.UserMessage is received from a #WebKitWebExtension. You can reply to the message using WebKit2.UserMessage.send_reply().

You can handle the user message asynchronously by calling GObject.Object.ref() on message and returning True.

New in version 2.28.

Property Details

WebKit2.WebContext.props.local_storage_directory
Name:local-storage-directory
Type:str
Default Value:None
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

The directory where local storage data will be saved.

New in version 2.8.

Deprecated since version 2.10.: Use WebKit2.WebsiteDataManager :local-storage-directory instead.

WebKit2.WebContext.props.process_swap_on_cross_site_navigation_enabled
Name:process-swap-on-cross-site-navigation-enabled
Type:bool
Default Value:False
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

Whether swap Web processes on cross-site navigations is enabled.

When enabled, pages from each security origin will be handled by their own separate Web processes, which are started (and terminated) on demand as the user navigates across different domains. This is an important security measure which helps prevent websites stealing data from other visited pages.

New in version 2.28.

WebKit2.WebContext.props.use_system_appearance_for_scrollbars
Name:use-system-appearance-for-scrollbars
Type:bool
Default Value:True
Flags:READABLE, WRITABLE, CONSTRUCT

Whether to use system appearance for rendering scrollbars.

This is enabled by default for backwards compatibility, but it’s only recommened to use when the application includes other widgets to ensure consistency, or when consistency with other applications is required too.

New in version 2.30.

WebKit2.WebContext.props.website_data_manager
Name:website-data-manager
Type:WebKit2.WebsiteDataManager
Default Value:None
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

The WebKit2.WebsiteDataManager associated with this context.

New in version 2.10.