Backed out changeset 5d0df5f74170 (bug 1497301) for failing at caps/tests/ and js/xpconnect/tests on a CLOSED TREE
authorGurzau Raul <rgurzau@mozilla.com>
Fri, 12 Oct 2018 19:28:29 +0300
changeset 496731 9268ec81fb01ae1fd1162fc6866ef8f74cd3ea09
parent 496730 78a9a2adf32a8798aea8c6c5347d2d4957fc939e
child 496732 efd0c87b160b7b2549890fe3d0b30a63fc2c6bc8
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1497301
milestone64.0a1
backs out5d0df5f741700ae8e74d894ae95ae590b239e0ec
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
Backed out changeset 5d0df5f74170 (bug 1497301) for failing at caps/tests/ and js/xpconnect/tests on a CLOSED TREE
dom/base/Location.cpp
dom/base/Location.h
dom/webidl/Location.webidl
--- a/dom/base/Location.cpp
+++ b/dom/base/Location.cpp
@@ -57,90 +57,101 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Location, mInnerWindow)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(Location)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(Location)
 
 nsresult
-Location::CheckURL(nsIURI* aURI, nsIPrincipal& aSubjectPrincipal, nsDocShellLoadInfo** aLoadInfo)
+Location::CheckURL(nsIURI* aURI, nsDocShellLoadInfo** aLoadInfo)
 {
   *aLoadInfo = nullptr;
 
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
   NS_ENSURE_TRUE(docShell, NS_ERROR_NOT_AVAILABLE);
 
   nsCOMPtr<nsIPrincipal> triggeringPrincipal;
   nsCOMPtr<nsIURI> sourceURI;
   net::ReferrerPolicy referrerPolicy = net::RP_Unset;
 
-  // Get security manager.
-  nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
-  NS_ENSURE_STATE(ssm);
-
-  // Check to see if URI is allowed.
-  nsresult rv = ssm->CheckLoadURIWithPrincipal(&aSubjectPrincipal, aURI,
-                                               nsIScriptSecurityManager::STANDARD);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (JSContext *cx = nsContentUtils::GetCurrentJSContext()) {
+    // No cx means that there's no JS running, or at least no JS that
+    // was run through code that properly pushed a context onto the
+    // context stack (as all code that runs JS off of web pages
+    // does). We won't bother with security checks in this case, but
+    // we need to create the loadinfo etc.
 
-  // Make the load's referrer reflect changes to the document's URI caused by
-  // push/replaceState, if possible.  First, get the document corresponding to
-  // fp.  If the document's original URI (i.e. its URI before
-  // push/replaceState) matches the principal's URI, use the document's
-  // current URI as the referrer.  If they don't match, use the principal's
-  // URI.
-  //
-  // The triggering principal for this load should be the principal of the
-  // incumbent document (which matches where the referrer information is
-  // coming from) when there is an incumbent document, and the subject
-  // principal otherwise.  Note that the URI in the triggering principal
-  // may not match the referrer URI in various cases, notably including
-  // the cases when the incumbent document's document URI was modified
-  // after the document was loaded.
+    // Get security manager.
+    nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
+    NS_ENSURE_STATE(ssm);
 
-  nsCOMPtr<nsPIDOMWindowInner> incumbent =
-    do_QueryInterface(mozilla::dom::GetIncumbentGlobal());
-  nsCOMPtr<nsIDocument> doc = incumbent ? incumbent->GetDoc() : nullptr;
-
-  if (doc) {
-    nsCOMPtr<nsIURI> docOriginalURI, docCurrentURI, principalURI;
-    docOriginalURI = doc->GetOriginalURI();
-    docCurrentURI = doc->GetDocumentURI();
-    rv = doc->NodePrincipal()->GetURI(getter_AddRefs(principalURI));
+    // Check to see if URI is allowed.
+    nsresult rv = ssm->CheckLoadURIFromScript(cx, aURI);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    triggeringPrincipal = doc->NodePrincipal();
-    referrerPolicy = doc->GetReferrerPolicy();
+    // Make the load's referrer reflect changes to the document's URI caused by
+    // push/replaceState, if possible.  First, get the document corresponding to
+    // fp.  If the document's original URI (i.e. its URI before
+    // push/replaceState) matches the principal's URI, use the document's
+    // current URI as the referrer.  If they don't match, use the principal's
+    // URI.
+    //
+    // The triggering principal for this load should be the principal of the
+    // incumbent document (which matches where the referrer information is
+    // coming from) when there is an incumbent document, and the subject
+    // principal otherwise.  Note that the URI in the triggering principal
+    // may not match the referrer URI in various cases, notably including
+    // the cases when the incumbent document's document URI was modified
+    // after the document was loaded.
+
+    nsCOMPtr<nsPIDOMWindowInner> incumbent =
+      do_QueryInterface(mozilla::dom::GetIncumbentGlobal());
+    nsCOMPtr<nsIDocument> doc = incumbent ? incumbent->GetDoc() : nullptr;
 
-    bool urisEqual = false;
-    if (docOriginalURI && docCurrentURI && principalURI) {
-      principalURI->Equals(docOriginalURI, &urisEqual);
-    }
-    if (urisEqual) {
-      sourceURI = docCurrentURI;
-    }
-    else {
-      // Use principalURI as long as it is not an NullPrincipalURI.  We
-      // could add a method such as GetReferrerURI to principals to make this
-      // cleaner, but given that we need to start using Source Browsing
-      // Context for referrer (see Bug 960639) this may be wasted effort at
-      // this stage.
-      if (principalURI) {
-        bool isNullPrincipalScheme;
-        rv = principalURI->SchemeIs(NS_NULLPRINCIPAL_SCHEME,
-                                    &isNullPrincipalScheme);
-        if (NS_SUCCEEDED(rv) && !isNullPrincipalScheme) {
-          sourceURI = principalURI;
+    if (doc) {
+      nsCOMPtr<nsIURI> docOriginalURI, docCurrentURI, principalURI;
+      docOriginalURI = doc->GetOriginalURI();
+      docCurrentURI = doc->GetDocumentURI();
+      rv = doc->NodePrincipal()->GetURI(getter_AddRefs(principalURI));
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      triggeringPrincipal = doc->NodePrincipal();
+      referrerPolicy = doc->GetReferrerPolicy();
+
+      bool urisEqual = false;
+      if (docOriginalURI && docCurrentURI && principalURI) {
+        principalURI->Equals(docOriginalURI, &urisEqual);
+      }
+      if (urisEqual) {
+        sourceURI = docCurrentURI;
+      }
+      else {
+        // Use principalURI as long as it is not an NullPrincipalURI.  We
+        // could add a method such as GetReferrerURI to principals to make this
+        // cleaner, but given that we need to start using Source Browsing
+        // Context for referrer (see Bug 960639) this may be wasted effort at
+        // this stage.
+        if (principalURI) {
+          bool isNullPrincipalScheme;
+          rv = principalURI->SchemeIs(NS_NULLPRINCIPAL_SCHEME,
+                                     &isNullPrincipalScheme);
+          if (NS_SUCCEEDED(rv) && !isNullPrincipalScheme) {
+            sourceURI = principalURI;
+          }
         }
       }
     }
-  } else {
-    // No document; just use our subject principal as the triggering principal.
-    triggeringPrincipal = &aSubjectPrincipal;
+    else {
+      // No document; determine triggeringPrincipal by quering the
+      // subjectPrincipal, wich is the principal of the current JS
+      // compartment, or a null principal in case there is no
+      // compartment yet.
+      triggeringPrincipal = nsContentUtils::SubjectPrincipal();
+    }
   }
 
   // Create load info
   RefPtr<nsDocShellLoadInfo> loadInfo = new nsDocShellLoadInfo();
 
   loadInfo->SetTriggeringPrincipal(triggeringPrincipal);
 
   if (sourceURI) {
@@ -191,23 +202,23 @@ Location::GetURI(nsIURI** aURI, bool aGe
 
   nsCOMPtr<nsIURIFixup> urifixup(do_GetService(NS_URIFIXUP_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return urifixup->CreateExposableURI(uri, aURI);
 }
 
 nsresult
-Location::SetURI(nsIURI* aURI, nsIPrincipal& aSubjectPrincipal, bool aReplace)
+Location::SetURI(nsIURI* aURI, bool aReplace)
 {
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
   if (docShell) {
     RefPtr<nsDocShellLoadInfo> loadInfo;
 
-    if(NS_FAILED(CheckURL(aURI, aSubjectPrincipal, getter_AddRefs(loadInfo))))
+    if(NS_FAILED(CheckURL(aURI, getter_AddRefs(loadInfo))))
       return NS_ERROR_FAILURE;
 
     if (aReplace) {
       loadInfo->SetLoadType(LOAD_STOP_CONTENT_AND_REPLACE);
     } else {
       loadInfo->SetLoadType(LOAD_STOP_CONTENT);
     }
 
@@ -289,17 +300,17 @@ Location::SetHash(const nsAString& aHash
 
   aRv = NS_MutateURI(uri)
           .SetRef(hash)
           .Finalize(uri);
   if (NS_WARN_IF(aRv.Failed()) || !uri) {
     return;
   }
 
-  aRv = SetURI(uri, aSubjectPrincipal);
+  aRv = SetURI(uri);
 }
 
 void
 Location::GetHost(nsAString& aHost,
                   nsIPrincipal& aSubjectPrincipal,
                   ErrorResult& aRv)
 {
   if (!CallerSubsumes(&aSubjectPrincipal)) {
@@ -343,17 +354,17 @@ Location::SetHost(const nsAString& aHost
 
   aRv = NS_MutateURI(uri)
           .SetHostPort(NS_ConvertUTF16toUTF8(aHost))
           .Finalize(uri);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
-  aRv = SetURI(uri, aSubjectPrincipal);
+  aRv = SetURI(uri);
 }
 
 void
 Location::GetHostname(nsAString& aHostname,
                       nsIPrincipal& aSubjectPrincipal,
                       ErrorResult& aRv)
 {
   if (!CallerSubsumes(&aSubjectPrincipal)) {
@@ -388,17 +399,17 @@ Location::SetHostname(const nsAString& a
 
   aRv = NS_MutateURI(uri)
           .SetHost(NS_ConvertUTF16toUTF8(aHostname))
           .Finalize(uri);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
-  aRv = SetURI(uri, aSubjectPrincipal);
+  aRv = SetURI(uri);
 }
 
 nsresult
 Location::GetHref(nsAString& aHref)
 {
   aHref.Truncate();
 
   nsCOMPtr<nsIURI> uri;
@@ -414,35 +425,32 @@ Location::GetHref(nsAString& aHref)
   }
 
   AppendUTF8toUTF16(uriString, aHref);
   return NS_OK;
 }
 
 void
 Location::SetHref(const nsAString& aHref,
-                  nsIPrincipal& aSubjectPrincipal,
                   ErrorResult& aRv)
 {
-  DoSetHref(aHref, aSubjectPrincipal, false, aRv);
+  DoSetHref(aHref, false, aRv);
 }
 
 void
-Location::DoSetHref(const nsAString& aHref, nsIPrincipal& aSubjectPrincipal,
-                    bool aReplace, ErrorResult& aRv)
+Location::DoSetHref(const nsAString& aHref, bool aReplace, ErrorResult& aRv)
 {
   // Get the source of the caller
   nsCOMPtr<nsIURI> base = GetSourceBaseURL();
 
-  aRv = SetHrefWithBase(aHref, base, aSubjectPrincipal, aReplace);
+  aRv = SetHrefWithBase(aHref, base, aReplace);
 }
 
 nsresult
 Location::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
-                          nsIPrincipal& aSubjectPrincipal,
                           bool aReplace)
 {
   nsresult result;
   nsCOMPtr<nsIURI> newUri;
 
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
 
   if (nsIDocument* doc = GetEntryDocument()) {
@@ -475,17 +483,17 @@ Location::SetHrefWithBase(const nsAStrin
         // since we only want to replace if the location is set by a
         // <script> tag in the same window.  See bug 178729.
         nsCOMPtr<nsIScriptGlobalObject> ourGlobal =
           docShell ? docShell->GetScriptGlobalObject() : nullptr;
         inScriptTag = (ourGlobal == scriptContext->GetGlobalObject());
       }
     }
 
-    return SetURI(newUri, aSubjectPrincipal, aReplace || inScriptTag);
+    return SetURI(newUri, aReplace || inScriptTag);
   }
   return result;
 }
 
 void
 Location::GetOrigin(nsAString& aOrigin,
                     nsIPrincipal& aSubjectPrincipal,
                     ErrorResult& aRv)
@@ -558,17 +566,17 @@ Location::SetPathname(const nsAString& a
 
   nsresult rv = NS_MutateURI(uri)
                   .SetFilePath(NS_ConvertUTF16toUTF8(aPathname))
                   .Finalize(uri);
   if (NS_FAILED(rv)) {
     return;
   }
 
-  aRv = SetURI(uri, aSubjectPrincipal);
+  aRv = SetURI(uri);
 }
 
 void
 Location::GetPort(nsAString& aPort,
                   nsIPrincipal& aSubjectPrincipal,
                   ErrorResult& aRv)
 {
   if (!CallerSubsumes(&aSubjectPrincipal)) {
@@ -627,17 +635,17 @@ Location::SetPort(const nsAString& aPort
 
   aRv = NS_MutateURI(uri)
           .SetPort(port)
           .Finalize(uri);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
-  aRv = SetURI(uri, aSubjectPrincipal);
+  aRv = SetURI(uri);
 }
 
 void
 Location::GetProtocol(nsAString& aProtocol,
                       nsIPrincipal& aSubjectPrincipal,
                       ErrorResult& aRv)
 {
   if (!CallerSubsumes(&aSubjectPrincipal)) {
@@ -724,17 +732,17 @@ Location::SetProtocol(const nsAString& a
     return;
   }
 
   if (!isHttp && !isHttps) {
     // No-op, per spec.
     return;
   }
 
-  aRv = SetURI(uri, aSubjectPrincipal);
+  aRv = SetURI(uri);
 }
 
 void
 Location::GetSearch(nsAString& aSearch,
                     nsIPrincipal& aSubjectPrincipal,
                     ErrorResult& aRv)
 {
   if (!CallerSubsumes(&aSubjectPrincipal)) {
@@ -789,17 +797,17 @@ Location::SetSearch(const nsAString& aSe
     aRv = NS_MutateURI(uri)
             .SetQuery(NS_ConvertUTF16toUTF8(aSearch))
             .Finalize(uri);
   }
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
-  aRv = SetURI(uri, aSubjectPrincipal);
+  aRv = SetURI(uri);
 }
 
 nsresult
 Location::Reload(bool aForceget)
 {
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
   nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
   nsCOMPtr<nsPIDOMWindowOuter> window = docShell ? docShell->GetWindow()
@@ -845,30 +853,30 @@ Location::Reload(bool aForceget)
   return rv;
 }
 
 void
 Location::Replace(const nsAString& aUrl,
                   nsIPrincipal& aSubjectPrincipal,
                   ErrorResult& aRv)
 {
-  DoSetHref(aUrl, aSubjectPrincipal, true, aRv);
+  DoSetHref(aUrl, true, aRv);
 }
 
 void
 Location::Assign(const nsAString& aUrl,
                  nsIPrincipal& aSubjectPrincipal,
                  ErrorResult& aRv)
 {
   if (!CallerSubsumes(&aSubjectPrincipal)) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return;
   }
 
-  DoSetHref(aUrl, aSubjectPrincipal, false, aRv);
+  DoSetHref(aUrl, false, aRv);
 }
 
 already_AddRefed<nsIURI>
 Location::GetSourceBaseURL()
 {
   nsIDocument* doc = GetEntryDocument();
   // If there's no entry document, we either have no Script Entry Point or one
   // that isn't a DOM Window.  This doesn't generally happen with the DOM, but
--- a/dom/base/Location.h
+++ b/dom/base/Location.h
@@ -63,17 +63,16 @@ public:
       aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
       return;
     }
 
     aError = GetHref(aHref);
   }
 
   void SetHref(const nsAString& aHref,
-               nsIPrincipal& aSubjectPrincipal,
                ErrorResult& aError);
 
   void GetOrigin(nsAString& aOrigin,
                  nsIPrincipal& aSubjectPrincipal,
                  ErrorResult& aError);
 
   void GetProtocol(nsAString& aProtocol,
                    nsIPrincipal& aSubjectPrincipal,
@@ -162,35 +161,27 @@ protected:
   virtual ~Location();
 
   // In the case of jar: uris, we sometimes want the place the jar was
   // fetched from as the URI instead of the jar: uri itself.  Pass in
   // true for aGetInnermostURI when that's the case.
   // Note, this method can return NS_OK with a null value for aURL. This happens
   // if the docShell is null.
   nsresult GetURI(nsIURI** aURL, bool aGetInnermostURI = false);
-  nsresult SetURI(nsIURI* aURL, nsIPrincipal& aSubjectPrincipal, bool aReplace = false);
+  nsresult SetURI(nsIURI* aURL, bool aReplace = false);
   nsresult SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
-                           nsIPrincipal& aSubjectPrincipal, bool aReplace);
+                           bool aReplace);
 
   // Helper for Assign/SetHref/Replace
-  void DoSetHref(const nsAString& aHref, nsIPrincipal& aSubjectPrincipal,
-                 bool aReplace, ErrorResult& aRv);
+  void DoSetHref(const nsAString& aHref, bool aReplace, ErrorResult& aRv);
 
   // Get the base URL we should be using for our relative URL
   // resolution for SetHref/Assign/Replace.
   already_AddRefed<nsIURI> GetSourceBaseURL();
-
-  // Check whether it's OK to load the given url with the given subject
-  // principal, and if so construct the right nsDocShellLoadInfo for the load
-  // and return it.
-  nsresult CheckURL(nsIURI *url,
-                    nsIPrincipal& aSubjectPrincipal,
-                    nsDocShellLoadInfo** aLoadInfo);
-
+  nsresult CheckURL(nsIURI *url, nsDocShellLoadInfo** aLoadInfo);
   bool CallerSubsumes(nsIPrincipal* aSubjectPrincipal);
 
   nsString mCachedHash;
   nsCOMPtr<nsPIDOMWindowInner> mInnerWindow;
   nsWeakPtr mDocShell;
 };
 
 } // dom namespace
--- a/dom/webidl/Location.webidl
+++ b/dom/webidl/Location.webidl
@@ -15,17 +15,17 @@
 interface Location {
   // Bug 824857: no support for stringifier attributes yet.
   //  stringifier attribute USVString href;
 
   // Bug 824857 should remove this.
   [Throws, NeedsSubjectPrincipal]
   stringifier;
 
-  [Throws, CrossOriginWritable, NeedsSubjectPrincipal]
+  [Throws, CrossOriginWritable, GetterNeedsSubjectPrincipal]
            attribute USVString href;
   [Throws, NeedsSubjectPrincipal]
   readonly attribute USVString origin;
   [Throws, NeedsSubjectPrincipal]
            attribute USVString protocol;
   [Throws, NeedsSubjectPrincipal]
            attribute USVString host;
   [Throws, NeedsSubjectPrincipal]