Bug 451081 - Introduce ORIGIN_IS_FULL_SPEC protocol handler flag, r=bz+standard8 IGNORE IDL
authorHonza Bambas <honzab.moz@firemni.cz>
Wed, 20 Jan 2016 20:02:23 +0100
changeset 280760 bbfbc6368c9378d3f40b5a5450a2edcfe8ea669c
parent 280759 8689d4697905af98cb8fc59fdc404ffea7fbc047
child 280761 676889159995b5c2948fa5ef6dd41e5bf7d02d1d
push id70574
push userhonzab.moz@firemni.cz
push dateWed, 20 Jan 2016 19:04:46 +0000
treeherdermozilla-inbound@bbfbc6368c93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs451081
milestone46.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 451081 - Introduce ORIGIN_IS_FULL_SPEC protocol handler flag, r=bz+standard8 IGNORE IDL
netwerk/base/nsIProtocolHandler.idl
netwerk/base/nsNetUtil.cpp
--- a/netwerk/base/nsIProtocolHandler.idl
+++ b/netwerk/base/nsIProtocolHandler.idl
@@ -289,19 +289,27 @@ interface nsIProtocolHandler : nsISuppor
     const unsigned long URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT = (1<<18);
 
     /**
      * This URI may be fetched and the contents are visible to anyone. This is
      * semantically equivalent to the resource being served with all-access CORS
      * headers.
      */
     const unsigned long URI_FETCHABLE_BY_ANYONE = (1 << 19);
+
+    /**
+     * If this flag is set, then the origin for this protocol is the full URI
+     * spec, not just the scheme + host + port.
+     */
+    const unsigned long ORIGIN_IS_FULL_SPEC = (1 << 20);
 };
 
 %{C++
 /**
  * Protocol handlers are registered with XPCOM under the following CONTRACTID prefix:
  */
 #define NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "@mozilla.org/network/protocol;1?name="
 /**
  * For example, "@mozilla.org/network/protocol;1?name=http"
  */
+
+#define IS_ORIGIN_IS_FULL_SPEC_DEFINED 1
 %}
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -1641,19 +1641,20 @@ NS_SecurityHashURI(nsIURI *aURI)
     uint32_t schemeHash = 0;
     if (NS_SUCCEEDED(baseURI->GetScheme(scheme)))
         schemeHash = mozilla::HashString(scheme);
 
     // TODO figure out how to hash file:// URIs
     if (scheme.EqualsLiteral("file"))
         return schemeHash; // sad face
 
-    if (scheme.EqualsLiteral("imap") ||
-        scheme.EqualsLiteral("mailbox") ||
-        scheme.EqualsLiteral("news"))
+    bool hasFlag;
+    if (NS_FAILED(NS_URIChainHasFlags(baseURI,
+        nsIProtocolHandler::ORIGIN_IS_FULL_SPEC, &hasFlag)) ||
+        hasFlag)
     {
         nsAutoCString spec;
         uint32_t specHash;
         nsresult res = baseURI->GetSpec(spec);
         if (NS_SUCCEEDED(res))
             specHash = mozilla::HashString(spec);
         else
             specHash = static_cast<uint32_t>(res);
@@ -1740,23 +1741,23 @@ NS_SecurityCompareURIs(nsIURI *aSourceUR
             return false;
 
         // Otherwise they had better match
         bool filesAreEqual = false;
         nsresult rv = sourceFile->Equals(targetFile, &filesAreEqual);
         return NS_SUCCEEDED(rv) && filesAreEqual;
     }
 
-    // Special handling for mailnews schemes
-    if (targetScheme.EqualsLiteral("imap") ||
-        targetScheme.EqualsLiteral("mailbox") ||
-        targetScheme.EqualsLiteral("news"))
+    bool hasFlag;
+    if (NS_FAILED(NS_URIChainHasFlags(targetBaseURI,
+        nsIProtocolHandler::ORIGIN_IS_FULL_SPEC, &hasFlag)) ||
+        hasFlag)
     {
-        // Each message is a distinct trust domain; use the
-        // whole spec for comparison
+        // URIs with this flag have the whole spec as a distinct trust
+        // domain; use the whole spec for comparison
         nsAutoCString targetSpec;
         nsAutoCString sourceSpec;
         return ( NS_SUCCEEDED( targetBaseURI->GetSpec(targetSpec) ) &&
                  NS_SUCCEEDED( sourceBaseURI->GetSpec(sourceSpec) ) &&
                  targetSpec.Equals(sourceSpec) );
     }
 
     // Compare hosts