WebKit2.UserContentManager¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
None
Signals¶
- Inherited:
Name |
Short Description |
---|---|
This signal is emitted when JavaScript in a web view calls <code>window.webkit.messageHandlers.<name>.postMessage()</code>, after registering <code><name></code> using |
|
This signal is emitted when JavaScript in a web view calls <code>window.webkit.messageHandlers.<name>.postMessage()</code>, after registering <code><name></code> using |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent |
r |
Class Details¶
- class WebKit2.UserContentManager(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Manages user-defined content which affects web pages.
Using a
WebKit2.UserContentManager
user CSS style sheets can be set to be injected in the web pages loaded by aWebKit2.WebView
, byWebKit2.UserContentManager.add_style_sheet
().To use a
WebKit2.UserContentManager
, it must be created usingWebKit2.UserContentManager.new
(), and then used to construct aWebKit2.WebView
. User style sheets can be created withWebKit2.UserStyleSheet.new
().User style sheets can be added and removed at any time, but they will affect the web pages loaded afterwards.
New in version 2.6.
- classmethod new()¶
- Returns:
- Return type:
Creates a new user content manager.
New in version 2.6.
- add_filter(filter)¶
- Parameters:
filter (
WebKit2.UserContentFilter
) – AWebKit2.UserContentFilter
Adds a
WebKit2.UserContentFilter
to the givenWebKit2.UserContentManager
.The same
WebKit2.UserContentFilter
can be reused with multipleWebKit2.UserContentManager
instances.Filters need to be saved and loaded from
WebKit2.UserContentFilterStore
.New in version 2.24.
- add_script(script)¶
- Parameters:
script (
WebKit2.UserScript
) – AWebKit2.UserScript
Adds a
WebKit2.UserScript
to the givenWebKit2.UserContentManager
.The same
WebKit2.UserScript
can be reused with multipleWebKit2.UserContentManager
instances.New in version 2.6.
- add_style_sheet(stylesheet)¶
- Parameters:
stylesheet (
WebKit2.UserStyleSheet
) – AWebKit2.UserStyleSheet
Adds a
WebKit2.UserStyleSheet
to the givenWebKit2.UserContentManager
.The same
WebKit2.UserStyleSheet
can be reused with multipleWebKit2.UserContentManager
instances.New in version 2.6.
- register_script_message_handler(name)¶
- Parameters:
name (
str
) – Name of the script message channel- Returns:
True
if message handler was registered successfully, orFalse
otherwise.- Return type:
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 theWebKit2.UserContentManager
::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:``c 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.
New in version 2.8.
- register_script_message_handler_in_world(name, world_name)¶
- Parameters:
- Returns:
True
if message handler was registered successfully, orFalse
otherwise.- Return type:
Registers a new user script message handler in script world.
Registers a new user script message handler in script world with name world_name. See
WebKit2.UserContentManager.register_script_message_handler
() for full description.Registering a script message handler will fail if the requested name has been already registered before.
New in version 2.22.
- register_script_message_handler_with_reply(name, world_name)¶
- Parameters:
- Returns:
True
if message handler was registered successfully, orFalse
otherwise.- Return type:
Registers a new user script message handler in script world with name world_name.
Different from
WebKit2.UserContentManager.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
None
is passed as the world_name, the default world will be used. SeeWebKit2.UserContentManager.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
WebKit2.UserContentManager.unregister_script_message_handler
().New in version 2.40.
- remove_all_filters()¶
Removes all content filters from the given
WebKit2.UserContentManager
.New in version 2.24.
- remove_all_scripts()¶
Removes all user scripts from the given
WebKit2.UserContentManager
See also
WebKit2.UserContentManager.remove_script
().New in version 2.6.
- remove_all_style_sheets()¶
Removes all user style sheets from the given
WebKit2.UserContentManager
.New in version 2.6.
- remove_filter(filter)¶
- Parameters:
filter (
WebKit2.UserContentFilter
) – AWebKit2.UserContentFilter
Removes a filter from the given
WebKit2.UserContentManager
.New in version 2.24.
- remove_filter_by_id(filter_id)¶
- Parameters:
filter_id (
str
) – Filter identifier
Removes a filter by the given identifier.
Removes a filter from the given
WebKit2.UserContentManager
given the identifier of aWebKit2.UserContentFilter
as returned byWebKit2.UserContentFilter.get_identifier
().New in version 2.26.
- remove_script(script)¶
- Parameters:
script (
WebKit2.UserScript
) – AWebKit2.UserScript
Removes a
WebKit2.UserScript
from the givenWebKit2.UserContentManager
.See also
WebKit2.UserContentManager.remove_all_scripts
().New in version 2.32.
- remove_style_sheet(stylesheet)¶
- Parameters:
stylesheet (
WebKit2.UserStyleSheet
) – AWebKit2.UserStyleSheet
Removes a
WebKit2.UserStyleSheet
from the givenWebKit2.UserContentManager
.See also
WebKit2.UserContentManager.remove_all_style_sheets
().New in version 2.32.
- unregister_script_message_handler(name)¶
- Parameters:
name (
str
) – Name of the script message channel
Unregisters a previously registered message handler.
Note that this does *not* disconnect handlers for the
WebKit2.UserContentManager
::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
WebKit2.UserContentManager.register_script_message_handler
().New in version 2.8.
- unregister_script_message_handler_in_world(name, world_name)¶
- Parameters:
Unregisters a previously registered message handler in script world with name world_name.
Note that this does *not* disconnect handlers for the
WebKit2.UserContentManager
::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
WebKit2.UserContentManager.register_script_message_handler_in_world
().New in version 2.22.
Signal Details¶
- WebKit2.UserContentManager.signals.script_message_received(user_content_manager, value)¶
- Signal Name:
script-message-received
- Flags:
- Parameters:
user_content_manager (
WebKit2.UserContentManager
) – The object which received the signalvalue (
WebKit2.JavascriptResult
) – the value received from the JavaScript world.
This signal is emitted when JavaScript in a web view calls <code>window.webkit.messageHandlers.<name>.postMessage()</code>, after registering <code><name></code> using
WebKit2.UserContentManager.register_script_message_handler
()New in version 2.8.
- WebKit2.UserContentManager.signals.script_message_with_reply_received(user_content_manager, value, reply)¶
- Signal Name:
script-message-with-reply-received
- Flags:
- Parameters:
user_content_manager (
WebKit2.UserContentManager
) – The object which received the signalvalue (
JavaScriptCore.Value
) – the value received from the JavaScript world.reply (
WebKit2.ScriptMessageReply
) – theWebKit2.ScriptMessageReply
to send the reply to the script message.
- Returns:
True
to stop other handlers from being invoked for the event.False
to propagate the event further.- Return type:
This signal is emitted when JavaScript in a web view calls <code>window.webkit.messageHandlers.<name>.postMessage()</code>, after registering <code><name></code> using
WebKit2.UserContentManager.register_script_message_handler_with_reply
()The given reply can be used to send a return value with
WebKit2.ScriptMessageReply.return_value
() or an error message withWebKit2.ScriptMessageReply.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
GObject.Object.ref
() on the reply and returningTrue
.New in version 2.40.