/src/mozilla-central/image/ImageCacheKey.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | /** |
7 | | * ImageCacheKey is the key type for the image cache (see imgLoader.h). |
8 | | */ |
9 | | |
10 | | #ifndef mozilla_image_src_ImageCacheKey_h |
11 | | #define mozilla_image_src_ImageCacheKey_h |
12 | | |
13 | | #include "mozilla/BasePrincipal.h" |
14 | | #include "mozilla/Maybe.h" |
15 | | #include "mozilla/RefPtr.h" |
16 | | #include "PLDHashTable.h" |
17 | | |
18 | | class nsIDocument; |
19 | | class nsIURI; |
20 | | |
21 | | namespace mozilla { |
22 | | namespace image { |
23 | | |
24 | | /** |
25 | | * An ImageLib cache entry key. |
26 | | * |
27 | | * We key the cache on the initial URI (before any redirects), with some |
28 | | * canonicalization applied. See ComputeHash() for the details. |
29 | | * Controlled documents do not share their cache entries with |
30 | | * non-controlled documents, or other controlled documents. |
31 | | */ |
32 | | class ImageCacheKey final |
33 | | { |
34 | | public: |
35 | | ImageCacheKey(nsIURI* aURI, const OriginAttributes& aAttrs, |
36 | | nsIDocument* aDocument, nsresult& aRv); |
37 | | |
38 | | ImageCacheKey(const ImageCacheKey& aOther); |
39 | | ImageCacheKey(ImageCacheKey&& aOther); |
40 | | |
41 | | bool operator==(const ImageCacheKey& aOther) const; |
42 | 0 | PLDHashNumber Hash() const { return mHash; } |
43 | | |
44 | | /// A weak pointer to the URI. |
45 | 0 | nsIURI* URI() const { return mURI; } |
46 | | |
47 | 0 | const OriginAttributes& OriginAttributesRef() const { return mOriginAttributes; } |
48 | | |
49 | | /// Is this cache entry for a chrome image? |
50 | 0 | bool IsChrome() const { return mIsChrome; } |
51 | | |
52 | | /// A token indicating which service worker controlled document this entry |
53 | | /// belongs to, if any. |
54 | 0 | void* ControlledDocument() const { return mControlledDocument; } |
55 | | |
56 | | private: |
57 | | bool SchemeIs(const char* aScheme); |
58 | | |
59 | | // For ServiceWorker and for anti-tracking we need to use the document as |
60 | | // token for the key. All those exceptions are handled by this method. |
61 | | static void* GetSpecialCaseDocumentToken(nsIDocument* aDocument, |
62 | | nsIURI* aURI); |
63 | | |
64 | | nsCOMPtr<nsIURI> mURI; |
65 | | Maybe<uint64_t> mBlobSerial; |
66 | | nsCString mBlobRef; |
67 | | OriginAttributes mOriginAttributes; |
68 | | void* mControlledDocument; |
69 | | PLDHashNumber mHash; |
70 | | bool mIsChrome; |
71 | | }; |
72 | | |
73 | | } // namespace image |
74 | | } // namespace mozilla |
75 | | |
76 | | #endif // mozilla_image_src_ImageCacheKey_h |