diff --git a/dom/base/Link.cpp b/dom/base/Link.cpp index 8929baf31957..eb20b32af758 100644 --- a/dom/base/Link.cpp +++ b/dom/base/Link.cpp @@ -14,6 +14,7 @@ #include "nsAttrValueInlines.h" #include "nsGkAtoms.h" #include "nsIURIMutator.h" +#include "nsIURIWithSizeOf.h" #include "nsLayoutUtils.h" #include "nsString.h" @@ -439,9 +440,9 @@ size_t Link::SizeOfExcludingThis(mozilla::SizeOfState& aState) const { // It is okay to include the size of mCachedURI here even though it might have // strong references from elsewhere because the URI was created for this // object, in nsGenericHTMLElement::GetURIAttr(). Only objects that created - // their own URI will call nsIURI::SizeOfIncludingThis(). + // their own URI will call nsIURIWithSizeOf::SizeOfIncludingThis(). if (mCachedURI) { - n += mCachedURI->SizeOfIncludingThis(aState.mMallocSizeOf); + n += SizeOfIncludingThisIfURIWithSizeOf(mCachedURI, aState.mMallocSizeOf); } // The following members don't need to be measured: diff --git a/dom/file/uri/BlobURL.cpp b/dom/file/uri/BlobURL.cpp index 2132e4a25db6..ef8b8af973c6 100644 --- a/dom/file/uri/BlobURL.cpp +++ b/dom/file/uri/BlobURL.cpp @@ -79,8 +79,7 @@ BlobURL::Write(nsIObjectOutputStream* aStream) { return NS_OK; } -NS_IMETHODIMP_(void) -BlobURL::Serialize(mozilla::ipc::URIParams& aParams) { +void BlobURL::Serialize(mozilla::ipc::URIParams& aParams) { using namespace mozilla::ipc; HostObjectURIParams hostParams; diff --git a/dom/file/uri/BlobURL.h b/dom/file/uri/BlobURL.h index b4779de587f0..a91665835ede 100644 --- a/dom/file/uri/BlobURL.h +++ b/dom/file/uri/BlobURL.h @@ -41,7 +41,7 @@ class BlobURL final : public mozilla::net::nsSimpleURI { // Override EqualsInternal() nsresult EqualsInternal(nsIURI* aOther, RefHandlingEnum aRefHandlingMode, bool* aResult) override; - NS_IMETHOD_(void) Serialize(mozilla::ipc::URIParams& aParams) override; + virtual void Serialize(mozilla::ipc::URIParams& aParams) override; // Override StartClone to hand back a BlobURL with mRevoked set. already_AddRefed StartClone() override { diff --git a/dom/html/HTMLImageElement.cpp b/dom/html/HTMLImageElement.cpp index 7c5a54042748..8fe6b7bbe36a 100644 --- a/dom/html/HTMLImageElement.cpp +++ b/dom/html/HTMLImageElement.cpp @@ -23,6 +23,7 @@ #include "nsGenericHTMLElement.h" #include "nsGkAtoms.h" #include "nsIMutationObserver.h" +#include "nsIURIWithSizeOf.h" #include "nsImageFrame.h" #include "nsNodeInfoManager.h" #include "nsPresContext.h" @@ -1224,9 +1225,10 @@ void HTMLImageElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes, // It is okay to include the size of mSrcURI here even though it might have // strong references from elsewhere because the URI was created for this // object, in nsImageLoadingContent::StringToURI(). Only objects that created - // their own URI will call nsIURI::SizeOfIncludingThis(). + // their own URI will call nsIURIWithSizeOf::SizeOfIncludingThis(). if (mSrcURI) { - *aNodeSize += mSrcURI->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); + *aNodeSize += SizeOfIncludingThisIfURIWithSizeOf( + mSrcURI, aSizes.mState.mMallocSizeOf); } } diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp index 4a9e91225258..1aab48120b31 100644 --- a/dom/html/HTMLLinkElement.cpp +++ b/dom/html/HTMLLinkElement.cpp @@ -32,6 +32,7 @@ #include "nsIContentPolicy.h" #include "nsINode.h" #include "nsIPrefetchService.h" +#include "nsIURIWithSizeOf.h" #include "nsMimeTypes.h" #include "nsPIDOMWindow.h" #include "nsReadableUtils.h" @@ -409,9 +410,10 @@ void HTMLLinkElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes, // It is okay to include the size of mCachedURI here even though it might have // strong references from elsewhere because the URI was created for this // object, in nsGenericHTMLElement::GetURIAttr(). Only objects that created - // their own URI will call nsIURI::SizeOfIncludingThis(). + // their own URI will call nsIURIWithSizeOf::SizeOfIncludingThis(). if (mCachedURI) { - *aNodeSize += mCachedURI->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); + *aNodeSize += SizeOfIncludingThisIfURIWithSizeOf( + mCachedURI, aSizes.mState.mMallocSizeOf); } } diff --git a/dom/jsurl/nsJSProtocolHandler.cpp b/dom/jsurl/nsJSProtocolHandler.cpp index feaf102fcdf3..3de50f3f4b1e 100644 --- a/dom/jsurl/nsJSProtocolHandler.cpp +++ b/dom/jsurl/nsJSProtocolHandler.cpp @@ -1386,7 +1386,7 @@ nsJSURI::Write(nsIObjectOutputStream* aStream) { return NS_OK; } -NS_IMETHODIMP_(void) nsJSURI::Serialize(mozilla::ipc::URIParams& aParams) { +void nsJSURI::Serialize(mozilla::ipc::URIParams& aParams) { using namespace mozilla::ipc; JSURIParams jsParams; diff --git a/dom/jsurl/nsJSProtocolHandler.h b/dom/jsurl/nsJSProtocolHandler.h index c4d5145c9642..1a7fb1e83f09 100644 --- a/dom/jsurl/nsJSProtocolHandler.h +++ b/dom/jsurl/nsJSProtocolHandler.h @@ -69,7 +69,7 @@ class nsJSURI final : public mozilla::net::nsSimpleURI { // nsIURI overrides virtual already_AddRefed StartClone() override; NS_IMETHOD Mutate(nsIURIMutator** _retval) override; - NS_IMETHOD_(void) Serialize(mozilla::ipc::URIParams& aParams) override; + virtual void Serialize(mozilla::ipc::URIParams& aParams) override; // nsISerializable overrides NS_IMETHOD Read(nsIObjectInputStream* aStream) override; diff --git a/dom/svg/SVGFEImageElement.cpp b/dom/svg/SVGFEImageElement.cpp index c148366621e5..293e95d7dd56 100644 --- a/dom/svg/SVGFEImageElement.cpp +++ b/dom/svg/SVGFEImageElement.cpp @@ -15,6 +15,7 @@ #include "mozilla/dom/UserActivation.h" #include "mozilla/gfx/2D.h" #include "nsContentUtils.h" +#include "nsIURIWithSizeOf.h" #include "nsLayoutUtils.h" #include "nsNetUtil.h" @@ -434,9 +435,10 @@ void SVGFEImageElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes, // It is okay to include the size of mSrcURI here even though it might have // strong references from elsewhere because the URI was created for this // object, in nsImageLoadingContent::StringToURI(). Only objects that created - // their own URI will call nsIURI::SizeOfIncludingThis(). + // their own URI will call nsIURIWithSizeOf::SizeOfIncludingThis(). if (mSrcURI) { - *aNodeSize += mSrcURI->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); + *aNodeSize += SizeOfIncludingThisIfURIWithSizeOf( + mSrcURI, aSizes.mState.mMallocSizeOf); } } diff --git a/dom/svg/SVGImageElement.cpp b/dom/svg/SVGImageElement.cpp index 4ce7f2c7c221..e5cfafb0c857 100644 --- a/dom/svg/SVGImageElement.cpp +++ b/dom/svg/SVGImageElement.cpp @@ -14,6 +14,7 @@ #include "mozilla/gfx/2D.h" #include "nsCOMPtr.h" #include "nsContentUtils.h" +#include "nsIURIWithSizeOf.h" #include "nsNetUtil.h" NS_IMPL_NS_NEW_SVG_ELEMENT(Image) @@ -341,9 +342,10 @@ void SVGImageElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes, // It is okay to include the size of mSrcURI here even though it might have // strong references from elsewhere because the URI was created for this // object, in nsImageLoadingContent::StringToURI(). Only objects that created - // their own URI will call nsIURI::SizeOfIncludingThis(). + // their own URI will call nsIURIWithSizeOf::SizeOfIncludingThis(). if (mSrcURI) { - *aNodeSize += mSrcURI->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); + *aNodeSize += SizeOfIncludingThisIfURIWithSizeOf( + mSrcURI, aSizes.mState.mMallocSizeOf); } } diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index 0d245d44a2c5..1365d60ff55d 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -103,6 +103,7 @@ #include "nsIScriptContext.h" #include "nsISupportsUtils.h" #include "nsIURI.h" +#include "nsIURIWithSizeOf.h" #include "nsIXPConnect.h" #include "nsMenuPopupFrame.h" #include "nsNodeInfoManager.h" @@ -1972,9 +1973,10 @@ void nsXULPrototypeScript::AddSizeOfExcludingThis(nsWindowSizes& aSizes, // strong references from elsewhere because the URI was created for this // object, in XULContentSinkImpl::OpenScript() or // nsXULPrototypeElement::Deserialize(). Only objects that created their own - // URI will call nsIURI::SizeOfIncludingThis(). + // URI will call nsIURIWithSizeOf::SizeOfIncludingThis(). if (mSrcURI) { - *aNodeSize += mSrcURI->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); + *aNodeSize += SizeOfIncludingThisIfURIWithSizeOf( + mSrcURI, aSizes.mState.mMallocSizeOf); } } diff --git a/image/decoders/icon/nsIconURI.cpp b/image/decoders/icon/nsIconURI.cpp index d55491049c1e..42472a819dc0 100644 --- a/image/decoders/icon/nsIconURI.cpp +++ b/image/decoders/icon/nsIconURI.cpp @@ -58,6 +58,8 @@ NS_INTERFACE_MAP_BEGIN(nsMozIconURI) NS_INTERFACE_MAP_ENTRY(nsIURI) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsINestedURI, mIconURL) NS_INTERFACE_MAP_ENTRY(nsISerializable) + NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableURI) + NS_INTERFACE_MAP_ENTRY(nsIURIWithSizeOf) NS_IMPL_QUERY_CLASSINFO(nsMozIconURI) NS_INTERFACE_MAP_END diff --git a/image/decoders/icon/nsIconURI.h b/image/decoders/icon/nsIconURI.h index 59e8c626c742..2c48a522bd93 100644 --- a/image/decoders/icon/nsIconURI.h +++ b/image/decoders/icon/nsIconURI.h @@ -6,11 +6,13 @@ #ifndef mozilla_image_decoders_icon_nsIconURI_h #define mozilla_image_decoders_icon_nsIconURI_h +#include "nsIIPCSerializableURI.h" #include "nsIIconURI.h" #include "nsCOMPtr.h" #include "nsString.h" #include "nsINestedURI.h" #include "nsIURIMutator.h" +#include "nsIURIWithSizeOf.h" #include "nsISerializable.h" #define NS_THIS_ICONURI_IMPLEMENTATION_CID \ @@ -26,13 +28,17 @@ class Encoding; class nsMozIconURI final : public nsIMozIconURI, public nsINestedURI, - public nsISerializable { + public nsISerializable, + public nsIIPCSerializableURI, + public nsIURIWithSizeOf { public: NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIURI NS_DECL_NSIMOZICONURI NS_DECL_NSINESTEDURI NS_DECL_NSISERIALIZABLE + NS_DECL_NSIIPCSERIALIZABLEURI + NS_DECL_NSIURIWITHSIZEOF protected: nsMozIconURI(); diff --git a/ipc/glue/URIUtils.cpp b/ipc/glue/URIUtils.cpp index 8de6dee79686..51c161b92997 100644 --- a/ipc/glue/URIUtils.cpp +++ b/ipc/glue/URIUtils.cpp @@ -13,6 +13,7 @@ #include "nsComponentManagerUtils.h" #include "nsDebug.h" #include "nsID.h" +#include "nsIIPCSerializableURI.h" #include "nsJARURI.h" #include "nsIIconURI.h" #include "nsJSProtocolHandler.h" @@ -38,7 +39,11 @@ namespace ipc { void SerializeURI(nsIURI* aURI, URIParams& aParams) { MOZ_ASSERT(aURI); - aURI->Serialize(aParams); + nsCOMPtr serializable = do_QueryInterface(aURI); + if (!serializable) { + MOZ_CRASH("URI does not implement nsIIPCSerializableURI!"); + } + serializable->Serialize(aParams); if (aParams.type() == URIParams::T__None) { MOZ_CRASH("Serialize failed!"); } diff --git a/ipc/glue/moz.build b/ipc/glue/moz.build index bfb11d852776..9c24b5b79ce4 100644 --- a/ipc/glue/moz.build +++ b/ipc/glue/moz.build @@ -5,6 +5,7 @@ include("/dom/media/webrtc/third_party_build/webrtc.mozbuild") EXPORTS += [ "nsIIPCSerializableInputStream.h", + "nsIIPCSerializableURI.h", ] EXPORTS.mozilla.ipc += [ diff --git a/ipc/glue/nsIIPCSerializableURI.h b/ipc/glue/nsIIPCSerializableURI.h new file mode 100644 index 000000000000..419ae87c9687 --- /dev/null +++ b/ipc/glue/nsIIPCSerializableURI.h @@ -0,0 +1,34 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_ipc_nsIIPCSerializableURI_h +#define mozilla_ipc_nsIIPCSerializableURI_h + +#include "nsISupports.h" + +namespace mozilla { +namespace ipc { +class URIParams; +} // namespace ipc +} // namespace mozilla + +#define NS_IIPCSERIALIZABLEURI_IID \ + {0xc1b67333, 0x8462, 0x4540, {0x93, 0x97, 0x34, 0x57, 0x3c, 0x3c, 0x35, 0x80}} + +class NS_NO_VTABLE nsIIPCSerializableURI : public nsISupports { + public: + NS_INLINE_DECL_STATIC_IID(NS_IIPCSERIALIZABLEURI_IID) + + virtual void Serialize(mozilla::ipc::URIParams& aParams) = 0; +}; + +#define NS_DECL_NSIIPCSERIALIZABLEURI \ + virtual void Serialize(mozilla::ipc::URIParams& aParams) override; + +#define NS_FORWARD_NSIIPCSERIALIZABLEURI(_to) \ + virtual void Serialize(mozilla::ipc::URIParams& aParams) override { \ + _to Serialize(aParams); \ + } + +#endif // mozilla_ipc_nsIIPCSerializableURI_h diff --git a/modules/libjar/nsJARURI.cpp b/modules/libjar/nsJARURI.cpp index cf5cecdc9d2a..1817f76ed99d 100644 --- a/modules/libjar/nsJARURI.cpp +++ b/modules/libjar/nsJARURI.cpp @@ -41,6 +41,8 @@ NS_INTERFACE_MAP_BEGIN(nsJARURI) NS_INTERFACE_MAP_ENTRY(nsISerializable) NS_IMPL_QUERY_CLASSINFO(nsJARURI) NS_INTERFACE_MAP_ENTRY(nsINestedURI) + NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableURI) + NS_INTERFACE_MAP_ENTRY(nsIURIWithSizeOf) NS_INTERFACE_MAP_ENTRY_CONCRETE(nsJARURI) NS_INTERFACE_MAP_END diff --git a/modules/libjar/nsJARURI.h b/modules/libjar/nsJARURI.h index 0bcc6b58b96b..4a34d0bd48af 100644 --- a/modules/libjar/nsJARURI.h +++ b/modules/libjar/nsJARURI.h @@ -6,12 +6,14 @@ #ifndef nsJARURI_h_ #define nsJARURI_h_ +#include "nsIIPCSerializableURI.h" #include "nsIJARURI.h" #include "nsISerializable.h" #include "nsCOMPtr.h" #include "nsString.h" #include "nsINestedURI.h" #include "nsIURIMutator.h" +#include "nsIURIWithSizeOf.h" #define NS_THIS_JARURI_IMPL_CID \ {/* 9a55f629-730b-4d08-b75b-fa7d9570a691 */ \ @@ -36,7 +38,9 @@ class nsJARURI final : public nsIJARURI, public nsISerializable, - public nsINestedURI { + public nsINestedURI, + public nsIIPCSerializableURI, + public nsIURIWithSizeOf { public: NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIURI @@ -44,6 +48,8 @@ class nsJARURI final : public nsIJARURI, NS_DECL_NSIJARURI NS_DECL_NSISERIALIZABLE NS_DECL_NSINESTEDURI + NS_DECL_NSIIPCSERIALIZABLEURI + NS_DECL_NSIURIWITHSIZEOF NS_INLINE_DECL_STATIC_IID(NS_THIS_JARURI_IMPL_CID) diff --git a/netwerk/base/DefaultURI.cpp b/netwerk/base/DefaultURI.cpp index 8d91d71dca44..623226a29f87 100644 --- a/netwerk/base/DefaultURI.cpp +++ b/netwerk/base/DefaultURI.cpp @@ -47,7 +47,8 @@ NS_IMPL_CI_INTERFACE_GETTER0(DefaultURI) NS_IMPL_ADDREF(DefaultURI) NS_IMPL_RELEASE(DefaultURI) NS_INTERFACE_TABLE_HEAD(DefaultURI) - NS_INTERFACE_TABLE(DefaultURI, nsIURI, nsISerializable) + NS_INTERFACE_TABLE(DefaultURI, nsIURI, nsISerializable, nsIIPCSerializableURI, + nsIURIWithSizeOf) NS_INTERFACE_TABLE_TO_MAP_SEGUE NS_IMPL_QUERY_CLASSINFO(DefaultURI) if (aIID.Equals(kDefaultURICID)) { diff --git a/netwerk/base/DefaultURI.h b/netwerk/base/DefaultURI.h index caf08a1a93b4..cc2df73b70b3 100644 --- a/netwerk/base/DefaultURI.h +++ b/netwerk/base/DefaultURI.h @@ -5,7 +5,9 @@ #ifndef DefaultURI_h_ #define DefaultURI_h_ +#include "nsIIPCSerializableURI.h" #include "nsIURI.h" +#include "nsIURIWithSizeOf.h" #include "nsISerializable.h" #include "nsIURIMutator.h" #include "mozilla/net/MozURL.h" @@ -13,11 +15,16 @@ namespace mozilla { namespace net { -class DefaultURI : public nsIURI, public nsISerializable { +class DefaultURI : public nsIURI, + public nsISerializable, + public nsIIPCSerializableURI, + public nsIURIWithSizeOf { public: NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIURI NS_DECL_NSISERIALIZABLE + NS_DECL_NSIIPCSERIALIZABLEURI + NS_DECL_NSIURIWITHSIZEOF class Mutator final : public nsIURIMutator, public nsISerializable { NS_DECL_ISUPPORTS diff --git a/netwerk/base/moz.build b/netwerk/base/moz.build index 478266fee418..2d551ad265e5 100644 --- a/netwerk/base/moz.build +++ b/netwerk/base/moz.build @@ -133,6 +133,7 @@ EXPORTS += [ "nsBaseParentChannel.h", "nsFileStreams.h", "nsInputStreamPump.h", + "nsIURIWithSizeOf.h", "nsMIMEInputStream.h", "nsNetUtil.h", "nsReadLine.h", diff --git a/netwerk/base/nsIURI.idl b/netwerk/base/nsIURI.idl index 3f414020a789..fdbf27b08fe1 100644 --- a/netwerk/base/nsIURI.idl +++ b/netwerk/base/nsIURI.idl @@ -49,10 +49,7 @@ class URIParams; } // namespace mozilla %} -[ptr] native Encoding(const mozilla::Encoding); -[ref] native URIParams(mozilla::ipc::URIParams); interface nsIURIMutator; -native MallocSizeOf(mozilla::MallocSizeOf); /** * nsIURI - interface for an uniform resource identifier w/ i18n support. @@ -310,24 +307,6 @@ interface nsIURI : nsISupports */ nsIURIMutator mutate(); - /** - * Serializes a URI object to a URIParams data structure in order for being - * passed over IPC. For deserialization, see nsIURIMutator. - */ - [noscript, notxpcom] void serialize(in URIParams aParams); - - /** - * Measures the size of the object and the things that it points to. - * - * WARNING: Don't call this more than once on a particular object or you - * will end up with overcounting. Having an nsCOMPtr is not - * sufficient to know that you are the only one measuring this object. - * - * SizeOfExcludingThis does not make sense here because this is a - * refcounted object, so it will never be embedded in something else. - */ - [notxpcom, nostdcall] size_t SizeOfIncludingThis(in MallocSizeOf aMallocSizeOf); - %{C++ // MOZ_DBG support friend std::ostream& operator<<(std::ostream& aOut, const nsIURI& aURI) { diff --git a/netwerk/base/nsIURIWithSizeOf.h b/netwerk/base/nsIURIWithSizeOf.h new file mode 100644 index 000000000000..f5ac1f4ced95 --- /dev/null +++ b/netwerk/base/nsIURIWithSizeOf.h @@ -0,0 +1,44 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsIURIWithSizeOf_h +#define nsIURIWithSizeOf_h + +#include "mozilla/MemoryReporting.h" +#include "nsISupports.h" +#include "nsCOMPtr.h" + +#define NS_IURIWITHSIZEOF_IID \ + {0x4245123a, 0x9c04, 0x4e5c, {0xa7, 0x48, 0x32, 0x8b, 0xa5, 0x88, 0x3b, 0x00}} + +class NS_NO_VTABLE nsIURIWithSizeOf : public nsISupports { + public: + NS_INLINE_DECL_STATIC_IID(NS_IURIWITHSIZEOF_IID) + + /** + * Measures the size of the object and the things that it points to. + * + * WARNING: Don't call this more than once on a particular object or you + * will end up with overcounting. Having an nsCOMPtr is not + * sufficient to know that you are the only one measuring this object. + * + * SizeOfExcludingThis does not make sense here because this is a + * refcounted object, so it will never be embedded in something else. + */ + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) = 0; +}; + +#define NS_DECL_NSIURIWITHSIZEOF \ + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) \ + override; + +class nsIURI; + +inline size_t SizeOfIncludingThisIfURIWithSizeOf( + nsIURI* aURI, mozilla::MallocSizeOf aMallocSizeOf) { + nsCOMPtr uriWithSizeOf = do_QueryInterface(aURI); + return uriWithSizeOf ? uriWithSizeOf->SizeOfIncludingThis(aMallocSizeOf) : 0; +} + +#endif // nsIURIWithSizeOf_h diff --git a/netwerk/base/nsSimpleNestedURI.cpp b/netwerk/base/nsSimpleNestedURI.cpp index aab2b7d3b23a..42426a9fda61 100644 --- a/netwerk/base/nsSimpleNestedURI.cpp +++ b/netwerk/base/nsSimpleNestedURI.cpp @@ -107,8 +107,7 @@ nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream) { return rv; } -NS_IMETHODIMP_(void) -nsSimpleNestedURI::Serialize(mozilla::ipc::URIParams& aParams) { +void nsSimpleNestedURI::Serialize(mozilla::ipc::URIParams& aParams) { using namespace mozilla::ipc; SimpleNestedURIParams params; diff --git a/netwerk/base/nsSimpleNestedURI.h b/netwerk/base/nsSimpleNestedURI.h index 2cdcecab1530..6421c48d4964 100644 --- a/netwerk/base/nsSimpleNestedURI.h +++ b/netwerk/base/nsSimpleNestedURI.h @@ -38,7 +38,7 @@ class nsSimpleNestedURI : public nsSimpleURI, public nsINestedURI { bool* result) override; virtual already_AddRefed StartClone() override; NS_IMETHOD Mutate(nsIURIMutator** _retval) override; - NS_IMETHOD_(void) Serialize(ipc::URIParams& aParams) override; + virtual void Serialize(ipc::URIParams& aParams) override; // nsISerializable overrides NS_IMETHOD Read(nsIObjectInputStream* aStream) override; diff --git a/netwerk/base/nsSimpleURI.cpp b/netwerk/base/nsSimpleURI.cpp index e279c27c4315..34d47a7d6f64 100644 --- a/netwerk/base/nsSimpleURI.cpp +++ b/netwerk/base/nsSimpleURI.cpp @@ -40,7 +40,8 @@ NS_IMPL_CI_INTERFACE_GETTER0(nsSimpleURI) NS_IMPL_ADDREF(nsSimpleURI) NS_IMPL_RELEASE(nsSimpleURI) NS_INTERFACE_TABLE_HEAD(nsSimpleURI) - NS_INTERFACE_TABLE(nsSimpleURI, nsIURI, nsISerializable) + NS_INTERFACE_TABLE(nsSimpleURI, nsIURI, nsISerializable, + nsIIPCSerializableURI, nsIURIWithSizeOf) NS_INTERFACE_TABLE_TO_MAP_SEGUE NS_IMPL_QUERY_CLASSINFO(nsSimpleURI) NS_INTERFACE_MAP_ENTRY_CONCRETE(nsSimpleURI) diff --git a/netwerk/base/nsSimpleURI.h b/netwerk/base/nsSimpleURI.h index 18b8a9d28354..b8267700e482 100644 --- a/netwerk/base/nsSimpleURI.h +++ b/netwerk/base/nsSimpleURI.h @@ -5,7 +5,9 @@ #ifndef nsSimpleURI_h_ #define nsSimpleURI_h_ +#include "nsIIPCSerializableURI.h" #include "nsIURI.h" +#include "nsIURIWithSizeOf.h" #include "nsISerializable.h" #include "nsString.h" #include "nsIClassInfo.h" @@ -22,7 +24,10 @@ namespace net { 0x470b, \ {0xb9, 0xb9, 0x9f, 0xd9, 0x46, 0x2b, 0x5e, 0x19}} -class nsSimpleURI : public nsIURI, public nsISerializable { +class nsSimpleURI : public nsIURI, + public nsISerializable, + public nsIIPCSerializableURI, + public nsIURIWithSizeOf { protected: nsSimpleURI() = default; virtual ~nsSimpleURI() = default; @@ -32,6 +37,8 @@ class nsSimpleURI : public nsIURI, public nsISerializable { NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIURI NS_DECL_NSISERIALIZABLE + NS_DECL_NSIIPCSERIALIZABLEURI + NS_DECL_NSIURIWITHSIZEOF // nsSimpleURI methods: diff --git a/netwerk/base/nsStandardURL.cpp b/netwerk/base/nsStandardURL.cpp index d72179bbb81f..2d8b05f3cf73 100644 --- a/netwerk/base/nsStandardURL.cpp +++ b/netwerk/base/nsStandardURL.cpp @@ -1145,6 +1145,8 @@ NS_INTERFACE_MAP_BEGIN(nsStandardURL) NS_INTERFACE_MAP_ENTRY(nsISerializable) NS_IMPL_QUERY_CLASSINFO(nsStandardURL) NS_INTERFACE_MAP_ENTRY(nsISensitiveInfoHiddenURI) + NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableURI) + NS_INTERFACE_MAP_ENTRY(nsIURIWithSizeOf) // see nsStandardURL::Equals if (aIID.Equals(kThisImplCID)) { foundInterface = static_cast(this); diff --git a/netwerk/base/nsStandardURL.h b/netwerk/base/nsStandardURL.h index 42f36a9f419b..3049cf6dd6fc 100644 --- a/netwerk/base/nsStandardURL.h +++ b/netwerk/base/nsStandardURL.h @@ -8,6 +8,7 @@ #include #include "nsString.h" +#include "nsIIPCSerializableURI.h" #include "nsISerializable.h" #include "nsIFileURL.h" #include "nsIStandardURL.h" @@ -18,6 +19,7 @@ #include "mozilla/LinkedList.h" #include "nsISensitiveInfoHiddenURI.h" #include "nsIURIMutator.h" +#include "nsIURIWithSizeOf.h" #ifdef NS_BUILD_REFCNT_LOGGING # define DEBUG_DUMP_URLS_AT_SHUTDOWN @@ -109,7 +111,9 @@ class URLSegmentNumber { class nsStandardURL : public nsIFileURL, public nsIStandardURL, public nsISerializable, - public nsISensitiveInfoHiddenURI + public nsISensitiveInfoHiddenURI, + public nsIIPCSerializableURI, + public nsIURIWithSizeOf #ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN , public LinkedListElement @@ -127,6 +131,8 @@ class nsStandardURL : public nsIFileURL, NS_DECL_NSISTANDARDURL NS_DECL_NSISERIALIZABLE NS_DECL_NSISENSITIVEINFOHIDDENURI + NS_DECL_NSIIPCSERIALIZABLEURI + NS_DECL_NSIURIWITHSIZEOF static void InitGlobalObjects(); static void ShutdownGlobalObjects(); diff --git a/netwerk/protocol/about/nsAboutProtocolHandler.cpp b/netwerk/protocol/about/nsAboutProtocolHandler.cpp index 9267b09bd7ac..b0aab9b8a5fc 100644 --- a/netwerk/protocol/about/nsAboutProtocolHandler.cpp +++ b/netwerk/protocol/about/nsAboutProtocolHandler.cpp @@ -317,8 +317,7 @@ nsNestedAboutURI::Write(nsIObjectOutputStream* aStream) { return NS_OK; } -NS_IMETHODIMP_(void) -nsNestedAboutURI::Serialize(mozilla::ipc::URIParams& aParams) { +void nsNestedAboutURI::Serialize(mozilla::ipc::URIParams& aParams) { using namespace mozilla::ipc; NestedAboutURIParams params; diff --git a/netwerk/protocol/about/nsAboutProtocolHandler.h b/netwerk/protocol/about/nsAboutProtocolHandler.h index ae362b8b01e5..7af15ed84361 100644 --- a/netwerk/protocol/about/nsAboutProtocolHandler.h +++ b/netwerk/protocol/about/nsAboutProtocolHandler.h @@ -65,7 +65,7 @@ class nsNestedAboutURI final : public nsSimpleNestedURI { // Override StartClone(), the nsISerializable methods, and virtual already_AddRefed StartClone() override; NS_IMETHOD Mutate(nsIURIMutator** _retval) override; - NS_IMETHOD_(void) Serialize(ipc::URIParams& aParams) override; + virtual void Serialize(ipc::URIParams& aParams) override; // nsISerializable NS_IMETHOD Read(nsIObjectInputStream* aStream) override; diff --git a/netwerk/protocol/res/SubstitutingJARURI.h b/netwerk/protocol/res/SubstitutingJARURI.h index f26842c47af5..7238939e08d0 100644 --- a/netwerk/protocol/res/SubstitutingJARURI.h +++ b/netwerk/protocol/res/SubstitutingJARURI.h @@ -5,8 +5,10 @@ #ifndef SubstitutingJARURI_h #define SubstitutingJARURI_h +#include "nsIIPCSerializableURI.h" #include "nsIStandardURL.h" #include "nsIURL.h" +#include "nsIURIWithSizeOf.h" #include "nsJARURI.h" #include "nsISerializable.h" @@ -24,7 +26,9 @@ namespace net { // allows consumers to access the underlying jar resource. class SubstitutingJARURI : public nsIJARURI, public nsIStandardURL, - public nsISerializable { + public nsISerializable, + public nsIIPCSerializableURI, + public nsIURIWithSizeOf { protected: // Contains the resource://-like URI to be mapped. nsIURI and nsIURL will // forward to this. @@ -41,6 +45,8 @@ class SubstitutingJARURI : public nsIJARURI, NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSISERIALIZABLE + NS_DECL_NSIIPCSERIALIZABLEURI + NS_DECL_NSIURIWITHSIZEOF NS_INLINE_DECL_STATIC_IID(NS_SUBSTITUTINGJARURI_IMPL_CID) @@ -150,8 +156,6 @@ class SubstitutingJARURI : public nsIJARURI, : mSource->GetDisplayPrePath(aDisplayPrePath); } NS_IMETHOD Mutate(nsIURIMutator** _retval) override; - NS_IMETHOD_(void) Serialize(mozilla::ipc::URIParams& aParams) override; - virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) override; private: nsresult Clone(nsIURI** aURI); diff --git a/netwerk/protocol/res/SubstitutingProtocolHandler.cpp b/netwerk/protocol/res/SubstitutingProtocolHandler.cpp index e710d941fec7..7367a10a5888 100644 --- a/netwerk/protocol/res/SubstitutingProtocolHandler.cpp +++ b/netwerk/protocol/res/SubstitutingProtocolHandler.cpp @@ -160,8 +160,8 @@ void SubstitutingJARURI::Serialize(mozilla::ipc::URIParams& aParams) { URIParams source; URIParams resolved; - mSource->Serialize(source); - mResolved->Serialize(resolved); + SerializeURI(mSource, source); + SerializeURI(mResolved, resolved); params.source() = source; params.resolved() = resolved; aParams = params; @@ -293,6 +293,8 @@ NS_INTERFACE_MAP_BEGIN(SubstitutingJARURI) NS_INTERFACE_MAP_ENTRY(nsIURL) NS_INTERFACE_MAP_ENTRY(nsIStandardURL) NS_INTERFACE_MAP_ENTRY(nsISerializable) + NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableURI) + NS_INTERFACE_MAP_ENTRY(nsIURIWithSizeOf) if (aIID.Equals(kSubstitutingJARURIImplCID)) { foundInterface = static_cast(this); } else @@ -301,7 +303,8 @@ NS_INTERFACE_MAP_BEGIN(SubstitutingJARURI) NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER(SubstitutingJARURI, nsIURI, nsIJARURI, nsIURL, - nsIStandardURL, nsISerializable) + nsIStandardURL, nsISerializable, + nsIIPCSerializableURI, nsIURIWithSizeOf) NS_IMPL_NSIURIMUTATOR_ISUPPORTS(SubstitutingJARURI::Mutator, nsIURISetters, nsIURIMutator, nsISerializable) diff --git a/netwerk/protocol/res/SubstitutingURL.h b/netwerk/protocol/res/SubstitutingURL.h index 7c4a37624338..e252ebfbc7b0 100644 --- a/netwerk/protocol/res/SubstitutingURL.h +++ b/netwerk/protocol/res/SubstitutingURL.h @@ -52,7 +52,7 @@ class SubstitutingURL : public nsStandardURL { return NS_OK; } - NS_IMETHOD_(void) Serialize(ipc::URIParams& aParams) override; + virtual void Serialize(ipc::URIParams& aParams) override; friend BaseURIMutator; friend TemplatedMutator; diff --git a/xpcom/rust/gtest/xpcom/TestXpcom.cpp b/xpcom/rust/gtest/xpcom/TestXpcom.cpp index 69425274f60e..9ca4e34b4f57 100644 --- a/xpcom/rust/gtest/xpcom/TestXpcom.cpp +++ b/xpcom/rust/gtest/xpcom/TestXpcom.cpp @@ -8,6 +8,9 @@ #include "nsIObserver.h" #include "mozilla/Services.h" #include "nsIObserverService.h" +#include "nsIURI.h" +#include "nsNetUtil.h" +#include "nsString.h" extern "C" nsIObserverService* Rust_ObserveFromRust(); @@ -33,6 +36,20 @@ TEST(RustXpcom, ImplementRunnableInRust) EXPECT_TRUE(itWorked); } +extern "C" nsresult Rust_GetSpecFromRust(nsIURI* aURI, nsACString* aSpec); + +TEST(RustXpcom, GetSpecFromRust) +{ + nsCOMPtr uri; + nsresult rv = NS_NewURI(getter_AddRefs(uri), "https://example.com/path"_ns); + ASSERT_TRUE(NS_SUCCEEDED(rv)); + + nsAutoCString spec; + rv = Rust_GetSpecFromRust(uri, &spec); + EXPECT_TRUE(NS_SUCCEEDED(rv)); + EXPECT_TRUE(spec.EqualsLiteral("https://example.com/path")); +} + extern "C" void Rust_GetMultipleInterfaces(nsIRunnable** aRunnable, nsIObserver** aObserver); diff --git a/xpcom/rust/gtest/xpcom/test.rs b/xpcom/rust/gtest/xpcom/test.rs index f26a0140f33e..64b32c05ea61 100644 --- a/xpcom/rust/gtest/xpcom/test.rs +++ b/xpcom/rust/gtest/xpcom/test.rs @@ -8,13 +8,23 @@ extern crate xpcom; extern crate nserror; +extern crate nsstring; use nserror::{nsresult, NS_OK}; +use nsstring::nsACString; use std::ffi::{CStr, CString}; use std::os::raw::c_char; use std::ptr; use xpcom::{interfaces, RefPtr}; +#[no_mangle] +pub unsafe extern "C" fn Rust_GetSpecFromRust( + uri: *const interfaces::nsIURI, + spec: *mut nsACString, +) -> nsresult { + (*uri).GetSpec(spec) +} + #[no_mangle] pub unsafe extern "C" fn Rust_ObserveFromRust() -> *const interfaces::nsIObserverService { let obssvc: RefPtr =