Clean up disabled Private Mode notice. Fixes #878

This commit is contained in:
Jonathan Kingston 2017-09-29 16:59:51 +01:00
parent c1e9cc3c56
commit c433c6b39e
4 changed files with 11 additions and 37 deletions

View file

@ -4,12 +4,13 @@ const badge = {
const currentWindow = await browser.windows.getCurrent(); const currentWindow = await browser.windows.getCurrent();
this.displayBrowserActionBadge(currentWindow.incognito); this.displayBrowserActionBadge(currentWindow.incognito);
}, },
async displayBrowserActionBadge(disable) {
if (disable) { disableAddon(tabId) {
browser.browserAction.disable(); browser.browserAction.disable(tabId);
} else { browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" });
browser.browserAction.enable(); },
}
async displayBrowserActionBadge() {
const extensionInfo = await backgroundLogic.getExtensionInfo(); const extensionInfo = await backgroundLogic.getExtensionInfo();
const storage = await browser.storage.local.get({browserActionBadgesClicked: []}); const storage = await browser.storage.local.get({browserActionBadgesClicked: []});

View file

@ -11,7 +11,6 @@
"js/background/badge.js", "js/background/badge.js",
"js/background/identityState.js", "js/background/identityState.js",
"js/background/messageHandler.js", "js/background/messageHandler.js",
"js/backdround/init.js"
] ]
--> -->
<script type="text/javascript" src="backgroundLogic.js"></script> <script type="text/javascript" src="backgroundLogic.js"></script>
@ -19,6 +18,5 @@
<script type="text/javascript" src="badge.js"></script> <script type="text/javascript" src="badge.js"></script>
<script type="text/javascript" src="identityState.js"></script> <script type="text/javascript" src="identityState.js"></script>
<script type="text/javascript" src="messageHandler.js"></script> <script type="text/javascript" src="messageHandler.js"></script>
<script type="text/javascript" src="init.js"></script>
</body> </body>
</html> </html>

View file

@ -1,27 +0,0 @@
browser.runtime.sendMessage({
method: "getPreference",
pref: "browser.privatebrowsing.autostart"
}).then(pbAutoStart => {
// We don't want to disable the addon if we are in auto private-browsing.
if (!pbAutoStart) {
browser.tabs.onCreated.addListener(tab => {
if (tab.incognito) {
disableAddon(tab.id);
}
});
browser.tabs.query({}).then(tabs => {
for (let tab of tabs) { // eslint-disable-line prefer-const
if (tab.incognito) {
disableAddon(tab.id);
}
}
}).catch(() => {});
}
}).catch(() => {});
function disableAddon(tabId) {
browser.browserAction.disable(tabId);
browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" });
}

View file

@ -106,6 +106,9 @@ const messageHandler = {
}, {urls: ["<all_urls>"], types: ["main_frame"]}); }, {urls: ["<all_urls>"], types: ["main_frame"]});
browser.tabs.onCreated.addListener((tab) => { browser.tabs.onCreated.addListener((tab) => {
if (tab.incognito) {
badge.disableAddon(tab.id);
}
// lets remember the last tab created so we can close it if it looks like a redirect // lets remember the last tab created so we can close it if it looks like a redirect
this.lastCreatedTab = tab; this.lastCreatedTab = tab;
if (tab.cookieStoreId) { if (tab.cookieStoreId) {
@ -130,12 +133,11 @@ const messageHandler = {
async onFocusChangedCallback(windowId) { async onFocusChangedCallback(windowId) {
assignManager.removeContextMenu(); assignManager.removeContextMenu();
const currentWindow = await browser.windows.getCurrent();
// browserAction loses background color in new windows ... // browserAction loses background color in new windows ...
// https://bugzil.la/1314674 // https://bugzil.la/1314674
// https://github.com/mozilla/testpilot-containers/issues/608 // https://github.com/mozilla/testpilot-containers/issues/608
// ... so re-call displayBrowserActionBadge on window changes // ... so re-call displayBrowserActionBadge on window changes
badge.displayBrowserActionBadge(currentWindow.incognito); badge.displayBrowserActionBadge();
browser.tabs.query({active: true, windowId}).then((tabs) => { browser.tabs.query({active: true, windowId}).then((tabs) => {
if (tabs && tabs[0]) { if (tabs && tabs[0]) {
assignManager.calculateContextMenu(tabs[0]); assignManager.calculateContextMenu(tabs[0]);