dom/indexedDB/IDBCursor.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_idbcursor_h__
     8 #define mozilla_dom_indexeddb_idbcursor_h__
    10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
    12 #include "mozilla/Attributes.h"
    13 #include "mozilla/dom/IDBCursorBinding.h"
    14 #include "mozilla/ErrorResult.h"
    15 #include "nsCycleCollectionParticipant.h"
    16 #include "nsWrapperCache.h"
    18 #include "mozilla/dom/indexedDB/IDBObjectStore.h"
    19 #include "mozilla/dom/indexedDB/Key.h"
    21 class nsIRunnable;
    22 class nsIScriptContext;
    23 class nsPIDOMWindow;
    25 namespace mozilla {
    26 namespace dom {
    27 class OwningIDBObjectStoreOrIDBIndex;
    28 }
    29 }
    31 BEGIN_INDEXEDDB_NAMESPACE
    33 class ContinueHelper;
    34 class ContinueObjectStoreHelper;
    35 class ContinueIndexHelper;
    36 class ContinueIndexObjectHelper;
    37 class IDBIndex;
    38 class IDBRequest;
    39 class IDBTransaction;
    40 class IndexedDBCursorChild;
    41 class IndexedDBCursorParent;
    43 class IDBCursor MOZ_FINAL : public nsISupports,
    44                             public nsWrapperCache
    45 {
    46   friend class ContinueHelper;
    47   friend class ContinueObjectStoreHelper;
    48   friend class ContinueIndexHelper;
    49   friend class ContinueIndexObjectHelper;
    51 public:
    52   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    53   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor)
    55   enum Type
    56   {
    57     OBJECTSTORE = 0,
    58     OBJECTSTOREKEY,
    59     INDEXKEY,
    60     INDEXOBJECT
    61   };
    63   enum Direction
    64   {
    65     NEXT = 0,
    66     NEXT_UNIQUE,
    67     PREV,
    68     PREV_UNIQUE,
    70     // Only needed for IPC serialization helper, should never be used in code.
    71     DIRECTION_INVALID
    72   };
    74   // For OBJECTSTORE cursors.
    75   static
    76   already_AddRefed<IDBCursor>
    77   Create(IDBRequest* aRequest,
    78          IDBTransaction* aTransaction,
    79          IDBObjectStore* aObjectStore,
    80          Direction aDirection,
    81          const Key& aRangeKey,
    82          const nsACString& aContinueQuery,
    83          const nsACString& aContinueToQuery,
    84          const Key& aKey,
    85          StructuredCloneReadInfo&& aCloneReadInfo);
    87   // For OBJECTSTOREKEY cursors.
    88   static
    89   already_AddRefed<IDBCursor>
    90   Create(IDBRequest* aRequest,
    91          IDBTransaction* aTransaction,
    92          IDBObjectStore* aObjectStore,
    93          Direction aDirection,
    94          const Key& aRangeKey,
    95          const nsACString& aContinueQuery,
    96          const nsACString& aContinueToQuery,
    97          const Key& aKey);
    99   // For INDEXKEY cursors.
   100   static
   101   already_AddRefed<IDBCursor>
   102   Create(IDBRequest* aRequest,
   103          IDBTransaction* aTransaction,
   104          IDBIndex* aIndex,
   105          Direction aDirection,
   106          const Key& aRangeKey,
   107          const nsACString& aContinueQuery,
   108          const nsACString& aContinueToQuery,
   109          const Key& aKey,
   110          const Key& aObjectKey);
   112   // For INDEXOBJECT cursors.
   113   static
   114   already_AddRefed<IDBCursor>
   115   Create(IDBRequest* aRequest,
   116          IDBTransaction* aTransaction,
   117          IDBIndex* aIndex,
   118          Direction aDirection,
   119          const Key& aRangeKey,
   120          const nsACString& aContinueQuery,
   121          const nsACString& aContinueToQuery,
   122          const Key& aKey,
   123          const Key& aObjectKey,
   124          StructuredCloneReadInfo&& aCloneReadInfo);
   126   IDBTransaction* Transaction() const
   127   {
   128     return mTransaction;
   129   }
   131   IDBRequest* Request() const
   132   {
   133     return mRequest;
   134   }
   136   static Direction
   137   ConvertDirection(IDBCursorDirection aDirection);
   139   void
   140   SetActor(IndexedDBCursorChild* aActorChild)
   141   {
   142     NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
   143     mActorChild = aActorChild;
   144   }
   146   void
   147   SetActor(IndexedDBCursorParent* aActorParent)
   148   {
   149     NS_ASSERTION(!aActorParent || !mActorParent,
   150                  "Shouldn't have more than one!");
   151     mActorParent = aActorParent;
   152   }
   154   IndexedDBCursorChild*
   155   GetActorChild() const
   156   {
   157     return mActorChild;
   158   }
   160   IndexedDBCursorParent*
   161   GetActorParent() const
   162   {
   163     return mActorParent;
   164   }
   166   void
   167   ContinueInternal(const Key& aKey, int32_t aCount,
   168                    ErrorResult& aRv);
   170   // nsWrapperCache
   171   virtual JSObject*
   172   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
   174   // WebIDL
   175   IDBTransaction*
   176   GetParentObject() const
   177   {
   178     return mTransaction;
   179   }
   181   void
   182   GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const;
   184   IDBCursorDirection
   185   GetDirection() const;
   187   void
   188   GetKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
   189          ErrorResult& aRv);
   191   void
   192   GetPrimaryKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
   193                 ErrorResult& aRv);
   195   already_AddRefed<IDBRequest>
   196   Update(JSContext* aCx, JS::Handle<JS::Value> aValue, ErrorResult& aRv);
   198   void
   199   Advance(uint32_t aCount, ErrorResult& aRv);
   201   void
   202   Continue(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv);
   204   already_AddRefed<IDBRequest>
   205   Delete(JSContext* aCx, ErrorResult& aRv);
   207   void
   208   GetValue(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
   209            ErrorResult& aRv);
   211 protected:
   212   IDBCursor();
   213   ~IDBCursor();
   215   void DropJSObjects();
   217   static
   218   already_AddRefed<IDBCursor>
   219   CreateCommon(IDBRequest* aRequest,
   220                IDBTransaction* aTransaction,
   221                IDBObjectStore* aObjectStore,
   222                Direction aDirection,
   223                const Key& aRangeKey,
   224                const nsACString& aContinueQuery,
   225                const nsACString& aContinueToQuery);
   227   nsRefPtr<IDBRequest> mRequest;
   228   nsRefPtr<IDBTransaction> mTransaction;
   229   nsRefPtr<IDBObjectStore> mObjectStore;
   230   nsRefPtr<IDBIndex> mIndex;
   232   JS::Heap<JSObject*> mScriptOwner;
   234   Type mType;
   235   Direction mDirection;
   236   nsCString mContinueQuery;
   237   nsCString mContinueToQuery;
   239   // These are cycle-collected!
   240   JS::Heap<JS::Value> mCachedKey;
   241   JS::Heap<JS::Value> mCachedPrimaryKey;
   242   JS::Heap<JS::Value> mCachedValue;
   244   Key mRangeKey;
   246   Key mKey;
   247   Key mObjectKey;
   248   StructuredCloneReadInfo mCloneReadInfo;
   249   Key mContinueToKey;
   251   IndexedDBCursorChild* mActorChild;
   252   IndexedDBCursorParent* mActorParent;
   254   bool mHaveCachedKey;
   255   bool mHaveCachedPrimaryKey;
   256   bool mHaveCachedValue;
   257   bool mRooted;
   258   bool mContinueCalled;
   259   bool mHaveValue;
   260 };
   262 END_INDEXEDDB_NAMESPACE
   264 #endif // mozilla_dom_indexeddb_idbcursor_h__

mercurial