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_idbobjectstore_h__
8 #define mozilla_dom_indexeddb_idbobjectstore_h__
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
12 #include "js/TypeDecls.h"
13 #include "mozilla/dom/IDBCursorBinding.h"
14 #include "mozilla/dom/IDBIndexBinding.h"
15 #include "mozilla/dom/IDBObjectStoreBinding.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "MainThreadUtils.h"
19 #include "mozilla/dom/indexedDB/IDBRequest.h"
20 #include "mozilla/dom/indexedDB/IDBTransaction.h"
21 #include "mozilla/dom/indexedDB/KeyPath.h"
24 class nsIScriptContext
;
29 class nsIContentParent
;
35 BEGIN_INDEXEDDB_NAMESPACE
37 class AsyncConnectionHelper
;
42 class IndexedDBObjectStoreChild
;
43 class IndexedDBObjectStoreParent
;
47 struct IndexUpdateInfo
;
48 struct ObjectStoreInfo
;
50 struct MutableFileData
;
51 struct BlobOrFileData
;
53 class IDBObjectStore MOZ_FINAL
: public nsISupports
,
57 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
58 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBObjectStore
)
60 static already_AddRefed
<IDBObjectStore
>
61 Create(IDBTransaction
* aTransaction
,
62 ObjectStoreInfo
* aInfo
,
63 const nsACString
& aDatabaseId
,
67 AppendIndexUpdateInfo(int64_t aIndexID
,
68 const KeyPath
& aKeyPath
,
72 JS::Handle
<JS::Value
> aObject
,
73 nsTArray
<IndexUpdateInfo
>& aUpdateInfoArray
);
76 UpdateIndexes(IDBTransaction
* aTransaction
,
77 int64_t aObjectStoreId
,
78 const Key
& aObjectStoreKey
,
80 int64_t aObjectDataId
,
81 const nsTArray
<IndexUpdateInfo
>& aUpdateInfoArray
);
84 GetStructuredCloneReadInfoFromStatement(mozIStorageStatement
* aStatement
,
86 uint32_t aFileIdsIndex
,
87 IDBDatabase
* aDatabase
,
88 StructuredCloneReadInfo
& aInfo
);
91 ClearCloneReadInfo(StructuredCloneReadInfo
& aReadInfo
);
94 ClearCloneWriteInfo(StructuredCloneWriteInfo
& aWriteInfo
);
97 DeserializeValue(JSContext
* aCx
,
98 StructuredCloneReadInfo
& aCloneReadInfo
,
99 JS::MutableHandle
<JS::Value
> aValue
);
102 SerializeValue(JSContext
* aCx
,
103 StructuredCloneWriteInfo
& aCloneWriteInfo
,
104 JS::Handle
<JS::Value
> aValue
);
106 template <class DeserializationTraits
>
108 StructuredCloneReadCallback(JSContext
* aCx
,
109 JSStructuredCloneReader
* aReader
,
114 StructuredCloneWriteCallback(JSContext
* aCx
,
115 JSStructuredCloneWriter
* aWriter
,
116 JS::Handle
<JSObject
*> aObj
,
120 ConvertFileIdsToArray(const nsAString
& aFileIds
,
121 nsTArray
<int64_t>& aResult
);
123 // Called only in the main process.
125 ConvertBlobsToActors(nsIContentParent
* aContentParent
,
126 FileManager
* aFileManager
,
127 const nsTArray
<StructuredCloneFile
>& aFiles
,
128 InfallibleTArray
<PBlobParent
*>& aActors
);
130 // Called only in the child process.
132 ConvertActorsToBlobs(const InfallibleTArray
<PBlobChild
*>& aActors
,
133 nsTArray
<StructuredCloneFile
>& aFiles
);
135 const nsString
& Name() const
140 bool IsAutoIncrement() const
142 return mAutoIncrement
;
145 bool IsWriteAllowed() const
147 return mTransaction
->IsWriteAllowed();
152 NS_ASSERTION(mId
!= INT64_MIN
, "Don't ask for this yet!");
156 const KeyPath
& GetKeyPath() const
161 const bool HasValidKeyPath() const
163 return mKeyPath
.IsValid();
166 IDBTransaction
* Transaction()
171 ObjectStoreInfo
* Info()
177 SetActor(IndexedDBObjectStoreChild
* aActorChild
)
179 NS_ASSERTION(!aActorChild
|| !mActorChild
, "Shouldn't have more than one!");
180 mActorChild
= aActorChild
;
184 SetActor(IndexedDBObjectStoreParent
* aActorParent
)
186 NS_ASSERTION(!aActorParent
|| !mActorParent
,
187 "Shouldn't have more than one!");
188 mActorParent
= aActorParent
;
191 IndexedDBObjectStoreChild
*
192 GetActorChild() const
197 IndexedDBObjectStoreParent
*
198 GetActorParent() const
203 already_AddRefed
<IDBIndex
>
204 CreateIndexInternal(const IndexInfo
& aInfo
,
207 nsresult
AddOrPutInternal(
208 const SerializedStructuredCloneWriteInfo
& aCloneWriteInfo
,
210 const InfallibleTArray
<IndexUpdateInfo
>& aUpdateInfoArray
,
211 const nsTArray
<nsCOMPtr
<nsIDOMBlob
> >& aBlobs
,
213 IDBRequest
** _retval
);
215 already_AddRefed
<IDBRequest
>
216 GetInternal(IDBKeyRange
* aKeyRange
,
219 already_AddRefed
<IDBRequest
>
220 GetAllInternal(IDBKeyRange
* aKeyRange
,
224 already_AddRefed
<IDBRequest
>
225 GetAllKeysInternal(IDBKeyRange
* aKeyRange
,
229 already_AddRefed
<IDBRequest
>
230 DeleteInternal(IDBKeyRange
* aKeyRange
,
233 already_AddRefed
<IDBRequest
>
234 CountInternal(IDBKeyRange
* aKeyRange
,
237 already_AddRefed
<IDBRequest
>
238 OpenCursorInternal(IDBKeyRange
* aKeyRange
,
242 already_AddRefed
<IDBRequest
>
243 OpenKeyCursorInternal(IDBKeyRange
* aKeyRange
,
248 OpenCursorFromChildProcess(
249 IDBRequest
* aRequest
,
252 const SerializedStructuredCloneReadInfo
& aCloneInfo
,
253 nsTArray
<StructuredCloneFile
>& aBlobs
,
254 IDBCursor
** _retval
);
257 OpenCursorFromChildProcess(IDBRequest
* aRequest
,
260 IDBCursor
** _retval
);
263 SetInfo(ObjectStoreInfo
* aInfo
);
265 static const JSClass sDummyPropJSClass
;
269 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
273 GetParentObject() const
279 GetName(nsString
& aName
) const
281 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
286 GetKeyPath(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
,
289 already_AddRefed
<DOMStringList
>
290 GetIndexNames(ErrorResult
& aRv
);
295 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
300 AutoIncrement() const
302 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
303 return mAutoIncrement
;
306 already_AddRefed
<IDBRequest
>
307 Put(JSContext
* aCx
, JS::Handle
<JS::Value
> aValue
,
308 JS::Handle
<JS::Value
> aKey
, ErrorResult
& aRv
)
310 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
311 return AddOrPut(aCx
, aValue
, aKey
, true, aRv
);
314 already_AddRefed
<IDBRequest
>
315 Add(JSContext
* aCx
, JS::Handle
<JS::Value
> aValue
,
316 JS::Handle
<JS::Value
> aKey
, ErrorResult
& aRv
)
318 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
319 return AddOrPut(aCx
, aValue
, aKey
, false, aRv
);
322 already_AddRefed
<IDBRequest
>
323 Delete(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
, ErrorResult
& aRv
);
325 already_AddRefed
<IDBRequest
>
326 Get(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
, ErrorResult
& aRv
);
328 already_AddRefed
<IDBRequest
>
329 Clear(ErrorResult
& aRv
);
331 already_AddRefed
<IDBRequest
>
332 OpenCursor(JSContext
* aCx
, JS::Handle
<JS::Value
> aRange
,
333 IDBCursorDirection aDirection
, ErrorResult
& aRv
);
335 already_AddRefed
<IDBIndex
>
336 CreateIndex(JSContext
* aCx
, const nsAString
& aName
, const nsAString
& aKeyPath
,
337 const IDBIndexParameters
& aOptionalParameters
, ErrorResult
& aRv
);
339 already_AddRefed
<IDBIndex
>
340 CreateIndex(JSContext
* aCx
, const nsAString
& aName
,
341 const Sequence
<nsString
>& aKeyPath
,
342 const IDBIndexParameters
& aOptionalParameters
, ErrorResult
& aRv
);
344 already_AddRefed
<IDBIndex
>
345 Index(const nsAString
& aName
, ErrorResult
&aRv
);
348 DeleteIndex(const nsAString
& aIndexName
, ErrorResult
& aRv
);
350 already_AddRefed
<IDBRequest
>
351 Count(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
,
354 already_AddRefed
<IDBRequest
>
355 GetAll(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
,
356 const Optional
<uint32_t>& aLimit
, ErrorResult
& aRv
);
358 already_AddRefed
<IDBRequest
>
359 GetAllKeys(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
,
360 const Optional
<uint32_t>& aLimit
, ErrorResult
& aRv
);
362 already_AddRefed
<IDBRequest
>
363 OpenKeyCursor(JSContext
* aCx
, JS::Handle
<JS::Value
> aRange
,
364 IDBCursorDirection aDirection
, ErrorResult
& aRv
);
370 nsresult
GetAddInfo(JSContext
* aCx
,
371 JS::Handle
<JS::Value
> aValue
,
372 JS::Handle
<JS::Value
> aKeyVal
,
373 StructuredCloneWriteInfo
& aCloneWriteInfo
,
375 nsTArray
<IndexUpdateInfo
>& aUpdateInfoArray
);
377 already_AddRefed
<IDBRequest
>
378 AddOrPut(JSContext
* aCx
, JS::Handle
<JS::Value
> aValue
,
379 JS::Handle
<JS::Value
> aKey
, bool aOverwrite
,
382 already_AddRefed
<IDBIndex
>
383 CreateIndex(JSContext
* aCx
, const nsAString
& aName
, KeyPath
& aKeyPath
,
384 const IDBIndexParameters
& aOptionalParameters
, ErrorResult
& aRv
);
387 ClearStructuredCloneBuffer(JSAutoStructuredCloneBuffer
& aBuffer
);
390 ReadMutableFile(JSStructuredCloneReader
* aReader
,
391 MutableFileData
* aRetval
);
394 ReadBlobOrFile(JSStructuredCloneReader
* aReader
,
396 BlobOrFileData
* aRetval
);
398 nsRefPtr
<IDBTransaction
> mTransaction
;
403 JS::Heap
<JS::Value
> mCachedKeyPath
;
406 nsCString mDatabaseId
;
407 nsRefPtr
<ObjectStoreInfo
> mInfo
;
409 nsTArray
<nsRefPtr
<IDBIndex
> > mCreatedIndexes
;
411 IndexedDBObjectStoreChild
* mActorChild
;
412 IndexedDBObjectStoreParent
* mActorParent
;
415 END_INDEXEDDB_NAMESPACE
417 #endif // mozilla_dom_indexeddb_idbobjectstore_h__