Bug 1431204 - Change calls to nsIURI.spec setter to use nsIURIMutator instead r=mayhemer

* changes call to use nsIURIMutator.setSpec()
* Add new NS_MutateURI constructor that takes new Mutator object
* Make nsSimpleNestedURI::Mutate() and nsNestedAboutURI::Mutate() return mutable URIs
* Make the finalizers for nsSimpleNestedURI and nsNestedAboutURI make the returned URIs immutable

MozReview-Commit-ID: 1kcv6zMxnv7
This commit is contained in:
Valentin Gosu
2018-01-19 15:19:42 +01:00
parent 5c304366ab
commit a215981c13
17 changed files with 192 additions and 110 deletions

View File

@@ -1196,20 +1196,22 @@ nsJSProtocolHandler::NewURI(const nsACString &aSpec,
// CreateInstance.
nsCOMPtr<nsIURI> url = new nsJSURI(aBaseURI);
if (!aCharset || !nsCRT::strcasecmp("UTF-8", aCharset))
rv = url->SetSpec(aSpec);
else {
NS_MutateURI mutator(url);
if (!aCharset || !nsCRT::strcasecmp("UTF-8", aCharset)) {
mutator.SetSpec(aSpec);
} else {
nsAutoCString utf8Spec;
rv = EnsureUTF8Spec(PromiseFlatCString(aSpec), aCharset, utf8Spec);
if (NS_SUCCEEDED(rv)) {
if (utf8Spec.IsEmpty())
rv = url->SetSpec(aSpec);
else
rv = url->SetSpec(utf8Spec);
if (utf8Spec.IsEmpty()) {
mutator.SetSpec(aSpec);
} else {
mutator.SetSpec(utf8Spec);
}
}
}
rv = mutator.Finalize(url);
if (NS_FAILED(rv)) {
return rv;
}