gi-webkit2webextension-4.0.28: WebKit2-WebExtension bindings
CopyrightWill Thompson and Iñaki García Etxebarria
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellSafe-Inferred
LanguageHaskell2010

GI.WebKit2WebExtension.Objects.WebExtension

Description

Represents an extension of the WebProcess.

WebKitWebExtension 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 WebKitWebExtension you should write a module with an initialization function that could be either webkit_web_extension_initialize() with prototype WebExtensionInitializeFunction or webkit_web_extension_initialize_with_user_data() with prototype 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 code

static void
web_page_created_callback (WebKitWebExtension *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_extension_initialize (WebKitWebExtension *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 WebKitWebExtension. 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 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 ();

  // ...
}
Synopsis

Exported types

newtype WebExtension Source #

Memory-managed wrapper type.

Constructors

WebExtension (ManagedPtr WebExtension) 

Instances

Instances details
Eq WebExtension Source # 
Instance details

Defined in GI.WebKit2WebExtension.Objects.WebExtension

GObject WebExtension Source # 
Instance details

Defined in GI.WebKit2WebExtension.Objects.WebExtension

ManagedPtrNewtype WebExtension Source # 
Instance details

Defined in GI.WebKit2WebExtension.Objects.WebExtension

Methods

toManagedPtr :: WebExtension -> ManagedPtr WebExtension

TypedObject WebExtension Source # 
Instance details

Defined in GI.WebKit2WebExtension.Objects.WebExtension

Methods

glibType :: IO GType

HasParentTypes WebExtension Source # 
Instance details

Defined in GI.WebKit2WebExtension.Objects.WebExtension

IsGValue (Maybe WebExtension) Source #

Convert WebExtension to and from GValue. See toGValue and fromGValue.

Instance details

Defined in GI.WebKit2WebExtension.Objects.WebExtension

Methods

gvalueGType_ :: IO GType

gvalueSet_ :: Ptr GValue -> Maybe WebExtension -> IO ()

gvalueGet_ :: Ptr GValue -> IO (Maybe WebExtension)

type ParentTypes WebExtension Source # 
Instance details

Defined in GI.WebKit2WebExtension.Objects.WebExtension

type ParentTypes WebExtension = '[Object]

class (GObject o, IsDescendantOf WebExtension o) => IsWebExtension o Source #

Type class for types which can be safely cast to WebExtension, for instance with toWebExtension.

Instances

Instances details
(GObject o, IsDescendantOf WebExtension o) => IsWebExtension o Source # 
Instance details

Defined in GI.WebKit2WebExtension.Objects.WebExtension

toWebExtension :: (MonadIO m, IsWebExtension o) => o -> m WebExtension Source #

Cast to WebExtension, for types for which this is known to be safe. For general casts, use castTo.

Methods

getPage

webExtensionGetPage Source #

Arguments

:: (HasCallStack, MonadIO m, IsWebExtension a) 
=> a

extension: a WebExtension

-> Word64

pageId: the identifier of the WebPage to get

-> m (Maybe WebPage)

Returns: the WebPage for the given pageId, or Nothing if the identifier doesn't correspond to an existing web page.

Get the web page of the given pageId.

sendMessageToContext

webExtensionSendMessageToContext Source #

Arguments

:: (HasCallStack, MonadIO m, IsWebExtension a, IsUserMessage b, IsCancellable c) 
=> a

extension: a WebExtension

-> b

message: a UserMessage

-> Maybe c

cancellable: a Cancellable or Nothing to ignore

-> Maybe AsyncReadyCallback

callback: (nullable): A AsyncReadyCallback to call when the request is satisfied or Nothing

-> 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 webExtensionSendMessageToContextFinish to get the message reply.

Since: 2.28

sendMessageToContextFinish

webExtensionSendMessageToContextFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsWebExtension a, IsAsyncResult b) 
=> a

extension: a WebExtension

-> b

result: a AsyncResult

-> m UserMessage

Returns: a UserMessage with the reply or Nothing in case of error. (Can throw GError)

Finish an asynchronous operation started with webExtensionSendMessageToContext.

Since: 2.28

Signals

pageCreated

type WebExtensionPageCreatedCallback Source #

Arguments

 = WebPage

webPage: the WebPage created

-> IO () 

This signal is emitted when a new WebPage is created in the Web Process.

afterWebExtensionPageCreated :: (IsWebExtension a, MonadIO m) => a -> ((?self :: a) => WebExtensionPageCreatedCallback) -> 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 webExtension #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.

onWebExtensionPageCreated :: (IsWebExtension a, MonadIO m) => a -> ((?self :: a) => WebExtensionPageCreatedCallback) -> 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 webExtension #pageCreated callback

userMessageReceived

type WebExtensionUserMessageReceivedCallback Source #

Arguments

 = UserMessage

message: the UserMessage received

-> 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 WebExtensions and they can't be replied to. Calling userMessageSendReply will do nothing.

Since: 2.28

afterWebExtensionUserMessageReceived :: (IsWebExtension a, MonadIO m) => a -> ((?self :: a) => WebExtensionUserMessageReceivedCallback) -> 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 webExtension #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.

onWebExtensionUserMessageReceived :: (IsWebExtension a, MonadIO m) => a -> ((?self :: a) => WebExtensionUserMessageReceivedCallback) -> 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 webExtension #userMessageReceived callback