Bug 308590 patch 3.5: Add nsIURI::CloneIgnoringRef interface & impls. r=bz sr=biesi

This commit is contained in:
Daniel Holbert 2011-05-21 18:12:45 -07:00
Родитель f4110d2e96
Коммит 2ee75e0a93
13 изменённых файлов: 134 добавлений и 34 удалений

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

@ -237,11 +237,18 @@ nsNullPrincipalURI::Clone(nsIURI **_newURI)
{
nsCOMPtr<nsIURI> uri =
new nsNullPrincipalURI(mScheme + NS_LITERAL_CSTRING(":") + mPath);
NS_ENSURE_TRUE(uri, NS_ERROR_OUT_OF_MEMORY);
uri.forget(_newURI);
return NS_OK;
}
NS_IMETHODIMP
nsNullPrincipalURI::CloneIgnoringRef(nsIURI **_newURI)
{
// GetRef/SetRef not supported by nsNullPrincipalURI, so
// CloneIgnoringRef() is the same as Clone().
return Clone(_newURI);
}
NS_IMETHODIMP
nsNullPrincipalURI::Equals(nsIURI *aOther, PRBool *_equals)
{

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

@ -147,14 +147,15 @@ public:
NS_DECL_NSISERIALIZABLE
NS_DECL_NSICLASSINFO
// Override Clone() and EqualsInternal()
NS_IMETHOD Clone(nsIURI** aClone);
// Override CloneInternal() and EqualsInternal()
virtual nsresult CloneInternal(RefHandlingEnum aRefHandlingMode,
nsIURI** aClone);
virtual nsresult EqualsInternal(nsIURI* aOther,
RefHandlingEnum aRefHandlingMode,
PRBool* aResult);
// Override StartClone to hand back a nsFileDataURI
virtual nsSimpleURI* StartClone()
virtual nsSimpleURI* StartClone(RefHandlingEnum /* unused */)
{ return new nsFileDataURI(); }
nsCOMPtr<nsIPrincipal> mPrincipal;
@ -215,12 +216,13 @@ nsFileDataURI::Write(nsIObjectOutputStream* aStream)
}
// nsIURI methods:
NS_IMETHODIMP
nsFileDataURI::Clone(nsIURI** aClone)
nsresult
nsFileDataURI::CloneInternal(nsSimpleURI::RefHandlingEnum aRefHandlingMode,
nsIURI** aClone)
{
nsCOMPtr<nsIURI> simpleClone;
nsresult rv = nsSimpleURI::Clone(getter_AddRefs(simpleClone));
nsresult rv =
nsSimpleURI::CloneInternal(aRefHandlingMode, getter_AddRefs(simpleClone));
NS_ENSURE_SUCCESS(rv, rv);
#ifdef DEBUG

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

@ -514,7 +514,19 @@ nsJARURI::Clone(nsIURI **result)
nsresult rv;
nsCOMPtr<nsIJARURI> uri;
rv = CloneWithJARFile(mJARFile, getter_AddRefs(uri));
rv = CloneWithJARFileInternal(mJARFile, eHonorRef, getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv;
return CallQueryInterface(uri, result);
}
NS_IMETHODIMP
nsJARURI::CloneIgnoringRef(nsIURI **result)
{
nsresult rv;
nsCOMPtr<nsIJARURI> uri;
rv = CloneWithJARFileInternal(mJARFile, eIgnoreRef, getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv;
return CallQueryInterface(uri, result);
@ -781,6 +793,14 @@ nsJARURI::SetJAREntry(const nsACString &entryPath)
NS_IMETHODIMP
nsJARURI::CloneWithJARFile(nsIURI *jarFile, nsIJARURI **result)
{
return CloneWithJARFileInternal(jarFile, eHonorRef, result);
}
nsresult
nsJARURI::CloneWithJARFileInternal(nsIURI *jarFile,
nsJARURI::RefHandlingEnum refHandlingMode,
nsIJARURI **result)
{
if (!jarFile) {
return NS_ERROR_INVALID_ARG;
@ -795,24 +815,22 @@ nsJARURI::CloneWithJARFile(nsIURI *jarFile, nsIJARURI **result)
NS_TryToSetImmutable(newJARFile);
nsCOMPtr<nsIURI> newJAREntryURI;
rv = mJAREntry->Clone(getter_AddRefs(newJAREntryURI));
rv = refHandlingMode == eHonorRef ?
mJAREntry->Clone(getter_AddRefs(newJAREntryURI)) :
mJAREntry->CloneIgnoringRef(getter_AddRefs(newJAREntryURI));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURL> newJAREntry(do_QueryInterface(newJAREntryURI));
NS_ASSERTION(newJAREntry, "This had better QI to nsIURL!");
nsJARURI* uri = new nsJARURI();
if (uri) {
NS_ADDREF(uri);
uri->mJARFile = newJARFile;
uri->mJAREntry = newJAREntry;
*result = uri;
rv = NS_OK;
} else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(uri);
uri->mJARFile = newJARFile;
uri->mJAREntry = newJAREntry;
*result = uri;
return rv;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

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

@ -105,6 +105,10 @@ protected:
RefHandlingEnum refHandlingMode,
PRBool* result);
// Helper to share code between Clone methods.
nsresult CloneWithJARFileInternal(nsIURI *jarFile,
RefHandlingEnum refHandlingMode,
nsIJARURI **result);
nsCOMPtr<nsIURI> mJARFile;
// mJarEntry stored as a URL so that we can easily access things
// like extensions, refs, etc.

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

@ -449,9 +449,6 @@ nsMozIconURI::Clone(nsIURI **result)
}
nsMozIconURI *uri = new nsMozIconURI();
if (!uri)
return NS_ERROR_OUT_OF_MEMORY;
newIconURL.swap(uri->mIconURL);
uri->mSize = mSize;
uri->mContentType = mContentType;
@ -464,6 +461,14 @@ nsMozIconURI::Clone(nsIURI **result)
return NS_OK;
}
NS_IMETHODIMP
nsMozIconURI::CloneIgnoringRef(nsIURI **result)
{
// GetRef/SetRef not supported by nsMozIconURI, so
// CloneIgnoringRef() is the same as Clone().
return Clone(result);
}
NS_IMETHODIMP
nsMozIconURI::Resolve(const nsACString &relativePath, nsACString &result)
{

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

@ -219,6 +219,11 @@ interface nsIURI : nsISupports
*/
nsIURI clone();
/**
* Clones the current URI, clearing the 'ref' attribute in the clone.
*/
nsIURI cloneIgnoringRef();
/**
* This method resolves a relative string into an absolute URI string,
* using this URI as the base.

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

@ -162,12 +162,15 @@ nsSimpleNestedURI::EqualsInternal(nsIURI* other,
}
/* virtual */ nsSimpleURI*
nsSimpleNestedURI::StartClone()
nsSimpleNestedURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode)
{
NS_ENSURE_TRUE(mInnerURI, nsnull);
nsCOMPtr<nsIURI> innerClone;
nsresult rv = mInnerURI->Clone(getter_AddRefs(innerClone));
nsresult rv = refHandlingMode == eHonorRef ?
mInnerURI->Clone(getter_AddRefs(innerClone)) :
mInnerURI->CloneIgnoringRef(getter_AddRefs(innerClone));
if (NS_FAILED(rv)) {
return nsnull;
}

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

@ -77,7 +77,7 @@ public:
virtual nsresult EqualsInternal(nsIURI* other,
RefHandlingEnum refHandlingMode,
PRBool* result);
virtual nsSimpleURI* StartClone();
virtual nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode);
// nsISerializable overrides
NS_IMETHOD Read(nsIObjectInputStream* aStream);

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

@ -395,15 +395,30 @@ nsSimpleURI::SchemeIs(const char *i_Scheme, PRBool *o_Equals)
}
/* virtual */ nsSimpleURI*
nsSimpleURI::StartClone()
nsSimpleURI::StartClone(nsSimpleURI::RefHandlingEnum /* ignored */)
{
return new nsSimpleURI();
}
NS_IMETHODIMP
nsSimpleURI::Clone(nsIURI* *result)
nsSimpleURI::Clone(nsIURI** result)
{
nsSimpleURI* url = StartClone();
return CloneInternal(eHonorRef, result);
}
NS_IMETHODIMP
nsSimpleURI::CloneIgnoringRef(nsIURI** result)
{
return CloneInternal(eIgnoreRef, result);
}
nsresult
nsSimpleURI::CloneInternal(nsSimpleURI::RefHandlingEnum refHandlingMode,
nsIURI** result)
{
// XXXdholbert Mostly ignoring refHandlingMode so far, but I'll make use
// of it in next patch, when I add support for .ref to this class.
nsSimpleURI* url = StartClone(refHandlingMode);
if (url == nsnull)
return NS_ERROR_OUT_OF_MEMORY;

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

@ -80,14 +80,20 @@ protected:
eHonorRef
};
// Helper to share code between Equals methods. Subclasses can override
// for custom Equals behavior.
// Helper to share code between Equals methods.
virtual nsresult EqualsInternal(nsIURI* other,
RefHandlingEnum refHandlingMode,
PRBool* result);
virtual nsSimpleURI* StartClone();
// NOTE: This takes the refHandlingMode as an argument because
// nsSimpleNestedURI's specialized version needs to know how to clone
// its inner URI.
virtual nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode);
// Helper to share code between Clone methods.
virtual nsresult CloneInternal(RefHandlingEnum refHandlingMode,
nsIURI** clone);
nsCString mScheme;
nsCString mPath;
PRBool mMutable;

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

@ -1697,7 +1697,22 @@ nsStandardURL::StartClone()
NS_IMETHODIMP
nsStandardURL::Clone(nsIURI **result)
{
nsStandardURL *clone = StartClone();
return CloneInternal(eHonorRef, result);
}
NS_IMETHODIMP
nsStandardURL::CloneIgnoringRef(nsIURI **result)
{
return CloneInternal(eIgnoreRef, result);
}
nsresult
nsStandardURL::CloneInternal(nsStandardURL::RefHandlingEnum refHandlingMode,
nsIURI **result)
{
nsRefPtr<nsStandardURL> clone = StartClone();
if (!clone)
return NS_ERROR_OUT_OF_MEMORY;
@ -1727,7 +1742,11 @@ nsStandardURL::Clone(nsIURI **result)
clone->mHostEncoding = mHostEncoding;
clone->mSpecEncoding = mSpecEncoding;
NS_ADDREF(*result = clone);
if (refHandlingMode == eIgnoreRef) {
clone->SetRef(EmptyCString());
}
clone.forget(result);
return NS_OK;
}

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

@ -167,6 +167,10 @@ protected:
virtual nsStandardURL* StartClone();
// Helper to share code between Clone methods.
nsresult CloneInternal(RefHandlingEnum aRefHandlingMode,
nsIURI** aClone);
// Helper for subclass implementation of GetFile(). Subclasses that map
// URIs to files in a special way should implement this method. It should
// ensure that our mFile is initialized, if it's possible.

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

@ -196,6 +196,7 @@ function do_test_uri_basic(aTest) {
// Sanity-check
do_info("testing " + aTest.spec + " equals a clone of itself");
do_check_uri_eq(URI, URI.clone());
do_check_uri_eq(URI, URI.cloneIgnoringRef());
do_info("testing " + aTest.spec + " instanceof nsIURL");
do_check_eq(URI instanceof Ci.nsIURL, aTest.nsIURL);
do_info("testing " + aTest.spec + " instanceof nsINestedURI");
@ -248,6 +249,17 @@ function do_test_uri_with_hash_suffix(aTest, aSuffix) {
do_info("testing " + aTest.spec +
" is equalExceptRef to self with '" + aSuffix + "' appended");
do_check_uri_eqExceptRef(origURI, testURI);
do_info("testing cloneIgnoringRef on " + testURI.spec +
" is equal to no-ref version but not equal to ref version");
var cloneNoRef = testURI.cloneIgnoringRef();
if (aTest.spec == "http://" && aSuffix == "#") {
do_info("TODO: bug 657033");
do_check_uri_eq(cloneNoRef, origURI, todo_check_true);
} else {
do_check_uri_eq(cloneNoRef, origURI);
}
do_check_false(cloneNoRef.equals(testURI));
}
}