Bug 1364392 - Provide correct triggeringPrincipal to openLinkIn r=Gijs
authorJonathan Kingston <jkt@mozilla.com>
Tue, 21 Aug 2018 14:15:40 +0000
changeset 487757 486f7f825c6bfb4b31cb76c49174f2880dd8af19
parent 487756 3d50f935615c9ba9179e8ab0dbb244ca65626967
child 487758 6577561a493b00dec6b3f4455674e410dddf936d
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1364392
milestone63.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 1364392 - Provide correct triggeringPrincipal to openLinkIn r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D3873
browser/base/content/nsContextMenu.js
browser/base/content/utilityOverlay.js
browser/components/newtab/lib/ASRouter.jsm
browser/components/uitour/UITour.jsm
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -842,16 +842,17 @@ nsContextMenu.prototype = {
                                                  null, { target: this.target, forceReload });
   },
 
   // Open clicked-in frame in its own window.
   openFrame() {
     let referrer = gContextMenuContentData.referrer;
     openLinkIn(gContextMenuContentData.docLocation, "window",
                { charset: gContextMenuContentData.charSet,
+                 triggeringPrincipal: this.browser.contentPrincipal,
                  referrerURI: referrer ? makeURI(referrer) : null });
   },
 
   // Open clicked-in frame in the same window.
   showOnlyThisFrame() {
     urlSecurityCheck(gContextMenuContentData.docLocation,
                      this.browser.contentPrincipal,
                      Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -295,16 +295,20 @@ function openLinkIn(url, where, params) 
   var aUserContextId        = params.userContextId;
   var aIndicateErrorPageLoad = params.indicateErrorPageLoad;
   var aPrincipal            = params.originPrincipal;
   var aTriggeringPrincipal  = params.triggeringPrincipal;
   var aForceAboutBlankViewerInCurrent =
       params.forceAboutBlankViewerInCurrent;
   var aResolveOnNewTabCreated = params.resolveOnNewTabCreated;
 
+  if (!aTriggeringPrincipal) {
+    throw new Error("Must load with a triggering Principal");
+  }
+
   if (where == "save") {
     // TODO(1073187): propagate referrerPolicy.
 
     // ContentClick.jsm passes isContentWindowPrivate for saveURL instead of passing a CPOW initiatingDoc
     if ("isContentWindowPrivate" in params) {
       saveURL(url, null, null, true, true, aNoReferrer ? null : aReferrerURI,
               null, params.isContentWindowPrivate, aPrincipal);
     } else {
--- a/browser/components/newtab/lib/ASRouter.jsm
+++ b/browser/components/newtab/lib/ASRouter.jsm
@@ -597,20 +597,29 @@ class _ASRouter {
 
   async handleUserAction({data: action, target}) {
     switch (action.type) {
       case ra.OPEN_PRIVATE_BROWSER_WINDOW:
         // Forcefully open about:privatebrowsing
         target.browser.ownerGlobal.OpenBrowserWindow({private: true});
         break;
       case ra.OPEN_URL:
-        this.openLinkIn(action.data.url, target, {isPrivate: false, where: "tabshifted"});
+        this.openLinkIn(action.data.url, target, {
+          isPrivate: false,
+          where: "tabshifted",
+          triggeringPrincipal: Services.scriptSecurityManager.getNullPrincipal({})
+        });
         break;
       case ra.OPEN_ABOUT_PAGE:
-        this.openLinkIn(`about:${action.data.page}`, target, {isPrivate: false, trusted: true, where: "tab"});
+        this.openLinkIn(`about:${action.data.page}`, target, {
+          isPrivate: false,
+          trusted: true,
+          where: "tab",
+          triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
+        });
         break;
       case ra.OPEN_APPLICATIONS_MENU:
         UITour.showMenu(target.browser.ownerGlobal, action.data.target);
         break;
       case ra.INSTALL_ADDON_FROM_URL:
         await MessageLoaderUtils.installAddonFromURL(target.browser, action.data.url);
         break;
     }
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -1359,17 +1359,21 @@ var UITour = {
     } else if (aMenuName == "urlbar") {
       aWindow.gURLBar.closePopup();
     } else if (aMenuName == "pageActionPanel") {
       aWindow.BrowserPageActions.panelNode.hidePopup();
     }
   },
 
   showNewTab(aWindow, aBrowser) {
-    aWindow.openLinkIn("about:newtab", "current", {targetBrowser: aBrowser});
+    let url = "about:newtab";
+    aWindow.openLinkIn(url, "current", {
+      targetBrowser: aBrowser,
+      triggeringPrincipal: Services.scriptSecurityManager.createCodebasePrincipal(Services.io.newURI(url), {}),
+    });
     aWindow.gURLBar.focus();
   },
 
   _hideAnnotationsForPanel(aEvent, aShouldClosePanel, aTargetPositionCallback) {
     let win = aEvent.target.ownerGlobal;
     let hideHighlightMethod = null;
     let hideInfoMethod = null;
     if (aShouldClosePanel) {