setting: always clear scripts previous to adding global ones
authorPatrick Steinhardt <ps@pks.im>
Sat, 20 May 2017 08:36:40 +0000 (10:36 +0200)
committerPatrick Steinhardt <ps@pks.im>
Sat, 20 May 2017 08:36:40 +0000 (10:36 +0200)
Previous to adding user scripts to the content manager, we should always
clear existing scripts. Otherwise, e.g. in the sequence

    :set user-scripts=off
    :set user-scripts=on

we'd end up with the same global scripts injected twice.

Fix the issue by unconditionally clearing all user scripts previous to
adding scripts.

src/setting.c

index de33832..ee7cb19 100644 (file)
@@ -607,6 +607,7 @@ static int user_scripts(Client *c, const char *name, DataType type, void *value,
     gboolean enabled = *(gboolean*)value;
 
     ucm = webkit_web_view_get_user_content_manager(c->webview);
+    webkit_user_content_manager_remove_all_scripts(ucm);
 
     if (enabled) {
         if (vb.files[FILES_SCRIPT]
@@ -621,8 +622,6 @@ static int user_scripts(Client *c, const char *name, DataType type, void *value,
             webkit_user_script_unref(script);
             g_free(source);
         }
-    } else {
-        webkit_user_content_manager_remove_all_scripts(ucm);
     }
 
     /* Inject the global scripts. */