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"
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "mozilla/dom/indexedDB/IDBObjectStore.h"
|
2011-11-03 08:57:30 -07:00
|
|
|
#include "mozilla/dom/indexedDB/Key.h"
|
2010-09-09 15:15:38 -07:00
|
|
|
|
2011-02-10 23:47:00 -08:00
|
|
|
#include "nsIIDBCursorWithValue.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2010-09-09 15:15:38 -07:00
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2012-05-14 21:50:29 -07:00
|
|
|
class IDBCursor MOZ_FINAL : public nsIIDBCursorWithValue
|
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
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_DECL_NSIIDBCURSOR
|
2011-02-10 23:47:00 -08:00
|
|
|
NS_DECL_NSIIDBCURSORWITHVALUE
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
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,
|
|
|
|
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,
|
2011-12-15 23:34:24 -08:00
|
|
|
StructuredCloneReadInfo& aCloneReadInfo);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
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,
|
2011-12-15 23:34:24 -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;
|
|
|
|
}
|
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
static nsresult ParseDirection(const nsAString& aDirection,
|
|
|
|
Direction* aResult);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
nsresult
|
|
|
|
ContinueInternal(const Key& aKey,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aCount);
|
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__
|