WebKit.WebContext¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
w/co |
|||
r/w/co |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
This signal is emitted when a new automation request is made. |
|
This signal is emitted when a |
|
This signal is emitted when a new web process is about to be launched. |
|
This signal is emitted when a |
Fields¶
- Inherited:
Class Details¶
- class WebKit.WebContext(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Manages aspects common to all
WebKit.WebView
sThe
WebKit.WebContext
manages all aspects common to allWebKit.WebView
s.You can define the
WebKit.CacheModel
withWebKit.WebContext.set_cache_model
(), depending on the needs of your application. You can access theWebKit.SecurityManager
to specify the behaviour of your application regarding security usingWebKit.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
() andWebKit.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 policyWebKit.TLSErrorsPolicy.IGNORE
; however, this is not appropriate for Internet applications.- classmethod get_default()¶
- Returns:
- Return type:
Gets the default web context.
- classmethod new()¶
- Returns:
a newly created
WebKit.WebContext
- Return type:
Create a new
WebKit.WebContext
.New in version 2.8.
- add_path_to_sandbox(path, read_only)¶
- Parameters:
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:
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:
Get the
WebKit.GeolocationManager
of self.New in version 2.26.
- get_network_session_for_automation()¶
- Returns:
a
WebKit.NetworkSession
, orNone
if automation is not enabled- Return type:
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:
Get the
WebKit.SecurityManager
of self.
- get_spell_checking_enabled()¶
-
Get whether spell checking feature is currently enabled.
- get_spell_checking_languages()¶
-
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:
Get the
WebKit.WebContext
:time-zone-override
property.New in version 2.38.
- initialize_notification_permissions(allowed_origins, disallowed_origins)¶
- Parameters:
allowed_origins ([
WebKit.SecurityOrigin
]) – aGLib.List
of security originsdisallowed_origins ([
WebKit.SecurityOrigin
]) – aGLib.List
of security origins
Sets initial desktop notification permissions for the self.
allowed_origins and disallowed_origins must each be
GLib.List
ofWebKit.SecurityOrigin
objects representing origins that will, respectively, either always or never have permission to show desktop notifications. NoWebKit.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()¶
-
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:
scheme (
str
) – the network scheme to registercallback (
WebKit.URISchemeRequestCallback
) – aWebKit.URISchemeRequestCallback
user_data (
object
orNone
) – data to pass to callback function
Register scheme in self.
Register scheme in self, so that when an URI request with scheme is made in the
WebKit.WebContext
, theWebKit.URISchemeRequestCallback
registered will be called with aWebKit.URISchemeRequest
. It is possible to handle URI scheme requests asynchronously, by callingGObject.Object.ref
() on theWebKit.URISchemeRequest
and callingWebKit.URISchemeRequest.finish
() later when the data of the request is available orWebKit.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; conststr
*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 aGio.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
) – aWebKit.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 passingTrue
to enable it.Note that only one
WebKit.WebContext
can have automation enabled, so this will do nothing if there’s anotherWebKit.WebContext
with automation already enabled.New in version 2.18.
- set_cache_model(cache_model)¶
- Parameters:
cache_model (
WebKit.CacheModel
) – aWebKit.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 specifyingWebKit.CacheModel.DOCUMENT_VIEWER
. The default value isWebKit.CacheModel.WEB_BROWSER
.
- set_preferred_languages(languages)¶
-
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 theWebKit.WebContext
.Setting the values of
navigator.language
andnavigator.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)¶
-
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
) – aGLib.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:
- Parameters:
web_context (
WebKit.WebContext
) – The object which received the signalsession (
WebKit.AutomationSession
) – theWebKit.AutomationSession
associated with this event
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:
- 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 useWebKit.WebContext.initialize_notification_permissions
(). If no notification permissions have changed since the last time this signal was emitted, then there is no need to callWebKit.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:
- 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
() andWebKit.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:
- Parameters:
web_context (
WebKit.WebContext
) – The object which received the signalmessage (
WebKit.UserMessage
) – theWebKit.UserMessage
received
- Returns:
- Return type:
This signal is emitted when a
WebKit.UserMessage
is received from a web process extension. You can reply to the message usingWebKit.UserMessage.send_reply
().You can handle the user message asynchronously by calling
GObject.Object.ref
() on message and returningTrue
.New in version 2.28.
Property Details¶
- WebKit.WebContext.props.memory_pressure_settings¶
- Name:
memory-pressure-settings
- Type:
- Default Value:
- Flags:
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:
- Default Value:
- Flags:
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.