WebKit2WebExtension.WebExtension¶
- 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:
Name |
Type |
Access |
Description |
|---|---|---|---|
parent |
r |
Class Details¶
- class WebKit2WebExtension.WebExtension(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Represents an extension of the WebProcess.
WebKit2WebExtension.WebExtensionis a loadable module for the WebProcess. It allows you to execute code in the WebProcess and being able to use the DOM API, to change any request or to inject custom JavaScript code, for example.To create a
WebKit2WebExtension.WebExtensionyou should write a module with an initialization function that could be either webkit_web_extension_initialize() with prototypeWebKit2WebExtension.WebExtensionInitializeFunctionor webkit_web_extension_initialize_with_user_data() with prototypeWebKit2WebExtension.WebExtensionInitializeWithUserDataFunction. 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 (
WebKit2WebExtension.WebExtension*extension,WebKit2WebExtension.WebPage*web_page,objectuser_data) { g_print (“Page %d created for %s\n”,WebKit2WebExtension.WebPage.get_id(web_page),WebKit2WebExtension.WebPage.get_uri(web_page)); }G_MODULE_EXPORT void webkit_web_extension_initialize (
WebKit2WebExtension.WebExtension*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
WebKit2WebExtension.WebPageis created.WebKit has to know where it can find the created
WebKit2WebExtension.WebExtension. 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_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 ();// … } ```
- get_page(page_id)¶
- Parameters:
page_id (
int) – the identifier of theWebKit2WebExtension.WebPageto get- Returns:
the
WebKit2WebExtension.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.
- send_message_to_context(message, cancellable, callback, *user_data)¶
- Parameters:
message (
WebKit2WebExtension.UserMessage) – aWebKit2WebExtension.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 callWebKit2WebExtension.WebExtension.send_message_to_context_finish() to get the message reply.New in version 2.28.
- send_message_to_context_finish(result)¶
- Parameters:
result (
Gio.AsyncResult) – aGio.AsyncResult- Raises:
- Returns:
a
WebKit2WebExtension.UserMessagewith the reply orNonein case of error.- Return type:
Finish an asynchronous operation started with
WebKit2WebExtension.WebExtension.send_message_to_context().New in version 2.28.
Signal Details¶
- WebKit2WebExtension.WebExtension.signals.page_created(web_extension, web_page)¶
- Signal Name:
page-created- Flags:
- Parameters:
web_extension (
WebKit2WebExtension.WebExtension) – The object which received the signalweb_page (
WebKit2WebExtension.WebPage) – theWebKit2WebExtension.WebPagecreated
This signal is emitted when a new
WebKit2WebExtension.WebPageis created in the Web Process.
- WebKit2WebExtension.WebExtension.signals.user_message_received(web_extension, message)¶
- Signal Name:
user-message-received- Flags:
- Parameters:
web_extension (
WebKit2WebExtension.WebExtension) – The object which received the signalmessage (
WebKit2WebExtension.UserMessage) – theWebKit2WebExtension.UserMessagereceived
This signal is emitted when a
WebKit2WebExtension.UserMessageis received from the #WebKitWebContext corresponding to extension. Messages sent by #WebKitWebContext are always broadcasted to allWebKit2WebExtension.WebExtensions and they can’t be replied to. CallingWebKit2WebExtension.UserMessage.send_reply() will do nothing.New in version 2.28.