[epiphany/pgriffis/web-extension/runtime-send-message: 7/15] WebExtensions: Load background page as URI instead of data
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/pgriffis/web-extension/runtime-send-message: 7/15] WebExtensions: Load background page as URI instead of data
- Date: Thu, 2 Jun 2022 20:32:48 +0000 (UTC)
commit 6d47e8997fa16052b5f054b1738610bc1e95d0d0
Author: Patrick Griffis <pgriffis igalia com>
Date: Tue May 31 15:38:53 2022 -0500
WebExtensions: Load background page as URI instead of data
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1122>
src/webextension/ephy-web-extension-manager.c | 51 ++++++++++++++-------------
1 file changed, 26 insertions(+), 25 deletions(-)
---
diff --git a/src/webextension/ephy-web-extension-manager.c b/src/webextension/ephy-web-extension-manager.c
index f9e2bd5f1..563b645bb 100644
--- a/src/webextension/ephy-web-extension-manager.c
+++ b/src/webextension/ephy-web-extension-manager.c
@@ -1025,8 +1025,9 @@ run_background_script (EphyWebExtensionManager *self,
{
WebKitUserContentManager *ucm;
GtkWidget *background;
- g_autofree char *base_uri = NULL;
+ GPtrArray *scripts;
const char *page;
+ g_autofree char *base_uri = NULL;
if (!ephy_web_extension_has_background_web_view (web_extension) ||
ephy_web_extension_manager_get_background_web_view (self, web_extension))
return;
@@ -1037,38 +1038,38 @@ run_background_script (EphyWebExtensionManager *self,
background = create_web_extensions_webview (web_extension);
ephy_web_extension_manager_set_background_web_view (self, web_extension, WEBKIT_WEB_VIEW (background));
- base_uri = create_base_uri_for_resource_path (web_extension, page);
-
if (page) {
- g_autofree char *data = ephy_web_extension_get_resource_as_string (web_extension, page);
- if (data)
- webkit_web_view_load_html (WEBKIT_WEB_VIEW (background), (char *)data, base_uri);
- } else {
- GPtrArray *scripts = ephy_web_extension_background_web_view_get_scripts (web_extension);
+ g_autofree char *page_uri = g_strdup_printf ("ephy-webextension://%s/%s", ephy_web_extension_get_guid
(web_extension), page);
+ webkit_web_view_load_uri (WEBKIT_WEB_VIEW (background), page_uri);
+ return;
+ }
- ucm = webkit_web_view_get_user_content_manager (WEBKIT_WEB_VIEW (background));
+ scripts = ephy_web_extension_background_web_view_get_scripts (web_extension);
+ base_uri = create_base_uri_for_resource_path (web_extension, page);
- for (unsigned int i = 0; i < scripts->len; i++) {
- const char *script_file = g_ptr_array_index (scripts, i);
- g_autofree char *data = NULL;
- WebKitUserScript *user_script;
+ ucm = webkit_web_view_get_user_content_manager (WEBKIT_WEB_VIEW (background));
- if (!script_file)
- continue;
+ for (unsigned int i = 0; i < scripts->len; i++) {
+ const char *script_file = g_ptr_array_index (scripts, i);
+ g_autofree char *data = NULL;
+ WebKitUserScript *user_script;
+
+ if (!script_file)
+ continue;
- data = ephy_web_extension_get_resource_as_string (web_extension, script_file);
- if (data) {
- user_script = webkit_user_script_new (data,
- WEBKIT_USER_CONTENT_INJECT_TOP_FRAME,
- WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END,
- NULL,
- NULL);
+ data = ephy_web_extension_get_resource_as_string (web_extension, script_file);
+ if (data) {
+ user_script = webkit_user_script_new (data,
+ WEBKIT_USER_CONTENT_INJECT_TOP_FRAME,
+ WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END,
+ NULL,
+ NULL);
- webkit_user_content_manager_add_script (ucm, user_script);
- }
+ webkit_user_content_manager_add_script (ucm, user_script);
}
- webkit_web_view_load_html (WEBKIT_WEB_VIEW (background), "<body></body>", base_uri);
}
+
+ webkit_web_view_load_html (WEBKIT_WEB_VIEW (background), "<body></body>", base_uri);
}
static GPtrArray *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]