Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_dom_cache_Cache_h
8 : #define mozilla_dom_cache_Cache_h
9 :
10 : #include "mozilla/dom/cache/Types.h"
11 : #include "mozilla/dom/cache/TypeUtils.h"
12 : #include "nsCOMPtr.h"
13 : #include "nsISupportsImpl.h"
14 : #include "nsString.h"
15 : #include "nsWrapperCache.h"
16 :
17 : class nsIGlobalObject;
18 :
19 : namespace mozilla {
20 :
21 : class ErrorResult;
22 :
23 : namespace dom {
24 :
25 : class OwningRequestOrUSVString;
26 : class Promise;
27 : struct CacheQueryOptions;
28 : class RequestOrUSVString;
29 : class Response;
30 : template<typename T> class Optional;
31 : template<typename T> class Sequence;
32 : enum class CallerType : uint32_t;
33 :
34 : namespace cache {
35 :
36 : class AutoChildOpArgs;
37 : class CacheChild;
38 :
39 : class Cache final : public nsISupports
40 : , public nsWrapperCache
41 : , public TypeUtils
42 : {
43 : public:
44 : Cache(nsIGlobalObject* aGlobal, CacheChild* aActor);
45 :
46 : // webidl interface methods
47 : already_AddRefed<Promise>
48 : Match(const RequestOrUSVString& aRequest, const CacheQueryOptions& aOptions,
49 : ErrorResult& aRv);
50 : already_AddRefed<Promise>
51 : MatchAll(const Optional<RequestOrUSVString>& aRequest,
52 : const CacheQueryOptions& aOptions, ErrorResult& aRv);
53 : already_AddRefed<Promise>
54 : Add(JSContext* aContext, const RequestOrUSVString& aRequest,
55 : CallerType aCallerType, ErrorResult& aRv);
56 : already_AddRefed<Promise>
57 : AddAll(JSContext* aContext,
58 : const Sequence<OwningRequestOrUSVString>& aRequests,
59 : CallerType aCallerType, ErrorResult& aRv);
60 : already_AddRefed<Promise>
61 : Put(const RequestOrUSVString& aRequest, Response& aResponse,
62 : ErrorResult& aRv);
63 : already_AddRefed<Promise>
64 : Delete(const RequestOrUSVString& aRequest, const CacheQueryOptions& aOptions,
65 : ErrorResult& aRv);
66 : already_AddRefed<Promise>
67 : Keys(const Optional<RequestOrUSVString>& aRequest,
68 : const CacheQueryOptions& aParams, ErrorResult& aRv);
69 :
70 : // binding methods
71 : static bool PrefEnabled(JSContext* aCx, JSObject* aObj);
72 :
73 : nsISupports* GetParentObject() const;
74 : virtual JSObject* WrapObject(JSContext* aContext, JS::Handle<JSObject*> aGivenProto) override;
75 :
76 : // Called when CacheChild actor is being destroyed
77 : void DestroyInternal(CacheChild* aActor);
78 :
79 : // TypeUtils methods
80 : virtual nsIGlobalObject*
81 : GetGlobalObject() const override;
82 :
83 : #ifdef DEBUG
84 : virtual void AssertOwningThread() const override;
85 : #endif
86 :
87 : virtual mozilla::ipc::PBackgroundChild*
88 : GetIPCManager() override;
89 :
90 : private:
91 : class FetchHandler;
92 :
93 : ~Cache();
94 :
95 : // Called when we're destroyed or CCed.
96 : void DisconnectFromActor();
97 :
98 : already_AddRefed<Promise>
99 : ExecuteOp(AutoChildOpArgs& aOpArgs, ErrorResult& aRv);
100 :
101 : already_AddRefed<Promise>
102 : AddAll(const GlobalObject& aGlobal, nsTArray<RefPtr<Request>>&& aRequestList,
103 : CallerType aCallerType, ErrorResult& aRv);
104 :
105 : already_AddRefed<Promise>
106 : PutAll(const nsTArray<RefPtr<Request>>& aRequestList,
107 : const nsTArray<RefPtr<Response>>& aResponseList,
108 : ErrorResult& aRv);
109 :
110 : nsCOMPtr<nsIGlobalObject> mGlobal;
111 : CacheChild* mActor;
112 :
113 : public:
114 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
115 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Cache)
116 : };
117 :
118 : } // namespace cache
119 : } // namespace dom
120 : } // namespace mozilla
121 :
122 : #endif // mozilla_dom_Cache_h
|