michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_indexeddb_idbrequest_h__ michael@0: #define mozilla_dom_indexeddb_idbrequest_h__ michael@0: michael@0: #include "mozilla/dom/indexedDB/IndexedDatabase.h" michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/EventForwards.h" michael@0: #include "mozilla/dom/DOMError.h" michael@0: #include "mozilla/dom/IDBRequestBinding.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsWrapperCache.h" michael@0: michael@0: #include "mozilla/dom/indexedDB/IDBWrapperCache.h" michael@0: michael@0: class nsIScriptContext; michael@0: class nsPIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: class EventChainPostVisitor; michael@0: class EventChainPreVisitor; michael@0: namespace dom { michael@0: class OwningIDBObjectStoreOrIDBIndexOrIDBCursor; michael@0: class ErrorEventInit; michael@0: } michael@0: } michael@0: michael@0: BEGIN_INDEXEDDB_NAMESPACE michael@0: michael@0: class HelperBase; michael@0: class IDBCursor; michael@0: class IDBFactory; michael@0: class IDBIndex; michael@0: class IDBObjectStore; michael@0: class IDBTransaction; michael@0: class IndexedDBRequestParentBase; michael@0: michael@0: class IDBRequest : public IDBWrapperCache michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IDBRequest, michael@0: IDBWrapperCache) michael@0: michael@0: static michael@0: already_AddRefed Create(IDBDatabase* aDatabase, michael@0: IDBTransaction* aTransaction); michael@0: michael@0: static michael@0: already_AddRefed Create(IDBObjectStore* aSource, michael@0: IDBDatabase* aDatabase, michael@0: IDBTransaction* aTransaction); michael@0: michael@0: static michael@0: already_AddRefed Create(IDBIndex* aSource, michael@0: IDBDatabase* aDatabase, michael@0: IDBTransaction* aTransaction); michael@0: michael@0: // nsIDOMEventTarget michael@0: virtual nsresult PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; michael@0: michael@0: void GetSource(Nullable& aSource) const; michael@0: michael@0: void Reset(); michael@0: michael@0: nsresult NotifyHelperCompleted(HelperBase* aHelper); michael@0: void NotifyHelperSentResultsToChildProcess(nsresult aRv); michael@0: michael@0: void SetError(nsresult aRv); michael@0: michael@0: nsresult michael@0: GetErrorCode() const michael@0: #ifdef DEBUG michael@0: ; michael@0: #else michael@0: { michael@0: return mErrorCode; michael@0: } michael@0: #endif michael@0: michael@0: DOMError* GetError(ErrorResult& aRv); michael@0: michael@0: JSContext* GetJSContext(); michael@0: michael@0: void michael@0: SetActor(IndexedDBRequestParentBase* aActorParent) michael@0: { michael@0: NS_ASSERTION(!aActorParent || !mActorParent, michael@0: "Shouldn't have more than one!"); michael@0: mActorParent = aActorParent; michael@0: } michael@0: michael@0: IndexedDBRequestParentBase* michael@0: GetActorParent() const michael@0: { michael@0: return mActorParent; michael@0: } michael@0: michael@0: void CaptureCaller(); michael@0: michael@0: void FillScriptErrorEvent(ErrorEventInit& aEventInit) const; michael@0: michael@0: bool michael@0: IsPending() const michael@0: { michael@0: return !mHaveResultOrErrorCode; michael@0: } michael@0: michael@0: #ifdef MOZ_ENABLE_PROFILER_SPS michael@0: uint64_t michael@0: GetSerialNumber() const michael@0: { michael@0: return mSerialNumber; michael@0: } michael@0: #endif michael@0: michael@0: // nsWrapperCache michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // WebIDL michael@0: nsPIDOMWindow* michael@0: GetParentObject() const michael@0: { michael@0: return GetOwner(); michael@0: } michael@0: michael@0: void michael@0: GetResult(JSContext* aCx, JS::MutableHandle aResult, michael@0: ErrorResult& aRv) const; michael@0: michael@0: IDBTransaction* michael@0: GetTransaction() const michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); michael@0: return mTransaction; michael@0: } michael@0: michael@0: IDBRequestReadyState michael@0: ReadyState() const; michael@0: michael@0: IMPL_EVENT_HANDLER(success); michael@0: IMPL_EVENT_HANDLER(error); michael@0: michael@0: protected: michael@0: IDBRequest(IDBDatabase* aDatabase); michael@0: IDBRequest(nsPIDOMWindow* aOwner); michael@0: ~IDBRequest(); michael@0: michael@0: // At most one of these three fields can be non-null. michael@0: nsRefPtr mSourceAsObjectStore; michael@0: nsRefPtr mSourceAsIndex; michael@0: nsRefPtr mSourceAsCursor; michael@0: michael@0: // Check that the above condition holds. michael@0: #ifdef DEBUG michael@0: void AssertSourceIsCorrect() const; michael@0: #else michael@0: void AssertSourceIsCorrect() const {} michael@0: #endif michael@0: michael@0: nsRefPtr mTransaction; michael@0: michael@0: JS::Heap mResultVal; michael@0: nsRefPtr mError; michael@0: IndexedDBRequestParentBase* mActorParent; michael@0: nsString mFilename; michael@0: #ifdef MOZ_ENABLE_PROFILER_SPS michael@0: uint64_t mSerialNumber; michael@0: #endif michael@0: nsresult mErrorCode; michael@0: uint32_t mLineNo; michael@0: bool mHaveResultOrErrorCode; michael@0: }; michael@0: michael@0: class IDBOpenDBRequest : public IDBRequest michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBOpenDBRequest, IDBRequest) michael@0: michael@0: static michael@0: already_AddRefed michael@0: Create(IDBFactory* aFactory, michael@0: nsPIDOMWindow* aOwner, michael@0: JS::Handle aScriptOwner); michael@0: michael@0: void SetTransaction(IDBTransaction* aTransaction); michael@0: michael@0: // nsIDOMEventTarget michael@0: virtual nsresult PostHandleEvent( michael@0: EventChainPostVisitor& aVisitor) MOZ_OVERRIDE; michael@0: michael@0: DOMError* GetError(ErrorResult& aRv) michael@0: { michael@0: return IDBRequest::GetError(aRv); michael@0: } michael@0: michael@0: IDBFactory* michael@0: Factory() const michael@0: { michael@0: return mFactory; michael@0: } michael@0: michael@0: // nsWrapperCache michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // WebIDL michael@0: IMPL_EVENT_HANDLER(blocked); michael@0: IMPL_EVENT_HANDLER(upgradeneeded); michael@0: michael@0: protected: michael@0: IDBOpenDBRequest(nsPIDOMWindow* aOwner); michael@0: ~IDBOpenDBRequest(); michael@0: michael@0: // Only touched on the main thread. michael@0: nsRefPtr mFactory; michael@0: }; michael@0: michael@0: END_INDEXEDDB_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_indexeddb_idbrequest_h__