Skip to content

Commit 3522ca6

Browse files
committed
Simplify injectPolicyScript and computeChildPolicy
1 parent 2e97e19 commit 3522ca6

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

src/bg/RequestGuard.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,10 +644,9 @@ var RequestGuard = (() => {
644644
return ABORT;
645645
}
646646

647-
async function injectPolicyScript(details) {
648-
let {url, tabId, frameId} = details;
649-
let tab = await browser.tabs.get(tabId);
650-
let policy = ns.computeChildPolicy({url}, {tab, frameId});
647+
function injectPolicyScript(details) {
648+
let {url, tabId, frameId, cookieStoreId} = details;
649+
let policy = ns.computeChildPolicy({url}, {tab: {id: tabId}, frameId, cookieStoreId});
651650
policy.navigationURL = url;
652651
let debugStatement = ns.local.debug ? `
653652
let mark = Date.now() + ":" + Math.random();

src/bg/main.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,19 @@
261261

262262
computeChildPolicy({url, contextUrl}, sender) {
263263
let {tab, frameId} = sender;
264-
let cookieStoreId = (tab)? tab.cookieStoreId : "default";
265-
var policy = ns.policy;
266-
debug("computing policy", cookieStoreId, ns.contextStore);
267-
if (
268-
cookieStoreId &&
269-
!cookieStoreId.toLowerCase().includes("default") && //exclude firefox-default
270-
ns.contextStore &&
271-
ns.contextStore.policies.hasOwnProperty(cookieStoreId)
272-
) {
273-
policy = ns.contextStore.policies[cookieStoreId];
264+
let tabId = tab ? tab.id : -1;
265+
let topUrl;
266+
if (frameId === 0) {
267+
topUrl = url;
268+
} else if (tab) {
269+
if (!tab.url) tab = TabCache.get(tabId);
270+
if (tab) topUrl = tab.url;
274271
}
275-
debug("chose policy", policy);
272+
if (!topUrl) topUrl = url;
273+
if (!contextUrl) contextUrl = topUrl;
274+
275+
let cookieStoreId = sender.cookieStoreId ? sender.cookieStoreId : tab.cookieStoreId;
276+
let policy = ns.getPolicy(cookieStoreId);
276277
let {isTorBrowser} = ns.local;
277278
if (!policy) {
278279
console.log("Policy is null, initializing: %o, sending fallback.", ns.initializing);
@@ -285,17 +286,6 @@
285286
};
286287
}
287288

288-
let tabId = tab ? tab.id : -1;
289-
let topUrl;
290-
if (frameId === 0) {
291-
topUrl = url;
292-
} else if (tab) {
293-
if (!tab.url) tab = TabCache.get(tabId);
294-
if (tab) topUrl = tab.url;
295-
}
296-
if (!topUrl) topUrl = url;
297-
if (!contextUrl) contextUrl = topUrl;
298-
299289
if (Sites.isInternal(url) || !ns.isEnforced(tabId)) {
300290
policy = null;
301291
}

src/nscl

0 commit comments

Comments
 (0)