diff --git a/image/ImageCacheKey.cpp b/image/ImageCacheKey.cpp index 9b7d7e258b66..d33773d0d94c 100644 --- a/image/ImageCacheKey.cpp +++ b/image/ImageCacheKey.cpp @@ -7,6 +7,7 @@ #include "mozilla/HashFunctions.h" #include "mozilla/Move.h" +#include "nsContentUtils.h" #include "nsLayoutUtils.h" #include "nsString.h" #include "mozilla/dom/BlobURLProtocolHandler.h" @@ -42,7 +43,7 @@ ImageCacheKey::ImageCacheKey(nsIURI* aURI, nsresult& aRv) : mURI(aURI) , mOriginAttributes(aAttrs) - , mControlledDocument(GetControlledDocumentToken(aDocument)) + , mControlledDocument(GetSpecialCaseDocumentToken(aDocument, aURI)) , mHash(0) , mIsChrome(false) { @@ -125,11 +126,10 @@ ImageCacheKey::SchemeIs(const char* aScheme) } /* static */ void* -ImageCacheKey::GetControlledDocumentToken(nsIDocument* aDocument) +ImageCacheKey::GetSpecialCaseDocumentToken(nsIDocument* aDocument, nsIURI* aURI) { - // For non-controlled documents, we just return null. For controlled - // documents, we cast the pointer into a void* to avoid dereferencing - // it (since we only use it for comparisons), and return it. + // For controlled documents, we cast the pointer into a void* to avoid + // dereferencing it (since we only use it for comparisons). void* pointer = nullptr; RefPtr swm = ServiceWorkerManager::GetInstance(); if (aDocument && swm) { @@ -138,6 +138,16 @@ ImageCacheKey::GetControlledDocumentToken(nsIDocument* aDocument) pointer = aDocument; } } + + // If this document has been marked as tracker, let's use its address to make + // a unique cache key. + if (!pointer && aDocument && + nsContentUtils::StorageDisabledByAntiTracking(nullptr, + aDocument->GetChannel(), + aURI)) { + pointer = aDocument; + } + return pointer; } diff --git a/image/ImageCacheKey.h b/image/ImageCacheKey.h index 96b5aa88b431..f8d089f4e70a 100644 --- a/image/ImageCacheKey.h +++ b/image/ImageCacheKey.h @@ -55,7 +55,11 @@ public: private: bool SchemeIs(const char* aScheme); - static void* GetControlledDocumentToken(nsIDocument* aDocument); + + // For ServiceWorker and for anti-tracking we need to use the document as + // token for the key. All those exceptions are handled by this method. + static void* GetSpecialCaseDocumentToken(nsIDocument* aDocument, + nsIURI* aURI); nsCOMPtr mURI; Maybe mBlobSerial;