1.38 <WebKitUserContentManager>

Class: <WebKitUserContentManager>

It derives from <GObject>.

Manages user-defined content which affects web pages.

Using a <WebKitUserContentManager> user CSS style sheets can be set to be injected in the web pages loaded by a <WebKitWebView>, by user-content-manager:add-style-sheet.

To use a <WebKitUserContentManager>, it must be created using user-content-manager:new, and then used to construct a <WebKitWebView>. User style sheets can be created with user-style-sheet:new.

User style sheets can be added and removed at any time, but they will affect the web pages loaded afterwards.

Procedures

Method: user-content-manager:add-filter self filter
Method: add-filter self filter

Adds a <WebKitUserContentFilter> to the given <WebKitUserContentManager>.

The same <WebKitUserContentFilter> can be reused with multiple <WebKitUserContentManager> instances.

Filters need to be saved and loaded from <WebKitUserContentFilterStore>.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

filter

Passed: a <WebKitUserContentFilter>.

A <WebKitUserContentFilter>

Method: user-content-manager:add-script self script
Method: add-script self script

Adds a <WebKitUserScript> to the given <WebKitUserContentManager>.

The same <WebKitUserScript> can be reused with multiple <WebKitUserContentManager> instances.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

script

Passed: a <WebKitUserScript>.

A <WebKitUserScript>

Method: user-content-manager:add-style-sheet self stylesheet
Method: add-style-sheet self stylesheet

Adds a <WebKitUserStyleSheet> to the given <WebKitUserContentManager>.

The same <WebKitUserStyleSheet> can be reused with multiple <WebKitUserContentManager> instances.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

stylesheet

Passed: a <WebKitUserStyleSheet>.

A <WebKitUserStyleSheet>

Procedure: user-content-manager:new ⇒ %return

Creates a new user content manager.

%return

Returned: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

Method: user-content-manager:register-script-message-handler-with-reply? self name [world-name] ⇒ %return
Method: register-script-message-handler-with-reply? self name [world-name] ⇒ %return

Registers a new user script message handler in script world with name world-name.

Different from user-content-manager:register-script-message-handler?, when using this function to register the handler, the connected signal is script-message-with-reply-received, and a reply provided by the user is expected. Otherwise, the user will receive a default undefined value.

If #f is passed as the world-name, the default world will be used. See user-content-manager:register-script-message-handler? for full description.

Registering a script message handler will fail if the requested name has been already registered before.

The registered handler can be unregistered by using user-content-manager:unregister-script-message-handler.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

name

Passed: a string.

Name of the script message channel

world-name

Passed, or left out: a string, or #f.

the name of a WebKitScriptWorld

%return

Returned: a boolean.

#t if message handler was registered successfully, or #f otherwise.

Method: user-content-manager:register-script-message-handler? self name [world-name] ⇒ %return
Method: register-script-message-handler? self name [world-name] ⇒ %return

Registers a new user script message handler in script world.

After it is registered, scripts can use window.webkit.messageHandlers.<name>.postMessage(value) to send messages. Those messages are received by connecting handlers to the user-content-manager:script-message-received signal. The handler name is used as the detail of the signal. To avoid race conditions between registering the handler name, and starting to receive the signals, it is recommended to connect to the signal before registering the handler name:

WebKitWebView *view = webkit_web_view_new ();
WebKitUserContentManager *manager = webkit_web_view_get_user_content_manager ();
g_signal_connect (manager, "script-message-received::foobar",
                  G_CALLBACK (handle_script_message), NULL);
webkit_user_content_manager_register_script_message_handler (manager, "foobar", "world");

Registering a script message handler will fail if the requested name has been already registered before.

If #f is passed as the world-name, the default world will be used.

The registered handler can be unregistered by using user-content-manager:unregister-script-message-handler.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

name

Passed: a string.

Name of the script message channel

world-name

Passed, or left out: a string, or #f.

the name of a WebKitScriptWorld

%return

Returned: a boolean.

#t if message handler was registered successfully, or #f otherwise.

Method: user-content-manager:remove-all-filters self
Method: remove-all-filters self

Removes all content filters from the given <WebKitUserContentManager>.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

Method: user-content-manager:remove-all-scripts self
Method: remove-all-scripts self

Removes all user scripts from the given <WebKitUserContentManager>

See also user-content-manager:remove-script.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

Method: user-content-manager:remove-all-style-sheets self
Method: remove-all-style-sheets self

Removes all user style sheets from the given <WebKitUserContentManager>.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

Method: user-content-manager:remove-filter self filter
Method: remove-filter self filter

Removes a filter from the given <WebKitUserContentManager>.

Since 2.24

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

filter

Passed: a <WebKitUserContentFilter>.

A <WebKitUserContentFilter>

Method: user-content-manager:remove-filter-by-id self filter-id
Method: remove-filter-by-id self filter-id

Removes a filter by the given identifier.

Removes a filter from the given <WebKitUserContentManager> given the identifier of a <WebKitUserContentFilter> as returned by user-content-filter:get-identifier.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

filter-id

Passed: a string.

Filter identifier

Method: user-content-manager:remove-script self script
Method: remove-script self script

Removes a <WebKitUserScript> from the given <WebKitUserContentManager>.

See also user-content-manager:remove-all-scripts.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

script

Passed: a <WebKitUserScript>.

A <WebKitUserScript>

Method: user-content-manager:remove-style-sheet self stylesheet
Method: remove-style-sheet self stylesheet

Removes a <WebKitUserStyleSheet> from the given <WebKitUserContentManager>.

See also user-content-manager:remove-all-style-sheets.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

stylesheet

Passed: a <WebKitUserStyleSheet>.

A <WebKitUserStyleSheet>

Method: user-content-manager:unregister-script-message-handler self name [world-name]
Method: unregister-script-message-handler self name [world-name]

Unregisters a previously registered message handler in script world with name world-name. If #f is passed as the world-name, the default world will be used.

Note that this does not disconnect handlers for the user-content-manager:script-message-received signal; they will be kept connected, but the signal will not be emitted unless the handler name is registered again.

See also user-content-manager:register-script-message-handler?.

self

Passed: a <WebKitUserContentManager>.

A <WebKitUserContentManager>

name

Passed: a string.

Name of the script message channel

world-name

Passed, or left out: a string, or #f.

the name of a WebKitScriptWorld

Signals

Signal: user-content-manager:script-message-received

Connect a handler with (connect object user-content-manager:script-message-received handler). It is called as (handler self value).

This signal is emitted when JavaScript in a web view calls <code>window.webkit.messageHandlers.<name>.postMessage()</code>, after registering <code><name></code> using user-content-manager:register-script-message-handler?

self

Passed: a <WebKitUserContentManager>.

value

Passed: a <JSCValue>.

the value received from the JavaScript world.

Signal: user-content-manager:script-message-with-reply-received

Connect a handler with (connect object user-content-manager:script-message-with-reply-received handler). It is called as (handler self value reply) ⇒ %return.

This signal is emitted when JavaScript in a web view calls <code>window.webkit.messageHandlers.<name>.postMessage()</code>, after registering <code><name></code> using user-content-manager:register-script-message-handler-with-reply?

The given reply can be used to send a return value with script-message-reply:return-value or an error message with script-message-reply:return-error-message. If none of them are called, an automatic reply with an undefined value will be sent.

It is possible to handle the reply asynchronously, by simply calling object:ref on the reply and returning #t.

self

Passed: a <WebKitUserContentManager>.

value

Passed: a <JSCValue>.

the value received from the JavaScript world.

reply

Passed: a <WebKitScriptMessageReply>.

the <WebKitScriptMessageReply> to send the reply to the script message.

%return

Returned: a boolean.

#t to stop other handlers from being invoked for the event. #f to propagate the event further.