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_idbindex_h__ |
michael@0 | 8 | #define mozilla_dom_indexeddb_idbindex_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/IDBRequest.h" |
michael@0 | 20 | #include "mozilla/dom/indexedDB/KeyPath.h" |
michael@0 | 21 | |
michael@0 | 22 | class nsIScriptContext; |
michael@0 | 23 | class nsPIDOMWindow; |
michael@0 | 24 | |
michael@0 | 25 | BEGIN_INDEXEDDB_NAMESPACE |
michael@0 | 26 | |
michael@0 | 27 | class AsyncConnectionHelper; |
michael@0 | 28 | class IDBCursor; |
michael@0 | 29 | class IDBKeyRange; |
michael@0 | 30 | class IDBObjectStore; |
michael@0 | 31 | class IDBRequest; |
michael@0 | 32 | class IndexedDBIndexChild; |
michael@0 | 33 | class IndexedDBIndexParent; |
michael@0 | 34 | class Key; |
michael@0 | 35 | |
michael@0 | 36 | struct IndexInfo; |
michael@0 | 37 | |
michael@0 | 38 | class IDBIndex MOZ_FINAL : public nsISupports, |
michael@0 | 39 | public nsWrapperCache |
michael@0 | 40 | { |
michael@0 | 41 | public: |
michael@0 | 42 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 43 | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBIndex) |
michael@0 | 44 | |
michael@0 | 45 | static already_AddRefed<IDBIndex> |
michael@0 | 46 | Create(IDBObjectStore* aObjectStore, |
michael@0 | 47 | const IndexInfo* aIndexInfo, |
michael@0 | 48 | bool aCreating); |
michael@0 | 49 | |
michael@0 | 50 | IDBObjectStore* ObjectStore() |
michael@0 | 51 | { |
michael@0 | 52 | return mObjectStore; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | const int64_t Id() const |
michael@0 | 56 | { |
michael@0 | 57 | return mId; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | const nsString& Name() const |
michael@0 | 61 | { |
michael@0 | 62 | return mName; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | bool IsUnique() const |
michael@0 | 66 | { |
michael@0 | 67 | return mUnique; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | bool IsMultiEntry() const |
michael@0 | 71 | { |
michael@0 | 72 | return mMultiEntry; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | const KeyPath& GetKeyPath() const |
michael@0 | 76 | { |
michael@0 | 77 | return mKeyPath; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | void |
michael@0 | 81 | SetActor(IndexedDBIndexChild* aActorChild) |
michael@0 | 82 | { |
michael@0 | 83 | NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!"); |
michael@0 | 84 | mActorChild = aActorChild; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | void |
michael@0 | 88 | SetActor(IndexedDBIndexParent* aActorParent) |
michael@0 | 89 | { |
michael@0 | 90 | NS_ASSERTION(!aActorParent || !mActorParent, |
michael@0 | 91 | "Shouldn't have more than one!"); |
michael@0 | 92 | mActorParent = aActorParent; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | IndexedDBIndexChild* |
michael@0 | 96 | GetActorChild() const |
michael@0 | 97 | { |
michael@0 | 98 | return mActorChild; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | IndexedDBIndexParent* |
michael@0 | 102 | GetActorParent() const |
michael@0 | 103 | { |
michael@0 | 104 | return mActorParent; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | already_AddRefed<IDBRequest> |
michael@0 | 108 | GetInternal(IDBKeyRange* aKeyRange, |
michael@0 | 109 | ErrorResult& aRv); |
michael@0 | 110 | |
michael@0 | 111 | already_AddRefed<IDBRequest> |
michael@0 | 112 | GetKeyInternal(IDBKeyRange* aKeyRange, |
michael@0 | 113 | ErrorResult& aRv); |
michael@0 | 114 | |
michael@0 | 115 | already_AddRefed<IDBRequest> |
michael@0 | 116 | GetAllInternal(IDBKeyRange* aKeyRange, |
michael@0 | 117 | uint32_t aLimit, |
michael@0 | 118 | ErrorResult& aRv); |
michael@0 | 119 | |
michael@0 | 120 | already_AddRefed<IDBRequest> |
michael@0 | 121 | GetAllKeysInternal(IDBKeyRange* aKeyRange, |
michael@0 | 122 | uint32_t aLimit, |
michael@0 | 123 | ErrorResult& aRv); |
michael@0 | 124 | |
michael@0 | 125 | already_AddRefed<IDBRequest> |
michael@0 | 126 | CountInternal(IDBKeyRange* aKeyRange, |
michael@0 | 127 | ErrorResult& aRv); |
michael@0 | 128 | |
michael@0 | 129 | nsresult OpenCursorFromChildProcess( |
michael@0 | 130 | IDBRequest* aRequest, |
michael@0 | 131 | size_t aDirection, |
michael@0 | 132 | const Key& aKey, |
michael@0 | 133 | const Key& aObjectKey, |
michael@0 | 134 | IDBCursor** _retval); |
michael@0 | 135 | |
michael@0 | 136 | already_AddRefed<IDBRequest> |
michael@0 | 137 | OpenKeyCursorInternal(IDBKeyRange* aKeyRange, |
michael@0 | 138 | size_t aDirection, |
michael@0 | 139 | ErrorResult& aRv); |
michael@0 | 140 | |
michael@0 | 141 | nsresult OpenCursorInternal(IDBKeyRange* aKeyRange, |
michael@0 | 142 | size_t aDirection, |
michael@0 | 143 | IDBRequest** _retval); |
michael@0 | 144 | |
michael@0 | 145 | nsresult OpenCursorFromChildProcess( |
michael@0 | 146 | IDBRequest* aRequest, |
michael@0 | 147 | size_t aDirection, |
michael@0 | 148 | const Key& aKey, |
michael@0 | 149 | const Key& aObjectKey, |
michael@0 | 150 | const SerializedStructuredCloneReadInfo& aCloneInfo, |
michael@0 | 151 | nsTArray<StructuredCloneFile>& aBlobs, |
michael@0 | 152 | IDBCursor** _retval); |
michael@0 | 153 | |
michael@0 | 154 | // nsWrapperCache |
michael@0 | 155 | virtual JSObject* |
michael@0 | 156 | WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
michael@0 | 157 | |
michael@0 | 158 | // WebIDL |
michael@0 | 159 | IDBObjectStore* |
michael@0 | 160 | GetParentObject() const |
michael@0 | 161 | { |
michael@0 | 162 | return mObjectStore; |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | void |
michael@0 | 166 | GetName(nsString& aName) const |
michael@0 | 167 | { |
michael@0 | 168 | NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 169 | aName.Assign(mName); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | IDBObjectStore* |
michael@0 | 173 | ObjectStore() const |
michael@0 | 174 | { |
michael@0 | 175 | NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 176 | return mObjectStore; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | void |
michael@0 | 180 | GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult, |
michael@0 | 181 | ErrorResult& aRv); |
michael@0 | 182 | |
michael@0 | 183 | bool |
michael@0 | 184 | MultiEntry() const |
michael@0 | 185 | { |
michael@0 | 186 | NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 187 | return mMultiEntry; |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | bool |
michael@0 | 191 | Unique() const |
michael@0 | 192 | { |
michael@0 | 193 | NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 194 | return mUnique; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | already_AddRefed<IDBRequest> |
michael@0 | 198 | OpenCursor(JSContext* aCx, JS::Handle<JS::Value> aRange, |
michael@0 | 199 | IDBCursorDirection aDirection, ErrorResult& aRv); |
michael@0 | 200 | |
michael@0 | 201 | already_AddRefed<IDBRequest> |
michael@0 | 202 | OpenKeyCursor(JSContext* aCx, JS::Handle<JS::Value> aRange, |
michael@0 | 203 | IDBCursorDirection aDirection, ErrorResult& aRv); |
michael@0 | 204 | |
michael@0 | 205 | already_AddRefed<IDBRequest> |
michael@0 | 206 | Get(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv); |
michael@0 | 207 | |
michael@0 | 208 | already_AddRefed<IDBRequest> |
michael@0 | 209 | GetKey(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv); |
michael@0 | 210 | |
michael@0 | 211 | already_AddRefed<IDBRequest> |
michael@0 | 212 | Count(JSContext* aCx, JS::Handle<JS::Value> aKey, |
michael@0 | 213 | ErrorResult& aRv); |
michael@0 | 214 | |
michael@0 | 215 | void |
michael@0 | 216 | GetStoreName(nsString& aStoreName) const |
michael@0 | 217 | { |
michael@0 | 218 | NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 219 | mObjectStore->GetName(aStoreName); |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | already_AddRefed<IDBRequest> |
michael@0 | 223 | GetAll(JSContext* aCx, JS::Handle<JS::Value> aKey, |
michael@0 | 224 | const Optional<uint32_t>& aLimit, ErrorResult& aRv); |
michael@0 | 225 | |
michael@0 | 226 | already_AddRefed<IDBRequest> |
michael@0 | 227 | GetAllKeys(JSContext* aCx, JS::Handle<JS::Value> aKey, |
michael@0 | 228 | const Optional<uint32_t>& aLimit, ErrorResult& aRv); |
michael@0 | 229 | |
michael@0 | 230 | private: |
michael@0 | 231 | IDBIndex(); |
michael@0 | 232 | ~IDBIndex(); |
michael@0 | 233 | |
michael@0 | 234 | nsRefPtr<IDBObjectStore> mObjectStore; |
michael@0 | 235 | |
michael@0 | 236 | int64_t mId; |
michael@0 | 237 | nsString mName; |
michael@0 | 238 | KeyPath mKeyPath; |
michael@0 | 239 | JS::Heap<JS::Value> mCachedKeyPath; |
michael@0 | 240 | |
michael@0 | 241 | IndexedDBIndexChild* mActorChild; |
michael@0 | 242 | IndexedDBIndexParent* mActorParent; |
michael@0 | 243 | |
michael@0 | 244 | bool mUnique; |
michael@0 | 245 | bool mMultiEntry; |
michael@0 | 246 | bool mRooted; |
michael@0 | 247 | }; |
michael@0 | 248 | |
michael@0 | 249 | END_INDEXEDDB_NAMESPACE |
michael@0 | 250 | |
michael@0 | 251 | #endif // mozilla_dom_indexeddb_idbindex_h__ |