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 const nsCString
& IsolationKeyRef() const { return mIsolationKey
; }
56 /// Is this cache entry for a chrome image?
57 bool IsChrome() const { return mIsChrome
; }
59 /// A token indicating which service worker controlled document this entry
60 /// belongs to, if any.
61 void* ControlledDocument() const { return mControlledDocument
; }
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
);
68 // For anti-tracking we need to use an isolation key. It can be the suffix of
69 // the PatitionedPrincipal (see StoragePrincipalHelper.h) or the top-level
70 // document's base domain. This is handled by this method.
71 static nsCString
GetIsolationKey(dom::Document
* aDocument
, nsIURI
* aURI
);
73 void EnsureHash() const;
75 nsCOMPtr
<nsIURI
> mURI
;
76 OriginAttributes mOriginAttributes
;
77 void* mControlledDocument
;
78 nsCString mIsolationKey
;
79 mutable Maybe
<PLDHashNumber
> mHash
;
84 } // namespace mozilla
86 #endif // mozilla_image_src_ImageCacheKey_h