WebKitUserContentManager

WebKitUserContentManager — Manages user-defined content which affects web pages.

Functions

Signals

Types and Values

Object Hierarchy

    GObject
    ╰── WebKitUserContentManager

Description

Using a WebKitUserContentManager user CSS style sheets can be set to be injected in the web pages loaded by a WebKitWebView, by webkit_user_content_manager_add_style_sheet().

To use a WebKitUserContentManager, it must be created using webkit_user_content_manager_new(), and then passed to webkit_web_view_new_with_user_content_manager(). User style sheets can be created with webkit_user_style_sheet_new().

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

Functions

webkit_user_content_manager_new ()

WebKitUserContentManager *
webkit_user_content_manager_new (void);

Creates a new user content manager.

Since: 2.6


webkit_user_content_manager_add_style_sheet ()

void
webkit_user_content_manager_add_style_sheet
                               (WebKitUserContentManager *manager,
                                WebKitUserStyleSheet *stylesheet);

Adds a WebKitUserStyleSheet to the given WebKitUserContentManager. The same WebKitUserStyleSheet can be reused with multiple WebKitUserContentManager instances.

Parameters

manager

A WebKitUserContentManager

 

stylesheet

A WebKitUserStyleSheet

 

Since: 2.6


webkit_user_content_manager_remove_style_sheet ()

void
webkit_user_content_manager_remove_style_sheet
                               (WebKitUserContentManager *manager,
                                WebKitUserStyleSheet *stylesheet);

Removes a WebKitUserStyleSheet from the given WebKitUserContentManager.

See also webkit_user_content_manager_remove_all_style_sheets().

Parameters

manager

A WebKitUserContentManager

 

stylesheet

A WebKitUserStyleSheet

 

Since: 2.32


webkit_user_content_manager_remove_all_style_sheets ()

void
webkit_user_content_manager_remove_all_style_sheets
                               (WebKitUserContentManager *manager);

Removes all user style sheets from the given WebKitUserContentManager.

Parameters

Since: 2.6


webkit_user_content_manager_add_script ()

void
webkit_user_content_manager_add_script
                               (WebKitUserContentManager *manager,
                                WebKitUserScript *script);

Adds a WebKitUserScript to the given WebKitUserContentManager. The same WebKitUserScript can be reused with multiple WebKitUserContentManager instances.

Parameters

manager

A WebKitUserContentManager

 

script

A WebKitUserScript

 

Since: 2.6


webkit_user_content_manager_remove_script ()

void
webkit_user_content_manager_remove_script
                               (WebKitUserContentManager *manager,
                                WebKitUserScript *script);

Removes a WebKitUserScript from the given WebKitUserContentManager.

See also webkit_user_content_manager_remove_all_scripts().

Parameters

manager

A WebKitUserContentManager

 

script

A WebKitUserScript

 

Since: 2.32


webkit_user_content_manager_remove_all_scripts ()

void
webkit_user_content_manager_remove_all_scripts
                               (WebKitUserContentManager *manager);

Removes all user scripts from the given WebKitUserContentManager

See also webkit_user_content_manager_remove_script().

Parameters

Since: 2.6


webkit_user_content_manager_register_script_message_handler ()

gboolean
webkit_user_content_manager_register_script_message_handler
                               (WebKitUserContentManager *manager,
                                const gchar *name);

Registers a new user script message handler. 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 “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:

1
2
3
4
5
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");

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

Parameters

manager

A WebKitUserContentManager

 

name

Name of the script message channel

 

Returns

TRUE if message handler was registered successfully, or FALSE otherwise.

Since: 2.8


webkit_user_content_manager_unregister_script_message_handler ()

void
webkit_user_content_manager_unregister_script_message_handler
                               (WebKitUserContentManager *manager,
                                const gchar *name);

Unregisters a previously registered message handler.

Note that this does *not* disconnect handlers for the “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 webkit_user_content_manager_register_script_message_handler().

Parameters

manager

A WebKitUserContentManager

 

name

Name of the script message channel

 

Since: 2.8


webkit_user_content_manager_register_script_message_handler_in_world ()

gboolean
webkit_user_content_manager_register_script_message_handler_in_world
                               (WebKitUserContentManager *manager,
                                const gchar *name,
                                const gchar *world_name);

Registers a new user script message handler in script world with name world_name . See webkit_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.

Parameters

manager

A WebKitUserContentManager

 

name

Name of the script message channel

 

world_name

the name of a WebKitScriptWorld

 

Returns

TRUE if message handler was registered successfully, or FALSE otherwise.

Since: 2.22


webkit_user_content_manager_unregister_script_message_handler_in_world ()

void
webkit_user_content_manager_unregister_script_message_handler_in_world
                               (WebKitUserContentManager *manager,
                                const gchar *name,
                                const gchar *world_name);

Unregisters a previously registered message handler in script world with name world_name .

Note that this does *not* disconnect handlers for the “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 webkit_user_content_manager_register_script_message_handler_in_world().

Parameters

manager

A WebKitUserContentManager

 

name

Name of the script message channel

 

world_name

the name of a WebKitScriptWorld

 

Since: 2.22


webkit_user_content_manager_add_filter ()

void
webkit_user_content_manager_add_filter
                               (WebKitUserContentManager *manager,
                                WebKitUserContentFilter *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.

Parameters

Since: 2.24


webkit_user_content_manager_remove_filter ()

void
webkit_user_content_manager_remove_filter
                               (WebKitUserContentManager *manager,
                                WebKitUserContentFilter *filter);

Removes a filter from the given WebKitUserContentManager.

Since 2.24

Parameters


webkit_user_content_manager_remove_filter_by_id ()

void
webkit_user_content_manager_remove_filter_by_id
                               (WebKitUserContentManager *manager,
                                const char *filter_id);

Removes a filter from the given WebKitUserContentManager given the identifier of a WebKitUserContentFilter as returned by webkit_user_content_filter_get_identifier().

Parameters

manager

A WebKitUserContentManager

 

filter_id

Filter identifier

 

Since: 2.26


webkit_user_content_manager_remove_all_filters ()

void
webkit_user_content_manager_remove_all_filters
                               (WebKitUserContentManager *manager);

Removes all content filters from the given WebKitUserContentManager.

Parameters

Since: 2.24

Types and Values

struct WebKitUserContentManager

struct WebKitUserContentManager;

Signal Details

The “script-message-received” signal

void
user_function (WebKitUserContentManager *manager,
               WebKitJavascriptResult   *js_result,
               gpointer                  user_data)

This signal is emitted when JavaScript in a web view calls

window.webkit.messageHandlers.<name>.postMessage(), after registering <name> using

webkit_user_content_manager_register_script_message_handler()

Parameters

manager

the WebKitUserContentManager

 

js_result

the WebKitJavascriptResult holding the value received from the JavaScript world.

 

user_data

user data set when the signal handler was connected.

 

Flags: Has Details

Since: 2.8