summaryrefslogtreecommitdiff
path: root/src/bg
diff options
context:
space:
mode:
Diffstat (limited to 'src/bg')
-rw-r--r--src/bg/ChildPolicies.js30
-rw-r--r--src/bg/Settings.js3
-rw-r--r--src/bg/defaults.js1
3 files changed, 26 insertions, 8 deletions
diff --git a/src/bg/ChildPolicies.js b/src/bg/ChildPolicies.js
index fd790c9..0a77b8b 100644
--- a/src/bg/ChildPolicies.js
+++ b/src/bg/ChildPolicies.js
@@ -1,5 +1,7 @@
-"use script";
+"use strict";
{
+ let marker = JSON.stringify(uuid());
+
let Scripts = {
references: new Set(),
opts: {
@@ -54,7 +56,27 @@
let siteKeys2MatchPatterns = keys => keys && flatten(keys.map(siteKey2MatchPattern)).filter(p => !!p) || [];
var ChildPolicies = {
+ async storeTabInfo(tabId, info) {
+ try {
+ await browser.tabs.executeScript(tabId, {
+ code: `window.name = ${marker} + ${JSON.stringify(JSON.stringify([info]))} + ${marker} + "," + window.name;`,
+ allFrames: false,
+ matchAboutBlank: true,
+ runAt: "document_start",
+ });
+ } catch (e) {
+ error(e);
+ }
+ },
async update(policy) {
+ Scripts.forget();
+
+ if (!policy.enforced) {
+ await Scripts.register(`ns.setup(null, ${marker});`,
+ ["<all_urls>"]);
+ return;
+ }
+
let serialized = policy.dry ? policy.dry(true) : policy;
let permsMap = new Map();
let trusted = JSON.stringify(serialized.TRUSTED);
@@ -96,15 +118,11 @@
));
}
- Scripts.forget();
// register new content scripts
for (let [perms, keys] of [...permsMap]) {
await Scripts.register(`ns.perms.CURRENT = ${perms};`, siteKeys2MatchPatterns(keys), excludeMap.get(perms));
}
- await Scripts.register(
- `ns.perms.DEFAULT = ${JSON.stringify(serialized.DEFAULT)};
- if(!ns.perms.CURRENT) ns.perms.CURRENT = ns.perms.DEFAULT;
- ns.fire("perms");`,
+ await Scripts.register(`ns.setup(${JSON.stringify(serialized.DEFAULT)}, ${marker});`,
["<all_urls>"]);
}
}
diff --git a/src/bg/Settings.js b/src/bg/Settings.js
index 4fb656f..09f0edd 100644
--- a/src/bg/Settings.js
+++ b/src/bg/Settings.js
@@ -89,7 +89,8 @@ var Settings = {
}
if (typeof unrestrictedTab === "boolean") {
- ns.unrestrictedTabs[settings.unrestrictedTab ? "add" : "delete"](tabId);
+ ns.unrestrictedTabs[unrestrictedTab ? "add" : "delete"](tabId);
+ ChildPolicies.storeTabInfo(tabId, {unrestricted: unrestrictedTab});
}
if (reloadAffected) {
browser.tabs.reload(tabId);
diff --git a/src/bg/defaults.js b/src/bg/defaults.js
index 220bd23..4d071b4 100644
--- a/src/bg/defaults.js
+++ b/src/bg/defaults.js
@@ -28,7 +28,6 @@ ns.defaults = (async () => {
// dynamic settings
if (!ns.local.uuid) {
- await include("/lib/uuid.js");
ns.local.uuid = uuid();
await ns.save(ns.local);
}