dom/indexedDB/IDBCursor.h

changeset 2
7e26c7da4463
equal deleted inserted replaced
-1:000000000000 0:449c1fa3ee2d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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/. */
6
7 #ifndef mozilla_dom_indexeddb_idbcursor_h__
8 #define mozilla_dom_indexeddb_idbcursor_h__
9
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
11
12 #include "mozilla/Attributes.h"
13 #include "mozilla/dom/IDBCursorBinding.h"
14 #include "mozilla/ErrorResult.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsWrapperCache.h"
17
18 #include "mozilla/dom/indexedDB/IDBObjectStore.h"
19 #include "mozilla/dom/indexedDB/Key.h"
20
21 class nsIRunnable;
22 class nsIScriptContext;
23 class nsPIDOMWindow;
24
25 namespace mozilla {
26 namespace dom {
27 class OwningIDBObjectStoreOrIDBIndex;
28 }
29 }
30
31 BEGIN_INDEXEDDB_NAMESPACE
32
33 class ContinueHelper;
34 class ContinueObjectStoreHelper;
35 class ContinueIndexHelper;
36 class ContinueIndexObjectHelper;
37 class IDBIndex;
38 class IDBRequest;
39 class IDBTransaction;
40 class IndexedDBCursorChild;
41 class IndexedDBCursorParent;
42
43 class IDBCursor MOZ_FINAL : public nsISupports,
44 public nsWrapperCache
45 {
46 friend class ContinueHelper;
47 friend class ContinueObjectStoreHelper;
48 friend class ContinueIndexHelper;
49 friend class ContinueIndexObjectHelper;
50
51 public:
52 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
53 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor)
54
55 enum Type
56 {
57 OBJECTSTORE = 0,
58 OBJECTSTOREKEY,
59 INDEXKEY,
60 INDEXOBJECT
61 };
62
63 enum Direction
64 {
65 NEXT = 0,
66 NEXT_UNIQUE,
67 PREV,
68 PREV_UNIQUE,
69
70 // Only needed for IPC serialization helper, should never be used in code.
71 DIRECTION_INVALID
72 };
73
74 // For OBJECTSTORE cursors.
75 static
76 already_AddRefed<IDBCursor>
77 Create(IDBRequest* aRequest,
78 IDBTransaction* aTransaction,
79 IDBObjectStore* aObjectStore,
80 Direction aDirection,
81 const Key& aRangeKey,
82 const nsACString& aContinueQuery,
83 const nsACString& aContinueToQuery,
84 const Key& aKey,
85 StructuredCloneReadInfo&& aCloneReadInfo);
86
87 // For OBJECTSTOREKEY cursors.
88 static
89 already_AddRefed<IDBCursor>
90 Create(IDBRequest* aRequest,
91 IDBTransaction* aTransaction,
92 IDBObjectStore* aObjectStore,
93 Direction aDirection,
94 const Key& aRangeKey,
95 const nsACString& aContinueQuery,
96 const nsACString& aContinueToQuery,
97 const Key& aKey);
98
99 // For INDEXKEY cursors.
100 static
101 already_AddRefed<IDBCursor>
102 Create(IDBRequest* aRequest,
103 IDBTransaction* aTransaction,
104 IDBIndex* aIndex,
105 Direction aDirection,
106 const Key& aRangeKey,
107 const nsACString& aContinueQuery,
108 const nsACString& aContinueToQuery,
109 const Key& aKey,
110 const Key& aObjectKey);
111
112 // For INDEXOBJECT cursors.
113 static
114 already_AddRefed<IDBCursor>
115 Create(IDBRequest* aRequest,
116 IDBTransaction* aTransaction,
117 IDBIndex* aIndex,
118 Direction aDirection,
119 const Key& aRangeKey,
120 const nsACString& aContinueQuery,
121 const nsACString& aContinueToQuery,
122 const Key& aKey,
123 const Key& aObjectKey,
124 StructuredCloneReadInfo&& aCloneReadInfo);
125
126 IDBTransaction* Transaction() const
127 {
128 return mTransaction;
129 }
130
131 IDBRequest* Request() const
132 {
133 return mRequest;
134 }
135
136 static Direction
137 ConvertDirection(IDBCursorDirection aDirection);
138
139 void
140 SetActor(IndexedDBCursorChild* aActorChild)
141 {
142 NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
143 mActorChild = aActorChild;
144 }
145
146 void
147 SetActor(IndexedDBCursorParent* aActorParent)
148 {
149 NS_ASSERTION(!aActorParent || !mActorParent,
150 "Shouldn't have more than one!");
151 mActorParent = aActorParent;
152 }
153
154 IndexedDBCursorChild*
155 GetActorChild() const
156 {
157 return mActorChild;
158 }
159
160 IndexedDBCursorParent*
161 GetActorParent() const
162 {
163 return mActorParent;
164 }
165
166 void
167 ContinueInternal(const Key& aKey, int32_t aCount,
168 ErrorResult& aRv);
169
170 // nsWrapperCache
171 virtual JSObject*
172 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
173
174 // WebIDL
175 IDBTransaction*
176 GetParentObject() const
177 {
178 return mTransaction;
179 }
180
181 void
182 GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const;
183
184 IDBCursorDirection
185 GetDirection() const;
186
187 void
188 GetKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
189 ErrorResult& aRv);
190
191 void
192 GetPrimaryKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
193 ErrorResult& aRv);
194
195 already_AddRefed<IDBRequest>
196 Update(JSContext* aCx, JS::Handle<JS::Value> aValue, ErrorResult& aRv);
197
198 void
199 Advance(uint32_t aCount, ErrorResult& aRv);
200
201 void
202 Continue(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv);
203
204 already_AddRefed<IDBRequest>
205 Delete(JSContext* aCx, ErrorResult& aRv);
206
207 void
208 GetValue(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
209 ErrorResult& aRv);
210
211 protected:
212 IDBCursor();
213 ~IDBCursor();
214
215 void DropJSObjects();
216
217 static
218 already_AddRefed<IDBCursor>
219 CreateCommon(IDBRequest* aRequest,
220 IDBTransaction* aTransaction,
221 IDBObjectStore* aObjectStore,
222 Direction aDirection,
223 const Key& aRangeKey,
224 const nsACString& aContinueQuery,
225 const nsACString& aContinueToQuery);
226
227 nsRefPtr<IDBRequest> mRequest;
228 nsRefPtr<IDBTransaction> mTransaction;
229 nsRefPtr<IDBObjectStore> mObjectStore;
230 nsRefPtr<IDBIndex> mIndex;
231
232 JS::Heap<JSObject*> mScriptOwner;
233
234 Type mType;
235 Direction mDirection;
236 nsCString mContinueQuery;
237 nsCString mContinueToQuery;
238
239 // These are cycle-collected!
240 JS::Heap<JS::Value> mCachedKey;
241 JS::Heap<JS::Value> mCachedPrimaryKey;
242 JS::Heap<JS::Value> mCachedValue;
243
244 Key mRangeKey;
245
246 Key mKey;
247 Key mObjectKey;
248 StructuredCloneReadInfo mCloneReadInfo;
249 Key mContinueToKey;
250
251 IndexedDBCursorChild* mActorChild;
252 IndexedDBCursorParent* mActorParent;
253
254 bool mHaveCachedKey;
255 bool mHaveCachedPrimaryKey;
256 bool mHaveCachedValue;
257 bool mRooted;
258 bool mContinueCalled;
259 bool mHaveValue;
260 };
261
262 END_INDEXEDDB_NAMESPACE
263
264 #endif // mozilla_dom_indexeddb_idbcursor_h__

mercurial