2010-06-23 19:46:08 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 19:46:08 +00:00
|
|
|
|
2010-06-28 18:51:06 +00:00
|
|
|
#ifndef mozilla_dom_indexeddb_idbcursor_h__
|
|
|
|
#define mozilla_dom_indexeddb_idbcursor_h__
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "IndexedDatabase.h"
|
|
|
|
#include "js/RootingAPI.h"
|
2013-07-31 22:28:13 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-07-31 15:48:36 +00:00
|
|
|
#include "mozilla/dom/IDBCursorBinding.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "mozilla/dom/indexedDB/Key.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2010-11-10 23:26:03 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-07-31 22:28:13 +00:00
|
|
|
#include "nsWrapperCache.h"
|
2010-09-09 22:15:38 +00:00
|
|
|
|
2010-11-10 23:26:03 +00:00
|
|
|
class nsPIDOMWindow;
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2013-08-23 05:17:10 +00:00
|
|
|
namespace mozilla {
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
2013-08-23 05:17:10 +00:00
|
|
|
namespace dom {
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2013-09-17 15:16:02 +00:00
|
|
|
class OwningIDBObjectStoreOrIDBIndex;
|
2013-08-23 05:17:10 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
namespace indexedDB {
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class BackgroundCursorChild;
|
2012-06-01 17:21:12 +00:00
|
|
|
class IDBIndex;
|
2014-09-26 23:21:57 +00:00
|
|
|
class IDBObjectStore;
|
2012-06-01 17:21:12 +00:00
|
|
|
class IDBRequest;
|
|
|
|
class IDBTransaction;
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class IDBCursor final
|
2014-09-26 23:21:57 +00:00
|
|
|
: public nsISupports
|
|
|
|
, public nsWrapperCache
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-03-13 04:44:45 +00:00
|
|
|
enum Direction
|
|
|
|
{
|
|
|
|
NEXT = 0,
|
|
|
|
NEXT_UNIQUE,
|
|
|
|
PREV,
|
2012-06-01 17:21:12 +00:00
|
|
|
PREV_UNIQUE,
|
|
|
|
|
|
|
|
// Only needed for IPC serialization helper, should never be used in code.
|
|
|
|
DIRECTION_INVALID
|
2012-03-13 04:44:45 +00:00
|
|
|
};
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
private:
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
Type_ObjectStore,
|
|
|
|
Type_ObjectStoreKey,
|
|
|
|
Type_Index,
|
|
|
|
Type_IndexKey,
|
|
|
|
};
|
|
|
|
|
2014-11-08 00:42:53 +00:00
|
|
|
BackgroundCursorChild* mBackgroundActor;
|
|
|
|
|
|
|
|
nsRefPtr<IDBRequest> mRequest;
|
2014-09-26 23:21:57 +00:00
|
|
|
nsRefPtr<IDBObjectStore> mSourceObjectStore;
|
|
|
|
nsRefPtr<IDBIndex> mSourceIndex;
|
|
|
|
|
2014-11-08 00:42:53 +00:00
|
|
|
// mSourceObjectStore or mSourceIndex will hold this alive.
|
|
|
|
IDBTransaction* mTransaction;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
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>
|
2014-11-08 00:42:53 +00:00
|
|
|
Create(BackgroundCursorChild* aBackgroundActor,
|
2010-12-10 02:15:00 +00:00
|
|
|
const Key& aKey,
|
2014-09-26 23:21:57 +00:00
|
|
|
StructuredCloneReadInfo&& aCloneInfo);
|
|
|
|
|
|
|
|
static already_AddRefed<IDBCursor>
|
2014-11-08 00:42:53 +00:00
|
|
|
Create(BackgroundCursorChild* aBackgroundActor,
|
2013-09-25 23:11:47 +00:00
|
|
|
const Key& aKey);
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
static already_AddRefed<IDBCursor>
|
2014-11-08 00:42:53 +00:00
|
|
|
Create(BackgroundCursorChild* aBackgroundActor,
|
2010-12-10 02:15:00 +00:00
|
|
|
const Key& aKey,
|
2014-09-26 23:21:57 +00:00
|
|
|
const Key& aPrimaryKey,
|
|
|
|
StructuredCloneReadInfo&& aCloneInfo);
|
|
|
|
|
|
|
|
static already_AddRefed<IDBCursor>
|
2014-11-08 00:42:53 +00:00
|
|
|
Create(BackgroundCursorChild* aBackgroundActor,
|
2010-12-10 02:15:00 +00:00
|
|
|
const Key& aKey,
|
2014-09-26 23:21:57 +00:00
|
|
|
const Key& aPrimaryKey);
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2013-07-31 15:48:36 +00:00
|
|
|
static Direction
|
|
|
|
ConvertDirection(IDBCursorDirection aDirection);
|
2012-03-13 04:44:45 +00:00
|
|
|
|
2012-06-01 17:21:12 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
2013-07-31 22:28:13 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const;
|
2013-07-31 22:28:13 +00:00
|
|
|
|
2013-08-23 05:17:10 +00:00
|
|
|
void
|
2013-09-17 15:16:02 +00:00
|
|
|
GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const;
|
2013-07-31 22:28:13 +00:00
|
|
|
|
|
|
|
IDBCursorDirection
|
|
|
|
GetDirection() const;
|
|
|
|
|
2014-06-11 20:26:52 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
GetKey(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
2014-06-11 20:26:52 +00:00
|
|
|
ErrorResult& aRv);
|
2013-07-31 22:28:13 +00:00
|
|
|
|
2014-06-11 20:26:52 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
GetPrimaryKey(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
2014-06-11 20:26:52 +00:00
|
|
|
ErrorResult& aRv);
|
2013-07-31 22:28:13 +00:00
|
|
|
|
2014-09-13 16:12:19 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
GetValue(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-17 23:36:01 +00:00
|
|
|
void
|
|
|
|
Continue(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv);
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
Advance(uint32_t aCount, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Update(JSContext* aCx, JS::Handle<JS::Value> aValue, ErrorResult& aRv);
|
|
|
|
|
2013-07-31 22:28:13 +00:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Delete(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
|
2014-06-11 20:26:52 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
Reset();
|
2012-11-28 01:37:57 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
Reset(Key&& aKey, StructuredCloneReadInfo&& aValue);
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
Reset(Key&& aKey);
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
Reset(Key&& aKey, Key&& aPrimaryKey, StructuredCloneReadInfo&& aValue);
|
2010-11-10 23:26:03 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
Reset(Key&& aKey, Key&& aPrimaryKey);
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
ClearBackgroundActor()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
mBackgroundActor = nullptr;
|
|
|
|
}
|
2010-12-10 02:15:00 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor)
|
|
|
|
|
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
2015-03-21 16:28:04 +00:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2010-12-10 02:15:00 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
private:
|
|
|
|
IDBCursor(Type aType,
|
|
|
|
BackgroundCursorChild* aBackgroundActor,
|
|
|
|
const Key& aKey);
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
~IDBCursor();
|
|
|
|
|
|
|
|
void
|
|
|
|
DropJSObjects();
|
2015-07-02 17:47:53 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
IsSourceDeleted() const;
|
2010-06-23 19:46:08 +00:00
|
|
|
};
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2010-06-28 18:51:06 +00:00
|
|
|
#endif // mozilla_dom_indexeddb_idbcursor_h__
|