Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / cache / CacheStorage.h
blobfe4ab68e6016fbc23fab4b31cafd8e06d1c508c3
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_CacheStorage_h
8 #define mozilla_dom_cache_CacheStorage_h
10 #include "mozilla/UniquePtr.h"
11 #include "mozilla/dom/cache/Types.h"
12 #include "mozilla/dom/cache/TypeUtils.h"
13 #include "nsCOMPtr.h"
14 #include "nsISupportsImpl.h"
15 #include "nsTArray.h"
16 #include "nsWrapperCache.h"
18 class nsIGlobalObject;
20 namespace mozilla {
22 class ErrorResult;
23 enum UseCounter : int16_t;
24 enum class UseCounterWorker : int16_t;
26 namespace ipc {
27 class PrincipalInfo;
28 } // namespace ipc
30 namespace dom {
32 enum class CacheStorageNamespace : uint8_t;
33 class Promise;
34 class WorkerPrivate;
36 namespace cache {
38 class CacheStorageChild;
39 class CacheWorkerRef;
41 class CacheStorage final : public nsISupports,
42 public nsWrapperCache,
43 public TypeUtils {
44 using PBackgroundChild = mozilla::ipc::PBackgroundChild;
46 public:
47 static already_AddRefed<CacheStorage> CreateOnMainThread(
48 Namespace aNamespace, nsIGlobalObject* aGlobal, nsIPrincipal* aPrincipal,
49 bool aForceTrustedOrigin, ErrorResult& aRv);
51 static already_AddRefed<CacheStorage> CreateOnWorker(
52 Namespace aNamespace, nsIGlobalObject* aGlobal,
53 WorkerPrivate* aWorkerPrivate, ErrorResult& aRv);
55 static bool DefineCachesForSandbox(JSContext* aCx,
56 JS::Handle<JSObject*> aGlobal);
58 // webidl interface methods
59 already_AddRefed<Promise> Match(JSContext* aCx,
60 const RequestOrUTF8String& aRequest,
61 const MultiCacheQueryOptions& aOptions,
62 ErrorResult& aRv);
63 already_AddRefed<Promise> Has(const nsAString& aKey, ErrorResult& aRv);
64 already_AddRefed<Promise> Open(const nsAString& aKey, ErrorResult& aRv);
65 already_AddRefed<Promise> Delete(const nsAString& aKey, ErrorResult& aRv);
66 already_AddRefed<Promise> Keys(ErrorResult& aRv);
68 // chrome-only webidl interface methods
69 static already_AddRefed<CacheStorage> Constructor(
70 const GlobalObject& aGlobal, CacheStorageNamespace aNamespace,
71 nsIPrincipal* aPrincipal, ErrorResult& aRv);
73 // binding methods
74 nsISupports* GetParentObject() const;
75 virtual JSObject* WrapObject(JSContext* aContext,
76 JS::Handle<JSObject*> aGivenProto) override;
78 // Called when CacheStorageChild actor is being destroyed
79 void DestroyInternal(CacheStorageChild* aActor);
81 // TypeUtils methods
82 virtual nsIGlobalObject* GetGlobalObject() const override;
83 #ifdef DEBUG
84 virtual void AssertOwningThread() const override;
85 #endif
87 virtual mozilla::ipc::PBackgroundChild* GetIPCManager() override;
89 private:
90 CacheStorage(Namespace aNamespace, nsIGlobalObject* aGlobal,
91 const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
92 SafeRefPtr<CacheWorkerRef> aWorkerRef);
93 explicit CacheStorage(nsresult aFailureResult);
94 ~CacheStorage();
96 struct Entry;
97 void RunRequest(UniquePtr<Entry> aEntry);
99 OpenMode GetOpenMode() const;
101 bool HasStorageAccess(UseCounter aLabel, UseCounterWorker aLabelWorker) const;
103 const Namespace mNamespace;
104 nsCOMPtr<nsIGlobalObject> mGlobal;
105 const UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
107 // weak ref cleared in DestroyInternal
108 CacheStorageChild* mActor;
110 nsresult mStatus;
112 public:
113 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
114 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(CacheStorage)
117 } // namespace cache
118 } // namespace dom
119 } // namespace mozilla
121 #endif // mozilla_dom_cache_CacheStorage_h