[epiphany/pgriffis/web-extension/thread-safety] WebExtensions: Fix webkit_user_script_new_for_world() called from thread




commit 9c579ea649def698194c7feb7fbed5ba5b6b28b7
Author: Patrick Griffis <pgriffis igalia com>
Date:   Tue Jun 14 12:23:27 2022 -0500

    WebExtensions: Fix webkit_user_script_new_for_world() called from thread
    
    We now lazily call it when its needed on the main thread.
    
    Fixes #1808

 src/webextension/ephy-web-extension.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/src/webextension/ephy-web-extension.c b/src/webextension/ephy-web-extension.c
index 1af140789..3365cd99b 100644
--- a/src/webextension/ephy-web-extension.c
+++ b/src/webextension/ephy-web-extension.c
@@ -505,9 +505,6 @@ web_extension_add_content_script (JsonArray *array,
   }
   g_ptr_array_add (content_script->js, NULL);
 
-  /* Create user scripts so that we can unload them if necessary */
-  web_extension_content_script_build (self, content_script);
-
   self->content_scripts = g_list_append (self->content_scripts, content_script);
 }
 
@@ -1134,6 +1131,14 @@ ephy_web_extension_get_content_script_js (EphyWebExtension *self,
                                           gpointer          content_script)
 {
   WebExtensionContentScript *script = content_script;
+
+  if (script->js && script->js->len && !script->user_scripts) {
+    /* Create user scripts so that we can unload them if necessary.
+     * They are lazily created here to ensure they happen on the main-thread
+     * since parsing happens on a thread. */
+    web_extension_content_script_build (self, script);
+  }
+
   return script->user_scripts;
 }
 


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