Bug 1292930: Handle the case of having unresolved URIs in nsStyleDisplay::mBinding. r?heycam draft
authorEmilio Cobos Álvarez <ecoal95@gmail.com>
Thu, 11 Aug 2016 19:24:17 -0700
changeset 400238 7dc0df9244fb7127698da5e68da9c03146433f6d
parent 399531 c45412486f686f78358df5572b28ad95ad6b563c
child 400239 770b98121091223d861dc33337ecf97d0add3074
push id26102
push userbmo:ealvarez@mozilla.com
push dateFri, 12 Aug 2016 20:17:45 +0000
reviewersheycam
bugs1292930
milestone51.0a1
Bug 1292930: Handle the case of having unresolved URIs in nsStyleDisplay::mBinding. r?heycam This handles the case of the URIs not being resolved. MozReview-Commit-ID: ExYsFbeaYWo
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
layout/style/nsStyleStruct.cpp
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -2633,16 +2633,26 @@ css::URLValueData::operator==(const URLV
            (mURI && aOther.mURI &&
             NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) &&
             eq)) &&
           (mOriginPrincipal == aOther.mOriginPrincipal ||
            self.mOriginPrincipal.get()->Equals(other.mOriginPrincipal.get()));
 }
 
 bool
+css::URLValueData::MaybeUnresolvedURIEquals(const URLValueData& aOther) const
+{
+  if (!mURIResolved || !aOther.mURIResolved) {
+    return false;
+  }
+
+  return URIEquals(aOther);
+}
+
+bool
 css::URLValueData::URIEquals(const URLValueData& aOther) const
 {
   MOZ_ASSERT(mURIResolved && aOther.mURIResolved,
              "How do you know the URIs aren't null?");
   bool eq;
   // Cast away const so we can call nsIPrincipal::Equals.
   auto& self = *const_cast<URLValueData*>(this);
   auto& other = const_cast<URLValueData&>(aOther);
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -112,16 +112,20 @@ struct URLValueData
   bool operator==(const URLValueData& aOther) const;
 
   // URIEquals only compares URIs and principals (unlike operator==, which
   // also compares the original strings).  URIEquals also assumes that the
   // mURI member of both URL objects is non-null.  Do NOT call this method
   // unless you're sure this is the case.
   bool URIEquals(const URLValueData& aOther) const;
 
+  // Pretty much like URIEquals, but allows comparing unresolved URIs (returning
+  // false in that case).
+  bool MaybeUnresolvedURIEquals(const URLValueData& aOther) const;
+
   nsIURI* GetURI() const;
 
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
   bool GetLocalURLFlag() const { return mLocalURLFlag; }
 
 private:
   // If mURIResolved is false, mURI stores the base URI.
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -58,17 +58,17 @@ EqualURIs(nsIURI *aURI1, nsIURI *aURI2)
           NS_SUCCEEDED(aURI1->Equals(aURI2, &eq)) && // not equal on fail
           eq);
 }
 
 static bool
 EqualURIs(mozilla::css::URLValue *aURI1, mozilla::css::URLValue *aURI2)
 {
   return aURI1 == aURI2 ||    // handle null==null, and optimize
-         (aURI1 && aURI2 && aURI1->URIEquals(*aURI2));
+         (aURI1 && aURI2 && aURI1->MaybeUnresolvedURIEquals(*aURI2));
 }
 
 static
 bool EqualURIs(const FragmentOrURL* aURI1, const FragmentOrURL* aURI2)
 {
   return aURI1 == aURI2 ||    // handle null==null, and optimize
          (aURI1 && aURI2 && *aURI1 == *aURI2);
 }