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_idbobjectstore_h__
|
|
|
|
#define mozilla_dom_indexeddb_idbobjectstore_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:36 -07:00
|
|
|
#include "mozilla/dom/IDBCursorBinding.h"
|
|
|
|
#include "mozilla/dom/IDBIndexBinding.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 "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2012-01-24 02:03:37 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
struct JSClass;
|
2010-11-10 15:26:03 -08:00
|
|
|
class nsPIDOMWindow;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
namespace mozilla {
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
namespace dom {
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
class DOMStringList;
|
2014-06-10 22:44:08 -07:00
|
|
|
class nsIContentParent;
|
2014-09-26 16:21:57 -07:00
|
|
|
template <typename> class Sequence;
|
2012-08-01 23:02:29 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
namespace indexedDB {
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
class FileManager;
|
2012-06-01 10:21:12 -07:00
|
|
|
class IDBKeyRange;
|
2012-06-19 18:50:39 -07:00
|
|
|
class IDBRequest;
|
2014-09-26 16:21:57 -07:00
|
|
|
class IDBTransaction;
|
|
|
|
class IndexUpdateInfo;
|
2011-11-03 08:57:30 -07:00
|
|
|
class Key;
|
2014-09-26 16:21:57 -07:00
|
|
|
class KeyPath;
|
|
|
|
class ObjectStoreSpec;
|
|
|
|
struct StructuredCloneFile;
|
|
|
|
struct StructuredCloneReadInfo;
|
|
|
|
|
|
|
|
class IDBObjectStore MOZ_FINAL
|
|
|
|
: public nsISupports
|
|
|
|
, public nsWrapperCache
|
|
|
|
{
|
|
|
|
static const JSClass sDummyPropJSClass;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsRefPtr<IDBTransaction> mTransaction;
|
|
|
|
JS::Heap<JS::Value> mCachedKeyPath;
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07: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;
|
|
|
|
|
|
|
|
nsTArray<nsRefPtr<IDBIndex>> mIndexes;
|
|
|
|
|
|
|
|
const int64_t mId;
|
|
|
|
bool mRooted;
|
2013-01-11 05:32:20 -08:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
public:
|
2014-09-26 16:21:57 -07:00
|
|
|
struct StructuredCloneWriteInfo;
|
2010-09-09 15:15:38 -07:00
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
static already_AddRefed<IDBObjectStore>
|
2014-09-26 16:21:57 -07:00
|
|
|
Create(IDBTransaction* aTransaction, const ObjectStoreSpec& aSpec);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
static nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
AppendIndexUpdateInfo(int64_t aIndexID,
|
2012-06-21 15:27:13 -07:00
|
|
|
const KeyPath& aKeyPath,
|
2011-12-04 09:39:01 -08:00
|
|
|
bool aUnique,
|
|
|
|
bool aMultiEntry,
|
|
|
|
JSContext* aCx,
|
2013-05-29 13:16:04 -07:00
|
|
|
JS::Handle<JS::Value> aObject,
|
2011-12-04 09:39:01 -08:00
|
|
|
nsTArray<IndexUpdateInfo>& aUpdateInfoArray);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-21 08:02:04 -08:00
|
|
|
static void
|
2012-10-03 12:05:20 -07:00
|
|
|
ClearCloneReadInfo(StructuredCloneReadInfo& aReadInfo);
|
|
|
|
|
2011-06-08 19:21:53 -07:00
|
|
|
static bool
|
|
|
|
DeserializeValue(JSContext* aCx,
|
2011-12-15 23:34:24 -08:00
|
|
|
StructuredCloneReadInfo& aCloneReadInfo,
|
2013-06-21 06:12:46 -07:00
|
|
|
JS::MutableHandle<JS::Value> aValue);
|
2011-06-08 19:21:53 -07:00
|
|
|
|
|
|
|
static bool
|
2014-09-26 16:21:57 -07:00
|
|
|
DeserializeIndexValue(JSContext* aCx,
|
|
|
|
StructuredCloneReadInfo& aCloneReadInfo,
|
|
|
|
JS::MutableHandle<JS::Value> aValue);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
static const JSClass*
|
|
|
|
DummyPropClass()
|
2014-09-17 16:36:01 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
return &sDummyPropJSClass;
|
2014-09-17 16:36:01 -07:00
|
|
|
}
|
2013-07-31 08:48:36 -07:00
|
|
|
|
|
|
|
void
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int64_t
|
|
|
|
Id() const
|
2014-09-17 16:36:01 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return mId;
|
2014-09-17 16:36:01 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const nsString&
|
|
|
|
Name() const;
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
bool
|
|
|
|
AutoIncrement() const;
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const KeyPath&
|
|
|
|
GetKeyPath() const;
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
bool
|
|
|
|
HasValidKeyPath() const;
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const;
|
2014-09-17 16:36:01 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
GetName(nsString& aName) const
|
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
aName = Name();
|
2013-07-31 08:48:36 -07:00
|
|
|
}
|
|
|
|
|
2014-06-11 13:26:52 -07:00
|
|
|
void
|
|
|
|
GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv);
|
2013-07-31 08:48:36 -07:00
|
|
|
|
2013-07-09 10:54:21 -07:00
|
|
|
already_AddRefed<DOMStringList>
|
2014-09-26 16:21:57 -07:00
|
|
|
IndexNames();
|
2013-07-31 08:48:36 -07:00
|
|
|
|
|
|
|
IDBTransaction*
|
|
|
|
Transaction() const
|
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2013-07-31 08:48:36 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return mTransaction;
|
2013-07-31 08:48:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 16:21:57 -07:00
|
|
|
Add(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv)
|
2013-07-31 08:48:36 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return AddOrPut(aCx, aValue, aKey, false, aRv);
|
2013-07-31 08:48:36 -07:00
|
|
|
}
|
|
|
|
|
2014-09-17 16:36:01 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 16:21:57 -07:00
|
|
|
Put(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
ErrorResult& aRv)
|
2014-09-17 16:36:01 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return AddOrPut(aCx, aValue, aKey, true, aRv);
|
2014-09-17 16:36:01 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:36 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Delete(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Get(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
Clear(ErrorResult& aRv);
|
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
already_AddRefed<IDBIndex>
|
2014-09-26 16:21:57 -07:00
|
|
|
CreateIndex(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsAString& aKeyPath,
|
|
|
|
const IDBIndexParameters& aOptionalParameters,
|
|
|
|
ErrorResult& aRv);
|
2013-07-31 08:48:36 -07:00
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
already_AddRefed<IDBIndex>
|
2014-09-26 16:21:57 -07:00
|
|
|
CreateIndex(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
2013-09-24 10:14:16 -07:00
|
|
|
const Sequence<nsString>& aKeyPath,
|
2014-09-26 16:21:57 -07:00
|
|
|
const IDBIndexParameters& aOptionalParameters,
|
|
|
|
ErrorResult& aRv);
|
2013-07-31 08:48:36 -07:00
|
|
|
|
2013-07-31 08:48:40 -07:00
|
|
|
already_AddRefed<IDBIndex>
|
2013-07-31 08:48:36 -07:00
|
|
|
Index(const nsAString& aName, ErrorResult &aRv);
|
|
|
|
|
|
|
|
void
|
|
|
|
DeleteIndex(const nsAString& aIndexName, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 16:21:57 -07:00
|
|
|
Count(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
2013-07-31 08:48:36 -07:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 16:21:57 -07:00
|
|
|
GetAll(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return GetAllInternal(/* aKeysOnly */ false, aCx, aKey, aLimit, aRv);
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-07-31 08:48:36 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
2014-09-26 16:21:57 -07:00
|
|
|
GetAllKeys(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2013-07-31 08:48:36 -07:00
|
|
|
|
2014-09-26 16:21:57 -07: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 13:21:07 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return OpenCursorInternal(/* aKeysOnly */ false, aCx, aRange, aDirection,
|
|
|
|
aRv);
|
|
|
|
}
|
2012-10-03 12:05:20 -07:00
|
|
|
|
2014-09-17 16:36:01 -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();
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return OpenCursorInternal(/* aKeysOnly */ true, aCx, aRange, aDirection,
|
|
|
|
aRv);
|
|
|
|
}
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
RefreshSpec(bool aMayDelete);
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
const ObjectStoreSpec&
|
|
|
|
Spec() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
NoteDeletion();
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBObjectStore)
|
|
|
|
|
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-01-11 05:32:20 -08:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
private:
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBObjectStore(IDBTransaction* aTransaction, const ObjectStoreSpec* aSpec);
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
~IDBObjectStore();
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsresult
|
|
|
|
GetAddInfo(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
JS::Handle<JS::Value> aKeyVal,
|
|
|
|
StructuredCloneWriteInfo& aCloneWriteInfo,
|
|
|
|
Key& aKey,
|
|
|
|
nsTArray<IndexUpdateInfo>& aUpdateInfoArray);
|
2014-09-13 09:12:19 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
AddOrPut(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
bool aOverwrite,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
GetAllInternal(bool aKeysOnly,
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aKey,
|
|
|
|
const Optional<uint32_t>& aLimit,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBIndex>
|
|
|
|
CreateIndexInternal(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
|
|
|
const KeyPath& aKeyPath,
|
|
|
|
const IDBIndexParameters& aOptionalParameters,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
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_idbobjectstore_h__
|