From 3d7dfba2f9c8ea0a64ad7e4eec30ba8a14f0e061 Mon Sep 17 00:00:00 2001 From: Tobias Laundal Date: Thu, 16 Nov 2017 22:00:36 +0100 Subject: [PATCH] Add button on container info pane to show only that container. Adds a button, located on the info pane for each container, to show only that container. This button will hide other containers, if they have visible tabs, and show the container the button was pressed for, if it has hidden tabs. This is a much-needed function to effectively use containers as workspaces, and will please most people coming to multi-account-containers from Panorama tabs. --- webextension/js/background/backgroundLogic.js | 29 +++++++++++++++++++ webextension/js/background/messageHandler.js | 6 ++++ webextension/js/popup.js | 16 ++++++++++ webextension/popup.html | 2 ++ 4 files changed, 53 insertions(+) diff --git a/webextension/js/background/backgroundLogic.js b/webextension/js/background/backgroundLogic.js index cb62e06..da59c33 100644 --- a/webextension/js/background/backgroundLogic.js +++ b/webextension/js/background/backgroundLogic.js @@ -318,6 +318,35 @@ const backgroundLogic = { return Promise.all(promises); }, + async showOnly(options) { + if (!("windowId" in options) || !("cookieStoreId" in options)) { + return Promise.reject("showOnly needs both a windowId and a cookieStoreId"); + } + + const [identities, state] = await Promise.all([ + browser.contextualIdentities.query({}), + backgroundLogic.queryIdentitiesState(options.windowId) + ]); + + const promises = []; + identities + .filter(identity => { + const stateObject = state[identity.cookieStoreId]; + const filt = identity.cookieStoreId !== options.cookieStoreId && + stateObject && stateObject.hasOpenTabs; + return filt; + }).map(identity => identity.cookieStoreId) + .forEach(cookieStoreId => { + promises.push(backgroundLogic.hideTabs({cookieStoreId, windowId: options.windowId})); + }); + + // We need to call unhideContainer in messageHandler to prevent it from + // unhiding multiple times + promises.push(messageHandler.unhideContainer(options.cookieStoreId)); + + return Promise.all(promises); + }, + cookieStoreId(userContextId) { return `firefox-container-${userContextId}`; } diff --git a/webextension/js/background/messageHandler.js b/webextension/js/background/messageHandler.js index 7648c9a..96e3628 100644 --- a/webextension/js/background/messageHandler.js +++ b/webextension/js/background/messageHandler.js @@ -71,6 +71,12 @@ const messageHandler = { case "unhideAllTabs": response = backgroundLogic.unhideAllTabs(m.message.windowId); break; + case "showOnly": + response = backgroundLogic.showOnly({ + windowId: m.windowId, + cookieStoreId: m.cookieStoreId + }); + break; } return response; }); diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 3b8c399..59f032a 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -719,6 +719,19 @@ Logic.registerPanel(P_CONTAINER_INFO, { } }); + Logic.addEnterHandler(document.querySelector("#container-info-hideothers"), async function () { + try { + browser.runtime.sendMessage({ + method: "showOnly", + windowId: browser.windows.WINDOW_ID_CURRENT, + cookieStoreId: Logic.currentCookieStoreId() + }); + window.close(); + } catch (e) { + window.close(); + } + }); + // Check if the user has incompatible add-ons installed try { const incompatible = await browser.runtime.sendMessage({ @@ -775,6 +788,9 @@ Logic.registerPanel(P_CONTAINER_INFO, { const hideShowLabel = document.getElementById("container-info-hideorshow-label"); hideShowLabel.textContent = identity.hasHiddenTabs ? "Show this container" : "Hide this container"; + const hideOthersLabel = document.getElementById("container-info-hideothers"); + hideOthersLabel.textContent = identity.hasHiddenTabs ? "Show only this container" : "Hide other containers"; + // Let's remove all the previous tabs. const table = document.getElementById("container-info-table"); while (table.firstChild) { diff --git a/webextension/popup.html b/webextension/popup.html index 68c2d86..1634f4b 100644 --- a/webextension/popup.html +++ b/webextension/popup.html @@ -1,3 +1,4 @@ + @@ -141,6 +142,7 @@ Hide Container icon Hide this container +
Hide other containers
Move tabs to a new window