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_idbindex_h__
|
|
|
|
#define mozilla_dom_idbindex_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:40 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/dom/IDBCursorBinding.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 "nsTArrayForwardDeclare.h"
|
2013-07-31 19:48:40 +04:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
class nsIGlobalObject;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
class IDBObjectStore;
|
|
|
|
class IDBRequest;
|
2014-09-27 03:21:57 +04:00
|
|
|
template <typename>
|
|
|
|
class Sequence;
|
|
|
|
|
|
|
|
namespace indexedDB {
|
|
|
|
class IndexMetadata;
|
|
|
|
class KeyPath;
|
2016-02-17 00:46:08 +03:00
|
|
|
} // namespace indexedDB
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
class IDBIndex final : public nsISupports, public nsWrapperCache {
|
2019-09-11 14:51:20 +03:00
|
|
|
// TODO: This could be made const if Bug 1575173 is resolved. It is
|
|
|
|
// initialized in the constructor and never modified/cleared.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBObjectStore> mObjectStore;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
JS::Heap<JS::Value> mCachedKeyPath;
|
|
|
|
|
|
|
|
// This normally points to the IndexMetadata owned by the parent IDBDatabase
|
|
|
|
// object. However, if this index is part of a versionchange transaction and
|
|
|
|
// it gets deleted then the metadata is copied into mDeletedMetadata and
|
|
|
|
// mMetadata is set to point at mDeletedMetadata.
|
2016-02-17 00:46:08 +03:00
|
|
|
const indexedDB::IndexMetadata* mMetadata;
|
|
|
|
nsAutoPtr<indexedDB::IndexMetadata> mDeletedMetadata;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
const int64_t mId;
|
|
|
|
bool mRooted;
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
public:
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2012-06-23 01:00:53 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBIndex)
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2019-12-16 16:17:33 +03:00
|
|
|
static MOZ_MUST_USE RefPtr<IDBIndex> Create(
|
2016-02-17 00:46:08 +03:00
|
|
|
IDBObjectStore* aObjectStore, const indexedDB::IndexMetadata& aMetadata);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
int64_t Id() const {
|
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsString& Name() const;
|
2011-12-04 21:39:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool Unique() const;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool MultiEntry() const;
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2015-09-04 22:12:29 +03:00
|
|
|
bool LocaleAware() const;
|
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
const indexedDB::KeyPath& GetKeyPath() const;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-09-04 22:12:29 +03:00
|
|
|
void GetLocale(nsString& aLocale) const;
|
|
|
|
|
|
|
|
const nsCString& Locale() const;
|
|
|
|
|
|
|
|
bool IsAutoLocale() const;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBObjectStore* ObjectStore() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return mObjectStore;
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
nsIGlobalObject* GetParentObject() const;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
void GetName(nsString& aName) const { aName = Name(); }
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2016-03-30 06:04:56 +03:00
|
|
|
void SetName(const nsAString& aName, ErrorResult& aRv);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-12-16 16:17:33 +03:00
|
|
|
MOZ_MUST_USE RefPtr<IDBRequest> OpenCursor(JSContext* aCx,
|
2014-09-27 03:21:57 +04:00
|
|
|
JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection,
|
2019-12-16 16:17:33 +03:00
|
|
|
ErrorResult& aRv);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-12-16 16:17:33 +03:00
|
|
|
MOZ_MUST_USE RefPtr<IDBRequest> OpenKeyCursor(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection,
|
|
|
|
ErrorResult& aRv);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-12-16 16:17:33 +03:00
|
|
|
MOZ_MUST_USE RefPtr<IDBRequest> Get(JSContext* aCx,
|
2014-09-27 03:21:57 +04:00
|
|
|
JS::Handle<JS::Value> aKey,
|
2019-12-16 16:17:33 +03:00
|
|
|
ErrorResult& aRv);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2019-12-16 16:17:33 +03:00
|
|
|
MOZ_MUST_USE RefPtr<IDBRequest> GetKey(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv);
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2019-12-16 16:17:33 +03:00
|
|
|
MOZ_MUST_USE RefPtr<IDBRequest> Count(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2019-12-16 16:17:33 +03:00
|
|
|
MOZ_MUST_USE RefPtr<IDBRequest> GetAll(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
|
|
|
ErrorResult& aRv);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-12-16 16:17:33 +03:00
|
|
|
MOZ_MUST_USE RefPtr<IDBRequest> GetAllKeys(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
|
|
|
ErrorResult& aRv);
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void RefreshMetadata(bool aMayDelete);
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void NoteDeletion();
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2015-07-02 20:47:53 +03:00
|
|
|
bool IsDeleted() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return !!mDeletedMetadata;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// nsWrapperCache
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
private:
|
2016-02-17 00:46:08 +03:00
|
|
|
IDBIndex(IDBObjectStore* aObjectStore,
|
|
|
|
const indexedDB::IndexMetadata* aMetadata);
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
~IDBIndex();
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2019-12-16 16:17:33 +03:00
|
|
|
MOZ_MUST_USE RefPtr<IDBRequest> GetInternal(bool aKeyOnly, JSContext* aCx,
|
2014-09-27 03:21:57 +04:00
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-12-16 16:17:33 +03:00
|
|
|
MOZ_MUST_USE RefPtr<IDBRequest> GetAllInternal(
|
|
|
|
bool aKeysOnly, JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit, ErrorResult& aRv);
|
|
|
|
|
|
|
|
MOZ_MUST_USE RefPtr<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_idbindex_h__
|