Bug 1374741 - Within devtools/ make openUILinkIn() provide the correct triggeringPrincipal. r?jryans draft
authorJonathan Kingston <jkt@mozilla.com>
Wed, 21 Feb 2018 16:01:03 +0000
changeset 779507 893d6f5e01652cefdecd07dc0f5aa5cbb68e81c5
parent 779221 04af342abe042e18c8115c6f3b22010ad51a7eff
child 779508 bc5dc3794db72456af7ccfad5d750f0afadc417b
push id105784
push userbmo:jkt@mozilla.com
push dateTue, 10 Apr 2018 00:20:01 +0000
reviewersjryans
bugs1374741
milestone61.0a1
Bug 1374741 - Within devtools/ make openUILinkIn() provide the correct triggeringPrincipal. r?jryans MozReview-Commit-ID: KecQcZWeU6a
devtools/client/debugger/content/views/sources-view.js
devtools/client/debugger/new/panel.js
devtools/client/dom/dom-panel.js
devtools/client/inspector/computed/computed.js
devtools/client/inspector/inspector.js
devtools/client/inspector/rules/views/text-property-editor.js
devtools/client/menus.js
devtools/client/netmonitor/initializer.js
devtools/client/netmonitor/src/components/MdnLink.js
devtools/client/netmonitor/src/utils/open-request-in-tab.js
devtools/client/scratchpad/scratchpad.js
devtools/client/shared/AppCacheUtils.jsm
devtools/client/styleeditor/StyleEditorUI.jsm
devtools/client/styleeditor/test/browser_styleeditor_opentab.js
devtools/client/webconsole/hudservice.js
devtools/client/webconsole/new-console-output/utils/context-menu.js
devtools/client/webide/content/webide.js
devtools/shared/gcli/commands/screenshot.js
toolkit/content/contentAreaUtils.js
--- a/devtools/client/debugger/content/views/sources-view.js
+++ b/devtools/client/debugger/content/views/sources-view.js
@@ -895,17 +895,20 @@ SourcesView.prototype = extend(WidgetMet
   },
 
   /**
    * Opens selected item source in a new tab.
    */
   _onNewTabCommand: function () {
     let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
     let selected = this.selectedItem.attachment;
-    win.openUILinkIn(selected.source.url, "tab", { relatedToCurrent: true });
+    win.openWebLinkIn(selected.source.url, "tab", {
+      triggeringPrincipal: win.document.nodePrincipal,
+      relatedToCurrent: true,
+    });
   },
 
   /**
    * Function called each time a breakpoint item is removed.
    *
    * @param object aItem
    *        The corresponding item.
    */
--- a/devtools/client/debugger/new/panel.js
+++ b/devtools/client/debugger/new/panel.js
@@ -69,21 +69,23 @@ DebuggerPanel.prototype = {
     }
 
     const win = parentDoc.querySelector("window");
     if (!win) {
       return;
     }
 
     const top = win.ownerDocument.defaultView.top;
-    if (!top || typeof top.openUILinkIn !== "function") {
+    if (!top || typeof top.openWebLink !== "function") {
       return;
     }
 
-    top.openUILinkIn(url, "tab");
+    top.openWebLinkIn(url, "tab", {
+      triggeringPrincipal: win.document.nodePrincipal
+    });
   },
 
   openWorkerToolbox: function(worker) {
     this.toolbox.target.client.attachWorker(
       worker.actor,
       (response, workerClient) => {
         const workerTarget = TargetFactory.forWorker(workerClient);
         gDevTools
--- a/devtools/client/dom/dom-panel.js
+++ b/devtools/client/dom/dom-panel.js
@@ -177,17 +177,17 @@ DomPanel.prototype = {
 
     return deferred.promise;
   },
 
   openLink: function(url) {
     let parentDoc = this._toolbox.doc;
     let iframe = parentDoc.getElementById("this._toolbox");
     let top = iframe.ownerDocument.defaultView.top;
-    top.openUILinkIn(url, "tab");
+    top.openWebLinkIn(url, "tab");
   },
 
   getRootGrip: function() {
     let deferred = defer();
 
     // Attach Console. It might involve RDP communication, so wait
     // asynchronously for the result
     this.target.activeConsole.evaluateJSAsync("window", res => {
--- a/devtools/client/inspector/computed/computed.js
+++ b/devtools/client/inspector/computed/computed.js
@@ -677,17 +677,17 @@ CssComputedView.prototype = {
 
   _onClick: function(event) {
     let target = event.target;
 
     if (target.nodeName === "a") {
       event.stopPropagation();
       event.preventDefault();
       let browserWin = this.inspector.target.tab.ownerDocument.defaultView;
-      browserWin.openUILinkIn(target.href, "tab");
+      browserWin.openWebLinkIn(target.href, "tab");
     }
   },
 
   /**
    * Callback for copy event. Copy selected text.
    *
    * @param {Event} event
    *        copy event object.
@@ -1162,17 +1162,17 @@ PropertyView.prototype = {
   /**
    * The action when a user clicks on the MDN help link for a property.
    */
   mdnLinkClick: function(event) {
     let inspector = this.tree.inspector;
 
     if (inspector.target.tab) {
       let browserWin = inspector.target.tab.ownerDocument.defaultView;
-      browserWin.openUILinkIn(this.link, "tab");
+      browserWin.openWebLinkIn(this.link, "tab");
     }
   },
 
   /**
    * Destroy this property view, removing event listeners
    */
   destroy: function() {
     if (this._matchedSelectorViews) {
--- a/devtools/client/inspector/inspector.js
+++ b/devtools/client/inspector/inspector.js
@@ -2286,17 +2286,17 @@ Inspector.prototype = {
     }
 
     if (type === "uri" || type === "cssresource" || type === "jsresource") {
       // Open link in a new tab.
       this.inspector.resolveRelativeURL(
         link, this.selection.nodeFront).then(url => {
           if (type === "uri") {
             let browserWin = this.target.tab.ownerDocument.defaultView;
-            browserWin.openUILinkIn(url, "tab");
+            browserWin.openWebLinkIn(url, "tab");
           } else if (type === "cssresource") {
             return this.toolbox.viewSourceInStyleEditor(url);
           } else if (type === "jsresource") {
             return this.toolbox.viewSourceInDebugger(url);
           }
           return null;
         }).catch(console.error);
     } else if (type == "idref") {
--- a/devtools/client/inspector/rules/views/text-property-editor.js
+++ b/devtools/client/inspector/rules/views/text-property-editor.js
@@ -294,17 +294,17 @@ TextPropertyEditor.prototype = {
 
       this.valueSpan.addEventListener("click", (event) => {
         let target = event.target;
 
         if (target.nodeName === "a") {
           event.stopPropagation();
           event.preventDefault();
           let browserWin = this.ruleView.inspector.target.tab.ownerDocument.defaultView;
-          browserWin.openUILinkIn(target.href, "tab");
+          browserWin.openTrustedLinkIn(target.href, "tab");
         }
       });
 
       editableField({
         start: this._onStartEditing,
         element: this.valueSpan,
         done: this._onValueDone,
         destroy: this.update,
--- a/devtools/client/menus.js
+++ b/devtools/client/menus.js
@@ -143,12 +143,12 @@ exports.menuitems = [
   },
   { separator: true,
     id: "devToolsEndSeparator"
   },
   { id: "getMoreDevtools",
     l10nKey: "getMoreDevtoolsCmd",
     oncommand(event) {
       let window = event.target.ownerDocument.defaultView;
-      window.openUILinkIn("https://addons.mozilla.org/firefox/collections/mozilla/webdeveloper/", "tab");
+      window.openTrustedLinkIn("https://addons.mozilla.org/firefox/collections/mozilla/webdeveloper/", "tab");
     }
   },
 ];
--- a/devtools/client/netmonitor/initializer.js
+++ b/devtools/client/netmonitor/initializer.js
@@ -60,17 +60,17 @@ window.Netmonitor = {
       toolbox,
       panel,
     };
 
     const openLink = (link) => {
       let parentDoc = toolbox.doc;
       let iframe = parentDoc.getElementById("toolbox-panel-iframe-netmonitor");
       let top = iframe.ownerDocument.defaultView.top;
-      top.openUILinkIn(link, "tab");
+      top.openWebLinkIn(link, "tab");
     };
 
     const openSplitConsole = (err) => {
       toolbox.openSplitConsole().then(() => {
         toolbox.target.logErrorInPage(err, "har");
       });
     };
 
--- a/devtools/client/netmonitor/src/components/MdnLink.js
+++ b/devtools/client/netmonitor/src/components/MdnLink.js
@@ -32,16 +32,16 @@ MDNLink.propTypes = {
 
 function onLearnMoreClick(e, url) {
   e.stopPropagation();
   e.preventDefault();
 
   let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
   let { button, ctrlKey, metaKey } = e;
   let isOSX = Services.appinfo.OS == "Darwin";
+  let where = "tab";
   if (button === 1 || (button === 0 && (isOSX ? metaKey : ctrlKey))) {
-    win.openUILinkIn(url, "tabshifted");
-  } else {
-    win.openUILinkIn(url, "tab");
+    where = "tabshifted";
   }
+  win.openWebLinkIn(url, where, {triggeringPrincipal: win.document.nodePrincipal});
 }
 
 module.exports = MDNLink;
--- a/devtools/client/netmonitor/src/utils/open-request-in-tab.js
+++ b/devtools/client/netmonitor/src/utils/open-request-in-tab.js
@@ -8,17 +8,17 @@ const Services = require("Services");
 const { gDevTools } = require("devtools/client/framework/devtools");
 
 /**
  * Opens given request in a new tab.
  */
 function openRequestInTab(url, requestPostData) {
   let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
   if (!requestPostData) {
-    win.openUILinkIn(url, "tab", {relatedToCurrent: true});
+    win.openWebLinkIn(url, "tab", {relatedToCurrent: true});
   } else {
     openPostRequestInTabHelper({
       url,
       data: requestPostData.postData
     });
   }
 }
 
--- a/devtools/client/scratchpad/scratchpad.js
+++ b/devtools/client/scratchpad/scratchpad.js
@@ -1977,17 +1977,17 @@ var Scratchpad = {
     }
   },
 
   /**
    * Opens the MDN documentation page for Scratchpad.
    */
   openDocumentationPage: function SP_openDocumentationPage() {
     let url = this.strings.GetStringFromName("help.openDocumentationPage");
-    this.browserWindow.openUILinkIn(url, "tab");
+    this.browserWindow.openTrustedLinkIn(url, "tab");
     this.browserWindow.focus();
   },
 };
 
 /**
  * Represents the DebuggerClient connection to a specific tab as used by the
  * Scratchpad.
  *
--- a/devtools/client/shared/AppCacheUtils.jsm
+++ b/devtools/client/shared/AppCacheUtils.jsm
@@ -287,17 +287,17 @@ AppCacheUtils.prototype = {
     return entries;
   },
 
   viewEntry: function ACU_viewEntry(key) {
     let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
                .getService(Ci.nsIWindowMediator);
     let win = wm.getMostRecentWindow(gDevTools.chromeWindowType);
     let url = "about:cache-entry?storage=appcache&context=&eid=&uri=" + key;
-    win.openUILinkIn(url, "tab");
+    win.openTrustedLinkIn(url, "tab");
   },
 
   clearAll: function ACU_clearAll() {
     if (!Services.prefs.getBoolPref("browser.cache.disk.enable")) {
       throw new Error(l10n.GetStringFromName("cacheDisabled"));
     }
 
     let appCacheStorage = Services.cache2.appCacheStorage(Services.loadContextInfo.default, null);
--- a/devtools/client/styleeditor/StyleEditorUI.jsm
+++ b/devtools/client/styleeditor/StyleEditorUI.jsm
@@ -483,17 +483,17 @@ StyleEditorUI.prototype = {
     }
   },
 
   /**
    * Open a particular stylesheet in a new tab.
    */
   _openLinkNewTab: function() {
     if (this._contextMenuStyleSheet) {
-      this._window.openUILinkIn(this._contextMenuStyleSheet.href, "tab");
+      this._window.openWebLinkIn(this._contextMenuStyleSheet.href, "tab");
     }
   },
 
   /**
    * Remove a particular stylesheet editor from the UI
    *
    * @param {StyleSheetEditor}  editor
    *        The editor to remove.
--- a/devtools/client/styleeditor/test/browser_styleeditor_opentab.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_opentab.js
@@ -16,21 +16,21 @@ add_task(async function() {
     "The menu item is not disabled");
   is(ui._openLinkNewTabItem.getAttribute("hidden"), "false",
     "The menu item is not hidden");
 
   let url = "https://example.com/browser/devtools/client/styleeditor/test/" +
     "simple.css";
   is(ui._contextMenuStyleSheet.href, url, "Correct URL for sheet");
 
-  let originalOpenUILinkIn = ui._window.openUILinkIn;
+  let originalOpenWebLinkIn = ui._window.openWebLinkIn;
   let tabOpenedDefer = new Promise(resolve => {
-    ui._window.openUILinkIn = newUrl => {
-      // Reset the actual openUILinkIn function before proceeding.
-      ui._window.openUILinkIn = originalOpenUILinkIn;
+    ui._window.openWebLinkIn = newUrl => {
+      // Reset the actual openWebLinkIn function before proceeding.
+      ui._window.openWebLinkIn = originalOpenWebLinkIn;
 
       is(newUrl, url, "The correct tab has been opened");
       resolve();
     };
   });
 
   ui._openLinkNewTabItem.click();
 
--- a/devtools/client/webconsole/hudservice.js
+++ b/devtools/client/webconsole/hudservice.js
@@ -376,21 +376,21 @@ WebConsole.prototype = {
   /**
    * Open a link in a new tab.
    *
    * @param string link
    *        The URL you want to open in a new tab.
    */
   openLink(link, e) {
     let isOSX = Services.appinfo.OS == "Darwin";
+    let where = "tab";
     if (e && (e.button === 1 || (e.button === 0 && (isOSX ? e.metaKey : e.ctrlKey)))) {
-      this.chromeUtilsWindow.openUILinkIn(link, "tabshifted");
-    } else {
-      this.chromeUtilsWindow.openUILinkIn(link, "tab");
+      where = "tabshifted";
     }
+    this.chromeUtilsWindow.openWebLinkIn(link, where);
   },
 
   /**
    * Open a link in Firefox's view source.
    *
    * @param string sourceURL
    *        The URL of the file.
    * @param integer sourceLine
--- a/devtools/client/webconsole/new-console-output/utils/context-menu.js
+++ b/devtools/client/webconsole/new-console-output/utils/context-menu.js
@@ -85,17 +85,19 @@ function createContextMenu(jsterm, paren
     label: l10n.getStr("webconsole.menu.openURL.label"),
     accesskey: l10n.getStr("webconsole.menu.openURL.accesskey"),
     visible: source === MESSAGE_SOURCE.NETWORK,
     click: () => {
       if (!request) {
         return;
       }
       let mainWindow = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
-      mainWindow.openUILinkIn(request.url, "tab");
+      mainWindow.openWebLinkIn(request.url, "tab", {
+        triggeringPrincipal: mainWindow.document.nodePrincipal,
+      });
     },
   }));
 
   // Store as global variable.
   menu.append(new MenuItem({
     id: "console-menu-store",
     label: l10n.getStr("webconsole.menu.storeAsGlobalVar.label"),
     accesskey: l10n.getStr("webconsole.menu.storeAsGlobalVar.accesskey"),
--- a/devtools/client/webide/content/webide.js
+++ b/devtools/client/webide/content/webide.js
@@ -177,17 +177,17 @@ var UI = {
     }
     this._updatePromise = promise.resolve();
   },
 
   openInBrowser: function (url) {
     // Open a URL in a Firefox window
     let mainWindow = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
     if (mainWindow) {
-      mainWindow.openUILinkIn(url, "tab");
+      mainWindow.openWebLinkIn(url, "tab");
       mainWindow.focus()
     } else {
       window.open(url);
     }
   },
 
   updateTitle: function () {
     let project = AppManager.selectedProject;
--- a/devtools/shared/gcli/commands/screenshot.js
+++ b/devtools/shared/gcli/commands/screenshot.js
@@ -155,17 +155,19 @@ exports.items = [
       }
 
       // Click handler
       if (imageSummary.href || imageSummary.filename) {
         root.style.cursor = "pointer";
         root.addEventListener("click", () => {
           if (imageSummary.href) {
             let mainWindow = context.environment.chromeWindow;
-            mainWindow.openUILinkIn(imageSummary.href, "tab");
+            mainWindow.openWebLinkIn(imageSummary.href, "tab", {
+              triggeringPrincipal: document.nodePrincipal,
+            });
           } else if (imageSummary.filename) {
             const file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
             file.initWithPath(imageSummary.filename);
             file.reveal();
           }
         });
       }
 
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -1175,17 +1175,19 @@ function openURL(aURL) {
                       .getService(Ci.nsIExternalProtocolService);
 
   if (!protocolSvc.isExposedProtocol(uri.scheme)) {
     // If we're not a browser, use the external protocol service to load the URI.
     protocolSvc.loadURI(uri);
   } else {
     var recentWindow = Services.wm.getMostRecentWindow("navigator:browser");
     if (recentWindow) {
-      recentWindow.openUILinkIn(uri.spec, "tab");
+      recentWindow.openWebLinkIn(uri.spec, "tab", {
+        triggeringPrincipal: recentWindow.document.contentPrincipal
+      });
       return;
     }
 
     var loadgroup = Cc["@mozilla.org/network/load-group;1"]
                       .createInstance(Ci.nsILoadGroup);
     var appstartup = Services.startup;
 
     var loadListener = {