dom/indexedDB/IDBRequest.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:af7901c196d9
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_idbrequest_h__
8 #define mozilla_dom_indexeddb_idbrequest_h__
9
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
11
12 #include "mozilla/Attributes.h"
13 #include "mozilla/EventForwards.h"
14 #include "mozilla/dom/DOMError.h"
15 #include "mozilla/dom/IDBRequestBinding.h"
16 #include "mozilla/ErrorResult.h"
17 #include "nsCycleCollectionParticipant.h"
18 #include "nsWrapperCache.h"
19
20 #include "mozilla/dom/indexedDB/IDBWrapperCache.h"
21
22 class nsIScriptContext;
23 class nsPIDOMWindow;
24
25 namespace mozilla {
26 class EventChainPostVisitor;
27 class EventChainPreVisitor;
28 namespace dom {
29 class OwningIDBObjectStoreOrIDBIndexOrIDBCursor;
30 class ErrorEventInit;
31 }
32 }
33
34 BEGIN_INDEXEDDB_NAMESPACE
35
36 class HelperBase;
37 class IDBCursor;
38 class IDBFactory;
39 class IDBIndex;
40 class IDBObjectStore;
41 class IDBTransaction;
42 class IndexedDBRequestParentBase;
43
44 class IDBRequest : public IDBWrapperCache
45 {
46 public:
47 NS_DECL_ISUPPORTS_INHERITED
48 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IDBRequest,
49 IDBWrapperCache)
50
51 static
52 already_AddRefed<IDBRequest> Create(IDBDatabase* aDatabase,
53 IDBTransaction* aTransaction);
54
55 static
56 already_AddRefed<IDBRequest> Create(IDBObjectStore* aSource,
57 IDBDatabase* aDatabase,
58 IDBTransaction* aTransaction);
59
60 static
61 already_AddRefed<IDBRequest> Create(IDBIndex* aSource,
62 IDBDatabase* aDatabase,
63 IDBTransaction* aTransaction);
64
65 // nsIDOMEventTarget
66 virtual nsresult PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
67
68 void GetSource(Nullable<OwningIDBObjectStoreOrIDBIndexOrIDBCursor>& aSource) const;
69
70 void Reset();
71
72 nsresult NotifyHelperCompleted(HelperBase* aHelper);
73 void NotifyHelperSentResultsToChildProcess(nsresult aRv);
74
75 void SetError(nsresult aRv);
76
77 nsresult
78 GetErrorCode() const
79 #ifdef DEBUG
80 ;
81 #else
82 {
83 return mErrorCode;
84 }
85 #endif
86
87 DOMError* GetError(ErrorResult& aRv);
88
89 JSContext* GetJSContext();
90
91 void
92 SetActor(IndexedDBRequestParentBase* aActorParent)
93 {
94 NS_ASSERTION(!aActorParent || !mActorParent,
95 "Shouldn't have more than one!");
96 mActorParent = aActorParent;
97 }
98
99 IndexedDBRequestParentBase*
100 GetActorParent() const
101 {
102 return mActorParent;
103 }
104
105 void CaptureCaller();
106
107 void FillScriptErrorEvent(ErrorEventInit& aEventInit) const;
108
109 bool
110 IsPending() const
111 {
112 return !mHaveResultOrErrorCode;
113 }
114
115 #ifdef MOZ_ENABLE_PROFILER_SPS
116 uint64_t
117 GetSerialNumber() const
118 {
119 return mSerialNumber;
120 }
121 #endif
122
123 // nsWrapperCache
124 virtual JSObject*
125 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
126
127 // WebIDL
128 nsPIDOMWindow*
129 GetParentObject() const
130 {
131 return GetOwner();
132 }
133
134 void
135 GetResult(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
136 ErrorResult& aRv) const;
137
138 IDBTransaction*
139 GetTransaction() const
140 {
141 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
142 return mTransaction;
143 }
144
145 IDBRequestReadyState
146 ReadyState() const;
147
148 IMPL_EVENT_HANDLER(success);
149 IMPL_EVENT_HANDLER(error);
150
151 protected:
152 IDBRequest(IDBDatabase* aDatabase);
153 IDBRequest(nsPIDOMWindow* aOwner);
154 ~IDBRequest();
155
156 // At most one of these three fields can be non-null.
157 nsRefPtr<IDBObjectStore> mSourceAsObjectStore;
158 nsRefPtr<IDBIndex> mSourceAsIndex;
159 nsRefPtr<IDBCursor> mSourceAsCursor;
160
161 // Check that the above condition holds.
162 #ifdef DEBUG
163 void AssertSourceIsCorrect() const;
164 #else
165 void AssertSourceIsCorrect() const {}
166 #endif
167
168 nsRefPtr<IDBTransaction> mTransaction;
169
170 JS::Heap<JS::Value> mResultVal;
171 nsRefPtr<mozilla::dom::DOMError> mError;
172 IndexedDBRequestParentBase* mActorParent;
173 nsString mFilename;
174 #ifdef MOZ_ENABLE_PROFILER_SPS
175 uint64_t mSerialNumber;
176 #endif
177 nsresult mErrorCode;
178 uint32_t mLineNo;
179 bool mHaveResultOrErrorCode;
180 };
181
182 class IDBOpenDBRequest : public IDBRequest
183 {
184 public:
185 NS_DECL_ISUPPORTS_INHERITED
186 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBOpenDBRequest, IDBRequest)
187
188 static
189 already_AddRefed<IDBOpenDBRequest>
190 Create(IDBFactory* aFactory,
191 nsPIDOMWindow* aOwner,
192 JS::Handle<JSObject*> aScriptOwner);
193
194 void SetTransaction(IDBTransaction* aTransaction);
195
196 // nsIDOMEventTarget
197 virtual nsresult PostHandleEvent(
198 EventChainPostVisitor& aVisitor) MOZ_OVERRIDE;
199
200 DOMError* GetError(ErrorResult& aRv)
201 {
202 return IDBRequest::GetError(aRv);
203 }
204
205 IDBFactory*
206 Factory() const
207 {
208 return mFactory;
209 }
210
211 // nsWrapperCache
212 virtual JSObject*
213 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
214
215 // WebIDL
216 IMPL_EVENT_HANDLER(blocked);
217 IMPL_EVENT_HANDLER(upgradeneeded);
218
219 protected:
220 IDBOpenDBRequest(nsPIDOMWindow* aOwner);
221 ~IDBOpenDBRequest();
222
223 // Only touched on the main thread.
224 nsRefPtr<IDBFactory> mFactory;
225 };
226
227 END_INDEXEDDB_NAMESPACE
228
229 #endif // mozilla_dom_indexeddb_idbrequest_h__

mercurial