WebKit.WebContext

g GObject.Object GObject.Object WebKit.WebContext WebKit.WebContext GObject.Object->WebKit.WebContext

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

get_default ()

class

new ()

add_path_to_sandbox (path, read_only)

get_cache_model ()

get_geolocation_manager ()

get_network_session_for_automation ()

get_security_manager ()

get_spell_checking_enabled ()

get_spell_checking_languages ()

get_time_zone_override ()

initialize_notification_permissions (allowed_origins, disallowed_origins)

is_automation_allowed ()

register_uri_scheme (scheme, callback, *user_data)

send_message_to_all_extensions (message)

set_automation_allowed (allowed)

set_cache_model (cache_model)

set_preferred_languages (languages)

set_spell_checking_enabled (enabled)

set_spell_checking_languages (languages)

set_web_process_extensions_directory (directory)

set_web_process_extensions_initialization_user_data (user_data)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

memory-pressure-settings

WebKit.MemoryPressureSettings

w/co

time-zone-override

str

r/w/co

Signals

Inherited:

GObject.Object (1)

Name

Short Description

automation-started

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

initialize-notification-permissions

This signal is emitted when a WebKit.WebContext needs to set initial notification permissions for a web process.

initialize-web-process-extensions

This signal is emitted when a new web process is about to be launched.

user-message-received

This signal is emitted when a WebKit.UserMessage is received from a web process extension.

Fields

Inherited:

GObject.Object (1)

Class Details

class WebKit.WebContext(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

WebKit.WebContextClass

Manages aspects common to all WebKit.WebView s

The WebKit.WebContext manages all aspects common to all WebKit.WebView s.

You can define the WebKit.CacheModel with WebKit.WebContext.set_cache_model(), depending on the needs of your application. You can access the WebKit.SecurityManager to specify the behaviour of your application regarding security using WebKit.WebContext.get_security_manager().

It is also possible to change your preferred language or enable spell checking, using WebKit.WebContext.set_preferred_languages(), WebKit.WebContext.set_spell_checking_languages() and WebKit.WebContext.set_spell_checking_enabled().

You can use WebKit.WebContext.register_uri_scheme() to register custom URI schemes, and manage several other settings.

TLS certificate validation failure is now treated as a transport error by default. To handle TLS failures differently, you can connect to WebKit.WebView ::load-failed-with-tls-errors. Alternatively, you can use webkit_web_context_set_tls_errors_policy() to set the policy WebKit.TLSErrorsPolicy.IGNORE; however, this is not appropriate for Internet applications.

classmethod get_default()
Returns:

a WebKit.WebContext

Return type:

WebKit.WebContext

Gets the default web context.

classmethod new()
Returns:

a newly created WebKit.WebContext

Return type:

WebKit.WebContext

Create a new WebKit.WebContext.

New in version 2.8.

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 under /sys, /proc, and /dev are invalid. Attempting to add all of / is not valid. Since 2.40, adding the user’s entire home directory or /home is also not valid.

See also webkit_web_context_set_sandbox_enabled()

New in version 2.26.

get_cache_model()
Returns:

the current WebKit.CacheModel

Return type:

WebKit.CacheModel

Returns the current cache model.

For more information about this value check the documentation of the function WebKit.WebContext.set_cache_model().

get_geolocation_manager()
Returns:

the WebKit.GeolocationManager of self.

Return type:

WebKit.GeolocationManager

Get the WebKit.GeolocationManager of self.

New in version 2.26.

get_network_session_for_automation()
Returns:

a WebKit.NetworkSession, or None if automation is not enabled

Return type:

WebKit.NetworkSession or None

Get the WebKit.NetworkSession used for automation sessions started in self.

New in version 2.40.

get_security_manager()
Returns:

the WebKit.SecurityManager of self.

Return type:

WebKit.SecurityManager

Get the WebKit.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.

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

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

get_time_zone_override()
Return type:

str

Get the WebKit.WebContext :time-zone-override property.

New in version 2.38.

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 WebKit.SecurityOrigin objects representing origins that will, respectively, either always or never have permission to show desktop notifications. No WebKit.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 WebKit.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 WebKit.WebContext.set_automation_allowed().

New in version 2.18.

register_uri_scheme(scheme, callback, *user_data)
Parameters:

Register scheme in self.

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

```c static void about_uri_scheme_request_cb (WebKit.URISchemeRequest *request, object user_data) { Gio.InputStream *stream; gsize stream_length; const str *path = WebKit.URISchemeRequest.get_path (request);

if (!:obj:GLib.strcmp0 (path, “memory”)) { // Create a Gio.InputStream with the contents of memory about page, and set its length to stream_length } else if (!:obj:GLib.strcmp0 (path, “applications”)) { // Create a Gio.InputStream with the contents of applications about page, and set its length to stream_length } else if (!:obj:GLib.strcmp0 (path, “example”)) { str *contents = g_strdup_printf (“<html><body><p>Example about page</p></body></html>”); stream_length = strlen (contents); stream = Gio.MemoryInputStream.new_from_data (contents, stream_length, GLib.free); } else { GLib.Error *error = g_error_new (ABOUT_HANDLER_ERROR, ABOUT_HANDLER_ERROR_INVALID, “Invalid about:%s page.”, path); WebKit.URISchemeRequest.finish_error (request, error); GLib.Error.free (error); return; } WebKit.URISchemeRequest.finish (request, stream, stream_length, “text/html”); GObject.Object.unref (stream); } ```

send_message_to_all_extensions(message)
Parameters:

message (WebKit.UserMessage) – a WebKit.UserMessage

Send message to all web process extensions associated to self.

If message is floating, it’s consumed.

New in version 2.28.

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 WebKit.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 WebKit.WebContext can have automation enabled, so this will do nothing if there’s another WebKit.WebContext with automation already enabled.

New in version 2.18.

set_cache_model(cache_model)
Parameters:

cache_model (WebKit.CacheModel) – a WebKit.CacheModel

Specifies a usage model for WebViews.

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 WebKit.CacheModel.WEB_BROWSER. Applications without a browsing interface can reduce memory usage substantially by specifying WebKit.CacheModel.DOCUMENT_VIEWER. The default value is WebKit.CacheModel.WEB_BROWSER.

set_preferred_languages(languages)
Parameters:

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

Set the list of preferred languages.

Set the list of preferred languages, sorted from most desirable to least desirable. The list will be used in the following ways:

  • Determining how to build the Accept-Language HTTP header that will be included in the network requests started by the WebKit.WebContext.

  • Setting the values of navigator.language and navigator.languages.

  • The first item in the list sets the default locale for JavaScript Intl functions.

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_web_process_extensions_directory(directory)
Parameters:

directory (str) – the directory to add

Set the directory where WebKit will look for web process extensions.

This method must be called before loading anything in this context, otherwise it will not have any effect. You can connect to WebKit.WebContext ::initialize-web-process-extensions to call this method before anything is loaded.

set_web_process_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 #WebKitWebProcessExtensionInitializeWithUserDataFunction. This method must be called before loading anything in this context, otherwise it will not have any effect. You can connect to WebKit.WebContext ::initialize-web-process-extensions to call this method before anything is loaded.

New in version 2.4.

Signal Details

WebKit.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 WebKit.WebContext.set_automation_allowed() for more details.

New in version 2.18.

WebKit.WebContext.signals.initialize_notification_permissions(web_context)
Signal Name:

initialize-notification-permissions

Flags:

RUN_LAST

Parameters:

web_context (WebKit.WebContext) – The object which received the signal

This signal is emitted when a WebKit.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 WebKit.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 WebKit.WebContext.initialize_notification_permissions() again.

New in version 2.16.

WebKit.WebContext.signals.initialize_web_process_extensions(web_context)
Signal Name:

initialize-web-process-extensions

Flags:

RUN_LAST

Parameters:

web_context (WebKit.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 WebKit.WebContext.set_web_process_extensions_initialization_user_data() and WebKit.WebContext.set_web_process_extensions_directory().

New in version 2.4.

WebKit.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 WebKit.UserMessage is received from a web process extension. You can reply to the message using WebKit.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

WebKit.WebContext.props.memory_pressure_settings
Name:

memory-pressure-settings

Type:

WebKit.MemoryPressureSettings

Default Value:

None

Flags:

WRITABLE, CONSTRUCT_ONLY

The WebKit.MemoryPressureSettings applied to the web processes created by this context.

New in version 2.34.

WebKit.WebContext.props.time_zone_override
Name:

time-zone-override

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The timezone override for this web context. Setting this property provides a better alternative to configure the timezone information for all webviews managed by the WebContext. The other, less optimal, approach is to globally set the TZ environment variable in the process before creating the context. However this approach might not be very convenient and can have side-effects in your application.

The expected values for this property are defined in the IANA timezone database. See this wikipedia page for instance, https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.

New in version 2.38.