From 8e783e6beede1878745d90601141025ebcd17919 Mon Sep 17 00:00:00 2001 From: Sean Feng Date: Thu, 10 Feb 2022 18:18:28 +0000 Subject: [PATCH] Bug 1753471 - Only notify http-on-image-cache-response once per cache entry r=tnikkel I've also tested the behavior in Chrome and I think this is the correct way of doing it. Chrome also only notifies the cached entry once, it won't notify it even if I manually trigger it after pageload. Differential Revision: https://phabricator.services.mozilla.com/D138346 --- image/imgLoader.cpp | 8 +++- image/imgLoader.h | 7 +++ image/test/mochitest/mochitest.ini | 1 + .../test_image_cache_notification.html | 47 +++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 image/test/mochitest/test_image_cache_notification.html diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index 2e4b3615b344..133aaea77b72 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -992,7 +992,8 @@ imgCacheEntry::imgCacheEntry(imgLoader* loader, imgRequest* request, // PutIntoCache will set this to false. mEvicted(true), mHasNoProxies(true), - mForcePrincipalCheck(forcePrincipalCheck) {} + mForcePrincipalCheck(forcePrincipalCheck), + mHasNotified(false) {} imgCacheEntry::~imgCacheEntry() { LOG_FUNC(gImgLog, "imgCacheEntry::~imgCacheEntry()"); @@ -1901,6 +1902,11 @@ void imgLoader::NotifyObserversForCachedImage( imgCacheEntry* aEntry, imgRequest* request, nsIURI* aURI, nsIReferrerInfo* aReferrerInfo, Document* aLoadingDocument, nsIPrincipal* aTriggeringPrincipal, CORSMode aCORSMode) { + if (aEntry->HasNotified()) { + return; + } + aEntry->SetHasNotified(); + nsCOMPtr newChannel; bool forcePrincipalCheck; nsresult rv = diff --git a/image/imgLoader.h b/image/imgLoader.h index 936b73b10617..05ff6dba7ec0 100644 --- a/image/imgLoader.h +++ b/image/imgLoader.h @@ -108,6 +108,12 @@ class imgCacheEntry { bool ForcePrincipalCheck() const { return mForcePrincipalCheck; } + bool HasNotified() const { return mHasNotified; } + void SetHasNotified() { + MOZ_ASSERT(!mHasNotified); + mHasNotified = true; + } + imgLoader* Loader() const { return mLoader; } private: // methods @@ -136,6 +142,7 @@ class imgCacheEntry { bool mEvicted : 1; bool mHasNoProxies : 1; bool mForcePrincipalCheck : 1; + bool mHasNotified : 1; }; #include diff --git a/image/test/mochitest/mochitest.ini b/image/test/mochitest/mochitest.ini index d55ac64aa1cc..6a1aea932758 100644 --- a/image/test/mochitest/mochitest.ini +++ b/image/test/mochitest/mochitest.ini @@ -165,3 +165,4 @@ disabled = bug 1295501 [test_undisplayed_iframe.html] [test_webcam.html] [test_xultree_animation.xhtml] +[test_image_cache_notification.html] diff --git a/image/test/mochitest/test_image_cache_notification.html b/image/test/mochitest/test_image_cache_notification.html new file mode 100644 index 000000000000..73adac25ff55 --- /dev/null +++ b/image/test/mochitest/test_image_cache_notification.html @@ -0,0 +1,47 @@ + + + + + + + + + +