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