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
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "IDBCursor.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
#include "mozilla/storage.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
2011-10-03 12:11:31 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2010-11-10 15:26:03 -08:00
|
|
|
#include "nsEventDispatcher.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#include "AsyncConnectionHelper.h"
|
|
|
|
#include "IDBEvents.h"
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "IDBIndex.h"
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "IDBObjectStore.h"
|
2010-06-28 09:46:21 -07:00
|
|
|
#include "IDBTransaction.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "TransactionThreadPool.h"
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
#include "ipc/IndexedDBChild.h"
|
|
|
|
#include "ipc/IndexedDBParent.h"
|
|
|
|
|
|
|
|
#include "IndexedDatabaseInlines.h"
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
USING_INDEXEDDB_NAMESPACE
|
2012-06-10 16:44:50 -07:00
|
|
|
using namespace mozilla::dom::indexedDB::ipc;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
MOZ_STATIC_ASSERT(sizeof(size_t) >= sizeof(IDBCursor::Direction),
|
|
|
|
"Relying on conversion between size_t and "
|
|
|
|
"IDBCursor::Direction");
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
namespace {
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
class CursorHelper : public AsyncConnectionHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CursorHelper(IDBCursor* aCursor)
|
|
|
|
: AsyncConnectionHelper(aCursor->Transaction(), aCursor->Request()),
|
2012-07-30 07:20:58 -07:00
|
|
|
mCursor(aCursor), mActor(nullptr)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aCursor, "Null cursor!");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ReleaseMainThreadObjects() MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual nsresult Dispatch(nsIEventTarget* aDatabaseThread) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
PackArgumentsForParentProcess(CursorRequestParams& aParams) = 0;
|
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
UnpackResponseFromParentProcess(const ResponseValue& aResponseValue) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsRefPtr<IDBCursor> mCursor;
|
|
|
|
|
|
|
|
private:
|
|
|
|
IndexedDBCursorRequestChild* mActor;
|
|
|
|
};
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
class ContinueHelper : public CursorHelper
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-11-07 15:37:19 -08:00
|
|
|
ContinueHelper(IDBCursor* aCursor,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aCount)
|
2012-06-01 10:21:12 -07:00
|
|
|
: CursorHelper(aCursor), mCount(aCount)
|
2011-11-07 15:37:19 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aCount > 0, "Must have a count!");
|
|
|
|
}
|
2010-12-09 18:15:00 -08:00
|
|
|
|
2011-01-26 17:53:02 -08:00
|
|
|
~ContinueHelper()
|
|
|
|
{
|
2012-10-03 12:05:20 -07:00
|
|
|
IDBObjectStore::ClearCloneReadInfo(mCloneReadInfo);
|
2011-01-26 17:53:02 -08:00
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
virtual nsresult DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
MOZ_OVERRIDE;
|
2010-12-09 18:15:00 -08:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
virtual nsresult GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal) MOZ_OVERRIDE;
|
|
|
|
|
2012-10-03 12:05:20 -07:00
|
|
|
virtual void ReleaseMainThreadObjects() MOZ_OVERRIDE;
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
virtual nsresult
|
|
|
|
PackArgumentsForParentProcess(CursorRequestParams& aParams) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual ChildProcessSendResult
|
2012-10-05 12:09:33 -07:00
|
|
|
SendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE;
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
UnpackResponseFromParentProcess(const ResponseValue& aResponseValue)
|
|
|
|
MOZ_OVERRIDE;
|
2010-12-09 18:15:00 -08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual nsresult
|
|
|
|
BindArgumentsToStatement(mozIStorageStatement* aStatement) = 0;
|
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
GatherResultsFromStatement(mozIStorageStatement* aStatement) = 0;
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
void UpdateCursorState()
|
|
|
|
{
|
|
|
|
mCursor->mCachedKey = JSVAL_VOID;
|
|
|
|
mCursor->mCachedPrimaryKey = JSVAL_VOID;
|
|
|
|
mCursor->mCachedValue = JSVAL_VOID;
|
|
|
|
mCursor->mHaveCachedKey = false;
|
|
|
|
mCursor->mHaveCachedPrimaryKey = false;
|
|
|
|
mCursor->mHaveCachedValue = false;
|
|
|
|
mCursor->mContinueCalled = false;
|
|
|
|
|
|
|
|
if (mKey.IsUnset()) {
|
|
|
|
mCursor->mHaveValue = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(mCursor->mType == IDBCursor::OBJECTSTORE ||
|
|
|
|
!mObjectKey.IsUnset(), "Bad key!");
|
|
|
|
|
|
|
|
// Set new values.
|
|
|
|
mCursor->mKey = mKey;
|
|
|
|
mCursor->mObjectKey = mObjectKey;
|
|
|
|
mCursor->mContinueToKey.Unset();
|
|
|
|
|
|
|
|
mCursor->mCloneReadInfo.Swap(mCloneReadInfo);
|
|
|
|
mCloneReadInfo.mCloneBuffer.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mCount;
|
2010-12-09 18:15:00 -08:00
|
|
|
Key mKey;
|
|
|
|
Key mObjectKey;
|
2011-12-15 23:34:24 -08:00
|
|
|
StructuredCloneReadInfo mCloneReadInfo;
|
2010-12-09 18:15:00 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ContinueObjectStoreHelper : public ContinueHelper
|
|
|
|
{
|
|
|
|
public:
|
2011-11-07 15:37:19 -08:00
|
|
|
ContinueObjectStoreHelper(IDBCursor* aCursor,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCount)
|
2011-11-07 15:37:19 -08:00
|
|
|
: ContinueHelper(aCursor, aCount)
|
2010-12-09 18:15:00 -08:00
|
|
|
{ }
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
private:
|
|
|
|
nsresult BindArgumentsToStatement(mozIStorageStatement* aStatement);
|
|
|
|
nsresult GatherResultsFromStatement(mozIStorageStatement* aStatement);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContinueIndexHelper : public ContinueHelper
|
|
|
|
{
|
|
|
|
public:
|
2011-11-07 15:37:19 -08:00
|
|
|
ContinueIndexHelper(IDBCursor* aCursor,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCount)
|
2011-11-07 15:37:19 -08:00
|
|
|
: ContinueHelper(aCursor, aCount)
|
2010-06-23 12:46:08 -07:00
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
2010-12-09 18:15:00 -08:00
|
|
|
nsresult BindArgumentsToStatement(mozIStorageStatement* aStatement);
|
|
|
|
nsresult GatherResultsFromStatement(mozIStorageStatement* aStatement);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContinueIndexObjectHelper : public ContinueIndexHelper
|
|
|
|
{
|
|
|
|
public:
|
2011-11-07 15:37:19 -08:00
|
|
|
ContinueIndexObjectHelper(IDBCursor* aCursor,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCount)
|
2011-11-07 15:37:19 -08:00
|
|
|
: ContinueIndexHelper(aCursor, aCount)
|
2010-12-09 18:15:00 -08:00
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult GatherResultsFromStatement(mozIStorageStatement* aStatement);
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
// static
|
2010-06-28 11:51:06 -07:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBObjectStore* aObjectStore,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
2011-12-15 23:34:24 -08:00
|
|
|
StructuredCloneReadInfo& aCloneReadInfo)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aObjectStore, "Null pointer!");
|
2010-12-15 13:21:07 -08:00
|
|
|
NS_ASSERTION(!aKey.IsUnset(), "Bad key!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-09 18:15:00 -08:00
|
|
|
IDBCursor::CreateCommon(aRequest, aTransaction, aObjectStore, aDirection,
|
|
|
|
aRangeKey, aContinueQuery, aContinueToQuery);
|
|
|
|
NS_ASSERTION(cursor, "This shouldn't fail!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
cursor->mObjectStore = aObjectStore;
|
|
|
|
cursor->mType = OBJECTSTORE;
|
2010-12-09 18:15:00 -08:00
|
|
|
cursor->mKey = aKey;
|
2011-12-15 23:34:24 -08:00
|
|
|
cursor->mCloneReadInfo.Swap(aCloneReadInfo);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2010-06-28 11:51:06 -07:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBIndex* aIndex,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
|
|
|
const Key& aObjectKey)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aIndex, "Null pointer!");
|
2010-12-15 13:21:07 -08:00
|
|
|
NS_ASSERTION(!aKey.IsUnset(), "Bad key!");
|
|
|
|
NS_ASSERTION(!aObjectKey.IsUnset(), "Bad key!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-09 18:15:00 -08:00
|
|
|
IDBCursor::CreateCommon(aRequest, aTransaction, aIndex->ObjectStore(),
|
|
|
|
aDirection, aRangeKey, aContinueQuery,
|
|
|
|
aContinueToQuery);
|
|
|
|
NS_ASSERTION(cursor, "This shouldn't fail!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
cursor->mIndex = aIndex;
|
2010-12-15 13:21:11 -08:00
|
|
|
cursor->mType = INDEXKEY;
|
2010-12-09 18:15:00 -08:00
|
|
|
cursor->mKey = aKey,
|
|
|
|
cursor->mObjectKey = aObjectKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2010-06-28 11:51:06 -07:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBIndex* aIndex,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
|
|
|
const Key& aObjectKey,
|
2011-12-15 23:34:24 -08:00
|
|
|
StructuredCloneReadInfo& aCloneReadInfo)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aIndex, "Null pointer!");
|
2010-12-15 13:21:07 -08:00
|
|
|
NS_ASSERTION(!aKey.IsUnset(), "Bad key!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-09 18:15:00 -08:00
|
|
|
IDBCursor::CreateCommon(aRequest, aTransaction, aIndex->ObjectStore(),
|
|
|
|
aDirection, aRangeKey, aContinueQuery,
|
|
|
|
aContinueToQuery);
|
|
|
|
NS_ASSERTION(cursor, "This shouldn't fail!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
cursor->mObjectStore = aIndex->ObjectStore();
|
|
|
|
cursor->mIndex = aIndex;
|
|
|
|
cursor->mType = INDEXOBJECT;
|
2010-12-09 18:15:00 -08:00
|
|
|
cursor->mKey = aKey;
|
|
|
|
cursor->mObjectKey = aObjectKey;
|
2011-12-15 23:34:24 -08:00
|
|
|
cursor->mCloneReadInfo.Swap(aCloneReadInfo);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
IDBCursor::ParseDirection(const nsAString& aDirection, Direction* aResult)
|
|
|
|
{
|
|
|
|
if (aDirection.EqualsLiteral("next")) {
|
|
|
|
*aResult = NEXT;
|
|
|
|
}
|
|
|
|
else if (aDirection.EqualsLiteral("nextunique")) {
|
|
|
|
*aResult = NEXT_UNIQUE;
|
|
|
|
}
|
|
|
|
else if (aDirection.EqualsLiteral("prev")) {
|
|
|
|
*aResult = PREV;
|
|
|
|
}
|
|
|
|
else if (aDirection.EqualsLiteral("prevunique")) {
|
|
|
|
*aResult = PREV_UNIQUE;
|
|
|
|
}
|
|
|
|
else {
|
2012-04-11 14:55:21 -07:00
|
|
|
return NS_ERROR_TYPE_ERR;
|
2012-03-12 21:44:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
// static
|
2010-06-28 11:51:06 -07:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::CreateCommon(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
2010-12-09 18:15:00 -08:00
|
|
|
IDBObjectStore* aObjectStore,
|
2012-03-12 21:44:45 -07:00
|
|
|
Direction aDirection,
|
2010-12-09 18:15:00 -08:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(aRequest, "Null pointer!");
|
|
|
|
NS_ASSERTION(aTransaction, "Null pointer!");
|
2010-12-09 18:15:00 -08:00
|
|
|
NS_ASSERTION(aObjectStore, "Null pointer!");
|
2012-06-01 10:21:12 -07:00
|
|
|
NS_ASSERTION(!aContinueQuery.IsEmpty() ||
|
|
|
|
!IndexedDatabaseManager::IsMainProcess(),
|
|
|
|
"Empty query!");
|
|
|
|
NS_ASSERTION(!aContinueToQuery.IsEmpty() ||
|
|
|
|
!IndexedDatabaseManager::IsMainProcess(),
|
|
|
|
"Empty query!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
nsRefPtr<IDBCursor> cursor = new IDBCursor();
|
2010-09-09 15:15:38 -07:00
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
IDBDatabase* database = aTransaction->Database();
|
|
|
|
cursor->mScriptOwner = database->GetScriptOwner();
|
|
|
|
|
2012-02-27 08:52:19 -08:00
|
|
|
if (cursor->mScriptOwner) {
|
2012-11-12 17:15:00 -08:00
|
|
|
NS_HOLD_JS_OBJECTS(cursor, IDBCursor);
|
2012-02-27 08:52:19 -08:00
|
|
|
cursor->mRooted = true;
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
cursor->mRequest = aRequest;
|
|
|
|
cursor->mTransaction = aTransaction;
|
2010-12-09 18:15:00 -08:00
|
|
|
cursor->mObjectStore = aObjectStore;
|
2010-06-23 12:46:08 -07:00
|
|
|
cursor->mDirection = aDirection;
|
2010-12-09 18:15:00 -08:00
|
|
|
cursor->mContinueQuery = aContinueQuery;
|
|
|
|
cursor->mContinueToQuery = aContinueToQuery;
|
|
|
|
cursor->mRangeKey = aRangeKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
IDBCursor::IDBCursor()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mScriptOwner(nullptr),
|
2012-01-24 02:03:37 -08:00
|
|
|
mType(OBJECTSTORE),
|
2012-03-12 21:44:45 -07:00
|
|
|
mDirection(IDBCursor::NEXT),
|
2011-11-03 08:57:30 -07:00
|
|
|
mCachedKey(JSVAL_VOID),
|
2011-02-10 23:47:00 -08:00
|
|
|
mCachedPrimaryKey(JSVAL_VOID),
|
2010-06-23 12:46:08 -07:00
|
|
|
mCachedValue(JSVAL_VOID),
|
2012-07-30 07:20:58 -07:00
|
|
|
mActorChild(nullptr),
|
|
|
|
mActorParent(nullptr),
|
2011-11-03 08:57:30 -07:00
|
|
|
mHaveCachedKey(false),
|
2011-02-10 23:47:00 -08:00
|
|
|
mHaveCachedPrimaryKey(false),
|
2010-06-23 12:46:08 -07:00
|
|
|
mHaveCachedValue(false),
|
2011-02-10 23:47:00 -08:00
|
|
|
mRooted(false),
|
2011-01-06 22:21:36 -08:00
|
|
|
mContinueCalled(false),
|
|
|
|
mHaveValue(true)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
}
|
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
IDBCursor::~IDBCursor()
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
NS_ASSERTION(!mActorParent, "Actor parent owns us, how can we be dying?!");
|
|
|
|
if (mActorChild) {
|
|
|
|
NS_ASSERTION(!IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
mActorChild->Send__delete__(mActorChild);
|
|
|
|
NS_ASSERTION(!mActorChild, "Should have cleared in Send__delete__!");
|
|
|
|
}
|
|
|
|
|
2012-11-27 17:37:57 -08:00
|
|
|
DropJSObjects();
|
2012-10-03 12:05:20 -07:00
|
|
|
IDBObjectStore::ClearCloneReadInfo(mCloneReadInfo);
|
2010-09-09 15:15:38 -07:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-11-27 17:37:57 -08:00
|
|
|
void
|
|
|
|
IDBCursor::DropJSObjects()
|
|
|
|
{
|
|
|
|
if (!mRooted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mScriptOwner = nullptr;
|
|
|
|
mCachedKey = JSVAL_VOID;
|
|
|
|
mCachedPrimaryKey = JSVAL_VOID;
|
|
|
|
mCachedValue = JSVAL_VOID;
|
|
|
|
mHaveCachedKey = false;
|
|
|
|
mHaveCachedPrimaryKey = false;
|
|
|
|
mHaveCachedValue = false;
|
|
|
|
mRooted = false;
|
|
|
|
mHaveValue = false;
|
|
|
|
NS_DROP_JS_OBJECTS(this, IDBCursor);
|
|
|
|
}
|
|
|
|
|
2011-11-07 15:37:19 -08:00
|
|
|
nsresult
|
|
|
|
IDBCursor::ContinueInternal(const Key& aKey,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aCount)
|
2011-11-07 15:37:19 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(aCount > 0, "Must have a count!");
|
|
|
|
|
|
|
|
if (!mTransaction->IsOpen()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHaveValue || mContinueCalled) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
mContinueToKey = aKey;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2012-03-12 21:44:45 -07:00
|
|
|
nsAutoString readyState;
|
|
|
|
if (NS_FAILED(mRequest->GetReadyState(readyState))) {
|
2011-11-07 15:37:19 -08:00
|
|
|
NS_ERROR("This should never fail!");
|
|
|
|
}
|
2012-03-12 21:44:45 -07:00
|
|
|
NS_ASSERTION(readyState.EqualsLiteral("done"), "Should be DONE!");
|
2011-11-07 15:37:19 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mRequest->Reset();
|
|
|
|
|
|
|
|
nsRefPtr<ContinueHelper> helper;
|
|
|
|
switch (mType) {
|
|
|
|
case OBJECTSTORE:
|
|
|
|
helper = new ContinueObjectStoreHelper(this, aCount);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INDEXKEY:
|
|
|
|
helper = new ContinueIndexHelper(this, aCount);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INDEXOBJECT:
|
|
|
|
helper = new ContinueIndexObjectHelper(this, aCount);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown cursor type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = helper->DispatchToTransactionPool();
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
mContinueCalled = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBCursor)
|
2010-09-13 15:32:56 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRequest)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTransaction)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mObjectStore)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIndex)
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2010-09-13 15:32:56 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBCursor)
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(tmp->mHaveCachedKey || JSVAL_IS_VOID(tmp->mCachedKey),
|
|
|
|
"Should have a cached key");
|
2011-02-10 23:47:00 -08:00
|
|
|
NS_ASSERTION(tmp->mHaveCachedPrimaryKey ||
|
|
|
|
JSVAL_IS_VOID(tmp->mCachedPrimaryKey),
|
|
|
|
"Should have a cached primary key");
|
|
|
|
NS_ASSERTION(tmp->mHaveCachedValue || JSVAL_IS_VOID(tmp->mCachedValue),
|
|
|
|
"Should have a cached value");
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScriptOwner)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedKey)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedPrimaryKey)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedValue)
|
2010-09-13 15:32:56 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBCursor)
|
2010-09-09 15:15:38 -07:00
|
|
|
// Don't unlink mObjectStore, mIndex, or mTransaction!
|
2012-11-27 17:37:57 -08:00
|
|
|
tmp->DropJSObjects();
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRequest)
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBCursor)
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIIDBCursor)
|
2011-02-10 23:47:00 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIIDBCursorWithValue, mType != INDEXKEY)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(IDBCursorWithValue,
|
|
|
|
mType != INDEXKEY)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(IDBCursor,
|
|
|
|
mType == INDEXKEY)
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2010-09-09 15:15:38 -07:00
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBCursor)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBCursor)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 11:51:06 -07:00
|
|
|
DOMCI_DATA(IDBCursor, IDBCursor)
|
2011-02-10 23:47:00 -08:00
|
|
|
DOMCI_DATA(IDBCursorWithValue, IDBCursor)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-03-12 21:44:45 -07:00
|
|
|
IDBCursor::GetDirection(nsAString& aDirection)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-03-13 13:25:05 -07:00
|
|
|
switch (mDirection) {
|
2012-03-12 21:44:45 -07:00
|
|
|
case NEXT:
|
|
|
|
aDirection.AssignLiteral("next");
|
|
|
|
break;
|
|
|
|
case NEXT_UNIQUE:
|
|
|
|
aDirection.AssignLiteral("nextunique");
|
|
|
|
break;
|
|
|
|
case PREV:
|
|
|
|
aDirection.AssignLiteral("prev");
|
|
|
|
break;
|
|
|
|
case PREV_UNIQUE:
|
|
|
|
aDirection.AssignLiteral("prevunique");
|
2012-06-01 10:21:12 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIRECTION_INVALID:
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Bad direction value!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2012-03-12 21:44:45 -07:00
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-09 18:14:09 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBCursor::GetSource(nsISupports** aSource)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
return mType == OBJECTSTORE ?
|
|
|
|
CallQueryInterface(mObjectStore, aSource) :
|
|
|
|
CallQueryInterface(mIndex, aSource);
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_IMETHODIMP
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBCursor::GetKey(JSContext* aCx,
|
|
|
|
jsval* aKey)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_ASSERTION(!mKey.IsUnset() || !mHaveValue, "Bad key!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!mHaveValue) {
|
|
|
|
*aKey = JSVAL_VOID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!mHaveCachedKey) {
|
|
|
|
if (!mRooted) {
|
|
|
|
NS_HOLD_JS_OBJECTS(this, IDBCursor);
|
|
|
|
mRooted = true;
|
2011-11-02 18:57:48 -07:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
JSAutoRequest ar(aCx);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
nsresult rv = mKey.ToJSVal(aCx, &mCachedKey);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
mHaveCachedKey = true;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
*aKey = mCachedKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-02-10 23:47:00 -08:00
|
|
|
IDBCursor::GetPrimaryKey(JSContext* aCx,
|
|
|
|
jsval* aValue)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
if (!mHaveValue) {
|
|
|
|
*aValue = JSVAL_VOID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-02-10 23:47:00 -08:00
|
|
|
if (!mHaveCachedPrimaryKey) {
|
|
|
|
if (!mRooted) {
|
|
|
|
NS_HOLD_JS_OBJECTS(this, IDBCursor);
|
|
|
|
mRooted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSAutoRequest ar(aCx);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-02-10 23:47:00 -08:00
|
|
|
NS_ASSERTION(mType == OBJECTSTORE ? !mKey.IsUnset() :
|
|
|
|
!mObjectKey.IsUnset(), "Bad key!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
const Key& key = mType == OBJECTSTORE ? mKey : mObjectKey;
|
|
|
|
|
|
|
|
nsresult rv = key.ToJSVal(aCx, &mCachedPrimaryKey);
|
2010-12-15 13:21:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-02-10 23:47:00 -08:00
|
|
|
mHaveCachedPrimaryKey = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aValue = mCachedPrimaryKey;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBCursor::GetValue(JSContext* aCx,
|
|
|
|
jsval* aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(mType != INDEXKEY, "GetValue shouldn't exist on index keys");
|
|
|
|
|
|
|
|
if (!mHaveValue) {
|
|
|
|
*aValue = JSVAL_VOID;
|
2010-06-23 12:46:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHaveCachedValue) {
|
2011-02-10 23:47:00 -08:00
|
|
|
if (!mRooted) {
|
2010-09-13 15:32:56 -07:00
|
|
|
NS_HOLD_JS_OBJECTS(this, IDBCursor);
|
2011-02-10 23:47:00 -08:00
|
|
|
mRooted = true;
|
2010-09-13 15:32:56 -07:00
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
jsval val;
|
|
|
|
if (!IDBObjectStore::DeserializeValue(aCx, mCloneReadInfo, &val)) {
|
2010-12-21 08:02:04 -08:00
|
|
|
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
mCloneReadInfo.mCloneBuffer.clear();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
mCachedValue = val;
|
2010-06-23 12:46:08 -07:00
|
|
|
mHaveCachedValue = true;
|
|
|
|
}
|
|
|
|
|
2010-06-28 15:22:41 -07:00
|
|
|
*aValue = mCachedValue;
|
2010-06-23 12:46:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-04-25 05:30:28 -07:00
|
|
|
IDBCursor::Continue(const jsval &aKey,
|
2010-12-15 13:21:07 -08:00
|
|
|
JSContext* aCx)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
Key key;
|
2011-11-03 08:57:30 -07:00
|
|
|
nsresult rv = key.SetFromJSVal(aCx, aKey);
|
2010-12-15 13:21:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
if (!key.IsUnset()) {
|
|
|
|
switch (mDirection) {
|
2012-03-12 21:44:45 -07:00
|
|
|
case IDBCursor::NEXT:
|
|
|
|
case IDBCursor::NEXT_UNIQUE:
|
2010-12-09 18:15:00 -08:00
|
|
|
if (key <= mKey) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
|
|
|
}
|
|
|
|
break;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
case IDBCursor::PREV:
|
|
|
|
case IDBCursor::PREV_UNIQUE:
|
2010-12-09 18:15:00 -08:00
|
|
|
if (key >= mKey) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
|
|
|
}
|
|
|
|
break;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown direction type!");
|
|
|
|
}
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-04-25 05:30:28 -07:00
|
|
|
return ContinueInternal(key, 1);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-11-10 15:25:44 -08:00
|
|
|
IDBCursor::Update(const jsval& aValue,
|
2010-06-28 15:22:41 -07:00
|
|
|
JSContext* aCx,
|
2010-06-28 11:51:06 -07:00
|
|
|
nsIIDBRequest** _retval)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-12-15 13:21:17 -08:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2010-12-15 13:21:14 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTransaction->IsWriteAllowed()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR;
|
|
|
|
}
|
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
if (!mHaveValue || mType == INDEXKEY) {
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
NS_ASSERTION(mObjectStore, "This cannot be null!");
|
2010-12-15 13:21:07 -08:00
|
|
|
NS_ASSERTION(!mKey.IsUnset() , "Bad key!");
|
2010-12-15 13:21:11 -08:00
|
|
|
NS_ASSERTION(mType != INDEXOBJECT || !mObjectKey.IsUnset(), "Bad key!");
|
|
|
|
|
|
|
|
nsresult rv;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 15:22:41 -07:00
|
|
|
JSAutoRequest ar(aCx);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-06-21 15:27:13 -07:00
|
|
|
if (mObjectStore->HasValidKeyPath()) {
|
2010-12-15 13:21:11 -08:00
|
|
|
// Make sure the object given has the correct keyPath value set on it.
|
2012-06-21 15:27:13 -07:00
|
|
|
const KeyPath& keyPath = mObjectStore->GetKeyPath();
|
2010-12-15 13:21:11 -08:00
|
|
|
Key key;
|
2012-06-21 15:27:13 -07:00
|
|
|
|
|
|
|
rv = keyPath.ExtractKey(aCx, aValue, key);
|
2010-12-15 13:21:11 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-15 13:21:11 -08:00
|
|
|
if (key != objectKey) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-04-25 05:30:28 -07:00
|
|
|
return mObjectStore->Put(aValue, JSVAL_VOID, aCx, 0, _retval);
|
2013-03-15 23:58:50 -07:00
|
|
|
}
|
|
|
|
|
2013-04-25 05:30:28 -07:00
|
|
|
jsval keyVal;
|
|
|
|
rv = objectKey.ToJSVal(aCx, &keyVal);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-04-25 05:30:28 -07:00
|
|
|
return mObjectStore->Put(aValue, keyVal, aCx, 1, _retval);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-12-15 13:21:11 -08:00
|
|
|
IDBCursor::Delete(JSContext* aCx,
|
|
|
|
nsIIDBRequest** _retval)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-12-15 13:21:17 -08:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2010-12-15 13:21:14 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTransaction->IsWriteAllowed()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR;
|
|
|
|
}
|
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
if (!mHaveValue || mType == INDEXKEY) {
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
NS_ASSERTION(mObjectStore, "This cannot be null!");
|
2010-12-15 13:21:11 -08:00
|
|
|
NS_ASSERTION(!mKey.IsUnset() , "Bad key!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-15 13:21:11 -08:00
|
|
|
jsval key;
|
2011-11-03 08:57:30 -07:00
|
|
|
nsresult rv = objectKey.ToJSVal(aCx, &key);
|
2010-12-15 13:21:11 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-04-25 05:30:28 -07:00
|
|
|
return mObjectStore->Delete(key, aCx, _retval);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2011-11-07 15:37:19 -08:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
IDBCursor::Advance(int64_t aCount)
|
2011-11-07 15:37:19 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-09-27 23:57:33 -07:00
|
|
|
if (aCount < 1 || aCount > UINT32_MAX) {
|
2012-04-11 14:55:21 -07:00
|
|
|
return NS_ERROR_TYPE_ERR;
|
2011-11-07 15:37:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Key key;
|
2013-04-25 05:30:28 -07:00
|
|
|
return ContinueInternal(key, int32_t(aCount));
|
2011-11-07 15:37:19 -08:00
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
void
|
|
|
|
CursorHelper::ReleaseMainThreadObjects()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mCursor = nullptr;
|
2012-06-01 10:21:12 -07:00
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CursorHelper::Dispatch(nsIEventTarget* aDatabaseThread)
|
|
|
|
{
|
|
|
|
if (IndexedDatabaseManager::IsMainProcess()) {
|
|
|
|
return AsyncConnectionHelper::Dispatch(aDatabaseThread);
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:29:07 -08:00
|
|
|
// If we've been invalidated then there's no point sending anything to the
|
|
|
|
// parent process.
|
|
|
|
if (mCursor->Transaction()->Database()->IsInvalidated()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
IndexedDBCursorChild* cursorActor = mCursor->GetActorChild();
|
|
|
|
NS_ASSERTION(cursorActor, "Must have an actor here!");
|
|
|
|
|
|
|
|
CursorRequestParams params;
|
|
|
|
nsresult rv = PackArgumentsForParentProcess(params);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
NoDispatchEventTarget target;
|
|
|
|
rv = AsyncConnectionHelper::Dispatch(&target);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
mActor = new IndexedDBCursorRequestChild(this, mCursor, params.type());
|
|
|
|
cursorActor->SendPIndexedDBRequestConstructor(mActor, params);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
nsresult
|
|
|
|
ContinueHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
{
|
|
|
|
// We need to pick a query based on whether or not the cursor's mContinueToKey
|
|
|
|
// is set. If it is unset then othing was passed to continue so we'll grab the
|
|
|
|
// next item in the database that is greater than (less than, if we're running
|
|
|
|
// a PREV cursor) the current key. If it is set then a key was passed to
|
|
|
|
// continue so we'll grab the next item in the database that is greater than
|
|
|
|
// (less than, if we're running a PREV cursor) or equal to the key that was
|
|
|
|
// specified.
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString query;
|
2011-11-07 15:37:19 -08:00
|
|
|
if (mCursor->mContinueToKey.IsUnset()) {
|
|
|
|
query.Assign(mCursor->mContinueQuery);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
query.Assign(mCursor->mContinueToQuery);
|
|
|
|
}
|
2010-12-09 18:15:00 -08:00
|
|
|
NS_ASSERTION(!query.IsEmpty(), "Bad query!");
|
|
|
|
|
2011-11-07 15:37:19 -08:00
|
|
|
query.AppendInt(mCount);
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mTransaction->GetCachedStatement(query);
|
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
|
|
|
nsresult rv = BindArgumentsToStatement(stmt);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
2011-11-07 15:37:19 -08:00
|
|
|
NS_ASSERTION(mCount > 0, "Not ok!");
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasResult;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t index = 0; index < mCount; index++) {
|
2011-11-07 15:37:19 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
if (!hasResult) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-09 18:15:00 -08:00
|
|
|
|
|
|
|
if (hasResult) {
|
|
|
|
rv = GatherResultsFromStatement(stmt);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else {
|
2011-11-03 08:57:30 -07:00
|
|
|
mKey.Unset();
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-01-26 17:53:02 -08:00
|
|
|
ContinueHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2012-06-01 10:21:12 -07:00
|
|
|
UpdateCursorState();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
if (mKey.IsUnset()) {
|
2012-06-10 16:44:50 -07:00
|
|
|
*aVal = JSVAL_NULL;
|
2011-01-06 22:21:36 -08:00
|
|
|
}
|
|
|
|
else {
|
2012-06-01 10:21:12 -07:00
|
|
|
nsresult rv = WrapNative(aCx, mCursor, aVal);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2011-01-26 17:53:02 -08:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-10-03 12:05:20 -07:00
|
|
|
void
|
|
|
|
ContinueHelper::ReleaseMainThreadObjects()
|
|
|
|
{
|
|
|
|
IDBObjectStore::ClearCloneReadInfo(mCloneReadInfo);
|
|
|
|
CursorHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
nsresult
|
|
|
|
ContinueHelper::PackArgumentsForParentProcess(CursorRequestParams& aParams)
|
|
|
|
{
|
2012-06-10 16:44:50 -07:00
|
|
|
ContinueParams params;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
params.key() = mCursor->mContinueToKey;
|
|
|
|
params.count() = uint32_t(mCount);
|
|
|
|
|
|
|
|
aParams = params;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-05 12:09:33 -07:00
|
|
|
AsyncConnectionHelper::ChildProcessSendResult
|
|
|
|
ContinueHelper::SendResponseToChildProcess(nsresult aResultCode)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
|
|
|
|
IndexedDBRequestParentBase* actor = mRequest->GetActorParent();
|
2012-10-05 12:09:33 -07:00
|
|
|
NS_ASSERTION(actor, "How did we get this far without an actor?");
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
InfallibleTArray<PBlobParent*> blobsParent;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(aResultCode)) {
|
|
|
|
IDBDatabase* database = mTransaction->Database();
|
|
|
|
NS_ASSERTION(database, "This should never be null!");
|
|
|
|
|
|
|
|
ContentParent* contentParent = database->GetContentParent();
|
|
|
|
NS_ASSERTION(contentParent, "This should never be null!");
|
|
|
|
|
|
|
|
FileManager* fileManager = database->Manager();
|
|
|
|
NS_ASSERTION(fileManager, "This should never be null!");
|
|
|
|
|
|
|
|
const nsTArray<StructuredCloneFile>& files = mCloneReadInfo.mFiles;
|
|
|
|
|
|
|
|
aResultCode =
|
|
|
|
IDBObjectStore::ConvertBlobsToActors(contentParent, fileManager, files,
|
|
|
|
blobsParent);
|
|
|
|
if (NS_FAILED(aResultCode)) {
|
|
|
|
NS_WARNING("ConvertBlobsToActors failed!");
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
ResponseValue response;
|
2012-06-01 10:21:12 -07:00
|
|
|
if (NS_FAILED(aResultCode)) {
|
|
|
|
response = aResultCode;
|
|
|
|
}
|
|
|
|
else {
|
2012-06-10 16:44:50 -07:00
|
|
|
ContinueResponse continueResponse;
|
2012-06-01 10:21:12 -07:00
|
|
|
continueResponse.key() = mKey;
|
|
|
|
continueResponse.objectKey() = mObjectKey;
|
|
|
|
continueResponse.cloneInfo() = mCloneReadInfo;
|
2012-08-01 23:02:29 -07:00
|
|
|
continueResponse.blobsParent().SwapElements(blobsParent);
|
2012-06-01 10:21:12 -07:00
|
|
|
response = continueResponse;
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:29:07 -08:00
|
|
|
if (!actor->SendResponse(response)) {
|
2012-06-01 10:21:12 -07:00
|
|
|
return Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateCursorState();
|
|
|
|
|
|
|
|
return Success_Sent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueHelper::UnpackResponseFromParentProcess(
|
|
|
|
const ResponseValue& aResponseValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aResponseValue.type() == ResponseValue::TContinueResponse,
|
|
|
|
"Bad response type!");
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
const ContinueResponse& response = aResponseValue.get_ContinueResponse();
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
mKey = response.key();
|
|
|
|
mObjectKey = response.objectKey();
|
|
|
|
|
|
|
|
const SerializedStructuredCloneReadInfo& cloneInfo = response.cloneInfo();
|
|
|
|
|
|
|
|
NS_ASSERTION((!cloneInfo.dataLength && !cloneInfo.data) ||
|
|
|
|
(cloneInfo.dataLength && cloneInfo.data),
|
|
|
|
"Inconsistent clone info!");
|
|
|
|
|
|
|
|
if (!mCloneReadInfo.SetFromSerialized(cloneInfo)) {
|
|
|
|
NS_WARNING("Failed to copy clone buffer!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2010-09-09 21:54:25 -07:00
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
IDBObjectStore::ConvertActorsToBlobs(response.blobsChild(),
|
|
|
|
mCloneReadInfo.mFiles);
|
2011-01-26 17:53:02 -08:00
|
|
|
return NS_OK;
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueObjectStoreHelper::BindArgumentsToStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
|
|
|
// Bind object store id.
|
|
|
|
nsresult rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("id"),
|
|
|
|
mCursor->mObjectStore->Id());
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(currentKeyName, "current_key");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(rangeKeyName, "range_key");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
// Bind current key.
|
|
|
|
const Key& currentKey = mCursor->mContinueToKey.IsUnset() ?
|
|
|
|
mCursor->mKey :
|
|
|
|
mCursor->mContinueToKey;
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = currentKey.BindToStatement(aStatement, currentKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-09 18:15:00 -08:00
|
|
|
|
|
|
|
// Bind range key if it is specified.
|
|
|
|
const Key& rangeKey = mCursor->mRangeKey;
|
|
|
|
|
|
|
|
if (!rangeKey.IsUnset()) {
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = rangeKey.BindToStatement(aStatement, rangeKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueObjectStoreHelper::GatherResultsFromStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
|
|
|
// Figure out what kind of key we have next.
|
2011-11-03 08:57:30 -07:00
|
|
|
nsresult rv = mKey.SetFromStatement(aStatement, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
rv = IDBObjectStore::GetStructuredCloneReadInfoFromStatement(aStatement, 1, 2,
|
2012-06-03 09:33:52 -07:00
|
|
|
mDatabase, mCloneReadInfo);
|
2010-12-21 08:02:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-09 18:15:00 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueIndexHelper::BindArgumentsToStatement(mozIStorageStatement* aStatement)
|
|
|
|
{
|
|
|
|
// Bind index id.
|
|
|
|
nsresult rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("id"),
|
|
|
|
mCursor->mIndex->Id());
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(currentKeyName, "current_key");
|
|
|
|
|
|
|
|
// Bind current key.
|
|
|
|
const Key& currentKey = mCursor->mContinueToKey.IsUnset() ?
|
|
|
|
mCursor->mKey :
|
|
|
|
mCursor->mContinueToKey;
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = currentKey.BindToStatement(aStatement, currentKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
// Bind range key if it is specified.
|
|
|
|
if (!mCursor->mRangeKey.IsUnset()) {
|
|
|
|
NS_NAMED_LITERAL_CSTRING(rangeKeyName, "range_key");
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = mCursor->mRangeKey.BindToStatement(aStatement, rangeKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
// Bind object key if duplicates are allowed and we're not continuing to a
|
|
|
|
// specific key.
|
2012-03-12 21:44:45 -07:00
|
|
|
if ((mCursor->mDirection == IDBCursor::NEXT ||
|
|
|
|
mCursor->mDirection == IDBCursor::PREV) &&
|
2010-12-09 18:15:00 -08:00
|
|
|
mCursor->mContinueToKey.IsUnset()) {
|
2010-12-15 13:21:07 -08:00
|
|
|
NS_ASSERTION(!mCursor->mObjectKey.IsUnset(), "Bad key!");
|
2010-12-09 18:15:00 -08:00
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(objectKeyName, "object_key");
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = mCursor->mObjectKey.BindToStatement(aStatement, objectKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueIndexHelper::GatherResultsFromStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
nsresult rv = mKey.SetFromStatement(aStatement, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-02 18:57:48 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = mObjectKey.SetFromStatement(aStatement, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-11-15 13:49:49 -08:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
nsresult
|
|
|
|
ContinueIndexObjectHelper::GatherResultsFromStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
nsresult rv = mKey.SetFromStatement(aStatement, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-02 18:57:48 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = mObjectKey.SetFromStatement(aStatement, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-09 18:15:00 -08:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
rv = IDBObjectStore::GetStructuredCloneReadInfoFromStatement(aStatement, 2, 3,
|
2012-06-03 09:33:52 -07:00
|
|
|
mDatabase, mCloneReadInfo);
|
2010-12-21 08:02:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-11-15 13:49:49 -08:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|