Skip to content

Commit 5b516a5

Browse files
committed
Bug 1858309 - Include tabs without a container set in the heuristic for guessing the container from external opener r=mossop
This fixes a bug where we assign a URL into a container when it shouldn't be. Differential Revision: https://phabricator.services.mozilla.com/D190646
1 parent 5b311b3 commit 5b516a5

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

browser/components/contextualidentity/test/browser/browser_guessusercontext.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"use strict";
55

6+
const DEFAULT = Ci.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID;
67
const PERSONAL = 1;
78
const WORK = 2;
89
const HOST_MOCHI = makeURI(
@@ -43,6 +44,17 @@ add_task(async function test() {
4344
await openTabInUserContext(HOST_EXAMPLE.spec, PERSONAL);
4445
is(guessUserContextId(HOST_EXAMPLE), PERSONAL, "one tab - matches container");
4546
is(guessUserContextId(HOST_MOCHI), null, "one tab - doesn't match container");
47+
48+
await openTabInUserContext(HOST_MOCHI.spec, PERSONAL);
49+
is(guessUserContextId(HOST_MOCHI), PERSONAL, "one tab - matches container");
50+
await openTabInUserContext(HOST_MOCHI.spec);
51+
await openTabInUserContext(HOST_MOCHI.spec);
52+
is(
53+
guessUserContextId(HOST_MOCHI),
54+
DEFAULT,
55+
"can guess guess default container"
56+
);
57+
4658
await openTabInUserContext(HOST_EXAMPLE.spec, WORK);
4759
is(guessUserContextId(HOST_EXAMPLE), PERSONAL, "same number - use first");
4860
await openTabInUserContext(HOST_EXAMPLE.spec, WORK);
@@ -76,5 +88,9 @@ add_task(async function test() {
7688
"opener flow"
7789
);
7890
is(guessUserContextId(HOST_EXAMPLE), WORK, "still the most common");
79-
is(guessUserContextId(HOST_MOCHI), null, "still doesn't match container");
91+
is(
92+
guessUserContextId(HOST_MOCHI),
93+
DEFAULT,
94+
"still matches default container"
95+
);
8096
});

browser/modules/URILoadingHelper.sys.mjs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -761,19 +761,17 @@ export const URILoadingHelper = {
761761
for (let win of lazy.BrowserWindowTracker.orderedWindows) {
762762
for (let tab of win.gBrowser.visibleTabs) {
763763
let { userContextId } = tab;
764-
if (userContextId) {
765-
let currentURIHost = null;
766-
try {
767-
currentURIHost = tab.linkedBrowser.currentURI.host;
768-
} catch (e) {}
769-
770-
if (currentURIHost == host) {
771-
let count = (containerScores.get(userContextId) ?? 0) + 1;
772-
containerScores.set(userContextId, count);
773-
if (count > maxCount) {
774-
guessedUserContextId = userContextId;
775-
maxCount = count;
776-
}
764+
let currentURIHost = null;
765+
try {
766+
currentURIHost = tab.linkedBrowser.currentURI.host;
767+
} catch (e) {}
768+
769+
if (currentURIHost == host) {
770+
let count = (containerScores.get(userContextId) ?? 0) + 1;
771+
containerScores.set(userContextId, count);
772+
if (count > maxCount) {
773+
guessedUserContextId = userContextId;
774+
maxCount = count;
777775
}
778776
}
779777
}

0 commit comments

Comments
 (0)