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