Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Represents an extension of the web process.
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 WebProcessExtensionInitializeFunction
or
webkit_web_process_extension_initialize_with_user_data()
with prototype 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 code
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 WebPage
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:
c 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
Synopsis
- newtype WebProcessExtension = WebProcessExtension (ManagedPtr WebProcessExtension)
- class (GObject o, IsDescendantOf WebProcessExtension o) => IsWebProcessExtension o
- toWebProcessExtension :: (MonadIO m, IsWebProcessExtension o) => o -> m WebProcessExtension
- webProcessExtensionGetPage :: (HasCallStack, MonadIO m, IsWebProcessExtension a) => a -> Word64 -> m WebPage
- webProcessExtensionSendMessageToContext :: (HasCallStack, MonadIO m, IsWebProcessExtension a, IsUserMessage b, IsCancellable c) => a -> b -> Maybe c -> Maybe AsyncReadyCallback -> m ()
- webProcessExtensionSendMessageToContextFinish :: (HasCallStack, MonadIO m, IsWebProcessExtension a, IsAsyncResult b) => a -> b -> m UserMessage
- type WebProcessExtensionPageCreatedCallback = WebPage -> IO ()
- afterWebProcessExtensionPageCreated :: (IsWebProcessExtension a, MonadIO m) => a -> ((?self :: a) => WebProcessExtensionPageCreatedCallback) -> m SignalHandlerId
- onWebProcessExtensionPageCreated :: (IsWebProcessExtension a, MonadIO m) => a -> ((?self :: a) => WebProcessExtensionPageCreatedCallback) -> m SignalHandlerId
- type WebProcessExtensionUserMessageReceivedCallback = UserMessage -> IO ()
- afterWebProcessExtensionUserMessageReceived :: (IsWebProcessExtension a, MonadIO m) => a -> ((?self :: a) => WebProcessExtensionUserMessageReceivedCallback) -> m SignalHandlerId
- onWebProcessExtensionUserMessageReceived :: (IsWebProcessExtension a, MonadIO m) => a -> ((?self :: a) => WebProcessExtensionUserMessageReceivedCallback) -> m SignalHandlerId
Exported types
newtype WebProcessExtension Source #
Memory-managed wrapper type.
WebProcessExtension (ManagedPtr WebProcessExtension) |
Instances
class (GObject o, IsDescendantOf WebProcessExtension o) => IsWebProcessExtension o Source #
Type class for types which can be safely cast to WebProcessExtension
, for instance with toWebProcessExtension
.
Instances
(GObject o, IsDescendantOf WebProcessExtension o) => IsWebProcessExtension o Source # | |
toWebProcessExtension :: (MonadIO m, IsWebProcessExtension o) => o -> m WebProcessExtension Source #
Cast to WebProcessExtension
, for types for which this is known to be safe. For general casts, use castTo
.
Methods
Click to display all available methods, including inherited ones
Methods
bindProperty, bindPropertyFull, forceFloating, freezeNotify, getv, isFloating, notify, notifyByPspec, ref, refSink, runDispose, sendMessageToContext, sendMessageToContextFinish, stealData, stealQdata, thawNotify, unref, watchClosure.
Getters
getData, getPage, getProperty, getQdata.
Setters
getPage
webProcessExtensionGetPage Source #
:: (HasCallStack, MonadIO m, IsWebProcessExtension a) | |
=> a |
|
-> Word64 |
|
-> m WebPage | Returns: the |
Get the web page of the given pageId
.
Since: 2.40
sendMessageToContext
webProcessExtensionSendMessageToContext Source #
:: (HasCallStack, MonadIO m, IsWebProcessExtension a, IsUserMessage b, IsCancellable c) | |
=> a |
|
-> b |
|
-> Maybe c |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
Send message
to the WebKitWebContext
corresponding to extension
. If message
is floating, it's consumed.
If you don't expect any reply, or you simply want to ignore it, you can pass Nothing
as calback
.
When the operation is finished, callback
will be called. You can then call
webProcessExtensionSendMessageToContextFinish
to get the message reply.
Since: 2.40
sendMessageToContextFinish
webProcessExtensionSendMessageToContextFinish Source #
:: (HasCallStack, MonadIO m, IsWebProcessExtension a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m UserMessage | Returns: a |
Finish an asynchronous operation started with webProcessExtensionSendMessageToContext
.
Since: 2.40
Signals
pageCreated
type WebProcessExtensionPageCreatedCallback Source #
This signal is emitted when a new WebPage
is created in
the Web Process.
Since: 2.40
afterWebProcessExtensionPageCreated :: (IsWebProcessExtension a, MonadIO m) => a -> ((?self :: a) => WebProcessExtensionPageCreatedCallback) -> m SignalHandlerId Source #
Connect a signal handler for the pageCreated signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
webProcessExtension #pageCreated callback
By default the object invoking the signal is not passed to the callback.
If you need to access it, you can use the implit ?self
parameter.
Note that this requires activating the ImplicitParams
GHC extension.
onWebProcessExtensionPageCreated :: (IsWebProcessExtension a, MonadIO m) => a -> ((?self :: a) => WebProcessExtensionPageCreatedCallback) -> m SignalHandlerId Source #
Connect a signal handler for the pageCreated signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
webProcessExtension #pageCreated callback
userMessageReceived
type WebProcessExtensionUserMessageReceivedCallback Source #
= UserMessage |
|
-> IO () |
This signal is emitted when a UserMessage
is 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. Calling userMessageSendReply
will do nothing.
Since: 2.40
afterWebProcessExtensionUserMessageReceived :: (IsWebProcessExtension a, MonadIO m) => a -> ((?self :: a) => WebProcessExtensionUserMessageReceivedCallback) -> m SignalHandlerId Source #
Connect a signal handler for the userMessageReceived signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
webProcessExtension #userMessageReceived callback
By default the object invoking the signal is not passed to the callback.
If you need to access it, you can use the implit ?self
parameter.
Note that this requires activating the ImplicitParams
GHC extension.
onWebProcessExtensionUserMessageReceived :: (IsWebProcessExtension a, MonadIO m) => a -> ((?self :: a) => WebProcessExtensionUserMessageReceivedCallback) -> m SignalHandlerId Source #
Connect a signal handler for the userMessageReceived signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
webProcessExtension #userMessageReceived callback