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.
- Since:
- 2.6
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theScriptMessageReceivedCallbackcallback.static interfaceFunctional interface declaration of theScriptMessageWithReplyReceivedCallbackcallback.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new UserContentManager.UserContentManager(MemorySegment address) Create a UserContentManager proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFilter(UserContentFilter filter) Adds aWebKitUserContentFilterto the givenWebKitUserContentManager.voidaddScript(UserScript script) Adds aWebKitUserScriptto the givenWebKitUserContentManager.voidaddStyleSheet(UserStyleSheet stylesheet) Adds aWebKitUserStyleSheetto the givenWebKitUserContentManager.protected UserContentManagerasParent()Returns this instance as if it were its parent type.static UserContentManager.Builder<? extends UserContentManager.Builder> builder()AUserContentManager.Builderobject constructs aUserContentManagerwith the specified properties.voidemitScriptMessageReceived(@Nullable String detail, @Nullable Value value) Emits the "script-message-received" signal.booleanemitScriptMessageWithReplyReceived(@Nullable String detail, @Nullable Value value, @Nullable ScriptMessageReply reply) Emits the "script-message-with-reply-received" signal.static @Nullable TypegetType()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()booleanregisterScriptMessageHandler(String name, @Nullable String worldName) Registers a new user script message handler in script world.booleanregisterScriptMessageHandlerWithReply(String name, @Nullable String worldName) Registers a new user script message handler in script world with nameworldName.voidRemoves all content filters from the givenWebKitUserContentManager.voidRemoves all user scripts from the givenWebKitUserContentManagervoidRemoves all user style sheets from the givenWebKitUserContentManager.voidremoveFilter(UserContentFilter filter) Removes a filter from the givenWebKitUserContentManager.voidremoveFilterById(String filterId) Removes a filter by the given identifier.voidremoveScript(UserScript script) Removes aWebKitUserScriptfrom the givenWebKitUserContentManager.voidremoveStyleSheet(UserStyleSheet stylesheet) Removes aWebKitUserStyleSheetfrom the givenWebKitUserContentManager.voidunregisterScriptMessageHandler(String name, @Nullable String worldName) Unregisters a previously registered message handler in script world with nameworldName.Ifnullis passed as theworldName,the default world will be used.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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.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
public UserContentManager()Creates a new UserContentManager.
-
-
Method Details
-
getType
Get the GType of the UserContentManager class- Returns:
- the GType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, 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 aWebKitUserContentFilterto the givenWebKitUserContentManager.The same
WebKitUserContentFiltercan be reused with multipleWebKitUserContentManagerinstances.Filters need to be saved and loaded from
WebKitUserContentFilterStore.- Parameters:
filter- AWebKitUserContentFilter- Since:
- 2.24
-
addScript
Adds aWebKitUserScriptto the givenWebKitUserContentManager.The same
WebKitUserScriptcan be reused with multipleWebKitUserContentManagerinstances.- Parameters:
script- AWebKitUserScript- Since:
- 2.6
-
addStyleSheet
Adds aWebKitUserStyleSheetto the givenWebKitUserContentManager.The same
WebKitUserStyleSheetcan be reused with multipleWebKitUserContentManagerinstances.- Parameters:
stylesheet- AWebKitUserStyleSheet- Since:
- 2.6
-
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
nullis 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:
trueif message handler was registered successfully, orfalseotherwise.- Since:
- 2.40
-
registerScriptMessageHandlerWithReply
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
nullis 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:
trueif message handler was registered successfully, orfalseotherwise.- Since:
- 2.40
-
removeAllFilters
public void removeAllFilters()Removes all content filters from the givenWebKitUserContentManager.- Since:
- 2.24
-
removeAllScripts
public void removeAllScripts()Removes all user scripts from the givenWebKitUserContentManagerSee also webkit_user_content_manager_remove_script().
- Since:
- 2.6
-
removeAllStyleSheets
public void removeAllStyleSheets()Removes all user style sheets from the givenWebKitUserContentManager.- Since:
- 2.6
-
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
WebKitUserContentManagergiven the identifier of aWebKitUserContentFilteras returned by webkit_user_content_filter_get_identifier().- Parameters:
filterId- Filter identifier- Since:
- 2.26
-
removeScript
Removes aWebKitUserScriptfrom the givenWebKitUserContentManager.See also webkit_user_content_manager_remove_all_scripts().
- Parameters:
script- AWebKitUserScript- Since:
- 2.32
-
removeStyleSheet
Removes aWebKitUserStyleSheetfrom the givenWebKitUserContentManager.See also webkit_user_content_manager_remove_all_style_sheets().
- Parameters:
stylesheet- AWebKitUserStyleSheet- Since:
- 2.32
-
unregisterScriptMessageHandler
Unregisters a previously registered message handler in script world with nameworldName.Ifnullis 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- Since:
- 2.40
-
onScriptMessageReceived
public SignalConnection<UserContentManager.ScriptMessageReceivedCallback> onScriptMessageReceived(@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
- Since:
- 2.8
- See Also:
-
emitScriptMessageReceived
Emits the "script-message-received" signal. SeeonScriptMessageReceived(java.lang.String, org.webkitgtk.UserContentManager.ScriptMessageReceivedCallback). -
onScriptMessageWithReplyReceived
public SignalConnection<UserContentManager.ScriptMessageWithReplyReceivedCallback> 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()The given
replycan 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
replyand returningtrue.- Parameters:
detail- the signal detailhandler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.40
- See Also:
-
emitScriptMessageWithReplyReceived
public boolean emitScriptMessageWithReplyReceived(@Nullable String detail, @Nullable Value value, @Nullable ScriptMessageReply reply) Emits the "script-message-with-reply-received" signal. SeeonScriptMessageWithReplyReceived(java.lang.String, org.webkitgtk.UserContentManager.ScriptMessageWithReplyReceivedCallback). -
builder
AUserContentManager.Builderobject constructs aUserContentManagerwith the specified properties. Use the variousset...()methods to set properties, and finish construction withUserContentManager.Builder.build().- Returns:
- the builder object
-