WebKitWebProcessExtension is a loadable module for the web process. It allows you to execute code in the
web process and being able to use the DOM API, to change any request or to inject custom
JavaScript code, for example.
To create a WebKitWebProcessExtension you should write a module with an initialization function that could
be either webkit_web_process_extension_initialize() with prototype #WebKitWebProcessExtensionInitializeFunction or
webkit_web_process_extension_initialize_with_user_data() with prototype #WebKitWebProcessExtensionInitializeWithUserDataFunction.
This function has to be public and it has to use the #G_MODULE_EXPORT macro. It is called when the
web process is initialized.
The previous piece of code shows a trivial example of an extension that notifies when
a #WebKitWebPage is created.
WebKit has to know where it can find the created WebKitWebProcessExtension. To do so you
should use the webkit_web_context_set_web_extensions_directory() function. The signal
#WebKitWebContext::initialize-web-extensions is the recommended place to call it.
To provide the initialization data used by the webkit_web_process_extension_initialize_with_user_data()
function, you have to call webkit_web_context_set_web_extensions_initialization_user_data() with
the desired data as parameter. You can see an example of this in the following piece of code:
#define WEB_EXTENSIONS_DIRECTORY // ...staticvoid
initialize_web_extensions (WebKitWebContext *context,
gpointer user_data)
{
// Web Extensions get a different ID for each Web Processstatic guint32 unique_id = 0;
webkit_web_context_set_web_extensions_directory (
context, WEB_EXTENSIONS_DIRECTORY);
webkit_web_context_set_web_extensions_initialization_user_data (
context, g_variant_new_uint32 (unique_id++));
}
int main (int argc, char **argv)
{
g_signal_connect (webkit_web_context_get_default (),
"initialize-web-extensions",
G_CALLBACK (initialize_web_extensions),
NULL);
GtkWidget *view = webkit_web_view_new ();
// ...
}
Represents an extension of the web process.
WebKitWebProcessExtension is a loadable module for the web process. It allows you to execute code in the web process and being able to use the DOM API, to change any request or to inject custom JavaScript code, for example.
To create a WebKitWebProcessExtension you should write a module with an initialization function that could be either webkit_web_process_extension_initialize() with prototype #WebKitWebProcessExtensionInitializeFunction or webkit_web_process_extension_initialize_with_user_data() with prototype #WebKitWebProcessExtensionInitializeWithUserDataFunction. This function has to be public and it has to use the #G_MODULE_EXPORT macro. It is called when the web process is initialized.
The previous piece of code shows a trivial example of an extension that notifies when a #WebKitWebPage is created.
WebKit has to know where it can find the created WebKitWebProcessExtension. To do so you should use the webkit_web_context_set_web_extensions_directory() function. The signal #WebKitWebContext::initialize-web-extensions is the recommended place to call it.
To provide the initialization data used by the webkit_web_process_extension_initialize_with_user_data() function, you have to call webkit_web_context_set_web_extensions_initialization_user_data() with the desired data as parameter. You can see an example of this in the following piece of code: