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_idbobjectstore_h__
|
|
|
|
#define mozilla_dom_idbobjectstore_h__
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "js/RootingAPI.h"
|
2013-07-31 19:48:36 +04:00
|
|
|
#include "mozilla/dom/IDBCursorBinding.h"
|
|
|
|
#include "mozilla/dom/IDBIndexBinding.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2010-11-11 02:26:03 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2012-01-24 14:03:37 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
struct JSClass;
|
2019-03-29 21:05:11 +03:00
|
|
|
class nsIGlobalObject;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
namespace mozilla {
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
namespace dom {
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
class DOMStringList;
|
2014-10-16 08:56:52 +04:00
|
|
|
class IDBCursor;
|
2012-06-20 05:50:39 +04:00
|
|
|
class IDBRequest;
|
2014-09-27 03:21:57 +04:00
|
|
|
class IDBTransaction;
|
2016-04-29 05:56:02 +03:00
|
|
|
class StringOrStringSequence;
|
2016-02-17 00:46:08 +03:00
|
|
|
template <typename>
|
|
|
|
class Sequence;
|
|
|
|
|
|
|
|
namespace indexedDB {
|
2011-11-03 19:57:30 +04:00
|
|
|
class Key;
|
2014-09-27 03:21:57 +04:00
|
|
|
class KeyPath;
|
2016-02-17 00:46:08 +03:00
|
|
|
class IndexUpdateInfo;
|
2014-09-27 03:21:57 +04:00
|
|
|
class ObjectStoreSpec;
|
|
|
|
struct StructuredCloneReadInfo;
|
2016-02-17 00:46:08 +03:00
|
|
|
} // namespace indexedDB
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class IDBObjectStore final : public nsISupports, public nsWrapperCache {
|
2016-02-17 00:46:08 +03:00
|
|
|
typedef indexedDB::IndexUpdateInfo IndexUpdateInfo;
|
|
|
|
typedef indexedDB::Key Key;
|
|
|
|
typedef indexedDB::KeyPath KeyPath;
|
|
|
|
typedef indexedDB::ObjectStoreSpec ObjectStoreSpec;
|
|
|
|
typedef indexedDB::StructuredCloneReadInfo StructuredCloneReadInfo;
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
// For AddOrPut() and DeleteInternal().
|
2016-02-17 00:46:08 +03:00
|
|
|
friend class IDBCursor;
|
2014-10-16 08:56:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
static const JSClass sDummyPropJSClass;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBTransaction> mTransaction;
|
2014-09-27 03:21:57 +04:00
|
|
|
JS::Heap<JS::Value> mCachedKeyPath;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// This normally points to the ObjectStoreSpec owned by the parent IDBDatabase
|
|
|
|
// object. However, if this objectStore is part of a versionchange transaction
|
|
|
|
// and it gets deleted then the spec is copied into mDeletedSpec and mSpec is
|
|
|
|
// set to point at mDeletedSpec.
|
|
|
|
const ObjectStoreSpec* mSpec;
|
|
|
|
nsAutoPtr<ObjectStoreSpec> mDeletedSpec;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<IDBIndex>> mIndexes;
|
2016-09-13 01:38:43 +03:00
|
|
|
nsTArray<RefPtr<IDBIndex>> mDeletedIndexes;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
const int64_t mId;
|
|
|
|
bool mRooted;
|
2013-01-11 17:32:20 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
public:
|
2014-09-27 03:21:57 +04:00
|
|
|
struct StructuredCloneWriteInfo;
|
2018-07-24 19:19:10 +03:00
|
|
|
struct StructuredCloneInfo;
|
|
|
|
|
|
|
|
class MOZ_STACK_CLASS ValueWrapper final {
|
|
|
|
JS::Rooted<JS::Value> mValue;
|
|
|
|
bool mCloned;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ValueWrapper(JSContext* aCx, JS::Handle<JS::Value> aValue)
|
|
|
|
: mValue(aCx, aValue), mCloned(false) {
|
|
|
|
MOZ_COUNT_CTOR(IDBObjectStore::ValueWrapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
~ValueWrapper() { MOZ_COUNT_DTOR(IDBObjectStore::ValueWrapper); }
|
|
|
|
|
|
|
|
const JS::Rooted<JS::Value>& Value() const { return mValue; }
|
|
|
|
|
|
|
|
bool Clone(JSContext* aCx);
|
|
|
|
};
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
static already_AddRefed<IDBObjectStore> Create(IDBTransaction* aTransaction,
|
|
|
|
const ObjectStoreSpec& aSpec);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-04-26 19:53:59 +03:00
|
|
|
static void AppendIndexUpdateInfo(int64_t aIndexID, const KeyPath& aKeyPath,
|
|
|
|
bool aUnique, bool aMultiEntry,
|
|
|
|
const nsCString& aLocale, JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aVal,
|
|
|
|
nsTArray<IndexUpdateInfo>& aUpdateInfoArray,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
static void DeserializeIndexValueToUpdateInfos(
|
2012-06-22 02:27:13 +04:00
|
|
|
int64_t aIndexID, const KeyPath& aKeyPath, bool aUnique, bool aMultiEntry,
|
2019-04-26 19:53:59 +03:00
|
|
|
const nsCString& aLocale, StructuredCloneReadInfo& aCloneReadInfo,
|
|
|
|
nsTArray<IndexUpdateInfo>& aUpdateInfoArray, ErrorResult& aRv);
|
2013-07-31 19:48:36 +04:00
|
|
|
|
|
|
|
static void ClearCloneReadInfo(StructuredCloneReadInfo& aReadInfo);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-06-09 06:21:53 +04:00
|
|
|
static bool DeserializeValue(JSContext* aCx,
|
2011-12-16 11:34:24 +04:00
|
|
|
StructuredCloneReadInfo& aCloneReadInfo,
|
2013-06-21 17:12:46 +04:00
|
|
|
JS::MutableHandle<JS::Value> aValue);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-18 15:19:06 +03:00
|
|
|
static nsresult DeserializeUpgradeValueToFileIds(
|
2012-10-03 23:05:20 +04:00
|
|
|
StructuredCloneReadInfo& aCloneReadInfo, nsAString& aFileIds);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
static const JSClass* DummyPropClass() { return &sDummyPropJSClass; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int64_t Id() const {
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mId;
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsString& Name() const;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool AutoIncrement() const;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const KeyPath& GetKeyPath() const;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool HasValidKeyPath() const;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
nsIGlobalObject* GetParentObject() const;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
|
|
|
void GetName(nsString& aName) const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
aName = Name();
|
2013-07-31 19:48:36 +04:00
|
|
|
}
|
|
|
|
|
2016-03-30 06:04:56 +03:00
|
|
|
void SetName(const nsAString& aName, ErrorResult& aRv);
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2013-07-31 19:48:36 +04:00
|
|
|
|
2013-07-09 21:54:21 +04:00
|
|
|
already_AddRefed<DOMStringList> IndexNames();
|
2013-07-31 19:48:36 +04:00
|
|
|
|
|
|
|
IDBTransaction* Transaction() const {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2013-07-31 19:48:36 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mTransaction;
|
2013-07-31 19:48:36 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest> Add(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2018-07-24 19:19:10 +03:00
|
|
|
ValueWrapper valueWrapper(aCx, aValue);
|
|
|
|
|
|
|
|
return AddOrPut(aCx, valueWrapper, aKey, false, /* aFromCursor */ false,
|
|
|
|
aRv);
|
2013-07-31 19:48:36 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest> Put(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2018-07-24 19:19:10 +03:00
|
|
|
ValueWrapper valueWrapper(aCx, aValue);
|
|
|
|
|
|
|
|
return AddOrPut(aCx, valueWrapper, aKey, true, /* aFromCursor */ false,
|
|
|
|
aRv);
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
already_AddRefed<IDBRequest> Delete(JSContext* aCx,
|
2014-10-16 08:56:52 +04:00
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return DeleteInternal(aCx, aKey, /* aFromCursor */ false, aRv);
|
|
|
|
}
|
2013-07-31 19:48:36 +04:00
|
|
|
|
|
|
|
already_AddRefed<IDBRequest> Get(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
2016-07-21 11:31:59 +03:00
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return GetInternal(/* aKeyOnly */ false, aCx, aKey, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest> GetKey(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return GetInternal(/* aKeyOnly */ true, aCx, aKey, aRv);
|
|
|
|
}
|
2013-07-31 19:48:36 +04:00
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
already_AddRefed<IDBRequest> Clear(JSContext* aCx, ErrorResult& aRv);
|
2013-07-31 19:48:36 +04:00
|
|
|
|
2013-07-31 19:48:40 +04:00
|
|
|
already_AddRefed<IDBIndex> CreateIndex(
|
2016-04-29 05:56:02 +03:00
|
|
|
const nsAString& aName, const StringOrStringSequence& aKeyPath,
|
2014-09-27 03:21:57 +04:00
|
|
|
const IDBIndexParameters& aOptionalParameters, ErrorResult& aRv);
|
2013-07-31 19:48:36 +04:00
|
|
|
|
|
|
|
already_AddRefed<IDBIndex> Index(const nsAString& aName, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void DeleteIndex(const nsAString& aIndexName, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest> Count(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest> GetAll(JSContext* aCx,
|
2014-09-27 03:21:57 +04:00
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return GetAllInternal(/* aKeysOnly */ false, aCx, aKey, aLimit, aRv);
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
already_AddRefed<IDBRequest> GetAllKeys(JSContext* aCx,
|
2014-09-27 03:21:57 +04:00
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
2013-07-31 19:48:36 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return GetAllInternal(/* aKeysOnly */ true, aCx, aKey, aLimit, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest> OpenCursor(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
2010-12-16 00:21:07 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return OpenCursorInternal(/* aKeysOnly */ false, aCx, aRange, aDirection,
|
|
|
|
aRv);
|
|
|
|
}
|
2012-10-03 23:05:20 +04:00
|
|
|
|
2016-03-18 06:23:55 +03:00
|
|
|
already_AddRefed<IDBRequest> OpenCursor(JSContext* aCx,
|
2016-03-30 14:03:03 +03:00
|
|
|
IDBCursorDirection aDirection,
|
2016-03-18 06:23:55 +03:00
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2016-03-30 14:03:03 +03:00
|
|
|
return OpenCursorInternal(/* aKeysOnly */ false, aCx,
|
2016-03-18 06:23:55 +03:00
|
|
|
JS::UndefinedHandleValue, aDirection, aRv);
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest> OpenKeyCursor(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return OpenCursorInternal(/* aKeysOnly */ true, aCx, aRange, aDirection,
|
|
|
|
aRv);
|
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void RefreshSpec(bool aMayDelete);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const ObjectStoreSpec& Spec() const;
|
|
|
|
|
|
|
|
void NoteDeletion();
|
|
|
|
|
2015-07-02 20:47:53 +03:00
|
|
|
bool IsDeleted() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return !!mDeletedSpec;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBObjectStore)
|
|
|
|
|
|
|
|
// nsWrapperCache
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-01-11 17:32:20 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
private:
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBObjectStore(IDBTransaction* aTransaction, const ObjectStoreSpec* aSpec);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
~IDBObjectStore();
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2019-04-26 19:53:59 +03:00
|
|
|
void GetAddInfo(JSContext* aCx, ValueWrapper& aValueWrapper,
|
|
|
|
JS::Handle<JS::Value> aKeyVal,
|
|
|
|
StructuredCloneWriteInfo& aCloneWriteInfo, Key& aKey,
|
|
|
|
nsTArray<IndexUpdateInfo>& aUpdateInfoArray,
|
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest> AddOrPut(JSContext* aCx,
|
2018-07-24 19:19:10 +03:00
|
|
|
ValueWrapper& aValueWrapper,
|
2014-09-27 03:21:57 +04:00
|
|
|
JS::Handle<JS::Value> aKey,
|
2014-10-16 08:56:52 +04:00
|
|
|
bool aOverwrite, bool aFromCursor,
|
2014-09-27 03:21:57 +04:00
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
already_AddRefed<IDBRequest> DeleteInternal(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
bool aFromCursor,
|
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-21 11:31:59 +03:00
|
|
|
already_AddRefed<IDBRequest> GetInternal(bool aKeyOnly, JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest> GetAllInternal(bool aKeysOnly, JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest> OpenCursorInternal(bool aKeysOnly,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection,
|
|
|
|
ErrorResult& aRv);
|
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_idbobjectstore_h__
|