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_workers_DataStore_h
6 #define mozilla_dom_workers_DataStore_h
8 #include "mozilla/DOMEventTargetHelper.h"
9 #include "nsProxyRelease.h"
11 #include "WorkerFeature.h"
22 class StringOrUnsignedLong
;
23 class OwningStringOrUnsignedLong
;
27 class DataStoreChangeEventProxy
;
28 class WorkerDataStoreCursor
;
29 class WorkerGlobalScope
;
31 class WorkerDataStore MOZ_FINAL
: public DOMEventTargetHelper
34 NS_DECL_ISUPPORTS_INHERITED
36 explicit WorkerDataStore(WorkerGlobalScope
* aScope
);
38 // WebIDL (internal functions)
40 static already_AddRefed
<WorkerDataStore
> Constructor(GlobalObject
& aGlobal
,
43 virtual JSObject
* WrapObject(JSContext
*aCx
) MOZ_OVERRIDE
;
45 // WebIDL (public APIs)
47 void GetName(JSContext
* aCx
, nsAString
& aName
, ErrorResult
& aRv
);
49 void GetOwner(JSContext
* aCx
, nsAString
& aOwner
, ErrorResult
& aRv
);
51 bool GetReadOnly(JSContext
* aCx
, ErrorResult
& aRv
);
53 already_AddRefed
<Promise
> Get(JSContext
* aCx
,
54 const Sequence
<OwningStringOrUnsignedLong
>& aId
,
57 already_AddRefed
<Promise
> Put(JSContext
* aCx
,
58 JS::Handle
<JS::Value
> aObj
,
59 const StringOrUnsignedLong
& aId
,
60 const nsAString
& aRevisionId
,
63 already_AddRefed
<Promise
> Add(JSContext
* aCx
,
64 JS::Handle
<JS::Value
> aObj
,
65 const Optional
<StringOrUnsignedLong
>& aId
,
66 const nsAString
& aRevisionId
,
69 already_AddRefed
<Promise
> Remove(JSContext
* aCx
,
70 const StringOrUnsignedLong
& aId
,
71 const nsAString
& aRevisionId
,
74 already_AddRefed
<Promise
> Clear(JSContext
* aCx
,
75 const nsAString
& aRevisionId
,
78 void GetRevisionId(JSContext
* aCx
, nsAString
& aRevisionId
, ErrorResult
& aRv
);
80 already_AddRefed
<Promise
> GetLength(JSContext
* aCx
, ErrorResult
& aRv
);
82 already_AddRefed
<WorkerDataStoreCursor
> Sync(JSContext
* aCx
,
83 const nsAString
& aRevisionId
,
86 IMPL_EVENT_HANDLER(change
)
88 // We don't use this for the WorkerDataStore.
89 void SetDataStoreImpl(DataStoreImpl
& aStore
, ErrorResult
& aRv
);
91 void SetBackingDataStore(
92 const nsMainThreadPtrHandle
<DataStore
>& aBackingStore
);
94 void SetDataStoreChangeEventProxy(DataStoreChangeEventProxy
* aEventProxy
);
97 virtual ~WorkerDataStore() {}
100 nsMainThreadPtrHandle
<DataStore
> mBackingStore
;
101 nsRefPtr
<DataStoreChangeEventProxy
> mEventProxy
;
104 class DataStoreChangeEventProxy MOZ_FINAL
: public nsIDOMEventListener
105 , public WorkerFeature
108 NS_DECL_THREADSAFE_ISUPPORTS
109 NS_DECL_NSIDOMEVENTLISTENER
111 DataStoreChangeEventProxy(WorkerPrivate
* aWorkerPrivate
,
112 WorkerDataStore
* aWorkerStore
);
114 WorkerPrivate
* GetWorkerPrivate() const;
116 WorkerDataStore
* GetWorkerStore() const;
119 // WorkerFeature implementation.
121 bool Notify(JSContext
* aCx
, Status aStatus
) MOZ_OVERRIDE
;
124 ~DataStoreChangeEventProxy() {};
126 WorkerPrivate
* mWorkerPrivate
;
128 nsRefPtr
<WorkerDataStore
> mWorkerStore
;
130 bool mCleanedUp
; // To specify if the worker has been cancelled.
132 // Ensure the worker and the main thread won't race to access |mCleanedUp|.
136 } //namespace workers
138 } //namespace mozilla