[epiphany/pgriffis/web-extension-fixes-2: 14/16] WebExtensions: Implement file argument of tabs.executeScript




commit 78eb131fcb44eefdd5dde4d73214fd475bfce867
Author: Patrick Griffis <pgriffis igalia com>
Date:   Thu May 19 15:47:57 2022 -0500

     WebExtensions: Implement file argument of tabs.executeScript

 src/webextension/api/tabs.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/src/webextension/api/tabs.c b/src/webextension/api/tabs.c
index ca156d137..88e4fe945 100644
--- a/src/webextension/api/tabs.c
+++ b/src/webextension/api/tabs.c
@@ -151,23 +151,36 @@ tabs_handler_execute_script (EphyWebExtension *self,
                              JSCValue         *args)
 {
   g_autoptr (JSCValue) code_value = NULL;
+  g_autoptr (JSCValue) file_value = NULL;
   g_autoptr (JSCValue) obj = NULL;
+  g_autofree char *code = NULL;
   EphyShell *shell = ephy_shell_get_default ();
 
+  g_message ("tabs_handler_execute_script");
+
   if (jsc_value_is_array (args)) {
     obj = jsc_value_object_get_property_at_index (args, 1);
   } else {
     obj = args;
   }
 
+  file_value = jsc_value_object_get_property (obj, "file");
   code_value = jsc_value_object_get_property (obj, "code");
-  if (code_value) {
-    g_autofree char *code = jsc_value_to_string (code_value);
-    webkit_web_view_run_javascript (WEBKIT_WEB_VIEW (ephy_shell_get_active_web_view (shell)),
-                                    code,
-                                    NULL,
-                                    NULL,
-                                    NULL);
+
+  if (code_value)
+    code = jsc_value_to_string (code_value);
+  else if (file_value) {
+    g_autofree char *resource_path = jsc_value_to_string (code_value);
+    code = g_strdup (ephy_web_extension_get_resource_as_string (self, resource_path));
+  }
+
+  if (code) {
+    webkit_web_view_run_javascript_in_world (WEBKIT_WEB_VIEW (ephy_shell_get_active_web_view (shell)),
+                                             code,
+                                             ephy_web_extension_get_guid (self),
+                                             NULL,
+                                             NULL,
+                                             NULL);
   }
 
   return NULL;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]