WebKitWebProcessExtension.WebProcessExtension¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
None
Signals¶
- Inherited:
Name |
Short Description |
|---|---|
This signal is emitted when a new |
|
This signal is emitted when a |
Fields¶
- Inherited:
Class Details¶
- class WebKitWebProcessExtension.WebProcessExtension(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Represents an extension of the web process.
WebKitWebProcessExtension.WebProcessExtensionis 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.WebProcessExtensionyou should write a module with an initialization function that could be either webkit_web_process_extension_initialize() with prototypeWebKitWebProcessExtension.WebProcessExtensionInitializeFunctionor webkit_web_process_extension_initialize_with_user_data() with prototypeWebKitWebProcessExtension.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,objectuser_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.WebPageis 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,
objectuser_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 theWebKitWebProcessExtension.WebPageto get- Returns:
the
WebKitWebProcessExtension.WebPagefor the given page_id, orNoneif the identifier doesn’t correspond to an existing web page.- Return type:
Get the web page of the given page_id.
New in version 2.40.
- send_message_to_context(message, cancellable, callback, *user_data)¶
- Parameters:
message (
WebKitWebProcessExtension.UserMessage) – aWebKitWebProcessExtension.UserMessagecancellable (
Gio.CancellableorNone) – aGio.CancellableorNoneto ignorecallback (
Gio.AsyncReadyCallbackorNone) – AGio.AsyncReadyCallbackto call when the request is satisfied orNoneuser_data (
objectorNone) – the data to pass to callback function
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
Noneas calback. When the operation is finished, callback will be called. You can then callWebKitWebProcessExtension.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) – aGio.AsyncResult- Raises:
- Returns:
a
WebKitWebProcessExtension.UserMessagewith the reply orNonein case of error.- Return type:
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:
- Parameters:
web_process_extension (
WebKitWebProcessExtension.WebProcessExtension) – The object which received the signalweb_page (
WebKitWebProcessExtension.WebPage) – theWebKitWebProcessExtension.WebPagecreated
This signal is emitted when a new
WebKitWebProcessExtension.WebPageis 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:
- Parameters:
web_process_extension (
WebKitWebProcessExtension.WebProcessExtension) – The object which received the signalmessage (
WebKitWebProcessExtension.UserMessage) – theWebKitWebProcessExtension.UserMessagereceived
This signal is emitted when a
WebKitWebProcessExtension.UserMessageis 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. CallingWebKitWebProcessExtension.UserMessage.send_reply() will do nothing.New in version 2.40.