|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef mozilla_dom_DataStore_h |
|
6 #define mozilla_dom_DataStore_h |
|
7 |
|
8 #include "mozilla/DOMEventTargetHelper.h" |
|
9 |
|
10 namespace mozilla { |
|
11 |
|
12 class ErrorResult; |
|
13 |
|
14 namespace dom { |
|
15 |
|
16 class Promise; |
|
17 class DataStoreCursor; |
|
18 class DataStoreImpl; |
|
19 class StringOrUnsignedLong; |
|
20 class OwningStringOrUnsignedLong; |
|
21 |
|
22 class DataStore MOZ_FINAL : public DOMEventTargetHelper |
|
23 { |
|
24 public: |
|
25 NS_DECL_ISUPPORTS_INHERITED |
|
26 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DataStore, |
|
27 DOMEventTargetHelper) |
|
28 |
|
29 explicit DataStore(nsPIDOMWindow* aWindow); |
|
30 |
|
31 // WebIDL (internal functions) |
|
32 |
|
33 static already_AddRefed<DataStore> Constructor(GlobalObject& aGlobal, |
|
34 ErrorResult& aRv); |
|
35 |
|
36 virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE; |
|
37 |
|
38 static bool EnabledForScope(JSContext* aCx, JS::Handle<JSObject*> aObj); |
|
39 |
|
40 // WebIDL (public APIs) |
|
41 |
|
42 void GetName(nsAString& aName, ErrorResult& aRv); |
|
43 |
|
44 void GetOwner(nsAString& aOwner, ErrorResult& aRv); |
|
45 |
|
46 bool GetReadOnly(ErrorResult& aRv); |
|
47 |
|
48 already_AddRefed<Promise> Get(const Sequence<OwningStringOrUnsignedLong>& aId, |
|
49 ErrorResult& aRv); |
|
50 |
|
51 already_AddRefed<Promise> Put(JSContext* aCx, |
|
52 JS::Handle<JS::Value> aObj, |
|
53 const StringOrUnsignedLong& aId, |
|
54 const nsAString& aRevisionId, |
|
55 ErrorResult& aRv); |
|
56 |
|
57 already_AddRefed<Promise> Add(JSContext* aCx, |
|
58 JS::Handle<JS::Value> aObj, |
|
59 const Optional<StringOrUnsignedLong>& aId, |
|
60 const nsAString& aRevisionId, |
|
61 ErrorResult& aRv); |
|
62 |
|
63 already_AddRefed<Promise> Remove(const StringOrUnsignedLong& aId, |
|
64 const nsAString& aRevisionId, |
|
65 ErrorResult& aRv); |
|
66 |
|
67 already_AddRefed<Promise> Clear(const nsAString& aRevisionId, |
|
68 ErrorResult& aRv); |
|
69 |
|
70 void GetRevisionId(nsAString& aRevisionId, ErrorResult& aRv); |
|
71 |
|
72 already_AddRefed<Promise> GetLength(ErrorResult& aRv); |
|
73 |
|
74 already_AddRefed<DataStoreCursor> Sync(const nsAString& aRevisionId, |
|
75 ErrorResult& aRv); |
|
76 |
|
77 IMPL_EVENT_HANDLER(change) |
|
78 |
|
79 // This internal function (ChromeOnly) is aimed to make the DataStore keep a |
|
80 // reference to the DataStoreImpl which really implements the API's logic in |
|
81 // JS. We also need to let the DataStoreImpl implementation keep the event |
|
82 // target of DataStore, so that it can know where to fire the events. |
|
83 void SetDataStoreImpl(DataStoreImpl& aStore, ErrorResult& aRv); |
|
84 |
|
85 protected: |
|
86 virtual ~DataStore() {} |
|
87 |
|
88 private: |
|
89 nsRefPtr<DataStoreImpl> mStore; |
|
90 }; |
|
91 |
|
92 } //namespace dom |
|
93 } //namespace mozilla |
|
94 |
|
95 #endif |