diff options
author | Patrick Griffis <pgriffis@igalia.com> | 2022-06-14 12:23:27 -0500 |
---|---|---|
committer | Patrick Griffis <pgriffis@igalia.com> | 2022-06-14 12:23:27 -0500 |
commit | 9c579ea649def698194c7feb7fbed5ba5b6b28b7 (patch) | |
tree | 81ef2f7189112d8b1447da869e665e1321fddb70 | |
parent | befeaa7092aed00cbae66f50121b68208cf9cc59 (diff) | |
download | epiphany-pgriffis/web-extension/thread-safety.tar.gz |
WebExtensions: Fix webkit_user_script_new_for_world() called from threadpgriffis/web-extension/thread-safety
We now lazily call it when its needed on the main thread.
Fixes #1808
-rw-r--r-- | src/webextension/ephy-web-extension.c | 11 |
1 files 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; } |