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
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
class nsIDOMBlob;
|
2010-11-11 02:26:03 +03:00
|
|
|
class nsIScriptContext;
|
|
|
|
class nsPIDOMWindow;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class ContentParent;
|
|
|
|
class PBlobChild;
|
|
|
|
class PBlobParent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
class AsyncConnectionHelper;
|
2012-08-02 10:02:29 +04:00
|
|
|
class FileManager;
|
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;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-01-11 17:32:20 +04:00
|
|
|
struct FileHandleData;
|
|
|
|
struct BlobOrFileData;
|
|
|
|
|
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
|
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,
|
|
|
|
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,
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t aObjectStoreId,
|
2010-06-23 23:46:08 +04:00
|
|
|
const Key& aObjectStoreKey,
|
|
|
|
bool aOverwrite,
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t aObjectDataId,
|
2010-06-23 23:46:08 +04:00
|
|
|
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,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aDataIndex,
|
|
|
|
uint32_t 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
|
2012-10-03 23:05:20 +04:00
|
|
|
ClearCloneReadInfo(StructuredCloneReadInfo& aReadInfo);
|
|
|
|
|
|
|
|
static void
|
|
|
|
ClearCloneWriteInfo(StructuredCloneWriteInfo& aWriteInfo);
|
2010-12-21 19:02:04 +03:00
|
|
|
|
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);
|
|
|
|
|
2013-01-11 17:32:20 +04:00
|
|
|
template <class DeserializationTraits>
|
2011-12-16 11:34:24 +04:00
|
|
|
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,
|
2012-08-22 19:56:38 +04:00
|
|
|
nsTArray<int64_t>& aResult);
|
2011-06-09 06:21:53 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
// Called only in the main process.
|
|
|
|
static nsresult
|
|
|
|
ConvertBlobsToActors(ContentParent* aContentParent,
|
|
|
|
FileManager* aFileManager,
|
|
|
|
const nsTArray<StructuredCloneFile>& aFiles,
|
|
|
|
InfallibleTArray<PBlobParent*>& aActors);
|
|
|
|
|
|
|
|
// Called only in the child process.
|
|
|
|
static void
|
|
|
|
ConvertActorsToBlobs(const InfallibleTArray<PBlobChild*>& aActors,
|
|
|
|
nsTArray<StructuredCloneFile>& aFiles);
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t Id() const
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2012-09-28 23:55:23 +04:00
|
|
|
NS_ASSERTION(mId != INT64_MIN, "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,
|
2012-08-02 10:02:29 +04:00
|
|
|
const nsTArray<nsCOMPtr<nsIDOMBlob> >& aBlobs,
|
2012-06-01 21:21:12 +04:00
|
|
|
bool aOverwrite,
|
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult GetInternal(IDBKeyRange* aKeyRange,
|
2012-06-29 20:48:34 +04:00
|
|
|
JSContext* aCx,
|
2012-06-01 21:21:12 +04:00
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult GetAllInternal(IDBKeyRange* aKeyRange,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLimit,
|
2012-06-29 20:48:34 +04:00
|
|
|
JSContext* aCx,
|
2012-06-01 21:21:12 +04:00
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult DeleteInternal(IDBKeyRange* aKeyRange,
|
2012-06-29 20:48:34 +04:00
|
|
|
JSContext* aCx,
|
2012-06-01 21:21:12 +04:00
|
|
|
IDBRequest** _retval);
|
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
nsresult ClearInternal(JSContext* aCx,
|
|
|
|
IDBRequest** _retval);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
nsresult CountInternal(IDBKeyRange* aKeyRange,
|
2012-06-29 20:48:34 +04:00
|
|
|
JSContext* aCx,
|
2012-06-01 21:21:12 +04:00
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult OpenCursorInternal(IDBKeyRange* aKeyRange,
|
|
|
|
size_t aDirection,
|
2012-06-29 20:48:34 +04:00
|
|
|
JSContext* aCx,
|
2012-06-01 21:21:12 +04:00
|
|
|
IDBRequest** _retval);
|
|
|
|
|
|
|
|
nsresult OpenCursorFromChildProcess(
|
|
|
|
IDBRequest* aRequest,
|
|
|
|
size_t aDirection,
|
|
|
|
const Key& aKey,
|
|
|
|
const SerializedStructuredCloneReadInfo& aCloneInfo,
|
2012-08-02 10:02:29 +04:00
|
|
|
nsTArray<StructuredCloneFile>& aBlobs,
|
2012-06-01 21:21:12 +04:00
|
|
|
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,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aOptionalArgCount,
|
2012-06-01 21:21:12 +04:00
|
|
|
bool aOverwrite,
|
|
|
|
IDBRequest** _retval);
|
2010-12-16 00:21:07 +03:00
|
|
|
|
2012-10-03 23:05:20 +04:00
|
|
|
static void
|
|
|
|
ClearStructuredCloneBuffer(JSAutoStructuredCloneBuffer& aBuffer);
|
|
|
|
|
2013-01-11 17:32:20 +04:00
|
|
|
static bool
|
|
|
|
ReadFileHandle(JSStructuredCloneReader* aReader,
|
|
|
|
FileHandleData* aRetval);
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ReadBlobOrFile(JSStructuredCloneReader* aReader,
|
|
|
|
uint32_t aTag,
|
|
|
|
BlobOrFileData* aRetval);
|
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
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mId;
|
2010-06-23 23:46:08 +04:00
|
|
|
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-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__
|