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"
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowInner;
|
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
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class IDBIndex final
|
2014-09-27 03:21:57 +04:00
|
|
|
: public nsISupports
|
|
|
|
, public nsWrapperCache
|
2014-09-18 03:36:01 +04:00
|
|
|
{
|
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
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
static already_AddRefed<IDBIndex>
|
2016-02-17 00:46:08 +03:00
|
|
|
Create(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
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
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&
|
2014-09-27 03:21:57 +04:00
|
|
|
GetKeyPath() const;
|
|
|
|
|
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
|
2014-09-18 03:36:01 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return mObjectStore;
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner*
|
2014-09-27 03:21:57 +04:00
|
|
|
GetParentObject() const;
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
GetName(nsString& aName) const
|
2012-06-01 21:21:12 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
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);
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
GetKeyPath(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
OpenCursor(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection,
|
|
|
|
ErrorResult& aRv)
|
2014-09-13 20:12:19 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return OpenCursorInternal(/* aKeysOnly */ false, aCx, aRange, aDirection,
|
|
|
|
aRv);
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2013-07-31 19:48:40 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-27 03:21:57 +04:00
|
|
|
OpenKeyCursor(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return OpenCursorInternal(/* aKeysOnly */ true, aCx, aRange, aDirection,
|
|
|
|
aRv);
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2013-07-31 19:48:40 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-27 03:21:57 +04:00
|
|
|
Get(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return GetInternal(/* aKeyOnly */ false, aCx, aKey, aRv);
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2013-07-31 19:48:40 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-27 03:21:57 +04:00
|
|
|
GetKey(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return GetInternal(/* aKeyOnly */ true, aCx, aKey, aRv);
|
|
|
|
}
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2014-09-13 20:12:19 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-27 03:21:57 +04:00
|
|
|
Count(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
GetAll(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit, ErrorResult& aRv)
|
2014-09-18 03:36:01 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2013-07-31 19:48:40 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return GetAllInternal(/* aKeysOnly */ false, aCx, aKey, aLimit, aRv);
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
GetAllKeys(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit, ErrorResult& aRv)
|
2014-09-18 03:36:01 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return GetAllInternal(/* aKeysOnly */ true, aCx, aKey, aLimit, aRv);
|
2013-07-31 19:48:40 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
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
|
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
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
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-27 03:21:57 +04:00
|
|
|
GetInternal(bool aKeyOnly,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv);
|
2013-07-31 19:48:40 +04:00
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-27 03:21:57 +04:00
|
|
|
GetAllInternal(bool aKeysOnly,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
|
|
|
ErrorResult& aRv);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-27 03:21:57 +04:00
|
|
|
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__
|