Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=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_idbindex_h__
8 : #define mozilla_dom_idbindex_h__
9 :
10 : #include "js/RootingAPI.h"
11 : #include "mozilla/Attributes.h"
12 : #include "mozilla/dom/IDBCursorBinding.h"
13 : #include "nsAutoPtr.h"
14 : #include "nsCycleCollectionParticipant.h"
15 : #include "nsISupports.h"
16 : #include "nsTArrayForwardDeclare.h"
17 : #include "nsWrapperCache.h"
18 :
19 : class nsPIDOMWindowInner;
20 :
21 : namespace mozilla {
22 :
23 : class ErrorResult;
24 :
25 : namespace dom {
26 :
27 : class IDBObjectStore;
28 : class IDBRequest;
29 : template <typename> class Sequence;
30 :
31 : namespace indexedDB {
32 : class IndexMetadata;
33 : class KeyPath;
34 : } // namespace indexedDB
35 :
36 : class IDBIndex final
37 : : public nsISupports
38 : , public nsWrapperCache
39 : {
40 : RefPtr<IDBObjectStore> mObjectStore;
41 :
42 : JS::Heap<JS::Value> mCachedKeyPath;
43 :
44 : // This normally points to the IndexMetadata owned by the parent IDBDatabase
45 : // object. However, if this index is part of a versionchange transaction and
46 : // it gets deleted then the metadata is copied into mDeletedMetadata and
47 : // mMetadata is set to point at mDeletedMetadata.
48 : const indexedDB::IndexMetadata* mMetadata;
49 : nsAutoPtr<indexedDB::IndexMetadata> mDeletedMetadata;
50 :
51 : const int64_t mId;
52 : bool mRooted;
53 :
54 : public:
55 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
56 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBIndex)
57 :
58 : static already_AddRefed<IDBIndex>
59 : Create(IDBObjectStore* aObjectStore, const indexedDB::IndexMetadata& aMetadata);
60 :
61 : int64_t
62 0 : Id() const
63 : {
64 0 : AssertIsOnOwningThread();
65 :
66 0 : return mId;
67 : }
68 :
69 : const nsString&
70 : Name() const;
71 :
72 : bool
73 : Unique() const;
74 :
75 : bool
76 : MultiEntry() const;
77 :
78 : bool
79 : LocaleAware() const;
80 :
81 : const indexedDB::KeyPath&
82 : GetKeyPath() const;
83 :
84 : void
85 : GetLocale(nsString& aLocale) const;
86 :
87 : const nsCString&
88 : Locale() const;
89 :
90 : bool
91 : IsAutoLocale() const;
92 :
93 : IDBObjectStore*
94 0 : ObjectStore() const
95 : {
96 0 : AssertIsOnOwningThread();
97 0 : return mObjectStore;
98 : }
99 :
100 : nsPIDOMWindowInner*
101 : GetParentObject() const;
102 :
103 : void
104 0 : GetName(nsString& aName) const
105 : {
106 0 : aName = Name();
107 0 : }
108 :
109 : void
110 : SetName(const nsAString& aName, ErrorResult& aRv);
111 :
112 : void
113 : GetKeyPath(JSContext* aCx,
114 : JS::MutableHandle<JS::Value> aResult,
115 : ErrorResult& aRv);
116 :
117 : already_AddRefed<IDBRequest>
118 0 : OpenCursor(JSContext* aCx,
119 : JS::Handle<JS::Value> aRange,
120 : IDBCursorDirection aDirection,
121 : ErrorResult& aRv)
122 : {
123 0 : AssertIsOnOwningThread();
124 :
125 : return OpenCursorInternal(/* aKeysOnly */ false, aCx, aRange, aDirection,
126 0 : aRv);
127 : }
128 :
129 : already_AddRefed<IDBRequest>
130 0 : OpenKeyCursor(JSContext* aCx,
131 : JS::Handle<JS::Value> aRange,
132 : IDBCursorDirection aDirection,
133 : ErrorResult& aRv)
134 : {
135 0 : AssertIsOnOwningThread();
136 :
137 : return OpenCursorInternal(/* aKeysOnly */ true, aCx, aRange, aDirection,
138 0 : aRv);
139 : }
140 :
141 : already_AddRefed<IDBRequest>
142 0 : Get(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv)
143 : {
144 0 : AssertIsOnOwningThread();
145 :
146 0 : return GetInternal(/* aKeyOnly */ false, aCx, aKey, aRv);
147 : }
148 :
149 : already_AddRefed<IDBRequest>
150 0 : GetKey(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv)
151 : {
152 0 : AssertIsOnOwningThread();
153 :
154 0 : return GetInternal(/* aKeyOnly */ true, aCx, aKey, aRv);
155 : }
156 :
157 : already_AddRefed<IDBRequest>
158 : Count(JSContext* aCx, JS::Handle<JS::Value> aKey,
159 : ErrorResult& aRv);
160 :
161 : already_AddRefed<IDBRequest>
162 0 : GetAll(JSContext* aCx, JS::Handle<JS::Value> aKey,
163 : const Optional<uint32_t>& aLimit, ErrorResult& aRv)
164 : {
165 0 : AssertIsOnOwningThread();
166 :
167 0 : return GetAllInternal(/* aKeysOnly */ false, aCx, aKey, aLimit, aRv);
168 : }
169 :
170 : already_AddRefed<IDBRequest>
171 0 : GetAllKeys(JSContext* aCx, JS::Handle<JS::Value> aKey,
172 : const Optional<uint32_t>& aLimit, ErrorResult& aRv)
173 : {
174 0 : AssertIsOnOwningThread();
175 :
176 0 : return GetAllInternal(/* aKeysOnly */ true, aCx, aKey, aLimit, aRv);
177 : }
178 :
179 : void
180 : RefreshMetadata(bool aMayDelete);
181 :
182 : void
183 : NoteDeletion();
184 :
185 : bool
186 0 : IsDeleted() const
187 : {
188 0 : AssertIsOnOwningThread();
189 :
190 0 : return !!mDeletedMetadata;
191 : }
192 :
193 : void
194 : AssertIsOnOwningThread() const
195 : #ifdef DEBUG
196 : ;
197 : #else
198 : { }
199 : #endif
200 :
201 : // nsWrapperCache
202 : virtual JSObject*
203 : WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
204 :
205 : private:
206 : IDBIndex(IDBObjectStore* aObjectStore, const indexedDB::IndexMetadata* aMetadata);
207 :
208 : ~IDBIndex();
209 :
210 : already_AddRefed<IDBRequest>
211 : GetInternal(bool aKeyOnly,
212 : JSContext* aCx,
213 : JS::Handle<JS::Value> aKey,
214 : ErrorResult& aRv);
215 :
216 : already_AddRefed<IDBRequest>
217 : GetAllInternal(bool aKeysOnly,
218 : JSContext* aCx,
219 : JS::Handle<JS::Value> aKey,
220 : const Optional<uint32_t>& aLimit,
221 : ErrorResult& aRv);
222 :
223 : already_AddRefed<IDBRequest>
224 : OpenCursorInternal(bool aKeysOnly,
225 : JSContext* aCx,
226 : JS::Handle<JS::Value> aRange,
227 : IDBCursorDirection aDirection,
228 : ErrorResult& aRv);
229 : };
230 :
231 : } // namespace dom
232 : } // namespace mozilla
233 :
234 : #endif // mozilla_dom_idbindex_h__
|