tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit bc71be21eca14b706c767ac876a06d05099fe2a6
parent 78055806dd0c0171ef1a62cc1c7e1b6dbacac4e5
Author: Andrew McCreight <continuation@gmail.com>
Date:   Mon,  8 Dec 2025 15:07:25 +0000

Bug 2003652, part 1 - Move the one nsISizeOf method into nsIURI. r=xpcom-reviewers,necko-reviewers,firefox-svg-reviewers,emilio,jesup,dholbert

Moving SizeOfIncludingThis from nsISizeOf to nsIURI makes using and
reasoning about this much easier.

When this nsIURI reporting was added in bug 682431, it was deliberately
added as a separate interface rather than on nsIURI. There's no explanation,
but that was in 2011 when compatibility for addons or whatever may have
been something they had to maintain. nsIURI has been changed a number of
times since 2015 without changing the UUID so I expect that isn't a
concern any more.

A few nsIURI subclasses get new SizeOfIncludingThis methods that don't
do anything, but we can fill these in if they show up on DMD reports.

Differential Revision: https://phabricator.services.mozilla.com/D274856

Diffstat:
Mdom/base/Link.cpp | 5++---
Mdom/html/HTMLImageElement.cpp | 5++---
Mdom/html/HTMLLinkElement.cpp | 5++---
Mdom/svg/SVGFEImageElement.cpp | 5++---
Mdom/svg/SVGImageElement.cpp | 5++---
Mdom/xul/nsXULElement.cpp | 5++---
Mimage/decoders/icon/nsIconURI.cpp | 5+++++
Mmodules/libjar/nsJARURI.cpp | 5+++++
Mnetwerk/base/DefaultURI.cpp | 13++++---------
Mnetwerk/base/DefaultURI.h | 5+----
Mnetwerk/base/nsIURI.idl | 13+++++++++++++
Mnetwerk/base/nsSimpleURI.cpp | 13+++++++------
Mnetwerk/base/nsSimpleURI.h | 13+------------
Mnetwerk/base/nsStandardURL.cpp | 7+------
Mnetwerk/base/nsStandardURL.h | 6------
Mnetwerk/protocol/res/SubstitutingJARURI.h | 1+
Mnetwerk/protocol/res/SubstitutingProtocolHandler.cpp | 5+++++
Mxpcom/base/moz.build | 1-
Dxpcom/base/nsISizeOf.h | 30------------------------------
19 files changed, 55 insertions(+), 92 deletions(-)

diff --git a/dom/base/Link.cpp b/dom/base/Link.cpp @@ -15,7 +15,6 @@ #include "mozilla/dom/SVGAElement.h" #include "nsAttrValueInlines.h" #include "nsGkAtoms.h" -#include "nsISizeOf.h" #include "nsIURIMutator.h" #include "nsLayoutUtils.h" #include "nsString.h" @@ -442,8 +441,8 @@ void Link::SetHrefAttribute(nsIURI* aURI) { size_t Link::SizeOfExcludingThis(mozilla::SizeOfState& aState) const { size_t n = 0; - if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mCachedURI)) { - n += iface->SizeOfIncludingThis(aState.mMallocSizeOf); + if (mCachedURI) { + n += mCachedURI->SizeOfIncludingThis(aState.mMallocSizeOf); } // The following members don't need to be measured: diff --git a/dom/html/HTMLImageElement.cpp b/dom/html/HTMLImageElement.cpp @@ -27,7 +27,6 @@ #include "nsGenericHTMLElement.h" #include "nsGkAtoms.h" #include "nsIMutationObserver.h" -#include "nsISizeOf.h" #include "nsImageFrame.h" #include "nsNodeInfoManager.h" #include "nsPresContext.h" @@ -1160,8 +1159,8 @@ FetchPriority HTMLImageElement::GetFetchPriorityForImage() const { void HTMLImageElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes, size_t* aNodeSize) const { nsGenericHTMLElement::AddSizeOfExcludingThis(aSizes, aNodeSize); - if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mSrcURI)) { - *aNodeSize += iface->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); + if (mSrcURI) { + *aNodeSize += mSrcURI->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); } } diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp @@ -34,7 +34,6 @@ #include "nsIContentPolicy.h" #include "nsINode.h" #include "nsIPrefetchService.h" -#include "nsISizeOf.h" #include "nsMimeTypes.h" #include "nsPIDOMWindow.h" #include "nsReadableUtils.h" @@ -408,8 +407,8 @@ Maybe<LinkStyle::SheetInfo> HTMLLinkElement::GetStyleSheetInfo() { void HTMLLinkElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes, size_t* aNodeSize) const { nsGenericHTMLElement::AddSizeOfExcludingThis(aSizes, aNodeSize); - if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mCachedURI)) { - *aNodeSize += iface->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); + if (mCachedURI) { + *aNodeSize += mCachedURI->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); } } diff --git a/dom/svg/SVGFEImageElement.cpp b/dom/svg/SVGFEImageElement.cpp @@ -17,7 +17,6 @@ #include "mozilla/dom/UserActivation.h" #include "mozilla/gfx/2D.h" #include "nsContentUtils.h" -#include "nsISizeOf.h" #include "nsLayoutUtils.h" #include "nsNetUtil.h" @@ -432,8 +431,8 @@ void SVGFEImageElement::NotifyImageContentChanged() { void SVGFEImageElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes, size_t* aNodeSize) const { SVGElement::AddSizeOfExcludingThis(aSizes, aNodeSize); - if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mSrcURI)) { - *aNodeSize += iface->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); + if (mSrcURI) { + *aNodeSize += mSrcURI->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); } } diff --git a/dom/svg/SVGImageElement.cpp b/dom/svg/SVGImageElement.cpp @@ -16,7 +16,6 @@ #include "mozilla/gfx/2D.h" #include "nsCOMPtr.h" #include "nsContentUtils.h" -#include "nsISizeOf.h" #include "nsNetUtil.h" NS_IMPL_NS_NEW_SVG_ELEMENT(Image) @@ -339,8 +338,8 @@ void SVGImageElement::DidAnimateAttribute(int32_t aNameSpaceID, void SVGImageElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes, size_t* aNodeSize) const { SVGElement::AddSizeOfExcludingThis(aSizes, aNodeSize); - if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mSrcURI)) { - *aNodeSize += iface->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); + if (mSrcURI) { + *aNodeSize += mSrcURI->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); } } diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp @@ -102,7 +102,6 @@ #include "nsIObjectOutputStream.h" #include "nsIRunnable.h" #include "nsIScriptContext.h" -#include "nsISizeOf.h" #include "nsISupportsUtils.h" #include "nsIURI.h" #include "nsIXPConnect.h" @@ -2012,8 +2011,8 @@ void nsXULPrototypeScript::Set(JS::Stencil* aStencil) { mStencil = aStencil; } void nsXULPrototypeScript::AddSizeOfExcludingThis(nsWindowSizes& aSizes, size_t* aNodeSize) const { - if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mSrcURI)) { - *aNodeSize += iface->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); + if (mSrcURI) { + *aNodeSize += mSrcURI->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf); } } diff --git a/image/decoders/icon/nsIconURI.cpp b/image/decoders/icon/nsIconURI.cpp @@ -603,6 +603,11 @@ bool nsMozIconURI::Deserialize(const URIParams& aParams) { return true; } +size_t nsMozIconURI::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) { + // We don't need to calculate this unless it shows up in DMD. + return 0; +}; + NS_IMETHODIMP nsMozIconURI::GetInnerURI(nsIURI** aURI) { nsCOMPtr<nsIURI> iconURL = mIconURL; diff --git a/modules/libjar/nsJARURI.cpp b/modules/libjar/nsJARURI.cpp @@ -720,3 +720,8 @@ bool nsJARURI::Deserialize(const URIParams& aParams) { return true; } + +size_t nsJARURI::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) { + // We don't need to calculate this unless it shows up in DMD. + return 0; +}; diff --git a/netwerk/base/DefaultURI.cpp b/netwerk/base/DefaultURI.cpp @@ -52,7 +52,6 @@ NS_INTERFACE_TABLE_HEAD(DefaultURI) if (aIID.Equals(kDefaultURICID)) { foundInterface = static_cast<nsIURI*>(this); } else - NS_INTERFACE_MAP_ENTRY(nsISizeOf) NS_INTERFACE_MAP_END //---------------------------------------------------------------------------- @@ -70,14 +69,6 @@ NS_IMETHODIMP DefaultURI::Write(nsIObjectOutputStream* aOutputStream) { } //---------------------------------------------------------------------------- -// nsISizeOf -//---------------------------------------------------------------------------- - -size_t DefaultURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { - return aMallocSizeOf(this) + mURL->SizeOf(); -} - -//---------------------------------------------------------------------------- // nsIURI //---------------------------------------------------------------------------- @@ -293,6 +284,10 @@ void DefaultURI::Serialize(ipc::URIParams& aParams) { aParams = params; } +size_t DefaultURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) { + return aMallocSizeOf(this) + mURL->SizeOf(); +} + //---------------------------------------------------------------------------- // nsIURIMutator //---------------------------------------------------------------------------- diff --git a/netwerk/base/DefaultURI.h b/netwerk/base/DefaultURI.h @@ -7,21 +7,18 @@ #include "nsIURI.h" #include "nsISerializable.h" -#include "nsISizeOf.h" #include "nsIURIMutator.h" #include "mozilla/net/MozURL.h" namespace mozilla { namespace net { -class DefaultURI : public nsIURI, public nsISerializable, public nsISizeOf { +class DefaultURI : public nsIURI, public nsISerializable { public: NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIURI NS_DECL_NSISERIALIZABLE - virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override; - class Mutator final : public nsIURIMutator, public nsISerializable { NS_DECL_ISUPPORTS NS_DECL_NSIURISETSPEC diff --git a/netwerk/base/nsIURI.idl b/netwerk/base/nsIURI.idl @@ -53,6 +53,7 @@ class URIParams; [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. @@ -316,6 +317,18 @@ interface nsIURI : nsISupports */ [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) { diff --git a/netwerk/base/nsSimpleURI.cpp b/netwerk/base/nsSimpleURI.cpp @@ -61,7 +61,6 @@ NS_INTERFACE_TABLE_HEAD(nsSimpleURI) if (aIID.Equals(kThisSimpleURIImplementationCID)) { foundInterface = static_cast<nsIURI*>(this); } else - NS_INTERFACE_MAP_ENTRY(nsISizeOf) NS_INTERFACE_MAP_END //////////////////////////////////////////////////////////////////////////////// @@ -637,11 +636,13 @@ nsSimpleURI::GetAsciiHost(nsACString& result) { return NS_OK; } -//---------------------------------------------------------------------------- -// nsSimpleURI::nsISizeOf -//---------------------------------------------------------------------------- - -size_t nsSimpleURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { +// Among the sub-classes that inherit (directly or indirectly) from +// nsSimpleURI, measurement of the following members may be added later if +// DMD finds it is worthwhile: +// - nsJSURI: mBaseURI +// - nsSimpleNestedURI: mInnerURI +// - nsBlobURI: mPrincipal +size_t nsSimpleURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) { return aMallocSizeOf(this) + mSpec.SizeOfExcludingThisIfUnshared(aMallocSizeOf); } diff --git a/netwerk/base/nsSimpleURI.h b/netwerk/base/nsSimpleURI.h @@ -6,12 +6,10 @@ #ifndef nsSimpleURI_h__ #define nsSimpleURI_h__ -#include "mozilla/MemoryReporting.h" #include "nsIURI.h" #include "nsISerializable.h" #include "nsString.h" #include "nsIClassInfo.h" -#include "nsISizeOf.h" #include "nsIURIMutator.h" #include "nsISimpleURIMutator.h" @@ -25,7 +23,7 @@ namespace net { 0x470b, \ {0xb9, 0xb9, 0x9f, 0xd9, 0x46, 0x2b, 0x5e, 0x19}} -class nsSimpleURI : public nsIURI, public nsISerializable, public nsISizeOf { +class nsSimpleURI : public nsIURI, public nsISerializable { protected: nsSimpleURI() = default; virtual ~nsSimpleURI() = default; @@ -41,15 +39,6 @@ class nsSimpleURI : public nsIURI, public nsISerializable, public nsISizeOf { bool Equals(nsSimpleURI* aOther) { return EqualsInternal(aOther, eHonorRef); } - // nsISizeOf - // Among the sub-classes that inherit (directly or indirectly) from - // nsSimpleURI, measurement of the following members may be added later if - // DMD finds it is worthwhile: - // - nsJSURI: mBaseURI - // - nsSimpleNestedURI: mInnerURI - // - nsBlobURI: mPrincipal - virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override; - protected: // enum used in a few places to specify how .ref attribute should be handled enum RefHandlingEnum { eIgnoreRef, eHonorRef, eReplaceRef }; diff --git a/netwerk/base/nsStandardURL.cpp b/netwerk/base/nsStandardURL.cpp @@ -1141,7 +1141,6 @@ NS_INTERFACE_MAP_BEGIN(nsStandardURL) if (aIID.Equals(kThisImplCID)) { foundInterface = static_cast<nsIURI*>(this); } else - NS_INTERFACE_MAP_ENTRY(nsISizeOf) NS_INTERFACE_MAP_END //---------------------------------------------------------------------------- @@ -3687,11 +3686,7 @@ bool nsStandardURL::Deserialize(const URIParams& aParams) { return true; } -//---------------------------------------------------------------------------- -// nsStandardURL::nsISizeOf -//---------------------------------------------------------------------------- - -size_t nsStandardURL::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { +size_t nsStandardURL::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) { return aMallocSizeOf(this) + mSpec.SizeOfExcludingThisIfUnshared(aMallocSizeOf) + mDisplayHost.SizeOfExcludingThisIfUnshared(aMallocSizeOf); diff --git a/netwerk/base/nsStandardURL.h b/netwerk/base/nsStandardURL.h @@ -15,10 +15,8 @@ #include "mozilla/Encoding.h" #include "nsCOMPtr.h" #include "nsURLHelper.h" -#include "nsISizeOf.h" #include "mozilla/Atomics.h" #include "mozilla/LinkedList.h" -#include "mozilla/MemoryReporting.h" #include "nsISensitiveInfoHiddenURI.h" #include "nsIURIMutator.h" @@ -112,7 +110,6 @@ class URLSegmentNumber { class nsStandardURL : public nsIFileURL, public nsIStandardURL, public nsISerializable, - public nsISizeOf, public nsISensitiveInfoHiddenURI #ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN , @@ -132,9 +129,6 @@ class nsStandardURL : public nsIFileURL, NS_DECL_NSISERIALIZABLE NS_DECL_NSISENSITIVEINFOHIDDENURI - // nsISizeOf - virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override; - static void InitGlobalObjects(); static void ShutdownGlobalObjects(); diff --git a/netwerk/protocol/res/SubstitutingJARURI.h b/netwerk/protocol/res/SubstitutingJARURI.h @@ -153,6 +153,7 @@ class SubstitutingJARURI : public nsIJARURI, } 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 @@ -169,6 +169,11 @@ void SubstitutingJARURI::Serialize(mozilla::ipc::URIParams& aParams) { aParams = params; } +size_t SubstitutingJARURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) { + // We don't need to calcaulte this unless it shows up in DMD. + return 0; +}; + // SubstitutingJARURI::nsISerializable NS_IMETHODIMP diff --git a/xpcom/base/moz.build b/xpcom/base/moz.build @@ -88,7 +88,6 @@ EXPORTS += [ "nsIInterfaceRequestorUtils.h", "nsINIParser.h", "nsInterfaceRequestorAgg.h", - "nsISizeOf.h", "nsISupportsImpl.h", "nsISupportsUtils.h", "nsIWeakReferenceUtils.h", diff --git a/xpcom/base/nsISizeOf.h b/xpcom/base/nsISizeOf.h @@ -1,30 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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 nsISizeOf_h___ -#define nsISizeOf_h___ - -#include "mozilla/MemoryReporting.h" -#include "nsISupports.h" - -#define NS_ISIZEOF_IID \ - {0x61d05579, 0xd7ec, 0x485c, {0xa4, 0x0c, 0x31, 0xc7, 0x9a, 0x5c, 0xf9, 0xf3}} - -class nsISizeOf : public nsISupports { - public: - NS_INLINE_DECL_STATIC_IID(NS_ISIZEOF_IID) - - /** - * Measures the size of the object and the things that it points to. - * Be careful to not call this more than once on a particular object! - * SizeOfExcludingThis does not make sense here because this is a refcounted - * object. - */ - virtual size_t SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const = 0; -}; - -#endif /* nsISizeOf_h___ */