forked from mirrors/gecko-dev
Bug 1081542 - Part 1: Add nsIBrowserDOMWindow.OPEN_NEWTAB_FOREGROUND. r=smaug,geckoview-reviewers,Gijs,amejiamarmol
Given meta/ctrl key should use browser.tabs.loadInBackground pref instead of browser.tabs.loadDivertedInBackground pref, the existing nsIBrowserDOMWindow.OPEN_NEWTAB behavior doesn't match the requirement. Add dedicate flag for "open in foreground tab" to make it controllable from nsWindowWatcher::IsWindowOpenLocationModified. Differential Revision: https://phabricator.services.mozilla.com/D201929
This commit is contained in:
parent
0d0dbf9c30
commit
86d5bc7bde
8 changed files with 41 additions and 20 deletions
|
|
@ -6061,7 +6061,7 @@ nsBrowserAccess.prototype = {
|
|||
aName = "",
|
||||
aCsp = null,
|
||||
aSkipLoad = false,
|
||||
aForceLoadInBackground = false
|
||||
aWhere = undefined
|
||||
) {
|
||||
let win, needToFocusWin;
|
||||
|
||||
|
|
@ -6084,11 +6084,20 @@ nsBrowserAccess.prototype = {
|
|||
return win.gBrowser.selectedBrowser;
|
||||
}
|
||||
|
||||
let loadInBackground = Services.prefs.getBoolPref(
|
||||
"browser.tabs.loadDivertedInBackground"
|
||||
);
|
||||
if (aForceLoadInBackground) {
|
||||
// OPEN_NEWTAB_BACKGROUND and OPEN_NEWTAB_FOREGROUND are used by
|
||||
// `window.open` with modifiers.
|
||||
// The last case is OPEN_NEWTAB, which is used by:
|
||||
// * a link with `target="_blank"`, without modifiers
|
||||
// * `window.open` without features, without modifiers
|
||||
let loadInBackground;
|
||||
if (aWhere === Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_BACKGROUND) {
|
||||
loadInBackground = true;
|
||||
} else if (aWhere === Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_FOREGROUND) {
|
||||
loadInBackground = false;
|
||||
} else {
|
||||
loadInBackground = Services.prefs.getBoolPref(
|
||||
"browser.tabs.loadDivertedInBackground"
|
||||
);
|
||||
}
|
||||
|
||||
let tab = win.gBrowser.addTab(aURI ? aURI.spec : "about:blank", {
|
||||
|
|
@ -6265,7 +6274,8 @@ nsBrowserAccess.prototype = {
|
|||
}
|
||||
break;
|
||||
case Ci.nsIBrowserDOMWindow.OPEN_NEWTAB:
|
||||
case Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_BACKGROUND: {
|
||||
case Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_BACKGROUND:
|
||||
case Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_FOREGROUND: {
|
||||
// If we have an opener, that means that the caller is expecting access
|
||||
// to the nsIDOMWindow of the opened tab right away. For e10s windows,
|
||||
// this means forcing the newly opened browser to be non-remote so that
|
||||
|
|
@ -6276,8 +6286,6 @@ nsBrowserAccess.prototype = {
|
|||
let userContextId = aOpenWindowInfo
|
||||
? aOpenWindowInfo.originAttributes.userContextId
|
||||
: openingUserContextId;
|
||||
let forceLoadInBackground =
|
||||
aWhere == Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_BACKGROUND;
|
||||
let browser = this._openURIInNewTab(
|
||||
aURI,
|
||||
referrerInfo,
|
||||
|
|
@ -6291,7 +6299,7 @@ nsBrowserAccess.prototype = {
|
|||
"",
|
||||
aCsp,
|
||||
aSkipLoad,
|
||||
forceLoadInBackground
|
||||
aWhere
|
||||
);
|
||||
if (browser) {
|
||||
browsingContext = browser.browsingContext;
|
||||
|
|
@ -6392,7 +6400,8 @@ nsBrowserAccess.prototype = {
|
|||
|
||||
if (
|
||||
aWhere != Ci.nsIBrowserDOMWindow.OPEN_NEWTAB &&
|
||||
aWhere != Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_BACKGROUND
|
||||
aWhere != Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_BACKGROUND &&
|
||||
aWhere != Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_FOREGROUND
|
||||
) {
|
||||
dump("Error: openURIInFrame can only open in new tabs or print");
|
||||
return null;
|
||||
|
|
@ -6406,9 +6415,6 @@ nsBrowserAccess.prototype = {
|
|||
? aParams.openerOriginAttributes.userContextId
|
||||
: Ci.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID;
|
||||
|
||||
var forceLoadInBackground =
|
||||
aWhere == Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_BACKGROUND;
|
||||
|
||||
return this._openURIInNewTab(
|
||||
aURI,
|
||||
aParams.referrerInfo,
|
||||
|
|
@ -6422,7 +6428,7 @@ nsBrowserAccess.prototype = {
|
|||
aName,
|
||||
aParams.csp,
|
||||
aSkipLoad,
|
||||
forceLoadInBackground
|
||||
aWhere
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ add_task(async function () {
|
|||
const tests = [
|
||||
["OPEN_NEWTAB", false],
|
||||
["OPEN_NEWTAB_BACKGROUND", true],
|
||||
["OPEN_NEWTAB_FOREGROUND", false],
|
||||
];
|
||||
|
||||
for (const [flag, isBackground] of tests) {
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ interface nsIBrowserDOMWindow : nsISupports
|
|||
/**
|
||||
* Open in a new content tab in the toplevel browser window corresponding to
|
||||
* this nsIBrowserDOMWindow.
|
||||
* Use browser.tabs.loadDivertedInBackground pref to choose whether to open
|
||||
* in background tab or foreground tab.
|
||||
*/
|
||||
const short OPEN_NEWTAB = 3;
|
||||
/**
|
||||
|
|
@ -76,6 +78,11 @@ interface nsIBrowserDOMWindow : nsISupports
|
|||
* corresponding to this nsIBrowserDOMWindow.
|
||||
*/
|
||||
const short OPEN_NEWTAB_BACKGROUND = 5;
|
||||
/**
|
||||
* Open in a new foreground content tab in the toplevel browser window
|
||||
* corresponding to this nsIBrowserDOMWindow.
|
||||
*/
|
||||
const short OPEN_NEWTAB_FOREGROUND = 6;
|
||||
|
||||
/**
|
||||
* Values for createContentWindow's and openURI's aFlags parameter.
|
||||
|
|
|
|||
|
|
@ -5592,6 +5592,7 @@ mozilla::ipc::IPCResult ContentParent::CommonCreateWindow(
|
|||
|
||||
MOZ_ASSERT(aOpenLocation == nsIBrowserDOMWindow::OPEN_NEWTAB ||
|
||||
aOpenLocation == nsIBrowserDOMWindow::OPEN_NEWTAB_BACKGROUND ||
|
||||
aOpenLocation == nsIBrowserDOMWindow::OPEN_NEWTAB_FOREGROUND ||
|
||||
aOpenLocation == nsIBrowserDOMWindow::OPEN_NEWWINDOW ||
|
||||
aOpenLocation == nsIBrowserDOMWindow::OPEN_PRINT_BROWSER);
|
||||
|
||||
|
|
@ -5602,6 +5603,7 @@ mozilla::ipc::IPCResult ContentParent::CommonCreateWindow(
|
|||
|
||||
if (aOpenLocation == nsIBrowserDOMWindow::OPEN_NEWTAB ||
|
||||
aOpenLocation == nsIBrowserDOMWindow::OPEN_NEWTAB_BACKGROUND ||
|
||||
aOpenLocation == nsIBrowserDOMWindow::OPEN_NEWTAB_FOREGROUND ||
|
||||
aOpenLocation == nsIBrowserDOMWindow::OPEN_PRINT_BROWSER) {
|
||||
RefPtr<Element> openerElement = do_QueryObject(frame);
|
||||
|
||||
|
|
@ -5830,7 +5832,8 @@ mozilla::ipc::IPCResult ContentParent::RecvCreateWindow(
|
|||
// do this work.
|
||||
MOZ_ALWAYS_SUCCEEDS(newBC->SetHasSiblings(
|
||||
openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB ||
|
||||
openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB_BACKGROUND));
|
||||
openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB_BACKGROUND ||
|
||||
openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB_FOREGROUND));
|
||||
|
||||
newTab->SwapFrameScriptsFrom(cwi.frameScripts());
|
||||
newTab->MaybeShowFrame();
|
||||
|
|
|
|||
|
|
@ -652,7 +652,7 @@ public class GeckoSession {
|
|||
case 0: // OPEN_DEFAULTWINDOW
|
||||
case 1: // OPEN_CURRENTWINDOW
|
||||
return NavigationDelegate.TARGET_WINDOW_CURRENT;
|
||||
default: // OPEN_NEWWINDOW, OPEN_NEWTAB, OPEN_NEWTAB_BACKGROUND
|
||||
default: // OPEN_NEWWINDOW, OPEN_NEWTAB, OPEN_NEWTAB_BACKGROUND, OPEN_NEWTAB_FOREGROUND
|
||||
return NavigationDelegate.TARGET_WINDOW_NEW;
|
||||
}
|
||||
}
|
||||
|
|
@ -5030,7 +5030,7 @@ public class GeckoSession {
|
|||
case 0: // OPEN_DEFAULTWINDOW
|
||||
case 1: // OPEN_CURRENTWINDOW
|
||||
return TARGET_WINDOW_CURRENT;
|
||||
default: // OPEN_NEWWINDOW, OPEN_NEWTAB, OPEN_NEWTAB_BACKGROUND
|
||||
default: // OPEN_NEWWINDOW, OPEN_NEWTAB, OPEN_NEWTAB_BACKGROUND, OPEN_NEWTAB_FOREGROUND
|
||||
return TARGET_WINDOW_NEW;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -490,7 +490,8 @@ export class GeckoViewNavigation extends GeckoViewModule {
|
|||
if (
|
||||
where === Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW ||
|
||||
where === Ci.nsIBrowserDOMWindow.OPEN_NEWTAB ||
|
||||
where === Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_BACKGROUND
|
||||
where === Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_BACKGROUND ||
|
||||
where === Ci.nsIBrowserDOMWindow.OPEN_NEWTAB_FOREGROUND
|
||||
) {
|
||||
browser = this.handleNewSession(uri, openWindowInfo, where, flags, name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1657,8 +1657,9 @@ static int32_t GetWhereToOpen(nsIChannel* aChannel, bool aIsDocumentLoad) {
|
|||
where == nsIBrowserDOMWindow::OPEN_NEWTAB) {
|
||||
return where;
|
||||
}
|
||||
// NOTE: nsIBrowserDOMWindow::OPEN_NEWTAB_BACKGROUND is not allowed as a pref
|
||||
// value.
|
||||
// NOTE: nsIBrowserDOMWindow::OPEN_NEWTAB_BACKGROUND and
|
||||
// nsIBrowserDOMWindow::OPEN_NEWTAB_FOREGROUND are not allowed as pref
|
||||
// values.
|
||||
return nsIBrowserDOMWindow::OPEN_NEWTAB;
|
||||
}
|
||||
|
||||
|
|
@ -1751,6 +1752,7 @@ static RefPtr<dom::BrowsingContextCallbackReceivedPromise> SwitchToNewTab(
|
|||
CanonicalBrowsingContext* aLoadingBrowsingContext, int32_t aWhere) {
|
||||
MOZ_ASSERT(aWhere == nsIBrowserDOMWindow::OPEN_NEWTAB ||
|
||||
aWhere == nsIBrowserDOMWindow::OPEN_NEWTAB_BACKGROUND ||
|
||||
aWhere == nsIBrowserDOMWindow::OPEN_NEWTAB_FOREGROUND ||
|
||||
aWhere == nsIBrowserDOMWindow::OPEN_NEWWINDOW,
|
||||
"Unsupported open location");
|
||||
|
||||
|
|
|
|||
|
|
@ -544,6 +544,7 @@ nsContentTreeOwner::ProvideWindow(
|
|||
|
||||
if (openLocation != nsIBrowserDOMWindow::OPEN_NEWTAB &&
|
||||
openLocation != nsIBrowserDOMWindow::OPEN_NEWTAB_BACKGROUND &&
|
||||
openLocation != nsIBrowserDOMWindow::OPEN_NEWTAB_FOREGROUND &&
|
||||
openLocation != nsIBrowserDOMWindow::OPEN_CURRENTWINDOW &&
|
||||
openLocation != nsIBrowserDOMWindow::OPEN_PRINT_BROWSER) {
|
||||
// Just open a window normally
|
||||
|
|
|
|||
Loading…
Reference in a new issue