summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhackademix2018-09-09 18:59:52 +0200
committerhackademix2018-09-09 18:59:52 +0200
commit305c6779a71d61be9dc7b7eb79fa2c5fab410a9e (patch)
treed3e4c3398859ffd0679c6eecbdd5d07322662041 /src
parent193e706a997ec91e75b5eff664c0d3766ba5d469 (diff)
downloadnoscript-305c6779a71d61be9dc7b7eb79fa2c5fab410a9e.tar.gz
noscript-305c6779a71d61be9dc7b7eb79fa2c5fab410a9e.tar.xz
noscript-305c6779a71d61be9dc7b7eb79fa2c5fab410a9e.zip
Fix for various content script timing related issues.
Diffstat (limited to 'src')
-rw-r--r--src/bg/ChildPolicies.js35
-rw-r--r--src/bg/main.js2
-rw-r--r--src/content/content.js3
-rw-r--r--src/content/dynamicNS.js4
4 files changed, 15 insertions, 29 deletions
diff --git a/src/bg/ChildPolicies.js b/src/bg/ChildPolicies.js
index d822f61..ec08623 100644
--- a/src/bg/ChildPolicies.js
+++ b/src/bg/ChildPolicies.js
@@ -6,18 +6,12 @@
let Scripts = {
references: new Set(),
opts: {
- js: [{}],
+ js: [{file: "/content/dynamicNS.js"}, {}],
allFrames: true,
matchAboutBlank: true,
runAt: "document_start"
},
async init() {
- let opts = Object.assign({}, this.opts);
- opts.js = [{file: "/content/dynamicNS.js"}];
- opts.matches = allUrls;
- delete opts.excludedMatches;
- this._stubScript = await browser.contentScripts.register(opts);
-
this.init = this.forget;
},
forget() {
@@ -38,7 +32,7 @@
if (!matches.length) return;
try {
let opts = Object.assign({}, this.opts);
- opts.js[0].code = this.trace(code);
+ opts.js[1].code = this.trace(code);
opts.matches = matches;
if (excludeMatches && excludeMatches.length) {
opts.excludeMatches = excludeMatches;
@@ -49,14 +43,11 @@
}
},
- buildPerms(perms, finalizeSetup = false) {
+ buildPerms(perms) {
if (typeof perms !== "string") {
perms = JSON.stringify(perms);
}
- return finalizeSetup
- ? `ns.setup(${perms}, ${marker});`
- : `ns.config.CURRENT = ${perms};`
- ;
+ return `ns.setup(${perms}, ${marker});`
}
};
@@ -169,10 +160,15 @@
}
// register new content scripts
+ let registering = [];
+ let allMatching = [];
for (let [perms, keys] of [...permsMap]) {
- await Scripts.register(Scripts.buildPerms(perms), siteKeys2MatchPatterns(keys), excludeMap.get(perms));
+ let match = siteKeys2MatchPatterns(keys);
+ allMatching.push(...match);
+ registering.push(Scripts.register(Scripts.buildPerms(perms), match, excludeMap.get(perms)));
}
- await Scripts.register(Scripts.buildPerms(serialized.DEFAULT, true), allUrls);
+ registering.push(Scripts.register(Scripts.buildPerms(serialized.DEFAULT), allUrls, allMatching));
+ await Promise.all(registering);
if (tracing) {
debug("All the child policies registered in %sms", Date.now() - t0);
}
@@ -186,14 +182,5 @@
};
},
- async updateFrame(tabId, frameId, perms, defaultPreset) {
- let code = Scripts.buildPerms(perms) + Scripts.buildPerms(defaultPreset, true);
- await browser.tabs.executeScript(tabId, {
- code,
- frameId,
- matchAboutBlank: true,
- runAt: "document_start"
- });
- }
};
}
diff --git a/src/bg/main.js b/src/bg/main.js
index 376a981..e9a4055 100644
--- a/src/bg/main.js
+++ b/src/bg/main.js
@@ -32,7 +32,7 @@
} else {
await include("/legacy/Legacy.js");
ns.policy = await Legacy.createOrMigratePolicy();
- ns.savePolicy();
+ await ns.savePolicy();
}
await RequestGuard.start();
diff --git a/src/content/content.js b/src/content/content.js
index c501282..b185f4f 100644
--- a/src/content/content.js
+++ b/src/content/content.js
@@ -54,8 +54,7 @@ var notifyPage = async () => {
debug(`No answer to fetchChildPolicy message. This should not be happening.`);
return;
}
- ns.config.CURRENT = childPolicy.CURRENT;
- ns.setup(childPolicy.DEFAULT, childPolicy.MARKER);
+ ns.setup(childPolicy.CURRENT, childPolicy.MARKER);
return;
}
diff --git a/src/content/dynamicNS.js b/src/content/dynamicNS.js
index cdd7a0e..f865e8b 100644
--- a/src/content/dynamicNS.js
+++ b/src/content/dynamicNS.js
@@ -7,8 +7,8 @@ if (!this.ns) {
let deferredSetup = null;
let nsStub = this.ns = {
config: {},
- setup(DEFAULT, MARKER) {
- deferredSetup = [DEFAULT, MARKER];
+ setup(CURRENT, MARKER) {
+ deferredSetup = [CURRENT, MARKER];
},
merge: ns => {
ns.config = Object.assign(ns.config, nsStub.config);