WebKitWebProcessExtension.WebProcessExtension

g GObject.Object GObject.Object WebKitWebProcessExtension.WebProcessExtension WebKitWebProcessExtension.WebProcessExtension GObject.Object->WebKitWebProcessExtension.WebProcessExtension

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

get_page (page_id)

send_message_to_context (message, cancellable, callback, *user_data)

send_message_to_context_finish (result)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Name

Short Description

page-created

This signal is emitted when a new WebKitWebProcessExtension.WebPage is created in the Web Process.

user-message-received

This signal is emitted when a WebKitWebProcessExtension.UserMessage is received from the #WebKitWebContext corresponding to extension.

Fields

Inherited:

GObject.Object (1)

Class Details

class WebKitWebProcessExtension.WebProcessExtension(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

WebKitWebProcessExtension.WebProcessExtensionClass

Represents an extension of the web process.

WebKitWebProcessExtension.WebProcessExtension 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.WebProcessExtension you should write a module with an initialization function that could be either webkit_web_process_extension_initialize() with prototype WebKitWebProcessExtension.WebProcessExtensionInitializeFunction or webkit_web_process_extension_initialize_with_user_data() with prototype WebKitWebProcessExtension.WebProcessExtensionInitializeWithUserDataFunction. 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.

```c static void web_page_created_callback (WebKitWebProcessExtension.WebProcessExtension *extension, WebKitWebProcessExtension.WebPage *web_page, object user_data) { g_print (“Page %d created for %s\n”, WebKitWebProcessExtension.WebPage.get_id (web_page), WebKitWebProcessExtension.WebPage.get_uri (web_page)); }

G_MODULE_EXPORT void webkit_web_process_extension_initialize (WebKitWebProcessExtension.WebProcessExtension *extension) { g_signal_connect (extension, “page-created”, G_CALLBACK (web_page_created_callback), None); } ```

The previous piece of code shows a trivial example of an extension that notifies when a WebKitWebProcessExtension.WebPage is created.

WebKit has to know where it can find the created WebKitWebProcessExtension.WebProcessExtension. 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:

```c #define WEB_EXTENSIONS_DIRECTORY // …

static void initialize_web_extensions (WebKitWebContext *context, object user_data) { // Web Extensions get a different ID for each Web Process static 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, GLib.Variant.new_uint32 (unique_id++)); }

int main (int argc, str **argv) { g_signal_connect (webkit_web_context_get_default (), “initialize-web-extensions”, G_CALLBACK (initialize_web_extensions), None);

Gtk.Widget *view = webkit_web_view_new ();

// … } ```

New in version 2.40.

get_page(page_id)
Parameters:

page_id (int) – the identifier of the WebKitWebProcessExtension.WebPage to get

Returns:

the WebKitWebProcessExtension.WebPage for the given page_id, or None if the identifier doesn’t correspond to an existing web page.

Return type:

WebKitWebProcessExtension.WebPage

Get the web page of the given page_id.

New in version 2.40.

send_message_to_context(message, cancellable, callback, *user_data)
Parameters:

Send message to the #WebKitWebContext corresponding to self. If message is floating, it’s consumed.

If you don’t expect any reply, or you simply want to ignore it, you can pass None as calback. When the operation is finished, callback will be called. You can then call WebKitWebProcessExtension.WebProcessExtension.send_message_to_context_finish() to get the message reply.

New in version 2.40.

send_message_to_context_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a WebKitWebProcessExtension.UserMessage with the reply or None in case of error.

Return type:

WebKitWebProcessExtension.UserMessage

Finish an asynchronous operation started with WebKitWebProcessExtension.WebProcessExtension.send_message_to_context().

New in version 2.40.

Signal Details

WebKitWebProcessExtension.WebProcessExtension.signals.page_created(web_process_extension, web_page)
Signal Name:

page-created

Flags:

RUN_LAST

Parameters:

This signal is emitted when a new WebKitWebProcessExtension.WebPage is created in the Web Process.

New in version 2.40.

WebKitWebProcessExtension.WebProcessExtension.signals.user_message_received(web_process_extension, message)
Signal Name:

user-message-received

Flags:

RUN_LAST

Parameters:

This signal is emitted when a WebKitWebProcessExtension.UserMessage is received from the #WebKitWebContext corresponding to extension. Messages sent by #WebKitWebContext are always broadcasted to all web extensions and they can’t be replied to. Calling WebKitWebProcessExtension.UserMessage.send_reply() will do nothing.

New in version 2.40.