1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/IDBRequest.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,229 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_indexeddb_idbrequest_h__ 1.11 +#define mozilla_dom_indexeddb_idbrequest_h__ 1.12 + 1.13 +#include "mozilla/dom/indexedDB/IndexedDatabase.h" 1.14 + 1.15 +#include "mozilla/Attributes.h" 1.16 +#include "mozilla/EventForwards.h" 1.17 +#include "mozilla/dom/DOMError.h" 1.18 +#include "mozilla/dom/IDBRequestBinding.h" 1.19 +#include "mozilla/ErrorResult.h" 1.20 +#include "nsCycleCollectionParticipant.h" 1.21 +#include "nsWrapperCache.h" 1.22 + 1.23 +#include "mozilla/dom/indexedDB/IDBWrapperCache.h" 1.24 + 1.25 +class nsIScriptContext; 1.26 +class nsPIDOMWindow; 1.27 + 1.28 +namespace mozilla { 1.29 +class EventChainPostVisitor; 1.30 +class EventChainPreVisitor; 1.31 +namespace dom { 1.32 +class OwningIDBObjectStoreOrIDBIndexOrIDBCursor; 1.33 +class ErrorEventInit; 1.34 +} 1.35 +} 1.36 + 1.37 +BEGIN_INDEXEDDB_NAMESPACE 1.38 + 1.39 +class HelperBase; 1.40 +class IDBCursor; 1.41 +class IDBFactory; 1.42 +class IDBIndex; 1.43 +class IDBObjectStore; 1.44 +class IDBTransaction; 1.45 +class IndexedDBRequestParentBase; 1.46 + 1.47 +class IDBRequest : public IDBWrapperCache 1.48 +{ 1.49 +public: 1.50 + NS_DECL_ISUPPORTS_INHERITED 1.51 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IDBRequest, 1.52 + IDBWrapperCache) 1.53 + 1.54 + static 1.55 + already_AddRefed<IDBRequest> Create(IDBDatabase* aDatabase, 1.56 + IDBTransaction* aTransaction); 1.57 + 1.58 + static 1.59 + already_AddRefed<IDBRequest> Create(IDBObjectStore* aSource, 1.60 + IDBDatabase* aDatabase, 1.61 + IDBTransaction* aTransaction); 1.62 + 1.63 + static 1.64 + already_AddRefed<IDBRequest> Create(IDBIndex* aSource, 1.65 + IDBDatabase* aDatabase, 1.66 + IDBTransaction* aTransaction); 1.67 + 1.68 + // nsIDOMEventTarget 1.69 + virtual nsresult PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; 1.70 + 1.71 + void GetSource(Nullable<OwningIDBObjectStoreOrIDBIndexOrIDBCursor>& aSource) const; 1.72 + 1.73 + void Reset(); 1.74 + 1.75 + nsresult NotifyHelperCompleted(HelperBase* aHelper); 1.76 + void NotifyHelperSentResultsToChildProcess(nsresult aRv); 1.77 + 1.78 + void SetError(nsresult aRv); 1.79 + 1.80 + nsresult 1.81 + GetErrorCode() const 1.82 +#ifdef DEBUG 1.83 + ; 1.84 +#else 1.85 + { 1.86 + return mErrorCode; 1.87 + } 1.88 +#endif 1.89 + 1.90 + DOMError* GetError(ErrorResult& aRv); 1.91 + 1.92 + JSContext* GetJSContext(); 1.93 + 1.94 + void 1.95 + SetActor(IndexedDBRequestParentBase* aActorParent) 1.96 + { 1.97 + NS_ASSERTION(!aActorParent || !mActorParent, 1.98 + "Shouldn't have more than one!"); 1.99 + mActorParent = aActorParent; 1.100 + } 1.101 + 1.102 + IndexedDBRequestParentBase* 1.103 + GetActorParent() const 1.104 + { 1.105 + return mActorParent; 1.106 + } 1.107 + 1.108 + void CaptureCaller(); 1.109 + 1.110 + void FillScriptErrorEvent(ErrorEventInit& aEventInit) const; 1.111 + 1.112 + bool 1.113 + IsPending() const 1.114 + { 1.115 + return !mHaveResultOrErrorCode; 1.116 + } 1.117 + 1.118 +#ifdef MOZ_ENABLE_PROFILER_SPS 1.119 + uint64_t 1.120 + GetSerialNumber() const 1.121 + { 1.122 + return mSerialNumber; 1.123 + } 1.124 +#endif 1.125 + 1.126 + // nsWrapperCache 1.127 + virtual JSObject* 1.128 + WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.129 + 1.130 + // WebIDL 1.131 + nsPIDOMWindow* 1.132 + GetParentObject() const 1.133 + { 1.134 + return GetOwner(); 1.135 + } 1.136 + 1.137 + void 1.138 + GetResult(JSContext* aCx, JS::MutableHandle<JS::Value> aResult, 1.139 + ErrorResult& aRv) const; 1.140 + 1.141 + IDBTransaction* 1.142 + GetTransaction() const 1.143 + { 1.144 + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); 1.145 + return mTransaction; 1.146 + } 1.147 + 1.148 + IDBRequestReadyState 1.149 + ReadyState() const; 1.150 + 1.151 + IMPL_EVENT_HANDLER(success); 1.152 + IMPL_EVENT_HANDLER(error); 1.153 + 1.154 +protected: 1.155 + IDBRequest(IDBDatabase* aDatabase); 1.156 + IDBRequest(nsPIDOMWindow* aOwner); 1.157 + ~IDBRequest(); 1.158 + 1.159 + // At most one of these three fields can be non-null. 1.160 + nsRefPtr<IDBObjectStore> mSourceAsObjectStore; 1.161 + nsRefPtr<IDBIndex> mSourceAsIndex; 1.162 + nsRefPtr<IDBCursor> mSourceAsCursor; 1.163 + 1.164 + // Check that the above condition holds. 1.165 +#ifdef DEBUG 1.166 + void AssertSourceIsCorrect() const; 1.167 +#else 1.168 + void AssertSourceIsCorrect() const {} 1.169 +#endif 1.170 + 1.171 + nsRefPtr<IDBTransaction> mTransaction; 1.172 + 1.173 + JS::Heap<JS::Value> mResultVal; 1.174 + nsRefPtr<mozilla::dom::DOMError> mError; 1.175 + IndexedDBRequestParentBase* mActorParent; 1.176 + nsString mFilename; 1.177 +#ifdef MOZ_ENABLE_PROFILER_SPS 1.178 + uint64_t mSerialNumber; 1.179 +#endif 1.180 + nsresult mErrorCode; 1.181 + uint32_t mLineNo; 1.182 + bool mHaveResultOrErrorCode; 1.183 +}; 1.184 + 1.185 +class IDBOpenDBRequest : public IDBRequest 1.186 +{ 1.187 +public: 1.188 + NS_DECL_ISUPPORTS_INHERITED 1.189 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBOpenDBRequest, IDBRequest) 1.190 + 1.191 + static 1.192 + already_AddRefed<IDBOpenDBRequest> 1.193 + Create(IDBFactory* aFactory, 1.194 + nsPIDOMWindow* aOwner, 1.195 + JS::Handle<JSObject*> aScriptOwner); 1.196 + 1.197 + void SetTransaction(IDBTransaction* aTransaction); 1.198 + 1.199 + // nsIDOMEventTarget 1.200 + virtual nsresult PostHandleEvent( 1.201 + EventChainPostVisitor& aVisitor) MOZ_OVERRIDE; 1.202 + 1.203 + DOMError* GetError(ErrorResult& aRv) 1.204 + { 1.205 + return IDBRequest::GetError(aRv); 1.206 + } 1.207 + 1.208 + IDBFactory* 1.209 + Factory() const 1.210 + { 1.211 + return mFactory; 1.212 + } 1.213 + 1.214 + // nsWrapperCache 1.215 + virtual JSObject* 1.216 + WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.217 + 1.218 + // WebIDL 1.219 + IMPL_EVENT_HANDLER(blocked); 1.220 + IMPL_EVENT_HANDLER(upgradeneeded); 1.221 + 1.222 +protected: 1.223 + IDBOpenDBRequest(nsPIDOMWindow* aOwner); 1.224 + ~IDBOpenDBRequest(); 1.225 + 1.226 + // Only touched on the main thread. 1.227 + nsRefPtr<IDBFactory> mFactory; 1.228 +}; 1.229 + 1.230 +END_INDEXEDDB_NAMESPACE 1.231 + 1.232 +#endif // mozilla_dom_indexeddb_idbrequest_h__