Bug 2020765 - Make nsIURI.rs usable in rust r=necko-reviewers,kershaw

- Moves URIParams Serialization to a different interface
- Moves SizeOfIncludingThis to a different interface

Differential Revision: https://phabricator.services.mozilla.com/D285809
This commit is contained in:
Valentin Gosu
2026-05-12 07:55:54 +00:00
committed by valentin.gosu@gmail.com
parent 4e2f23e9c7
commit f618d10405
35 changed files with 205 additions and 59 deletions
+3 -2
View File
@@ -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:
+1 -2
View File
@@ -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;
+1 -1
View File
@@ -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<mozilla::net::nsSimpleURI> StartClone() override {
+4 -2
View File
@@ -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);
}
}
+4 -2
View File
@@ -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);
}
}
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -69,7 +69,7 @@ class nsJSURI final : public mozilla::net::nsSimpleURI {
// nsIURI overrides
virtual already_AddRefed<mozilla::net::nsSimpleURI> 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;
+4 -2
View File
@@ -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);
}
}
+4 -2
View File
@@ -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);
}
}
+4 -2
View File
@@ -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);
}
}
+2
View File
@@ -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
+7 -1
View File
@@ -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();
+6 -1
View File
@@ -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<nsIIPCSerializableURI> 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!");
}
+1
View File
@@ -5,6 +5,7 @@ include("/dom/media/webrtc/third_party_build/webrtc.mozbuild")
EXPORTS += [
"nsIIPCSerializableInputStream.h",
"nsIIPCSerializableURI.h",
]
EXPORTS.mozilla.ipc += [
+34
View File
@@ -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
+2
View File
@@ -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
+7 -1
View File
@@ -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)
+2 -1
View File
@@ -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)) {
+8 -1
View File
@@ -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
+1
View File
@@ -133,6 +133,7 @@ EXPORTS += [
"nsBaseParentChannel.h",
"nsFileStreams.h",
"nsInputStreamPump.h",
"nsIURIWithSizeOf.h",
"nsMIMEInputStream.h",
"nsNetUtil.h",
"nsReadLine.h",
-21
View File
@@ -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<nsIURI> 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) {
+44
View File
@@ -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<nsIURI> 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<nsIURIWithSizeOf> uriWithSizeOf = do_QueryInterface(aURI);
return uriWithSizeOf ? uriWithSizeOf->SizeOfIncludingThis(aMallocSizeOf) : 0;
}
#endif // nsIURIWithSizeOf_h
+1 -2
View File
@@ -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;
+1 -1
View File
@@ -38,7 +38,7 @@ class nsSimpleNestedURI : public nsSimpleURI, public nsINestedURI {
bool* result) override;
virtual already_AddRefed<nsSimpleURI> 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;
+2 -1
View File
@@ -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)
+8 -1
View File
@@ -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:
+2
View File
@@ -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<nsIURI*>(this);
+7 -1
View File
@@ -8,6 +8,7 @@
#include <bitset>
#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<nsStandardURL>
@@ -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();
@@ -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;
@@ -65,7 +65,7 @@ class nsNestedAboutURI final : public nsSimpleNestedURI {
// Override StartClone(), the nsISerializable methods, and
virtual already_AddRefed<nsSimpleURI> 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;
+7 -3
View File
@@ -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);
@@ -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<nsIURI*>(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)
+1 -1
View File
@@ -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<SubstitutingURL>;
friend TemplatedMutator<SubstitutingURL>;
+17
View File
@@ -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<nsIURI> 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);
+10
View File
@@ -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<interfaces::nsIObserverService> =