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 ();
// ...
}
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of thePageCreatedCallback
callback.static interface
Functional interface declaration of theUserMessageReceivedCallback
callback.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionWebProcessExtension
(MemorySegment address) Create a WebProcessExtension proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected WebProcessExtension
asParent()
Returns this instance as if it were its parent type.static WebProcessExtension.Builder
<? extends WebProcessExtension.Builder> builder()
AWebProcessExtension.Builder
object constructs aWebProcessExtension
with the specified properties.void
emitPageCreated
(WebPage webPage) Emits the "page-created" signal.void
emitUserMessageReceived
(UserMessage message) Emits the "user-message-received" signal.getPage
(long pageId) Get the web page of the givenpageId
.static Type
getType()
Get the GType of the WebProcessExtension classThis signal is emitted when a newWebKitWebPage
is created in the Web Process.This signal is emitted when aWebKitUserMessage
is received from theWebKitWebContext
corresponding toextension
.void
sendMessageToContext
(UserMessage message, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Sendmessage
to theWebKitWebContext
corresponding to this WebProcessExtension.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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.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
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, 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 theWebKitWebPage
to get- Returns:
- the
WebKitWebPage
for the givenpageId
, ornull
if the identifier doesn't correspond to an existing web page.
-
sendMessageToContext
public void sendMessageToContext(UserMessage message, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Sendmessage
to theWebKitWebContext
corresponding to this WebProcessExtension. Ifmessage
is floating, it's consumed.If you don't expect any reply, or you simply want to ignore it, you can pass
null
ascalback
. When the operation is finished,callback
will be called. You can then call webkit_web_process_extension_send_message_to_context_finish() to get the message reply.- Parameters:
message
- aWebKitUserMessage
cancellable
- aGCancellable
ornull
to ignorecallback
- AGAsyncReadyCallback
to call when the request is satisfied ornull
-
sendMessageToContextFinish
Finish an asynchronous operation started with webkit_web_process_extension_send_message_to_context().- Parameters:
result
- aGAsyncResult
- Returns:
- a
WebKitUserMessage
with the reply ornull
in case of error. - Throws:
GErrorException
- seeGError
-
onPageCreated
public SignalConnection<WebProcessExtension.PageCreatedCallback> onPageCreated(WebProcessExtension.PageCreatedCallback handler) This signal is emitted when a newWebKitWebPage
is created in the Web Process.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitPageCreated
Emits the "page-created" signal. SeeonPageCreated(org.gnome.webkit.wpe.WebProcessExtension.PageCreatedCallback)
. -
onUserMessageReceived
public SignalConnection<WebProcessExtension.UserMessageReceivedCallback> onUserMessageReceived(WebProcessExtension.UserMessageReceivedCallback handler) This signal is emitted when aWebKitUserMessage
is received from theWebKitWebContext
corresponding toextension
. Messages sent byWebKitWebContext
are 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
- See Also:
-
emitUserMessageReceived
Emits the "user-message-received" signal. SeeonUserMessageReceived(org.gnome.webkit.wpe.WebProcessExtension.UserMessageReceivedCallback)
. -
builder
AWebProcessExtension.Builder
object constructs aWebProcessExtension
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withWebProcessExtension.Builder.build()
.
-