[epiphany/pgriffis/web-extension/unify-web-process-extensions: 2/2] WebExtensions: Implement runtime.getManifest()
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/pgriffis/web-extension/unify-web-process-extensions: 2/2] WebExtensions: Implement runtime.getManifest()
- Date: Sun, 17 Jul 2022 23:15:39 +0000 (UTC)
commit d6ca021c5f90b5a9274988b4e180837d15c5524c
Author: Patrick Griffis <pgriffis igalia com>
Date: Sun Jul 17 18:12:46 2022 -0500
WebExtensions: Implement runtime.getManifest()
Closes #1822
.../ephy-web-process-extension.c | 6 ++++--
.../web-process-extension/ephy-webextension-common.c | 20 +++++++++++++++++++-
.../web-process-extension/ephy-webextension-common.h | 3 ++-
.../resources/js/webextensions-common.js | 2 +-
src/webextension/ephy-web-extension-manager.c | 1 +
5 files changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/embed/web-process-extension/ephy-web-process-extension.c
b/embed/web-process-extension/ephy-web-process-extension.c
index 9fbfa01db..46c5ebc1b 100644
--- a/embed/web-process-extension/ephy-web-process-extension.c
+++ b/embed/web-process-extension/ephy-web-process-extension.c
@@ -389,7 +389,8 @@ content_script_window_object_cleared_cb (WebKitScriptWorld *world,
frame,
js_context,
guid,
- extension_data->translations);
+ extension_data->translations,
+ extension_data->manifest);
}
static void
@@ -904,7 +905,8 @@ default_window_object_cleared_cb (WebKitScriptWorld *world,
frame,
js_context,
guid,
- extension_data->translations);
+ extension_data->translations,
+ extension_data->manifest);
js_browser = jsc_context_get_value (js_context, "browser");
js_extension = jsc_value_object_get_property (js_browser, "extension");
diff --git a/embed/web-process-extension/ephy-webextension-common.c
b/embed/web-process-extension/ephy-webextension-common.c
index 41d36df39..f0f211073 100644
--- a/embed/web-process-extension/ephy-webextension-common.c
+++ b/embed/web-process-extension/ephy-webextension-common.c
@@ -156,6 +156,13 @@ js_geturl (const char *path,
return g_strdup_printf ("ephy-webextension://%s/%s", guid, path[0] == '/' ? path + 1 : path);
}
+static JSCValue *
+js_getmanifest (gpointer user_data)
+{
+ JSCValue *manifest_object = user_data;
+ return g_object_ref (manifest_object);
+}
+
static void
js_exception_handler (JSCContext *context,
JSCException *exception)
@@ -178,7 +185,8 @@ ephy_webextension_install_common_apis (WebKitWebPage *page,
WebKitFrame *frame,
JSCContext *js_context,
const char *guid,
- JsonObject *translations)
+ JsonObject *translations,
+ const char *manifest)
{
g_autoptr (JSCValue) result = NULL;
g_autoptr (JSCValue) js_browser = NULL;
@@ -186,6 +194,7 @@ ephy_webextension_install_common_apis (WebKitWebPage *page,
g_autoptr (JSCValue) js_extension = NULL;
g_autoptr (JSCValue) js_function = NULL;
g_autoptr (JSCValue) js_object = NULL;
+ g_autoptr (JSCValue) manifest_object = NULL;
EphySendMessageData *send_message_data;
jsc_context_push_exception_handler (js_context, (JSCExceptionHandler)js_exception_handler, NULL, NULL);
@@ -230,6 +239,15 @@ ephy_webextension_install_common_apis (WebKitWebPage *page,
jsc_value_object_set_property (js_extension, "getURL", js_function);
g_clear_object (&js_function);
+ manifest_object = jsc_value_new_from_json (js_context, manifest);
+ js_function = jsc_value_new_function (js_context,
+ NULL,
+ G_CALLBACK (js_getmanifest), g_object_ref (manifest_object),
g_object_unref,
+ JSC_TYPE_VALUE,
+ 0);
+ jsc_value_object_set_property (js_extension, "getManifest", js_function);
+ g_clear_object (&js_function);
+
/* global functions */
send_message_data = g_new (EphySendMessageData, 1);
send_message_data->page = page;
diff --git a/embed/web-process-extension/ephy-webextension-common.h
b/embed/web-process-extension/ephy-webextension-common.h
index cda5e308e..77e6aa1ec 100644
--- a/embed/web-process-extension/ephy-webextension-common.h
+++ b/embed/web-process-extension/ephy-webextension-common.h
@@ -31,6 +31,7 @@ void ephy_webextension_install_common_apis (WebKitWebPage *page,
WebKitFrame *frame,
JSCContext *js_context,
const char *guid,
- JsonObject *translations);
+ JsonObject *translations,
+ const char *manifest);
G_END_DECLS
diff --git a/embed/web-process-extension/resources/js/webextensions-common.js
b/embed/web-process-extension/resources/js/webextensions-common.js
index 86c8d8460..965873d58 100644
--- a/embed/web-process-extension/resources/js/webextensions-common.js
+++ b/embed/web-process-extension/resources/js/webextensions-common.js
@@ -84,7 +84,7 @@ const ephy_message = function (fn, args) {
window.browser.runtime = {
getURL: function (args) { return window.browser.extension.getURL(args); },
- getManifest: function () { return {}; },
+ getManifest: function () { return window.browser.extension.getManifest(); },
onMessage: new EphyEventListener (),
onConnect: new EphyEventListener (),
sendMessage: function (...args) {
diff --git a/src/webextension/ephy-web-extension-manager.c b/src/webextension/ephy-web-extension-manager.c
index d70020590..1be70e505 100644
--- a/src/webextension/ephy-web-extension-manager.c
+++ b/src/webextension/ephy-web-extension-manager.c
@@ -115,6 +115,7 @@ create_extension_data_variant (EphyWebExtension *extension)
g_auto (GVariantDict) dict = G_VARIANT_DICT_INIT (NULL);
g_autofree char *translations = get_translation_contents (extension);
+ /* FIXME: The manifest is not localized. */
g_variant_dict_insert (&dict, "manifest", "s", ephy_web_extension_get_manifest (extension));
g_variant_dict_insert (&dict, "translations", "s", translations);
g_variant_dict_insert (&dict, "has-background-page", "b", ephy_web_extension_has_background_web_view
(extension));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]