Top |
WebKitWebContextWebKitWebContext — Manages aspects common to all WebKitWebViews |
char * | local-storage-directory | Read / Write / Construct Only |
gboolean | process-swap-on-cross-site-navigation-enabled | Read / Write / Construct Only |
gboolean | use-system-appearance-for-scrollbars | Read / Write / Construct |
WebKitWebsiteDataManager * | website-data-manager | Read / Write / Construct Only |
The WebKitWebContext manages all aspects common to all WebKitWebViews.
You can define the WebKitCacheModel and WebKitProcessModel with
webkit_web_context_set_cache_model()
and
webkit_web_context_set_process_model()
, depending on the needs of
your application. You can access the WebKitSecurityManager to specify
the behaviour of your application regarding security using
webkit_web_context_get_security_manager()
.
It is also possible to change your preferred language or enable
spell checking, using webkit_web_context_set_preferred_languages()
,
webkit_web_context_set_spell_checking_languages()
and
webkit_web_context_set_spell_checking_enabled()
.
You can use webkit_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 “load-failed-with-tls-errors”.
Alternatively, you can use webkit_web_context_set_tls_errors_policy()
to set the policy WEBKIT_TLS_ERRORS_POLICY_IGNORE
; however, this is
not appropriate for Internet applications.
WebKitWebContext *
webkit_web_context_get_default (void
);
Gets the default web context
WebKitWebContext *
webkit_web_context_new (void
);
Create a new WebKitWebContext
Since: 2.8
WebKitWebContext *
webkit_web_context_new_ephemeral (void
);
Create a new ephemeral WebKitWebContext. An ephemeral WebKitWebContext is a context created with an ephemeral WebKitWebsiteDataManager. This is just a convenient method to create ephemeral contexts without having to create your own WebKitWebsiteDataManager. All WebKitWebViews 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.
Since: 2.16
WebKitWebContext *
webkit_web_context_new_with_website_data_manager
(WebKitWebsiteDataManager *manager
);
Create a new WebKitWebContext with a WebKitWebsiteDataManager.
Since: 2.10
gboolean
webkit_web_context_is_ephemeral (WebKitWebContext *context
);
Get whether a WebKitWebContext is ephemeral.
Since: 2.16
gboolean
webkit_web_context_is_automation_allowed
(WebKitWebContext *context
);
Get whether automation is allowed in context
.
See also webkit_web_context_set_automation_allowed()
.
Since: 2.18
void webkit_web_context_set_automation_allowed (WebKitWebContext *context
,gboolean allowed
);
Set whether automation is allowed in context
. 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 “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 WebKitWebContext can have automation enabled, so this will do nothing if there's another WebKitWebContext with automation already enabled.
Since: 2.18
WebKitWebsiteDataManager *
webkit_web_context_get_website_data_manager
(WebKitWebContext *context
);
Get the WebKitWebsiteDataManager of context
.
Since: 2.10
WebKitCacheModel
webkit_web_context_get_cache_model (WebKitWebContext *context
);
Returns the current cache model. For more information about this
value check the documentation of the function
webkit_web_context_set_cache_model()
.
void webkit_web_context_set_cache_model (WebKitWebContext *context
,WebKitCacheModel cache_model
);
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_CACHE_MODEL_WEB_BROWSER
. Applications without a
browsing interface can reduce memory usage substantially by
specifying WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER
. The default value is
WEBKIT_CACHE_MODEL_WEB_BROWSER
.
guint
webkit_web_context_get_web_process_count_limit
(WebKitWebContext *context
);
webkit_web_context_get_web_process_count_limit
has been deprecated since version 2.26 and should not be used in newly-written code.
Gets the maximum number of web processes that can be created at the same time for the context
.
This function is now deprecated and always returns 0 (no limit). See also webkit_web_context_set_web_process_count_limit()
.
Since: 2.10
void webkit_web_context_set_web_process_count_limit (WebKitWebContext *context
,guint limit
);
webkit_web_context_set_web_process_count_limit
has been deprecated since version 2.26 and should not be used in newly-written code.
Sets the maximum number of web processes that can be created at the same time for the context
.
The default value is 0 and means no limit.
This function is now deprecated and does nothing for security reasons.
Since: 2.10
void
webkit_web_context_clear_cache (WebKitWebContext *context
);
Clears all resources currently cached.
See also webkit_web_context_set_cache_model()
.
void webkit_web_context_set_network_proxy_settings (WebKitWebContext *context
,WebKitNetworkProxyMode proxy_mode
,WebKitNetworkProxySettings *proxy_settings
);
webkit_web_context_set_network_proxy_settings
has been deprecated since version 2.32. and should not be used in newly-written code.
Use webkit_website_data_manager_set_network_proxy_settings()
instead.
Set the network proxy settings to be used by connections started in context
.
By default WEBKIT_NETWORK_PROXY_MODE_DEFAULT
is used, which means that the
system settings will be used (g_proxy_resolver_get_default()
).
If you want to override the system default settings, you can either use
WEBKIT_NETWORK_PROXY_MODE_NO_PROXY
to make sure no proxies are used at all,
or WEBKIT_NETWORK_PROXY_MODE_CUSTOM
to provide your own proxy settings.
When proxy_mode
is WEBKIT_NETWORK_PROXY_MODE_CUSTOM
proxy_settings
must be
a valid WebKitNetworkProxySettings; otherwise, proxy_settings
must be NULL
.
Since: 2.16
WebKitDownload * webkit_web_context_download_uri (WebKitWebContext *context
,const gchar *uri
);
Requests downloading of the specified URI string. The download operation
will not be associated to any WebKitWebView, if you are interested in
starting a download from a particular WebKitWebView use
webkit_web_view_download_uri()
instead.
WebKitCookieManager *
webkit_web_context_get_cookie_manager (WebKitWebContext *context
);
Get the WebKitCookieManager of the context
's WebKitWebsiteDataManager.
WebKitGeolocationManager *
webkit_web_context_get_geolocation_manager
(WebKitWebContext *context
);
Get the WebKitGeolocationManager of context
.
Since: 2.26
WebKitFaviconDatabase *
webkit_web_context_get_favicon_database
(WebKitWebContext *context
);
Get the WebKitFaviconDatabase associated with context
.
To initialize the database you need to call
webkit_web_context_set_favicon_database_directory()
.
void webkit_web_context_set_favicon_database_directory (WebKitWebContext *context
,const gchar *path
);
Set the directory path to be used to store the favicons database
for context
on disk. Passing NULL
as path
means using the
default directory for the platform (see g_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 WebKitWebContext won't cause any effect.
context |
||
path |
an absolute path to the icon database
directory or |
[allow-none] |
const gchar *
webkit_web_context_get_favicon_database_directory
(WebKitWebContext *context
);
Get the directory path being used to store the favicons database
for context
, or NULL
if
webkit_web_context_set_favicon_database_directory()
hasn't been
called yet.
This function will always return the same path after having called
webkit_web_context_set_favicon_database_directory()
for the first
time.
the path of the directory of the favicons
database associated with context
, or NULL
.
[transfer none]
WebKitSecurityManager *
webkit_web_context_get_security_manager
(WebKitWebContext *context
);
Get the WebKitSecurityManager of context
.
void webkit_web_context_set_additional_plugins_directory (WebKitWebContext *context
,const gchar *directory
);
webkit_web_context_set_additional_plugins_directory
has been deprecated since version 2.32 and should not be used in newly-written code.
Set an additional directory where WebKit will look for plugins.
void webkit_web_context_get_plugins (WebKitWebContext *context
,GCancellable *cancellable
,GAsyncReadyCallback callback
,gpointer user_data
);
webkit_web_context_get_plugins
has been deprecated since version 2.32 and should not be used in newly-written code.
Asynchronously get the list of installed plugins.
When the operation is finished, callback
will be called. You can then call
webkit_web_context_get_plugins_finish()
to get the result of the operation.
context |
||
cancellable |
a GCancellable or |
[allow-none] |
callback |
a GAsyncReadyCallback to call when the request is satisfied. |
[scope async] |
user_data |
the data to pass to callback function. |
[closure] |
GList * webkit_web_context_get_plugins_finish (WebKitWebContext *context
,GAsyncResult *result
,GError **error
);
webkit_web_context_get_plugins_finish
has been deprecated since version 2.32 and should not be used in newly-written code.
Finish an asynchronous operation started with webkit_web_context_get_plugins.
a GList of WebKitPlugin. You must free the GList with
g_list_free()
and unref the WebKitPlugins with g_object_unref()
when you're done with them.
[element-type WebKitPlugin][transfer full]
gboolean
webkit_web_context_get_sandbox_enabled
(WebKitWebContext *context
);
Get whether sandboxing is currently enabled.
Since: 2.26
void webkit_web_context_set_sandbox_enabled (WebKitWebContext *context
,gboolean enabled
);
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.
Since: 2.26
void webkit_web_context_add_path_to_sandbox (WebKitWebContext *context
,const char *path
,gboolean 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 webkit_web_context_set_sandbox_enabled()
context |
||
path |
an absolute path to mount in the sandbox. |
[type filename] |
read_only |
if |
Since: 2.26
gboolean
webkit_web_context_get_spell_checking_enabled
(WebKitWebContext *context
);
Get whether spell checking feature is currently enabled.
void webkit_web_context_set_spell_checking_enabled (WebKitWebContext *context
,gboolean enabled
);
Enable or disable the spell checking feature.
const gchar * const *
webkit_web_context_get_spell_checking_languages
(WebKitWebContext *context
);
Get the the list of spell checking languages associated with
context
, or NULL
if no languages have been previously set.
See webkit_web_context_set_spell_checking_languages()
for more
details on the format of the languages in the list.
void webkit_web_context_set_spell_checking_languages (WebKitWebContext *context
,const gchar * const *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.
context |
||
languages |
a |
[array zero-terminated=1][transfer none] |
void webkit_web_context_set_preferred_languages (WebKitWebContext *context
,const gchar * const *languages
);
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 WebKitWebContext.
context |
||
languages |
a |
[allow-none][array zero-terminated=1][element-type utf8][transfer none] |
void webkit_web_context_set_tls_errors_policy (WebKitWebContext *context
,WebKitTLSErrorsPolicy policy
);
webkit_web_context_set_tls_errors_policy
has been deprecated since version 2.32. and should not be used in newly-written code.
Use webkit_website_data_manager_set_tls_errors_policy()
instead.
Set the TLS errors policy of context
as policy
WebKitTLSErrorsPolicy
webkit_web_context_get_tls_errors_policy
(WebKitWebContext *context
);
webkit_web_context_get_tls_errors_policy
has been deprecated since version 2.32. and should not be used in newly-written code.
Use webkit_website_data_manager_get_tls_errors_policy()
instead.
Get the TLS errors policy of context
void webkit_web_context_set_web_extensions_directory (WebKitWebContext *context
,const gchar *directory
);
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 “initialize-web-extensions” to call this method before anything is loaded.
void webkit_web_context_set_web_extensions_initialization_user_data (WebKitWebContext *context
,GVariant *user_data
);
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 “initialize-web-extensions” to call this method before anything is loaded.
Since: 2.4
void webkit_web_context_prefetch_dns (WebKitWebContext *context
,const gchar *hostname
);
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.
void webkit_web_context_set_disk_cache_directory (WebKitWebContext *context
,const gchar *directory
);
webkit_web_context_set_disk_cache_directory
has been deprecated since version 2.10. and should not be used in newly-written code.
Use webkit_web_context_new_with_website_data_manager()
instead.
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 WebKitWebsiteDataManager,
but it doesn't change the value returned by webkit_website_data_manager_get_disk_cache_directory()
since the WebKitWebsiteDataManager is immutable.
void webkit_web_context_allow_tls_certificate_for_host (WebKitWebContext *context
,GTlsCertificate *certificate
,const gchar *host
);
Ignore further TLS errors on the host
for the certificate present in info
.
Since: 2.6
WebKitProcessModel
webkit_web_context_get_process_model (WebKitWebContext *context
);
Returns the current process model. For more information about this value
see webkit_web_context_set_process_model()
.
Since: 2.4
void webkit_web_context_set_process_model (WebKitWebContext *context
,WebKitProcessModel process_model
);
Specifies a process model for WebViews, which WebKit will use to determine how auxiliary processes are handled.
WEBKIT_PROCESS_MODEL_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.
WEBKIT_PROCESS_MODEL_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.
Since: 2.4
void webkit_web_context_initialize_notification_permissions (WebKitWebContext *context
,GList *allowed_origins
,GList *disallowed_origins
);
Sets initial desktop notification permissions for the context
.
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 “initialize-notification-permissions” so as to ensure that new web processes receive the most recent set of permissions.
context |
the WebKitWebContext |
|
allowed_origins |
a GList of security origins. |
[element-type WebKitSecurityOrigin] |
disallowed_origins |
a GList of security origins. |
[element-type WebKitSecurityOrigin] |
Since: 2.16
void webkit_web_context_send_message_to_all_extensions (WebKitWebContext *context
,WebKitUserMessage *message
);
Send message
to all WebKitWebExtensions associated to context
.
If message
is floating, it's consumed.
Since: 2.28
void webkit_web_context_set_use_system_appearance_for_scrollbars (WebKitWebContext *context
,gboolean enabled
);
Set the “use-system-appearance-for-scrollbars” property.
Since: 2.30
gboolean
webkit_web_context_get_use_system_appearance_for_scrollbars
(WebKitWebContext *context
);
Get the “use-system-appearance-for-scrollbars” property.
Since: 2.30
void (*WebKitURISchemeRequestCallback) (WebKitURISchemeRequest *request
,gpointer user_data
);
Type definition for a function that will be called back when an URI request is made for a user registered URI scheme.
void webkit_web_context_register_uri_scheme (WebKitWebContext *context
,const gchar *scheme
,WebKitURISchemeRequestCallback callback
,gpointer user_data
,GDestroyNotify user_data_destroy_func
);
Register scheme
in context
, 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 g_object_ref()
on the
WebKitURISchemeRequest and calling webkit_uri_scheme_request_finish()
later
when the data of the request is available or
webkit_uri_scheme_request_finish_error()
in case of error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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); } |
Enum values used for determining the WebKitWebContext cache model.
Disable the cache completely, which substantially reduces memory usage. Useful for applications that only access a single local file, with no navigation to other pages. No remote resources will be cached. |
||
Improve document load speed substantially by caching a very large number of resources and previously viewed content. |
||
A cache model optimized for viewing a series of local files -- for example, a documentation viewer or a website designer. WebKit will cache a moderate number of resources. |
Enum values used for determining the WebKitWebContext process model.
Deprecated 2.26. |
||
Use one process for each WebKitWebView, while still allowing for some of them to share a process in certain situations. The main advantage of this process model is that the rendering process for a web view can crash while the rest of the views keep working normally. This process model is indicated for applications which may use a number of web views and the content of in each must not interfere with the rest — for example a full-fledged web browser with support for multiple tabs. |
Since: 2.4
“local-storage-directory”
property “local-storage-directory” char *
The directory where local storage data will be saved.
WebKitWebContext:local-storage-directory
has been deprecated since version 2.10. and should not be used in newly-written code.
Use “local-storage-directory” instead.
Owner: WebKitWebContext
Flags: Read / Write / Construct Only
Default value: NULL
Since: 2.8
“process-swap-on-cross-site-navigation-enabled”
property“process-swap-on-cross-site-navigation-enabled” gboolean
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.
Owner: WebKitWebContext
Flags: Read / Write / Construct Only
Default value: FALSE
Since: 2.28
“use-system-appearance-for-scrollbars”
property“use-system-appearance-for-scrollbars” gboolean
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.
Owner: WebKitWebContext
Flags: Read / Write / Construct
Default value: TRUE
Since: 2.30
“website-data-manager”
property“website-data-manager” WebKitWebsiteDataManager *
The WebKitWebsiteDataManager associated with this context.
Owner: WebKitWebContext
Flags: Read / Write / Construct Only
Since: 2.10
“automation-started”
signalvoid user_function (WebKitWebContext *context, WebKitAutomationSession *session, gpointer user_data)
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_web_context_set_automation_allowed()
for more details.
context |
the WebKitWebContext |
|
session |
the WebKitAutomationSession associated with this event |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
Since: 2.18
“download-started”
signalvoid user_function (WebKitWebContext *context, WebKitDownload *download, gpointer user_data)
This signal is emitted when a new download request is made.
context |
the WebKitWebContext |
|
download |
the WebKitDownload associated with this event |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
“initialize-notification-permissions”
signalvoid user_function (WebKitWebContext *context, gpointer user_data)
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
webkit_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
webkit_web_context_initialize_notification_permissions()
again.
context |
the WebKitWebContext |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
Since: 2.16
“initialize-web-extensions”
signalvoid user_function (WebKitWebContext *context, gpointer user_data)
This signal is emitted when a new web process is about to be
launched. It signals the most appropriate moment to use
webkit_web_context_set_web_extensions_initialization_user_data()
and webkit_web_context_set_web_extensions_directory()
.
context |
the WebKitWebContext |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
Since: 2.4
“user-message-received”
signalgboolean user_function (WebKitWebContext *context, WebKitUserMessage *message, gpointer user_data)
This signal is emitted when a WebKitUserMessage is received from a
WebKitWebExtension. You can reply to the message using
webkit_user_message_send_reply()
.
You can handle the user message asynchronously by calling g_object_ref()
on
message
and returning TRUE
.
context |
the WebKitWebContext |
|
message |
the WebKitUserMessage received |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
Since: 2.28