Line data Source code
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 68 : 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 : PLDHashNumber Hash() const { return mHash; }
43 :
44 : /// A weak pointer to the URI. For logging only.
45 : nsIURI* URI() const { return mURI; }
46 :
47 : /// Is this cache entry for a chrome image?
48 : bool IsChrome() const { return mIsChrome; }
49 :
50 : /// A token indicating which service worker controlled document this entry
51 : /// belongs to, if any.
52 : void* ControlledDocument() const { return mControlledDocument; }
53 :
54 : private:
55 : bool SchemeIs(const char* aScheme);
56 : static void* GetControlledDocumentToken(nsIDocument* aDocument);
57 :
58 : nsCOMPtr<nsIURI> mURI;
59 : Maybe<uint64_t> mBlobSerial;
60 : nsCString mBlobRef;
61 : OriginAttributes mOriginAttributes;
62 : void* mControlledDocument;
63 : PLDHashNumber mHash;
64 : bool mIsChrome;
65 : };
66 :
67 : } // namespace image
68 : } // namespace mozilla
69 :
70 : #endif // mozilla_image_src_ImageCacheKey_h
|