Class WebProcessExtension
- All Implemented Interfaces:
Proxy
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.
static void
web_page_created_callback (WebKitWebProcessExtension *extension,
WebKitWebPage *web_page,
gpointer user_data)
{
g_print ("Page %d created for %s\\n",
webkit_web_page_get_id (web_page),
webkit_web_page_get_uri (web_page));
}
G_MODULE_EXPORT void
webkit_web_process_extension_initialize (WebKitWebProcessExtension *extension)
{
g_signal_connect (extension, "page-created",
G_CALLBACK (web_page_created_callback),
NULL);
}
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 // ...
static void
initialize_web_extensions (WebKitWebContext *context,
gpointer 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, 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 ();
// ...
}
- Since:
- 2.40
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of thePageCreatedCallbackcallback.static interfaceFunctional interface declaration of theUserMessageReceivedCallbackcallback.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new WebProcessExtension.WebProcessExtension(MemorySegment address) Create a WebProcessExtension proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected WebProcessExtensionasParent()Returns this instance as if it were its parent type.static WebProcessExtension.Builder<? extends WebProcessExtension.Builder> builder()AWebProcessExtension.Builderobject constructs aWebProcessExtensionwith the specified properties.voidemitPageCreated(@Nullable WebPage webPage) Emits the "page-created" signal.voidemitUserMessageReceived(@Nullable UserMessage message) Emits the "user-message-received" signal.getPage(long pageId) Get the web page of the givenpageId.static @Nullable TypegetType()Get the GType of the WebProcessExtension classThis signal is emitted when a newWebKitWebPageis created in the Web Process.This signal is emitted when aWebKitUserMessageis received from theWebKitWebContextcorresponding toextension.Messages sent byWebKitWebContextare always broadcasted to all web extensions and they can't be replied to.voidsendMessageToContext(UserMessage message, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Sendmessageto theWebKitWebContextcorresponding toextension.Ifmessageis floating, it's consumed.Finish an asynchronous operation started with webkit_web_process_extension_send_message_to_context().Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
WebProcessExtension
Create a WebProcessExtension proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
WebProcessExtension
public WebProcessExtension()Creates a new WebProcessExtension.
-
-
Method Details
-
getType
Get the GType of the WebProcessExtension class- Returns:
- the GType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
getPage
Get the web page of the givenpageId.- Parameters:
pageId- the identifier of theWebKitWebPageto get- Returns:
- the
WebKitWebPagefor the givenpageId,ornullif the identifier doesn't correspond to an existing web page. - Since:
- 2.40
-
sendMessageToContext
public void sendMessageToContext(UserMessage message, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Sendmessageto theWebKitWebContextcorresponding toextension.Ifmessageis floating, it's consumed.If you don't expect any reply, or you simply want to ignore it, you can pass
nullascalback.When the operation is finished,callbackwill be called. You can then call webkit_web_process_extension_send_message_to_context_finish() to get the message reply.- Parameters:
message- aWebKitUserMessagecancellable- aGCancellableornullto ignorecallback- AGAsyncReadyCallbackto call when the request is satisfied ornull- Since:
- 2.40
-
sendMessageToContextFinish
Finish an asynchronous operation started with webkit_web_process_extension_send_message_to_context().- Parameters:
result- aGAsyncResult- Returns:
- a
WebKitUserMessagewith the reply ornullin case of error. - Throws:
GErrorException- seeGError- Since:
- 2.40
-
onPageCreated
public SignalConnection<WebProcessExtension.PageCreatedCallback> onPageCreated(WebProcessExtension.PageCreatedCallback handler) This signal is emitted when a newWebKitWebPageis created in the Web Process.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.40
- See Also:
-
emitPageCreated
Emits the "page-created" signal. SeeonPageCreated(org.webkitgtk.webprocessextension.WebProcessExtension.PageCreatedCallback). -
onUserMessageReceived
public SignalConnection<WebProcessExtension.UserMessageReceivedCallback> onUserMessageReceived(WebProcessExtension.UserMessageReceivedCallback handler) This signal is emitted when aWebKitUserMessageis received from theWebKitWebContextcorresponding toextension.Messages sent byWebKitWebContextare always broadcasted to all web extensions and they can't be replied to. Calling webkit_user_message_send_reply() will do nothing.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.40
- See Also:
-
emitUserMessageReceived
Emits the "user-message-received" signal. SeeonUserMessageReceived(org.webkitgtk.webprocessextension.WebProcessExtension.UserMessageReceivedCallback). -
builder
AWebProcessExtension.Builderobject constructs aWebProcessExtensionwith the specified properties. Use the variousset...()methods to set properties, and finish construction withWebProcessExtension.Builder.build().- Returns:
- the builder object
-