1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/IDBCursor.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,264 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_indexeddb_idbcursor_h__ 1.11 +#define mozilla_dom_indexeddb_idbcursor_h__ 1.12 + 1.13 +#include "mozilla/dom/indexedDB/IndexedDatabase.h" 1.14 + 1.15 +#include "mozilla/Attributes.h" 1.16 +#include "mozilla/dom/IDBCursorBinding.h" 1.17 +#include "mozilla/ErrorResult.h" 1.18 +#include "nsCycleCollectionParticipant.h" 1.19 +#include "nsWrapperCache.h" 1.20 + 1.21 +#include "mozilla/dom/indexedDB/IDBObjectStore.h" 1.22 +#include "mozilla/dom/indexedDB/Key.h" 1.23 + 1.24 +class nsIRunnable; 1.25 +class nsIScriptContext; 1.26 +class nsPIDOMWindow; 1.27 + 1.28 +namespace mozilla { 1.29 +namespace dom { 1.30 +class OwningIDBObjectStoreOrIDBIndex; 1.31 +} 1.32 +} 1.33 + 1.34 +BEGIN_INDEXEDDB_NAMESPACE 1.35 + 1.36 +class ContinueHelper; 1.37 +class ContinueObjectStoreHelper; 1.38 +class ContinueIndexHelper; 1.39 +class ContinueIndexObjectHelper; 1.40 +class IDBIndex; 1.41 +class IDBRequest; 1.42 +class IDBTransaction; 1.43 +class IndexedDBCursorChild; 1.44 +class IndexedDBCursorParent; 1.45 + 1.46 +class IDBCursor MOZ_FINAL : public nsISupports, 1.47 + public nsWrapperCache 1.48 +{ 1.49 + friend class ContinueHelper; 1.50 + friend class ContinueObjectStoreHelper; 1.51 + friend class ContinueIndexHelper; 1.52 + friend class ContinueIndexObjectHelper; 1.53 + 1.54 +public: 1.55 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.56 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor) 1.57 + 1.58 + enum Type 1.59 + { 1.60 + OBJECTSTORE = 0, 1.61 + OBJECTSTOREKEY, 1.62 + INDEXKEY, 1.63 + INDEXOBJECT 1.64 + }; 1.65 + 1.66 + enum Direction 1.67 + { 1.68 + NEXT = 0, 1.69 + NEXT_UNIQUE, 1.70 + PREV, 1.71 + PREV_UNIQUE, 1.72 + 1.73 + // Only needed for IPC serialization helper, should never be used in code. 1.74 + DIRECTION_INVALID 1.75 + }; 1.76 + 1.77 + // For OBJECTSTORE cursors. 1.78 + static 1.79 + already_AddRefed<IDBCursor> 1.80 + Create(IDBRequest* aRequest, 1.81 + IDBTransaction* aTransaction, 1.82 + IDBObjectStore* aObjectStore, 1.83 + Direction aDirection, 1.84 + const Key& aRangeKey, 1.85 + const nsACString& aContinueQuery, 1.86 + const nsACString& aContinueToQuery, 1.87 + const Key& aKey, 1.88 + StructuredCloneReadInfo&& aCloneReadInfo); 1.89 + 1.90 + // For OBJECTSTOREKEY cursors. 1.91 + static 1.92 + already_AddRefed<IDBCursor> 1.93 + Create(IDBRequest* aRequest, 1.94 + IDBTransaction* aTransaction, 1.95 + IDBObjectStore* aObjectStore, 1.96 + Direction aDirection, 1.97 + const Key& aRangeKey, 1.98 + const nsACString& aContinueQuery, 1.99 + const nsACString& aContinueToQuery, 1.100 + const Key& aKey); 1.101 + 1.102 + // For INDEXKEY cursors. 1.103 + static 1.104 + already_AddRefed<IDBCursor> 1.105 + Create(IDBRequest* aRequest, 1.106 + IDBTransaction* aTransaction, 1.107 + IDBIndex* aIndex, 1.108 + Direction aDirection, 1.109 + const Key& aRangeKey, 1.110 + const nsACString& aContinueQuery, 1.111 + const nsACString& aContinueToQuery, 1.112 + const Key& aKey, 1.113 + const Key& aObjectKey); 1.114 + 1.115 + // For INDEXOBJECT cursors. 1.116 + static 1.117 + already_AddRefed<IDBCursor> 1.118 + Create(IDBRequest* aRequest, 1.119 + IDBTransaction* aTransaction, 1.120 + IDBIndex* aIndex, 1.121 + Direction aDirection, 1.122 + const Key& aRangeKey, 1.123 + const nsACString& aContinueQuery, 1.124 + const nsACString& aContinueToQuery, 1.125 + const Key& aKey, 1.126 + const Key& aObjectKey, 1.127 + StructuredCloneReadInfo&& aCloneReadInfo); 1.128 + 1.129 + IDBTransaction* Transaction() const 1.130 + { 1.131 + return mTransaction; 1.132 + } 1.133 + 1.134 + IDBRequest* Request() const 1.135 + { 1.136 + return mRequest; 1.137 + } 1.138 + 1.139 + static Direction 1.140 + ConvertDirection(IDBCursorDirection aDirection); 1.141 + 1.142 + void 1.143 + SetActor(IndexedDBCursorChild* aActorChild) 1.144 + { 1.145 + NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!"); 1.146 + mActorChild = aActorChild; 1.147 + } 1.148 + 1.149 + void 1.150 + SetActor(IndexedDBCursorParent* aActorParent) 1.151 + { 1.152 + NS_ASSERTION(!aActorParent || !mActorParent, 1.153 + "Shouldn't have more than one!"); 1.154 + mActorParent = aActorParent; 1.155 + } 1.156 + 1.157 + IndexedDBCursorChild* 1.158 + GetActorChild() const 1.159 + { 1.160 + return mActorChild; 1.161 + } 1.162 + 1.163 + IndexedDBCursorParent* 1.164 + GetActorParent() const 1.165 + { 1.166 + return mActorParent; 1.167 + } 1.168 + 1.169 + void 1.170 + ContinueInternal(const Key& aKey, int32_t aCount, 1.171 + ErrorResult& aRv); 1.172 + 1.173 + // nsWrapperCache 1.174 + virtual JSObject* 1.175 + WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.176 + 1.177 + // WebIDL 1.178 + IDBTransaction* 1.179 + GetParentObject() const 1.180 + { 1.181 + return mTransaction; 1.182 + } 1.183 + 1.184 + void 1.185 + GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const; 1.186 + 1.187 + IDBCursorDirection 1.188 + GetDirection() const; 1.189 + 1.190 + void 1.191 + GetKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult, 1.192 + ErrorResult& aRv); 1.193 + 1.194 + void 1.195 + GetPrimaryKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult, 1.196 + ErrorResult& aRv); 1.197 + 1.198 + already_AddRefed<IDBRequest> 1.199 + Update(JSContext* aCx, JS::Handle<JS::Value> aValue, ErrorResult& aRv); 1.200 + 1.201 + void 1.202 + Advance(uint32_t aCount, ErrorResult& aRv); 1.203 + 1.204 + void 1.205 + Continue(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv); 1.206 + 1.207 + already_AddRefed<IDBRequest> 1.208 + Delete(JSContext* aCx, ErrorResult& aRv); 1.209 + 1.210 + void 1.211 + GetValue(JSContext* aCx, JS::MutableHandle<JS::Value> aResult, 1.212 + ErrorResult& aRv); 1.213 + 1.214 +protected: 1.215 + IDBCursor(); 1.216 + ~IDBCursor(); 1.217 + 1.218 + void DropJSObjects(); 1.219 + 1.220 + static 1.221 + already_AddRefed<IDBCursor> 1.222 + CreateCommon(IDBRequest* aRequest, 1.223 + IDBTransaction* aTransaction, 1.224 + IDBObjectStore* aObjectStore, 1.225 + Direction aDirection, 1.226 + const Key& aRangeKey, 1.227 + const nsACString& aContinueQuery, 1.228 + const nsACString& aContinueToQuery); 1.229 + 1.230 + nsRefPtr<IDBRequest> mRequest; 1.231 + nsRefPtr<IDBTransaction> mTransaction; 1.232 + nsRefPtr<IDBObjectStore> mObjectStore; 1.233 + nsRefPtr<IDBIndex> mIndex; 1.234 + 1.235 + JS::Heap<JSObject*> mScriptOwner; 1.236 + 1.237 + Type mType; 1.238 + Direction mDirection; 1.239 + nsCString mContinueQuery; 1.240 + nsCString mContinueToQuery; 1.241 + 1.242 + // These are cycle-collected! 1.243 + JS::Heap<JS::Value> mCachedKey; 1.244 + JS::Heap<JS::Value> mCachedPrimaryKey; 1.245 + JS::Heap<JS::Value> mCachedValue; 1.246 + 1.247 + Key mRangeKey; 1.248 + 1.249 + Key mKey; 1.250 + Key mObjectKey; 1.251 + StructuredCloneReadInfo mCloneReadInfo; 1.252 + Key mContinueToKey; 1.253 + 1.254 + IndexedDBCursorChild* mActorChild; 1.255 + IndexedDBCursorParent* mActorParent; 1.256 + 1.257 + bool mHaveCachedKey; 1.258 + bool mHaveCachedPrimaryKey; 1.259 + bool mHaveCachedValue; 1.260 + bool mRooted; 1.261 + bool mContinueCalled; 1.262 + bool mHaveValue; 1.263 +}; 1.264 + 1.265 +END_INDEXEDDB_NAMESPACE 1.266 + 1.267 +#endif // mozilla_dom_indexeddb_idbcursor_h__