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
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "IndexedDatabase.h"
|
|
|
|
#include "js/RootingAPI.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"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "mozilla/dom/indexedDB/Key.h"
|
|
|
|
#include "nsAutoPtr.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
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
class nsPIDOMWindow;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-08-22 22:17:10 -07:00
|
|
|
namespace mozilla {
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
2013-08-22 22:17:10 -07:00
|
|
|
namespace dom {
|
2014-09-26 16:21:57 -07:00
|
|
|
|
2013-09-17 08:16:02 -07:00
|
|
|
class OwningIDBObjectStoreOrIDBIndex;
|
2013-08-22 22:17:10 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
namespace indexedDB {
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
class BackgroundCursorChild;
|
2012-06-01 10:21:12 -07:00
|
|
|
class IDBIndex;
|
2014-09-26 16:21:57 -07:00
|
|
|
class IDBObjectStore;
|
2012-06-01 10:21:12 -07:00
|
|
|
class IDBRequest;
|
|
|
|
class IDBTransaction;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
class IDBCursor MOZ_FINAL
|
|
|
|
: public nsISupports
|
|
|
|
, public nsWrapperCache
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-03-12 21:44:45 -07:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
private:
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
Type_ObjectStore,
|
|
|
|
Type_ObjectStoreKey,
|
|
|
|
Type_Index,
|
|
|
|
Type_IndexKey,
|
|
|
|
};
|
|
|
|
|
|
|
|
nsRefPtr<IDBObjectStore> mSourceObjectStore;
|
|
|
|
nsRefPtr<IDBIndex> mSourceIndex;
|
|
|
|
nsRefPtr<IDBTransaction> mTransaction;
|
|
|
|
|
|
|
|
BackgroundCursorChild* mBackgroundActor;
|
|
|
|
|
|
|
|
JS::Heap<JSObject*> mScriptOwner;
|
|
|
|
|
|
|
|
// These are cycle-collected!
|
|
|
|
JS::Heap<JS::Value> mCachedKey;
|
|
|
|
JS::Heap<JS::Value> mCachedPrimaryKey;
|
|
|
|
JS::Heap<JS::Value> mCachedValue;
|
|
|
|
|
|
|
|
Key mKey;
|
|
|
|
Key mPrimaryKey;
|
|
|
|
StructuredCloneReadInfo mCloneInfo;
|
|
|
|
|
|
|
|
const Type mType;
|
|
|
|
const Direction mDirection;
|
|
|
|
|
|
|
|
bool mHaveCachedKey : 1;
|
|
|
|
bool mHaveCachedPrimaryKey : 1;
|
|
|
|
bool mHaveCachedValue : 1;
|
|
|
|
bool mRooted : 1;
|
|
|
|
bool mContinueCalled : 1;
|
|
|
|
bool mHaveValue : 1;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<IDBCursor>
|
|
|
|
Create(IDBObjectStore* aObjectStore,
|
|
|
|
BackgroundCursorChild* aBackgroundActor,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aKey,
|
2014-09-26 16:21:57 -07:00
|
|
|
StructuredCloneReadInfo&& aCloneInfo);
|
|
|
|
|
|
|
|
static already_AddRefed<IDBCursor>
|
|
|
|
Create(IDBObjectStore* aObjectStore,
|
|
|
|
BackgroundCursorChild* aBackgroundActor,
|
2013-09-25 16:11:47 -07:00
|
|
|
Direction aDirection,
|
|
|
|
const Key& aKey);
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
static already_AddRefed<IDBCursor>
|
|
|
|
Create(IDBIndex* aIndex,
|
|
|
|
BackgroundCursorChild* aBackgroundActor,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aKey,
|
2014-09-26 16:21:57 -07:00
|
|
|
const Key& aPrimaryKey,
|
|
|
|
StructuredCloneReadInfo&& aCloneInfo);
|
|
|
|
|
|
|
|
static already_AddRefed<IDBCursor>
|
|
|
|
Create(IDBIndex* aIndex,
|
|
|
|
BackgroundCursorChild* aBackgroundActor,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aKey,
|
2014-09-26 16:21:57 -07:00
|
|
|
const Key& aPrimaryKey);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
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
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
2013-07-31 15:28:13 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const;
|
2013-07-31 15:28:13 -07:00
|
|
|
|
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;
|
|
|
|
|
2014-06-11 13:26:52 -07:00
|
|
|
void
|
2014-09-26 16:21:57 -07:00
|
|
|
GetKey(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
2014-06-11 13:26:52 -07:00
|
|
|
ErrorResult& aRv);
|
2013-07-31 15:28:13 -07:00
|
|
|
|
2014-06-11 13:26:52 -07:00
|
|
|
void
|
2014-09-26 16:21:57 -07:00
|
|
|
GetPrimaryKey(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
2014-06-11 13:26:52 -07:00
|
|
|
ErrorResult& aRv);
|
2013-07-31 15:28:13 -07:00
|
|
|
|
2014-09-13 09:12:19 -07:00
|
|
|
void
|
2014-09-26 16:21:57 -07:00
|
|
|
GetValue(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-17 16:36:01 -07:00
|
|
|
void
|
|
|
|
Continue(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv);
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
Advance(uint32_t aCount, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Update(JSContext* aCx, JS::Handle<JS::Value> aValue, ErrorResult& aRv);
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Delete(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
|
2014-06-11 13:26:52 -07:00
|
|
|
void
|
2014-09-26 16:21:57 -07:00
|
|
|
Reset();
|
2012-11-27 17:37:57 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
Reset(Key&& aKey, StructuredCloneReadInfo&& aValue);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
Reset(Key&& aKey);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
Reset(Key&& aKey, Key&& aPrimaryKey, StructuredCloneReadInfo&& aValue);
|
2010-11-10 15:26:03 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
Reset(Key&& aKey, Key&& aPrimaryKey);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
ClearBackgroundActor()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
mBackgroundActor = nullptr;
|
|
|
|
}
|
2010-12-09 18:15:00 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor)
|
|
|
|
|
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2010-12-09 18:15:00 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
private:
|
|
|
|
IDBCursor(Type aType,
|
|
|
|
IDBObjectStore* aSourceObjectStore,
|
|
|
|
IDBIndex* aSourceIndex,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
BackgroundCursorChild* aBackgroundActor,
|
|
|
|
Direction aDirection,
|
|
|
|
const Key& aKey);
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
~IDBCursor();
|
|
|
|
|
|
|
|
void
|
|
|
|
DropJSObjects();
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
#endif // mozilla_dom_indexeddb_idbcursor_h__
|