Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / indexedDB / IDBRequest.h
blobd628b5a7998f5f5bd214408f7d6a9c9786d1253f
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_idbrequest_h__
8 #define mozilla_dom_indexeddb_idbrequest_h__
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
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"
20 #include "mozilla/dom/indexedDB/IDBWrapperCache.h"
22 class nsIScriptContext;
23 class nsPIDOMWindow;
25 namespace mozilla {
26 class EventChainPostVisitor;
27 class EventChainPreVisitor;
28 namespace dom {
29 class OwningIDBObjectStoreOrIDBIndexOrIDBCursor;
30 struct ErrorEventInit;
34 BEGIN_INDEXEDDB_NAMESPACE
36 class HelperBase;
37 class IDBCursor;
38 class IDBFactory;
39 class IDBIndex;
40 class IDBObjectStore;
41 class IDBTransaction;
42 class IndexedDBRequestParentBase;
44 class IDBRequest : public IDBWrapperCache
46 public:
47 NS_DECL_ISUPPORTS_INHERITED
48 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IDBRequest,
49 IDBWrapperCache)
51 static
52 already_AddRefed<IDBRequest> Create(IDBDatabase* aDatabase,
53 IDBTransaction* aTransaction);
55 static
56 already_AddRefed<IDBRequest> Create(IDBObjectStore* aSource,
57 IDBDatabase* aDatabase,
58 IDBTransaction* aTransaction);
60 static
61 already_AddRefed<IDBRequest> Create(IDBIndex* aSource,
62 IDBDatabase* aDatabase,
63 IDBTransaction* aTransaction);
65 // nsIDOMEventTarget
66 virtual nsresult PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
68 void GetSource(Nullable<OwningIDBObjectStoreOrIDBIndexOrIDBCursor>& aSource) const;
70 void Reset();
72 nsresult NotifyHelperCompleted(HelperBase* aHelper);
73 void NotifyHelperSentResultsToChildProcess(nsresult aRv);
75 void SetError(nsresult aRv);
77 nsresult
78 GetErrorCode() const
79 #ifdef DEBUG
81 #else
83 return mErrorCode;
85 #endif
87 DOMError* GetError(ErrorResult& aRv);
89 void
90 SetActor(IndexedDBRequestParentBase* aActorParent)
92 NS_ASSERTION(!aActorParent || !mActorParent,
93 "Shouldn't have more than one!");
94 mActorParent = aActorParent;
97 IndexedDBRequestParentBase*
98 GetActorParent() const
100 return mActorParent;
103 void CaptureCaller();
105 void FillScriptErrorEvent(ErrorEventInit& aEventInit) const;
107 bool
108 IsPending() const
110 return !mHaveResultOrErrorCode;
113 #ifdef MOZ_ENABLE_PROFILER_SPS
114 uint64_t
115 GetSerialNumber() const
117 return mSerialNumber;
119 #endif
121 // nsWrapperCache
122 virtual JSObject*
123 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
125 // WebIDL
126 nsPIDOMWindow*
127 GetParentObject() const
129 return GetOwner();
132 void
133 GetResult(JS::MutableHandle<JS::Value> aResult, ErrorResult& aRv) const;
135 void
136 GetResult(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
137 ErrorResult& aRv) const
139 GetResult(aResult, aRv);
142 IDBTransaction*
143 GetTransaction() const
145 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
146 return mTransaction;
149 IDBRequestReadyState
150 ReadyState() const;
152 IMPL_EVENT_HANDLER(success);
153 IMPL_EVENT_HANDLER(error);
155 protected:
156 explicit IDBRequest(IDBDatabase* aDatabase);
157 explicit IDBRequest(nsPIDOMWindow* aOwner);
158 ~IDBRequest();
160 // At most one of these three fields can be non-null.
161 nsRefPtr<IDBObjectStore> mSourceAsObjectStore;
162 nsRefPtr<IDBIndex> mSourceAsIndex;
163 nsRefPtr<IDBCursor> mSourceAsCursor;
165 // Check that the above condition holds.
166 #ifdef DEBUG
167 void AssertSourceIsCorrect() const;
168 #else
169 void AssertSourceIsCorrect() const {}
170 #endif
172 nsRefPtr<IDBTransaction> mTransaction;
174 JS::Heap<JS::Value> mResultVal;
175 nsRefPtr<mozilla::dom::DOMError> mError;
176 IndexedDBRequestParentBase* mActorParent;
177 nsString mFilename;
178 #ifdef MOZ_ENABLE_PROFILER_SPS
179 uint64_t mSerialNumber;
180 #endif
181 nsresult mErrorCode;
182 uint32_t mLineNo;
183 bool mHaveResultOrErrorCode;
186 class IDBOpenDBRequest : public IDBRequest
188 public:
189 NS_DECL_ISUPPORTS_INHERITED
190 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBOpenDBRequest, IDBRequest)
192 static
193 already_AddRefed<IDBOpenDBRequest>
194 Create(IDBFactory* aFactory,
195 nsPIDOMWindow* aOwner,
196 JS::Handle<JSObject*> aScriptOwner);
198 void SetTransaction(IDBTransaction* aTransaction);
200 // nsIDOMEventTarget
201 virtual nsresult PostHandleEvent(
202 EventChainPostVisitor& aVisitor) MOZ_OVERRIDE;
204 DOMError* GetError(ErrorResult& aRv)
206 return IDBRequest::GetError(aRv);
209 IDBFactory*
210 Factory() const
212 return mFactory;
215 // nsWrapperCache
216 virtual JSObject*
217 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
219 // WebIDL
220 IMPL_EVENT_HANDLER(blocked);
221 IMPL_EVENT_HANDLER(upgradeneeded);
223 protected:
224 explicit IDBOpenDBRequest(nsPIDOMWindow* aOwner);
225 ~IDBOpenDBRequest();
227 // Only touched on the main thread.
228 nsRefPtr<IDBFactory> mFactory;
231 END_INDEXEDDB_NAMESPACE
233 #endif // mozilla_dom_indexeddb_idbrequest_h__