Skip to content

Commit 6c1c199

Browse files
committed
Make "Temporarily set top-level sites to TRUSTED" work on Manifest V3 (issue #388).
1 parent 747c059 commit 6c1c199

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/bg/RequestGuard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,9 @@
817817
}
818818
};
819819

820-
function injectPolicyScript(details) {
820+
async function injectPolicyScript(details) {
821821
const {url, tabId, frameId} = details;
822-
const domPolicy = ns.computeChildPolicy({url}, {tab: {id: tabId}, frameId});
822+
const domPolicy = await ns.computeChildPolicy({url}, {tab: {id: tabId}, frameId});
823823
domPolicy.navigationURL = url;
824824
const callback = "ns_setupCallback";
825825
if (DocStartInjection.mv3Callbacks) {

src/bg/main.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200

201201
async fetchChildPolicy({url, contextUrl}, sender) {
202202
await ns.initializing;
203-
return ns.computeChildPolicy(...arguments);
203+
return await ns.computeChildPolicy(...arguments);
204204
},
205205

206206
async openStandalonePopup(tab) {
@@ -305,7 +305,7 @@
305305
return !this.isEnforced(request.tabId) || this.policy.can(request.url, capability, this.policyContext(request));
306306
},
307307

308-
computeChildPolicy({url, contextUrl}, sender) {
308+
async computeChildPolicy({url, contextUrl}, sender) {
309309
let {tab} = sender;
310310
let policy = ns.policy;
311311
const {isTorBrowser} = ns.local;
@@ -322,7 +322,8 @@
322322

323323
const tabId = tab ? tab.id : -1;
324324
let topUrl;
325-
if (sender.frameId === 0) {
325+
const isTop = sender.frameId === 0;
326+
if (isTop) {
326327
topUrl = url;
327328
} else if (tab) {
328329
if (!tab.url) tab = TabCache.get(tabId);
@@ -338,9 +339,16 @@
338339
let permissions, unrestricted, cascaded;
339340
if (policy) {
340341
let perms = policy.get(url, contextUrl).perms;
341-
cascaded = topUrl && ns.sync.cascadeRestrictions;
342-
if (cascaded) {
343-
perms = policy.cascadeRestrictions(perms, topUrl);
342+
if (isTop) {
343+
if (policy.autoAllowTop && perms === policy.DEFAULT) {
344+
policy.set(Sites.optimalKey(url), perms = policy.TRUSTED.tempTwin);
345+
await RequestGuard.DNRPolicy?.update();
346+
}
347+
} else {
348+
cascaded = topUrl && ns.sync.cascadeRestrictions;
349+
if (cascaded) {
350+
perms = policy.cascadeRestrictions(perms, topUrl);
351+
}
344352
}
345353
permissions = perms.dry();
346354
} else {

0 commit comments

Comments
 (0)