Skip to content
Permalink
Browse files

Removed all references to RequestUtil.js and dependancies.

  • Loading branch information...
hackademix committed Aug 18, 2018
1 parent e959acc commit 2f9c5299afe0d612deff7f89c948bb44332f2abf
@@ -58,8 +58,9 @@
var ChildPolicies = {
async storeTabInfo(tabId, info) {
try {
let preamble = info ? `${marker} + ${JSON.stringify(JSON.stringify([info]))} + ${marker} + "," + ` : "";
await browser.tabs.executeScript(tabId, {
code: `window.name = ${marker} + ${JSON.stringify(JSON.stringify([info]))} + ${marker} + "," + window.name;`,
code: `window.name = ${preamble}window.name.split(${marker} + ",").pop();`,
allFrames: false,
matchAboutBlank: true,
runAt: "document_start",
@@ -0,0 +1,52 @@
var ContentScriptOnce = (() => {
"use strict";

let requestMap = new Map();

{
let cleanup = r => {
let {requestId} = r;
let scripts = requestMap.get(requestId);
if (scripts) {
window.setTimeout(() => {
requestMap.delete(requestId);
for (let s of scripts) s.unregister();
}, 0);
}
}

let filter = {
urls: ["<all_urls>"],
types: ["main_frame", "sub_frame", "object"]
};
let wr = browser.webRequest;
for (let event of ["onCompleted", "onErrorOccurred"]) {
wr[event].addListener(cleanup, filter);
}
}

return {
async execute(request, options) {
let {requestId, url} = request;
let scripts = requestMap.get(requestId);
if (!scripts) requestMap.set(requestId, scripts = new Set());
try {
let urlObj = new URL(url);
if (urlObj.port) {
urlObj.port = "";
url = urlObj.toString();
}
} catch (e) {}
let defOpts = {
runAt: "document_start",
matchAboutBlank: true,
matches: [url],
allFrames: true,
};

scripts.add(await browser.contentScripts.register(
Object.assign(defOpts, options)
));
}
}
})();

This file was deleted.

@@ -90,7 +90,7 @@ var Settings = {

if (typeof unrestrictedTab === "boolean") {
ns.unrestrictedTabs[unrestrictedTab ? "add" : "delete"](tabId);
ChildPolicies.storeTabInfo(tabId, {unrestricted: unrestrictedTab});
ChildPolicies.storeTabInfo(tabId, unrestrictedTab && {unrestricted: true});
}
if (reloadAffected) {
browser.tabs.reload(tabId);
@@ -34,16 +34,20 @@ function deferWebTraffic(promiseToWaitFor, next) {
if (frameId !== 0) {
documentUrl = request.frameAncestors.pop().url;
}
reloadTab(tabId);
if (tabId !== -1) {
reloadTab(tabId);
} else {
debug("No tab to reload for %s %s from %s", type, url, documentUrl);
}
}
}
debug("Deferring ", url, type);
debug("Deferring %s %s from %s", type, url, documentUrl);
try {
await promiseToWaitFor;
} catch (e) {
error(e);
}
debug("Green light to ", url, type);
debug("Green light to %s %s from %s", type, url, documentUrl);
}

function spyTabs(request) {
@@ -36,7 +36,7 @@

await include("/bg/defaults.js");
await ns.defaults;
await include(["/bg/RequestGuard.js", "/bg/RequestUtil.js"]);
await include("/bg/RequestGuard.js");
await RequestGuard.start();
await XSS.start(); // we must start it anyway to initialize sub-objects
if (!ns.sync.xss) {
@@ -3,23 +3,30 @@
// debug = () => {}; // REL_ONLY
{
let listenersMap = new Map();
let backlog = new Set();
var ns = {
on(eventName, listener) {
let listeners = listenersMap.get(eventName);
if (!listeners) listenersMap.set(eventName, listeners = new Set());
listeners.add(listener);
if (backlog.has(eventName)) this.fire(eventName, listener);
},
detach(eventName, listener) {
let listeners = listenersMap.get(eventName);
if (listeners) listeners.delete(listener);
},
fire(eventName) {
fire(eventName, listener = null) {
if (listener) {
listener({type:eventName, source: this});
return;
}
let listeners = listenersMap.get(eventName);
if (listeners) {
for (let l of listeners) {
l(this);
this.fire(eventName, l);
}
}
backlog.add(eventName);
},
setup(DEFAULT, MARKER) {
this.perms.DEFAULT = DEFAULT;
@@ -36,10 +43,10 @@
let tabInfoRx = new RegExp(`^${MARKER}\\[([^]*?)\\]${MARKER},`);
if (top === window) { // wrap to hide
Reflect.defineProperty(top.wrappedJSObject, "name", {
get: exportFunction(() => _name.replace(eraseTabInfoRx, ""), top.wrappedJSObject),
get: exportFunction(() => top.name.replace(eraseTabInfoRx, ""), top.wrappedJSObject),
set: exportFunction(value => {
let preamble = _name.match(tabInfoRx);
_name = `${preamble && preamble[0] || ""}${value}`;
let preamble = top.name.match(tabInfoRx);
top.name = `${preamble && preamble[0] || ""}${value}`;
return value;
}, top.wrappedJSObject)
});
@@ -57,14 +64,14 @@
}
ns.fire("perms");
},
storeTabInfo(info) {
let {MARKER} = this.perms;
window.name = `${MARKER}${JSON.stringify([info])}${MARKER},${window.name.split(marker).pop()}`;
},
perms: { DEFAULT: null, CURRENT: null, tabInfo: {} },
perms: { DEFAULT: null, CURRENT: null, tabInfo: {}, MARKER: "" },
allows(cap) {
let perms = this.perms.CURRENT;
return perms && perms.capabilities.includes(cap);
},
getWindowName() {
return top !== window || !this.perms.MARKER ? window.name
: window.name.split(this.perms.MARKER + ",").pop();
}
}
}
@@ -1,4 +1,4 @@
ns.on("perms", ns => {
ns.on("perms", event => {
debug("Media Hook", document.URL, document.documentElement && document.documentElement.innerHTML, ns.perms.CURRENT); // DEV_ONLY
let mediaBlocker = !ns.allows("media");
let unpatched = new Map();
@@ -54,6 +54,4 @@ ns.on("perms", ns => {

return unpatched.get(window.MediaSource.prototype).addSourceBuffer.call(ms, mime, ...args);
});

})();
document.URL;
});
@@ -1,4 +1,4 @@
ns.on("perms", ns => {
ns.on("perms", event => {
debug("WebGL Hook", document.URL, document.documentElement && document.documentElement.innerHTML, ns.perms.CURRENT); // DEV_ONLY
if (ns.allows("webgl")) return;
let proto = HTMLCanvasElement.prototype;
@@ -26,4 +26,3 @@ ns.on("perms", ns => {
return getContext.call(this, type, ...rest);
}, proto, {defineAs: "getContext"});
});
document.URL;

0 comments on commit 2f9c529

Please sign in to comment.
You can’t perform that action at this time.