Bug 1442239 - Make URI deserialization (nsISerializable.read) happen via nsIURIMutator only r=mayhemer

* Deserialization now only happens via a mutator
* The CID for URI implementations actually returns the nsIURIMutator for each class
* The QueryInterface of mutators implementing nsISerializable will now act as a finalizer if passed the IID of an interface implemented by the URI it holds

MozReview-Commit-ID: H5MUJOEkpia

--HG--
extra : rebase_source : 01c8d16f7d31977eda6ca061e7889cedbf6940c2
This commit is contained in:
Valentin Gosu 2018-03-19 20:22:32 +01:00
parent f80768ca40
commit af5eeff2e3
24 changed files with 299 additions and 81 deletions

View File

@ -84,11 +84,6 @@ public:
return InitFromIPCParams(aParams);
}
NS_IMETHOD Read(nsIObjectInputStream* aStream) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD Finalize(nsIURI** aURI) override
{
mURI.forget(aURI);

View File

@ -75,7 +75,7 @@ nsHostObjectURI::GetPrincipalUri(nsIURI** aUri)
NS_IMETHODIMP
nsHostObjectURI::Read(nsIObjectInputStream* aStream)
{
nsresult rv = mozilla::net::nsSimpleURI::Read(aStream);
nsresult rv = mozilla::net::nsSimpleURI::ReadPrivate(aStream);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupports> supports;
@ -230,7 +230,13 @@ nsHostObjectURI::EqualsInternal(nsIURI* aOther,
return NS_OK;
}
NS_IMPL_ISUPPORTS(nsHostObjectURI::Mutator, nsIURISetters, nsIURIMutator, nsIBlobURIMutator, nsIPrincipalURIMutator)
// Queries this list of interfaces. If none match, it queries mURI.
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsHostObjectURI::Mutator,
nsIURISetters,
nsIURIMutator,
nsIBlobURIMutator,
nsIPrincipalURIMutator,
nsISerializable)
NS_IMETHODIMP
nsHostObjectURI::Mutate(nsIURIMutator** aMutator)

View File

@ -85,11 +85,24 @@ public:
, public BaseURIMutator<nsHostObjectURI>
, public nsIBlobURIMutator
, public nsIPrincipalURIMutator
, public nsISerializable
{
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
NS_DEFINE_NSIMUTATOR_COMMON
NS_IMETHOD
Write(nsIObjectOutputStream *aOutputStream) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
MOZ_MUST_USE NS_IMETHOD
Read(nsIObjectInputStream* aStream) override
{
return InitFromInputStream(aStream);
}
MOZ_MUST_USE NS_IMETHOD
SetBlobImpl(mozilla::dom::BlobImpl *aBlobImpl) override
{
@ -124,4 +137,8 @@ public:
{ 0xf5475c51, 0x59a7, 0x4757, \
{ 0xb3, 0xd9, 0xe2, 0x11, 0xa9, 0x41, 0x08, 0x72 } }
#define NS_HOSTOBJECTURIMUTATOR_CID \
{ 0xbbe50ef2, 0x80eb, 0x469d, \
{ 0xb7, 0x0d, 0x02, 0x85, 0x82, 0x75, 0x38, 0x9f } }
#endif /* nsHostObjectURI_h */

View File

@ -1283,9 +1283,16 @@ NS_INTERFACE_MAP_END_INHERITING(mozilla::net::nsSimpleURI)
// nsISerializable methods:
NS_IMETHODIMP
nsJSURI::Read(nsIObjectInputStream* aStream)
nsJSURI::Read(nsIObjectInputStream *aStream)
{
nsresult rv = mozilla::net::nsSimpleURI::Read(aStream);
NS_NOTREACHED("Use nsIURIMutator.read() instead");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsJSURI::ReadPrivate(nsIObjectInputStream *aStream)
{
nsresult rv = mozilla::net::nsSimpleURI::ReadPrivate(aStream);
if (NS_FAILED(rv)) return rv;
bool haveBase;
@ -1380,7 +1387,11 @@ nsJSURI::StartClone(mozilla::net::nsSimpleURI::RefHandlingEnum refHandlingMode,
return url;
}
NS_IMPL_ISUPPORTS(nsJSURI::Mutator, nsIURISetters, nsIURIMutator)
// Queries this list of interfaces. If none match, it queries mURI.
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsJSURI::Mutator,
nsIURISetters,
nsIURIMutator,
nsISerializable)
NS_IMETHODIMP
nsJSURI::Mutate(nsIURIMutator** aMutator)

View File

@ -31,6 +31,14 @@
{0xa9, 0x35, 0xd0, 0xc8, 0x74, 0x12, 0x89, 0x30} \
}
#define NS_JSURIMUTATOR_CID \
{ /* 574ce83e-fe9f-4095-b85c-7909abbf7c37 */ \
0x574ce83e, \
0xfe9f, \
0x4095, \
{0xb8, 0x5c, 0x79, 0x09, 0xab, 0xbf, 0x7c, 0x37} \
}
#define NS_JSPROTOCOLHANDLER_CONTRACTID \
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "javascript"
@ -103,6 +111,7 @@ protected:
RefHandlingEnum refHandlingMode,
bool* result) override;
bool Deserialize(const mozilla::ipc::URIParams&);
nsresult ReadPrivate(nsIObjectInputStream *aStream);
private:
nsCOMPtr<nsIURI> mBaseURI;
@ -111,11 +120,24 @@ public:
class Mutator final
: public nsIURIMutator
, public BaseURIMutator<nsJSURI>
, public nsISerializable
{
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
NS_DEFINE_NSIMUTATOR_COMMON
NS_IMETHOD
Write(nsIObjectOutputStream *aOutputStream) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
MOZ_MUST_USE NS_IMETHOD
Read(nsIObjectInputStream* aStream) override
{
return InitFromInputStream(aStream);
}
explicit Mutator() { }
private:
virtual ~Mutator() { }

View File

@ -77,11 +77,6 @@ public:
return InitFromIPCParams(aParams);
}
NS_IMETHOD Read(nsIObjectInputStream* aStream) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD Finalize(nsIURI** aURI) override
{
mURI.forget(aURI);

View File

@ -220,7 +220,8 @@ already_AddRefed<nsIPresentationService> NS_CreatePresentationService();
// Factory Constructor
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(txNodeSetAdaptor, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSerializer)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHostObjectURI)
typedef nsHostObjectURI::Mutator nsHostObjectURIMutator;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHostObjectURIMutator)
NS_GENERIC_FACTORY_CONSTRUCTOR(DOMParser)
NS_GENERIC_FACTORY_CONSTRUCTOR(LocalStorageManager)
NS_GENERIC_FACTORY_CONSTRUCTOR(SessionStorageManager)
@ -434,7 +435,8 @@ MAKE_CTOR(CreateFocusManager, nsIFocusManager, NS_NewFocusManag
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsStyleSheetService, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSURI)
typedef nsJSURI::Mutator nsJSURIMutator;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSURIMutator)
// views are not refcounted, so this is the same as
// NS_GENERIC_FACTORY_CONSTRUCTOR without the NS_ADDREF/NS_RELEASE
@ -573,6 +575,7 @@ NS_DEFINE_NAMED_CID(NS_XULDOCUMENT_CID);
NS_DEFINE_NAMED_CID(NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID);
NS_DEFINE_NAMED_CID(NS_JSPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_JSURI_CID);
NS_DEFINE_NAMED_CID(NS_JSURIMUTATOR_CID);
NS_DEFINE_NAMED_CID(NS_WINDOWCOMMANDTABLE_CID);
NS_DEFINE_NAMED_CID(NS_WINDOWCONTROLLER_CID);
NS_DEFINE_NAMED_CID(NS_PLUGINDOCLOADERFACTORY_CID);
@ -582,6 +585,7 @@ NS_DEFINE_NAMED_CID(NS_STYLESHEETSERVICE_CID);
NS_DEFINE_NAMED_CID(TRANSFORMIIX_NODESET_CID);
NS_DEFINE_NAMED_CID(NS_XMLSERIALIZER_CID);
NS_DEFINE_NAMED_CID(NS_HOSTOBJECTURI_CID);
NS_DEFINE_NAMED_CID(NS_HOSTOBJECTURIMUTATOR_CID);
NS_DEFINE_NAMED_CID(NS_DOMPARSER_CID);
NS_DEFINE_NAMED_CID(NS_DOMSESSIONSTORAGEMANAGER_CID);
NS_DEFINE_NAMED_CID(NS_DOMLOCALSTORAGEMANAGER_CID);
@ -819,7 +823,8 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
#endif
{ &kNS_CONTENT_DOCUMENT_LOADER_FACTORY_CID, false, nullptr, CreateContentDLF },
{ &kNS_JSPROTOCOLHANDLER_CID, false, nullptr, nsJSProtocolHandler::Create },
{ &kNS_JSURI_CID, false, nullptr, nsJSURIConstructor },
{ &kNS_JSURI_CID, false, nullptr, nsJSURIMutatorConstructor }, // do_CreateInstance returns mutator
{ &kNS_JSURIMUTATOR_CID, false, nullptr, nsJSURIMutatorConstructor },
{ &kNS_WINDOWCOMMANDTABLE_CID, false, nullptr, CreateWindowCommandTableConstructor },
{ &kNS_WINDOWCONTROLLER_CID, false, nullptr, CreateWindowControllerWithSingletonCommandTable },
{ &kNS_PLUGINDOCLOADERFACTORY_CID, false, nullptr, CreateContentDLF },
@ -828,7 +833,8 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kNS_STYLESHEETSERVICE_CID, false, nullptr, nsStyleSheetServiceConstructor },
{ &kTRANSFORMIIX_NODESET_CID, false, nullptr, txNodeSetAdaptorConstructor },
{ &kNS_XMLSERIALIZER_CID, false, nullptr, nsDOMSerializerConstructor },
{ &kNS_HOSTOBJECTURI_CID, false, nullptr, nsHostObjectURIConstructor },
{ &kNS_HOSTOBJECTURI_CID, false, nullptr, nsHostObjectURIMutatorConstructor }, // do_CreateInstance returns mutator
{ &kNS_HOSTOBJECTURIMUTATOR_CID, false, nullptr, nsHostObjectURIMutatorConstructor },
{ &kNS_DOMPARSER_CID, false, nullptr, DOMParserConstructor },
{ &kNS_DOMSESSIONSTORAGEMANAGER_CID, false, nullptr, SessionStorageManagerConstructor },
{ &kNS_DOMLOCALSTORAGEMANAGER_CID, false, nullptr, LocalStorageManagerConstructor },

View File

@ -20,7 +20,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsJAR)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsZipReaderCache)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsJARProtocolHandler,
nsJARProtocolHandler::GetSingleton)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsJARURI)
typedef nsJARURI::Mutator nsJARURIMutator;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsJARURIMutator)
@ -35,7 +34,7 @@ static const mozilla::Module::CIDEntry kJARCIDs[] = {
{ &kNS_ZIPREADER_CID, false, nullptr, nsJARConstructor },
{ &kNS_ZIPREADERCACHE_CID, false, nullptr, nsZipReaderCacheConstructor },
{ &kNS_JARPROTOCOLHANDLER_CID, false, nullptr, nsJARProtocolHandlerConstructor },
{ &kNS_JARURI_CID, false, nullptr, nsJARURIConstructor },
{ &kNS_JARURI_CID, false, nullptr, nsJARURIMutatorConstructor }, // do_CreateInstance returns mutator
{ &kNS_JARURIMUTATOR_CID, false, nullptr, nsJARURIMutatorConstructor },
{ nullptr }
};

View File

@ -107,7 +107,14 @@ nsJARURI::CreateEntryURL(const nsACString& entryFilename,
// nsISerializable methods:
NS_IMETHODIMP
nsJARURI::Read(nsIObjectInputStream* aInputStream)
nsJARURI::Read(nsIObjectInputStream *aStream)
{
NS_NOTREACHED("Use nsIURIMutator.read() instead");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsJARURI::ReadPrivate(nsIObjectInputStream *aInputStream)
{
nsresult rv;
@ -256,7 +263,12 @@ nsJARURI::SetSpecInternal(const nsACString& aSpec)
return SetSpecWithBase(aSpec, nullptr);
}
NS_IMPL_ISUPPORTS(nsJARURI::Mutator, nsIURISetters, nsIURIMutator, nsIURLMutator)
// Queries this list of interfaces. If none match, it queries mURI.
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsJARURI::Mutator,
nsIURISetters,
nsIURIMutator,
nsIURLMutator,
nsISerializable)
NS_IMETHODIMP
nsJARURI::Mutator::SetFileName(const nsACString& aFileName, nsIURIMutator** aMutator)

View File

@ -114,6 +114,7 @@ private:
nsresult SetQuery(const nsACString &input);
nsresult SetQueryWithEncoding(const nsACString &input, const Encoding* encoding);
bool Deserialize(const mozilla::ipc::URIParams&);
nsresult ReadPrivate(nsIObjectInputStream *aStream);
nsresult SetFileNameInternal(const nsACString& fileName);
nsresult SetFileBaseNameInternal(const nsACString& fileBaseName);
@ -124,12 +125,25 @@ public:
: public nsIURIMutator
, public BaseURIMutator<nsJARURI>
, public nsIURLMutator
, public nsISerializable
{
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
NS_DEFINE_NSIMUTATOR_COMMON
NS_DECL_NSIURLMUTATOR
NS_IMETHOD
Write(nsIObjectOutputStream *aOutputStream) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
MOZ_MUST_USE NS_IMETHOD
Read(nsIObjectInputStream* aStream) override
{
return InitFromInputStream(aStream);
}
explicit Mutator() { }
private:
virtual ~Mutator() { }

View File

@ -46,7 +46,7 @@ protected:
MOZ_MUST_USE nsresult InitFromInputStream(nsIObjectInputStream* aStream)
{
RefPtr<T> uri = new T();
nsresult rv = uri->Read(aStream);
nsresult rv = uri->ReadPrivate(aStream);
if (NS_FAILED(rv)) {
return rv;
}
@ -98,12 +98,6 @@ protected:
} \
\
MOZ_MUST_USE NS_IMETHOD \
Read(nsIObjectInputStream* aStream) override \
{ \
return InitFromInputStream(aStream); \
} \
\
MOZ_MUST_USE NS_IMETHOD \
Finalize(nsIURI** aURI) override \
{ \
mURI.forget(aURI); return NS_OK; \
@ -115,6 +109,39 @@ protected:
if (aMutator) NS_ADDREF(*aMutator = this); \
return InitFromSpec(aSpec); \
} \
// Implements AddRef, Release and QueryInterface for the mutator
#define NS_IMPL_NSIURIMUTATOR_ISUPPORTS(aClass, ...) \
NS_IMPL_ADDREF(aClass) \
NS_IMPL_RELEASE(aClass) \
NS_IMPL_NSIURIMUTATOR_QUERY_INTERFACE(aClass, __VA_ARGS__) \
// The list of interfaces is queried and an AddRef-ed pointer is returned if
// there is a match. Otherwise, we call QueryInterface on mURI and return.
// The reason for this specialized QueryInterface implementation is that we
// we want to be able to instantiate the mutator for a given CID of a
// nsIURI implementation, call nsISerializable.Read() on the mutator to
// deserialize the URI then QueryInterface the mutator to an nsIURI interface.
// See bug 1442239.
// If you QueryInterface a mutator to an interface of the URI
// implementation this is similar to calling Finalize.
#define NS_IMPL_NSIURIMUTATOR_QUERY_INTERFACE(aClass, ...) \
static_assert(MOZ_ARG_COUNT(__VA_ARGS__) > 0, \
"Need more arguments"); \
NS_INTERFACE_MAP_BEGIN(aClass) \
nsCOMPtr<nsIURI> uri; \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURIMutator) \
MOZ_FOR_EACH(NS_INTERFACE_MAP_ENTRY, (), (__VA_ARGS__)) \
if (aIID.Equals(NS_GET_IID(nsIClassInfo))) { \
foundInterface = nullptr; \
} else \
if (mURI && \
NS_SUCCEEDED(mURI->QueryInterface(aIID, getter_AddRefs(uri)))) { \
mURI = nullptr; \
foundInterface = uri.get(); \
} else \
NS_INTERFACE_MAP_END \
%}
[ptr] native Encoding(const mozilla::Encoding);
@ -252,14 +279,6 @@ interface nsIURISetters : nsIURISetSpec
[scriptable, builtinclass, uuid(4d1f3103-1c44-4dcd-b717-5d22a697a7d9)]
interface nsIURIMutator : nsIURISetters
{
/**
* Initializes the URI by reading from the input stream.
* The input stream must contain the serialization of the same object type.
* See nsISerializable.
*/
[must_use]
void read(in nsIObjectInputStream aInputStream);
/**
* Initalizes the URI by reading IPC URIParams.
* See nsIIPCSerializableURI.

View File

@ -28,9 +28,16 @@ nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI)
// nsISerializable
NS_IMETHODIMP
nsSimpleNestedURI::Read(nsIObjectInputStream* aStream)
nsSimpleNestedURI::Read(nsIObjectInputStream *aStream)
{
nsresult rv = nsSimpleURI::Read(aStream);
NS_NOTREACHED("Use nsIURIMutator.read() instead");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsSimpleNestedURI::ReadPrivate(nsIObjectInputStream *aStream)
{
nsresult rv = nsSimpleURI::ReadPrivate(aStream);
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(!mMutable, "How did that happen?");
@ -186,7 +193,11 @@ nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
return NS_OK;
}
NS_IMPL_ISUPPORTS(nsSimpleNestedURI::Mutator, nsIURISetters, nsIURIMutator)
// Queries this list of interfaces. If none match, it queries mURI.
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsSimpleNestedURI::Mutator,
nsIURISetters,
nsIURIMutator,
nsISerializable)
NS_IMETHODIMP
nsSimpleNestedURI::Mutate(nsIURIMutator** aMutator)

View File

@ -71,11 +71,13 @@ protected:
nsCOMPtr<nsIURI> mInnerURI;
bool Deserialize(const mozilla::ipc::URIParams&);
nsresult ReadPrivate(nsIObjectInputStream *stream);
public:
class Mutator final
: public nsIURIMutator
, public BaseURIMutator<nsSimpleNestedURI>
, public nsISerializable
{
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
@ -90,6 +92,12 @@ public:
return InitFromIPCParams(aParams);
}
NS_IMETHOD
Write(nsIObjectOutputStream *aOutputStream) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
MOZ_MUST_USE NS_IMETHOD
Read(nsIObjectInputStream* aStream) override
{

View File

@ -75,7 +75,14 @@ NS_INTERFACE_MAP_END
// nsISerializable methods:
NS_IMETHODIMP
nsSimpleURI::Read(nsIObjectInputStream* aStream)
nsSimpleURI::Read(nsIObjectInputStream *aStream)
{
NS_NOTREACHED("Use nsIURIMutator.read() instead");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsSimpleURI::ReadPrivate(nsIObjectInputStream *aStream)
{
nsresult rv;
@ -877,8 +884,11 @@ nsSimpleURI::SetQueryWithEncoding(const nsACString& aQuery,
return SetQuery(aQuery);
}
NS_IMPL_ISUPPORTS(nsSimpleURI::Mutator, nsIURISetters, nsIURIMutator)
// Queries this list of interfaces. If none match, it queries mURI.
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsSimpleURI::Mutator,
nsIURISetters,
nsIURIMutator,
nsISerializable)
NS_IMETHODIMP
nsSimpleURI::Mutate(nsIURIMutator** aMutator)

View File

@ -88,6 +88,7 @@ protected:
virtual nsresult SetFilePath(const nsACString &input);
virtual nsresult SetQuery(const nsACString &input);
virtual nsresult SetQueryWithEncoding(const nsACString &input, const Encoding* encoding);
nsresult ReadPrivate(nsIObjectInputStream *stream);
// Helper to share code between Equals methods.
virtual nsresult EqualsInternal(nsIURI* other,
@ -132,11 +133,24 @@ public:
class Mutator final
: public nsIURIMutator
, public BaseURIMutator<nsSimpleURI>
, public nsISerializable
{
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
NS_DEFINE_NSIMUTATOR_COMMON
NS_IMETHOD
Write(nsIObjectOutputStream *aOutputStream) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
MOZ_MUST_USE NS_IMETHOD
Read(nsIObjectInputStream* aStream) override
{
return InitFromInputStream(aStream);
}
explicit Mutator() { }
private:
virtual ~Mutator() { }

View File

@ -2219,12 +2219,14 @@ nsStandardURL::SetPathQueryRef(const nsACString &input)
}
// When updating this also update SubstitutingURL::Mutator
NS_IMPL_ISUPPORTS(nsStandardURL::Mutator,
nsIURISetters,
nsIURIMutator,
nsIStandardURLMutator,
nsIURLMutator,
nsIFileURLMutator)
// Queries this list of interfaces. If none match, it queries mURI.
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsStandardURL::Mutator,
nsIURISetters,
nsIURIMutator,
nsIStandardURLMutator,
nsIURLMutator,
nsIFileURLMutator,
nsISerializable)
NS_IMETHODIMP
nsStandardURL::Mutate(nsIURIMutator** aMutator)
@ -3386,6 +3388,13 @@ nsStandardURL::SetMutable(bool value)
NS_IMETHODIMP
nsStandardURL::Read(nsIObjectInputStream *stream)
{
NS_NOTREACHED("Use nsIURIMutator.read() instead");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsStandardURL::ReadPrivate(nsIObjectInputStream *stream)
{
NS_PRECONDITION(mDisplayHost.IsEmpty(), "Shouldn't have cached unicode host");
NS_PRECONDITION(mSpecEncoding == eEncoding_Unknown,

View File

@ -194,6 +194,7 @@ protected:
virtual nsresult SetQuery(const nsACString &input);
virtual nsresult SetQueryWithEncoding(const nsACString &input, const Encoding* encoding);
bool Deserialize(const mozilla::ipc::URIParams&);
nsresult ReadPrivate(nsIObjectInputStream *stream);
private:
nsresult Init(uint32_t urlType, int32_t defaultPort, const nsACString &spec,
@ -347,6 +348,7 @@ public:
, public nsIStandardURLMutator
, public nsIURLMutator
, public nsIFileURLMutator
, public nsISerializable
{
NS_FORWARD_SAFE_NSIURISETTERS_RET(BaseURIMutator<T>::mURI)
@ -356,6 +358,13 @@ public:
return BaseURIMutator<T>::InitFromIPCParams(aParams);
}
NS_IMETHOD
Write(nsIObjectOutputStream *aOutputStream) override
{
NS_NOTREACHED("Use nsIURIMutator.read() instead");
return NS_ERROR_NOT_IMPLEMENTED;
}
MOZ_MUST_USE NS_IMETHOD
Read(nsIObjectInputStream* aStream) override
{

View File

@ -101,6 +101,14 @@
{ 0xa7, 0x85, 0x85, 0xc3, 0x94, 0x01, 0x25, 0x03 } \
}
#define NS_SIMPLENESTEDURIMUTATOR_CID \
{ /* 9c4e9d49-ce64-4ca3-acef-3075c5e5aba7 */ \
0x9c4e9d49, \
0xce64, \
0x4ca3, \
{ 0xac, 0xef, 0x30, 0x75, 0xc5, 0xe5, 0xab, 0xa7 } \
}
// component inheriting from the nested simple URI component and also
// carrying along its base URI
#define NS_NESTEDABOUTURI_CID \
@ -111,6 +119,14 @@
{ 0xb9, 0x36, 0x41, 0x32, 0x6b, 0xa4, 0x8a, 0xae } \
}
#define NS_NESTEDABOUTURIMUTATOR_CID \
{ /* b0054ef3-b096-483d-8242-4ee36b7b2115 */ \
0xb0054ef3, \
0xb096, \
0x483d, \
{ 0x82, 0x42, 0x4e, 0xe3, 0x6b, 0x7b, 0x21, 0x15 } \
}
// component implementing nsIStandardURL, nsIURI, nsIURL, nsISerializable,
// and nsIClassInfo.
#define NS_STANDARDURL_CONTRACTID \
@ -696,6 +712,13 @@
{ 0xbd, 0xe9, 0xcc, 0xef, 0x5d, 0x8a, 0xb4, 0x73 } \
}
#define NS_SUBSTITUTINGURLMUTATOR_CID \
{ 0xb3cfeb91, \
0x332a, \
0x46c9, \
{ 0xad, 0x97, 0x93, 0xff, 0x39, 0x84, 0x14, 0x94 } \
}
/******************************************************************************
* netwerk/protocol/file/ classes
*/

View File

@ -222,10 +222,10 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsWifiMonitor)
#include "nsAboutBlank.h"
typedef mozilla::net::nsAboutProtocolHandler nsAboutProtocolHandler;
typedef mozilla::net::nsSafeAboutProtocolHandler nsSafeAboutProtocolHandler;
typedef mozilla::net::nsNestedAboutURI nsNestedAboutURI;
typedef mozilla::net::nsNestedAboutURI::Mutator nsNestedAboutURIMutator;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAboutProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSafeAboutProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNestedAboutURI)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNestedAboutURIMutator)
// about
#include "nsAboutCache.h"
@ -294,12 +294,13 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(NamedPipeService, Init)
#include "nsResProtocolHandler.h"
#include "ExtensionProtocolHandler.h"
#include "SubstitutingProtocolHandler.h"
typedef mozilla::net::SubstitutingURL::Mutator SubstitutingURLMutator;
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsResProtocolHandler, Init)
namespace mozilla {
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ExtensionProtocolHandler,
ExtensionProtocolHandler::GetSingleton)
NS_GENERIC_FACTORY_CONSTRUCTOR(SubstitutingURL)
NS_GENERIC_FACTORY_CONSTRUCTOR(SubstitutingURLMutator)
} // namespace mozilla
#include "nsViewSourceHandler.h"
@ -363,17 +364,13 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAuthURLParser)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsStdURLParser)
#include "nsStandardURL.h"
typedef mozilla::net::nsStandardURL nsStandardURL;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsStandardURL)
typedef mozilla::net::nsStandardURL::Mutator nsStandardURLMutator;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsStandardURLMutator)
typedef mozilla::net::nsSimpleURI nsSimpleURI;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSimpleURI)
typedef mozilla::net::nsSimpleURI::Mutator nsSimpleURIMutator;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSimpleURIMutator)
typedef mozilla::net::nsSimpleNestedURI nsSimpleNestedURI;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSimpleNestedURI)
typedef mozilla::net::nsSimpleNestedURI::Mutator nsSimpleNestedURIMutator;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSimpleNestedURIMutator)
///////////////////////////////////////////////////////////////////////////////
@ -646,7 +643,7 @@ static nsresult nsNetStartup()
static void nsNetShutdown()
{
// Release the url parser that the stdurl is holding.
nsStandardURL::ShutdownGlobalObjects();
mozilla::net::nsStandardURL::ShutdownGlobalObjects();
// Release global state used by the URL helper module.
net_ShutdownURLHelper();
@ -681,6 +678,7 @@ NS_DEFINE_NAMED_CID(NS_EFFECTIVETLDSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_SIMPLEURI_CID);
NS_DEFINE_NAMED_CID(NS_SIMPLEURIMUTATOR_CID);
NS_DEFINE_NAMED_CID(NS_SIMPLENESTEDURI_CID);
NS_DEFINE_NAMED_CID(NS_SIMPLENESTEDURIMUTATOR_CID);
NS_DEFINE_NAMED_CID(NS_ASYNCSTREAMCOPIER_CID);
NS_DEFINE_NAMED_CID(NS_INPUTSTREAMPUMP_CID);
NS_DEFINE_NAMED_CID(NS_INPUTSTREAMCHANNEL_CID);
@ -742,10 +740,12 @@ NS_DEFINE_NAMED_CID(NS_FTPPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_RESPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_EXTENSIONPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_SUBSTITUTINGURL_CID);
NS_DEFINE_NAMED_CID(NS_SUBSTITUTINGURLMUTATOR_CID);
NS_DEFINE_NAMED_CID(NS_ABOUTPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_SAFEABOUTPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_ABOUT_BLANK_MODULE_CID);
NS_DEFINE_NAMED_CID(NS_NESTEDABOUTURI_CID);
NS_DEFINE_NAMED_CID(NS_NESTEDABOUTURIMUTATOR_CID);
NS_DEFINE_NAMED_CID(NS_ABOUT_CACHE_MODULE_CID);
NS_DEFINE_NAMED_CID(NS_ABOUT_CACHE_ENTRY_MODULE_CID);
NS_DEFINE_NAMED_CID(NS_SOCKSSOCKETPROVIDER_CID);
@ -798,9 +798,10 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
{ &kNS_DNSSERVICE_CID, false, nullptr, nsIDNSServiceConstructor },
{ &kNS_IDNSERVICE_CID, false, nullptr, nsIDNServiceConstructor },
{ &kNS_EFFECTIVETLDSERVICE_CID, false, nullptr, nsEffectiveTLDServiceConstructor },
{ &kNS_SIMPLEURI_CID, false, nullptr, nsSimpleURIConstructor },
{ &kNS_SIMPLEURI_CID, false, nullptr, nsSimpleURIMutatorConstructor }, // do_CreateInstance returns mutator
{ &kNS_SIMPLEURIMUTATOR_CID, false, nullptr, nsSimpleURIMutatorConstructor },
{ &kNS_SIMPLENESTEDURI_CID, false, nullptr, nsSimpleNestedURIConstructor },
{ &kNS_SIMPLENESTEDURI_CID, false, nullptr, nsSimpleNestedURIMutatorConstructor }, // do_CreateInstance returns mutator
{ &kNS_SIMPLENESTEDURIMUTATOR_CID, false, nullptr, nsSimpleNestedURIMutatorConstructor },
{ &kNS_ASYNCSTREAMCOPIER_CID, false, nullptr, nsAsyncStreamCopierConstructor },
{ &kNS_INPUTSTREAMPUMP_CID, false, nullptr, nsInputStreamPumpConstructor },
{ &kNS_INPUTSTREAMCHANNEL_CID, false, nullptr, nsInputStreamChannelConstructor },
@ -826,7 +827,7 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
{ &kNS_STDURLPARSER_CID, false, nullptr, nsStdURLParserConstructor },
{ &kNS_NOAUTHURLPARSER_CID, false, nullptr, nsNoAuthURLParserConstructor },
{ &kNS_AUTHURLPARSER_CID, false, nullptr, nsAuthURLParserConstructor },
{ &kNS_STANDARDURL_CID, false, nullptr, nsStandardURLConstructor },
{ &kNS_STANDARDURL_CID, false, nullptr, nsStandardURLMutatorConstructor }, // do_CreateInstance returns mutator
{ &kNS_STANDARDURLMUTATOR_CID, false, nullptr, nsStandardURLMutatorConstructor },
{ &kNS_ARRAYBUFFERINPUTSTREAM_CID, false, nullptr, ArrayBufferInputStreamConstructor },
{ &kNS_BUFFEREDINPUTSTREAM_CID, false, nullptr, nsBufferedInputStream::Create },
@ -863,11 +864,13 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
{ &kNS_FTPPROTOCOLHANDLER_CID, false, nullptr, nsFtpProtocolHandlerConstructor },
{ &kNS_RESPROTOCOLHANDLER_CID, false, nullptr, nsResProtocolHandlerConstructor },
{ &kNS_EXTENSIONPROTOCOLHANDLER_CID, false, nullptr, mozilla::ExtensionProtocolHandlerConstructor },
{ &kNS_SUBSTITUTINGURL_CID, false, nullptr, mozilla::SubstitutingURLConstructor },
{ &kNS_SUBSTITUTINGURL_CID, false, nullptr, mozilla::SubstitutingURLMutatorConstructor }, // do_CreateInstance returns mutator
{ &kNS_SUBSTITUTINGURLMUTATOR_CID, false, nullptr, mozilla::SubstitutingURLMutatorConstructor },
{ &kNS_ABOUTPROTOCOLHANDLER_CID, false, nullptr, nsAboutProtocolHandlerConstructor },
{ &kNS_SAFEABOUTPROTOCOLHANDLER_CID, false, nullptr, nsSafeAboutProtocolHandlerConstructor },
{ &kNS_ABOUT_BLANK_MODULE_CID, false, nullptr, nsAboutBlank::Create },
{ &kNS_NESTEDABOUTURI_CID, false, nullptr, nsNestedAboutURIConstructor },
{ &kNS_NESTEDABOUTURI_CID, false, nullptr, nsNestedAboutURIMutatorConstructor }, // do_CreateInstance returns mutator
{ &kNS_NESTEDABOUTURIMUTATOR_CID, false, nullptr, nsNestedAboutURIMutatorConstructor },
{ &kNS_ABOUT_CACHE_MODULE_CID, false, nullptr, nsAboutCache::Create },
{ &kNS_ABOUT_CACHE_ENTRY_MODULE_CID, false, nullptr, nsAboutCacheEntryConstructor },
{ &kNS_SOCKSSOCKETPROVIDER_CID, false, nullptr, nsSOCKSSocketProvider::CreateV5 },
@ -925,7 +928,6 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
{ NS_DNSSERVICE_CONTRACTID, &kNS_DNSSERVICE_CID },
{ NS_IDNSERVICE_CONTRACTID, &kNS_IDNSERVICE_CID },
{ NS_EFFECTIVETLDSERVICE_CONTRACTID, &kNS_EFFECTIVETLDSERVICE_CID },
{ NS_SIMPLEURI_CONTRACTID, &kNS_SIMPLEURI_CID },
{ NS_SIMPLEURIMUTATOR_CONTRACTID, &kNS_SIMPLEURIMUTATOR_CID },
{ NS_ASYNCSTREAMCOPIER_CONTRACTID, &kNS_ASYNCSTREAMCOPIER_CID },
{ NS_INPUTSTREAMPUMP_CONTRACTID, &kNS_INPUTSTREAMPUMP_CID },
@ -950,7 +952,6 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
{ NS_STDURLPARSER_CONTRACTID, &kNS_STDURLPARSER_CID },
{ NS_NOAUTHURLPARSER_CONTRACTID, &kNS_NOAUTHURLPARSER_CID },
{ NS_AUTHURLPARSER_CONTRACTID, &kNS_AUTHURLPARSER_CID },
{ NS_STANDARDURL_CONTRACTID, &kNS_STANDARDURL_CID },
{ NS_STANDARDURLMUTATOR_CONTRACTID, &kNS_STANDARDURLMUTATOR_CID },
{ NS_ARRAYBUFFERINPUTSTREAM_CONTRACTID, &kNS_ARRAYBUFFERINPUTSTREAM_CID },
{ NS_BUFFEREDINPUTSTREAM_CONTRACTID, &kNS_BUFFEREDINPUTSTREAM_CID },

View File

@ -360,10 +360,18 @@ NS_INTERFACE_MAP_BEGIN(nsNestedAboutURI)
NS_INTERFACE_MAP_END_INHERITING(nsSimpleNestedURI)
// nsISerializable
NS_IMETHODIMP
nsNestedAboutURI::Read(nsIObjectInputStream* aStream)
nsNestedAboutURI::Read(nsIObjectInputStream *aStream)
{
nsresult rv = nsSimpleNestedURI::Read(aStream);
NS_NOTREACHED("Use nsIURIMutator.read() instead");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsNestedAboutURI::ReadPrivate(nsIObjectInputStream *aStream)
{
nsresult rv = nsSimpleNestedURI::ReadPrivate(aStream);
if (NS_FAILED(rv)) return rv;
bool haveBase;
@ -439,7 +447,11 @@ nsNestedAboutURI::StartClone(nsSimpleURI::RefHandlingEnum aRefHandlingMode,
return url;
}
NS_IMPL_ISUPPORTS(nsNestedAboutURI::Mutator, nsIURISetters, nsIURIMutator)
// Queries this list of interfaces. If none match, it queries mURI.
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsNestedAboutURI::Mutator,
nsIURISetters,
nsIURIMutator,
nsISerializable)
NS_IMETHODIMP
nsNestedAboutURI::Mutate(nsIURIMutator** aMutator)

View File

@ -87,11 +87,13 @@ public:
protected:
nsCOMPtr<nsIURI> mBaseURI;
nsresult ReadPrivate(nsIObjectInputStream *stream);
public:
class Mutator final
: public nsIURIMutator
, public BaseURIMutator<nsNestedAboutURI>
, public nsISerializable
{
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
@ -106,6 +108,12 @@ public:
return InitFromIPCParams(aParams);
}
NS_IMETHOD
Write(nsIObjectOutputStream *aOutputStream) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
MOZ_MUST_USE NS_IMETHOD
Read(nsIObjectInputStream* aStream) override
{

View File

@ -32,12 +32,15 @@ static NS_DEFINE_CID(kSubstitutingURLCID, NS_SUBSTITUTINGURL_CID);
// SubstitutingURL : overrides nsStandardURL::GetFile to provide nsIFile resolution
//---------------------------------------------------------------------------------
NS_IMPL_ISUPPORTS(SubstitutingURL::Mutator,
nsIURISetters,
nsIURIMutator,
nsIStandardURLMutator,
nsIURLMutator,
nsIFileURLMutator)
// The list of interfaces should be in sync with nsStandardURL
// Queries this list of interfaces. If none match, it queries mURI.
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(SubstitutingURL::Mutator,
nsIURISetters,
nsIURIMutator,
nsIStandardURLMutator,
nsIURLMutator,
nsIFileURLMutator,
nsISerializable)
nsresult
SubstitutingURL::EnsureFile()

View File

@ -21,3 +21,22 @@ add_task(async function test_simple_setter_chaining() {
.finalize();
equal(uri.spec, "ftp://example.com/?hello#bla");
});
add_task(async function test_qi_behaviour() {
let uri = standardMutator()
.setSpec("http://example.com/")
.QueryInterface(Ci.nsIURI);
equal(uri.spec, "http://example.com/");
Assert.throws(() => { uri = standardMutator().QueryInterface(Ci.nsIURI); },
/NS_NOINTERFACE/,
"mutator doesn't QI if it holds no URI");
let mutator = standardMutator()
.setSpec("http://example.com/path");
uri = mutator.QueryInterface(Ci.nsIURI);
equal(uri.spec, "http://example.com/path");
Assert.throws(() => { uri = mutator.QueryInterface(Ci.nsIURI); },
/NS_NOINTERFACE/,
"Second QueryInterface should fail");
});

View File

@ -101,11 +101,6 @@ function test_hashes()
uri1 = uri1.mutate().setSpec("https://www.123.com/").finalize();
link.uri = uri1;
Assert.equal(link.uriHash, "iSx6UH1a9enVPzUA9JZ42g==");
var uri3 = Cc["@mozilla.org/network/simple-uri;1"]
.createInstance(Ci.nsIURI);
link.uri = uri3;
Assert.equal(link.uriHash, "hTrpDwNRMkvXPqYV5kh1Fw==");
}
function test_links()