Bug 1298774 - Part 3: Copy helper functions from FragmentOrURL to URLValueData. r=cjku

MozReview-Commit-ID: 9gs8d0fMdYJ

--HG--
extra : rebase_source : 18d4ad350d529c4da9188f8c7ff6a2cece9273c8
This commit is contained in:
Cameron McCormack 2016-10-11 14:56:11 +08:00
Родитель b490466d48
Коммит 5ed807d5a2
2 изменённых файлов: 75 добавлений и 0 удалений

Просмотреть файл

@ -2728,6 +2728,69 @@ css::URLValueData::GetURI() const
return mURI;
}
already_AddRefed<nsIURI>
css::URLValueData::ResolveLocalRef(nsIURI* aURI) const
{
nsCOMPtr<nsIURI> result = GetURI();
if (result && mIsLocalRef) {
nsCString ref;
mURI->GetRef(ref);
aURI->Clone(getter_AddRefs(result));
result->SetRef(ref);
}
return result.forget();
}
already_AddRefed<nsIURI>
css::URLValueData::ResolveLocalRef(nsIContent* aContent) const
{
nsCOMPtr<nsIURI> 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
{

Просмотреть файл

@ -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<nsIURI> ResolveLocalRef(nsIURI* aURI) const;
already_AddRefed<nsIURI> 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.