Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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_idbobjectstore_h__ |
michael@0 | 8 | #define mozilla_dom_indexeddb_idbobjectstore_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/dom/indexedDB/IndexedDatabase.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "js/TypeDecls.h" |
michael@0 | 13 | #include "mozilla/dom/IDBCursorBinding.h" |
michael@0 | 14 | #include "mozilla/dom/IDBIndexBinding.h" |
michael@0 | 15 | #include "mozilla/dom/IDBObjectStoreBinding.h" |
michael@0 | 16 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 17 | #include "MainThreadUtils.h" |
michael@0 | 18 | |
michael@0 | 19 | #include "mozilla/dom/indexedDB/IDBRequest.h" |
michael@0 | 20 | #include "mozilla/dom/indexedDB/IDBTransaction.h" |
michael@0 | 21 | #include "mozilla/dom/indexedDB/KeyPath.h" |
michael@0 | 22 | |
michael@0 | 23 | class nsIDOMBlob; |
michael@0 | 24 | class nsIScriptContext; |
michael@0 | 25 | class nsPIDOMWindow; |
michael@0 | 26 | |
michael@0 | 27 | namespace mozilla { |
michael@0 | 28 | namespace dom { |
michael@0 | 29 | class ContentParent; |
michael@0 | 30 | class PBlobChild; |
michael@0 | 31 | class PBlobParent; |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | BEGIN_INDEXEDDB_NAMESPACE |
michael@0 | 36 | |
michael@0 | 37 | class AsyncConnectionHelper; |
michael@0 | 38 | class FileManager; |
michael@0 | 39 | class IDBCursor; |
michael@0 | 40 | class IDBKeyRange; |
michael@0 | 41 | class IDBRequest; |
michael@0 | 42 | class IndexedDBObjectStoreChild; |
michael@0 | 43 | class IndexedDBObjectStoreParent; |
michael@0 | 44 | class Key; |
michael@0 | 45 | |
michael@0 | 46 | struct IndexInfo; |
michael@0 | 47 | struct IndexUpdateInfo; |
michael@0 | 48 | struct ObjectStoreInfo; |
michael@0 | 49 | |
michael@0 | 50 | struct FileHandleData; |
michael@0 | 51 | struct BlobOrFileData; |
michael@0 | 52 | |
michael@0 | 53 | class IDBObjectStore MOZ_FINAL : public nsISupports, |
michael@0 | 54 | public nsWrapperCache |
michael@0 | 55 | { |
michael@0 | 56 | public: |
michael@0 | 57 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 58 | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBObjectStore) |
michael@0 | 59 | |
michael@0 | 60 | static already_AddRefed<IDBObjectStore> |
michael@0 | 61 | Create(IDBTransaction* aTransaction, |
michael@0 | 62 | ObjectStoreInfo* aInfo, |
michael@0 | 63 | const nsACString& aDatabaseId, |
michael@0 | 64 | bool aCreating); |
michael@0 | 65 | |
michael@0 | 66 | static nsresult |
michael@0 | 67 | AppendIndexUpdateInfo(int64_t aIndexID, |
michael@0 | 68 | const KeyPath& aKeyPath, |
michael@0 | 69 | bool aUnique, |
michael@0 | 70 | bool aMultiEntry, |
michael@0 | 71 | JSContext* aCx, |
michael@0 | 72 | JS::Handle<JS::Value> aObject, |
michael@0 | 73 | nsTArray<IndexUpdateInfo>& aUpdateInfoArray); |
michael@0 | 74 | |
michael@0 | 75 | static nsresult |
michael@0 | 76 | UpdateIndexes(IDBTransaction* aTransaction, |
michael@0 | 77 | int64_t aObjectStoreId, |
michael@0 | 78 | const Key& aObjectStoreKey, |
michael@0 | 79 | bool aOverwrite, |
michael@0 | 80 | int64_t aObjectDataId, |
michael@0 | 81 | const nsTArray<IndexUpdateInfo>& aUpdateInfoArray); |
michael@0 | 82 | |
michael@0 | 83 | static nsresult |
michael@0 | 84 | GetStructuredCloneReadInfoFromStatement(mozIStorageStatement* aStatement, |
michael@0 | 85 | uint32_t aDataIndex, |
michael@0 | 86 | uint32_t aFileIdsIndex, |
michael@0 | 87 | IDBDatabase* aDatabase, |
michael@0 | 88 | StructuredCloneReadInfo& aInfo); |
michael@0 | 89 | |
michael@0 | 90 | static void |
michael@0 | 91 | ClearCloneReadInfo(StructuredCloneReadInfo& aReadInfo); |
michael@0 | 92 | |
michael@0 | 93 | static void |
michael@0 | 94 | ClearCloneWriteInfo(StructuredCloneWriteInfo& aWriteInfo); |
michael@0 | 95 | |
michael@0 | 96 | static bool |
michael@0 | 97 | DeserializeValue(JSContext* aCx, |
michael@0 | 98 | StructuredCloneReadInfo& aCloneReadInfo, |
michael@0 | 99 | JS::MutableHandle<JS::Value> aValue); |
michael@0 | 100 | |
michael@0 | 101 | static bool |
michael@0 | 102 | SerializeValue(JSContext* aCx, |
michael@0 | 103 | StructuredCloneWriteInfo& aCloneWriteInfo, |
michael@0 | 104 | JS::Handle<JS::Value> aValue); |
michael@0 | 105 | |
michael@0 | 106 | template <class DeserializationTraits> |
michael@0 | 107 | static JSObject* |
michael@0 | 108 | StructuredCloneReadCallback(JSContext* aCx, |
michael@0 | 109 | JSStructuredCloneReader* aReader, |
michael@0 | 110 | uint32_t aTag, |
michael@0 | 111 | uint32_t aData, |
michael@0 | 112 | void* aClosure); |
michael@0 | 113 | static bool |
michael@0 | 114 | StructuredCloneWriteCallback(JSContext* aCx, |
michael@0 | 115 | JSStructuredCloneWriter* aWriter, |
michael@0 | 116 | JS::Handle<JSObject*> aObj, |
michael@0 | 117 | void* aClosure); |
michael@0 | 118 | |
michael@0 | 119 | static nsresult |
michael@0 | 120 | ConvertFileIdsToArray(const nsAString& aFileIds, |
michael@0 | 121 | nsTArray<int64_t>& aResult); |
michael@0 | 122 | |
michael@0 | 123 | // Called only in the main process. |
michael@0 | 124 | static nsresult |
michael@0 | 125 | ConvertBlobsToActors(ContentParent* aContentParent, |
michael@0 | 126 | FileManager* aFileManager, |
michael@0 | 127 | const nsTArray<StructuredCloneFile>& aFiles, |
michael@0 | 128 | InfallibleTArray<PBlobParent*>& aActors); |
michael@0 | 129 | |
michael@0 | 130 | // Called only in the child process. |
michael@0 | 131 | static void |
michael@0 | 132 | ConvertActorsToBlobs(const InfallibleTArray<PBlobChild*>& aActors, |
michael@0 | 133 | nsTArray<StructuredCloneFile>& aFiles); |
michael@0 | 134 | |
michael@0 | 135 | const nsString& Name() const |
michael@0 | 136 | { |
michael@0 | 137 | return mName; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | bool IsAutoIncrement() const |
michael@0 | 141 | { |
michael@0 | 142 | return mAutoIncrement; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | bool IsWriteAllowed() const |
michael@0 | 146 | { |
michael@0 | 147 | return mTransaction->IsWriteAllowed(); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | int64_t Id() const |
michael@0 | 151 | { |
michael@0 | 152 | NS_ASSERTION(mId != INT64_MIN, "Don't ask for this yet!"); |
michael@0 | 153 | return mId; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | const KeyPath& GetKeyPath() const |
michael@0 | 157 | { |
michael@0 | 158 | return mKeyPath; |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | const bool HasValidKeyPath() const |
michael@0 | 162 | { |
michael@0 | 163 | return mKeyPath.IsValid(); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | IDBTransaction* Transaction() |
michael@0 | 167 | { |
michael@0 | 168 | return mTransaction; |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | ObjectStoreInfo* Info() |
michael@0 | 172 | { |
michael@0 | 173 | return mInfo; |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | void |
michael@0 | 177 | SetActor(IndexedDBObjectStoreChild* aActorChild) |
michael@0 | 178 | { |
michael@0 | 179 | NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!"); |
michael@0 | 180 | mActorChild = aActorChild; |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | void |
michael@0 | 184 | SetActor(IndexedDBObjectStoreParent* aActorParent) |
michael@0 | 185 | { |
michael@0 | 186 | NS_ASSERTION(!aActorParent || !mActorParent, |
michael@0 | 187 | "Shouldn't have more than one!"); |
michael@0 | 188 | mActorParent = aActorParent; |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | IndexedDBObjectStoreChild* |
michael@0 | 192 | GetActorChild() const |
michael@0 | 193 | { |
michael@0 | 194 | return mActorChild; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | IndexedDBObjectStoreParent* |
michael@0 | 198 | GetActorParent() const |
michael@0 | 199 | { |
michael@0 | 200 | return mActorParent; |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | already_AddRefed<IDBIndex> |
michael@0 | 204 | CreateIndexInternal(const IndexInfo& aInfo, |
michael@0 | 205 | ErrorResult& aRv); |
michael@0 | 206 | |
michael@0 | 207 | nsresult AddOrPutInternal( |
michael@0 | 208 | const SerializedStructuredCloneWriteInfo& aCloneWriteInfo, |
michael@0 | 209 | const Key& aKey, |
michael@0 | 210 | const InfallibleTArray<IndexUpdateInfo>& aUpdateInfoArray, |
michael@0 | 211 | const nsTArray<nsCOMPtr<nsIDOMBlob> >& aBlobs, |
michael@0 | 212 | bool aOverwrite, |
michael@0 | 213 | IDBRequest** _retval); |
michael@0 | 214 | |
michael@0 | 215 | already_AddRefed<IDBRequest> |
michael@0 | 216 | GetInternal(IDBKeyRange* aKeyRange, |
michael@0 | 217 | ErrorResult& aRv); |
michael@0 | 218 | |
michael@0 | 219 | already_AddRefed<IDBRequest> |
michael@0 | 220 | GetAllInternal(IDBKeyRange* aKeyRange, |
michael@0 | 221 | uint32_t aLimit, |
michael@0 | 222 | ErrorResult& aRv); |
michael@0 | 223 | |
michael@0 | 224 | already_AddRefed<IDBRequest> |
michael@0 | 225 | GetAllKeysInternal(IDBKeyRange* aKeyRange, |
michael@0 | 226 | uint32_t aLimit, |
michael@0 | 227 | ErrorResult& aRv); |
michael@0 | 228 | |
michael@0 | 229 | already_AddRefed<IDBRequest> |
michael@0 | 230 | DeleteInternal(IDBKeyRange* aKeyRange, |
michael@0 | 231 | ErrorResult& aRv); |
michael@0 | 232 | |
michael@0 | 233 | already_AddRefed<IDBRequest> |
michael@0 | 234 | CountInternal(IDBKeyRange* aKeyRange, |
michael@0 | 235 | ErrorResult& aRv); |
michael@0 | 236 | |
michael@0 | 237 | already_AddRefed<IDBRequest> |
michael@0 | 238 | OpenCursorInternal(IDBKeyRange* aKeyRange, |
michael@0 | 239 | size_t aDirection, |
michael@0 | 240 | ErrorResult& aRv); |
michael@0 | 241 | |
michael@0 | 242 | already_AddRefed<IDBRequest> |
michael@0 | 243 | OpenKeyCursorInternal(IDBKeyRange* aKeyRange, |
michael@0 | 244 | size_t aDirection, |
michael@0 | 245 | ErrorResult& aRv); |
michael@0 | 246 | |
michael@0 | 247 | nsresult |
michael@0 | 248 | OpenCursorFromChildProcess( |
michael@0 | 249 | IDBRequest* aRequest, |
michael@0 | 250 | size_t aDirection, |
michael@0 | 251 | const Key& aKey, |
michael@0 | 252 | const SerializedStructuredCloneReadInfo& aCloneInfo, |
michael@0 | 253 | nsTArray<StructuredCloneFile>& aBlobs, |
michael@0 | 254 | IDBCursor** _retval); |
michael@0 | 255 | |
michael@0 | 256 | nsresult |
michael@0 | 257 | OpenCursorFromChildProcess(IDBRequest* aRequest, |
michael@0 | 258 | size_t aDirection, |
michael@0 | 259 | const Key& aKey, |
michael@0 | 260 | IDBCursor** _retval); |
michael@0 | 261 | |
michael@0 | 262 | void |
michael@0 | 263 | SetInfo(ObjectStoreInfo* aInfo); |
michael@0 | 264 | |
michael@0 | 265 | static const JSClass sDummyPropJSClass; |
michael@0 | 266 | |
michael@0 | 267 | // nsWrapperCache |
michael@0 | 268 | virtual JSObject* |
michael@0 | 269 | WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
michael@0 | 270 | |
michael@0 | 271 | // WebIDL |
michael@0 | 272 | IDBTransaction* |
michael@0 | 273 | GetParentObject() const |
michael@0 | 274 | { |
michael@0 | 275 | return mTransaction; |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | void |
michael@0 | 279 | GetName(nsString& aName) const |
michael@0 | 280 | { |
michael@0 | 281 | NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 282 | aName.Assign(mName); |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | void |
michael@0 | 286 | GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult, |
michael@0 | 287 | ErrorResult& aRv); |
michael@0 | 288 | |
michael@0 | 289 | already_AddRefed<DOMStringList> |
michael@0 | 290 | GetIndexNames(ErrorResult& aRv); |
michael@0 | 291 | |
michael@0 | 292 | IDBTransaction* |
michael@0 | 293 | Transaction() const |
michael@0 | 294 | { |
michael@0 | 295 | NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 296 | return mTransaction; |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | bool |
michael@0 | 300 | AutoIncrement() const |
michael@0 | 301 | { |
michael@0 | 302 | NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 303 | return mAutoIncrement; |
michael@0 | 304 | } |
michael@0 | 305 | |
michael@0 | 306 | already_AddRefed<IDBRequest> |
michael@0 | 307 | Put(JSContext* aCx, JS::Handle<JS::Value> aValue, |
michael@0 | 308 | JS::Handle<JS::Value> aKey, ErrorResult& aRv) |
michael@0 | 309 | { |
michael@0 | 310 | NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 311 | return AddOrPut(aCx, aValue, aKey, true, aRv); |
michael@0 | 312 | } |
michael@0 | 313 | |
michael@0 | 314 | already_AddRefed<IDBRequest> |
michael@0 | 315 | Add(JSContext* aCx, JS::Handle<JS::Value> aValue, |
michael@0 | 316 | JS::Handle<JS::Value> aKey, ErrorResult& aRv) |
michael@0 | 317 | { |
michael@0 | 318 | NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 319 | return AddOrPut(aCx, aValue, aKey, false, aRv); |
michael@0 | 320 | } |
michael@0 | 321 | |
michael@0 | 322 | already_AddRefed<IDBRequest> |
michael@0 | 323 | Delete(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv); |
michael@0 | 324 | |
michael@0 | 325 | already_AddRefed<IDBRequest> |
michael@0 | 326 | Get(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv); |
michael@0 | 327 | |
michael@0 | 328 | already_AddRefed<IDBRequest> |
michael@0 | 329 | Clear(ErrorResult& aRv); |
michael@0 | 330 | |
michael@0 | 331 | already_AddRefed<IDBRequest> |
michael@0 | 332 | OpenCursor(JSContext* aCx, JS::Handle<JS::Value> aRange, |
michael@0 | 333 | IDBCursorDirection aDirection, ErrorResult& aRv); |
michael@0 | 334 | |
michael@0 | 335 | already_AddRefed<IDBIndex> |
michael@0 | 336 | CreateIndex(JSContext* aCx, const nsAString& aName, const nsAString& aKeyPath, |
michael@0 | 337 | const IDBIndexParameters& aOptionalParameters, ErrorResult& aRv); |
michael@0 | 338 | |
michael@0 | 339 | already_AddRefed<IDBIndex> |
michael@0 | 340 | CreateIndex(JSContext* aCx, const nsAString& aName, |
michael@0 | 341 | const Sequence<nsString>& aKeyPath, |
michael@0 | 342 | const IDBIndexParameters& aOptionalParameters, ErrorResult& aRv); |
michael@0 | 343 | |
michael@0 | 344 | already_AddRefed<IDBIndex> |
michael@0 | 345 | Index(const nsAString& aName, ErrorResult &aRv); |
michael@0 | 346 | |
michael@0 | 347 | void |
michael@0 | 348 | DeleteIndex(const nsAString& aIndexName, ErrorResult& aRv); |
michael@0 | 349 | |
michael@0 | 350 | already_AddRefed<IDBRequest> |
michael@0 | 351 | Count(JSContext* aCx, JS::Handle<JS::Value> aKey, |
michael@0 | 352 | ErrorResult& aRv); |
michael@0 | 353 | |
michael@0 | 354 | already_AddRefed<IDBRequest> |
michael@0 | 355 | GetAll(JSContext* aCx, JS::Handle<JS::Value> aKey, |
michael@0 | 356 | const Optional<uint32_t>& aLimit, ErrorResult& aRv); |
michael@0 | 357 | |
michael@0 | 358 | already_AddRefed<IDBRequest> |
michael@0 | 359 | GetAllKeys(JSContext* aCx, JS::Handle<JS::Value> aKey, |
michael@0 | 360 | const Optional<uint32_t>& aLimit, ErrorResult& aRv); |
michael@0 | 361 | |
michael@0 | 362 | already_AddRefed<IDBRequest> |
michael@0 | 363 | OpenKeyCursor(JSContext* aCx, JS::Handle<JS::Value> aRange, |
michael@0 | 364 | IDBCursorDirection aDirection, ErrorResult& aRv); |
michael@0 | 365 | |
michael@0 | 366 | protected: |
michael@0 | 367 | IDBObjectStore(); |
michael@0 | 368 | ~IDBObjectStore(); |
michael@0 | 369 | |
michael@0 | 370 | nsresult GetAddInfo(JSContext* aCx, |
michael@0 | 371 | JS::Handle<JS::Value> aValue, |
michael@0 | 372 | JS::Handle<JS::Value> aKeyVal, |
michael@0 | 373 | StructuredCloneWriteInfo& aCloneWriteInfo, |
michael@0 | 374 | Key& aKey, |
michael@0 | 375 | nsTArray<IndexUpdateInfo>& aUpdateInfoArray); |
michael@0 | 376 | |
michael@0 | 377 | already_AddRefed<IDBRequest> |
michael@0 | 378 | AddOrPut(JSContext* aCx, JS::Handle<JS::Value> aValue, |
michael@0 | 379 | JS::Handle<JS::Value> aKey, bool aOverwrite, |
michael@0 | 380 | ErrorResult& aRv); |
michael@0 | 381 | |
michael@0 | 382 | already_AddRefed<IDBIndex> |
michael@0 | 383 | CreateIndex(JSContext* aCx, const nsAString& aName, KeyPath& aKeyPath, |
michael@0 | 384 | const IDBIndexParameters& aOptionalParameters, ErrorResult& aRv); |
michael@0 | 385 | |
michael@0 | 386 | static void |
michael@0 | 387 | ClearStructuredCloneBuffer(JSAutoStructuredCloneBuffer& aBuffer); |
michael@0 | 388 | |
michael@0 | 389 | static bool |
michael@0 | 390 | ReadFileHandle(JSStructuredCloneReader* aReader, |
michael@0 | 391 | FileHandleData* aRetval); |
michael@0 | 392 | |
michael@0 | 393 | static bool |
michael@0 | 394 | ReadBlobOrFile(JSStructuredCloneReader* aReader, |
michael@0 | 395 | uint32_t aTag, |
michael@0 | 396 | BlobOrFileData* aRetval); |
michael@0 | 397 | private: |
michael@0 | 398 | nsRefPtr<IDBTransaction> mTransaction; |
michael@0 | 399 | |
michael@0 | 400 | int64_t mId; |
michael@0 | 401 | nsString mName; |
michael@0 | 402 | KeyPath mKeyPath; |
michael@0 | 403 | JS::Heap<JS::Value> mCachedKeyPath; |
michael@0 | 404 | bool mRooted; |
michael@0 | 405 | bool mAutoIncrement; |
michael@0 | 406 | nsCString mDatabaseId; |
michael@0 | 407 | nsRefPtr<ObjectStoreInfo> mInfo; |
michael@0 | 408 | |
michael@0 | 409 | nsTArray<nsRefPtr<IDBIndex> > mCreatedIndexes; |
michael@0 | 410 | |
michael@0 | 411 | IndexedDBObjectStoreChild* mActorChild; |
michael@0 | 412 | IndexedDBObjectStoreParent* mActorParent; |
michael@0 | 413 | }; |
michael@0 | 414 | |
michael@0 | 415 | END_INDEXEDDB_NAMESPACE |
michael@0 | 416 | |
michael@0 | 417 | #endif // mozilla_dom_indexeddb_idbobjectstore_h__ |