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/. */
7 #ifndef mozilla_dom_indexeddb_idbcursor_h__
8 #define mozilla_dom_indexeddb_idbcursor_h__
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/dom/IDBCursorBinding.h"
14 #include "mozilla/ErrorResult.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsWrapperCache.h"
18 #include "mozilla/dom/indexedDB/IDBObjectStore.h"
19 #include "mozilla/dom/indexedDB/Key.h"
22 class nsIScriptContext
;
27 class OwningIDBObjectStoreOrIDBIndex
;
31 BEGIN_INDEXEDDB_NAMESPACE
34 class ContinueObjectStoreHelper
;
35 class ContinueIndexHelper
;
36 class ContinueIndexObjectHelper
;
40 class IndexedDBCursorChild
;
41 class IndexedDBCursorParent
;
43 class IDBCursor MOZ_FINAL
: public nsISupports
,
46 friend class ContinueHelper
;
47 friend class ContinueObjectStoreHelper
;
48 friend class ContinueIndexHelper
;
49 friend class ContinueIndexObjectHelper
;
52 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
53 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor
)
70 // Only needed for IPC serialization helper, should never be used in code.
74 // For OBJECTSTORE cursors.
76 already_AddRefed
<IDBCursor
>
77 Create(IDBRequest
* aRequest
,
78 IDBTransaction
* aTransaction
,
79 IDBObjectStore
* aObjectStore
,
82 const nsACString
& aContinueQuery
,
83 const nsACString
& aContinueToQuery
,
85 StructuredCloneReadInfo
&& aCloneReadInfo
);
87 // For OBJECTSTOREKEY cursors.
89 already_AddRefed
<IDBCursor
>
90 Create(IDBRequest
* aRequest
,
91 IDBTransaction
* aTransaction
,
92 IDBObjectStore
* aObjectStore
,
95 const nsACString
& aContinueQuery
,
96 const nsACString
& aContinueToQuery
,
99 // For INDEXKEY cursors.
101 already_AddRefed
<IDBCursor
>
102 Create(IDBRequest
* aRequest
,
103 IDBTransaction
* aTransaction
,
105 Direction aDirection
,
106 const Key
& aRangeKey
,
107 const nsACString
& aContinueQuery
,
108 const nsACString
& aContinueToQuery
,
110 const Key
& aObjectKey
);
112 // For INDEXOBJECT cursors.
114 already_AddRefed
<IDBCursor
>
115 Create(IDBRequest
* aRequest
,
116 IDBTransaction
* aTransaction
,
118 Direction aDirection
,
119 const Key
& aRangeKey
,
120 const nsACString
& aContinueQuery
,
121 const nsACString
& aContinueToQuery
,
123 const Key
& aObjectKey
,
124 StructuredCloneReadInfo
&& aCloneReadInfo
);
126 IDBTransaction
* Transaction() const
131 IDBRequest
* Request() const
137 ConvertDirection(IDBCursorDirection aDirection
);
140 SetActor(IndexedDBCursorChild
* aActorChild
)
142 NS_ASSERTION(!aActorChild
|| !mActorChild
, "Shouldn't have more than one!");
143 mActorChild
= aActorChild
;
147 SetActor(IndexedDBCursorParent
* aActorParent
)
149 NS_ASSERTION(!aActorParent
|| !mActorParent
,
150 "Shouldn't have more than one!");
151 mActorParent
= aActorParent
;
154 IndexedDBCursorChild
*
155 GetActorChild() const
160 IndexedDBCursorParent
*
161 GetActorParent() const
167 ContinueInternal(const Key
& aKey
, int32_t aCount
,
172 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
176 GetParentObject() const
182 GetSource(OwningIDBObjectStoreOrIDBIndex
& aSource
) const;
185 GetDirection() const;
188 GetKey(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
,
192 GetPrimaryKey(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
,
195 already_AddRefed
<IDBRequest
>
196 Update(JSContext
* aCx
, JS::Handle
<JS::Value
> aValue
, ErrorResult
& aRv
);
199 Advance(uint32_t aCount
, ErrorResult
& aRv
);
202 Continue(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
, ErrorResult
& aRv
);
204 already_AddRefed
<IDBRequest
>
205 Delete(JSContext
* aCx
, ErrorResult
& aRv
);
208 GetValue(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
,
215 void DropJSObjects();
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
);
227 nsRefPtr
<IDBRequest
> mRequest
;
228 nsRefPtr
<IDBTransaction
> mTransaction
;
229 nsRefPtr
<IDBObjectStore
> mObjectStore
;
230 nsRefPtr
<IDBIndex
> mIndex
;
232 JS::Heap
<JSObject
*> mScriptOwner
;
235 Direction mDirection
;
236 nsCString mContinueQuery
;
237 nsCString mContinueToQuery
;
239 // These are cycle-collected!
240 JS::Heap
<JS::Value
> mCachedKey
;
241 JS::Heap
<JS::Value
> mCachedPrimaryKey
;
242 JS::Heap
<JS::Value
> mCachedValue
;
248 StructuredCloneReadInfo mCloneReadInfo
;
251 IndexedDBCursorChild
* mActorChild
;
252 IndexedDBCursorParent
* mActorParent
;
255 bool mHaveCachedPrimaryKey
;
256 bool mHaveCachedValue
;
258 bool mContinueCalled
;
262 END_INDEXEDDB_NAMESPACE
264 #endif // mozilla_dom_indexeddb_idbcursor_h__