From f3ebe7806190afa1745595da084b523db89f37c3 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Sat, 5 Nov 2016 13:56:08 +0000 Subject: [PATCH] Bug 1313403 - text (focus) goes to the wrong browser after foreground tab change, r=florian,mak MozReview-Commit-ID: BxqYL1p494h --HG-- extra : rebase_source : 1b1c1a9554dea796ec7c1f6420e11a6bdde28760 --- browser/base/content/utilityOverlay.js | 15 +++++++++++---- .../search/test/browser_oneOffContextMenu.js | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/browser/base/content/utilityOverlay.js b/browser/base/content/utilityOverlay.js index e0793aa67b0d..9e33dad611d0 100644 --- a/browser/base/content/utilityOverlay.js +++ b/browser/base/content/utilityOverlay.js @@ -324,11 +324,11 @@ function openLinkIn(url, where, params) { } catch (e) {} } - // NB: we avoid using |w| here because in the 'popup window' case, + // We avoid using |w| here because in the 'popup window' case, // if we pass a currentBrowser param |w.gBrowser| might not be the // tabbrowser that contains |aCurrentBrowser|. We really only care // about the tab linked to |aCurrentBrowser|. - let tab = aCurrentBrowser.ownerGlobal.gBrowser.getTabForBrowser(aCurrentBrowser); + let tab = aCurrentBrowser.getTabBrowser().getTabForBrowser(aCurrentBrowser); if (where == "current" && tab.pinned && !aAllowPinnedTabHostChange) { try { @@ -348,6 +348,7 @@ function openLinkIn(url, where, params) { // result in a new frontmost window (e.g. "javascript:window.open('');"). w.focus(); + let browserUsedForLoad = null; switch (where) { case "current": let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE; @@ -383,12 +384,13 @@ function openLinkIn(url, where, params) { postData: aPostData, userContextId: aUserContextId }); + browserUsedForLoad = aCurrentBrowser; break; case "tabshifted": loadInBackground = !loadInBackground; // fall through case "tab": - w.gBrowser.loadOneTab(url, { + let tabUsedForLoad = w.gBrowser.loadOneTab(url, { referrerURI: aReferrerURI, referrerPolicy: aReferrerPolicy, charset: aCharset, @@ -402,10 +404,15 @@ function openLinkIn(url, where, params) { userContextId: aUserContextId, originPrincipal: aPrincipal, }); + browserUsedForLoad = tabUsedForLoad.linkedBrowser; break; } - aCurrentBrowser.focus(); + // Focus the content, but only if the browser used for the load is selected. + if (browserUsedForLoad && + browserUsedForLoad == browserUsedForLoad.getTabBrowser().selectedBrowser) { + browserUsedForLoad.focus(); + } if (!loadInBackground && w.isBlankPageURL(url)) { w.focusAndSelectUrlBar(); diff --git a/browser/components/search/test/browser_oneOffContextMenu.js b/browser/components/search/test/browser_oneOffContextMenu.js index eacab116cfc1..69207923bb4d 100644 --- a/browser/components/search/test/browser_oneOffContextMenu.js +++ b/browser/components/search/test/browser_oneOffContextMenu.js @@ -70,6 +70,12 @@ function* doTest() { EventUtils.synthesizeMouseAtCenter(searchInNewTabMenuItem, {}); let tab = yield promise; + // By default the search will open in the background and the popup will stay open: + promise = promiseEvent(searchPopup, "popuphidden"); + info("Closing search panel"); + EventUtils.synthesizeKey("VK_ESCAPE", {}); + yield promise; + // Check the loaded tab. Assert.equal(tab.linkedBrowser.currentURI.spec, "http://mochi.test:8888/browser/browser/components/search/test/",