2010-06-23 23:46:08 +04: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 15:12:37 +04: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 23:46:08 +04:00
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
#ifndef mozilla_dom_indexeddb_idbcursor_h__
|
|
|
|
#define mozilla_dom_indexeddb_idbcursor_h__
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-09-10 02:15:38 +04:00
|
|
|
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-07-31 19:48:36 +04:00
|
|
|
#include "mozilla/dom/IDBCursorBinding.h"
|
2013-08-01 02:28:13 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2010-11-11 02:26:03 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-08-01 02:28:13 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
#include "mozilla/dom/indexedDB/IDBObjectStore.h"
|
|
|
|
#include "mozilla/dom/indexedDB/Key.h"
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
class nsIRunnable;
|
2010-11-11 02:26:03 +03:00
|
|
|
class nsIScriptContext;
|
|
|
|
class nsPIDOMWindow;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-23 09:17:10 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-09-17 19:16:02 +04:00
|
|
|
class OwningIDBObjectStoreOrIDBIndex;
|
2013-08-23 09:17:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
class ContinueHelper;
|
|
|
|
class ContinueObjectStoreHelper;
|
|
|
|
class ContinueIndexHelper;
|
|
|
|
class ContinueIndexObjectHelper;
|
2012-06-01 21:21:12 +04:00
|
|
|
class IDBIndex;
|
|
|
|
class IDBRequest;
|
|
|
|
class IDBTransaction;
|
|
|
|
class IndexedDBCursorChild;
|
|
|
|
class IndexedDBCursorParent;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
class IDBCursor MOZ_FINAL : public nsISupports,
|
|
|
|
public nsWrapperCache
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2010-12-10 05:15:00 +03:00
|
|
|
friend class ContinueHelper;
|
|
|
|
friend class ContinueObjectStoreHelper;
|
|
|
|
friend class ContinueIndexHelper;
|
|
|
|
friend class ContinueIndexObjectHelper;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
public:
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor)
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
OBJECTSTORE = 0,
|
2013-09-26 03:11:47 +04:00
|
|
|
OBJECTSTOREKEY,
|
2012-03-13 08:44:45 +04:00
|
|
|
INDEXKEY,
|
|
|
|
INDEXOBJECT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Direction
|
|
|
|
{
|
|
|
|
NEXT = 0,
|
|
|
|
NEXT_UNIQUE,
|
|
|
|
PREV,
|
2012-06-01 21:21:12 +04:00
|
|
|
PREV_UNIQUE,
|
|
|
|
|
|
|
|
// Only needed for IPC serialization helper, should never be used in code.
|
|
|
|
DIRECTION_INVALID
|
2012-03-13 08:44:45 +04:00
|
|
|
};
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
// For OBJECTSTORE cursors.
|
2010-06-23 23:46:08 +04:00
|
|
|
static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
2010-06-23 23:46:08 +04:00
|
|
|
Create(IDBRequest* aRequest,
|
2010-06-28 20:46:21 +04:00
|
|
|
IDBTransaction* aTransaction,
|
2010-06-28 22:51:06 +04:00
|
|
|
IDBObjectStore* aObjectStore,
|
2012-03-13 08:44:45 +04:00
|
|
|
Direction aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
2014-02-01 06:50:07 +04:00
|
|
|
StructuredCloneReadInfo&& aCloneReadInfo);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-09-26 03:11:47 +04: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-11 10:47:00 +03:00
|
|
|
// For INDEXKEY cursors.
|
2010-06-23 23:46:08 +04:00
|
|
|
static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
2010-06-23 23:46:08 +04:00
|
|
|
Create(IDBRequest* aRequest,
|
2010-06-28 20:46:21 +04:00
|
|
|
IDBTransaction* aTransaction,
|
2010-06-28 22:51:06 +04:00
|
|
|
IDBIndex* aIndex,
|
2012-03-13 08:44:45 +04:00
|
|
|
Direction aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
|
|
|
const Key& aObjectKey);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
// For INDEXOBJECT cursors.
|
2010-06-23 23:46:08 +04:00
|
|
|
static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
2010-06-23 23:46:08 +04:00
|
|
|
Create(IDBRequest* aRequest,
|
2010-06-28 20:46:21 +04:00
|
|
|
IDBTransaction* aTransaction,
|
2010-06-28 22:51:06 +04:00
|
|
|
IDBIndex* aIndex,
|
2012-03-13 08:44:45 +04:00
|
|
|
Direction aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
|
|
|
const Key& aObjectKey,
|
2014-02-01 06:50:07 +04:00
|
|
|
StructuredCloneReadInfo&& aCloneReadInfo);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
IDBTransaction* Transaction() const
|
2010-09-10 02:15:38 +04:00
|
|
|
{
|
|
|
|
return mTransaction;
|
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
IDBRequest* Request() const
|
|
|
|
{
|
|
|
|
return mRequest;
|
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
static Direction
|
|
|
|
ConvertDirection(IDBCursorDirection aDirection);
|
2012-03-13 08:44:45 +04:00
|
|
|
|
2012-06-01 21:21:12 +04: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-10 07:29:07 +04:00
|
|
|
IndexedDBCursorParent*
|
|
|
|
GetActorParent() const
|
|
|
|
{
|
|
|
|
return mActorParent;
|
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
void
|
|
|
|
ContinueInternal(const Key& aKey, int32_t aCount,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
2014-04-09 02:27:18 +04:00
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-08-01 02:28:13 +04:00
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
IDBTransaction*
|
|
|
|
GetParentObject() const
|
|
|
|
{
|
|
|
|
return mTransaction;
|
|
|
|
}
|
|
|
|
|
2013-08-23 09:17:10 +04:00
|
|
|
void
|
2013-09-17 19:16:02 +04:00
|
|
|
GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const;
|
2013-08-01 02:28:13 +04:00
|
|
|
|
|
|
|
IDBCursorDirection
|
|
|
|
GetDirection() const;
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void
|
|
|
|
GetKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2013-08-01 02:28:13 +04:00
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void
|
|
|
|
GetPrimaryKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2013-08-01 02:28:13 +04:00
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Update(JSContext* aCx, JS::Handle<JS::Value> aValue, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void
|
|
|
|
Advance(uint32_t aCount, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void
|
2014-02-19 19:13:38 +04:00
|
|
|
Continue(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv);
|
2013-08-01 02:28:13 +04:00
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Delete(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void
|
|
|
|
GetValue(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
protected:
|
2010-06-28 22:51:06 +04:00
|
|
|
IDBCursor();
|
|
|
|
~IDBCursor();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-11-28 05:37:57 +04:00
|
|
|
void DropJSObjects();
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
2010-06-23 23:46:08 +04:00
|
|
|
CreateCommon(IDBRequest* aRequest,
|
2010-06-28 20:46:21 +04:00
|
|
|
IDBTransaction* aTransaction,
|
2010-12-10 05:15:00 +03:00
|
|
|
IDBObjectStore* aObjectStore,
|
2012-03-13 08:44:45 +04:00
|
|
|
Direction aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
nsRefPtr<IDBRequest> mRequest;
|
2010-06-28 20:46:21 +04:00
|
|
|
nsRefPtr<IDBTransaction> mTransaction;
|
2010-06-28 22:51:06 +04:00
|
|
|
nsRefPtr<IDBObjectStore> mObjectStore;
|
2010-06-28 22:51:06 +04:00
|
|
|
nsRefPtr<IDBIndex> mIndex;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-06-18 14:00:38 +04:00
|
|
|
JS::Heap<JSObject*> mScriptOwner;
|
2010-11-11 02:26:03 +03:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
Type mType;
|
2012-03-13 08:44:45 +04:00
|
|
|
Direction mDirection;
|
2010-12-10 05:15:00 +03:00
|
|
|
nsCString mContinueQuery;
|
|
|
|
nsCString mContinueToQuery;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-02-11 10:47:00 +03:00
|
|
|
// These are cycle-collected!
|
2013-06-18 14:00:37 +04:00
|
|
|
JS::Heap<JS::Value> mCachedKey;
|
|
|
|
JS::Heap<JS::Value> mCachedPrimaryKey;
|
|
|
|
JS::Heap<JS::Value> mCachedValue;
|
2010-12-10 05:15:00 +03:00
|
|
|
|
|
|
|
Key mRangeKey;
|
|
|
|
|
|
|
|
Key mKey;
|
|
|
|
Key mObjectKey;
|
2011-12-16 11:34:24 +04:00
|
|
|
StructuredCloneReadInfo mCloneReadInfo;
|
2010-12-10 05:15:00 +03:00
|
|
|
Key mContinueToKey;
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
IndexedDBCursorChild* mActorChild;
|
|
|
|
IndexedDBCursorParent* mActorParent;
|
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
bool mHaveCachedKey;
|
2011-02-11 10:47:00 +03:00
|
|
|
bool mHaveCachedPrimaryKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
bool mHaveCachedValue;
|
2011-02-11 10:47:00 +03:00
|
|
|
bool mRooted;
|
2010-06-23 23:46:08 +04:00
|
|
|
bool mContinueCalled;
|
2011-01-07 09:21:36 +03:00
|
|
|
bool mHaveValue;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
#endif // mozilla_dom_indexeddb_idbcursor_h__
|