commit 9ded3da8bee66b05748cc174a3475e72e13f255a
parent 2c134d9838d14a82982bdcfb97d77749167d222a
Author: Jeff Muizelaar <jmuizelaar@mozilla.com>
Date: Fri, 28 Nov 2025 04:48:32 +0000
Bug 2002857 - Include the size of the url in Image elements. r=jwatt
This basically matches the behaviour of HTMLLinkElement.
It's important because there can be big data urls in images.
Differential Revision: https://phabricator.services.mozilla.com/D274339
Diffstat:
8 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/dom/html/HTMLImageElement.cpp b/dom/html/HTMLImageElement.cpp
@@ -27,6 +27,7 @@
#include "nsGenericHTMLElement.h"
#include "nsGkAtoms.h"
#include "nsIMutationObserver.h"
+#include "nsISizeOf.h"
#include "nsImageFrame.h"
#include "nsNodeInfoManager.h"
#include "nsPresContext.h"
@@ -1156,4 +1157,12 @@ FetchPriority HTMLImageElement::GetFetchPriorityForImage() const {
return Element::GetFetchPriority();
}
+void HTMLImageElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
+ size_t* aNodeSize) const {
+ nsGenericHTMLElement::AddSizeOfExcludingThis(aSizes, aNodeSize);
+ if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mSrcURI)) {
+ *aNodeSize += iface->SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
+ }
+}
+
} // namespace mozilla::dom
diff --git a/dom/html/HTMLImageElement.h b/dom/html/HTMLImageElement.h
@@ -36,6 +36,7 @@ class HTMLImageElement final : public nsGenericHTMLElement,
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
+ NS_DECL_ADDSIZEOFEXCLUDINGTHIS
bool Draggable() const override;
diff --git a/dom/svg/SVGFEImageElement.cpp b/dom/svg/SVGFEImageElement.cpp
@@ -17,6 +17,7 @@
#include "mozilla/dom/UserActivation.h"
#include "mozilla/gfx/2D.h"
#include "nsContentUtils.h"
+#include "nsISizeOf.h"
#include "nsLayoutUtils.h"
#include "nsNetUtil.h"
@@ -428,4 +429,12 @@ void SVGFEImageElement::NotifyImageContentChanged() {
// We don't support rendering fragments yet (bug 455986)
}
+void SVGFEImageElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
+ size_t* aNodeSize) const {
+ SVGElement::AddSizeOfExcludingThis(aSizes, aNodeSize);
+ if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mSrcURI)) {
+ *aNodeSize += iface->SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
+ }
+}
+
} // namespace mozilla::dom
diff --git a/dom/svg/SVGFEImageElement.h b/dom/svg/SVGFEImageElement.h
@@ -9,6 +9,7 @@
#include "SVGAnimatedPreserveAspectRatio.h"
#include "mozilla/dom/SVGFilters.h"
+#include "nsISizeOf.h"
nsresult NS_NewSVGFEImageElement(
nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
@@ -41,6 +42,7 @@ class SVGFEImageElement final : public SVGFEImageElementBase,
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
+ NS_DECL_ADDSIZEOFEXCLUDINGTHIS
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGFEImageElement,
SVGFEImageElementBase)
diff --git a/dom/svg/SVGImageElement.cpp b/dom/svg/SVGImageElement.cpp
@@ -336,4 +336,12 @@ void SVGImageElement::DidAnimateAttribute(int32_t aNameSpaceID,
SVGImageElementBase::DidAnimateAttribute(aNameSpaceID, aAttribute);
}
+void SVGImageElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
+ size_t* aNodeSize) const {
+ SVGElement::AddSizeOfExcludingThis(aSizes, aNodeSize);
+ if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mSrcURI)) {
+ *aNodeSize += iface->SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
+ }
+}
+
} // namespace mozilla::dom
diff --git a/dom/svg/SVGImageElement.h b/dom/svg/SVGImageElement.h
@@ -12,6 +12,7 @@
#include "mozilla/dom/SVGAnimatedString.h"
#include "mozilla/dom/SVGGeometryElement.h"
#include "mozilla/gfx/2D.h"
+#include "nsISizeOf.h"
#include "nsImageLoadingContent.h"
nsresult NS_NewSVGImageElement(
@@ -43,6 +44,7 @@ class SVGImageElement final : public SVGImageElementBase,
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
+ NS_DECL_ADDSIZEOFEXCLUDINGTHIS
// EventTarget
void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp
@@ -2011,6 +2011,13 @@ nsresult nsXULPrototypeScript::InstantiateScript(
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->SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
+ }
+}
+
//----------------------------------------------------------------------
//
// nsXULPrototypeText
diff --git a/dom/xul/nsXULElement.h b/dom/xul/nsXULElement.h
@@ -43,6 +43,7 @@
#include "nsGkAtoms.h"
#include "nsIContent.h"
#include "nsINode.h"
+#include "nsISizeOf.h"
#include "nsISupports.h"
#include "nsLiteralString.h"
#include "nsString.h"
@@ -266,6 +267,8 @@ class nsXULPrototypeScript : public nsXULPrototypeNode {
nsresult InstantiateScript(JSContext* aCx,
JS::MutableHandle<JSScript*> aScript);
+ void AddSizeOfExcludingThis(nsWindowSizes& aSizes, size_t* aNodeSize) const;
+
nsCOMPtr<nsIURI> mSrcURI;
uint32_t mLineNo;
bool mSrcLoading;