Class UserContentManager
- All Implemented Interfaces:
Proxy
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 used to construct
a WebKitWebView
. 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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theScriptMessageReceivedCallback
callback.static interface
Functional interface declaration of theScriptMessageWithReplyReceivedCallback
callback.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionCreates a new user content manager.UserContentManager
(MemorySegment address) Create a UserContentManager proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFilter
(UserContentFilter filter) Adds aWebKitUserContentFilter
to the givenWebKitUserContentManager
.void
addScript
(UserScript script) Adds aWebKitUserScript
to the givenWebKitUserContentManager
.void
addStyleSheet
(UserStyleSheet stylesheet) Adds aWebKitUserStyleSheet
to the givenWebKitUserContentManager
.protected UserContentManager
asParent()
Returns this instance as if it were its parent type.static UserContentManager.Builder
<? extends UserContentManager.Builder> builder()
AUserContentManager.Builder
object constructs aUserContentManager
with the specified properties.void
emitScriptMessageReceived
(@Nullable String detail, Value value) Emits the "script-message-received" signal.boolean
emitScriptMessageWithReplyReceived
(@Nullable String detail, Value value, ScriptMessageReply reply) Emits the "script-message-with-reply-received" signal.static Type
getType()
Get the GType of the UserContentManager classonScriptMessageReceived
(@Nullable String detail, UserContentManager.ScriptMessageReceivedCallback handler) 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_user_content_manager_register_script_message_handler()onScriptMessageWithReplyReceived
(@Nullable String detail, UserContentManager.ScriptMessageWithReplyReceivedCallback handler) 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_user_content_manager_register_script_message_handler_with_reply()boolean
registerScriptMessageHandler
(String name, @Nullable String worldName) Registers a new user script message handler in script world.boolean
registerScriptMessageHandlerWithReply
(String name, @Nullable String worldName) Registers a new user script message handler in script world with nameworldName
.void
Removes all content filters from the givenWebKitUserContentManager
.void
Removes all user scripts from the givenWebKitUserContentManager
void
Removes all user style sheets from the givenWebKitUserContentManager
.void
removeFilter
(UserContentFilter filter) Removes a filter from the givenWebKitUserContentManager
.void
removeFilterById
(String filterId) Removes a filter by the given identifier.void
removeScript
(UserScript script) Removes aWebKitUserScript
from the givenWebKitUserContentManager
.void
removeStyleSheet
(UserStyleSheet stylesheet) Removes aWebKitUserStyleSheet
from the givenWebKitUserContentManager
.void
unregisterScriptMessageHandler
(String name, @Nullable String worldName) Unregisters a previously registered message handler in script world with nameworldName
.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
UserContentManager
Create a UserContentManager proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
UserContentManager
Creates a new user content manager.- Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
addFilter
Adds aWebKitUserContentFilter
to the givenWebKitUserContentManager
.The same
WebKitUserContentFilter
can be reused with multipleWebKitUserContentManager
instances.Filters need to be saved and loaded from
WebKitUserContentFilterStore
.- Parameters:
filter
- AWebKitUserContentFilter
-
addScript
Adds aWebKitUserScript
to the givenWebKitUserContentManager
.The same
WebKitUserScript
can be reused with multipleWebKitUserContentManager
instances.- Parameters:
script
- AWebKitUserScript
-
addStyleSheet
Adds aWebKitUserStyleSheet
to the givenWebKitUserContentManager
.The same
WebKitUserStyleSheet
can be reused with multipleWebKitUserContentManager
instances.- Parameters:
stylesheet
- AWebKitUserStyleSheet
-
registerScriptMessageHandler
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 theWebKitUserContentManager
::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");
Registering a script message handler will fail if the requested name has been already registered before.
If
null
is passed as theworldName
, the default world will be used.The registered handler can be unregistered by using webkit_user_content_manager_unregister_script_message_handler().
- Parameters:
name
- Name of the script message channelworldName
- the name of aWebKitScriptWorld
- Returns:
true
if message handler was registered successfully, orfalse
otherwise.
-
registerScriptMessageHandlerWithReply
public boolean registerScriptMessageHandlerWithReply(String name, @Nullable @Nullable String worldName) Registers a new user script message handler in script world with nameworldName
.Different from webkit_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
null
is passed as theworldName
, the default world will be used. 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.
The registered handler can be unregistered by using webkit_user_content_manager_unregister_script_message_handler().
- Parameters:
name
- Name of the script message channelworldName
- the name of aWebKitScriptWorld
- Returns:
true
if message handler was registered successfully, orfalse
otherwise.
-
removeAllFilters
public void removeAllFilters()Removes all content filters from the givenWebKitUserContentManager
. -
removeAllScripts
public void removeAllScripts()Removes all user scripts from the givenWebKitUserContentManager
See also webkit_user_content_manager_remove_script().
-
removeAllStyleSheets
public void removeAllStyleSheets()Removes all user style sheets from the givenWebKitUserContentManager
. -
removeFilter
Removes a filter from the givenWebKitUserContentManager
.Since 2.24
- Parameters:
filter
- AWebKitUserContentFilter
-
removeFilterById
Removes a filter by the given identifier.Removes a filter from the given
WebKitUserContentManager
given the identifier of aWebKitUserContentFilter
as returned by webkit_user_content_filter_get_identifier().- Parameters:
filterId
- Filter identifier
-
removeScript
Removes aWebKitUserScript
from the givenWebKitUserContentManager
.See also webkit_user_content_manager_remove_all_scripts().
- Parameters:
script
- AWebKitUserScript
-
removeStyleSheet
Removes aWebKitUserStyleSheet
from the givenWebKitUserContentManager
.See also webkit_user_content_manager_remove_all_style_sheets().
- Parameters:
stylesheet
- AWebKitUserStyleSheet
-
unregisterScriptMessageHandler
Unregisters a previously registered message handler in script world with nameworldName
. Ifnull
is passed as theworldName
, the default world will be used.Note that this does not disconnect handlers for the
WebKitUserContentManager
::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:
name
- Name of the script message channelworldName
- the name of aWebKitScriptWorld
-
onScriptMessageReceived
public SignalConnection<UserContentManager.ScriptMessageReceivedCallback> onScriptMessageReceived(@Nullable @Nullable String detail, UserContentManager.ScriptMessageReceivedCallback handler) 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_user_content_manager_register_script_message_handler()- Parameters:
detail
- the signal detailhandler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitScriptMessageReceived
Emits the "script-message-received" signal. SeeonScriptMessageReceived(java.lang.String, org.gnome.webkit.UserContentManager.ScriptMessageReceivedCallback)
. -
onScriptMessageWithReplyReceived
public SignalConnection<UserContentManager.ScriptMessageWithReplyReceivedCallback> onScriptMessageWithReplyReceived(@Nullable @Nullable String detail, UserContentManager.ScriptMessageWithReplyReceivedCallback handler) 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_user_content_manager_register_script_message_handler_with_reply()The given
reply
can be used to send a return value with webkit_script_message_reply_return_value() or an error message with webkit_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 g_object_ref() on the
reply
and returningtrue
.- Parameters:
detail
- the signal detailhandler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitScriptMessageWithReplyReceived
public boolean emitScriptMessageWithReplyReceived(@Nullable @Nullable String detail, Value value, ScriptMessageReply reply) Emits the "script-message-with-reply-received" signal. SeeonScriptMessageWithReplyReceived(java.lang.String, org.gnome.webkit.UserContentManager.ScriptMessageWithReplyReceivedCallback)
. -
builder
AUserContentManager.Builder
object constructs aUserContentManager
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withUserContentManager.Builder.build()
.
-