2021-04-20 00:46:46 +00:00
|
|
|
/* Copyright (C) <2021> Thibault Saunier <tsaunier@igalia.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstwpeextension.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gmodule.h>
|
|
|
|
#include <gio/gunixfdlist.h>
|
|
|
|
#include <wpe/webkit-web-extension.h>
|
|
|
|
|
2022-12-22 10:17:42 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (wpe_extension_debug);
|
|
|
|
#define GST_CAT_DEFAULT wpe_extension_debug
|
|
|
|
|
2021-04-20 00:46:46 +00:00
|
|
|
G_MODULE_EXPORT void webkit_web_extension_initialize (WebKitWebExtension *
|
|
|
|
extension);
|
|
|
|
|
|
|
|
static WebKitWebExtension *global_extension = NULL;
|
|
|
|
|
2023-01-22 18:23:18 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-04-20 00:46:46 +00:00
|
|
|
void
|
|
|
|
webkit_web_extension_initialize (WebKitWebExtension * extension)
|
|
|
|
{
|
|
|
|
g_return_if_fail (!global_extension);
|
|
|
|
|
|
|
|
gst_init (NULL, NULL);
|
|
|
|
|
2022-12-22 10:17:42 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (wpe_extension_debug, "wpewebextension", 0,
|
|
|
|
"GstWPE WebExtension");
|
|
|
|
|
2021-04-20 00:46:46 +00:00
|
|
|
/* Register our own audio sink to */
|
|
|
|
gst_element_register (NULL, "gstwpeaudiosink", GST_RANK_PRIMARY + 500,
|
|
|
|
gst_wpe_audio_sink_get_type ());
|
2021-05-02 01:48:23 +00:00
|
|
|
gst_object_unref (g_object_new (gst_wpe_bus_msg_forwarder_get_type (), NULL));
|
2021-04-20 00:46:46 +00:00
|
|
|
|
|
|
|
global_extension = extension;
|
2022-12-22 10:17:42 +00:00
|
|
|
GST_INFO ("Setting as global extension.");
|
2023-01-22 18:23:18 +00:00
|
|
|
|
|
|
|
g_signal_connect (global_extension, "page-created",
|
|
|
|
G_CALLBACK (web_page_created_callback), NULL);
|
2021-04-20 00:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_wpe_extension_send_message (WebKitUserMessage * msg,
|
|
|
|
GCancellable * cancellable, GAsyncReadyCallback cb, gpointer udata)
|
|
|
|
{
|
|
|
|
webkit_web_extension_send_message_to_context (global_extension, msg,
|
|
|
|
cancellable, cb, udata);
|
|
|
|
}
|