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