Bug 1297961 (part 2) - Use nsIURI::GetSpecOrDefault() for comparisons to fixed URIs. r=hurley.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 26 Aug 2016 16:02:32 +1000
changeset 312381 d8b7827cca8303713e401363e701bdcc6553a8c4
parent 312380 b516e1d6e46165d5553ec894fadc55ce514f862c
child 312382 93657f8dedaafa384bcd49c71b52e195ec968de8
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershurley
bugs1297961
milestone51.0a1
Bug 1297961 (part 2) - Use nsIURI::GetSpecOrDefault() for comparisons to fixed URIs. r=hurley.
docshell/base/nsDocShell.cpp
dom/html/nsHTMLDocument.cpp
netwerk/base/nsNetUtil.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -14222,18 +14222,17 @@ nsDocShell::SetOriginAttributes(const Do
   // attributes.
   if (mContentViewer) {
     nsIDocument* doc = mContentViewer->GetDocument();
     if (doc) {
       nsIURI* uri = doc->GetDocumentURI();
       if (!uri) {
         return NS_ERROR_FAILURE;
       }
-      nsAutoCString uriSpec;
-      uri->GetSpec(uriSpec);
+      nsCString uriSpec = uri->GetSpecOrDefault();
       MOZ_ASSERT(uriSpec.EqualsLiteral("about:blank"));
       if (!uriSpec.EqualsLiteral("about:blank")) {
         return NS_ERROR_FAILURE;
       }
     }
   }
 
   AssertOriginAttributesMatchPrivateBrowsing();
@@ -14452,18 +14451,17 @@ nsDocShell::ShouldPrepareForIntercept(ns
   nsresult result;
   nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
     do_GetService(THIRDPARTYUTIL_CONTRACTID, &result);
   NS_ENSURE_SUCCESS(result, result);
 
   if (mCurrentURI &&
       nsContentUtils::CookiesBehavior() == nsICookieService::BEHAVIOR_REJECT_FOREIGN) {
     nsAutoCString uriSpec;
-    mCurrentURI->GetSpec(uriSpec);
-    if (!(uriSpec.EqualsLiteral("about:blank"))) {
+    if (!(mCurrentURI->GetSpecOrDefault().EqualsLiteral("about:blank"))) {
       // Reject the interception of third-party iframes if the cookie behaviour
       // is set to reject all third-party cookies (1). In case that this pref
       // is not set or can't be read, we default to allow all cookies (0) as
       // this is the default value in all.js.
       bool isThirdPartyURI = true;
       result = thirdPartyUtil->IsThirdPartyURI(mCurrentURI, aURI,
                                                &isThirdPartyURI);
       if (NS_FAILED(result)) {
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -552,36 +552,34 @@ nsHTMLDocument::StartDocumentLoad(const 
   bool loadAsHtml5 = true;
 
   if (!viewSource && xhtml) {
       // We're parsing XHTML as XML, remember that.
       mType = eXHTML;
       mCompatMode = eCompatibility_FullStandards;
       loadAsHtml5 = false;
   }
-  
+
   // TODO: Proper about:blank treatment is bug 543435
   if (loadAsHtml5 && view) {
     // mDocumentURI hasn't been set, yet, so get the URI from the channel
     nsCOMPtr<nsIURI> uri;
     aChannel->GetOriginalURI(getter_AddRefs(uri));
     // Adapted from nsDocShell:
     // GetSpec can be expensive for some URIs, so check the scheme first.
     bool isAbout = false;
     if (uri && NS_SUCCEEDED(uri->SchemeIs("about", &isAbout)) && isAbout) {
-      nsAutoCString str;
-      uri->GetSpec(str);
-      if (str.EqualsLiteral("about:blank")) {
-        loadAsHtml5 = false;    
+      if (uri->GetSpecOrDefault().EqualsLiteral("about:blank")) {
+        loadAsHtml5 = false;
       }
     }
   }
-  
+
   CSSLoader()->SetCompatibilityMode(mCompatMode);
-  
+
   nsresult rv = nsDocument::StartDocumentLoad(aCommand,
                                               aChannel, aLoadGroup,
                                               aContainer,
                                               aDocListener, aReset);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -2159,19 +2159,17 @@ void net_EnsurePSMInit()
 bool NS_IsAboutBlank(nsIURI *uri)
 {
     // GetSpec can be expensive for some URIs, so check the scheme first.
     bool isAbout = false;
     if (NS_FAILED(uri->SchemeIs("about", &isAbout)) || !isAbout) {
         return false;
     }
 
-    nsAutoCString str;
-    uri->GetSpec(str);
-    return str.EqualsLiteral("about:blank");
+    return uri->GetSpecOrDefault().EqualsLiteral("about:blank");
 }
 
 nsresult
 NS_GenerateHostPort(const nsCString& host, int32_t port,
                     nsACString &hostLine)
 {
     if (strchr(host.get(), ':')) {
         // host is an IPv6 address literal and must be encapsulated in []'s
@@ -2395,18 +2393,17 @@ NS_CompareLoadInfoAndLoadContext(nsIChan
   // https:// and blob URLs.
   // about:sync-tabs will fetch icons through moz-icon://.
   bool isAboutPage = false;
   nsINode* node = loadInfo->LoadingNode();
   if (node) {
     nsIDocument* doc = node->OwnerDoc();
     if (doc) {
       nsIURI* uri = doc->GetDocumentURI();
-      nsAutoCString spec;
-      uri->GetSpec(spec);
+      nsCString spec = uri->GetSpecOrDefault();
       isAboutPage = spec.EqualsLiteral("about:newtab") ||
                     spec.EqualsLiteral("about:sync-tabs");
     }
   }
 
   if (isAboutPage) {
     return NS_OK;
   }