Bug 1432187 - Change code to use nsIStandardURLMutator.{init,setDefaultPort} r=mayhemer

MozReview-Commit-ID: K2Uy9ET3Ay6

--HG--
extra : rebase_source : fb5e19bc7b71a6f0264471bf8f07febf1bc55900
This commit is contained in:
Valentin Gosu 2018-01-24 20:33:02 +01:00
parent 358af2c859
commit b53812bfed
18 changed files with 169 additions and 177 deletions

View File

@ -76,13 +76,16 @@ nsChromeProtocolHandler::NewURI(const nsACString &aSpec,
// Chrome: URLs (currently) have no additional structure beyond that provided
// by standard URLs, so there is no "outer" given to CreateInstance
RefPtr<mozilla::net::nsStandardURL> surl = new mozilla::net::nsStandardURL();
nsresult rv = surl->Init(nsIStandardURL::URLTYPE_STANDARD, -1, aSpec,
aCharset, aBaseURI);
if (NS_FAILED(rv))
nsresult rv;
nsCOMPtr<nsIURL> surl;
rv = NS_MutateURI(new mozilla::net::nsStandardURL::Mutator())
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_STANDARD, -1,
nsCString(aSpec), aCharset, aBaseURI, nullptr)
.Finalize(surl);
if (NS_FAILED(rv)) {
return rv;
}
// Canonify the "chrome:" URL; e.g., so that we collapse
// "chrome://navigator/content/" and "chrome://navigator/content"
@ -92,7 +95,7 @@ nsChromeProtocolHandler::NewURI(const nsACString &aSpec,
if (NS_FAILED(rv))
return rv;
surl->SetMutable(false);
NS_TryToSetImmutable(surl);
surl.forget(result);
return NS_OK;

View File

@ -632,8 +632,6 @@ URLWorker::Init(const nsAString& aURL, const Optional<nsAString>& aBase,
if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https")) {
nsCOMPtr<nsIURI> baseURL;
if (aBase.WasPassed()) {
baseURL = new nsStandardURL();
// XXXcatalinb: SetSpec only writes a warning to the console on urls
// without a valid scheme. I can't fix that because we've come to rely
// on that behaviour in a bunch of different places.
@ -649,9 +647,17 @@ URLWorker::Init(const nsAString& aURL, const Optional<nsAString>& aBase,
return;
}
}
mStdURL = new nsStandardURL();
aRv = mStdURL->Init(nsIStandardURL::URLTYPE_STANDARD, -1,
NS_ConvertUTF16toUTF8(aURL), nullptr, baseURL);
nsCOMPtr<nsIURI> uri;
rv = NS_MutateURI(new nsStandardURL::Mutator())
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_STANDARD, -1,
NS_ConvertUTF16toUTF8(aURL),
nullptr, baseURL, nullptr)
.Finalize(uri);
aRv = rv;
if (NS_SUCCEEDED(rv)) {
mStdURL = static_cast<nsStandardURL*>(uri.get());
}
return;
}

View File

@ -94,21 +94,14 @@ nsJARURI::CreateEntryURL(const nsACString& entryFilename,
nsIURL** url)
{
*url = nullptr;
nsCOMPtr<nsIStandardURL> stdURL(do_CreateInstance(NS_STANDARDURL_CONTRACTID));
if (!stdURL) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Flatten the concatenation, just in case. See bug 128288
nsAutoCString spec(NS_BOGUS_ENTRY_SCHEME + entryFilename);
nsresult rv = stdURL->Init(nsIStandardURL::URLTYPE_NO_AUTHORITY, -1,
spec, charset, nullptr);
if (NS_FAILED(rv)) {
return rv;
}
return CallQueryInterface(stdURL, url);
return NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_NO_AUTHORITY, -1,
spec, charset, nullptr,
nullptr)
.Finalize(url);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -2861,24 +2861,20 @@ NS_ShouldSecureUpgrade(nsIURI* aURI,
nsresult
NS_GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI)
{
nsCOMPtr<nsIURI> upgradedURI;
nsresult rv = aURI->Clone(getter_AddRefs(upgradedURI));
NS_ENSURE_SUCCESS(rv,rv);
// Change the scheme to HTTPS:
upgradedURI->SetScheme(NS_LITERAL_CSTRING("https"));
NS_MutateURI mutator(aURI);
mutator.SetScheme(NS_LITERAL_CSTRING("https")); // Change the scheme to HTTPS:
// Change the default port to 443:
nsCOMPtr<nsIStandardURL> upgradedStandardURL = do_QueryInterface(upgradedURI);
if (upgradedStandardURL) {
upgradedStandardURL->SetDefaultPort(443);
nsCOMPtr<nsIStandardURL> stdURL = do_QueryInterface(aURI);
if (stdURL) {
mutator.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::SetDefaultPort, 443, nullptr);
} else {
// If we don't have a nsStandardURL, fall back to using GetPort/SetPort.
// XXXdholbert Is this function even called with a non-nsStandardURL arg,
// in practice?
NS_WARNING("Calling NS_GetSecureUpgradedURI for non nsStandardURL");
int32_t oldPort = -1;
rv = aURI->GetPort(&oldPort);
nsresult rv = aURI->GetPort(&oldPort);
if (NS_FAILED(rv)) return rv;
// Keep any nonstandard ports so only the scheme is changed.
@ -2887,14 +2883,13 @@ NS_GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI)
// http://foo.com:81 -> https://foo.com:81
if (oldPort == 80 || oldPort == -1) {
upgradedURI->SetPort(-1);
mutator.SetPort(-1);
} else {
upgradedURI->SetPort(oldPort);
mutator.SetPort(oldPort);
}
}
upgradedURI.forget(aUpgradedURI);
return NS_OK;
return mutator.Finalize(aUpgradedURI);
}
nsresult

View File

@ -9,6 +9,7 @@
#include "nsFileChannel.h"
#include "nsStandardURL.h"
#include "nsURLHelper.h"
#include "nsIURIMutator.h"
#include "nsNetUtil.h"
@ -166,23 +167,22 @@ nsFileProtocolHandler::NewURI(const nsACString &spec,
nsIURI *baseURI,
nsIURI **result)
{
nsCOMPtr<nsIStandardURL> url = new nsStandardURL(true);
if (!url)
return NS_ERROR_OUT_OF_MEMORY;
const nsACString *specPtr = &spec;
nsCOMPtr<nsIURI> url = new nsStandardURL(true);
nsAutoCString buf(spec);
#if defined(XP_WIN)
nsAutoCString buf;
if (net_NormalizeFileURL(spec, buf))
specPtr = &buf;
buf.Truncate();
if (!net_NormalizeFileURL(spec, buf)) {
buf = spec;
}
#endif
nsresult rv = url->Init(nsIStandardURL::URLTYPE_NO_AUTHORITY, -1,
*specPtr, charset, baseURI);
if (NS_FAILED(rv)) return rv;
return CallQueryInterface(url, result);
return NS_MutateURI(url)
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_NO_AUTHORITY, -1,
buf, charset, baseURI,
nullptr)
.Finalize(result);
}
NS_IMETHODIMP

View File

@ -171,14 +171,13 @@ nsFtpProtocolHandler::NewURI(const nsACString &aSpec,
if (spec.FindCharInSet(CRLF) >= 0 || spec.FindChar('\0') >= 0)
return NS_ERROR_MALFORMED_URI;
nsresult rv;
nsCOMPtr<nsIStandardURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY, 21, aSpec, aCharset, aBaseURI);
if (NS_FAILED(rv)) return rv;
return CallQueryInterface(url, result);
nsCOMPtr<nsIURI> url;
return NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_AUTHORITY, 21,
nsCString(aSpec), aCharset, aBaseURI,
nullptr)
.Finalize(result);
}
NS_IMETHODIMP

View File

@ -20,6 +20,7 @@
#include "nsNetUtil.h"
#include "nsServiceManagerUtils.h"
#include "nsIURI.h"
#include "nsIURIMutator.h"
#include "nsIAuthPrompt.h"
#include "nsIChannel.h"
#include "nsIInputStream.h"
@ -1026,18 +1027,12 @@ nsGIOProtocolHandler::NewURI(const nsACString &aSpec,
}
}
nsresult rv;
nsCOMPtr<nsIStandardURL> url =
do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
rv = url->Init(nsIStandardURL::URLTYPE_STANDARD, -1, flatSpec,
aOriginCharset, aBaseURI);
if (NS_SUCCEEDED(rv))
rv = CallQueryInterface(url, aResult);
return rv;
return NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_STANDARD, -1,
flatSpec, aOriginCharset, aBaseURI,
nullptr)
.Finalize(aResult);
}
NS_IMETHODIMP

View File

@ -1888,7 +1888,7 @@ Http2Session::RecvPushPromise(Http2Session *self)
// does the pushed origin belong on this connection?
LOG3(("Http2Session::RecvPushPromise %p origin check %s", self,
pushedStream->Origin().get()));
RefPtr<nsStandardURL> pushedOrigin;
nsCOMPtr<nsIURI> pushedOrigin;
rv = Http2Stream::MakeOriginURL(pushedStream->Origin(), pushedOrigin);
nsAutoCString pushedHostName;
int32_t pushedPort = -1;
@ -1943,7 +1943,7 @@ Http2Session::RecvPushPromise(Http2Session *self)
nsAutoCString spec;
spec.Assign(pushedStream->Origin());
spec.Append(pushedStream->Path());
RefPtr<nsStandardURL> pushedURL;
nsCOMPtr<nsIURI> pushedURL;
// Nifty trick: this doesn't actually do anything origin-specific, it's just
// named that way. So by passing it the full spec here, we get a URL with
// the full path.
@ -2651,7 +2651,7 @@ Http2Session::RecvOrigin(Http2Session *self)
}
nsAutoCString originString;
RefPtr<nsStandardURL> originURL;
nsCOMPtr<nsIURI> originURL;
originString.Assign(self->mInputFrameBuffer.get() + kFrameHeaderBytes + offset + 2, originLen);
offset += originLen + 2;
if (NS_FAILED(Http2Stream::MakeOriginURL(originString, originURL))){

View File

@ -333,7 +333,7 @@ Http2Stream::WriteSegments(nsAHttpSegmentWriter *writer,
}
nsresult
Http2Stream::MakeOriginURL(const nsACString &origin, RefPtr<nsStandardURL> &url)
Http2Stream::MakeOriginURL(const nsACString &origin, nsCOMPtr<nsIURI> &url)
{
nsAutoCString scheme;
nsresult rv = net_ExtractURLScheme(origin, scheme);
@ -343,15 +343,17 @@ Http2Stream::MakeOriginURL(const nsACString &origin, RefPtr<nsStandardURL> &url)
nsresult
Http2Stream::MakeOriginURL(const nsACString &scheme, const nsACString &origin,
RefPtr<nsStandardURL> &url)
nsCOMPtr<nsIURI> &url)
{
url = new nsStandardURL();
nsresult rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY,
scheme.EqualsLiteral("http") ?
NS_HTTP_DEFAULT_PORT :
NS_HTTPS_DEFAULT_PORT,
origin, nullptr, nullptr);
return rv;
return NS_MutateURI(new nsStandardURL::Mutator())
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_AUTHORITY,
scheme.EqualsLiteral("http") ?
NS_HTTP_DEFAULT_PORT :
NS_HTTPS_DEFAULT_PORT,
nsCString(origin), nullptr, nullptr,
nullptr)
.Finalize(url);
}
void
@ -367,7 +369,7 @@ Http2Stream::CreatePushHashKey(const nsCString &scheme,
fullOrigin.AppendLiteral("://");
fullOrigin.Append(hostHeader);
RefPtr<nsStandardURL> origin;
nsCOMPtr<nsIURI> origin;
nsresult rv = Http2Stream::MakeOriginURL(scheme, fullOrigin, origin);
if (NS_SUCCEEDED(rv)) {

View File

@ -161,11 +161,11 @@ public:
Http2Session *Session() { return mSession; }
static MOZ_MUST_USE nsresult MakeOriginURL(const nsACString &origin,
RefPtr<nsStandardURL> &url);
nsCOMPtr<nsIURI> &url);
static MOZ_MUST_USE nsresult MakeOriginURL(const nsACString &scheme,
const nsACString &origin,
RefPtr<nsStandardURL> &url);
nsCOMPtr<nsIURI> &url);
// Mirrors nsAHttpTransaction
bool Do0RTT();

View File

@ -136,16 +136,12 @@ NewURI(const nsACString &aSpec,
int32_t aDefaultPort,
nsIURI **aURI)
{
RefPtr<nsStandardURL> url = new nsStandardURL();
nsresult rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY,
aDefaultPort, aSpec, aCharset, aBaseURI);
if (NS_FAILED(rv)) {
return rv;
}
url.forget(aURI);
return NS_OK;
return NS_MutateURI(new nsStandardURL::Mutator())
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_AUTHORITY,
aDefaultPort, nsCString(aSpec), aCharset, aBaseURI,
nullptr)
.Finalize(aURI);
}
#ifdef ANDROID

View File

@ -32,6 +32,8 @@ static NS_DEFINE_CID(kSubstitutingURLCID, NS_SUBSTITUTINGURL_CID);
// SubstitutingURL : overrides nsStandardURL::GetFile to provide nsIFile resolution
//---------------------------------------------------------------------------------
NS_IMPL_ISUPPORTS(SubstitutingURL::Mutator, nsIURISetters, nsIURIMutator, nsIStandardURLMutator)
nsresult
SubstitutingURL::EnsureFile()
{
@ -196,12 +198,6 @@ SubstitutingProtocolHandler::NewURI(const nsACString &aSpec,
nsIURI *aBaseURI,
nsIURI **result)
{
nsresult rv;
RefPtr<SubstitutingURL> url = new SubstitutingURL();
if (!url)
return NS_ERROR_OUT_OF_MEMORY;
// unescape any %2f and %2e to make sure nsStandardURL coalesces them.
// Later net_GetFileFromURLSpec() will do a full unescape and we want to
// treat them the same way the file system will. (bugs 380994, 394075)
@ -233,11 +229,12 @@ SubstitutingProtocolHandler::NewURI(const nsACString &aSpec,
if (last < src)
spec.Append(last, src-last);
rv = url->Init(nsIStandardURL::URLTYPE_STANDARD, -1, spec, aCharset, aBaseURI);
if (NS_SUCCEEDED(rv)) {
url.forget(result);
}
return rv;
return NS_MutateURI(new SubstitutingURL::Mutator())
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_STANDARD, -1,
spec, aCharset, aBaseURI,
nullptr)
.Finalize(result);
}
nsresult

View File

@ -306,13 +306,12 @@ BaseWebSocketChannel::NewURI(const nsACString & aSpec, const char *aOriginCharse
if (NS_FAILED(rv))
return rv;
RefPtr<nsStandardURL> url = new nsStandardURL();
rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY, port, aSpec,
aOriginCharset, aBaseURI);
if (NS_FAILED(rv))
return rv;
url.forget(_retval);
return NS_OK;
return NS_MutateURI(new nsStandardURL::Mutator())
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_AUTHORITY, port,
nsCString(aSpec), aOriginCharset, aBaseURI,
nullptr)
.Finalize(_retval);
}
NS_IMETHODIMP

View File

@ -1,8 +1,3 @@
const StandardURL = Components.Constructor("@mozilla.org/network/standard-url;1",
"nsIStandardURL",
"init");
// 1.percent-encoded IDN that contains blacklisted character should be converted
// to punycode, not UTF-8 string
// 2.only hostname-valid percent encoded ASCII characters should be decoded
@ -37,8 +32,10 @@ let prefData =
};
function stringToURL(str) {
return (new StandardURL(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 80,
str, "UTF-8", null))
return Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIStandardURLMutator)
.init(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 80, str, "UTF-8", null)
.finalize()
.QueryInterface(Ci.nsIURL);
}

View File

@ -9,28 +9,40 @@
var Cc = Components.classes;
var Ci = Components.interfaces;
const StandardURL = Components.Constructor("@mozilla.org/network/standard-url;1",
"nsIStandardURL",
"init");
function run_test()
{
let mutator = Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIURIMutator);
Assert.ok(mutator, "Mutator constructor works");
let url = Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIStandardURLMutator)
.init(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 65535,
"http://localhost", "UTF-8", null)
.finalize();
// Bug 1301621 makes invalid ports throw
Assert.throws(() => {
new StandardURL(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 65536,
"http://localhost", "UTF-8", null)
url = Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIStandardURLMutator)
.init(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 65536,
"http://localhost", "UTF-8", null)
.finalize();
}, "invalid port during creation");
let url = new StandardURL(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 65535,
"http://localhost", "UTF-8", null)
.QueryInterface(Ci.nsIStandardURL)
Assert.throws(() => {
url.setDefaultPort(65536);
url = url.mutate()
.QueryInterface(Ci.nsIStandardURLMutator)
.setDefaultPort(65536)
.finalize();
}, "invalid port in setDefaultPort");
Assert.throws(() => {
url.port = 65536;
url = url.mutate()
.setPort(65536)
.finalize();
}, "invalid port in port setter");
Assert.equal(url.QueryInterface(Ci.nsIURI).port, -1);
Assert.equal(url.port, -1);
do_test_finished();
}

View File

@ -1,9 +1,5 @@
"use strict";
const StandardURL = Components.Constructor("@mozilla.org/network/standard-url;1",
"nsIStandardURL",
"init");
const nsIStandardURL = Components.interfaces.nsIStandardURL;
const gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
function symmetricEquality(expect, a, b)
@ -31,9 +27,11 @@ function symmetricEquality(expect, a, b)
}
function stringToURL(str) {
return (new StandardURL(nsIStandardURL.URLTYPE_AUTHORITY, 80,
str, "UTF-8", null))
.QueryInterface(Components.interfaces.nsIURL);
return Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIStandardURLMutator)
.init(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 80, str, "UTF-8", null)
.finalize()
.QueryInterface(Ci.nsIURL);
}
function pairToURLs(pair) {

View File

@ -11,41 +11,50 @@
var Cc = Components.classes;
var Ci = Components.interfaces;
const StandardURL = Components.Constructor("@mozilla.org/network/standard-url;1",
"nsIStandardURL",
"init");
function run_test() {
function stringToURL(str) {
return (new StandardURL(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 80,
str, "UTF-8", null))
.QueryInterface(Ci.nsIStandardURL);
return Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIStandardURLMutator)
.init(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 80, str, "UTF-8", null)
.finalize()
.QueryInterface(Ci.nsIStandardURL);
}
// Create a nsStandardURL:
var origUrlStr = "http://foo.com/";
var stdUrl = stringToURL(origUrlStr);
var stdUrlAsUri = stdUrl.QueryInterface(Ci.nsIURI);
Assert.equal(-1, stdUrlAsUri.port);
Assert.equal(-1, stdUrl.port);
// Changing default port shouldn't adjust the value returned by "port",
// or the string representation.
stdUrl.setDefaultPort(100);
Assert.equal(-1, stdUrlAsUri.port);
Assert.equal(stdUrlAsUri.spec, origUrlStr);
let def100Url = stdUrl.mutate()
.QueryInterface(Ci.nsIStandardURLMutator)
.setDefaultPort(100)
.finalize();
Assert.equal(-1, def100Url.port);
Assert.equal(def100Url.spec, origUrlStr);
// Changing port directly should update .port and .spec, though:
stdUrlAsUri.port = "200";
Assert.equal(200, stdUrlAsUri.port);
Assert.equal(stdUrlAsUri.spec, "http://foo.com:200/");
let port200Url = stdUrl.mutate()
.setPort("200")
.finalize();
Assert.equal(200, port200Url.port);
Assert.equal(port200Url.spec, "http://foo.com:200/");
// ...but then if we change default port to match the custom port,
// the custom port should reset to -1 and disappear from .spec:
stdUrl.setDefaultPort(200);
Assert.equal(-1, stdUrlAsUri.port);
Assert.equal(stdUrlAsUri.spec, origUrlStr);
let def200Url = port200Url.mutate()
.QueryInterface(Ci.nsIStandardURLMutator)
.setDefaultPort(200)
.finalize();
Assert.equal(-1, def200Url.port);
Assert.equal(def200Url.spec, origUrlStr);
// And further changes to default port should not make custom port reappear.
stdUrl.setDefaultPort(300);
Assert.equal(-1, stdUrlAsUri.port);
Assert.equal(stdUrlAsUri.spec, origUrlStr);
let def300Url = def200Url.mutate()
.QueryInterface(Ci.nsIStandardURLMutator)
.setDefaultPort(300)
.finalize();
Assert.equal(-1, def300Url.port);
Assert.equal(def300Url.spec, origUrlStr);
}

View File

@ -10,6 +10,7 @@
#include "nsIIOService.h"
#include "nsIStandardURL.h"
#include "nsIURL.h"
#include "nsIURIMutator.h"
#include "android/log.h"
#include "nsBaseChannel.h"
#include "AndroidBridge.h"
@ -140,22 +141,12 @@ nsAndroidProtocolHandler::NewURI(const nsACString &aSpec,
nsIURI *aBaseURI,
nsIURI **result)
{
nsresult rv;
nsCOMPtr<nsIStandardURL> surl(do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
rv = surl->Init(nsIStandardURL::URLTYPE_STANDARD, -1, aSpec, aCharset, aBaseURI);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIURL> url(do_QueryInterface(surl, &rv));
NS_ENSURE_SUCCESS(rv, rv);
surl->SetMutable(false);
NS_ADDREF(*result = url);
return NS_OK;
return NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
.Apply<nsIStandardURLMutator>(&nsIStandardURLMutator::Init,
nsIStandardURL::URLTYPE_STANDARD, -1,
nsCString(aSpec), aCharset, aBaseURI,
nullptr)
.Finalize(result);
}
NS_IMETHODIMP