1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * ImageCacheKey is the key type for the image cache (see imgLoader.h).
10 #ifndef mozilla_image_src_ImageCacheKey_h
11 #define mozilla_image_src_ImageCacheKey_h
13 #include "mozilla/BasePrincipal.h"
14 #include "mozilla/Maybe.h"
15 #include "mozilla/RefPtr.h"
16 #include "PLDHashTable.h"
24 * An ImageLib cache entry key.
26 * We key the cache on the initial URI (before any redirects), with some
27 * canonicalization applied. See ComputeHash() for the details.
28 * Controlled documents do not share their cache entries with
29 * non-controlled documents, or other controlled documents.
31 class ImageCacheKey final
{
33 ImageCacheKey(nsIURI
* aURI
, const OriginAttributes
& aAttrs
,
34 dom::Document
* aDocument
);
36 ImageCacheKey(const ImageCacheKey
& aOther
);
37 ImageCacheKey(ImageCacheKey
&& aOther
);
39 bool operator==(const ImageCacheKey
& aOther
) const;
40 PLDHashNumber
Hash() const {
41 if (MOZ_UNLIKELY(mHash
.isNothing())) {
47 /// A weak pointer to the URI.
48 nsIURI
* URI() const { return mURI
; }
50 const OriginAttributes
& OriginAttributesRef() const {
51 return mOriginAttributes
;
54 /// Is this cache entry for a chrome image?
55 bool IsChrome() const { return mIsChrome
; }
57 /// A token indicating which service worker controlled document this entry
58 /// belongs to, if any.
59 void* ControlledDocument() const { return mControlledDocument
; }
62 bool SchemeIs(const char* aScheme
);
64 // For ServiceWorker we need to use the document as
65 // token for the key. All those exceptions are handled by this method.
66 static void* GetSpecialCaseDocumentToken(dom::Document
* aDocument
,
69 // For anti-tracking we need to use the top-level document's base domain for
70 // the key. This is handled by this method.
71 static nsCString
GetTopLevelBaseDomain(dom::Document
* aDocument
,
74 void EnsureHash() const;
75 void EnsureBlobRef() const;
77 nsCOMPtr
<nsIURI
> mURI
;
78 Maybe
<uint64_t> mBlobSerial
;
79 mutable nsCString mBlobRef
;
80 OriginAttributes mOriginAttributes
;
81 void* mControlledDocument
;
82 nsCString mTopLevelBaseDomain
;
83 mutable Maybe
<PLDHashNumber
> mHash
;
88 } // namespace mozilla
90 #endif // mozilla_image_src_ImageCacheKey_h