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
;
26 class EventChainPostVisitor
;
27 class EventChainPreVisitor
;
29 class OwningIDBObjectStoreOrIDBIndexOrIDBCursor
;
30 struct ErrorEventInit
;
34 BEGIN_INDEXEDDB_NAMESPACE
42 class IndexedDBRequestParentBase
;
44 class IDBRequest
: public IDBWrapperCache
47 NS_DECL_ISUPPORTS_INHERITED
48 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IDBRequest
,
52 already_AddRefed
<IDBRequest
> Create(IDBDatabase
* aDatabase
,
53 IDBTransaction
* aTransaction
);
56 already_AddRefed
<IDBRequest
> Create(IDBObjectStore
* aSource
,
57 IDBDatabase
* aDatabase
,
58 IDBTransaction
* aTransaction
);
61 already_AddRefed
<IDBRequest
> Create(IDBIndex
* aSource
,
62 IDBDatabase
* aDatabase
,
63 IDBTransaction
* aTransaction
);
66 virtual nsresult
PreHandleEvent(EventChainPreVisitor
& aVisitor
) MOZ_OVERRIDE
;
68 void GetSource(Nullable
<OwningIDBObjectStoreOrIDBIndexOrIDBCursor
>& aSource
) const;
72 nsresult
NotifyHelperCompleted(HelperBase
* aHelper
);
73 void NotifyHelperSentResultsToChildProcess(nsresult aRv
);
75 void SetError(nsresult aRv
);
87 DOMError
* GetError(ErrorResult
& aRv
);
90 SetActor(IndexedDBRequestParentBase
* aActorParent
)
92 NS_ASSERTION(!aActorParent
|| !mActorParent
,
93 "Shouldn't have more than one!");
94 mActorParent
= aActorParent
;
97 IndexedDBRequestParentBase
*
98 GetActorParent() const
103 void CaptureCaller();
105 void FillScriptErrorEvent(ErrorEventInit
& aEventInit
) const;
110 return !mHaveResultOrErrorCode
;
113 #ifdef MOZ_ENABLE_PROFILER_SPS
115 GetSerialNumber() const
117 return mSerialNumber
;
123 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
127 GetParentObject() const
133 GetResult(JS::MutableHandle
<JS::Value
> aResult
, ErrorResult
& aRv
) const;
136 GetResult(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
,
137 ErrorResult
& aRv
) const
139 GetResult(aResult
, aRv
);
143 GetTransaction() const
145 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
152 IMPL_EVENT_HANDLER(success
);
153 IMPL_EVENT_HANDLER(error
);
156 explicit IDBRequest(IDBDatabase
* aDatabase
);
157 explicit IDBRequest(nsPIDOMWindow
* aOwner
);
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.
167 void AssertSourceIsCorrect() const;
169 void AssertSourceIsCorrect() const {}
172 nsRefPtr
<IDBTransaction
> mTransaction
;
174 JS::Heap
<JS::Value
> mResultVal
;
175 nsRefPtr
<mozilla::dom::DOMError
> mError
;
176 IndexedDBRequestParentBase
* mActorParent
;
178 #ifdef MOZ_ENABLE_PROFILER_SPS
179 uint64_t mSerialNumber
;
183 bool mHaveResultOrErrorCode
;
186 class IDBOpenDBRequest
: public IDBRequest
189 NS_DECL_ISUPPORTS_INHERITED
190 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBOpenDBRequest
, IDBRequest
)
193 already_AddRefed
<IDBOpenDBRequest
>
194 Create(IDBFactory
* aFactory
,
195 nsPIDOMWindow
* aOwner
,
196 JS::Handle
<JSObject
*> aScriptOwner
);
198 void SetTransaction(IDBTransaction
* aTransaction
);
201 virtual nsresult
PostHandleEvent(
202 EventChainPostVisitor
& aVisitor
) MOZ_OVERRIDE
;
204 DOMError
* GetError(ErrorResult
& aRv
)
206 return IDBRequest::GetError(aRv
);
217 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
220 IMPL_EVENT_HANDLER(blocked
);
221 IMPL_EVENT_HANDLER(upgradeneeded
);
224 explicit IDBOpenDBRequest(nsPIDOMWindow
* aOwner
);
227 // Only touched on the main thread.
228 nsRefPtr
<IDBFactory
> mFactory
;
231 END_INDEXEDDB_NAMESPACE
233 #endif // mozilla_dom_indexeddb_idbrequest_h__