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 // For ServiceWorker we need to use the document as
63 // token for the key. All those exceptions are handled by this method.
64 static void* GetSpecialCaseDocumentToken(dom::Document
* aDocument
);
66 // For anti-tracking we need to use an isolation key. It can be the suffix of
67 // the PatitionedPrincipal (see StoragePrincipalHelper.h) or the top-level
68 // document's base domain. This is handled by this method.
69 static nsCString
GetIsolationKey(dom::Document
* aDocument
, nsIURI
* aURI
);
71 void EnsureHash() const;
72 void EnsureBlobRef() const;
74 nsCOMPtr
<nsIURI
> mURI
;
75 Maybe
<uint64_t> mBlobSerial
;
76 mutable nsCString mBlobRef
;
77 OriginAttributes mOriginAttributes
;
78 void* mControlledDocument
;
79 nsCString mIsolationKey
;
80 mutable Maybe
<PLDHashNumber
> mHash
;
85 } // namespace mozilla
87 #endif // mozilla_image_src_ImageCacheKey_h