Class WebContext
- All Implemented Interfaces:
Proxy
WebKitWebView<!-- -->s
The WebKitWebContext manages all aspects common to all
WebKitWebView<!-- -->s.
You can define the WebKitCacheModel with
webkit_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
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 WebKitWebView::load-failed-with-tls-errors.
Alternatively, you can use webkit_web_context_set_tls_errors_policy()
to set the policy TLSErrorsPolicy.IGNORE; however, this is
not appropriate for Internet applications.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface declaration of theAutomationStartedCallbackcallback.static classWebContext.Builder<B extends WebContext.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theInitializeNotificationPermissionsCallbackcallback.static interfaceFunctional interface declaration of theInitializeWebProcessExtensionsCallbackcallback.static interfaceFunctional interface declaration of theUserMessageReceivedCallbackcallback.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new WebContext.WebContext(MemorySegment address) Create a WebContext proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPathToSandbox(String path, boolean readOnly) Adds a path to be mounted in the sandbox.protected WebContextasParent()Returns this instance as if it were its parent type.static WebContext.Builder<? extends WebContext.Builder> builder()AWebContext.Builderobject constructs aWebContextwith the specified properties.voidemitAutomationStarted(@Nullable AutomationSession session) Emits the "automation-started" signal.voidEmits the "initialize-notification-permissions" signal.voidEmits the "initialize-web-process-extensions" signal.booleanemitUserMessageReceived(@Nullable UserMessage message) Emits the "user-message-received" signal.Returns the current cache model.static WebContextGets the default web context.Get theWebKitGeolocationManagerofcontext.@Nullable NetworkSessionGet theWebKitNetworkSessionused for automation sessions started incontext.Get theWebKitSecurityManagerofcontext.booleanGet whether spell checking feature is currently enabled.String[]Get the the list of spell checking languages.Get theWebKitWebContext:time-zone-override property.static @Nullable TypegetType()Get the GType of the WebContext classvoidinitializeNotificationPermissions(List<SecurityOrigin> allowedOrigins, List<SecurityOrigin> disallowedOrigins) Sets initial desktop notification permissions for thecontext.booleanGet whether automation is allowed incontext.This signal is emitted when a new automation request is made.This signal is emitted when aWebKitWebContextneeds to set initial notification permissions for a web process.This signal is emitted when a new web process is about to be launched.This signal is emitted when aWebKitUserMessageis received from a web process extension.voidregisterUriScheme(String scheme, @Nullable URISchemeRequestCallback callback) Registerschemeincontext.voidsendMessageToAllExtensions(UserMessage message) Sendmessageto all web process extensions associated tocontext.voidsetAutomationAllowed(boolean allowed) Set whether automation is allowed incontext.voidsetCacheModel(CacheModel cacheModel) Specifies a usage model for WebViews.voidsetPreferredLanguages(@Nullable String @Nullable [] languages) Set the list of preferred languages.voidsetSpellCheckingEnabled(boolean enabled) Enable or disable the spell checking feature.voidsetSpellCheckingLanguages(@Nullable String @Nullable [] languages) Set the list of spell checking languages to be used for spell checking.voidsetWebProcessExtensionsDirectory(String directory) Set the directory where WebKit will look for web process extensions.voidSet user data to be passed to Web Extensions on initialization.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
WebContext
Create a WebContext proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
WebContext
public WebContext()Creates a new WebContext.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
getDefault
-
addPathToSandbox
Adds a path to be mounted in the sandbox.pathmust 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/devare 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()
- Parameters:
path- an absolute path to mount in the sandboxreadOnly- iftruethe path will be read-only- Since:
- 2.26
-
getCacheModel
Returns the current cache model.For more information about this value check the documentation of the function webkit_web_context_set_cache_model().
- Returns:
- the current
WebKitCacheModel
-
getGeolocationManager
Get theWebKitGeolocationManagerofcontext.- Returns:
- the
WebKitGeolocationManagerofcontext. - Since:
- 2.26
-
getNetworkSessionForAutomation
Get theWebKitNetworkSessionused for automation sessions started incontext.- Returns:
- a
WebKitNetworkSession, ornullif automation is not enabled - Since:
- 2.40
-
getSecurityManager
Get theWebKitSecurityManagerofcontext.- Returns:
- the
WebKitSecurityManagerofcontext.
-
getSpellCheckingEnabled
public boolean getSpellCheckingEnabled()Get whether spell checking feature is currently enabled.- Returns:
trueIf spell checking is enabled, orfalseotherwise.
-
getSpellCheckingLanguages
Get the the list of spell checking languages.Get the the list of spell checking languages associated with
context,ornullif 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.
- Returns:
- A
null-terminated array of languages if available, ornullotherwise.
-
getTimeZoneOverride
Get theWebKitWebContext:time-zone-override property.- Since:
- 2.38
-
initializeNotificationPermissions
public void initializeNotificationPermissions(List<SecurityOrigin> allowedOrigins, List<SecurityOrigin> disallowedOrigins) Sets initial desktop notification permissions for thecontext.allowedOriginsanddisallowedOriginsmust each beGListofWebKitSecurityOriginobjects representing origins that will, respectively, either always or never have permission to show desktop notifications. NoWebKitNotificationPermissionRequestwill ever be generated for any of the security origins represented inallowedOriginsordisallowedOrigins.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
WebKitWebContext::initialize-notification-permissions so as to ensure that new web processes receive the most recent set of permissions.- Parameters:
allowedOrigins- aGListof security originsdisallowedOrigins- aGListof security origins- Since:
- 2.16
-
isAutomationAllowed
public boolean isAutomationAllowed()Get whether automation is allowed incontext.See also webkit_web_context_set_automation_allowed().
- Returns:
trueif automation is allowed orfalseotherwise.- Since:
- 2.18
-
registerUriScheme
Registerschemeincontext.Register
schemeincontext,so that when an URI request withschemeis made in theWebKitWebContext, theWebKitURISchemeRequestCallbackregistered will be called with aWebKitURISchemeRequest. It is possible to handle URI scheme requests asynchronously, by calling g_object_ref() on theWebKitURISchemeRequestand 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.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); }- Parameters:
scheme- the network scheme to registercallback- aWebKitURISchemeRequestCallback
-
sendMessageToAllExtensions
Sendmessageto all web process extensions associated tocontext.If
messageis floating, it's consumed.- Parameters:
message- aWebKitUserMessage- Since:
- 2.28
-
setAutomationAllowed
public void setAutomationAllowed(boolean allowed) Set whether automation is allowed incontext.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
WebKitWebContext::automation-started is emitted. Automation is disabled by default, so you need to explicitly call this method passingtrueto enable it.Note that only one
WebKitWebContextcan have automation enabled, so this will do nothing if there's anotherWebKitWebContextwith automation already enabled.- Parameters:
allowed- value to set- Since:
- 2.18
-
setCacheModel
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
CacheModel.WEB_BROWSER. Applications without a browsing interface can reduce memory usage substantially by specifyingCacheModel.DOCUMENT_VIEWER. The default value isCacheModel.WEB_BROWSER.- Parameters:
cacheModel- aWebKitCacheModel
-
setPreferredLanguages
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-LanguageHTTP header that will be included in the network requests started by theWebKitWebContext. - Setting the values of
navigator.languageandnavigator.languages. - The first item in the list sets the default locale for JavaScript
Intlfunctions.
- Parameters:
languages- anull-terminated list of language identifiers
- Determining how to build the
-
setSpellCheckingEnabled
public void setSpellCheckingEnabled(boolean enabled) Enable or disable the spell checking feature.- Parameters:
enabled- Value to be set
-
setSpellCheckingLanguages
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.
- Parameters:
languages- anull-terminated list of spell checking languages
-
setWebProcessExtensionsDirectory
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
WebKitWebContext::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 webkit_web_context_add_path_to_sandbox().
- Parameters:
directory- the directory to add
-
setWebProcessExtensionsInitializationUserData
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 toWebKitWebContext::initialize-web-process-extensions to call this method before anything is loaded.- Parameters:
userData- aGVariant- Since:
- 2.4
-
onAutomationStarted
public SignalConnection<WebContext.AutomationStartedCallback> onAutomationStarted(WebContext.AutomationStartedCallback handler) This signal is emitted when a new automation request is made. Note that it will never be emitted if automation is not enabled incontext,see webkit_web_context_set_automation_allowed() for more details.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.18
- See Also:
-
emitAutomationStarted
Emits the "automation-started" signal. SeeonAutomationStarted(org.webkitgtk.WebContext.AutomationStartedCallback). -
onInitializeNotificationPermissions
public SignalConnection<WebContext.InitializeNotificationPermissionsCallback> onInitializeNotificationPermissions(WebContext.InitializeNotificationPermissionsCallback handler) This signal is emitted when aWebKitWebContextneeds 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.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.16
- See Also:
-
emitInitializeNotificationPermissions
public void emitInitializeNotificationPermissions()Emits the "initialize-notification-permissions" signal. SeeonInitializeNotificationPermissions(org.webkitgtk.WebContext.InitializeNotificationPermissionsCallback). -
onInitializeWebProcessExtensions
public SignalConnection<WebContext.InitializeWebProcessExtensionsCallback> onInitializeWebProcessExtensions(WebContext.InitializeWebProcessExtensionsCallback handler) 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_process_extensions_initialization_user_data() and webkit_web_context_set_web_process_extensions_directory().- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.4
- See Also:
-
emitInitializeWebProcessExtensions
public void emitInitializeWebProcessExtensions()Emits the "initialize-web-process-extensions" signal. SeeonInitializeWebProcessExtensions(org.webkitgtk.WebContext.InitializeWebProcessExtensionsCallback). -
onUserMessageReceived
public SignalConnection<WebContext.UserMessageReceivedCallback> onUserMessageReceived(WebContext.UserMessageReceivedCallback handler) This signal is emitted when aWebKitUserMessageis received from a web process extension. 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
messageand returningtrue.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.28
- See Also:
-
emitUserMessageReceived
Emits the "user-message-received" signal. SeeonUserMessageReceived(org.webkitgtk.WebContext.UserMessageReceivedCallback). -
builder
AWebContext.Builderobject constructs aWebContextwith the specified properties. Use the variousset...()methods to set properties, and finish construction withWebContext.Builder.build().- Returns:
- the builder object
-