From 4caf735a50c6de1ee2210ff6053b8f7fe8f99e83 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Mon, 13 Mar 2017 13:20:24 -0700 Subject: [PATCH] disable the pageshot button on about,data,moz-extension pages --- addon/webextension/background/main.js | 26 ++++++++++++++++++++++- addon/webextension/manifest.json.template | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/addon/webextension/background/main.js b/addon/webextension/background/main.js index 179d08b503..2f5cabd195 100644 --- a/addon/webextension/background/main.js +++ b/addon/webextension/background/main.js @@ -40,8 +40,12 @@ window.main = (function () { }); } + function opensMyShots(url) { + return /^about:(?:newtab|blank)/i.test(url) || /^resource:\/\/activity-streams\//i.test(url); + } + browser.browserAction.onClicked.addListener(catcher.watchFunction((tab) => { - if (tab.url.match(/about:(newtab|blank)/i)) { + if (opensMyShots(tab.url)) { catcher.watchPromise(analytics.refreshTelemetryPref().then(() => { sendEvent("goto-myshots", "about-newtab"); })); @@ -77,6 +81,26 @@ window.main = (function () { .then(() => sendEvent("start-shot", "context-menu"))); })); + function urlEnabled(url) { + if (opensMyShots(url)) { + return true; + } + if (url.startsWith(backend) || /^(?:about|data|moz-extension):/i.test(url)) { + return false; + } + return true; + } + + browser.tabs.onUpdated.addListener((id, info, tab) => { + if (info.url && tab.selected) { + if (urlEnabled(info.url)) { + browser.browserAction.enable(tab.id); + } + else { + browser.browserAction.disable(tab.id); + } + } + }); communication.register("sendEvent", (sender, ...args) => { catcher.watchPromise(sendEvent(...args)); diff --git a/addon/webextension/manifest.json.template b/addon/webextension/manifest.json.template index c765e52bd9..6d1177e8b3 100644 --- a/addon/webextension/manifest.json.template +++ b/addon/webextension/manifest.json.template @@ -57,6 +57,7 @@ ], "permissions": [ "activeTab", + "tabs", "storage", "notifications", "clipboardWrite",