2010-06-23 19:46:08 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=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
|
|
|
|
2010-06-28 18:51:06 +00:00
|
|
|
#ifndef mozilla_dom_indexeddb_idbindex_h__
|
|
|
|
#define mozilla_dom_indexeddb_idbindex_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:40 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/dom/IDBCursorBinding.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 "nsTArrayForwardDeclare.h"
|
2013-07-31 15:48:40 +00:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
2014-09-17 23:36:01 +00:00
|
|
|
class nsPIDOMWindow;
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
template <typename> class Sequence;
|
|
|
|
|
|
|
|
namespace indexedDB {
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2010-06-28 18:51:06 +00:00
|
|
|
class IDBObjectStore;
|
2012-06-01 17:21:12 +00:00
|
|
|
class IDBRequest;
|
2014-09-26 23:21:57 +00:00
|
|
|
class IndexMetadata;
|
2012-06-01 17:21:12 +00:00
|
|
|
class Key;
|
2014-09-26 23:21:57 +00:00
|
|
|
class KeyPath;
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class IDBIndex MOZ_FINAL
|
|
|
|
: public nsISupports
|
|
|
|
, public nsWrapperCache
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
nsRefPtr<IDBObjectStore> mObjectStore;
|
|
|
|
|
|
|
|
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.
|
|
|
|
const IndexMetadata* mMetadata;
|
|
|
|
nsAutoPtr<IndexMetadata> mDeletedMetadata;
|
|
|
|
|
|
|
|
const int64_t mId;
|
|
|
|
bool mRooted;
|
|
|
|
|
2010-06-23 19:46:08 +00:00
|
|
|
public:
|
2010-11-10 23:26:03 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2012-06-22 21:00:53 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBIndex)
|
2010-09-09 22:15:38 +00:00
|
|
|
|
2010-06-28 18:51:06 +00:00
|
|
|
static already_AddRefed<IDBIndex>
|
2014-09-26 23:21:57 +00:00
|
|
|
Create(IDBObjectStore* aObjectStore, const IndexMetadata& aMetadata);
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
int64_t
|
|
|
|
Id() const
|
2010-06-23 19:46:08 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2010-10-19 17:58:52 +00:00
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
const nsString&
|
|
|
|
Name() const;
|
2011-12-04 17:39:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool
|
|
|
|
Unique() const;
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool
|
|
|
|
MultiEntry() const;
|
2010-10-19 17:58:52 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
const KeyPath&
|
|
|
|
GetKeyPath() const;
|
|
|
|
|
|
|
|
IDBObjectStore*
|
|
|
|
ObjectStore() const
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return mObjectStore;
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const;
|
|
|
|
|
2012-06-01 17:21:12 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
GetName(nsString& aName) const
|
2012-06-01 17:21:12 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
aName = Name();
|
2012-06-01 17:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
GetKeyPath(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
OpenCursor(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection,
|
|
|
|
ErrorResult& aRv)
|
2014-09-13 16:12:19 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return OpenCursorInternal(/* aKeysOnly */ false, aCx, aRange, aDirection,
|
|
|
|
aRv);
|
2014-09-13 16:12:19 +00:00
|
|
|
}
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2013-07-31 15:48:40 +00:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
OpenKeyCursor(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aRange,
|
|
|
|
IDBCursorDirection aDirection,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return OpenCursorInternal(/* aKeysOnly */ true, aCx, aRange, aDirection,
|
|
|
|
aRv);
|
|
|
|
}
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2013-07-31 15:48:40 +00:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
Get(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return GetInternal(/* aKeyOnly */ false, aCx, aKey, aRv);
|
|
|
|
}
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2013-07-31 15:48:40 +00:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
GetKey(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return GetInternal(/* aKeyOnly */ true, aCx, aKey, aRv);
|
|
|
|
}
|
2013-07-31 15:48:40 +00:00
|
|
|
|
2014-09-13 16:12:19 +00:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
Count(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv);
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
GetAll(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit, ErrorResult& aRv)
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
2013-07-31 15:48:40 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return GetAllInternal(/* aKeysOnly */ false, aCx, aKey, aLimit, aRv);
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
GetAllKeys(JSContext* aCx, JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit, ErrorResult& aRv)
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return GetAllInternal(/* aKeysOnly */ true, aCx, aKey, aLimit, aRv);
|
2013-07-31 15:48:40 +00:00
|
|
|
}
|
|
|
|
|
2014-06-11 20:26:52 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
RefreshMetadata(bool aMayDelete);
|
2013-07-31 15:48:40 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
NoteDeletion();
|
2013-07-31 15:48:40 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
2013-07-31 15:48:40 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-07-31 15:48:40 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
private:
|
|
|
|
IDBIndex(IDBObjectStore* aObjectStore, const IndexMetadata* aMetadata);
|
2013-07-31 15:48:40 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
~IDBIndex();
|
2013-07-31 15:48:40 +00:00
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
GetInternal(bool aKeyOnly,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv);
|
2013-07-31 15:48:40 +00:00
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
GetAllInternal(bool aKeysOnly,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
|
|
|
ErrorResult& aRv);
|
2014-09-17 23:36:01 +00:00
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
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 indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2010-06-28 18:51:06 +00:00
|
|
|
#endif // mozilla_dom_indexeddb_idbindex_h__
|