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