wpe: Post console messages as element messages

Fixes #1731

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3769>
This commit is contained in:
Jonas Danielsson 2023-01-22 19:23:18 +01:00 committed by GStreamer Marge Bot
parent 236465e5d4
commit e8060c40f5
2 changed files with 32 additions and 1 deletions

View file

@ -326,6 +326,14 @@ webkit_extension_msg_received (WebKitWebContext *context,
webkit_extension_gerror_msg_received (src, params);
} else if (!g_strcmp0(name, "gstwpe.bus_message")) {
webkit_extension_bus_message_received (src, params);
} else if (!g_strcmp0(name, "gstwpe.console_message")) {
const gchar *message = g_variant_get_string (g_variant_get_child_value (params, 0), NULL);
GstStructure *structure = gst_structure_new ("wpe-console-message",
"message", G_TYPE_STRING, message,
NULL);
gst_element_post_message(GST_ELEMENT(src), gst_message_new_custom(GST_MESSAGE_ELEMENT,
GST_OBJECT(src), structure));
} else {
res = FALSE;
g_error("Unknown event: %s", name);
@ -348,7 +356,7 @@ WPEView* WPEContextThread::createWPEView(GstWpeVideoSrc* src, GstGLContext* cont
WPEView* view = nullptr;
dispatch([&]() mutable {
if (!glib.web_context) {
auto *manager = webkit_website_data_manager_new_ephemeral();
auto *manager = webkit_website_data_manager_new(NULL);
glib.web_context =
webkit_web_context_new_with_website_data_manager(manager);
g_object_unref(manager);

View file

@ -38,6 +38,26 @@ G_MODULE_EXPORT void webkit_web_extension_initialize (WebKitWebExtension *
static WebKitWebExtension *global_extension = NULL;
static void
console_message_cb (WebKitWebPage * page,
WebKitConsoleMessage * console_message, gpointer data)
{
char *message = g_strdup (webkit_console_message_get_text (console_message));
gst_wpe_extension_send_message (webkit_user_message_new
("gstwpe.console_message", g_variant_new ("(s)", message)), NULL, NULL,
NULL);
g_free (message);
}
static void
web_page_created_callback (WebKitWebExtension * extension,
WebKitWebPage * web_page, gpointer data)
{
g_signal_connect (web_page, "console-message-sent",
G_CALLBACK (console_message_cb), NULL);
}
void
webkit_web_extension_initialize (WebKitWebExtension * extension)
{
@ -55,6 +75,9 @@ webkit_web_extension_initialize (WebKitWebExtension * extension)
global_extension = extension;
GST_INFO ("Setting as global extension.");
g_signal_connect (global_extension, "page-created",
G_CALLBACK (web_page_created_callback), NULL);
}
void