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.WebExtension
is 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.WebExtension
you should write a module with an initialization function that could be either webkit_web_extension_initialize() with prototypeWebKit2WebExtension.WebExtensionInitializeFunction
or 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,object
user_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.WebPage
is 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,
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 ();// … } ```
- get_page(page_id)¶
- Parameters:
page_id (
int
) – the identifier of theWebKit2WebExtension.WebPage
to get- Returns:
the
WebKit2WebExtension.WebPage
for the given page_id, orNone
if 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.UserMessage
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – AGio.AsyncReadyCallback
to call when the request is satisfied orNone
user_data (
object
orNone
) – 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
None
as 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.UserMessage
with the reply orNone
in 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.WebPage
created
This signal is emitted when a new
WebKit2WebExtension.WebPage
is 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.UserMessage
received
This signal is emitted when a
WebKit2WebExtension.UserMessage
is received from the #WebKitWebContext corresponding to extension. Messages sent by #WebKitWebContext are always broadcasted to allWebKit2WebExtension.WebExtension
s and they can’t be replied to. CallingWebKit2WebExtension.UserMessage.send_reply
() will do nothing.New in version 2.28.