Bug 1297963 - Part 2: Add URLValueData comparison functions that work OMT. r=emilio draft
authorCameron McCormack <cam@mcc.id.au>
Fri, 02 Sep 2016 19:56:59 +1000
changeset 409178 f8444472c8125bb68fe23f32a4b5b67ae32d2fbf
parent 409177 ab129177dca19216ba6f8836acdc2c63ea72cedd
child 409179 8e2c677cbef35995c869374a0b85f87390fe9b66
push id28409
push usercmccormack@mozilla.com
push dateFri, 02 Sep 2016 10:01:25 +0000
reviewersemilio
bugs1297963
milestone51.0a1
Bug 1297963 - Part 2: Add URLValueData comparison functions that work OMT. r=emilio MozReview-Commit-ID: LqcX6jadxnv
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -2673,16 +2673,33 @@ css::URLValueData::URIEquals(const URLVa
   // fast path to equality
   return (mURI == aOther.mURI ||
           (NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) && eq)) &&
          (mOriginPrincipal == aOther.mOriginPrincipal ||
           self.mOriginPrincipal.get()->Equals(other.mOriginPrincipal.get())) &&
          mLocalURLFlag == aOther.mLocalURLFlag;
 }
 
+bool
+css::URLValueData::DefinitelyEqualURIs(const URLValueData& aOther) const
+{
+  return mBaseURI == aOther.mBaseURI &&
+         (mString == aOther.mString ||
+          NS_strcmp(nsCSSValue::GetBufferValue(mString),
+                    nsCSSValue::GetBufferValue(aOther.mString)));
+}
+
+bool
+css::URLValueData::DefinitelyEqualURIsAndPrincipal(
+    const URLValueData& aOther) const
+{
+  return mOriginPrincipal == aOther.mOriginPrincipal &&
+         DefinitelyEqualURIs(aOther);
+}
+
 nsIURI*
 css::URLValueData::GetURI() const
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!mURIResolved) {
     MOZ_ASSERT(!mURI);
     nsCOMPtr<nsIURI> newURI;
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -117,16 +117,29 @@ struct URLValueData
   // 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;
 
+  // Returns true iff we know for sure, by comparing the mBaseURI pointer,
+  // the specified url() value mString, and the mLocalURLFlag, that these
+  // two URLValueData objects represent the same computed url() value.
+  //
+  // Doesn't look at mReferrer or mOriginPrincipal.
+  //
+  // Safe to call from any thread.
+  bool DefinitelyEqualURIs(const URLValueData& aOther) const;
+
+  // Smae as DefinitelyEqualURIs but additionally compares the nsIPrincipal
+  // pointers of the two URLValueData objects.
+  bool DefinitelyEqualURIsAndPrincipal(const URLValueData& aOther) const;
+
   nsIURI* GetURI() const;
 
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
   bool GetLocalURLFlag() const { return mLocalURLFlag; }
 
 private:
   // mURI stores the lazily resolved URI.  This may be null if the URI is