dom/indexedDB/IDBRequest.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     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 class ErrorEventInit;
    31 }
    32 }
    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
    45 {
    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
    80   ;
    81 #else
    82   {
    83     return mErrorCode;
    84   }
    85 #endif
    87   DOMError* GetError(ErrorResult& aRv);
    89   JSContext* GetJSContext();
    91   void
    92   SetActor(IndexedDBRequestParentBase* aActorParent)
    93   {
    94     NS_ASSERTION(!aActorParent || !mActorParent,
    95                  "Shouldn't have more than one!");
    96     mActorParent = aActorParent;
    97   }
    99   IndexedDBRequestParentBase*
   100   GetActorParent() const
   101   {
   102     return mActorParent;
   103   }
   105   void CaptureCaller();
   107   void FillScriptErrorEvent(ErrorEventInit& aEventInit) const;
   109   bool
   110   IsPending() const
   111   {
   112     return !mHaveResultOrErrorCode;
   113   }
   115 #ifdef MOZ_ENABLE_PROFILER_SPS
   116   uint64_t
   117   GetSerialNumber() const
   118   {
   119     return mSerialNumber;
   120   }
   121 #endif
   123   // nsWrapperCache
   124   virtual JSObject*
   125   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
   127   // WebIDL
   128   nsPIDOMWindow*
   129   GetParentObject() const
   130   {
   131     return GetOwner();
   132   }
   134   void
   135   GetResult(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
   136             ErrorResult& aRv) const;
   138   IDBTransaction*
   139   GetTransaction() const
   140   {
   141     NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   142     return mTransaction;
   143   }
   145   IDBRequestReadyState
   146   ReadyState() const;
   148   IMPL_EVENT_HANDLER(success);
   149   IMPL_EVENT_HANDLER(error);
   151 protected:
   152   IDBRequest(IDBDatabase* aDatabase);
   153   IDBRequest(nsPIDOMWindow* aOwner);
   154   ~IDBRequest();
   156   // At most one of these three fields can be non-null.
   157   nsRefPtr<IDBObjectStore> mSourceAsObjectStore;
   158   nsRefPtr<IDBIndex> mSourceAsIndex;
   159   nsRefPtr<IDBCursor> mSourceAsCursor;
   161   // Check that the above condition holds.
   162 #ifdef DEBUG
   163   void AssertSourceIsCorrect() const;
   164 #else
   165   void AssertSourceIsCorrect() const {}
   166 #endif
   168   nsRefPtr<IDBTransaction> mTransaction;
   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 };
   182 class IDBOpenDBRequest : public IDBRequest
   183 {
   184 public:
   185   NS_DECL_ISUPPORTS_INHERITED
   186   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBOpenDBRequest, IDBRequest)
   188   static
   189   already_AddRefed<IDBOpenDBRequest>
   190   Create(IDBFactory* aFactory,
   191          nsPIDOMWindow* aOwner,
   192          JS::Handle<JSObject*> aScriptOwner);
   194   void SetTransaction(IDBTransaction* aTransaction);
   196   // nsIDOMEventTarget
   197   virtual nsresult PostHandleEvent(
   198                      EventChainPostVisitor& aVisitor) MOZ_OVERRIDE;
   200   DOMError* GetError(ErrorResult& aRv)
   201   {
   202     return IDBRequest::GetError(aRv);
   203   }
   205   IDBFactory*
   206   Factory() const
   207   {
   208     return mFactory;
   209   }
   211   // nsWrapperCache
   212   virtual JSObject*
   213   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
   215   // WebIDL
   216   IMPL_EVENT_HANDLER(blocked);
   217   IMPL_EVENT_HANDLER(upgradeneeded);
   219 protected:
   220   IDBOpenDBRequest(nsPIDOMWindow* aOwner);
   221   ~IDBOpenDBRequest();
   223   // Only touched on the main thread.
   224   nsRefPtr<IDBFactory> mFactory;
   225 };
   227 END_INDEXEDDB_NAMESPACE
   229 #endif // mozilla_dom_indexeddb_idbrequest_h__

mercurial