diff --git a/layout/style/nsCSSValue.cpp b/layout/style/nsCSSValue.cpp index a898878ff4e6..a97d4c81c780 100644 --- a/layout/style/nsCSSValue.cpp +++ b/layout/style/nsCSSValue.cpp @@ -2728,6 +2728,69 @@ css::URLValueData::GetURI() const return mURI; } +already_AddRefed +css::URLValueData::ResolveLocalRef(nsIURI* aURI) const +{ + nsCOMPtr result = GetURI(); + + if (result && mIsLocalRef) { + nsCString ref; + mURI->GetRef(ref); + + aURI->Clone(getter_AddRefs(result)); + result->SetRef(ref); + } + + return result.forget(); +} + +already_AddRefed +css::URLValueData::ResolveLocalRef(nsIContent* aContent) const +{ + nsCOMPtr url = aContent->GetBaseURI(); + return ResolveLocalRef(url); +} + +void +css::URLValueData::GetSourceString(nsString& aRef) const +{ + nsIURI* uri = GetURI(); + if (!uri) { + aRef.Truncate(); + return; + } + + nsCString cref; + if (mIsLocalRef) { + // XXXheycam It's possible we can just return mString in this case, since + // it should be the "#fragment" string the URLValueData was created with. + uri->GetRef(cref); + cref.Insert('#', 0); + } else { + // It's not entirely clear how to best handle failure here. Ensuring the + // string is empty seems safest. + nsresult rv = uri->GetSpec(cref); + if (NS_FAILED(rv)) { + cref.Truncate(); + } + } + + aRef = NS_ConvertUTF8toUTF16(cref); +} + +bool +css::URLValueData::EqualsExceptRef(nsIURI* aURI) const +{ + nsIURI* uri = GetURI(); + if (!uri) { + return false; + } + + bool ret = false; + uri->EqualsExceptRef(aURI, &ret); + return ret; +} + size_t css::URLValueData::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { diff --git a/layout/style/nsCSSValue.h b/layout/style/nsCSSValue.h index c3b8fa92c197..d40661f287fb 100644 --- a/layout/style/nsCSSValue.h +++ b/layout/style/nsCSSValue.h @@ -33,6 +33,7 @@ #include "gfxFontFamilyList.h" class imgRequestProxy; +class nsIContent; class nsIDocument; class nsIPrincipal; class nsIURI; @@ -138,6 +139,17 @@ public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(URLValueData) + // When matching a url with mIsLocalRef set, resolve it against aURI; + // Otherwise, ignore aURL and return mURL directly. + already_AddRefed ResolveLocalRef(nsIURI* aURI) const; + already_AddRefed ResolveLocalRef(nsIContent* aContent) const; + + // Serializes mURI as a computed URI value, taking into account mIsLocalRef + // and serializing just the fragment if true. + void GetSourceString(nsString& aRef) const; + + bool EqualsExceptRef(nsIURI* aURI) const; + private: // mURI stores the lazily resolved URI. This may be null if the URI is // invalid, even once resolved.