[webkit-gtk] Webkit2 signals/callbacks

Michael Catanzaro mcatanzaro at igalia.com
Tue Feb 12 08:43:39 PST 2019


On Tue, Feb 12, 2019 at 1:35 AM, Daniel Berek <berekdaniel at gmail.com> 
wrote:
> Thanks it really works. But I still have to figure out how to pass 
> data to my core class through webview widget -> gtk:window -> 
> gui thread -> core app. A simple function call freezes the gui, so 
> some kind of in-build signal handling is needed. (in the other 
> direction I have already managed by glib:dispatcher). Any idea how to 
> bring out the script messages? Thanks

Did you try using 
webkit_user_content_manager_register_script_message_handler() to 
register a message handler? Then your JS content can use 
window.webkit.messageHandlers.<foobar>.postMessage([value]) to send 
messages to the UI process, and you receive them by connecting to the 
script-message-received::foobar signal. That's what Adrian was trying 
to suggest.

Regarding thread safety, there is none: the entire WebKit API must only 
be used from the GUI thread (whatever thread is running 
gtk_application_run() or gtk_main(), recommended but not required to be 
your main thread). If you need to perform blocking operations on a 
secondary thread, you can run code back on the GUI thread using e.g. 
g_main_context_invoke() or g_idle_add().

GObject signals are not threadsafe. Only connect to them from the GUI 
thread.

Michael



More information about the webkit-gtk mailing list