WebKit.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:
Class Details¶
- class WebKit.UserContentManager(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Manages user-defined content which affects web pages.
Using a
WebKit.UserContentManager
user CSS style sheets can be set to be injected in the web pages loaded by aWebKit.WebView
, byWebKit.UserContentManager.add_style_sheet
().To use a
WebKit.UserContentManager
, it must be created usingWebKit.UserContentManager.new
(), and then used to construct aWebKit.WebView
. User style sheets can be created withWebKit.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 (
WebKit.UserContentFilter
) – AWebKit.UserContentFilter
Adds a
WebKit.UserContentFilter
to the givenWebKit.UserContentManager
.The same
WebKit.UserContentFilter
can be reused with multipleWebKit.UserContentManager
instances.Filters need to be saved and loaded from
WebKit.UserContentFilterStore
.New in version 2.24.
- add_script(script)¶
- Parameters:
script (
WebKit.UserScript
) – AWebKit.UserScript
Adds a
WebKit.UserScript
to the givenWebKit.UserContentManager
.The same
WebKit.UserScript
can be reused with multipleWebKit.UserContentManager
instances.New in version 2.6.
- add_style_sheet(stylesheet)¶
- Parameters:
stylesheet (
WebKit.UserStyleSheet
) – AWebKit.UserStyleSheet
Adds a
WebKit.UserStyleSheet
to the givenWebKit.UserContentManager
.The same
WebKit.UserStyleSheet
can be reused with multipleWebKit.UserContentManager
instances.New in version 2.6.
- register_script_message_handler(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.
After it is registered, scripts can use
window.webkit.messageHandlers.<name>.postMessage(value)
to send messages. Those messages are received by connecting handlers to theWebKit.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.
If
None
is passed as the world_name, the default world will be used.The registered handler can be unregistered by using
WebKit.UserContentManager.unregister_script_message_handler
().New in version 2.40.
- 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
WebKit.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. SeeWebKit.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
WebKit.UserContentManager.unregister_script_message_handler
().New in version 2.40.
- remove_all_filters()¶
Removes all content filters from the given
WebKit.UserContentManager
.New in version 2.24.
- remove_all_scripts()¶
Removes all user scripts from the given
WebKit.UserContentManager
See also
WebKit.UserContentManager.remove_script
().New in version 2.6.
- remove_all_style_sheets()¶
Removes all user style sheets from the given
WebKit.UserContentManager
.New in version 2.6.
- remove_filter(filter)¶
- Parameters:
filter (
WebKit.UserContentFilter
) – AWebKit.UserContentFilter
Removes a filter from the given
WebKit.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
WebKit.UserContentManager
given the identifier of aWebKit.UserContentFilter
as returned byWebKit.UserContentFilter.get_identifier
().New in version 2.26.
- remove_script(script)¶
- Parameters:
script (
WebKit.UserScript
) – AWebKit.UserScript
Removes a
WebKit.UserScript
from the givenWebKit.UserContentManager
.See also
WebKit.UserContentManager.remove_all_scripts
().New in version 2.32.
- remove_style_sheet(stylesheet)¶
- Parameters:
stylesheet (
WebKit.UserStyleSheet
) – AWebKit.UserStyleSheet
Removes a
WebKit.UserStyleSheet
from the givenWebKit.UserContentManager
.See also
WebKit.UserContentManager.remove_all_style_sheets
().New in version 2.32.
- unregister_script_message_handler(name, world_name)¶
- Parameters:
Unregisters a previously registered message handler in script world with name world_name. If
None
is passed as the world_name, the default world will be used.Note that this does *not* disconnect handlers for the
WebKit.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
WebKit.UserContentManager.register_script_message_handler
().New in version 2.40.
Signal Details¶
- WebKit.UserContentManager.signals.script_message_received(user_content_manager, value)¶
- Signal Name:
script-message-received
- Flags:
- Parameters:
user_content_manager (
WebKit.UserContentManager
) – The object which received the signalvalue (
JavaScriptCore.Value
) – 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
WebKit.UserContentManager.register_script_message_handler
()New in version 2.8.
- WebKit.UserContentManager.signals.script_message_with_reply_received(user_content_manager, value, reply)¶
- Signal Name:
script-message-with-reply-received
- Flags:
- Parameters:
user_content_manager (
WebKit.UserContentManager
) – The object which received the signalvalue (
JavaScriptCore.Value
) – the value received from the JavaScript world.reply (
WebKit.ScriptMessageReply
) – theWebKit.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
WebKit.UserContentManager.register_script_message_handler_with_reply
()The given reply can be used to send a return value with
WebKit.ScriptMessageReply.return_value
() or an error message withWebKit.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.