Bug 1669129 - [devtools] Enable devtools.overflow.debugging.enabled. r=jdescottes
[gecko.git] / image / ImageCacheKey.h
bloba8ccb4513b0d5a2a43a44e83a77264a0bcd0216a
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/. */
6 /**
7 * ImageCacheKey is the key type for the image cache (see imgLoader.h).
8 */
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"
18 class nsIURI;
20 namespace mozilla {
21 namespace image {
23 /**
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 {
32 public:
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())) {
42 EnsureHash();
44 return mHash.value();
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; }
61 private:
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;
73 nsCOMPtr<nsIURI> mURI;
74 OriginAttributes mOriginAttributes;
75 void* mControlledDocument;
76 nsCString mIsolationKey;
77 mutable Maybe<PLDHashNumber> mHash;
78 bool mIsChrome;
81 } // namespace image
82 } // namespace mozilla
84 #endif // mozilla_image_src_ImageCacheKey_h