Bug 1572460 - Refactor `selection` out of the `InspectorFront`. r=yulia
[gecko.git] / dom / cache / Cache.h
blob0d9078994116c107111752d66f75e4c3be76cb02
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/. */
7 #ifndef mozilla_dom_cache_Cache_h
8 #define mozilla_dom_cache_Cache_h
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"
17 class nsIGlobalObject;
19 namespace mozilla {
21 class ErrorResult;
23 namespace dom {
25 class OwningRequestOrUSVString;
26 class Promise;
27 struct CacheQueryOptions;
28 class RequestOrUSVString;
29 class Response;
30 template <typename T>
31 class Optional;
32 template <typename T>
33 class Sequence;
34 enum class CallerType : uint32_t;
36 namespace cache {
38 class AutoChildOpArgs;
39 class CacheChild;
41 class Cache final : public nsISupports,
42 public nsWrapperCache,
43 public TypeUtils {
44 public:
45 Cache(nsIGlobalObject* aGlobal, CacheChild* aActor, Namespace aNamespace);
47 // webidl interface methods
48 already_AddRefed<Promise> Match(JSContext* aCx,
49 const RequestOrUSVString& aRequest,
50 const CacheQueryOptions& aOptions,
51 ErrorResult& aRv);
52 already_AddRefed<Promise> MatchAll(
53 JSContext* aCx, const Optional<RequestOrUSVString>& aRequest,
54 const CacheQueryOptions& aOptions, ErrorResult& aRv);
55 already_AddRefed<Promise> Add(JSContext* aContext,
56 const RequestOrUSVString& aRequest,
57 CallerType aCallerType, ErrorResult& aRv);
58 already_AddRefed<Promise> AddAll(
59 JSContext* aContext, const Sequence<OwningRequestOrUSVString>& aRequests,
60 CallerType aCallerType, ErrorResult& aRv);
61 already_AddRefed<Promise> Put(JSContext* aCx,
62 const RequestOrUSVString& aRequest,
63 Response& aResponse, ErrorResult& aRv);
64 already_AddRefed<Promise> Delete(JSContext* aCx,
65 const RequestOrUSVString& aRequest,
66 const CacheQueryOptions& aOptions,
67 ErrorResult& aRv);
68 already_AddRefed<Promise> Keys(JSContext* aCx,
69 const Optional<RequestOrUSVString>& aRequest,
70 const CacheQueryOptions& aParams,
71 ErrorResult& aRv);
73 // binding methods
74 nsISupports* GetParentObject() const;
75 virtual JSObject* WrapObject(JSContext* aContext,
76 JS::Handle<JSObject*> aGivenProto) override;
78 // Called when CacheChild actor is being destroyed
79 void DestroyInternal(CacheChild* aActor);
81 // TypeUtils methods
82 virtual nsIGlobalObject* GetGlobalObject() const override;
84 #ifdef DEBUG
85 virtual void AssertOwningThread() const override;
86 #endif
88 virtual mozilla::ipc::PBackgroundChild* GetIPCManager() override;
90 private:
91 class FetchHandler;
93 ~Cache();
95 // Called when we're destroyed or CCed.
96 void DisconnectFromActor();
98 already_AddRefed<Promise> ExecuteOp(AutoChildOpArgs& aOpArgs,
99 ErrorResult& aRv);
101 already_AddRefed<Promise> AddAll(const GlobalObject& aGlobal,
102 nsTArray<RefPtr<Request>>&& aRequestList,
103 CallerType aCallerType, ErrorResult& aRv);
105 already_AddRefed<Promise> PutAll(
106 JSContext* aCx, const nsTArray<RefPtr<Request>>& aRequestList,
107 const nsTArray<RefPtr<Response>>& aResponseList, ErrorResult& aRv);
109 OpenMode GetOpenMode() const;
111 nsCOMPtr<nsIGlobalObject> mGlobal;
112 CacheChild* mActor;
113 const Namespace mNamespace;
115 public:
116 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
117 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Cache)
120 } // namespace cache
121 } // namespace dom
122 } // namespace mozilla
124 #endif // mozilla_dom_Cache_h