author | Andrea Marchesini <amarchesini@mozilla.com> |
Wed, 20 Jun 2018 13:38:22 -0400 | |
changeset 423173 | f1401b74761911baf8a453d26bfc2add5573e1e2 |
parent 423172 | a8b4f415c04375d1bf0420cf06690ffecf2b8d3f |
child 423174 | 0ffa02850c0426401f86ce9a9ef6ac1344f14718 |
push id | 34164 |
push user | csabou@mozilla.com |
push date | Thu, 21 Jun 2018 01:17:13 +0000 |
treeherder | mozilla-central@d231a3231680 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | aosmond |
bugs | 1461921 |
milestone | 62.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
image/ImageCacheKey.cpp | file | annotate | diff | comparison | revisions | |
image/ImageCacheKey.h | file | annotate | diff | comparison | revisions |
--- a/image/ImageCacheKey.cpp +++ b/image/ImageCacheKey.cpp @@ -2,16 +2,17 @@ /* 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/. */ #include "ImageCacheKey.h" #include "mozilla/HashFunctions.h" #include "mozilla/Move.h" +#include "nsContentUtils.h" #include "nsLayoutUtils.h" #include "nsString.h" #include "mozilla/dom/BlobURLProtocolHandler.h" #include "mozilla/dom/File.h" #include "mozilla/dom/ServiceWorkerManager.h" #include "nsIDocument.h" #include "nsPrintfCString.h" @@ -37,17 +38,17 @@ BlobSerial(nsIURI* aURI) } ImageCacheKey::ImageCacheKey(nsIURI* aURI, const OriginAttributes& aAttrs, nsIDocument* aDocument, nsresult& aRv) : mURI(aURI) , mOriginAttributes(aAttrs) - , mControlledDocument(GetControlledDocumentToken(aDocument)) + , mControlledDocument(GetSpecialCaseDocumentToken(aDocument, aURI)) , mHash(0) , mIsChrome(false) { if (SchemeIs("blob")) { mBlobSerial = BlobSerial(mURI); } else if (SchemeIs("chrome")) { mIsChrome = true; } @@ -120,26 +121,35 @@ ImageCacheKey::operator==(const ImageCac bool ImageCacheKey::SchemeIs(const char* aScheme) { bool matches = false; return NS_SUCCEEDED(mURI->SchemeIs(aScheme, &matches)) && matches; } /* 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<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance(); if (aDocument && swm) { ErrorResult rv; if (aDocument->GetController().isSome()) { 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; } } // namespace image } // namespace mozilla
--- a/image/ImageCacheKey.h +++ b/image/ImageCacheKey.h @@ -50,17 +50,21 @@ public: bool IsChrome() const { return mIsChrome; } /// A token indicating which service worker controlled document this entry /// belongs to, if any. void* ControlledDocument() const { return mControlledDocument; } 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<nsIURI> mURI; Maybe<uint64_t> mBlobSerial; nsCString mBlobRef; OriginAttributes mOriginAttributes; void* mControlledDocument; PLDHashNumber mHash; bool mIsChrome;