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