1.41 <WebKitWebContext>

Class: <WebKitWebContext>

It derives from <GObject>.

Manages aspects common to all <WebKitWebView><!– –>s

The <WebKitWebContext> manages all aspects common to all <WebKitWebView><!– –>s.

You can define the <WebKitCacheModel> with web-context:set-cache-model, depending on the needs of your application. You can access the <WebKitSecurityManager> to specify the behaviour of your application regarding security using web-context:get-security-manager.

It is also possible to change your preferred language or enable spell checking, using web-context:set-preferred-languages, web-context:set-spell-checking-languages and web-context:set-spell-checking-enabled.

You can use web-context: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 web-view:load-failed-with-tls-errors. Alternatively, you can use webkit_web_context_set_tls_errors_policy() to set the policy ignore; however, this is not appropriate for Internet applications.

Properties

Property: web-context:memory-pressure-settings self

The <WebKitMemoryPressureSettings> applied to the web processes created by this context.

Its value is a <WebKitMemoryPressureSettings>, or #f.

It can only be set when the object is made, with #:memory-pressure-settings. It cannot be read.

Property: web-context:time-zone-override self

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.

Its value is a string, or #f.

It can only be set when the object is made, with #:time-zone-override.

Procedures

Method: web-context:add-path-to-sandbox self path read-only
Method: add-path-to-sandbox self path read-only

Adds a path to be mounted in the sandbox.

path must exist before any web process has been created. 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()

self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

path

Passed: a file name, as a string.

an absolute path to mount in the sandbox

read-only

Passed: a boolean.

if #t the path will be read-only

Method: web-context:get-cache-model self ⇒ %return
Method: get-cache-model self ⇒ %return

Returns the current cache model.

For more information about this value check the documentation of the function web-context:set-cache-model.

self

Passed: a <WebKitWebContext>.

the <WebKitWebContext>

%return

Returned: a <WebKitCacheModel>.

the current <WebKitCacheModel>

Procedure: web-context:get-default ⇒ %return

Gets the default web context.

%return

Returned: a <WebKitWebContext>.

a <WebKitWebContext>

Method: web-context:get-geolocation-manager self ⇒ %return
Method: get-geolocation-manager self ⇒ %return

Get the <WebKitGeolocationManager> of self.

self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

%return

Returned: a <WebKitGeolocationManager>.

the <WebKitGeolocationManager> of self.

Method: web-context:get-network-session-for-automation self ⇒ %return
Method: get-network-session-for-automation self ⇒ %return

Get the <WebKitNetworkSession> used for automation sessions started in self.

self

Passed: a <WebKitWebContext>.

the <WebKitWebContext>

%return

Returned: a <WebKitNetworkSession>, or #f.

a <WebKitNetworkSession>, or #f if automation is not enabled

Method: web-context:get-security-manager self ⇒ %return
Method: get-security-manager self ⇒ %return

Get the <WebKitSecurityManager> of self.

self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

%return

Returned: a <WebKitSecurityManager>.

the <WebKitSecurityManager> of self.

Method: web-context:get-spell-checking-enabled? self ⇒ %return
Method: get-spell-checking-enabled? self ⇒ %return

Get whether spell checking feature is currently enabled.

self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

%return

Returned: a boolean.

#t If spell checking is enabled, or #f otherwise.

Method: web-context:get-spell-checking-languages self ⇒ %return
Method: get-spell-checking-languages self ⇒ %return

Get the the list of spell checking languages.

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

See web-context:set-spell-checking-languages for more details on the format of the languages in the list.

self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

%return

Returned: a vector, each a string.

A #f-terminated array of languages if available, or #f otherwise.

Method: web-context:get-time-zone-override self ⇒ %return
Method: get-time-zone-override self ⇒ %return

Get the web-context:time-zone-override property.

self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

%return

Returned: a string.

Method: web-context:initialize-notification-permissions self allowed-origins disallowed-origins
Method: initialize-notification-permissions self allowed-origins disallowed-origins

Sets initial desktop notification permissions for the self.

allowed-origins and disallowed-origins must each be GList of <WebKitSecurityOrigin> objects representing origins that will, respectively, either always or never have permission to show desktop notifications. No <WebKitNotificationPermissionRequest> 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 web-context:initialize-notification-permissions so as to ensure that new web processes receive the most recent set of permissions.

self

Passed: a <WebKitWebContext>.

the <WebKitWebContext>

allowed-origins

Passed: a list, each a <WebKitSecurityOrigin>.

a GList of security origins

disallowed-origins

Passed: a list, each a <WebKitSecurityOrigin>.

a GList of security origins

Method: web-context:is-automation-allowed? self ⇒ %return
Method: is-automation-allowed? self ⇒ %return

Get whether automation is allowed in self.

See also web-context:set-automation-allowed.

self

Passed: a <WebKitWebContext>.

the <WebKitWebContext>

%return

Returned: a boolean.

#t if automation is allowed or #f otherwise.

Procedure: web-context:new ⇒ %return

Create a new <WebKitWebContext>.

%return

Returned: a <WebKitWebContext>.

a newly created <WebKitWebContext>

Method: web-context:register-uri-scheme self scheme callback
Method: register-uri-scheme self scheme callback

Register scheme in self.

Register scheme in self, so that when an URI request with scheme is made in the <WebKitWebContext>, the WebKitURISchemeRequestCallback registered will be called with a <WebKitURISchemeRequest>. It is possible to handle URI scheme requests asynchronously, by calling object:ref on the <WebKitURISchemeRequest> and calling urischeme-request:finish later when the data of the request is available or urischeme-request: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 = 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 = 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 = 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);
}
self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

scheme

Passed: a string.

the network scheme to register

callback

Passed: a procedure.

a WebKitURISchemeRequestCallback

See WebKitURISchemeRequestCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

data to pass to callback function

user-data-destroy-func

Not passed: guile-gi supplies it.

destroy notify for user-data

See GDestroyNotify for how it is called.

Method: web-context:send-message-to-all-extensions self message
Method: send-message-to-all-extensions self message

Send message to all web process extensions associated to self.

If message is floating, it’s consumed.

self

Passed: a <WebKitWebContext>.

the <WebKitWebContext>

message

Passed: a <WebKitUserMessage>.

a <WebKitUserMessage>

Method: web-context:set-automation-allowed self allowed
Method: set-automation-allowed self allowed

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 web-context:automation-started is emitted. Automation is disabled by default, so you need to explicitly call this method passing #t to enable it.

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

self

Passed: a <WebKitWebContext>.

the <WebKitWebContext>

allowed

Passed: a boolean.

value to set

Method: web-context:set-cache-model self cache-model
Method: set-cache-model self cache-model

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 web-browser. Applications without a browsing interface can reduce memory usage substantially by specifying document-viewer. The default value is web-browser.

self

Passed: a <WebKitWebContext>.

the <WebKitWebContext>

cache-model

Passed: a <WebKitCacheModel>, or one of its symbols.

a <WebKitCacheModel>

Method: web-context:set-preferred-languages self [languages]
Method: set-preferred-languages self [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 the <WebKitWebContext>.
  • Setting the values of navigator.language and navigator.languages.
  • The first item in the list sets the default locale for JavaScript Intl functions.
self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

languages

Passed, or left out: a list or vector, each a string, or #f.

a #f-terminated list of language identifiers

Method: web-context:set-spell-checking-enabled self enabled
Method: set-spell-checking-enabled self enabled

Enable or disable the spell checking feature.

self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

enabled

Passed: a boolean.

Value to be set

Method: web-context:set-spell-checking-languages self languages
Method: set-spell-checking-languages self 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.

self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

languages

Passed: a list or vector, each a string.

a #f-terminated list of spell checking languages

Method: web-context:set-web-process-extensions-directory self directory
Method: set-web-process-extensions-directory self directory

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 web-context:initialize-web-process-extensions to call this method before anything is loaded.

If your web process extension is installed to an unusual location, then you may also need to call web-context:add-path-to-sandbox.

self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

directory

Passed: a string.

the directory to add

Method: web-context:set-web-process-extensions-initialization-user-data self user-data
Method: set-web-process-extensions-initialization-user-data self user-data

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 web-context:initialize-web-process-extensions to call this method before anything is loaded.

self

Passed: a <WebKitWebContext>.

a <WebKitWebContext>

user-data

Passed: a <GVariant>.

a <GVariant>

Signals

Signal: web-context:automation-started

Connect a handler with (connect object web-context:automation-started handler). It is called as (handler self session).

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 web-context:set-automation-allowed for more details.

self

Passed: a <WebKitWebContext>.

session

Passed: a <WebKitAutomationSession>.

the <WebKitAutomationSession> associated with this event

Signal: web-context:initialize-notification-permissions

Connect a handler with (connect object web-context:initialize-notification-permissions handler). It is called as (handler self).

This signal is emitted when a <WebKitWebContext> 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 web-context:initialize-notification-permissions. If no notification permissions have changed since the last time this signal was emitted, then there is no need to call web-context:initialize-notification-permissions again.

self

Passed: a <WebKitWebContext>.

Signal: web-context:initialize-web-process-extensions

Connect a handler with (connect object web-context:initialize-web-process-extensions handler). It is called as (handler self).

This signal is emitted when a new web process is about to be launched. It signals the most appropriate moment to use web-context:set-web-process-extensions-initialization-user-data and web-context:set-web-process-extensions-directory.

self

Passed: a <WebKitWebContext>.

Signal: web-context:user-message-received

Connect a handler with (connect object web-context:user-message-received handler). It is called as (handler self message) ⇒ %return.

This signal is emitted when a <WebKitUserMessage> is received from a web process extension. You can reply to the message using user-message:send-reply.

You can handle the user message asynchronously by calling object:ref on message and returning #t.

self

Passed: a <WebKitWebContext>.

message

Passed: a <WebKitUserMessage>.

the <WebKitUserMessage> received

%return

Returned: a boolean.

#t if the message was handled, or #f otherwise.