tor-browser

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

commit f0a2798907e418d00b5fcae95f7c5a72ac1590c1
parent 999a77895fec9d953cdedb4a7665a04e727fd200
Author: Timothy Nikkel <tnikkel@gmail.com>
Date:   Tue, 16 Dec 2025 10:41:26 +0000

Bug 2006297. Some nsImageLoadingContent cleanup. r=emilio

Move members all to one place in the file. Order them so there are no empty holes of padding to save space. Use initializers.

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

Diffstat:
Mdom/base/nsImageLoadingContent.cpp | 12+-----------
Mdom/base/nsImageLoadingContent.h | 87++++++++++++++++++++++++++++++++++++++++---------------------------------------
2 files changed, 45 insertions(+), 54 deletions(-)

diff --git a/dom/base/nsImageLoadingContent.cpp b/dom/base/nsImageLoadingContent.cpp @@ -128,17 +128,7 @@ class ImageLoadTask : public MicroTaskRunnable { const bool mUseUrgentStartForChannel; }; -nsImageLoadingContent::nsImageLoadingContent() - : mObserverList(nullptr), - mOutstandingDecodePromises(0), - mRequestGeneration(0), - mLoadingEnabled(true), - mUseUrgentStartForChannel(false), - mLazyLoading(false), - mSyncDecodingHint(false), - mInDocResponsiveContent(false), - mCurrentRequestRegistered(false), - mPendingRequestRegistered(false) { +nsImageLoadingContent::nsImageLoadingContent() : mObserverList(nullptr) { if (!nsContentUtils::GetImgLoaderForChannel(nullptr, nullptr)) { mLoadingEnabled = false; } diff --git a/dom/base/nsImageLoadingContent.h b/dom/base/nsImageLoadingContent.h @@ -455,26 +455,6 @@ class nsImageLoadingContent : public nsIImageLoadingContent { nsLoadFlags LoadFlags(); - /* MEMBERS */ - RefPtr<imgRequestProxy> mCurrentRequest; - RefPtr<imgRequestProxy> mPendingRequest; - uint8_t mCurrentRequestFlags = 0; - uint8_t mPendingRequestFlags = 0; - - enum { - // Set if the request is currently tracked with the document. - REQUEST_IS_TRACKED = 1 << 0, - // Set if this is an imageset request, such as from <img srcset> or - // <picture> - REQUEST_IS_IMAGESET = 1 << 1, - }; - - // If the image was blocked or if there was an error loading, it's nice to - // still keep track of what the URI was despite not having an imgIRequest. - // We only maintain this in those situations (in the common case, this is - // always null). - nsCOMPtr<nsIURI> mCurrentURI; - private: /** * Clones the given "current" or "pending" request for each scripted observer. @@ -507,6 +487,23 @@ class nsImageLoadingContent : public nsIImageLoadingContent { void MaybeForceSyncDecoding(bool aPrepareNextRequest, nsIFrame* aFrame = nullptr); + protected: + void QueueImageTask(nsIURI* aURI, nsIPrincipal* aSrcTriggeringPrincipal, + bool aForceAsync, bool aAlwaysLoad, bool aNotify); + void QueueImageTask(nsIURI* aURI, bool aAlwaysLoad, bool aNotify) { + QueueImageTask(aURI, nullptr, false, aAlwaysLoad, aNotify); + } + + void ClearImageLoadTask(); + + virtual void LoadSelectedImage(bool aAlwaysLoad, bool aStopLazyLoading) = 0; + + RefPtr<ImageLoadTask> mPendingImageLoadTask; + + RefPtr<imgRequestProxy> mCurrentRequest; + RefPtr<imgRequestProxy> mPendingRequest; + + private: /** * Typically we will have only one observer (our frame in the screen * prescontext), so we want to only make space for one and to @@ -524,21 +521,27 @@ class nsImageLoadingContent : public nsIImageLoadingContent { */ nsTArray<RefPtr<ScriptedImageObserver>> mScriptedObservers; + // If the image was blocked or if there was an error loading, it's nice to + // still keep track of what the URI was despite not having an imgIRequest. + // We only maintain this in those situations (in the common case, this is + // always null). + nsCOMPtr<nsIURI> mCurrentURI; + + mozilla::TimeStamp mMostRecentRequestChange; + /** * Promises created by QueueDecodeAsync that are still waiting to be * fulfilled by the image being fully decoded. */ nsTArray<RefPtr<mozilla::dom::Promise>> mDecodePromises; - mozilla::TimeStamp mMostRecentRequestChange; - /** * Total number of outstanding decode promises, including those stored in * mDecodePromises and those embedded in runnables waiting to be enqueued. * This is used to determine whether we need to register as an observer for * document activity notifications. */ - size_t mOutstandingDecodePromises; + size_t mOutstandingDecodePromises = 0; /** * An incrementing counter representing the current request generation; @@ -547,44 +550,42 @@ class nsImageLoadingContent : public nsIImageLoadingContent { * of the current request so that when it is processed, it knows if it * should have rejected because the request changed. */ - uint32_t mRequestGeneration; + uint32_t mRequestGeneration = 0; protected: - void QueueImageTask(nsIURI* aURI, nsIPrincipal* aSrcTriggeringPrincipal, - bool aForceAsync, bool aAlwaysLoad, bool aNotify); - void QueueImageTask(nsIURI* aURI, bool aAlwaysLoad, bool aNotify) { - QueueImageTask(aURI, nullptr, false, aAlwaysLoad, aNotify); - } - - void ClearImageLoadTask(); - - virtual void LoadSelectedImage(bool aAlwaysLoad, bool aStopLazyLoading) = 0; - - RefPtr<ImageLoadTask> mPendingImageLoadTask; - - bool mLoadingEnabled : 1; + bool mLoadingEnabled : 1 = true; /** * Flag to indicate whether the channel should be mark as urgent-start. * It should be set in *Element and passed to nsContentUtils::LoadImage. * True if we want to set nsIClassOfService::UrgentStart to the channel to * get the response ASAP for better user responsiveness. */ - bool mUseUrgentStartForChannel : 1; + bool mUseUrgentStartForChannel : 1 = false; // Represents the image is deferred loading until this element gets visible. - bool mLazyLoading : 1; + bool mLazyLoading : 1 = false; // If true, force frames to synchronously decode images on draw. - bool mSyncDecodingHint : 1; + bool mSyncDecodingHint : 1 = false; // Whether we're in the doc responsive content set (HTMLImageElement only). - bool mInDocResponsiveContent : 1; + bool mInDocResponsiveContent : 1 = false; private: // Flags to indicate whether each of the current and pending requests are // registered with the refresh driver. - bool mCurrentRequestRegistered; - bool mPendingRequestRegistered; + bool mCurrentRequestRegistered = false; + bool mPendingRequestRegistered = false; + + enum { + // Set if the request is currently tracked with the document. + REQUEST_IS_TRACKED = 1 << 0, + // Set if this is an imageset request, such as from <img srcset> or + // <picture> + REQUEST_IS_IMAGESET = 1 << 1, + }; + uint8_t mCurrentRequestFlags = 0; + uint8_t mPendingRequestFlags = 0; }; #endif // nsImageLoadingContent_h__