Incognito-aware permissions persistence and UI (https://trac.torproject.org/projects/tor/ticket/29957)

This commit is contained in:
hackademix 2020-06-01 19:50:44 +02:00
parent 890c3a0a55
commit 27ddb8124d
4 changed files with 23 additions and 4 deletions

View File

@ -191,7 +191,7 @@ var RequestGuard = (() => {
title: _("BlockedObjects"),
message: _("allowLocal", TAG),
options});
debug(`Prompt returned %o`);
debug(`Prompt returned`, ret, sender);
if (ret.button !== 0) return;
if (ret.option === 2) {
return {collapse: "all"};
@ -201,7 +201,8 @@ var RequestGuard = (() => {
let {siteMatch, contextMatch, perms} = ns.policy.get(key, documentUrl);
let {capabilities} = perms;
if (!capabilities.has(policyType)) {
perms = new Permissions(new Set(capabilities), false);
let temp = sender.tab.incognito; // we don't want to store in PBM
perms = new Permissions(new Set(capabilities), temp);
perms.capabilities.add(policyType);
/* TODO: handle contextual permissions
if (documentUrl) {

View File

@ -303,7 +303,12 @@ addEventListener("unload", e => {
sitesUI.mainUrl = new URL(mainFrame.request.url)
sitesUI.mainSite = urlToLabel(sitesUI.mainUrl);
sitesUI.mainDomain = tld.getDomain(sitesUI.mainUrl.hostname);
sitesUI.incognito = tab.incognito;
if (sitesUI.incognito) {
document.body.classList.add("incognito");
}
sitesUI.render(sites);
}

View File

@ -335,6 +335,10 @@ html:not(.mobile) :focus {
-3px 3px 3px rgba(255,255,100, .5), 3px -3px 3px rgba(255,255,100, .5);
}
input.preset:disabled {
filter: grayscale(100%);
}
input.preset[value="T_TRUSTED"] {
background-image: url(/img/ui-temp64.png);
}

View File

@ -237,6 +237,7 @@ var UI = (() => {
"UNTRUSTED": false,
"CUSTOM": true,
};
const INCOGNITO_PRESETS = ["DEFAULT", "T_TRUSTED", "CUSTOM"];
UI.Sites = class {
constructor(parentNode, presets = DEF_PRESETS) {
@ -261,16 +262,19 @@ var UI = (() => {
let messageKey = UI.presets[preset];
input.value = preset;
label.textContent = label.title = input.title = _(messageKey);
input.disabled = this.incognito && !INCOGNITO_PRESETS.includes(preset);
let clone = span.cloneNode(true);
clone.classList.add(preset);
let temp = clone.querySelector(".temp");
if (TEMP_PRESETS.includes(preset)) {
temp.title = _("allowTemp", `(${label.title.toUpperCase()})`);
temp.nextElementSibling.textContent = _("allowTemp", ""); // label;
temp.disabled = this.incognito;
} else {
temp.nextElementSibling.remove();
temp.remove();
}
presets.appendChild(clone);
}
@ -418,6 +422,9 @@ var UI = (() => {
}
if (isCap) {
perms.set(target.value, target.checked);
if (this.incognito) {
row.perms.temp = tempToggle.checked = true;
}
} else if (policyPreset) {
if (tempToggle && tempToggle.checked) {
policyPreset = policyPreset.tempTwin;
@ -434,8 +441,9 @@ var UI = (() => {
} else if (preset.value === "CUSTOM") {
if (isTemp) {
row.perms.temp = target.checked;
row.perms.temp = target.checked || this.incognito;
} else {
if (this.incognito) row.perms.temp = true;
let temp = row.perms.temp;
tempToggle.checked = temp;
let perms = row._customPerms ||
@ -525,7 +533,7 @@ var UI = (() => {
case "KeyT":
{
let temp = preset.parentNode.querySelector("input.temp");
if (temp) temp.checked = !temp.checked;
if (temp) temp.checked = !temp.checked || this.incognito;
}
}
}
@ -855,6 +863,7 @@ var UI = (() => {
temp.checked = perms.temp;
}
}
preset.disabled = false;
}
return row;
}