Reordered startup sequence to be more friendly with embedders like the Tor Browser.
This commit is contained in:
parent
5bfba8a40f
commit
e8716657e4
|
@ -1,36 +1,38 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
ns.defaults = (async () => {
|
var Defaults = {
|
||||||
let defaults = {
|
async init() {
|
||||||
local: {
|
let defaults = {
|
||||||
debug: false,
|
local: {
|
||||||
showCtxMenuItem: true,
|
debug: false,
|
||||||
showCountBadge: true,
|
showCtxMenuItem: true,
|
||||||
showFullAddresses: false,
|
showCountBadge: true,
|
||||||
},
|
showFullAddresses: false,
|
||||||
sync: {
|
},
|
||||||
"global": false,
|
sync: {
|
||||||
"xss": true,
|
"global": false,
|
||||||
"clearclick": true
|
"xss": true,
|
||||||
|
"clearclick": true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let defaultsClone = JSON.parse(JSON.stringify(defaults));
|
||||||
|
|
||||||
|
for (let [k, v] of Object.entries(defaults)) {
|
||||||
|
let store = await Storage.get(k, k);
|
||||||
|
if (k in store) {
|
||||||
|
Object.assign(v, store[k]);
|
||||||
|
}
|
||||||
|
v.storage = k;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
let defaultsClone = JSON.parse(JSON.stringify(defaults));
|
|
||||||
|
|
||||||
for (let [k, v] of Object.entries(defaults)) {
|
Object.assign(ns, defaults);
|
||||||
let store = await Storage.get(k, k);
|
|
||||||
if (k in store) {
|
// dynamic settings
|
||||||
Object.assign(v, store[k]);
|
if (!ns.local.uuid) {
|
||||||
|
ns.local.uuid = uuid();
|
||||||
|
await ns.save(ns.local);
|
||||||
}
|
}
|
||||||
v.storage = k;
|
|
||||||
|
return ns.defaults = defaultsClone;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
Object.assign(ns, defaults);
|
|
||||||
|
|
||||||
// dynamic settings
|
|
||||||
if (!ns.local.uuid) {
|
|
||||||
ns.local.uuid = uuid();
|
|
||||||
await ns.save(ns.local);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ns.defaults = defaultsClone;
|
|
||||||
})();
|
|
||||||
|
|
|
@ -23,8 +23,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
await include("/bg/defaults.js");
|
await Defaults.init();
|
||||||
await ns.defaults;
|
|
||||||
|
|
||||||
let policyData = (await Storage.get("sync", "policy")).policy;
|
let policyData = (await Storage.get("sync", "policy")).policy;
|
||||||
if (policyData && policyData.DEFAULT) {
|
if (policyData && policyData.DEFAULT) {
|
||||||
|
@ -35,16 +34,22 @@
|
||||||
ns.policy = await Legacy.createOrMigratePolicy();
|
ns.policy = await Legacy.createOrMigratePolicy();
|
||||||
ns.savePolicy();
|
ns.savePolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
await include("/bg/RequestGuard.js");
|
|
||||||
await RequestGuard.start();
|
await RequestGuard.start();
|
||||||
await XSS.start(); // we must start it anyway to initialize sub-objects
|
await XSS.start(); // we must start it anyway to initialize sub-objects
|
||||||
if (!ns.sync.xss) {
|
if (!ns.sync.xss) {
|
||||||
XSS.stop();
|
XSS.stop();
|
||||||
}
|
}
|
||||||
Commands.install();
|
|
||||||
|
Messages.addHandler(messageHandler);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await Messages.send("started");
|
||||||
|
} catch (e) {
|
||||||
|
// no embedder to answer us
|
||||||
|
}
|
||||||
|
log("STARTED");
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let Commands = {
|
let Commands = {
|
||||||
|
@ -65,8 +70,6 @@
|
||||||
|
|
||||||
togglePermissions() {},
|
togglePermissions() {},
|
||||||
install() {
|
install() {
|
||||||
|
|
||||||
|
|
||||||
if ("command" in browser) {
|
if ("command" in browser) {
|
||||||
// keyboard shortcuts
|
// keyboard shortcuts
|
||||||
browser.commands.onCommand.addListener(cmd => {
|
browser.commands.onCommand.addListener(cmd => {
|
||||||
|
@ -182,13 +185,8 @@
|
||||||
|
|
||||||
deferWebTraffic(init(),
|
deferWebTraffic(init(),
|
||||||
async () => {
|
async () => {
|
||||||
|
Commands.install();
|
||||||
await include("/bg/Settings.js");
|
|
||||||
Messages.addHandler(messageHandler);
|
|
||||||
|
|
||||||
await Messages.send("started");
|
|
||||||
log("STARTED");
|
|
||||||
|
|
||||||
this.devMode = (await browser.management.getSelf()).installType === "development";
|
this.devMode = (await browser.management.getSelf()).installType === "development";
|
||||||
if (this.local.debug) {
|
if (this.local.debug) {
|
||||||
if (this.devMode) {
|
if (this.devMode) {
|
||||||
|
|
|
@ -1,17 +1,23 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
{
|
{
|
||||||
let handlers = new Set();
|
let handlers = new Set();
|
||||||
|
|
||||||
let forever = new Promise(resolve => {});
|
|
||||||
let dispatch = async (msg, sender) => {
|
let dispatch = async (msg, sender) => {
|
||||||
let {_messageName} = msg;
|
let {_messageName} = msg;
|
||||||
|
let answers = [];
|
||||||
for (let h of handlers) {
|
for (let h of handlers) {
|
||||||
let f = h[_messageName];
|
let f = h[_messageName];
|
||||||
if (typeof f === "function") {
|
if (typeof f === "function") {
|
||||||
return await f(msg, sender);
|
answers.push(f(msg, sender));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await forever;
|
if (answers.length) {
|
||||||
|
return await (
|
||||||
|
answers.length === 1 ? answers.pop(): Promise.all(answers)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
console.log("Answering %s", _messageName);
|
||||||
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
var Messages = {
|
var Messages = {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
"strict_min_version": "59.0"
|
"strict_min_version": "59.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "10.1.9rc1",
|
"version": "10.1.9rc3",
|
||||||
"description": "__MSG_Description__",
|
"description": "__MSG_Description__",
|
||||||
|
|
||||||
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'none'",
|
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'none'",
|
||||||
|
@ -54,6 +54,9 @@
|
||||||
"bg/ReportingCSP.js",
|
"bg/ReportingCSP.js",
|
||||||
"bg/deferWebTraffic.js",
|
"bg/deferWebTraffic.js",
|
||||||
"bg/ChildPolicies.js",
|
"bg/ChildPolicies.js",
|
||||||
|
"bg/Defaults.js",
|
||||||
|
"bg/RequestGuard.js",
|
||||||
|
"bg/Settings.js",
|
||||||
"bg/main.js"
|
"bg/main.js"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue