Skip to content

Commit 54d259a

Browse files
committed
Bug 1874599 - Add a pref to disable userContextId guessing for external opens;r=mossop
Bug 1692124 improved the behavior for workflows where external opens should move into sessions inside containers, but it created an issue for those where external opens should move into the default container and there are also tabs from the same domains inside containers, and would create extra interstitials with the Multi-Account Containers addon if the predicted container is different than the "always open" addon setting. While the heuristic could be improved, it will never be perfect for all workflows, so this patch introduces a pref to opt out of the behavior (and always open external links in the default user context ID). Differential Revision: https://phabricator.services.mozilla.com/D199443
1 parent 4eaf954 commit 54d259a

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

browser/app/profile/firefox.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@ pref("permissions.desktop-notification.notNow.enabled", false);
826826

827827
pref("permissions.fullscreen.allowed", false);
828828

829+
// Force external link opens into the default user context ID instead of guessing
830+
// the most appropriate one based on the URL (https://bugzilla.mozilla.org/show_bug.cgi?id=1874599#c8)
831+
pref("browser.link.force_default_user_context_id_for_external_opens", false);
832+
829833
// handle links targeting new windows
830834
// 1=current window/tab, 2=new window, 3=new tab in most recent window
831835
pref("browser.link.open_newwindow", 3);

browser/base/content/browser.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6139,8 +6139,15 @@ nsBrowserAccess.prototype = {
61396139
) {
61406140
var browsingContext = null;
61416141
var isExternal = !!(aFlags & Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
6142+
var guessUserContextIdEnabled =
6143+
isExternal &&
6144+
!Services.prefs.getBoolPref(
6145+
"browser.link.force_default_user_context_id_for_external_opens",
6146+
false
6147+
);
61426148
var openingUserContextId =
6143-
(isExternal && URILoadingHelper.guessUserContextId(aURI)) ||
6149+
(guessUserContextIdEnabled &&
6150+
URILoadingHelper.guessUserContextId(aURI)) ||
61446151
Ci.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID;
61456152

61466153
if (aOpenWindowInfo && isExternal) {

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

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ async function openTabInUserContext(uri, userContextId, win = window) {
2727
}
2828

2929
registerCleanupFunction(async function cleanup() {
30+
Services.prefs.clearUserPref(
31+
"browser.link.force_default_user_context_id_for_external_opens"
32+
);
3033
while (gBrowser.tabs.length > 1) {
3134
gBrowser.removeTab(gBrowser.selectedTab, { animate: false });
3235
}
@@ -69,19 +72,7 @@ add_task(async function test() {
6972
is(guessUserContextId(HOST_EXAMPLE), WORK, "forgets closed window");
7073

7174
// Check the opener flow more directly
72-
let browsingContext = window.browserDOMWindow.openURI(
73-
makeURI(HOST_EXAMPLE.spec + "?new"),
74-
null,
75-
Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
76-
Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL,
77-
Services.scriptSecurityManager.getSystemPrincipal()
78-
);
79-
await BrowserTestUtils.browserLoaded(browsingContext.embedderElement);
80-
is(
81-
browsingContext.embedderElement,
82-
gBrowser.selectedBrowser,
83-
"opener selected"
84-
);
75+
openURIFromExternal(HOST_EXAMPLE.spec + "?new");
8576
is(
8677
gBrowser.selectedTab.getAttribute("usercontextid"),
8778
WORK.toString(),
@@ -93,4 +84,32 @@ add_task(async function test() {
9384
DEFAULT,
9485
"still matches default container"
9586
);
87+
88+
// Force into default with the pref from https://bugzilla.mozilla.org/show_bug.cgi?id=1692124
89+
Services.prefs.setBoolPref(
90+
"browser.link.force_default_user_context_id_for_external_opens",
91+
true
92+
);
93+
openURIFromExternal(HOST_EXAMPLE.spec + "?new");
94+
is(
95+
gBrowser.selectedTab.getAttribute("usercontextid"),
96+
"",
97+
"opener flow with default user context ID forced by pref"
98+
);
9699
});
100+
101+
async function openURIFromExternal(spec) {
102+
let browsingContext = window.browserDOMWindow.openURI(
103+
makeURI(spec),
104+
null,
105+
Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
106+
Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL,
107+
Services.scriptSecurityManager.getSystemPrincipal()
108+
);
109+
await BrowserTestUtils.browserLoaded(browsingContext.embedderElement);
110+
is(
111+
browsingContext.embedderElement,
112+
gBrowser.selectedBrowser,
113+
"opener selected"
114+
);
115+
}

0 commit comments

Comments
 (0)