no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / cache / CacheStorage.h
blob306c7cccd42d24430f23f99ad88d7cd9d6cff240
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 DefineCaches(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
57 // webidl interface methods
58 already_AddRefed<Promise> Match(JSContext* aCx,
59 const RequestOrUSVString& aRequest,
60 const MultiCacheQueryOptions& aOptions,
61 ErrorResult& aRv);
62 already_AddRefed<Promise> Has(const nsAString& aKey, ErrorResult& aRv);
63 already_AddRefed<Promise> Open(const nsAString& aKey, ErrorResult& aRv);
64 already_AddRefed<Promise> Delete(const nsAString& aKey, ErrorResult& aRv);
65 already_AddRefed<Promise> Keys(ErrorResult& aRv);
67 // chrome-only webidl interface methods
68 static already_AddRefed<CacheStorage> Constructor(
69 const GlobalObject& aGlobal, CacheStorageNamespace aNamespace,
70 nsIPrincipal* aPrincipal, ErrorResult& aRv);
72 // binding methods
73 nsISupports* GetParentObject() const;
74 virtual JSObject* WrapObject(JSContext* aContext,
75 JS::Handle<JSObject*> aGivenProto) override;
77 // Called when CacheStorageChild actor is being destroyed
78 void DestroyInternal(CacheStorageChild* aActor);
80 // TypeUtils methods
81 virtual nsIGlobalObject* GetGlobalObject() const override;
82 #ifdef DEBUG
83 virtual void AssertOwningThread() const override;
84 #endif
86 virtual mozilla::ipc::PBackgroundChild* GetIPCManager() override;
88 private:
89 CacheStorage(Namespace aNamespace, nsIGlobalObject* aGlobal,
90 const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
91 SafeRefPtr<CacheWorkerRef> aWorkerRef);
92 explicit CacheStorage(nsresult aFailureResult);
93 ~CacheStorage();
95 struct Entry;
96 void RunRequest(UniquePtr<Entry> aEntry);
98 OpenMode GetOpenMode() const;
100 bool HasStorageAccess(UseCounter aLabel, UseCounterWorker aLabelWorker) const;
102 const Namespace mNamespace;
103 nsCOMPtr<nsIGlobalObject> mGlobal;
104 const UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
106 // weak ref cleared in DestroyInternal
107 CacheStorageChild* mActor;
109 nsresult mStatus;
111 public:
112 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
113 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(CacheStorage)
116 } // namespace cache
117 } // namespace dom
118 } // namespace mozilla
120 #endif // mozilla_dom_cache_CacheStorage_h