2010-06-23 12:46:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
#ifndef mozilla_dom_indexeddb_idbcursor_h__
|
|
|
|
#define mozilla_dom_indexeddb_idbcursor_h__
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-07-31 08:48:36 -07:00
|
|
|
#include "mozilla/dom/IDBCursorBinding.h"
|
2013-07-31 15:28:13 -07:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2010-11-10 15:26:03 -08:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-07-31 15:28:13 -07:00
|
|
|
#include "nsWrapperCache.h"
|
2010-09-09 15:15:38 -07:00
|
|
|
|
2013-07-31 08:48:36 -07:00
|
|
|
#include "mozilla/dom/indexedDB/IDBObjectStore.h"
|
|
|
|
#include "mozilla/dom/indexedDB/Key.h"
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
class nsIRunnable;
|
2010-11-10 15:26:03 -08:00
|
|
|
class nsIScriptContext;
|
|
|
|
class nsPIDOMWindow;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-08-22 22:17:10 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-09-17 08:16:02 -07:00
|
|
|
class OwningIDBObjectStoreOrIDBIndex;
|
2013-08-22 22:17:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
class ContinueHelper;
|
|
|
|
class ContinueObjectStoreHelper;
|
|
|
|
class ContinueIndexHelper;
|
|
|
|
class ContinueIndexObjectHelper;
|
2012-06-01 10:21:12 -07:00
|
|
|
class IDBIndex;
|
|
|
|
class IDBRequest;
|
|
|
|
class IDBTransaction;
|
|
|
|
class IndexedDBCursorChild;
|
|
|
|
class IndexedDBCursorParent;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
class IDBCursor MOZ_FINAL : public nsISupports,
|
|
|
|
public nsWrapperCache
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2010-12-09 18:15:00 -08:00
|
|
|
friend class ContinueHelper;
|
|
|
|
friend class ContinueObjectStoreHelper;
|
|
|
|
friend class ContinueIndexHelper;
|
|
|
|
friend class ContinueIndexObjectHelper;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
public:
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor)
|
2010-09-09 15:15:38 -07:00
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
OBJECTSTORE = 0,
|
2013-09-25 16:11:47 -07:00
|
|
|
OBJECTSTOREKEY,
|
2012-03-12 21:44:45 -07:00
|
|
|
INDEXKEY,
|
|
|
|
INDEXOBJECT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Direction
|
|
|
|
{
|
|
|
|
NEXT = 0,
|
|
|
|
NEXT_UNIQUE,
|
|
|
|
PREV,
|
2012-06-01 10:21:12 -07:00
|
|
|
PREV_UNIQUE,
|
|
|
|
|
|
|
|
// Only needed for IPC serialization helper, should never be used in code.
|
|
|
|
DIRECTION_INVALID
|
2012-03-12 21:44:45 -07:00
|
|
|
};
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
// For OBJECTSTORE cursors.
|
2010-06-23 12:46:08 -07:00
|
|
|
static
|
2010-06-28 11:51:06 -07:00
|
|
|
already_AddRefed<IDBCursor>
|
2010-06-23 12:46:08 -07:00
|
|
|
Create(IDBRequest* aRequest,
|
2010-06-28 09:46:21 -07:00
|
|
|
IDBTransaction* aTransaction,
|
2010-06-28 11:51:06 -07:00
|
|
|
IDBObjectStore* aObjectStore,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
2014-01-31 18:50:07 -08:00
|
|
|
StructuredCloneReadInfo&& aCloneReadInfo);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
// For OBJECTSTOREKEY cursors.
|
|
|
|
static
|
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBObjectStore* aObjectStore,
|
|
|
|
Direction aDirection,
|
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey);
|
|
|
|
|
2011-02-10 23:47:00 -08:00
|
|
|
// For INDEXKEY cursors.
|
2010-06-23 12:46:08 -07:00
|
|
|
static
|
2010-06-28 11:51:06 -07:00
|
|
|
already_AddRefed<IDBCursor>
|
2010-06-23 12:46:08 -07:00
|
|
|
Create(IDBRequest* aRequest,
|
2010-06-28 09:46:21 -07:00
|
|
|
IDBTransaction* aTransaction,
|
2010-06-28 11:51:06 -07:00
|
|
|
IDBIndex* aIndex,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
|
|
|
const Key& aObjectKey);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
// For INDEXOBJECT cursors.
|
2010-06-23 12:46:08 -07:00
|
|
|
static
|
2010-06-28 11:51:06 -07:00
|
|
|
already_AddRefed<IDBCursor>
|
2010-06-23 12:46:08 -07:00
|
|
|
Create(IDBRequest* aRequest,
|
2010-06-28 09:46:21 -07:00
|
|
|
IDBTransaction* aTransaction,
|
2010-06-28 11:51:06 -07:00
|
|
|
IDBIndex* aIndex,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
|
|
|
const Key& aObjectKey,
|
2014-01-31 18:50:07 -08:00
|
|
|
StructuredCloneReadInfo&& aCloneReadInfo);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
IDBTransaction* Transaction() const
|
2010-09-09 15:15:38 -07:00
|
|
|
{
|
|
|
|
return mTransaction;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
IDBRequest* Request() const
|
|
|
|
{
|
|
|
|
return mRequest;
|
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:36 -07:00
|
|
|
static Direction
|
|
|
|
ConvertDirection(IDBCursorDirection aDirection);
|
2012-03-12 21:44:45 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
void
|
|
|
|
SetActor(IndexedDBCursorChild* aActorChild)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
|
|
|
|
mActorChild = aActorChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetActor(IndexedDBCursorParent* aActorParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aActorParent || !mActorParent,
|
|
|
|
"Shouldn't have more than one!");
|
|
|
|
mActorParent = aActorParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexedDBCursorChild*
|
|
|
|
GetActorChild() const
|
|
|
|
{
|
|
|
|
return mActorChild;
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:29:07 -08:00
|
|
|
IndexedDBCursorParent*
|
|
|
|
GetActorParent() const
|
|
|
|
{
|
|
|
|
return mActorParent;
|
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
void
|
|
|
|
ContinueInternal(const Key& aKey, int32_t aCount,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-07-31 15:28:13 -07:00
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
IDBTransaction*
|
|
|
|
GetParentObject() const
|
|
|
|
{
|
|
|
|
return mTransaction;
|
|
|
|
}
|
|
|
|
|
2013-08-22 22:17:10 -07:00
|
|
|
void
|
2013-09-17 08:16:02 -07:00
|
|
|
GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const;
|
2013-07-31 15:28:13 -07:00
|
|
|
|
|
|
|
IDBCursorDirection
|
|
|
|
GetDirection() const;
|
|
|
|
|
|
|
|
JS::Value
|
|
|
|
GetKey(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
|
|
|
|
JS::Value
|
|
|
|
GetPrimaryKey(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Update(JSContext* aCx, JS::Handle<JS::Value> aValue, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void
|
|
|
|
Advance(uint32_t aCount, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void
|
2014-02-19 07:13:38 -08:00
|
|
|
Continue(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv);
|
2013-07-31 15:28:13 -07:00
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Delete(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
|
|
|
|
JS::Value
|
|
|
|
GetValue(JSContext* aCx, ErrorResult& aRv);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
protected:
|
2010-06-28 11:51:06 -07:00
|
|
|
IDBCursor();
|
|
|
|
~IDBCursor();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-11-27 17:37:57 -08:00
|
|
|
void DropJSObjects();
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
static
|
2010-06-28 11:51:06 -07:00
|
|
|
already_AddRefed<IDBCursor>
|
2010-06-23 12:46:08 -07:00
|
|
|
CreateCommon(IDBRequest* aRequest,
|
2010-06-28 09:46:21 -07:00
|
|
|
IDBTransaction* aTransaction,
|
2010-12-09 18:15:00 -08:00
|
|
|
IDBObjectStore* aObjectStore,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
nsRefPtr<IDBRequest> mRequest;
|
2010-06-28 09:46:21 -07:00
|
|
|
nsRefPtr<IDBTransaction> mTransaction;
|
2010-06-28 11:51:06 -07:00
|
|
|
nsRefPtr<IDBObjectStore> mObjectStore;
|
2010-06-28 11:51:06 -07:00
|
|
|
nsRefPtr<IDBIndex> mIndex;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
JS::Heap<JSObject*> mScriptOwner;
|
2010-11-10 15:26:03 -08:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
Type mType;
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction mDirection;
|
2010-12-09 18:15:00 -08:00
|
|
|
nsCString mContinueQuery;
|
|
|
|
nsCString mContinueToQuery;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-02-10 23:47:00 -08:00
|
|
|
// These are cycle-collected!
|
2013-06-18 03:00:37 -07:00
|
|
|
JS::Heap<JS::Value> mCachedKey;
|
|
|
|
JS::Heap<JS::Value> mCachedPrimaryKey;
|
|
|
|
JS::Heap<JS::Value> mCachedValue;
|
2010-12-09 18:15:00 -08:00
|
|
|
|
|
|
|
Key mRangeKey;
|
|
|
|
|
|
|
|
Key mKey;
|
|
|
|
Key mObjectKey;
|
2011-12-15 23:34:24 -08:00
|
|
|
StructuredCloneReadInfo mCloneReadInfo;
|
2010-12-09 18:15:00 -08:00
|
|
|
Key mContinueToKey;
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
IndexedDBCursorChild* mActorChild;
|
|
|
|
IndexedDBCursorParent* mActorParent;
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
bool mHaveCachedKey;
|
2011-02-10 23:47:00 -08:00
|
|
|
bool mHaveCachedPrimaryKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
bool mHaveCachedValue;
|
2011-02-10 23:47:00 -08:00
|
|
|
bool mRooted;
|
2010-06-23 12:46:08 -07:00
|
|
|
bool mContinueCalled;
|
2011-01-06 22:21:36 -08:00
|
|
|
bool mHaveValue;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
#endif // mozilla_dom_indexeddb_idbcursor_h__
|