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:
@@ -892,18 +892,20 @@ nsHostObjectProtocolHandler::NewURI(const nsACString& aSpec,
|
|||||||
|
|
||||||
DataInfo* info = GetDataInfo(aSpec);
|
DataInfo* info = GetDataInfo(aSpec);
|
||||||
|
|
||||||
RefPtr<nsHostObjectURI> uri;
|
nsCOMPtr<nsIURI> uri;
|
||||||
if (info && info->mObjectType == DataInfo::eBlobImpl) {
|
rv = NS_MutateURI(new nsHostObjectURI::Mutator())
|
||||||
MOZ_ASSERT(info->mBlobImpl);
|
.SetSpec(aSpec)
|
||||||
uri = new nsHostObjectURI(info->mPrincipal, info->mBlobImpl);
|
.Finalize(uri);
|
||||||
} else {
|
|
||||||
uri = new nsHostObjectURI(nullptr, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = uri->SetSpec(aSpec);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
NS_TryToSetImmutable(uri);
|
RefPtr<nsHostObjectURI> hostURI = static_cast<nsHostObjectURI*>(uri.get());
|
||||||
|
if (info && info->mObjectType == DataInfo::eBlobImpl) {
|
||||||
|
MOZ_ASSERT(info->mBlobImpl);
|
||||||
|
hostURI->mPrincipal = info->mPrincipal;
|
||||||
|
hostURI->mBlobImpl = info->mBlobImpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_TryToSetImmutable(hostURI);
|
||||||
uri.forget(aResult);
|
uri.forget(aResult);
|
||||||
|
|
||||||
if (info && info->mObjectType == DataInfo::eBlobImpl) {
|
if (info && info->mObjectType == DataInfo::eBlobImpl) {
|
||||||
@@ -1120,21 +1122,23 @@ nsFontTableProtocolHandler::NewURI(const nsACString& aSpec,
|
|||||||
nsIURI *aBaseURI,
|
nsIURI *aBaseURI,
|
||||||
nsIURI **aResult)
|
nsIURI **aResult)
|
||||||
{
|
{
|
||||||
RefPtr<nsIURI> uri;
|
nsresult rv;
|
||||||
|
nsCOMPtr<nsIURI> uri;
|
||||||
|
|
||||||
// Either you got here via a ref or a fonttable: uri
|
// Either you got here via a ref or a fonttable: uri
|
||||||
if (aSpec.Length() && aSpec.CharAt(0) == '#') {
|
if (aSpec.Length() && aSpec.CharAt(0) == '#') {
|
||||||
nsresult rv = aBaseURI->CloneIgnoringRef(getter_AddRefs(uri));
|
rv = NS_MutateURI(aBaseURI)
|
||||||
|
.SetRef(aSpec)
|
||||||
|
.Finalize(uri);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
uri->SetRef(aSpec);
|
|
||||||
} else {
|
} else {
|
||||||
// Relative URIs (other than #ref) are not meaningful within the
|
// Relative URIs (other than #ref) are not meaningful within the
|
||||||
// fonttable: scheme.
|
// fonttable: scheme.
|
||||||
// If aSpec is a relative URI -other- than a bare #ref,
|
// If aSpec is a relative URI -other- than a bare #ref,
|
||||||
// this will leave uri empty, and we'll return a failure code below.
|
// this will leave uri empty, and we'll return a failure code below.
|
||||||
uri = new mozilla::net::nsSimpleURI();
|
rv = NS_MutateURI(new mozilla::net::nsSimpleURI::Mutator())
|
||||||
nsresult rv = uri->SetSpec(aSpec);
|
.SetSpec(aSpec)
|
||||||
|
.Finalize(uri);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1196,20 +1196,22 @@ nsJSProtocolHandler::NewURI(const nsACString &aSpec,
|
|||||||
// CreateInstance.
|
// CreateInstance.
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> url = new nsJSURI(aBaseURI);
|
nsCOMPtr<nsIURI> url = new nsJSURI(aBaseURI);
|
||||||
|
NS_MutateURI mutator(url);
|
||||||
if (!aCharset || !nsCRT::strcasecmp("UTF-8", aCharset))
|
if (!aCharset || !nsCRT::strcasecmp("UTF-8", aCharset)) {
|
||||||
rv = url->SetSpec(aSpec);
|
mutator.SetSpec(aSpec);
|
||||||
else {
|
} else {
|
||||||
nsAutoCString utf8Spec;
|
nsAutoCString utf8Spec;
|
||||||
rv = EnsureUTF8Spec(PromiseFlatCString(aSpec), aCharset, utf8Spec);
|
rv = EnsureUTF8Spec(PromiseFlatCString(aSpec), aCharset, utf8Spec);
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
if (utf8Spec.IsEmpty())
|
if (utf8Spec.IsEmpty()) {
|
||||||
rv = url->SetSpec(aSpec);
|
mutator.SetSpec(aSpec);
|
||||||
else
|
} else {
|
||||||
rv = url->SetSpec(utf8Spec);
|
mutator.SetSpec(utf8Spec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rv = mutator.Finalize(url);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -630,16 +630,20 @@ URLWorker::Init(const nsAString& aURL, const Optional<nsAString>& aBase,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https")) {
|
if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https")) {
|
||||||
RefPtr<nsStandardURL> baseURL;
|
nsCOMPtr<nsIURI> baseURL;
|
||||||
if (aBase.WasPassed()) {
|
if (aBase.WasPassed()) {
|
||||||
baseURL = new nsStandardURL();
|
baseURL = new nsStandardURL();
|
||||||
|
|
||||||
// XXXcatalinb: SetSpec only writes a warning to the console on urls
|
// 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
|
// without a valid scheme. I can't fix that because we've come to rely
|
||||||
// on that behaviour in a bunch of different places.
|
// on that behaviour in a bunch of different places.
|
||||||
nsresult rv = baseURL->SetSpec(NS_ConvertUTF16toUTF8(aBase.Value()));
|
nsresult rv = NS_MutateURI(new nsStandardURL::Mutator())
|
||||||
|
.SetSpec(NS_ConvertUTF16toUTF8(aBase.Value()))
|
||||||
|
.Finalize(baseURL);
|
||||||
nsAutoCString baseScheme;
|
nsAutoCString baseScheme;
|
||||||
baseURL->GetScheme(baseScheme);
|
if (baseURL) {
|
||||||
|
baseURL->GetScheme(baseScheme);
|
||||||
|
}
|
||||||
if (NS_WARN_IF(NS_FAILED(rv)) || baseScheme.IsEmpty()) {
|
if (NS_WARN_IF(NS_FAILED(rv)) || baseScheme.IsEmpty()) {
|
||||||
aRv.ThrowTypeError<MSG_INVALID_URL>(aBase.Value());
|
aRv.ThrowTypeError<MSG_INVALID_URL>(aBase.Value());
|
||||||
return;
|
return;
|
||||||
@@ -707,8 +711,11 @@ URLWorker::SetHref(const nsAString& aHref, ErrorResult& aRv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https")) {
|
if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https")) {
|
||||||
mStdURL = new nsStandardURL();
|
nsCOMPtr<nsIURI> uri;
|
||||||
aRv = mStdURL->SetSpec(NS_ConvertUTF16toUTF8(aHref));
|
aRv = NS_MutateURI(new nsStandardURL::Mutator())
|
||||||
|
.SetSpec(NS_ConvertUTF16toUTF8(aHref))
|
||||||
|
.Finalize(uri);
|
||||||
|
mStdURL = static_cast<net::nsStandardURL*>(uri.get());
|
||||||
if (mURLProxy) {
|
if (mURLProxy) {
|
||||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||||
|
|
||||||
|
|||||||
@@ -68,14 +68,9 @@ nsIconProtocolHandler::NewURI(const nsACString& aSpec,
|
|||||||
nsIURI* aBaseURI,
|
nsIURI* aBaseURI,
|
||||||
nsIURI** result)
|
nsIURI** result)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIMozIconURI> uri = new nsMozIconURI();
|
return NS_MutateURI(new nsMozIconURI::Mutator())
|
||||||
if (!uri) return NS_ERROR_OUT_OF_MEMORY;
|
.SetSpec(aSpec)
|
||||||
|
.Finalize(result);
|
||||||
nsresult rv = uri->SetSpec(aSpec);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
NS_ADDREF(*result = uri);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|||||||
@@ -278,6 +278,12 @@ public:
|
|||||||
explicit NS_MutateURI(nsIURI* aURI);
|
explicit NS_MutateURI(nsIURI* aURI);
|
||||||
explicit NS_MutateURI(const char * aContractID);
|
explicit NS_MutateURI(const char * aContractID);
|
||||||
|
|
||||||
|
explicit NS_MutateURI(nsIURIMutator* m)
|
||||||
|
{
|
||||||
|
mStatus = m ? NS_OK : NS_ERROR_NULL_POINTER;
|
||||||
|
mMutator = m;
|
||||||
|
}
|
||||||
|
|
||||||
NS_MutateURI& SetSpec(const nsACString& aSpec)
|
NS_MutateURI& SetSpec(const nsACString& aSpec)
|
||||||
{
|
{
|
||||||
NS_ENSURE_SUCCESS(mStatus, *this);
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
||||||
|
|||||||
@@ -196,6 +196,9 @@ nsSimpleNestedURI::Mutate(nsIURIMutator** aMutator)
|
|||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
// StartClone calls SetMutable(false) but we need the mutator clone
|
||||||
|
// to be mutable
|
||||||
|
mutator->ResetMutable();
|
||||||
mutator.forget(aMutator);
|
mutator.forget(aMutator);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,13 +77,48 @@ public:
|
|||||||
, public BaseURIMutator<nsSimpleNestedURI>
|
, public BaseURIMutator<nsSimpleNestedURI>
|
||||||
{
|
{
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
NS_DEFINE_NSIMUTATOR_COMMON
|
|
||||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||||
|
|
||||||
explicit Mutator() { }
|
explicit Mutator() { }
|
||||||
private:
|
private:
|
||||||
virtual ~Mutator() { }
|
virtual ~Mutator() { }
|
||||||
|
|
||||||
|
MOZ_MUST_USE NS_IMETHOD
|
||||||
|
Deserialize(const mozilla::ipc::URIParams& aParams) override
|
||||||
|
{
|
||||||
|
return InitFromIPCParams(aParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_MUST_USE NS_IMETHOD
|
||||||
|
Read(nsIObjectInputStream* aStream) override
|
||||||
|
{
|
||||||
|
return InitFromInputStream(aStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_MUST_USE NS_IMETHOD
|
||||||
|
Finalize(nsIURI** aURI) override
|
||||||
|
{
|
||||||
|
mURI->mMutable = false;
|
||||||
|
mURI.forget(aURI);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_MUST_USE NS_IMETHOD
|
||||||
|
SetSpec(const nsACString& aSpec, nsIURIMutator** aMutator) override
|
||||||
|
{
|
||||||
|
if (aMutator) {
|
||||||
|
NS_ADDREF(*aMutator = this);
|
||||||
|
}
|
||||||
|
return InitFromSpec(aSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetMutable()
|
||||||
|
{
|
||||||
|
if (mURI) {
|
||||||
|
mURI->mMutable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
friend class nsSimpleNestedURI;
|
friend class nsSimpleNestedURI;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -113,11 +113,13 @@ nsAboutProtocolHandler::NewURI(const nsACString &aSpec,
|
|||||||
*result = nullptr;
|
*result = nullptr;
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
||||||
// Use a simple URI to parse out some stuff first
|
|
||||||
nsCOMPtr<nsIURI> url = do_CreateInstance(kSimpleURICID, &rv);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
rv = url->SetSpec(aSpec);
|
// Use a simple URI to parse out some stuff first
|
||||||
|
nsCOMPtr<nsIURI> url;
|
||||||
|
rv = NS_MutateURI(new nsSimpleURI::Mutator())
|
||||||
|
.SetSpec(aSpec)
|
||||||
|
.Finalize(url);
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@@ -148,13 +150,10 @@ nsAboutProtocolHandler::NewURI(const nsACString &aSpec,
|
|||||||
rv = NS_NewURI(getter_AddRefs(inner), spec);
|
rv = NS_NewURI(getter_AddRefs(inner), spec);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsSimpleNestedURI* outer = new nsNestedAboutURI(inner, aBaseURI);
|
RefPtr<nsSimpleNestedURI> outer = new nsNestedAboutURI(inner, aBaseURI);
|
||||||
NS_ENSURE_TRUE(outer, NS_ERROR_OUT_OF_MEMORY);
|
rv = NS_MutateURI(outer)
|
||||||
|
.SetSpec(aSpec)
|
||||||
// Take a ref to it in the COMPtr we plan to return
|
.Finalize(url);
|
||||||
url = outer;
|
|
||||||
|
|
||||||
rv = outer->SetSpec(aSpec);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,21 +297,15 @@ nsSafeAboutProtocolHandler::NewURI(const nsACString &aSpec,
|
|||||||
nsIURI *aBaseURI,
|
nsIURI *aBaseURI,
|
||||||
nsIURI **result)
|
nsIURI **result)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv = NS_MutateURI(new nsSimpleURI::Mutator())
|
||||||
|
.SetSpec(aSpec)
|
||||||
nsCOMPtr<nsIURI> url = do_CreateInstance(kSimpleURICID, &rv);
|
.Finalize(result);
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
rv = url->SetSpec(aSpec);
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_TryToSetImmutable(url);
|
NS_TryToSetImmutable(*result);
|
||||||
|
return NS_OK;
|
||||||
*result = nullptr;
|
|
||||||
url.swap(*result);
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
@@ -437,6 +430,9 @@ nsNestedAboutURI::Mutate(nsIURIMutator** aMutator)
|
|||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
// StartClone calls SetMutable(false) but we need the mutator clone
|
||||||
|
// to be mutable
|
||||||
|
mutator->ResetMutable();
|
||||||
mutator.forget(aMutator);
|
mutator.forget(aMutator);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,12 +93,47 @@ public:
|
|||||||
{
|
{
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||||
NS_DEFINE_NSIMUTATOR_COMMON
|
|
||||||
|
|
||||||
explicit Mutator() { }
|
explicit Mutator() { }
|
||||||
private:
|
private:
|
||||||
virtual ~Mutator() { }
|
virtual ~Mutator() { }
|
||||||
|
|
||||||
|
MOZ_MUST_USE NS_IMETHOD
|
||||||
|
Deserialize(const mozilla::ipc::URIParams& aParams) override
|
||||||
|
{
|
||||||
|
return InitFromIPCParams(aParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_MUST_USE NS_IMETHOD
|
||||||
|
Read(nsIObjectInputStream* aStream) override
|
||||||
|
{
|
||||||
|
return InitFromInputStream(aStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_MUST_USE NS_IMETHOD
|
||||||
|
Finalize(nsIURI** aURI) override
|
||||||
|
{
|
||||||
|
mURI->mMutable = false;
|
||||||
|
mURI.forget(aURI);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_MUST_USE NS_IMETHOD
|
||||||
|
SetSpec(const nsACString& aSpec, nsIURIMutator** aMutator) override
|
||||||
|
{
|
||||||
|
if (aMutator) {
|
||||||
|
NS_ADDREF(*aMutator = this);
|
||||||
|
}
|
||||||
|
return InitFromSpec(aSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetMutable()
|
||||||
|
{
|
||||||
|
if (mURI) {
|
||||||
|
mURI->mMutable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
friend class nsNestedAboutURI;
|
friend class nsNestedAboutURI;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
#include "nsError.h"
|
#include "nsError.h"
|
||||||
#include "DataChannelChild.h"
|
#include "DataChannelChild.h"
|
||||||
#include "plstr.h"
|
#include "plstr.h"
|
||||||
|
#include "nsSimpleURI.h"
|
||||||
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -64,7 +63,7 @@ nsDataHandler::NewURI(const nsACString &aSpec,
|
|||||||
nsIURI *aBaseURI,
|
nsIURI *aBaseURI,
|
||||||
nsIURI **result) {
|
nsIURI **result) {
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
RefPtr<nsIURI> uri;
|
nsCOMPtr<nsIURI> uri;
|
||||||
|
|
||||||
nsCString spec(aSpec);
|
nsCString spec(aSpec);
|
||||||
|
|
||||||
@@ -94,10 +93,9 @@ nsDataHandler::NewURI(const nsACString &aSpec,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uri = do_CreateInstance(kSimpleURICID, &rv);
|
rv = NS_MutateURI(new nsSimpleURI::Mutator())
|
||||||
if (NS_FAILED(rv))
|
.SetSpec(spec)
|
||||||
return rv;
|
.Finalize(uri);
|
||||||
rv = uri->SetSpec(spec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
|
|||||||
@@ -75,18 +75,19 @@ nsViewSourceHandler::NewURI(const nsACString &aSpec,
|
|||||||
|
|
||||||
// We can't swap() from an RefPtr<nsSimpleNestedURI> to an nsIURI**,
|
// We can't swap() from an RefPtr<nsSimpleNestedURI> to an nsIURI**,
|
||||||
// sadly.
|
// sadly.
|
||||||
nsSimpleNestedURI* ourURI = new nsSimpleNestedURI(innerURI);
|
RefPtr<nsSimpleNestedURI> ourURI = new nsSimpleNestedURI(innerURI);
|
||||||
nsCOMPtr<nsIURI> uri = ourURI;
|
|
||||||
if (!uri)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
rv = ourURI->SetSpec(asciiSpec);
|
nsCOMPtr<nsIURI> uri;
|
||||||
if (NS_FAILED(rv))
|
rv = NS_MutateURI(ourURI)
|
||||||
|
.SetSpec(asciiSpec)
|
||||||
|
.Finalize(uri);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
// Make the URI immutable so it's impossible to get it out of sync
|
// Make the URI immutable so it's impossible to get it out of sync
|
||||||
// with its inner URI.
|
// with its inner URI.
|
||||||
ourURI->SetMutable(false);
|
NS_TryToSetImmutable(uri);
|
||||||
|
|
||||||
uri.swap(*aResult);
|
uri.swap(*aResult);
|
||||||
return rv;
|
return rv;
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
#include "mozilla/net/HttpAuthUtils.h"
|
#include "mozilla/net/HttpAuthUtils.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
#include "nsIURL.h"
|
#include "nsNetUtil.h"
|
||||||
#include "nsNetCID.h"
|
|
||||||
#include "nsComponentManagerUtils.h"
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace net {
|
namespace net {
|
||||||
@@ -12,31 +10,29 @@ namespace net {
|
|||||||
#define TEST_PREF "network.http_test.auth_utils"
|
#define TEST_PREF "network.http_test.auth_utils"
|
||||||
|
|
||||||
TEST(TestHttpAuthUtils, Bug1351301) {
|
TEST(TestHttpAuthUtils, Bug1351301) {
|
||||||
nsCOMPtr<nsIURL> url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) );
|
nsCOMPtr<nsIURI> url;
|
||||||
ASSERT_TRUE(url) << "couldn't create URL";
|
|
||||||
|
|
||||||
nsAutoCString spec;
|
nsAutoCString spec;
|
||||||
|
|
||||||
ASSERT_EQ(Preferences::SetCString(TEST_PREF, "bar.com"), NS_OK);
|
ASSERT_EQ(Preferences::SetCString(TEST_PREF, "bar.com"), NS_OK);
|
||||||
spec = "http://bar.com";
|
spec = "http://bar.com";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(auth::URIMatchesPrefPattern(url,TEST_PREF), true);
|
ASSERT_EQ(auth::URIMatchesPrefPattern(url,TEST_PREF), true);
|
||||||
|
|
||||||
spec = "http://foo.bar.com";
|
spec = "http://foo.bar.com";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(auth::URIMatchesPrefPattern(url,TEST_PREF), true);
|
ASSERT_EQ(auth::URIMatchesPrefPattern(url,TEST_PREF), true);
|
||||||
|
|
||||||
spec = "http://foobar.com";
|
spec = "http://foobar.com";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(auth::URIMatchesPrefPattern(url,TEST_PREF), false);
|
ASSERT_EQ(auth::URIMatchesPrefPattern(url,TEST_PREF), false);
|
||||||
|
|
||||||
ASSERT_EQ(Preferences::SetCString(TEST_PREF, ".bar.com"), NS_OK);
|
ASSERT_EQ(Preferences::SetCString(TEST_PREF, ".bar.com"), NS_OK);
|
||||||
spec = "http://foo.bar.com";
|
spec = "http://foo.bar.com";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(auth::URIMatchesPrefPattern(url,TEST_PREF), true);
|
ASSERT_EQ(auth::URIMatchesPrefPattern(url,TEST_PREF), true);
|
||||||
|
|
||||||
spec = "http://bar.com";
|
spec = "http://bar.com";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(auth::URIMatchesPrefPattern(url,TEST_PREF), false);
|
ASSERT_EQ(auth::URIMatchesPrefPattern(url,TEST_PREF), false);
|
||||||
|
|
||||||
ASSERT_EQ(Preferences::ClearUser(TEST_PREF), NS_OK);
|
ASSERT_EQ(Preferences::ClearUser(TEST_PREF), NS_OK);
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsNetCID.h"
|
#include "nsNetCID.h"
|
||||||
#include "nsIURL.h"
|
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsComponentManagerUtils.h"
|
#include "nsComponentManagerUtils.h"
|
||||||
#include "../../base/nsProtocolProxyService.h"
|
#include "../../base/nsProtocolProxyService.h"
|
||||||
#include "nsServiceManagerUtils.h"
|
#include "nsServiceManagerUtils.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
|
#include "nsNetUtil.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace net {
|
namespace net {
|
||||||
@@ -17,68 +17,66 @@ TEST(TestProtocolProxyService, LoadHostFilters) {
|
|||||||
ASSERT_TRUE(ps);
|
ASSERT_TRUE(ps);
|
||||||
mozilla::net::nsProtocolProxyService* pps = static_cast<mozilla::net::nsProtocolProxyService*>(ps.get());
|
mozilla::net::nsProtocolProxyService* pps = static_cast<mozilla::net::nsProtocolProxyService*>(ps.get());
|
||||||
|
|
||||||
nsCOMPtr<nsIURL> url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) );
|
nsCOMPtr<nsIURI> url;
|
||||||
ASSERT_TRUE(url) << "couldn't create URL";
|
|
||||||
|
|
||||||
nsAutoCString spec;
|
nsAutoCString spec;
|
||||||
|
|
||||||
auto CheckLoopbackURLs = [&](bool expected)
|
auto CheckLoopbackURLs = [&](bool expected)
|
||||||
{
|
{
|
||||||
// loopback IPs are always filtered
|
// loopback IPs are always filtered
|
||||||
spec = "http://127.0.0.1";
|
spec = "http://127.0.0.1";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
spec = "http://[::1]";
|
spec = "http://[::1]";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto CheckURLs = [&](bool expected)
|
auto CheckURLs = [&](bool expected)
|
||||||
{
|
{
|
||||||
spec = "http://example.com";
|
spec = "http://example.com";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
|
|
||||||
spec = "https://10.2.3.4";
|
spec = "https://10.2.3.4";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 443), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 443), expected);
|
||||||
|
|
||||||
spec = "http://1.2.3.4";
|
spec = "http://1.2.3.4";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
|
|
||||||
spec = "http://1.2.3.4:8080";
|
spec = "http://1.2.3.4:8080";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
|
|
||||||
spec = "http://[2001::1]";
|
spec = "http://[2001::1]";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
|
|
||||||
spec = "http://2.3.4.5:7777";
|
spec = "http://2.3.4.5:7777";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
|
|
||||||
spec = "http://[abcd::2]:123";
|
spec = "http://[abcd::2]:123";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
|
|
||||||
spec = "http://bla.test.com";
|
spec = "http://bla.test.com";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto CheckPortDomain = [&](bool expected)
|
auto CheckPortDomain = [&](bool expected)
|
||||||
{
|
{
|
||||||
spec = "http://blabla.com:10";
|
spec = "http://blabla.com:10";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto CheckLocalDomain = [&](bool expected)
|
auto CheckLocalDomain = [&](bool expected)
|
||||||
{
|
{
|
||||||
spec = "http://test";
|
spec = "http://test";
|
||||||
ASSERT_EQ(url->SetSpec(spec), NS_OK);
|
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||||
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
ASSERT_EQ(pps->CanUseProxy(url, 80), expected);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ extern nsresult Test_NormalizeIPv4(const nsACString& host, nsCString& result);
|
|||||||
TEST(TestStandardURL, Simple) {
|
TEST(TestStandardURL, Simple) {
|
||||||
nsCOMPtr<nsIURL> url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) );
|
nsCOMPtr<nsIURL> url( do_CreateInstance(NS_STANDARDURL_CONTRACTID) );
|
||||||
ASSERT_TRUE(url);
|
ASSERT_TRUE(url);
|
||||||
ASSERT_EQ(url->SetSpec(NS_LITERAL_CSTRING("http://example.com")), NS_OK);
|
ASSERT_EQ(url->SetSpecInternal(NS_LITERAL_CSTRING("http://example.com")), NS_OK);
|
||||||
|
|
||||||
nsAutoCString out;
|
nsAutoCString out;
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ MOZ_GTEST_BENCH(TestStandardURL, Perf, [] {
|
|||||||
nsAutoCString out;
|
nsAutoCString out;
|
||||||
|
|
||||||
for (int i = COUNT; i; --i) {
|
for (int i = COUNT; i; --i) {
|
||||||
ASSERT_EQ(url->SetSpec(NS_LITERAL_CSTRING("http://example.com")), NS_OK);
|
ASSERT_EQ(url->SetSpecInternal(NS_LITERAL_CSTRING("http://example.com")), NS_OK);
|
||||||
ASSERT_EQ(url->GetSpec(out), NS_OK);
|
ASSERT_EQ(url->GetSpec(out), NS_OK);
|
||||||
url->Resolve(NS_LITERAL_CSTRING("foo.html?q=45"), out);
|
url->Resolve(NS_LITERAL_CSTRING("foo.html?q=45"), out);
|
||||||
url->SetScheme(NS_LITERAL_CSTRING("foo"));
|
url->SetScheme(NS_LITERAL_CSTRING("foo"));
|
||||||
|
|||||||
@@ -625,7 +625,7 @@ function do_test_immutable(aTest) {
|
|||||||
|
|
||||||
var URI = NetUtil.newURI(aTest.spec);
|
var URI = NetUtil.newURI(aTest.spec);
|
||||||
// All the non-readonly attributes on nsIURI.idl:
|
// All the non-readonly attributes on nsIURI.idl:
|
||||||
var propertiesToCheck = ["spec", "scheme", "userPass", "username", "password",
|
var propertiesToCheck = ["scheme", "userPass", "username", "password",
|
||||||
"hostPort", "host", "port", "pathQueryRef", "query", "ref"];
|
"hostPort", "host", "port", "pathQueryRef", "query", "ref"];
|
||||||
|
|
||||||
propertiesToCheck.forEach(function(aProperty) {
|
propertiesToCheck.forEach(function(aProperty) {
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ add_test(function test_hugeStringThrows()
|
|||||||
let url = stringToURL("http://test:test@example.com");
|
let url = stringToURL("http://test:test@example.com");
|
||||||
|
|
||||||
let hugeString = new Array(maxLen + 1).fill("a").join("");
|
let hugeString = new Array(maxLen + 1).fill("a").join("");
|
||||||
let properties = ["spec", "scheme", "userPass", "username",
|
let properties = ["scheme", "userPass", "username",
|
||||||
"password", "hostPort", "host", "pathQueryRef", "ref",
|
"password", "hostPort", "host", "pathQueryRef", "ref",
|
||||||
"query", "fileName", "filePath", "fileBaseName", "fileExtension"];
|
"query", "fileName", "filePath", "fileBaseName", "fileExtension"];
|
||||||
for (let prop of properties) {
|
for (let prop of properties) {
|
||||||
@@ -312,6 +312,10 @@ add_test(function test_hugeStringThrows()
|
|||||||
`Passing a huge string to "${prop}" should throw`);
|
`Passing a huge string to "${prop}" should throw`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Assert.throws(() => { url = url.mutate().setSpec(hugeString).finalize(); },
|
||||||
|
/NS_ERROR_MALFORMED_URI/,
|
||||||
|
"Passing a huge string to setSpec should throw");
|
||||||
|
|
||||||
run_next_test();
|
run_next_test();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
#include "mozilla/Maybe.h"
|
#include "mozilla/Maybe.h"
|
||||||
#include "mozilla/Printf.h"
|
#include "mozilla/Printf.h"
|
||||||
#include "mozilla/UniquePtr.h"
|
#include "mozilla/UniquePtr.h"
|
||||||
|
#include "nsNetCID.h"
|
||||||
|
#include "nsIURIMutator.h"
|
||||||
|
|
||||||
using namespace JS;
|
using namespace JS;
|
||||||
|
|
||||||
@@ -127,12 +129,12 @@ TEST_F(TestStartupCache, WriteObject)
|
|||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> obj
|
nsCOMPtr<nsIURI> obj;
|
||||||
= do_CreateInstance("@mozilla.org/network/simple-uri;1");
|
|
||||||
ASSERT_TRUE(obj);
|
|
||||||
|
|
||||||
NS_NAMED_LITERAL_CSTRING(spec, "http://www.mozilla.org");
|
NS_NAMED_LITERAL_CSTRING(spec, "http://www.mozilla.org");
|
||||||
rv = obj->SetSpec(spec);
|
rv = NS_MutateURI(NS_SIMPLEURIMUTATOR_CONTRACTID)
|
||||||
|
.SetSpec(spec)
|
||||||
|
.Finalize(obj);
|
||||||
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
EXPECT_TRUE(NS_SUCCEEDED(rv));
|
||||||
|
|
||||||
StartupCache* sc = StartupCache::GetSingleton();
|
StartupCache* sc = StartupCache::GetSingleton();
|
||||||
|
|||||||
Reference in New Issue
Block a user