Trait webkit2gtk::prelude::UserContentManagerExt
source · [−]pub trait UserContentManagerExt: 'static {
Show 15 methods
fn add_filter(&self, filter: &UserContentFilter);
fn add_script(&self, script: &UserScript);
fn add_style_sheet(&self, stylesheet: &UserStyleSheet);
fn register_script_message_handler(&self, name: &str) -> bool;
fn register_script_message_handler_in_world(
&self,
name: &str,
world_name: &str
) -> bool;
fn remove_all_filters(&self);
fn remove_all_scripts(&self);
fn remove_all_style_sheets(&self);
fn remove_filter(&self, filter: &UserContentFilter);
fn remove_filter_by_id(&self, filter_id: &str);
fn remove_script(&self, script: &UserScript);
fn remove_style_sheet(&self, stylesheet: &UserStyleSheet);
fn unregister_script_message_handler(&self, name: &str);
fn unregister_script_message_handler_in_world(
&self,
name: &str,
world_name: &str
);
fn connect_script_message_received<F: Fn(&Self, &JavascriptResult) + 'static>(
&self,
detail: Option<&str>,
f: F
) -> SignalHandlerId;
}
v2_6
only.Expand description
Required Methods
sourcefn add_filter(&self, filter: &UserContentFilter)
fn add_filter(&self, filter: &UserContentFilter)
v2_24
only.Adds a UserContentFilter
to the given UserContentManager
.
The same UserContentFilter
can be reused with multiple
UserContentManager
instances.
Filters need to be saved and loaded from UserContentFilterStore
.
filter
sourcefn add_script(&self, script: &UserScript)
fn add_script(&self, script: &UserScript)
Adds a UserScript
to the given UserContentManager
.
The same UserScript
can be reused with multiple
UserContentManager
instances.
script
sourcefn add_style_sheet(&self, stylesheet: &UserStyleSheet)
fn add_style_sheet(&self, stylesheet: &UserStyleSheet)
Adds a UserStyleSheet
to the given UserContentManager
.
The same UserStyleSheet
can be reused with multiple
UserContentManager
instances.
stylesheet
sourcefn register_script_message_handler(&self, name: &str) -> bool
fn register_script_message_handler(&self, name: &str) -> bool
v2_8
only.Registers a new user script message handler.
After it is registered,
scripts can use window.webkit.messageHandlers.
.postMessage(value)
to send messages. Those messages are received by connecting handlers
to the signal::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:
⚠️ The following code is in 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.
name
Name of the script message channel
Returns
true
if message handler was registered successfully, or false
otherwise.
sourcefn register_script_message_handler_in_world(
&self,
name: &str,
world_name: &str
) -> bool
fn register_script_message_handler_in_world(
&self,
name: &str,
world_name: &str
) -> bool
v2_22
only.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 register_script_message_handler()
for full description.
Registering a script message handler will fail if the requested name has been already registered before.
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.
sourcefn remove_all_filters(&self)
fn remove_all_filters(&self)
v2_24
only.Removes all content filters from the given UserContentManager
.
sourcefn remove_all_scripts(&self)
fn remove_all_scripts(&self)
Removes all user scripts from the given UserContentManager
See also remove_script()
.
sourcefn remove_all_style_sheets(&self)
fn remove_all_style_sheets(&self)
Removes all user style sheets from the given UserContentManager
.
sourcefn remove_filter(&self, filter: &UserContentFilter)
fn remove_filter(&self, filter: &UserContentFilter)
v2_24
only.sourcefn remove_filter_by_id(&self, filter_id: &str)
fn remove_filter_by_id(&self, filter_id: &str)
v2_26
only.Removes a filter by the given identifier.
Removes a filter from the given UserContentManager
given the
identifier of a UserContentFilter
as returned by
UserContentFilter::identifier()
.
filter_id
Filter identifier
sourcefn remove_script(&self, script: &UserScript)
fn remove_script(&self, script: &UserScript)
v2_32
only.sourcefn remove_style_sheet(&self, stylesheet: &UserStyleSheet)
fn remove_style_sheet(&self, stylesheet: &UserStyleSheet)
v2_32
only.Removes a UserStyleSheet
from the given UserContentManager
.
See also remove_all_style_sheets()
.
stylesheet
sourcefn unregister_script_message_handler(&self, name: &str)
fn unregister_script_message_handler(&self, name: &str)
v2_8
only.Unregisters a previously registered message handler.
Note that this does not disconnect handlers for the
signal::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 register_script_message_handler()
.
name
Name of the script message channel
sourcefn unregister_script_message_handler_in_world(&self, name: &str, world_name: &str)
fn unregister_script_message_handler_in_world(&self, name: &str, world_name: &str)
v2_22
only.Unregisters a previously registered message handler in script world with name world_name
.
Note that this does not disconnect handlers for the
signal::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 register_script_message_handler_in_world()
.
name
Name of the script message channel
world_name
the name of a WebKitScriptWorld
sourcefn connect_script_message_received<F: Fn(&Self, &JavascriptResult) + 'static>(
&self,
detail: Option<&str>,
f: F
) -> SignalHandlerId
fn connect_script_message_received<F: Fn(&Self, &JavascriptResult) + 'static>(
&self,
detail: Option<&str>,
f: F
) -> SignalHandlerId
v2_8
only.This signal is emitted when JavaScript in a web view calls
<code>
window.webkit.messageHandlers.<name>
.postMessage()</code>
, after registering
<code>``<name>``</code>
using
register_script_message_handler()
js_result
the JavascriptResult
holding the value received from the JavaScript world.