Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / indexedDB / IDBIndex.h
blob806f4ec93e9a2c3a3ef7027d4f66696f9065f3f5
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;
23 class nsPIDOMWindow;
25 BEGIN_INDEXEDDB_NAMESPACE
27 class AsyncConnectionHelper;
28 class IDBCursor;
29 class IDBKeyRange;
30 class IDBObjectStore;
31 class IDBRequest;
32 class IndexedDBIndexChild;
33 class IndexedDBIndexParent;
34 class Key;
36 struct IndexInfo;
38 class IDBIndex MOZ_FINAL : public nsISupports,
39 public nsWrapperCache
41 public:
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,
48 bool aCreating);
50 IDBObjectStore* ObjectStore()
52 return mObjectStore;
55 const int64_t Id() const
57 return mId;
60 const nsString& Name() const
62 return mName;
65 bool IsUnique() const
67 return mUnique;
70 bool IsMultiEntry() const
72 return mMultiEntry;
75 const KeyPath& GetKeyPath() const
77 return mKeyPath;
80 void
81 SetActor(IndexedDBIndexChild* aActorChild)
83 NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
84 mActorChild = aActorChild;
87 void
88 SetActor(IndexedDBIndexParent* aActorParent)
90 NS_ASSERTION(!aActorParent || !mActorParent,
91 "Shouldn't have more than one!");
92 mActorParent = aActorParent;
95 IndexedDBIndexChild*
96 GetActorChild() const
98 return mActorChild;
101 IndexedDBIndexParent*
102 GetActorParent() const
104 return mActorParent;
107 already_AddRefed<IDBRequest>
108 GetInternal(IDBKeyRange* aKeyRange,
109 ErrorResult& aRv);
111 already_AddRefed<IDBRequest>
112 GetKeyInternal(IDBKeyRange* aKeyRange,
113 ErrorResult& aRv);
115 already_AddRefed<IDBRequest>
116 GetAllInternal(IDBKeyRange* aKeyRange,
117 uint32_t aLimit,
118 ErrorResult& aRv);
120 already_AddRefed<IDBRequest>
121 GetAllKeysInternal(IDBKeyRange* aKeyRange,
122 uint32_t aLimit,
123 ErrorResult& aRv);
125 already_AddRefed<IDBRequest>
126 CountInternal(IDBKeyRange* aKeyRange,
127 ErrorResult& aRv);
129 nsresult OpenCursorFromChildProcess(
130 IDBRequest* aRequest,
131 size_t aDirection,
132 const Key& aKey,
133 const Key& aObjectKey,
134 IDBCursor** _retval);
136 already_AddRefed<IDBRequest>
137 OpenKeyCursorInternal(IDBKeyRange* aKeyRange,
138 size_t aDirection,
139 ErrorResult& aRv);
141 nsresult OpenCursorInternal(IDBKeyRange* aKeyRange,
142 size_t aDirection,
143 IDBRequest** _retval);
145 nsresult OpenCursorFromChildProcess(
146 IDBRequest* aRequest,
147 size_t aDirection,
148 const Key& aKey,
149 const Key& aObjectKey,
150 const SerializedStructuredCloneReadInfo& aCloneInfo,
151 nsTArray<StructuredCloneFile>& aBlobs,
152 IDBCursor** _retval);
154 // nsWrapperCache
155 virtual JSObject*
156 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
158 // WebIDL
159 IDBObjectStore*
160 GetParentObject() const
162 return mObjectStore;
165 void
166 GetName(nsString& aName) const
168 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
169 aName.Assign(mName);
172 IDBObjectStore*
173 ObjectStore() const
175 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
176 return mObjectStore;
179 void
180 GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
181 ErrorResult& aRv);
183 bool
184 MultiEntry() const
186 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
187 return mMultiEntry;
190 bool
191 Unique() const
193 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
194 return mUnique;
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,
213 ErrorResult& aRv);
215 void
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);
230 private:
231 IDBIndex();
232 ~IDBIndex();
234 nsRefPtr<IDBObjectStore> mObjectStore;
236 int64_t mId;
237 nsString mName;
238 KeyPath mKeyPath;
239 JS::Heap<JS::Value> mCachedKeyPath;
241 IndexedDBIndexChild* mActorChild;
242 IndexedDBIndexParent* mActorParent;
244 bool mUnique;
245 bool mMultiEntry;
246 bool mRooted;
249 END_INDEXEDDB_NAMESPACE
251 #endif // mozilla_dom_indexeddb_idbindex_h__