Bug 1638683 - When opening a PDF internally, the new tab should appear adjacent to the opening tab. r=Gijs
authorJared Wein <jwein@mozilla.com>
Wed, 20 May 2020 14:28:04 +0000
changeset 531249 ae4bb7a34b7e61c612afe22703363b0d17b821f3
parent 531248 2c5eea62791725beabc11d5fcfe17f0c5f515860
child 531250 bce461cdebb5b0676ef9df590bb6407aeae80c08
push id37436
push userncsoregi@mozilla.com
push dateWed, 20 May 2020 21:30:50 +0000
treeherdermozilla-central@6c10970490f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1638683
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1638683 - When opening a PDF internally, the new tab should appear adjacent to the opening tab. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D75818
browser/base/content/utilityOverlay.js
toolkit/components/downloads/DownloadIntegration.jsm
uriloader/exthandler/tests/mochitest/browser_download_open_with_internal_handler.js
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -663,16 +663,17 @@ function openLinkIn(url, where, params) 
         allowMixedContent: aAllowMixedContent,
         userContextId: aUserContextId,
         originPrincipal: aPrincipal,
         originStoragePrincipal: aStoragePrincipal,
         triggeringPrincipal: aTriggeringPrincipal,
         allowInheritPrincipal: aAllowInheritPrincipal,
         csp: aCsp,
         focusUrlBar,
+        openerBrowser: params.openerBrowser,
       });
       targetBrowser = tabUsedForLoad.linkedBrowser;
 
       if (aResolveOnNewTabCreated) {
         aResolveOnNewTabCreated(targetBrowser);
       }
 
       if (params.frameOuterWindowID != undefined && w) {
--- a/toolkit/components/downloads/DownloadIntegration.jsm
+++ b/toolkit/components/downloads/DownloadIntegration.jsm
@@ -798,16 +798,17 @@ var DownloadIntegration = {
       );
       let fileURI = Services.io.newFileURI(file);
       if (win) {
         // TODO: Replace openTrustedLinkIn with openUILink once
         //       we have access to the event.
         win.openTrustedLinkIn(fileURI.spec, "tab", {
           triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
           userContextId: aDownload.source.userContextId,
+          openerBrowser: browsingContext?.top?.embedderElement,
         });
         return;
       }
       let features = "chrome,dialog=no,all";
       if (aDownload.source.isPrivate) {
         features += ",private";
       }
       let args = Cc["@mozilla.org/supports-string;1"].createInstance(
--- a/uriloader/exthandler/tests/mochitest/browser_download_open_with_internal_handler.js
+++ b/uriloader/exthandler/tests/mochitest/browser_download_open_with_internal_handler.js
@@ -51,16 +51,20 @@ add_task(async function test_check_open_
   registerCleanupFunction(async () => {
     await publicList.removeFinished();
   });
   let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
   let loadingTab = await BrowserTestUtils.openNewForegroundTab(
     gBrowser,
     TEST_PATH + "file_pdfjs_test.pdf"
   );
+  // Add an extra tab after the loading tab so we can test that
+  // pdf.js is opened in the adjacent tab and not at the end of
+  // the tab strip.
+  let extraTab = await BrowserTestUtils.addTab(gBrowser, "about:blank");
   let dialogWindow = await dialogWindowPromise;
   is(
     dialogWindow.location,
     "chrome://mozapps/content/downloads/unknownContentType.xhtml",
     "Should have seen the unknown content dialogWindow."
   );
   let doc = dialogWindow.document;
   let internalHandlerRadio = doc.querySelector("#handleInternally");
@@ -73,16 +77,22 @@ add_task(async function test_check_open_
   let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
   let dialog = doc.querySelector("#unknownContentType");
   let button = dialog.getButton("accept");
   button.disabled = false;
   dialog.acceptDialog();
   info("waiting for new tab to open");
   let newTab = await newTabPromise;
 
+  is(
+    newTab._tPos - 1,
+    loadingTab._tPos,
+    "pdf.js should be opened in an adjacent tab"
+  );
+
   await ContentTask.spawn(newTab.linkedBrowser, null, async () => {
     await ContentTaskUtils.waitForCondition(
       () => content.document.readyState == "complete"
     );
   });
 
   let publicDownloads = await publicList.getAll();
   Assert.equal(
@@ -113,16 +123,17 @@ add_task(async function test_check_open_
     subInternalHandlerRadio.hidden,
     "The option should be hidden when the dialog is opened from pdf.js"
   );
 
   subDoc.querySelector("#unknownContentType").cancelDialog();
 
   BrowserTestUtils.removeTab(loadingTab);
   BrowserTestUtils.removeTab(newTab);
+  BrowserTestUtils.removeTab(extraTab);
 });
 
 /**
  * Check that the "Open with internal handler" option is not presented
  * for non-PDF types.
  */
 add_task(async function test_internal_handler_hidden_with_nonpdf_type() {
   let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded();