Bug 1353204 - Follow-up: Use entire spec for origin for Thunderbird. r=bz
authorJorg K <jorgk@jorgk.com>
Mon, 10 Apr 2017 14:04:11 +0200
changeset 400296 5a07a004ca309f405dd7b20ba57ab224aae494b5
parent 400295 16e85d7e7400febe85909d6f1baa5b0ff03fb2ab
child 400297 344527734950caddf7279c5ee5c7be78532362bb
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1353204
milestone55.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 1353204 - Follow-up: Use entire spec for origin for Thunderbird. r=bz
caps/ContentPrincipal.cpp
--- a/caps/ContentPrincipal.cpp
+++ b/caps/ContentPrincipal.cpp
@@ -122,39 +122,16 @@ ContentPrincipal::Init(nsIURI *aCodebase
 }
 
 nsresult
 ContentPrincipal::GetScriptLocation(nsACString &aStr)
 {
   return mCodebase->GetSpec(aStr);
 }
 
-static nsresult
-AssignFullSpecToOriginNoSuffix(nsIURI* aURI, nsACString& aOriginNoSuffix)
-{
-  nsresult rv = aURI->GetAsciiSpec(aOriginNoSuffix);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // The origin, when taken from the spec, should not contain the ref part of
-  // the URL.
-
-  int32_t pos = aOriginNoSuffix.FindChar('?');
-  int32_t hashPos = aOriginNoSuffix.FindChar('#');
-
-  if (hashPos != kNotFound && (pos == kNotFound || hashPos < pos)) {
-    pos = hashPos;
-  }
-
-  if (pos != kNotFound) {
-    aOriginNoSuffix.Truncate(pos);
-  }
-
-  return NS_OK;
-}
-
 /* static */ nsresult
 ContentPrincipal::GenerateOriginNoSuffixFromURI(nsIURI* aURI,
                                                 nsACString& aOriginNoSuffix)
 {
   if (!aURI) {
     return NS_ERROR_FAILURE;
   }
 
@@ -178,17 +155,17 @@ ContentPrincipal::GenerateOriginNoSuffix
 
   nsresult rv;
 // NB: This is only compiled for Thunderbird/Suite.
 #if IS_ORIGIN_IS_FULL_SPEC_DEFINED
   bool fullSpec = false;
   rv = NS_URIChainHasFlags(origin, nsIProtocolHandler::ORIGIN_IS_FULL_SPEC, &fullSpec);
   NS_ENSURE_SUCCESS(rv, rv);
   if (fullSpec) {
-    return AssignFullSpecToOriginNoSuffix(origin, aOriginNoSuffix);
+    return origin->GetAsciiSpec(aOriginNoSuffix);
   }
 #endif
 
   // We want the invariant that prinA.origin == prinB.origin i.f.f.
   // prinA.equals(prinB). However, this requires that we impose certain constraints
   // on the behavior and origin semantics of principals, and in particular, forbid
   // creating origin strings for principals whose equality constraints are not
   // expressible as strings (i.e. object equality). Moreover, we want to forbid URIs
@@ -253,18 +230,34 @@ ContentPrincipal::GenerateOriginNoSuffix
   if (!hostPort.IsEmpty()) {
     rv = origin->GetScheme(aOriginNoSuffix);
     NS_ENSURE_SUCCESS(rv, rv);
     aOriginNoSuffix.AppendLiteral("://");
     aOriginNoSuffix.Append(hostPort);
     return NS_OK;
   }
 
-  // Use the full spec.
-  return AssignFullSpecToOriginNoSuffix(origin, aOriginNoSuffix);
+  rv = aURI->GetAsciiSpec(aOriginNoSuffix);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  // The origin, when taken from the spec, should not contain the ref part of
+  // the URL.
+
+  int32_t pos = aOriginNoSuffix.FindChar('?');
+  int32_t hashPos = aOriginNoSuffix.FindChar('#');
+
+  if (hashPos != kNotFound && (pos == kNotFound || hashPos < pos)) {
+    pos = hashPos;
+  }
+
+  if (pos != kNotFound) {
+    aOriginNoSuffix.Truncate(pos);
+  }
+
+  return NS_OK;
 }
 
 bool
 ContentPrincipal::SubsumesInternal(nsIPrincipal* aOther,
                                    BasePrincipal::DocumentDomainConsideration aConsideration)
 {
   MOZ_ASSERT(aOther);