2010-06-23 23:46:08 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=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
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
#ifndef mozilla_dom_idbcursor_h__
|
|
|
|
#define mozilla_dom_idbcursor_h__
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "IndexedDatabase.h"
|
|
|
|
#include "js/RootingAPI.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"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/indexedDB/Key.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
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowInner;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-23 09:17:10 +04:00
|
|
|
namespace mozilla {
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
2013-08-23 09:17:10 +04:00
|
|
|
namespace dom {
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
class IDBIndex;
|
2014-09-27 03:21:57 +04:00
|
|
|
class IDBObjectStore;
|
2012-06-01 21:21:12 +04:00
|
|
|
class IDBRequest;
|
|
|
|
class IDBTransaction;
|
2016-02-17 00:46:08 +03:00
|
|
|
class OwningIDBObjectStoreOrIDBIndex;
|
|
|
|
|
|
|
|
namespace indexedDB {
|
|
|
|
class BackgroundCursorChild;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class IDBCursor final
|
2014-09-27 03:21:57 +04:00
|
|
|
: public nsISupports
|
|
|
|
, public nsWrapperCache
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-02-17 00:46:08 +03:00
|
|
|
typedef indexedDB::Key Key;
|
|
|
|
typedef indexedDB::StructuredCloneReadInfo StructuredCloneReadInfo;
|
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
private:
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
Type_ObjectStore,
|
|
|
|
Type_ObjectStoreKey,
|
|
|
|
Type_Index,
|
|
|
|
Type_IndexKey,
|
|
|
|
};
|
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundCursorChild* mBackgroundActor;
|
2014-11-08 03:42:53 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBRequest> mRequest;
|
|
|
|
RefPtr<IDBObjectStore> mSourceObjectStore;
|
|
|
|
RefPtr<IDBIndex> mSourceIndex;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2014-11-08 03:42:53 +03:00
|
|
|
// mSourceObjectStore or mSourceIndex will hold this alive.
|
|
|
|
IDBTransaction* mTransaction;
|
2014-09-27 03:21:57 +04: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;
|
2015-09-04 22:12:29 +03:00
|
|
|
Key mSortKey;
|
2014-09-27 03:21:57 +04:00
|
|
|
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>
|
2016-02-17 00:46:08 +03:00
|
|
|
Create(indexedDB::BackgroundCursorChild* aBackgroundActor,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aKey,
|
2014-09-27 03:21:57 +04:00
|
|
|
StructuredCloneReadInfo&& aCloneInfo);
|
|
|
|
|
|
|
|
static already_AddRefed<IDBCursor>
|
2016-02-17 00:46:08 +03:00
|
|
|
Create(indexedDB::BackgroundCursorChild* aBackgroundActor,
|
2013-09-26 03:11:47 +04:00
|
|
|
const Key& aKey);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
static already_AddRefed<IDBCursor>
|
2016-02-17 00:46:08 +03:00
|
|
|
Create(indexedDB::BackgroundCursorChild* aBackgroundActor,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aKey,
|
2015-09-04 22:12:29 +03:00
|
|
|
const Key& aSortKey,
|
2014-09-27 03:21:57 +04:00
|
|
|
const Key& aPrimaryKey,
|
|
|
|
StructuredCloneReadInfo&& aCloneInfo);
|
|
|
|
|
|
|
|
static already_AddRefed<IDBCursor>
|
2016-02-17 00:46:08 +03:00
|
|
|
Create(indexedDB::BackgroundCursorChild* aBackgroundActor,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aKey,
|
2015-09-04 22:12:29 +03:00
|
|
|
const Key& aSortKey,
|
2014-09-27 03:21:57 +04:00
|
|
|
const Key& aPrimaryKey);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
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
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
2013-08-01 02:28:13 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner*
|
2014-09-27 03:21:57 +04:00
|
|
|
GetParentObject() const;
|
2013-08-01 02:28:13 +04:00
|
|
|
|
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
|
2014-09-27 03:21:57 +04:00
|
|
|
GetKey(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
2014-06-12 00:26:52 +04:00
|
|
|
ErrorResult& aRv);
|
2013-08-01 02:28:13 +04:00
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
GetPrimaryKey(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
2014-06-12 00:26:52 +04:00
|
|
|
ErrorResult& aRv);
|
2013-08-01 02:28:13 +04:00
|
|
|
|
2014-09-13 20:12:19 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
GetValue(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-18 03:36:01 +04:00
|
|
|
void
|
|
|
|
Continue(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
Advance(uint32_t aCount, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Update(JSContext* aCx, JS::Handle<JS::Value> aValue, 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
|
2014-09-27 03:21:57 +04:00
|
|
|
Reset();
|
2012-11-28 05:37:57 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
Reset(Key&& aKey, StructuredCloneReadInfo&& aValue);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
Reset(Key&& aKey);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2015-09-04 22:12:29 +03:00
|
|
|
Reset(Key&& aKey, Key&& aSortKey, Key&& aPrimaryKey, StructuredCloneReadInfo&& aValue);
|
2010-11-11 02:26:03 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2015-09-04 22:12:29 +03:00
|
|
|
Reset(Key&& aKey, Key&& aSortKey, Key&& aPrimaryKey);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
ClearBackgroundActor()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mBackgroundActor = nullptr;
|
|
|
|
}
|
2010-12-10 05:15:00 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBCursor)
|
|
|
|
|
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2010-12-10 05:15:00 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
private:
|
|
|
|
IDBCursor(Type aType,
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundCursorChild* aBackgroundActor,
|
2014-09-27 03:21:57 +04:00
|
|
|
const Key& aKey);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
~IDBCursor();
|
|
|
|
|
2015-09-04 22:12:29 +03:00
|
|
|
#ifdef ENABLE_INTL_API
|
|
|
|
// Checks if this is a locale aware cursor (ie. the index's sortKey is unset)
|
|
|
|
bool
|
|
|
|
IsLocaleAware() const;
|
|
|
|
#endif
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
DropJSObjects();
|
2015-07-02 20:47:53 +03:00
|
|
|
|
|
|
|
bool
|
|
|
|
IsSourceDeleted() const;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
#endif // mozilla_dom_idbcursor_h__
|