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
|
|
|
|
2010-09-10 02:15:38 +04:00
|
|
|
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "nsIIDBObjectStore.h"
|
2010-10-19 21:58:52 +04:00
|
|
|
#include "nsIIDBTransaction.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
#include "mozilla/dom/indexedDB/IDBTransaction.h"
|
2012-06-22 02:27:13 +04:00
|
|
|
#include "mozilla/dom/indexedDB/KeyPath.h"
|
2012-01-24 14:03:37 +04:00
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
class nsIScriptContext;
|
|
|
|
class nsPIDOMWindow;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
class AsyncConnectionHelper;
|
2012-06-01 21:21:12 +04:00
|
|
|
class IDBCursor;
|
|
|
|
class IDBKeyRange;
|
2012-06-20 05:50:39 +04:00
|
|
|
class IDBRequest;
|
2012-06-01 21:21:12 +04:00
|
|
|
class IndexedDBObjectStoreChild;
|
|
|
|
class IndexedDBObjectStoreParent;
|
2011-11-03 19:57:30 +04:00
|
|
|
class Key;
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
struct IndexInfo;
|
|
|
|
struct IndexUpdateInfo;
|
2012-06-01 21:21:12 +04:00
|
|
|
struct ObjectStoreInfo;
|
2011-12-16 11:34:24 +04:00
|
|
|
struct StructuredCloneReadInfo;
|
|
|
|
struct StructuredCloneWriteInfo;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-05-15 08:50:29 +04:00
|
|
|
class IDBObjectStore MOZ_FINAL : public nsIIDBObjectStore
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2010-06-23 23:46:08 +04:00
|
|
|
NS_DECL_NSIIDBOBJECTSTORE
|
|
|
|
|
2012-06-23 01:00:53 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBObjectStore)
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
static already_AddRefed<IDBObjectStore>
|
2010-09-10 02:15:38 +04:00
|
|
|
Create(IDBTransaction* aTransaction,
|
2011-12-17 04:40:47 +04:00
|
|
|
ObjectStoreInfo* aInfo,
|
2012-06-01 21:21:12 +04:00
|
|
|
nsIAtom* aDatabaseId,
|
|
|
|
bool aCreating);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
static nsresult
|
2011-12-04 21:39:01 +04:00
|
|
|
AppendIndexUpdateInfo(PRInt64 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,
|
|
|
|
jsval aObject,
|
|
|
|
nsTArray<IndexUpdateInfo>& aUpdateInfoArray);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
static nsresult
|
2010-06-28 20:46:21 +04:00
|
|
|
UpdateIndexes(IDBTransaction* aTransaction,
|
2010-06-23 23:46:08 +04:00
|
|
|
PRInt64 aObjectStoreId,
|
|
|
|
const Key& aObjectStoreKey,
|
|
|
|
bool aOverwrite,
|
|
|
|
PRInt64 aObjectDataId,
|
|
|
|
const nsTArray<IndexUpdateInfo>& aUpdateInfoArray);
|
|
|
|
|
2010-12-21 19:02:04 +03:00
|
|
|
static nsresult
|
2011-12-16 11:34:24 +04:00
|
|
|
GetStructuredCloneReadInfoFromStatement(mozIStorageStatement* aStatement,
|
|
|
|
PRUint32 aDataIndex,
|
|
|
|
PRUint32 aFileIdsIndex,
|
2012-06-03 20:33:52 +04:00
|
|
|
IDBDatabase* aDatabase,
|
2011-12-16 11:34:24 +04:00
|
|
|
StructuredCloneReadInfo& aInfo);
|
2010-12-21 19:02:04 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
ClearStructuredCloneBuffer(JSAutoStructuredCloneBuffer& aBuffer);
|
|
|
|
|
2011-06-09 06:21:53 +04:00
|
|
|
static bool
|
|
|
|
DeserializeValue(JSContext* aCx,
|
2011-12-16 11:34:24 +04:00
|
|
|
StructuredCloneReadInfo& aCloneReadInfo,
|
|
|
|
jsval* aValue);
|
2011-06-09 06:21:53 +04:00
|
|
|
|
|
|
|
static bool
|
|
|
|
SerializeValue(JSContext* aCx,
|
2011-12-16 11:34:24 +04:00
|
|
|
StructuredCloneWriteInfo& aCloneWriteInfo,
|
|
|
|
jsval aValue);
|
|
|
|
|
|
|
|
static JSObject*
|
|
|
|
StructuredCloneReadCallback(JSContext* aCx,
|
|
|
|
JSStructuredCloneReader* aReader,
|
2011-12-16 18:42:09 +04:00
|
|
|
uint32_t aTag,
|
|
|
|
uint32_t aData,
|
2011-12-16 11:34:24 +04:00
|
|
|
void* aClosure);
|
|
|
|
static JSBool
|
|
|
|
StructuredCloneWriteCallback(JSContext* aCx,
|
|
|
|
JSStructuredCloneWriter* aWriter,
|
|
|
|
JSObject* aObj,
|
|
|
|
void* aClosure);
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
ConvertFileIdsToArray(const nsAString& aFileIds,
|
|
|
|
nsTArray<PRInt64>& aResult);
|
2011-06-09 06:21:53 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
const nsString& Name() const
|
|
|
|
{
|
|
|
|
return mName;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
bool IsAutoIncrement() const
|
|
|
|
{
|
|
|
|
return mAutoIncrement;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsWriteAllowed() const
|
|
|
|
{
|
|
|
|
return mTransaction->IsWriteAllowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt64 Id() const
|
|
|
|
{
|
2010-10-19 21:58:52 +04:00
|
|
|
NS_ASSERTION(mId != LL_MININT, "Don't ask for this yet!");
|
2010-06-23 23:46:08 +04:00
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
2012-06-22 02:27:13 +04:00
|
|
|
const KeyPath& GetKeyPath() const
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
return mKeyPath;
|
|
|
|
}
|
|
|
|
|
2012-06-22 02:27:13 +04:00
|
|
|
const bool HasValidKeyPath() const
|
2011-12-20 14:59:07 +04:00
|
|
|
{
|
2012-06-22 02:27:13 +04:00
|
|
|
return mKeyPath.IsValid();
|
2011-12-04 21:39:01 +04:00
|
|
|
}
|
|
|
|
|
2010-06-28 20:46:21 +04:00
|
|
|
IDBTransaction* Transaction()
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
return mTransaction;
|
|
|
|
}
|
|
|
|
|
2011-12-17 04:40:47 +04:00
|
|
|
ObjectStoreInfo* Info()
|
|
|
|
{
|
|
|
|
return mInfo;
|
|
|
|
}
|
2011-06-24 18:21:21 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
void
|
|
|
|
SetActor(IndexedDBObjectStoreChild* aActorChild)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
|
|
|
|
mActorChild = aActorChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetActor(IndexedDBObjectStoreParent* aActorParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aActorParent || !mActorParent,
|
|
|
|
"Shouldn't have more than one!");
|
|
|
|
mActorParent = aActorParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexedDBObjectStoreChild*
|
|
|
|
GetActorChild() const
|
|
|
|
{
|
|
|
|
return mActorChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexedDBObjectStoreParent*
|
|
|
|
GetActorParent() const
|
|
|
|
{
|
|
|
|
return mActorParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CreateIndexInternal(const IndexInfo& aInfo,
|
|
|
|
IDBIndex** _retval);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
IndexInternal(const nsAString& aName,
|
|
|
|
IDBIndex** _retval);
|
|
|
|
|
|
|
|
nsresult AddOrPutInternal(
|
|
|
|
const SerializedStructuredCloneWriteInfo& aCloneWriteInfo,
|
|
|
|
const Key& aKey,
|
|
|
|
const InfallibleTArray<IndexUpdateInfo>& aUpdateInfoArray,
|
|
|
|
bool aOverwrite,
|
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult GetInternal(IDBKeyRange* aKeyRange,
|
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult GetAllInternal(IDBKeyRange* aKeyRange,
|
|
|
|
PRUint32 aLimit,
|
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult DeleteInternal(IDBKeyRange* aKeyRange,
|
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult ClearInternal(IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult CountInternal(IDBKeyRange* aKeyRange,
|
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult OpenCursorInternal(IDBKeyRange* aKeyRange,
|
|
|
|
size_t aDirection,
|
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult OpenCursorFromChildProcess(
|
|
|
|
IDBRequest* aRequest,
|
|
|
|
size_t aDirection,
|
|
|
|
const Key& aKey,
|
|
|
|
const SerializedStructuredCloneReadInfo& aCloneInfo,
|
|
|
|
IDBCursor** _retval);
|
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
void
|
|
|
|
SetInfo(ObjectStoreInfo* aInfo);
|
|
|
|
|
2012-06-22 02:27:13 +04:00
|
|
|
static JSClass sDummyPropJSClass;
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
protected:
|
2010-06-28 22:51:06 +04:00
|
|
|
IDBObjectStore();
|
|
|
|
~IDBObjectStore();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-29 02:22:41 +04:00
|
|
|
nsresult GetAddInfo(JSContext* aCx,
|
|
|
|
jsval aValue,
|
|
|
|
jsval aKeyVal,
|
2011-12-16 11:34:24 +04:00
|
|
|
StructuredCloneWriteInfo& aCloneWriteInfo,
|
2010-06-23 23:46:08 +04:00
|
|
|
Key& aKey,
|
2011-12-16 11:34:24 +04:00
|
|
|
nsTArray<IndexUpdateInfo>& aUpdateInfoArray);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-16 00:21:07 +03:00
|
|
|
nsresult AddOrPut(const jsval& aValue,
|
|
|
|
const jsval& aKey,
|
|
|
|
JSContext* aCx,
|
|
|
|
PRUint8 aOptionalArgCount,
|
2012-06-01 21:21:12 +04:00
|
|
|
bool aOverwrite,
|
|
|
|
IDBRequest** _retval);
|
2010-12-16 00:21:07 +03:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
private:
|
2010-06-28 20:46:21 +04:00
|
|
|
nsRefPtr<IDBTransaction> mTransaction;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
PRInt64 mId;
|
|
|
|
nsString mName;
|
2012-06-22 02:27:13 +04:00
|
|
|
KeyPath mKeyPath;
|
2012-06-23 01:00:53 +04:00
|
|
|
JS::Value mCachedKeyPath;
|
|
|
|
bool mRooted;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAutoIncrement;
|
2011-11-02 16:53:12 +04:00
|
|
|
nsCOMPtr<nsIAtom> mDatabaseId;
|
2011-12-17 04:40:47 +04:00
|
|
|
nsRefPtr<ObjectStoreInfo> mInfo;
|
2010-12-21 19:02:04 +03:00
|
|
|
PRUint32 mStructuredCloneVersion;
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2010-11-11 02:25:40 +03:00
|
|
|
nsTArray<nsRefPtr<IDBIndex> > mCreatedIndexes;
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
IndexedDBObjectStoreChild* mActorChild;
|
|
|
|
IndexedDBObjectStoreParent* mActorParent;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
#endif // mozilla_dom_indexeddb_idbobjectstore_h__
|