WebKit2.WebContext¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
Virtual Methods¶
- Inherited:
|
|
|
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/co |
|
||
w/co |
|||
r/w/co |
|||
r/w/co |
|||
r/w/c |
|||
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 new download 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:
Name |
Type |
Access |
Description |
---|---|---|---|
parent |
r |
Class Details¶
- class WebKit2.WebContext(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Manages aspects common to all
WebKit2.WebView
sThe
WebKit2.WebContext
manages all aspects common to allWebKit2.WebView
s.You can define the
WebKit2.CacheModel
withWebKit2.WebContext.set_cache_model
(), depending on the needs of your application. You can access theWebKit2.SecurityManager
to specify the behaviour of your application regarding security usingWebKit2.WebContext.get_security_manager
().It is also possible to change your preferred language or enable spell checking, using
WebKit2.WebContext.set_preferred_languages
(),WebKit2.WebContext.set_spell_checking_languages
() andWebKit2.WebContext.set_spell_checking_enabled
().You can use
WebKit2.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
WebKit2.WebView
::load-failed-with-tls-errors
. Alternatively, you can useWebKit2.WebContext.set_tls_errors_policy
() to set the policyWebKit2.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
WebKit2.WebContext
- Return type:
Create a new
WebKit2.WebContext
.New in version 2.8.
- classmethod new_ephemeral()¶
- Returns:
a new ephemeral
WebKit2.WebContext
.- Return type:
Create a new ephemeral
WebKit2.WebContext
.An ephemeral
WebKit2.WebContext
is a context created with an ephemeralWebKit2.WebsiteDataManager
. This is just a convenient method to create ephemeral contexts without having to create your ownWebKit2.WebsiteDataManager
. AllWebKit2.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
) – aWebKit2.WebsiteDataManager
- Returns:
a newly created
WebKit2.WebContext
- Return type:
Create a new
WebKit2.WebContext
with aWebKit2.WebsiteDataManager
.New in version 2.10.
- 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
WebKit2.WebContext.set_sandbox_enabled
()New in version 2.26.
- allow_tls_certificate_for_host(certificate, host)¶
- Parameters:
certificate (
Gio.TlsCertificate
) – aGio.TlsCertificate
host (
str
) – the host for which a certificate is to be allowed
Ignore further TLS errors on the host for the certificate present in info.
If host is an IPv6 address, it should not be surrounded by brackets. This expectation matches
GLib.Uri.get_host
().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:
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 particularWebKit2.WebView
useWebKit2.WebView.download_uri
() instead.
- get_cache_model()¶
- Returns:
the current
WebKit2.CacheModel
- Return type:
Returns the current cache model.
For more information about this value check the documentation of the function
WebKit2.WebContext.set_cache_model
().
- get_cookie_manager()¶
- Returns:
the
WebKit2.CookieManager
of self.- Return type:
Get the
WebKit2.CookieManager
of the self'sWebKit2.WebsiteDataManager
.
- get_favicon_database()¶
- Returns:
the
WebKit2.FaviconDatabase
of self.- Return type:
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:
Get the directory path to store the favicons database.
Get the directory path being used to store the favicons database for self, or
None
ifWebKit2.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:
Get the
WebKit2.GeolocationManager
of self.New in version 2.26.
- get_plugins(cancellable, callback, *user_data)¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
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
) – aGio.AsyncResult
- Raises:
- Returns:
a
GLib.List
ofWebKit2.Plugin
. You must free theGLib.List
with g_list_free() and unref theWebKit2.Plugin
s withGObject.Object.unref
() when you’re done with them.- Return type:
Finish an asynchronous operation started with
WebKit2.WebContext.get_plugins
.Deprecated since version 2.32.
- get_process_model()¶
- Returns:
- Return type:
Returns
WebKit2.ProcessModel.MULTIPLE_SECONDARY_PROCESSES
.For more information about why this function is deprecated, see
WebKit2.WebContext.set_process_model
().New in version 2.4.
Deprecated since version 2.40.
- get_sandbox_enabled()¶
-
Get whether sandboxing is currently enabled.
New in version 2.26.
- get_security_manager()¶
- Returns:
the
WebKit2.SecurityManager
of self.- Return type:
Get the
WebKit2.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
WebKit2.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
WebKit2.WebContext
:time-zone-override
property.New in version 2.38.
- get_tls_errors_policy()¶
- Returns:
- Return type:
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, orFalse
otherwise- Return type:
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:
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:
- Return type:
Get the
WebKit2.WebsiteDataManager
of self.New in version 2.10.
- initialize_notification_permissions(allowed_origins, disallowed_origins)¶
- Parameters:
allowed_origins ([
WebKit2.SecurityOrigin
]) – aGLib.List
of security originsdisallowed_origins ([
WebKit2.SecurityOrigin
]) – aGLib.List
of security origins
Sets initial desktop notification permissions for the self.
allowed_origins and disallowed_origins must each be
GLib.List
ofWebKit2.SecurityOrigin
objects representing origins that will, respectively, either always or never have permission to show desktop notifications. NoWebKit2.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()¶
-
Get whether automation is allowed in self.
See also
WebKit2.WebContext.set_automation_allowed
().New in version 2.18.
- is_ephemeral()¶
-
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.
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:
scheme (
str
) – the network scheme to registercallback (
WebKit2.URISchemeRequestCallback
) – aWebKit2.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
WebKit2.WebContext
, theWebKit2.URISchemeRequestCallback
registered will be called with aWebKit2.URISchemeRequest
. It is possible to handle URI scheme requests asynchronously, by callingGObject.Object.ref
() on theWebKit2.URISchemeRequest
and callingWebKit2.URISchemeRequest.finish
() later when the data of the request is available orWebKit2.URISchemeRequest.finish_error
() in case of error.```c static void about_uri_scheme_request_cb (
WebKit2.URISchemeRequest
*request,object
user_data) {Gio.InputStream
*stream; gsize stream_length; conststr
*path =WebKit2.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);WebKit2.URISchemeRequest.finish_error
(request, error);GLib.Error.free
(error); return; }WebKit2.URISchemeRequest.finish
(request, stream, stream_length, “text/html”);GObject.Object.unref
(stream); } ```
- send_message_to_all_extensions(message)¶
- Parameters:
message (
WebKit2.UserMessage
) – aWebKit2.UserMessage
Send message to all web process extensions 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 passingTrue
to enable it.Note that only one
WebKit2.WebContext
can have automation enabled, so this will do nothing if there’s anotherWebKit2.WebContext
with automation already enabled.New in version 2.18.
- set_cache_model(cache_model)¶
- Parameters:
cache_model (
WebKit2.CacheModel
) – aWebKit2.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
WebKit2.CacheModel.WEB_BROWSER
. Applications without a browsing interface can reduce memory usage substantially by specifyingWebKit2.CacheModel.DOCUMENT_VIEWER
. The default value isWebKit2.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 byWebKit2.WebsiteDataManager.get_disk_cache_directory
() since theWebKit2.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
orNone
) – an absolute path to the icon database directory orNone
to use the defaults
Set the directory path to store the favicons database.
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 (seeGLib.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:
proxy_mode (
WebKit2.NetworkProxyMode
) – aWebKit2.NetworkProxyMode
proxy_settings (
WebKit2.NetworkProxySettings
orNone
) – aWebKit2.NetworkProxySettings
, orNone
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 useWebKit2.NetworkProxyMode.NO_PROXY
to make sure no proxies are used at all, orWebKit2.NetworkProxyMode.CUSTOM
to provide your own proxy settings. When proxy_mode isWebKit2.NetworkProxyMode.CUSTOM
proxy_settings must be a validWebKit2.NetworkProxySettings
; otherwise, proxy_settings must beNone
.New in version 2.16.
Deprecated since version 2.32.: Use
WebKit2.WebsiteDataManager.set_network_proxy_settings
() instead.
- 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 theWebKit2.WebContext
.Setting the values of
navigator.language
andnavigator.languages
.The first item in the list sets the default locale for JavaScript
Intl
functions.
- set_process_model(process_model)¶
- Parameters:
process_model (
WebKit2.ProcessModel
) – aWebKit2.ProcessModel
This function previously allowed specifying the process model to use. However, since 2.26, the only allowed process model is
WebKit2.ProcessModel.MULTIPLE_SECONDARY_PROCESSES
, so this function does nothing.New in version 2.4.
Deprecated since version 2.40.
- set_sandbox_enabled(enabled)¶
-
Set whether WebKit subprocesses will be sandboxed.
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)¶
-
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
) – aWebKit2.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 process 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
) – aGLib.Variant
Set user data to be passed to web process 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.
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:
Signal Details¶
- WebKit2.WebContext.signals.automation_started(web_context, session)¶
- Signal Name:
automation-started
- Flags:
- Parameters:
web_context (
WebKit2.WebContext
) – The object which received the signalsession (
WebKit2.AutomationSession
) – theWebKit2.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
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:
- Parameters:
web_context (
WebKit2.WebContext
) – The object which received the signaldownload (
WebKit2.Download
) – theWebKit2.Download
associated with this event
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:
- 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 useWebKit2.WebContext.initialize_notification_permissions
(). If no notification permissions have changed since the last time this signal was emitted, then there is no need to callWebKit2.WebContext.initialize_notification_permissions
() again.New in version 2.16.
- WebKit2.WebContext.signals.initialize_web_extensions(web_context)¶
- Signal Name:
initialize-web-extensions
- Flags:
- 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
() andWebKit2.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:
- Parameters:
web_context (
WebKit2.WebContext
) – The object which received the signalmessage (
WebKit2.UserMessage
) – theWebKit2.UserMessage
received
- Returns:
- Return type:
This signal is emitted when a
WebKit2.UserMessage
is received from a web process extension. You can reply to the message usingWebKit2.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¶
- WebKit2.WebContext.props.local_storage_directory¶
- Name:
local-storage-directory
- Type:
- Default Value:
- Flags:
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.memory_pressure_settings¶
- Name:
memory-pressure-settings
- Type:
- Default Value:
- Flags:
The
WebKit2.MemoryPressureSettings
applied to the web processes created by this context.New in version 2.34.
- Name:
process-swap-on-cross-site-navigation-enabled
- Type:
- Default Value:
- Flags:
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.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.
- WebKit2.WebContext.props.use_system_appearance_for_scrollbars¶
- Name:
use-system-appearance-for-scrollbars
- Type:
- Default Value:
- Flags:
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:
- Default Value:
- Flags:
The
WebKit2.WebsiteDataManager
associated with this context.New in version 2.10.