Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
5 #ifndef mozilla_dom_DataStore_h
6 #define mozilla_dom_DataStore_h
8 #include "mozilla/DOMEventTargetHelper.h"
10 namespace mozilla {
12 class ErrorResult;
14 namespace dom {
16 class Promise;
17 class DataStoreCursor;
18 class DataStoreImpl;
19 class StringOrUnsignedLong;
20 class OwningStringOrUnsignedLong;
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)
29 explicit DataStore(nsPIDOMWindow* aWindow);
31 // WebIDL (internal functions)
33 static already_AddRefed<DataStore> Constructor(GlobalObject& aGlobal,
34 ErrorResult& aRv);
36 virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
38 static bool EnabledForScope(JSContext* aCx, JS::Handle<JSObject*> aObj);
40 // WebIDL (public APIs)
42 void GetName(nsAString& aName, ErrorResult& aRv);
44 void GetOwner(nsAString& aOwner, ErrorResult& aRv);
46 bool GetReadOnly(ErrorResult& aRv);
48 already_AddRefed<Promise> Get(const Sequence<OwningStringOrUnsignedLong>& aId,
49 ErrorResult& aRv);
51 already_AddRefed<Promise> Put(JSContext* aCx,
52 JS::Handle<JS::Value> aObj,
53 const StringOrUnsignedLong& aId,
54 const nsAString& aRevisionId,
55 ErrorResult& aRv);
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);
63 already_AddRefed<Promise> Remove(const StringOrUnsignedLong& aId,
64 const nsAString& aRevisionId,
65 ErrorResult& aRv);
67 already_AddRefed<Promise> Clear(const nsAString& aRevisionId,
68 ErrorResult& aRv);
70 void GetRevisionId(nsAString& aRevisionId, ErrorResult& aRv);
72 already_AddRefed<Promise> GetLength(ErrorResult& aRv);
74 already_AddRefed<DataStoreCursor> Sync(const nsAString& aRevisionId,
75 ErrorResult& aRv);
77 IMPL_EVENT_HANDLER(change)
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);
85 protected:
86 virtual ~DataStore() {}
88 private:
89 nsRefPtr<DataStoreImpl> mStore;
90 };
92 } //namespace dom
93 } //namespace mozilla
95 #endif