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
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
#ifndef mozilla_dom_idbcursor_h__
|
|
|
|
#define mozilla_dom_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"
|
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
|
|
|
|
2019-03-29 18:05:11 +00:00
|
|
|
class nsIGlobalObject;
|
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
|
|
|
|
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;
|
2016-02-16 21:46:08 +00:00
|
|
|
class OwningIDBObjectStoreOrIDBIndex;
|
|
|
|
|
|
|
|
namespace indexedDB {
|
|
|
|
class BackgroundCursorChild;
|
|
|
|
}
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class IDBCursor final : public nsISupports, public nsWrapperCache {
|
2010-06-23 19:46:08 +00:00
|
|
|
public:
|
2016-02-16 21:46:08 +00:00
|
|
|
typedef indexedDB::Key Key;
|
|
|
|
typedef indexedDB::StructuredCloneReadInfo StructuredCloneReadInfo;
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
indexedDB::BackgroundCursorChild* mBackgroundActor;
|
2014-11-08 00:42:53 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBRequest> mRequest;
|
|
|
|
RefPtr<IDBObjectStore> mSourceObjectStore;
|
|
|
|
RefPtr<IDBIndex> mSourceIndex;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
// These are cycle-collected!
|
|
|
|
JS::Heap<JS::Value> mCachedKey;
|
|
|
|
JS::Heap<JS::Value> mCachedPrimaryKey;
|
|
|
|
JS::Heap<JS::Value> mCachedValue;
|
|
|
|
|
|
|
|
Key mKey;
|
2015-09-04 19:12:29 +00:00
|
|
|
Key mSortKey;
|
2014-09-26 23:21:57 +00: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> Create(
|
2016-02-16 21:46:08 +00:00
|
|
|
indexedDB::BackgroundCursorChild* aBackgroundActor, const Key& aKey,
|
2014-09-26 23:21:57 +00:00
|
|
|
StructuredCloneReadInfo&& aCloneInfo);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
static already_AddRefed<IDBCursor> Create(
|
2016-02-16 21:46:08 +00:00
|
|
|
indexedDB::BackgroundCursorChild* aBackgroundActor, const Key& aKey);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
static already_AddRefed<IDBCursor> Create(
|
2016-02-16 21:46:08 +00:00
|
|
|
indexedDB::BackgroundCursorChild* aBackgroundActor, const Key& aKey,
|
2014-09-26 23:21:57 +00:00
|
|
|
const Key& aSortKey, const Key& aPrimaryKey,
|
|
|
|
StructuredCloneReadInfo&& aCloneInfo);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
static already_AddRefed<IDBCursor> Create(
|
2016-02-16 21:46:08 +00:00
|
|
|
indexedDB::BackgroundCursorChild* aBackgroundActor, const Key& aKey,
|
2014-09-26 23:21:57 +00:00
|
|
|
const Key& aSortKey, const Key& aPrimaryKey);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2013-07-31 15:48:36 +00:00
|
|
|
static Direction ConvertDirection(IDBCursorDirection aDirection);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2013-07-31 22:28:13 +00:00
|
|
|
|
2019-03-29 18:05:11 +00:00
|
|
|
nsIGlobalObject* GetParentObject() const;
|
2013-07-31 22:28:13 +00:00
|
|
|
|
2013-09-17 15:16:02 +00:00
|
|
|
void GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const;
|
2013-07-31 22:28:13 +00:00
|
|
|
|
|
|
|
IDBCursorDirection GetDirection() const;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void 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-09-26 23:21:57 +00:00
|
|
|
void 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-26 23:21:57 +00:00
|
|
|
void 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
|
|
|
|
2016-07-26 07:26:50 +00:00
|
|
|
void ContinuePrimaryKey(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
JS::Handle<JS::Value> aPrimaryKey, ErrorResult& aRv);
|
|
|
|
|
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-09-26 23:21:57 +00:00
|
|
|
void 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
|
|
|
|
2015-09-04 19:12:29 +00:00
|
|
|
void Reset(Key&& aKey, Key&& aSortKey, Key&& aPrimaryKey,
|
|
|
|
StructuredCloneReadInfo&& aValue);
|
2010-11-10 23:26:03 +00:00
|
|
|
|
2015-09-04 19:12:29 +00:00
|
|
|
void Reset(Key&& aKey, Key&& aSortKey, 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
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* 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:
|
2016-02-16 21:46:08 +00:00
|
|
|
IDBCursor(Type aType, indexedDB::BackgroundCursorChild* aBackgroundActor,
|
2014-09-26 23:21:57 +00:00
|
|
|
const Key& aKey);
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
~IDBCursor();
|
|
|
|
|
2015-09-04 19:12:29 +00:00
|
|
|
// Checks if this is a locale aware cursor (ie. the index's sortKey is unset)
|
|
|
|
bool IsLocaleAware() const;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
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 dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
#endif // mozilla_dom_idbcursor_h__
|