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_idbindex_h__
8 #define mozilla_dom_indexeddb_idbindex_h__
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/dom/IDBCursorBinding.h"
14 #include "mozilla/ErrorResult.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsWrapperCache.h"
18 #include "mozilla/dom/indexedDB/IDBObjectStore.h"
19 #include "mozilla/dom/indexedDB/IDBRequest.h"
20 #include "mozilla/dom/indexedDB/KeyPath.h"
22 class nsIScriptContext
;
25 BEGIN_INDEXEDDB_NAMESPACE
27 class AsyncConnectionHelper
;
32 class IndexedDBIndexChild
;
33 class IndexedDBIndexParent
;
38 class IDBIndex MOZ_FINAL
: public nsISupports
,
42 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
43 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBIndex
)
45 static already_AddRefed
<IDBIndex
>
46 Create(IDBObjectStore
* aObjectStore
,
47 const IndexInfo
* aIndexInfo
,
50 IDBObjectStore
* ObjectStore()
55 const int64_t Id() const
60 const nsString
& Name() const
70 bool IsMultiEntry() const
75 const KeyPath
& GetKeyPath() const
81 SetActor(IndexedDBIndexChild
* aActorChild
)
83 NS_ASSERTION(!aActorChild
|| !mActorChild
, "Shouldn't have more than one!");
84 mActorChild
= aActorChild
;
88 SetActor(IndexedDBIndexParent
* aActorParent
)
90 NS_ASSERTION(!aActorParent
|| !mActorParent
,
91 "Shouldn't have more than one!");
92 mActorParent
= aActorParent
;
101 IndexedDBIndexParent
*
102 GetActorParent() const
107 already_AddRefed
<IDBRequest
>
108 GetInternal(IDBKeyRange
* aKeyRange
,
111 already_AddRefed
<IDBRequest
>
112 GetKeyInternal(IDBKeyRange
* aKeyRange
,
115 already_AddRefed
<IDBRequest
>
116 GetAllInternal(IDBKeyRange
* aKeyRange
,
120 already_AddRefed
<IDBRequest
>
121 GetAllKeysInternal(IDBKeyRange
* aKeyRange
,
125 already_AddRefed
<IDBRequest
>
126 CountInternal(IDBKeyRange
* aKeyRange
,
129 nsresult
OpenCursorFromChildProcess(
130 IDBRequest
* aRequest
,
133 const Key
& aObjectKey
,
134 IDBCursor
** _retval
);
136 already_AddRefed
<IDBRequest
>
137 OpenKeyCursorInternal(IDBKeyRange
* aKeyRange
,
141 nsresult
OpenCursorInternal(IDBKeyRange
* aKeyRange
,
143 IDBRequest
** _retval
);
145 nsresult
OpenCursorFromChildProcess(
146 IDBRequest
* aRequest
,
149 const Key
& aObjectKey
,
150 const SerializedStructuredCloneReadInfo
& aCloneInfo
,
151 nsTArray
<StructuredCloneFile
>& aBlobs
,
152 IDBCursor
** _retval
);
156 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
160 GetParentObject() const
166 GetName(nsString
& aName
) const
168 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
175 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
180 GetKeyPath(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
,
186 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
193 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
197 already_AddRefed
<IDBRequest
>
198 OpenCursor(JSContext
* aCx
, JS::Handle
<JS::Value
> aRange
,
199 IDBCursorDirection aDirection
, ErrorResult
& aRv
);
201 already_AddRefed
<IDBRequest
>
202 OpenKeyCursor(JSContext
* aCx
, JS::Handle
<JS::Value
> aRange
,
203 IDBCursorDirection aDirection
, ErrorResult
& aRv
);
205 already_AddRefed
<IDBRequest
>
206 Get(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
, ErrorResult
& aRv
);
208 already_AddRefed
<IDBRequest
>
209 GetKey(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
, ErrorResult
& aRv
);
211 already_AddRefed
<IDBRequest
>
212 Count(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
,
216 GetStoreName(nsString
& aStoreName
) const
218 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
219 mObjectStore
->GetName(aStoreName
);
222 already_AddRefed
<IDBRequest
>
223 GetAll(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
,
224 const Optional
<uint32_t>& aLimit
, ErrorResult
& aRv
);
226 already_AddRefed
<IDBRequest
>
227 GetAllKeys(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
,
228 const Optional
<uint32_t>& aLimit
, ErrorResult
& aRv
);
234 nsRefPtr
<IDBObjectStore
> mObjectStore
;
239 JS::Heap
<JS::Value
> mCachedKeyPath
;
241 IndexedDBIndexChild
* mActorChild
;
242 IndexedDBIndexParent
* mActorParent
;
249 END_INDEXEDDB_NAMESPACE
251 #endif // mozilla_dom_indexeddb_idbindex_h__