Skip to content

Commit 26e3113

Browse files
committed
[Containers] Gracefully degrade when containers are disabled by browser options.
1 parent 84ee07d commit 26e3113

5 files changed

Lines changed: 64 additions & 26 deletions

File tree

src/nscl

src/ui/options.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,23 @@ fieldset:disabled {
120120
justify-content: flex-start;
121121
}
122122

123+
#container-options::before {
124+
content: "📦︎";
125+
font-variant-emoji: text;
126+
font-size: 2em;
127+
color: var(--container-color);
128+
}
129+
130+
#select-container {
131+
border-color: var(--container-color);
132+
}
133+
123134
#container-options label {
124135
margin-block: auto;
125136
}
126137

127138
#container-options div {
128-
margin-inline-end: 1em;
139+
margin-inline: .5em;
129140
}
130141

131142
#container-options button{

src/ui/options.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,27 @@ document.querySelector("#version").textContent = _("Version",
223223
var currentPolicy = await UI.getPolicy(cookieStoreId);
224224

225225
function updateContainersEnabled() {
226-
const containersEnabled = Boolean(contextStore.enabled && browser.contextualIdentities);
227-
document.querySelector("#containers-opt").style.display = browser.contextualIdentities? "": "none";
228-
document.querySelector("#opt-containers").disabled = !browser.contextualIdentities;
226+
const supported = browser.contextualIdentities && !contextStore.disabledByHost;
227+
const containersEnabled = supported && contextStore.enabled;
228+
document.querySelector("#containers-opt").style.display = supported ? "": "none";
229+
document.querySelector("#opt-containers").disabled = !supported;
229230
document.querySelector("#opt-containers").checked = contextStore.enabled;
230-
document.querySelector("#container-options").style.display = containersEnabled ? "" : "none";
231+
document.querySelector("#container-options").style.display = supported ? "" : "none";
231232
}
232233
updateContainersEnabled();
233234

234-
function constrainContainerCopy() {
235+
function syncContainerSelectors() {
235236
containerCopy.disabled = cookieStoreId == "default";
236237
for (const opt of containerCopy.options) {
237-
opt.disabled = opt.value == cookieStoreId;
238+
if (opt.disabled = (opt.value == cookieStoreId)) {
239+
document.querySelector("#container-options").style.setProperty("--container-color", opt.style.color);
240+
}
238241
}
239242
}
240243

241244
async function changeContainer() {
242245
cookieStoreId = containerSelect.value;
243-
constrainContainerCopy();
246+
syncContainerSelectors();
244247
currentPolicy = await UI.getPolicy(cookieStoreId);
245248
debug("container change", cookieStoreId, currentPolicy);
246249
sitesUI.clear()
@@ -275,9 +278,7 @@ document.querySelector("#version").textContent = _("Version",
275278
let newContainers = [{cookieStoreId: "default", name: "Default"},];
276279
let identities = browser.contextualIdentities && await browser.contextualIdentities.query({});
277280
if (identities) {
278-
identities.forEach(({cookieStoreId, name}) => {
279-
newContainers.push({cookieStoreId, name});
280-
})
281+
newContainers.push(...identities);
281282
}
282283
if (JSON.stringify(newContainers) == JSON.stringify(containers)) return;
283284
containers = newContainers;
@@ -286,6 +287,7 @@ document.querySelector("#version").textContent = _("Version",
286287
const o = options.appendChild(document.createElement("option"));
287288
o.value = container.cookieStoreId;
288289
o.text = container.name;
290+
o.style.color = container.colorCode || "";
289291
}
290292
while (containerSelect.firstChild) {
291293
containerSelect.removeChild(containerSelect.firstChild);
@@ -298,7 +300,7 @@ document.querySelector("#version").textContent = _("Version",
298300
containerCopy.appendChild(document.createElement("option")).value = "blank";
299301
containerCopy.appendChild(options);
300302

301-
constrainContainerCopy();
303+
syncContainerSelectors();
302304
}
303305
containerSelect.onfocus = updateContainerOptions;
304306
containerCopy.onfocus = updateContainerOptions;

src/ui/popup.css

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,25 @@ html:not(.mobile) #scrollable {
157157
margin-block: auto;
158158
padding: .4em;
159159
font-size: 1.2em;
160-
border:1px solid lightgray;
160+
border:1px solid;
161+
border-color: var(--container-color);
161162
border-radius: .3em;
163+
content: "📦︎";
164+
font-variant-emoji: text;
162165
}
163166

167+
.container-id::before {
168+
content: "📦︎";
169+
font-variant-emoji: text;
170+
font-size: 1em;
171+
line-height: 0;
172+
padding: 0 .4em 0 0;
173+
margin: 0;
174+
color: var(--container-color);
175+
}
176+
177+
178+
164179
.hider {
165180
background: var(--form-color1);
166181
box-shadow: inset 0 1px 3px #444;

src/ui/popup.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,30 @@ addEventListener("unload", e => {
186186
if (e.tabId !== tabId) close();
187187
});
188188
}
189-
190-
if (UI.contextStore && UI.contextStore.enabled && browser.contextualIdentities) {
191-
try {
192-
let containerName = (await browser.contextualIdentities.get(cookieStoreId)).name;
193-
document.querySelector("#container-id").textContent = containerName;
194-
debug("found container name", containerName, "for cookieStoreId", cookieStoreId);
195-
} catch(err) {
196-
document.querySelector("#container-id").textContent = _("DefaultContainerName");
197-
debug("no container for cookieStoreId", cookieStoreId, "error:", err.message);
189+
{
190+
let { contextStore } = UI;
191+
const containerId = document.querySelector("#container-id");
192+
if (contextStore?.enabled && !contextStore.disabledByHost && browser.contextualIdentities) {
193+
try {
194+
const { name, colorCode} = await browser.contextualIdentities.get(cookieStoreId);
195+
containerId.textContent = name;
196+
containerId.style.setProperty("--container-color", colorCode);
197+
198+
debug("found container name", name, "for cookieStoreId", cookieStoreId); // DEV_ONLY
199+
} catch (err) {
200+
if (/\bdisabled\b/.test(err.message)) {
201+
contextStore = null;
202+
} else {
203+
containerId.textContent = _("DefaultContainerName");
204+
}
205+
debug("no container for cookieStoreId", cookieStoreId, "error:", err.message); // DEV_ONLY
206+
} } else {
207+
contextStore = null;
208+
}
209+
if (!contextStore) {
210+
containerId.style.display = "none";
198211
}
199-
} else {
200-
document.querySelector("#container-id").style.visibility = 'hidden';
201212
}
202-
203213
await include("/ui/toolbar.js");
204214
UI.toolbarInit();
205215
{

0 commit comments

Comments
 (0)