Bug 1859752 - Part 4: Update language tag mappings. r=platform-i18n-reviewers,dminor
[gecko.git] / image / ImageCacheKey.h
blob2be4493081bd1af2511b3b7aa7d8f6ca1cd86d90
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 {
22 enum CORSMode : uint8_t;
24 namespace image {
26 /**
27 * An ImageLib cache entry key.
29 * We key the cache on the initial URI (before any redirects), with some
30 * canonicalization applied. See ComputeHash() for the details.
31 * Controlled documents do not share their cache entries with
32 * non-controlled documents, or other controlled documents.
34 class ImageCacheKey final {
35 public:
36 ImageCacheKey(nsIURI*, CORSMode, const OriginAttributes&, dom::Document*);
38 ImageCacheKey(const ImageCacheKey& aOther);
39 ImageCacheKey(ImageCacheKey&& aOther);
41 bool operator==(const ImageCacheKey& aOther) const;
42 PLDHashNumber Hash() const {
43 if (MOZ_UNLIKELY(mHash.isNothing())) {
44 EnsureHash();
46 return mHash.value();
49 /// A weak pointer to the URI.
50 nsIURI* URI() const { return mURI; }
52 CORSMode GetCORSMode() const { return mCORSMode; }
54 const OriginAttributes& OriginAttributesRef() const {
55 return mOriginAttributes;
58 const nsCString& IsolationKeyRef() const { return mIsolationKey; }
60 /// A token indicating which service worker controlled document this entry
61 /// belongs to, if any.
62 void* ControlledDocument() const { return mControlledDocument; }
64 private:
65 // For ServiceWorker we need to use the document as
66 // token for the key. All those exceptions are handled by this method.
67 static void* GetSpecialCaseDocumentToken(dom::Document* aDocument);
69 // For anti-tracking we need to use an isolation key. It can be the suffix of
70 // the PatitionedPrincipal (see StoragePrincipalHelper.h) or the top-level
71 // document's base domain. This is handled by this method.
72 static nsCString GetIsolationKey(dom::Document* aDocument, nsIURI* aURI);
74 void EnsureHash() const;
76 nsCOMPtr<nsIURI> mURI;
77 const OriginAttributes mOriginAttributes;
78 void* mControlledDocument;
79 nsCString mIsolationKey;
80 mutable Maybe<PLDHashNumber> mHash;
81 const CORSMode mCORSMode;
84 } // namespace image
85 } // namespace mozilla
87 #endif // mozilla_image_src_ImageCacheKey_h