[nscl] Switch early content script configuration to use /nscl/service/DocStartInjection.js.
This commit is contained in:
parent
c293ebc250
commit
cc06e86a1d
|
@ -533,10 +533,12 @@ var RequestGuard = (() => {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error(e, "Error in onHeadersReceived", request);
|
error(e, "Error in onHeadersReceived", request);
|
||||||
}
|
}
|
||||||
|
|
||||||
promises = promises.filter(p => p instanceof Promise);
|
promises = promises.filter(p => p instanceof Promise);
|
||||||
if (promises.length > 0) {
|
if (promises.length > 0) {
|
||||||
return Promise.all(promises).then(() => result);
|
return Promise.all(promises).then(() => result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
onResponseStarted(request) {
|
onResponseStarted(request) {
|
||||||
|
@ -553,6 +555,7 @@ var RequestGuard = (() => {
|
||||||
TabStatus.record(request, "noscriptFrame", scriptBlocked);
|
TabStatus.record(request, "noscriptFrame", scriptBlocked);
|
||||||
let pending = pendingRequests.get(requestId);
|
let pending = pendingRequests.get(requestId);
|
||||||
if (pending) {
|
if (pending) {
|
||||||
|
|
||||||
pending.scriptBlocked = scriptBlocked;
|
pending.scriptBlocked = scriptBlocked;
|
||||||
if (!(pending.headersProcessed &&
|
if (!(pending.headersProcessed &&
|
||||||
(scriptBlocked || ns.requestCan(request, "script"))
|
(scriptBlocked || ns.requestCan(request, "script"))
|
||||||
|
@ -617,38 +620,28 @@ var RequestGuard = (() => {
|
||||||
return ABORT;
|
return ABORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onNavCommitted(details) {
|
function injectPolicyScript(details) {
|
||||||
debug("onNavCommitted", details);
|
|
||||||
let {url, tabId, frameId} = details;
|
let {url, tabId, frameId} = details;
|
||||||
try {
|
let policy = ns.computeChildPolicy({url}, {tab: {id: tabId}, frameId});
|
||||||
let policy = ns.computeChildPolicy({url}, {tab: {id: tabId}, frameId});
|
policy.navigationURL = url;
|
||||||
policy.navigationURL = url;
|
let debugStatement = ns.local.debug ? `console.debug("domPolicy", domPolicy, mark);` : '';
|
||||||
let debugStatement = ns.local.debug ? 'console.debug("domPolicy", domPolicy);' : '';
|
return `
|
||||||
let ret = await browser.tabs.executeScript(details.tabId, {
|
let mark = Date.now() + ":" + Math.random();
|
||||||
code:
|
console.log("domPolicy", document.readyState, mark);
|
||||||
`{
|
let domPolicy = ${JSON.stringify(policy)};
|
||||||
let domPolicy = ${JSON.stringify(policy)};
|
let {ns} = window;
|
||||||
if (this.ns) {
|
if (ns) {
|
||||||
ns.domPolicy = domPolicy;
|
ns.domPolicy = domPolicy;
|
||||||
if (ns.setup) {
|
if (ns.setup) {
|
||||||
if (ns.syncSetup) ns.syncSetup(domPolicy);
|
if (ns.syncSetup) ns.syncSetup(domPolicy);
|
||||||
else if (!ns.pendingSyncFetchPolicy) {
|
else if (!ns.pendingSyncFetchPolicy) {
|
||||||
ns.setup(domPolicy);
|
ns.setup(domPolicy);
|
||||||
}
|
|
||||||
} ;
|
|
||||||
} else {
|
|
||||||
ns = {domPolicy}
|
|
||||||
}
|
}
|
||||||
${debugStatement}
|
} ;
|
||||||
}
|
} else {
|
||||||
ns;`,
|
window.ns = {domPolicy}
|
||||||
runAt: "document_start",
|
}
|
||||||
frameId,
|
${debugStatement}`;
|
||||||
});
|
|
||||||
debug("onNavCommitted return: ", ret);
|
|
||||||
} catch(e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const RequestGuard = {
|
const RequestGuard = {
|
||||||
|
@ -702,11 +695,10 @@ var RequestGuard = (() => {
|
||||||
wr.onBeforeRequest.addListener(onViolationReport,
|
wr.onBeforeRequest.addListener(onViolationReport,
|
||||||
{urls: [csp.reportURI], types: ["csp_report"]}, ["blocking", "requestBody"]);
|
{urls: [csp.reportURI], types: ["csp_report"]}, ["blocking", "requestBody"]);
|
||||||
}
|
}
|
||||||
browser.webNavigation.onCommitted.addListener(onNavCommitted);
|
DocStartInjection.register(injectPolicyScript);
|
||||||
TabStatus.probe();
|
TabStatus.probe();
|
||||||
},
|
},
|
||||||
stop() {
|
stop() {
|
||||||
browser.webNavigation.onCommitted.removeListener(onNavCommitted);
|
|
||||||
let wr = browser.webRequest;
|
let wr = browser.webRequest;
|
||||||
for (let [name, listener] of Object.entries(listeners)) {
|
for (let [name, listener] of Object.entries(listeners)) {
|
||||||
if (typeof listener === "function") {
|
if (typeof listener === "function") {
|
||||||
|
@ -719,6 +711,7 @@ var RequestGuard = (() => {
|
||||||
if (listeners.onHeadersReceived.resetCSP) {
|
if (listeners.onHeadersReceived.resetCSP) {
|
||||||
wr.onHeadersReceived.removeListener(listeners.onHeadersReceived.resetCSP);
|
wr.onHeadersReceived.removeListener(listeners.onHeadersReceived.resetCSP);
|
||||||
}
|
}
|
||||||
|
DocStartInjection.unregister(injectPolicyScript);
|
||||||
Messages.removeHandler(messageHandler);
|
Messages.removeHandler(messageHandler);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,6 +42,15 @@
|
||||||
//, document.domain, document.baseURI, window.isSecureContext // DEV_ONLY
|
//, document.domain, document.baseURI, window.isSecureContext // DEV_ONLY
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.domPolicy) {
|
||||||
|
debug("Injected policy found!");
|
||||||
|
try {
|
||||||
|
this.setup(this.domPolicy);
|
||||||
|
return;
|
||||||
|
} catch(e) {
|
||||||
|
error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (/^(ftp|file):/.test(url)) { // ftp: or file: - no CSP headers yet
|
if (/^(ftp|file):/.test(url)) { // ftp: or file: - no CSP headers yet
|
||||||
if (this.syncFetchPolicy) {
|
if (this.syncFetchPolicy) {
|
||||||
|
@ -52,15 +61,6 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.domPolicy) {
|
|
||||||
debug("File policy set in webNavigation found!");
|
|
||||||
try {
|
|
||||||
this.setup(this.domPolicy);
|
|
||||||
return;
|
|
||||||
} catch(e) {
|
|
||||||
error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// CSP headers have been already provided by webRequest, we are not in a hurry...
|
// CSP headers have been already provided by webRequest, we are not in a hurry...
|
||||||
if (/^(javascript|about):/.test(url)) {
|
if (/^(javascript|about):/.test(url)) {
|
||||||
url = document.readyState === "loading"
|
url = document.readyState === "loading"
|
||||||
|
@ -118,6 +118,6 @@
|
||||||
return this.capabilities && this.capabilities.has(cap);
|
return this.capabilities && this.capabilities.has(cap);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
this.ns = this.ns ? Object.assign(ns, this.ns) : ns;
|
window.ns = window.ns ? Object.assign(ns, window.ns) : ns;
|
||||||
debug("StaticNS", JSON.stringify(this.ns)); // DEV_ONLY
|
debug("StaticNS", window.domPolicy, Date.now(), JSON.stringify(window.ns)); // DEV_ONLY
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(this.ns || (this.ns = {})).syncFetchPolicy = function() {
|
(window.ns || (window.ns = {})).syncFetchPolicy = function() {
|
||||||
|
|
||||||
let url = document.URL;
|
let url = document.URL;
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.ns.pendingSyncFetchPolicy) {
|
if (ns.pendingSyncFetchPolicy) {
|
||||||
this.ns.pendingSyncFetchPolicy = false;
|
ns.pendingSyncFetchPolicy = false;
|
||||||
this.ns.syncFetchPolicy();
|
ns.syncFetchPolicy();
|
||||||
}
|
}
|
|
@ -36,6 +36,7 @@
|
||||||
"scripts": [
|
"scripts": [
|
||||||
"/nscl/lib/browser-polyfill.js",
|
"/nscl/lib/browser-polyfill.js",
|
||||||
"/nscl/lib/punycode.js",
|
"/nscl/lib/punycode.js",
|
||||||
|
"/nscl/lib/sha256.js",
|
||||||
"/nscl/common/UA.js",
|
"/nscl/common/UA.js",
|
||||||
"/nscl/common/uuid.js",
|
"/nscl/common/uuid.js",
|
||||||
"/nscl/common/SyncMessage.js",
|
"/nscl/common/SyncMessage.js",
|
||||||
|
@ -53,6 +54,7 @@
|
||||||
"/nscl/common/SyntaxChecker.js",
|
"/nscl/common/SyntaxChecker.js",
|
||||||
"/nscl/common/Storage.js",
|
"/nscl/common/Storage.js",
|
||||||
"/nscl/common/include.js",
|
"/nscl/common/include.js",
|
||||||
|
"/nscl/service/DocStartInjection.js",
|
||||||
"/nscl/service/LastListener.js",
|
"/nscl/service/LastListener.js",
|
||||||
"/nscl/service/TabCache.js",
|
"/nscl/service/TabCache.js",
|
||||||
"ui/Prompts.js",
|
"ui/Prompts.js",
|
||||||
|
@ -75,15 +77,6 @@
|
||||||
"/content/content.css"
|
"/content/content.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"run_at": "document_start",
|
|
||||||
"matches": ["file://*/*", "ftp://*/*"],
|
|
||||||
"all_frames": true,
|
|
||||||
"js": [
|
|
||||||
"lib/DocumentFreezer.js",
|
|
||||||
"content/syncFetchPolicy.js"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"run_at": "document_start",
|
"run_at": "document_start",
|
||||||
"matches": ["<all_urls>"],
|
"matches": ["<all_urls>"],
|
||||||
|
@ -114,13 +107,21 @@
|
||||||
"content/content.js"
|
"content/content.js"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"run_at": "document_start",
|
"run_at": "document_start",
|
||||||
"matches": ["ftp://*/*"],
|
"matches": ["ftp://*/*"],
|
||||||
"js": [
|
"js": [
|
||||||
"content/ftp.js"
|
"content/ftp.js"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"run_at": "document_start",
|
||||||
|
"matches": ["file://*/*", "ftp://*/*"],
|
||||||
|
"all_frames": true,
|
||||||
|
"js": [
|
||||||
|
"lib/DocumentFreezer.js",
|
||||||
|
"content/syncFetchPolicy.js"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
2
src/nscl
2
src/nscl
|
@ -1 +1 @@
|
||||||
Subproject commit b6506b0275720233a500fbdb1cdb6548815405eb
|
Subproject commit c89b6b972aafbdb6bb1e520d7ecb4eea67d727d1
|
Loading…
Reference in New Issue