From 1ee85084f75f59fe83aeed17e5a1c59837e1db92 Mon Sep 17 00:00:00 2001 From: hackademix Date: Fri, 6 Jul 2018 00:59:12 +0200 Subject: [PATCH] More informative / useful popup on (semi)privileged pages. --- src/ui/popup.js | 53 +++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/ui/popup.js b/src/ui/popup.js index 3f84549..8ca4f44 100644 --- a/src/ui/popup.js +++ b/src/ui/popup.js @@ -107,27 +107,42 @@ addEventListener("unload", e => { let mainFrame = UI.seen && UI.seen.find(thing => thing.request.type === "main_frame"); debug("Seen: %o", UI.seen); if (!mainFrame) { - - if (/^https?:/.test(tab.url) && !tab.url.startsWith("https://addons.mozilla.org/")) { - document.body.classList.add("disabled"); - showMessage("warning", _("freshInstallReload")); - let buttons = document.querySelector("#buttons"); - let b = document.createElement("button"); - b.textContent = _("OK"); - b.onclick = document.getElementById("reload").onclick = () => { - reload(); - close(); + let isHttp = /^https?:/.test(tab.url); + try { + await browser.tabs.executeScript(tabId, { code: "" }); + if (isHttp) { + document.body.classList.add("disabled"); + showMessage("warning", _("freshInstallReload")); + let buttons = document.querySelector("#buttons"); + let b = document.createElement("button"); + b.textContent = _("OK"); + b.onclick = document.getElementById("reload").onclick = () => { + reload(); + close(); + } + buttons.appendChild(b); + b = document.createElement("button"); + b.textContent = _("Cancel"); + b.onclick = () => close(); + buttons.appendChild(b); + return; } - buttons.appendChild(b); - b = document.createElement("button"); - b.textContent = _("Cancel"); - b.onclick = () => close(); - buttons.appendChild(b); - return; + } catch (e) { + error(e, "Could not run scripts on %s: privileged page?", tab.url); + } + if (!isHttp) { + showMessage("warning", _("privilegedPage")); + let tempTrust = document.getElementById("temp-trust-page"); + tempTrust.disabled = true; + } + if (!UI.seen) { + if (!isHttp) return; + UI.seen = [ + mainFrame = { + request: { url: tab.url, documentUrl: tab.url, type: "main_frame" } + } + ]; } - showMessage("warning", _("privilegedPage")); - document.getElementById("temp-trust-page").disabled = true; - if (!UI.seen) return; } let justDomains = !UI.local.showFullAddresses;