From 27ddb8124df1e1acdddd39c1d93ce36a34b7aa8b Mon Sep 17 00:00:00 2001 From: hackademix Date: Mon, 1 Jun 2020 19:50:44 +0200 Subject: [PATCH] Incognito-aware permissions persistence and UI (https://trac.torproject.org/projects/tor/ticket/29957) --- src/bg/RequestGuard.js | 5 +++-- src/ui/popup.js | 5 +++++ src/ui/ui.css | 4 ++++ src/ui/ui.js | 13 +++++++++++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/bg/RequestGuard.js b/src/bg/RequestGuard.js index 40611b7..1f23042 100644 --- a/src/bg/RequestGuard.js +++ b/src/bg/RequestGuard.js @@ -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) { diff --git a/src/ui/popup.js b/src/ui/popup.js index 843e54d..a6cae6c 100644 --- a/src/ui/popup.js +++ b/src/ui/popup.js @@ -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); } diff --git a/src/ui/ui.css b/src/ui/ui.css index 98747b3..302b24e 100644 --- a/src/ui/ui.css +++ b/src/ui/ui.css @@ -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); } diff --git a/src/ui/ui.js b/src/ui/ui.js index 1bdf1aa..11f0621 100644 --- a/src/ui/ui.js +++ b/src/ui/ui.js @@ -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; }