Bug 1394473 - Fix up target=_blank links in RDM. r=ochameau, a=lizzard DEVEDITION_56_0b8_RELEASE FIREFOX_56_0b8_BUILD1 FIREFOX_56_0b8_RELEASE
authorJ. Ryan Stinnett <jryans@gmail.com>
Mon, 28 Aug 2017 18:25:16 -0500
changeset 423900 dcb3e24852c4b3ddc900d5e2430853cb9a51cdc4
parent 423899 76813e4100eaa0e97f167a0a409ebfc59ccb97a1
child 423901 1ffd33f6b648abed6b9ec41e556dfd329ce08457
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau, lizzard
bugs1394473
milestone56.0
Bug 1394473 - Fix up target=_blank links in RDM. r=ochameau, a=lizzard Sometime during Firefox 56, the `dataTransfer` property was removed, so this started to fail. It was a bit strange anyway, since we have a principal on the outer browser. Adds a test to cover this use case. MozReview-Commit-ID: 9UOCc77ZRxk
devtools/client/responsive.html/browser/tunnel.js
devtools/client/responsive.html/test/browser/browser.ini
devtools/client/responsive.html/test/browser/browser_target_blank.js
--- a/devtools/client/responsive.html/browser/tunnel.js
+++ b/devtools/client/responsive.html/browser/tunnel.js
@@ -236,28 +236,24 @@ function tunnelToInnerBrowser(outer, inn
       //   * Specific target names (everything treated as _blank)
       //   * Window features
       //   * window.opener
       // These things are deferred for now, since content which does depend on them seems
       // outside the main focus of RDM.
       let { detail } = event;
       event.preventDefault();
       let uri = Services.io.newURI(detail.url);
-      let sourceNode = event.dataTransfer.mozSourceNode;
-      let triggeringPrincipal = sourceNode
-        ? sourceNode.nodePrincipal
-        : Services.scriptSecurityManager.getSystemPrincipal();
       // This API is used mainly because it's near the path used for <a target/> with
       // regular browser tabs (which calls `openURIInFrame`).  The more elaborate APIs
       // that support openers, window features, etc. didn't seem callable from JS and / or
       // this event doesn't give enough info to use them.
       browserWindow.browserDOMWindow
         .openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
                  Ci.nsIBrowserDOMWindow.OPEN_NEW,
-                 triggeringPrincipal);
+                 outer.contentPrincipal);
     },
 
     stop() {
       let tab = gBrowser.getTabForBrowser(outer);
       let filteredProgressListener = gBrowser._tabFilters.get(tab);
 
       // The browser's state has changed over time while the tunnel was active.  Push the
       // the current state down to the inner browser, so that it follows the content in
--- a/devtools/client/responsive.html/test/browser/browser.ini
+++ b/devtools/client/responsive.html/test/browser/browser.ini
@@ -33,15 +33,16 @@ support-files =
 [browser_network_throttling.js]
 [browser_page_state.js]
 [browser_permission_doorhanger.js]
 tags = geolocation
 [browser_resize_cmd.js]
 [browser_screenshot_button.js]
 [browser_tab_close.js]
 [browser_tab_remoteness_change.js]
+[browser_target_blank.js]
 [browser_toolbox_computed_view.js]
 [browser_toolbox_rule_view.js]
 [browser_toolbox_swap_browsers.js]
 [browser_touch_device.js]
 [browser_touch_simulation.js]
 [browser_viewport_basics.js]
 [browser_window_close.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/responsive.html/test/browser/browser_target_blank.js
@@ -0,0 +1,26 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Ensure target="_blank" link opens a new tab
+
+const TAB_URL = "http://example.com/";
+const TEST_URL =
+  `data:text/html,<a href="${TAB_URL}" target="_blank">Click me</a>`
+  .replace(/ /g, "%20");
+
+addRDMTask(TEST_URL, function* ({ ui }) {
+  let store = ui.toolWindow.store;
+
+  // Wait until the viewport has been added
+  yield waitUntilState(store, state => state.viewports.length == 1);
+
+  // Click the target="_blank" link and wait for a new tab
+  yield waitForFrameLoad(ui, TEST_URL);
+  let newTab = BrowserTestUtils.waitForNewTab(gBrowser, TAB_URL);
+  spawnViewportTask(ui, {}, function* () {
+    content.document.querySelector("a").click(); // eslint-disable-line
+  });
+  ok(yield newTab, "New tab opened from link");
+});