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"
13 #include "nsISupportsImpl.h"
15 #include "nsWrapperCache.h"
17 class nsIGlobalObject
;
25 class OwningRequestOrUSVString
;
27 struct CacheQueryOptions
;
28 class RequestOrUSVString
;
34 enum class CallerType
: uint32_t;
38 class AutoChildOpArgs
;
41 class Cache final
: public nsISupports
,
42 public nsWrapperCache
,
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
,
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
,
68 already_AddRefed
<Promise
> Keys(JSContext
* aCx
,
69 const Optional
<RequestOrUSVString
>& aRequest
,
70 const CacheQueryOptions
& aParams
,
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
);
82 virtual nsIGlobalObject
* GetGlobalObject() const override
;
85 virtual void AssertOwningThread() const override
;
88 virtual mozilla::ipc::PBackgroundChild
* GetIPCManager() override
;
95 // Called when we're destroyed or CCed.
96 void DisconnectFromActor();
98 already_AddRefed
<Promise
> ExecuteOp(AutoChildOpArgs
& aOpArgs
,
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
;
113 const Namespace mNamespace
;
116 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
117 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Cache
)
122 } // namespace mozilla
124 #endif // mozilla_dom_Cache_h