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
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBCursor.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
#include "mozilla/storage.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2010-11-11 02:26:03 +03:00
|
|
|
#include "nsEventDispatcher.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#include "AsyncConnectionHelper.h"
|
|
|
|
#include "IDBEvents.h"
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBIndex.h"
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBObjectStore.h"
|
2010-06-28 20:46:21 +04:00
|
|
|
#include "IDBTransaction.h"
|
2013-03-16 10:58:50 +04:00
|
|
|
#include "ProfilerHelpers.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "TransactionThreadPool.h"
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
#include "ipc/IndexedDBChild.h"
|
|
|
|
#include "ipc/IndexedDBParent.h"
|
|
|
|
|
|
|
|
#include "IndexedDatabaseInlines.h"
|
2013-08-01 02:28:13 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2013-08-23 09:17:10 +04:00
|
|
|
#include "mozilla/dom/UnionTypes.h"
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
USING_INDEXEDDB_NAMESPACE
|
2012-06-11 03:44:50 +04:00
|
|
|
using namespace mozilla::dom::indexedDB::ipc;
|
2013-08-01 02:28:13 +04:00
|
|
|
using mozilla::dom::Optional;
|
2013-08-23 09:17:10 +04:00
|
|
|
using mozilla::dom::IDBObjectStoreOrIDBIndexReturnValue;
|
2013-08-01 02:28:13 +04:00
|
|
|
using mozilla::ErrorResult;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(sizeof(size_t) >= sizeof(IDBCursor::Direction),
|
|
|
|
"Relying on conversion between size_t and "
|
|
|
|
"IDBCursor::Direction");
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
namespace {
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
class CursorHelper : public AsyncConnectionHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CursorHelper(IDBCursor* aCursor)
|
|
|
|
: AsyncConnectionHelper(aCursor->Transaction(), aCursor->Request()),
|
2012-07-30 18:20:58 +04:00
|
|
|
mCursor(aCursor), mActor(nullptr)
|
2012-06-01 21:21:12 +04: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 23:46:08 +04:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
class ContinueHelper : public CursorHelper
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2011-11-08 03:37:19 +04:00
|
|
|
ContinueHelper(IDBCursor* aCursor,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aCount)
|
2012-06-01 21:21:12 +04:00
|
|
|
: CursorHelper(aCursor), mCount(aCount)
|
2011-11-08 03:37:19 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aCount > 0, "Must have a count!");
|
|
|
|
}
|
2010-12-10 05:15:00 +03:00
|
|
|
|
2011-01-27 04:53:02 +03:00
|
|
|
~ContinueHelper()
|
|
|
|
{
|
2012-10-03 23:05:20 +04:00
|
|
|
IDBObjectStore::ClearCloneReadInfo(mCloneReadInfo);
|
2011-01-27 04:53:02 +03:00
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
virtual nsresult DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
MOZ_OVERRIDE;
|
2010-12-10 05:15:00 +03:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
virtual nsresult GetSuccessResult(JSContext* aCx,
|
2013-06-21 17:12:46 +04:00
|
|
|
JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE;
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2012-10-03 23:05:20 +04:00
|
|
|
virtual void ReleaseMainThreadObjects() MOZ_OVERRIDE;
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
virtual nsresult
|
|
|
|
PackArgumentsForParentProcess(CursorRequestParams& aParams) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual ChildProcessSendResult
|
2012-10-05 23:09:33 +04:00
|
|
|
SendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE;
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
UnpackResponseFromParentProcess(const ResponseValue& aResponseValue)
|
|
|
|
MOZ_OVERRIDE;
|
2010-12-10 05:15:00 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual nsresult
|
|
|
|
BindArgumentsToStatement(mozIStorageStatement* aStatement) = 0;
|
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
GatherResultsFromStatement(mozIStorageStatement* aStatement) = 0;
|
|
|
|
|
2012-06-01 21:21:12 +04: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 19:56:38 +04:00
|
|
|
int32_t mCount;
|
2010-12-10 05:15:00 +03:00
|
|
|
Key mKey;
|
|
|
|
Key mObjectKey;
|
2011-12-16 11:34:24 +04:00
|
|
|
StructuredCloneReadInfo mCloneReadInfo;
|
2010-12-10 05:15:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ContinueObjectStoreHelper : public ContinueHelper
|
|
|
|
{
|
|
|
|
public:
|
2011-11-08 03:37:19 +04:00
|
|
|
ContinueObjectStoreHelper(IDBCursor* aCursor,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aCount)
|
2011-11-08 03:37:19 +04:00
|
|
|
: ContinueHelper(aCursor, aCount)
|
2010-12-10 05:15:00 +03:00
|
|
|
{ }
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
private:
|
|
|
|
nsresult BindArgumentsToStatement(mozIStorageStatement* aStatement);
|
|
|
|
nsresult GatherResultsFromStatement(mozIStorageStatement* aStatement);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContinueIndexHelper : public ContinueHelper
|
|
|
|
{
|
|
|
|
public:
|
2011-11-08 03:37:19 +04:00
|
|
|
ContinueIndexHelper(IDBCursor* aCursor,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aCount)
|
2011-11-08 03:37:19 +04:00
|
|
|
: ContinueHelper(aCursor, aCount)
|
2010-06-23 23:46:08 +04:00
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
2010-12-10 05:15:00 +03:00
|
|
|
nsresult BindArgumentsToStatement(mozIStorageStatement* aStatement);
|
|
|
|
nsresult GatherResultsFromStatement(mozIStorageStatement* aStatement);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContinueIndexObjectHelper : public ContinueIndexHelper
|
|
|
|
{
|
|
|
|
public:
|
2011-11-08 03:37:19 +04:00
|
|
|
ContinueIndexObjectHelper(IDBCursor* aCursor,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aCount)
|
2011-11-08 03:37:19 +04:00
|
|
|
: ContinueIndexHelper(aCursor, aCount)
|
2010-12-10 05:15:00 +03:00
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult GatherResultsFromStatement(mozIStorageStatement* aStatement);
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBObjectStore* aObjectStore,
|
2012-03-13 08:44:45 +04:00
|
|
|
Direction aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
2011-12-16 11:34:24 +04:00
|
|
|
StructuredCloneReadInfo& aCloneReadInfo)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aObjectStore, "Null pointer!");
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ASSERTION(!aKey.IsUnset(), "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-10 05:15:00 +03:00
|
|
|
IDBCursor::CreateCommon(aRequest, aTransaction, aObjectStore, aDirection,
|
|
|
|
aRangeKey, aContinueQuery, aContinueToQuery);
|
|
|
|
NS_ASSERTION(cursor, "This shouldn't fail!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
cursor->mObjectStore = aObjectStore;
|
|
|
|
cursor->mType = OBJECTSTORE;
|
2010-12-10 05:15:00 +03:00
|
|
|
cursor->mKey = aKey;
|
2011-12-16 11:34:24 +04:00
|
|
|
cursor->mCloneReadInfo.Swap(aCloneReadInfo);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBIndex* aIndex,
|
2012-03-13 08:44:45 +04:00
|
|
|
Direction aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
|
|
|
const Key& aObjectKey)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aIndex, "Null pointer!");
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ASSERTION(!aKey.IsUnset(), "Bad key!");
|
|
|
|
NS_ASSERTION(!aObjectKey.IsUnset(), "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-10 05:15:00 +03:00
|
|
|
IDBCursor::CreateCommon(aRequest, aTransaction, aIndex->ObjectStore(),
|
|
|
|
aDirection, aRangeKey, aContinueQuery,
|
|
|
|
aContinueToQuery);
|
|
|
|
NS_ASSERTION(cursor, "This shouldn't fail!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
cursor->mIndex = aIndex;
|
2010-12-16 00:21:11 +03:00
|
|
|
cursor->mType = INDEXKEY;
|
2010-12-10 05:15:00 +03:00
|
|
|
cursor->mKey = aKey,
|
|
|
|
cursor->mObjectKey = aObjectKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBIndex* aIndex,
|
2012-03-13 08:44:45 +04:00
|
|
|
Direction aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey,
|
|
|
|
const Key& aObjectKey,
|
2011-12-16 11:34:24 +04:00
|
|
|
StructuredCloneReadInfo& aCloneReadInfo)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aIndex, "Null pointer!");
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ASSERTION(!aKey.IsUnset(), "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
nsRefPtr<IDBCursor> cursor =
|
2010-12-10 05:15:00 +03:00
|
|
|
IDBCursor::CreateCommon(aRequest, aTransaction, aIndex->ObjectStore(),
|
|
|
|
aDirection, aRangeKey, aContinueQuery,
|
|
|
|
aContinueToQuery);
|
|
|
|
NS_ASSERTION(cursor, "This shouldn't fail!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
cursor->mObjectStore = aIndex->ObjectStore();
|
|
|
|
cursor->mIndex = aIndex;
|
|
|
|
cursor->mType = INDEXOBJECT;
|
2010-12-10 05:15:00 +03:00
|
|
|
cursor->mKey = aKey;
|
|
|
|
cursor->mObjectKey = aObjectKey;
|
2011-12-16 11:34:24 +04:00
|
|
|
cursor->mCloneReadInfo.Swap(aCloneReadInfo);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
// static
|
|
|
|
IDBCursor::Direction
|
|
|
|
IDBCursor::ConvertDirection(mozilla::dom::IDBCursorDirection aDirection)
|
|
|
|
{
|
|
|
|
switch (aDirection) {
|
|
|
|
case mozilla::dom::IDBCursorDirection::Next:
|
|
|
|
return NEXT;
|
|
|
|
|
|
|
|
case mozilla::dom::IDBCursorDirection::Nextunique:
|
|
|
|
return NEXT_UNIQUE;
|
|
|
|
|
|
|
|
case mozilla::dom::IDBCursorDirection::Prev:
|
|
|
|
return PREV;
|
|
|
|
|
|
|
|
case mozilla::dom::IDBCursorDirection::Prevunique:
|
|
|
|
return PREV_UNIQUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown direction!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
// static
|
2010-06-28 22:51:06 +04:00
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::CreateCommon(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
2010-12-10 05:15:00 +03:00
|
|
|
IDBObjectStore* aObjectStore,
|
2012-03-13 08:44:45 +04:00
|
|
|
Direction aDirection,
|
2010-12-10 05:15:00 +03:00
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(aRequest, "Null pointer!");
|
|
|
|
NS_ASSERTION(aTransaction, "Null pointer!");
|
2010-12-10 05:15:00 +03:00
|
|
|
NS_ASSERTION(aObjectStore, "Null pointer!");
|
2012-06-01 21:21:12 +04:00
|
|
|
NS_ASSERTION(!aContinueQuery.IsEmpty() ||
|
|
|
|
!IndexedDatabaseManager::IsMainProcess(),
|
|
|
|
"Empty query!");
|
|
|
|
NS_ASSERTION(!aContinueToQuery.IsEmpty() ||
|
|
|
|
!IndexedDatabaseManager::IsMainProcess(),
|
|
|
|
"Empty query!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
nsRefPtr<IDBCursor> cursor = new IDBCursor();
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
IDBDatabase* database = aTransaction->Database();
|
|
|
|
cursor->mScriptOwner = database->GetScriptOwner();
|
|
|
|
|
2012-02-27 20:52:19 +04:00
|
|
|
if (cursor->mScriptOwner) {
|
2012-11-13 05:15:00 +04:00
|
|
|
NS_HOLD_JS_OBJECTS(cursor, IDBCursor);
|
2012-02-27 20:52:19 +04:00
|
|
|
cursor->mRooted = true;
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
cursor->mRequest = aRequest;
|
|
|
|
cursor->mTransaction = aTransaction;
|
2010-12-10 05:15:00 +03:00
|
|
|
cursor->mObjectStore = aObjectStore;
|
2010-06-23 23:46:08 +04:00
|
|
|
cursor->mDirection = aDirection;
|
2010-12-10 05:15:00 +03:00
|
|
|
cursor->mContinueQuery = aContinueQuery;
|
|
|
|
cursor->mContinueToQuery = aContinueToQuery;
|
|
|
|
cursor->mRangeKey = aRangeKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
IDBCursor::IDBCursor()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mScriptOwner(nullptr),
|
2012-01-24 14:03:37 +04:00
|
|
|
mType(OBJECTSTORE),
|
2012-03-13 08:44:45 +04:00
|
|
|
mDirection(IDBCursor::NEXT),
|
2011-11-03 19:57:30 +04:00
|
|
|
mCachedKey(JSVAL_VOID),
|
2011-02-11 10:47:00 +03:00
|
|
|
mCachedPrimaryKey(JSVAL_VOID),
|
2010-06-23 23:46:08 +04:00
|
|
|
mCachedValue(JSVAL_VOID),
|
2012-07-30 18:20:58 +04:00
|
|
|
mActorChild(nullptr),
|
|
|
|
mActorParent(nullptr),
|
2011-11-03 19:57:30 +04:00
|
|
|
mHaveCachedKey(false),
|
2011-02-11 10:47:00 +03:00
|
|
|
mHaveCachedPrimaryKey(false),
|
2010-06-23 23:46:08 +04:00
|
|
|
mHaveCachedValue(false),
|
2011-02-11 10:47:00 +03:00
|
|
|
mRooted(false),
|
2011-01-07 09:21:36 +03:00
|
|
|
mContinueCalled(false),
|
|
|
|
mHaveValue(true)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2013-08-01 02:28:13 +04:00
|
|
|
|
|
|
|
SetIsDOMBinding();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-06-28 22:51:06 +04:00
|
|
|
IDBCursor::~IDBCursor()
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-06-01 21:21:12 +04: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-28 05:37:57 +04:00
|
|
|
DropJSObjects();
|
2012-10-03 23:05:20 +04:00
|
|
|
IDBObjectStore::ClearCloneReadInfo(mCloneReadInfo);
|
2010-09-10 02:15:38 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-11-28 05:37:57 +04: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);
|
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
void
|
|
|
|
IDBCursor::ContinueInternal(const Key& aKey, int32_t aCount, ErrorResult& aRv)
|
2011-11-08 03:37:19 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(aCount > 0, "Must have a count!");
|
|
|
|
|
|
|
|
if (!mTransaction->IsOpen()) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return;
|
2011-11-08 03:37:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHaveValue || mContinueCalled) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return;
|
2011-11-08 03:37:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mContinueToKey = aKey;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2013-08-01 02:28:15 +04:00
|
|
|
NS_ASSERTION(mRequest->ReadyState() == IDBRequestReadyState::Done,
|
|
|
|
"Should be DONE!");
|
2011-11-08 03:37:19 +04: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();
|
2013-08-01 02:28:13 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to dispatch!");
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2011-11-08 03:37:19 +04:00
|
|
|
|
|
|
|
mContinueCalled = true;
|
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBCursor)
|
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBCursor)
|
2010-09-14 02:32:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2012-11-15 11:32:40 +04: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-10 02:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2010-09-14 02:32:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBCursor)
|
2013-08-01 02:28:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
2011-11-03 19:57:30 +04:00
|
|
|
NS_ASSERTION(tmp->mHaveCachedKey || JSVAL_IS_VOID(tmp->mCachedKey),
|
|
|
|
"Should have a cached key");
|
2011-02-11 10:47:00 +03: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-11 03:44:50 +04: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-14 02:32:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBCursor)
|
2013-08-01 02:28:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2010-09-10 02:15:38 +04:00
|
|
|
// Don't unlink mObjectStore, mIndex, or mTransaction!
|
2012-11-28 05:37:57 +04:00
|
|
|
tmp->DropJSObjects();
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRequest)
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBCursor)
|
2013-08-01 02:28:13 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBCursor)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBCursor)
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
JSObject*
|
|
|
|
IDBCursor::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
|
|
|
{
|
|
|
|
return mType != INDEXKEY
|
|
|
|
? IDBCursorWithValueBinding::Wrap(aCx, aScope, this)
|
|
|
|
: IDBCursorBinding::Wrap(aCx, aScope, this);
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
mozilla::dom::IDBCursorDirection
|
|
|
|
IDBCursor::GetDirection() const
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-03-14 00:25:05 +04:00
|
|
|
switch (mDirection) {
|
2012-03-13 08:44:45 +04:00
|
|
|
case NEXT:
|
2013-08-01 02:28:13 +04:00
|
|
|
return mozilla::dom::IDBCursorDirection::Next;
|
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
case NEXT_UNIQUE:
|
2013-08-01 02:28:13 +04:00
|
|
|
return mozilla::dom::IDBCursorDirection::Nextunique;
|
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
case PREV:
|
2013-08-01 02:28:13 +04:00
|
|
|
return mozilla::dom::IDBCursorDirection::Prev;
|
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
case PREV_UNIQUE:
|
2013-08-01 02:28:13 +04:00
|
|
|
return mozilla::dom::IDBCursorDirection::Prevunique;
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
case DIRECTION_INVALID:
|
|
|
|
default:
|
2013-08-01 02:28:13 +04:00
|
|
|
MOZ_CRASH("Unknown direction!");
|
|
|
|
return mozilla::dom::IDBCursorDirection::Next;
|
2012-03-13 08:44:45 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
|
2013-08-23 09:17:10 +04:00
|
|
|
void
|
|
|
|
IDBCursor::GetSource(IDBObjectStoreOrIDBIndexReturnValue& aSource) const
|
2010-12-10 05:14:09 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
if (mType == OBJECTSTORE) {
|
2013-08-23 09:17:10 +04:00
|
|
|
aSource.SetAsIDBObjectStore() = mObjectStore;
|
2013-08-01 02:28:13 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-08-23 09:17:10 +04:00
|
|
|
aSource.SetAsIDBIndex() = mIndex;
|
2013-08-01 02:28:13 +04:00
|
|
|
}
|
2010-12-10 05:14:09 +03:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
JS::Value
|
|
|
|
IDBCursor::GetKey(JSContext* aCx, ErrorResult& aRv)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
NS_ASSERTION(!mKey.IsUnset() || !mHaveValue, "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
if (!mHaveValue) {
|
2013-08-01 02:28:13 +04:00
|
|
|
return JSVAL_VOID;
|
2011-11-03 19:57:30 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
if (!mHaveCachedKey) {
|
|
|
|
if (!mRooted) {
|
|
|
|
NS_HOLD_JS_OBJECTS(this, IDBCursor);
|
|
|
|
mRooted = true;
|
2011-11-03 05:57:48 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv = mKey.ToJSVal(aCx, mCachedKey);
|
|
|
|
ENSURE_SUCCESS(aRv, JSVAL_VOID);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
mHaveCachedKey = true;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
return mCachedKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
JS::Value
|
|
|
|
IDBCursor::GetPrimaryKey(JSContext* aCx, ErrorResult& aRv)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
if (!mHaveValue) {
|
2013-08-01 02:28:13 +04:00
|
|
|
return JSVAL_VOID;
|
2011-01-07 09:21:36 +03:00
|
|
|
}
|
|
|
|
|
2011-02-11 10:47:00 +03:00
|
|
|
if (!mHaveCachedPrimaryKey) {
|
|
|
|
if (!mRooted) {
|
|
|
|
NS_HOLD_JS_OBJECTS(this, IDBCursor);
|
|
|
|
mRooted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSAutoRequest ar(aCx);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-02-11 10:47:00 +03:00
|
|
|
NS_ASSERTION(mType == OBJECTSTORE ? !mKey.IsUnset() :
|
|
|
|
!mObjectKey.IsUnset(), "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
const Key& key = mType == OBJECTSTORE ? mKey : mObjectKey;
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv = key.ToJSVal(aCx, mCachedPrimaryKey);
|
|
|
|
ENSURE_SUCCESS(aRv, JSVAL_VOID);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-02-11 10:47:00 +03:00
|
|
|
mHaveCachedPrimaryKey = true;
|
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
return mCachedPrimaryKey;
|
2011-02-11 10:47:00 +03:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
JS::Value
|
|
|
|
IDBCursor::GetValue(JSContext* aCx, ErrorResult& aRv)
|
2011-02-11 10:47:00 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(mType != INDEXKEY, "GetValue shouldn't exist on index keys");
|
|
|
|
|
|
|
|
if (!mHaveValue) {
|
2013-08-01 02:28:13 +04:00
|
|
|
return JSVAL_VOID;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHaveCachedValue) {
|
2011-02-11 10:47:00 +03:00
|
|
|
if (!mRooted) {
|
2010-09-14 02:32:56 +04:00
|
|
|
NS_HOLD_JS_OBJECTS(this, IDBCursor);
|
2011-02-11 10:47:00 +03:00
|
|
|
mRooted = true;
|
2010-09-14 02:32:56 +04:00
|
|
|
}
|
|
|
|
|
2013-05-02 13:12:47 +04:00
|
|
|
JS::Rooted<JS::Value> val(aCx);
|
2013-06-21 17:12:46 +04:00
|
|
|
if (!IDBObjectStore::DeserializeValue(aCx, mCloneReadInfo, &val)) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
|
|
|
|
return JSVAL_VOID;
|
2010-12-21 19:02:04 +03:00
|
|
|
}
|
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
mCloneReadInfo.mCloneBuffer.clear();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
mCachedValue = val;
|
2010-06-23 23:46:08 +04:00
|
|
|
mHaveCachedValue = true;
|
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
return mCachedValue;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
void
|
|
|
|
IDBCursor::Continue(JSContext* aCx,
|
|
|
|
const Optional<JS::Handle<JS::Value> >& aKey,
|
|
|
|
ErrorResult &aRv)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
Key key;
|
2013-08-01 02:28:13 +04:00
|
|
|
if (aKey.WasPassed()) {
|
|
|
|
aRv = key.SetFromJSVal(aCx, aKey.Value());
|
|
|
|
ENSURE_SUCCESS_VOID(aRv);
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
if (!key.IsUnset()) {
|
|
|
|
switch (mDirection) {
|
2012-03-13 08:44:45 +04:00
|
|
|
case IDBCursor::NEXT:
|
|
|
|
case IDBCursor::NEXT_UNIQUE:
|
2010-12-10 05:15:00 +03:00
|
|
|
if (key <= mKey) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return;
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
break;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
case IDBCursor::PREV:
|
|
|
|
case IDBCursor::PREV_UNIQUE:
|
2010-12-10 05:15:00 +03:00
|
|
|
if (key >= mKey) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return;
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
break;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown direction type!");
|
|
|
|
}
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
ContinueInternal(key, 1, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef IDB_PROFILER_USE_MARKS
|
|
|
|
if (mType == OBJECTSTORE) {
|
|
|
|
IDB_PROFILER_MARK("IndexedDB Request %llu: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s).cursor(%s)."
|
|
|
|
"continue(%s)",
|
|
|
|
"IDBRequest[%llu] MT IDBCursor.continue()",
|
|
|
|
Request()->GetSerialNumber(),
|
|
|
|
IDB_PROFILER_STRING(Transaction()->Database()),
|
|
|
|
IDB_PROFILER_STRING(Transaction()),
|
|
|
|
IDB_PROFILER_STRING(mObjectStore),
|
|
|
|
IDB_PROFILER_STRING(mDirection),
|
|
|
|
key.IsUnset() ? "" : IDB_PROFILER_STRING(key));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
IDB_PROFILER_MARK("IndexedDB Request %llu: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s).index(%s)."
|
|
|
|
"cursor(%s).continue(%s)",
|
|
|
|
"IDBRequest[%llu] MT IDBCursor.continue()",
|
|
|
|
Request()->GetSerialNumber(),
|
|
|
|
IDB_PROFILER_STRING(Transaction()->Database()),
|
|
|
|
IDB_PROFILER_STRING(Transaction()),
|
|
|
|
IDB_PROFILER_STRING(mObjectStore),
|
|
|
|
IDB_PROFILER_STRING(mIndex),
|
|
|
|
IDB_PROFILER_STRING(mDirection),
|
|
|
|
key.IsUnset() ? "" : IDB_PROFILER_STRING(key));
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
IDBCursor::Update(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
|
|
|
ErrorResult& aRv)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-12-16 00:21:17 +03:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2010-12-16 00:21:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTransaction->IsWriteAllowed()) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR);
|
|
|
|
return nullptr;
|
2010-12-16 00:21:14 +03:00
|
|
|
}
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
if (!mHaveValue || mType == INDEXKEY) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
NS_ASSERTION(mObjectStore, "This cannot be null!");
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ASSERTION(!mKey.IsUnset() , "Bad key!");
|
2010-12-16 00:21:11 +03:00
|
|
|
NS_ASSERTION(mType != INDEXOBJECT || !mObjectKey.IsUnset(), "Bad key!");
|
|
|
|
|
2010-06-29 02:22:41 +04:00
|
|
|
JSAutoRequest ar(aCx);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
nsRefPtr<IDBRequest> request;
|
2012-06-22 02:27:13 +04:00
|
|
|
if (mObjectStore->HasValidKeyPath()) {
|
2010-12-16 00:21:11 +03:00
|
|
|
// Make sure the object given has the correct keyPath value set on it.
|
2012-06-22 02:27:13 +04:00
|
|
|
const KeyPath& keyPath = mObjectStore->GetKeyPath();
|
2010-12-16 00:21:11 +03:00
|
|
|
Key key;
|
2012-06-22 02:27:13 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv = keyPath.ExtractKey(aCx, aValue, key);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-12-16 00:21:11 +03:00
|
|
|
if (key != objectKey) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return nullptr;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
JS::Rooted<JS::Value> value(aCx, aValue);
|
|
|
|
Optional<JS::Handle<JS::Value> > keyValue(aCx);
|
2013-08-01 02:28:13 +04:00
|
|
|
request = mObjectStore->Put(aCx, value, keyValue, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
2013-03-16 10:58:50 +04:00
|
|
|
else {
|
2013-05-02 13:12:47 +04:00
|
|
|
JS::Rooted<JS::Value> keyVal(aCx);
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv = objectKey.ToJSVal(aCx, &keyVal);
|
|
|
|
ENSURE_SUCCESS(aRv, nullptr);
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
JS::Rooted<JS::Value> value(aCx, aValue);
|
|
|
|
Optional<JS::Handle<JS::Value> > keyValue(aCx, keyVal);
|
2013-08-01 02:28:13 +04:00
|
|
|
request = mObjectStore->Put(aCx, value, keyValue, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef IDB_PROFILER_USE_MARKS
|
|
|
|
{
|
|
|
|
uint64_t requestSerial =
|
|
|
|
static_cast<IDBRequest*>(request.get())->GetSerialNumber();
|
|
|
|
if (mType == OBJECTSTORE) {
|
|
|
|
IDB_PROFILER_MARK("IndexedDB Request %llu: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s)."
|
|
|
|
"cursor(%s).update(%s)",
|
|
|
|
"IDBRequest[%llu] MT IDBCursor.update()",
|
|
|
|
requestSerial,
|
|
|
|
IDB_PROFILER_STRING(mTransaction->Database()),
|
|
|
|
IDB_PROFILER_STRING(mTransaction),
|
|
|
|
IDB_PROFILER_STRING(mObjectStore),
|
|
|
|
IDB_PROFILER_STRING(mDirection),
|
|
|
|
mObjectStore->HasValidKeyPath() ? "" :
|
|
|
|
IDB_PROFILER_STRING(objectKey));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
IDB_PROFILER_MARK("IndexedDB Request %llu: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s)."
|
|
|
|
"index(%s).cursor(%s).update(%s)",
|
|
|
|
"IDBRequest[%llu] MT IDBCursor.update()",
|
|
|
|
requestSerial,
|
|
|
|
IDB_PROFILER_STRING(mTransaction->Database()),
|
|
|
|
IDB_PROFILER_STRING(mTransaction),
|
|
|
|
IDB_PROFILER_STRING(mObjectStore),
|
|
|
|
IDB_PROFILER_STRING(mIndex),
|
|
|
|
IDB_PROFILER_STRING(mDirection),
|
|
|
|
mObjectStore->HasValidKeyPath() ? "" :
|
|
|
|
IDB_PROFILER_STRING(objectKey));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
return request.forget();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
IDBCursor::Delete(JSContext* aCx, ErrorResult& aRv)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-12-16 00:21:17 +03:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2010-12-16 00:21:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTransaction->IsWriteAllowed()) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR);
|
|
|
|
return nullptr;
|
2010-12-16 00:21:14 +03:00
|
|
|
}
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
if (!mHaveValue || mType == INDEXKEY) {
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
NS_ASSERTION(mObjectStore, "This cannot be null!");
|
2010-12-16 00:21:11 +03:00
|
|
|
NS_ASSERTION(!mKey.IsUnset() , "Bad key!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-05-02 13:12:47 +04:00
|
|
|
JS::Rooted<JS::Value> key(aCx);
|
2013-08-01 02:28:13 +04:00
|
|
|
aRv = objectKey.ToJSVal(aCx, &key);
|
|
|
|
ENSURE_SUCCESS(aRv, nullptr);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
nsRefPtr<IDBRequest> request = mObjectStore->Delete(aCx, key, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef IDB_PROFILER_USE_MARKS
|
|
|
|
{
|
2013-08-01 02:28:13 +04:00
|
|
|
uint64_t requestSerial = request->GetSerialNumber();
|
2013-03-16 10:58:50 +04:00
|
|
|
if (mType == OBJECTSTORE) {
|
|
|
|
IDB_PROFILER_MARK("IndexedDB Request %llu: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s)."
|
|
|
|
"cursor(%s).delete(%s)",
|
|
|
|
"IDBRequest[%llu] MT IDBCursor.delete()",
|
|
|
|
requestSerial,
|
|
|
|
IDB_PROFILER_STRING(mTransaction->Database()),
|
|
|
|
IDB_PROFILER_STRING(mTransaction),
|
|
|
|
IDB_PROFILER_STRING(mObjectStore),
|
|
|
|
IDB_PROFILER_STRING(mDirection),
|
|
|
|
mObjectStore->HasValidKeyPath() ? "" :
|
|
|
|
IDB_PROFILER_STRING(objectKey));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
IDB_PROFILER_MARK("IndexedDB Request %llu: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s)."
|
|
|
|
"index(%s).cursor(%s).delete(%s)",
|
|
|
|
"IDBRequest[%llu] MT IDBCursor.delete()",
|
|
|
|
requestSerial,
|
|
|
|
IDB_PROFILER_STRING(mTransaction->Database()),
|
|
|
|
IDB_PROFILER_STRING(mTransaction),
|
|
|
|
IDB_PROFILER_STRING(mObjectStore),
|
|
|
|
IDB_PROFILER_STRING(mIndex),
|
|
|
|
IDB_PROFILER_STRING(mDirection),
|
|
|
|
mObjectStore->HasValidKeyPath() ? "" :
|
|
|
|
IDB_PROFILER_STRING(objectKey));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
return request.forget();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
void
|
|
|
|
IDBCursor::Advance(uint32_t aCount, ErrorResult &aRv)
|
2011-11-08 03:37:19 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2013-08-01 02:28:13 +04:00
|
|
|
if (aCount < 1) {
|
|
|
|
aRv.ThrowTypeError(MSG_INVALID_ADVANCE_COUNT);
|
|
|
|
return;
|
2011-11-08 03:37:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Key key;
|
2013-08-01 02:28:13 +04:00
|
|
|
ContinueInternal(key, int32_t(aCount), aRv);
|
|
|
|
ENSURE_SUCCESS_VOID(aRv);
|
2013-03-16 10:58:50 +04:00
|
|
|
|
|
|
|
#ifdef IDB_PROFILER_USE_MARKS
|
|
|
|
{
|
|
|
|
if (mType == OBJECTSTORE) {
|
|
|
|
IDB_PROFILER_MARK("IndexedDB Request %llu: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s)."
|
|
|
|
"cursor(%s).advance(%ld)",
|
|
|
|
"IDBRequest[%llu] MT IDBCursor.advance()",
|
|
|
|
Request()->GetSerialNumber(),
|
|
|
|
IDB_PROFILER_STRING(Transaction()->Database()),
|
|
|
|
IDB_PROFILER_STRING(Transaction()),
|
|
|
|
IDB_PROFILER_STRING(mObjectStore),
|
|
|
|
IDB_PROFILER_STRING(mDirection), aCount);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
IDB_PROFILER_MARK("IndexedDB Request %llu: "
|
|
|
|
"database(%s).transaction(%s).objectStore(%s)."
|
|
|
|
"index(%s).cursor(%s).advance(%ld)",
|
|
|
|
"IDBRequest[%llu] MT IDBCursor.advance()",
|
|
|
|
Request()->GetSerialNumber(),
|
|
|
|
IDB_PROFILER_STRING(Transaction()->Database()),
|
|
|
|
IDB_PROFILER_STRING(Transaction()),
|
|
|
|
IDB_PROFILER_STRING(mObjectStore),
|
|
|
|
IDB_PROFILER_STRING(mIndex),
|
|
|
|
IDB_PROFILER_STRING(mDirection), aCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-11-08 03:37:19 +04:00
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
void
|
|
|
|
CursorHelper::ReleaseMainThreadObjects()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mCursor = nullptr;
|
2012-06-01 21:21:12 +04:00
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CursorHelper::Dispatch(nsIEventTarget* aDatabaseThread)
|
|
|
|
{
|
2013-03-16 10:58:50 +04:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
PROFILER_MAIN_THREAD_LABEL("IndexedDB", "CursorHelper::Dispatch");
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
if (IndexedDatabaseManager::IsMainProcess()) {
|
|
|
|
return AsyncConnectionHelper::Dispatch(aDatabaseThread);
|
|
|
|
}
|
|
|
|
|
2012-11-10 07:29:07 +04: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 21:21:12 +04: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-10 05:15:00 +03:00
|
|
|
nsresult
|
|
|
|
ContinueHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
{
|
2013-03-16 10:58:50 +04:00
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
|
|
|
|
PROFILER_LABEL("IndexedDB", "ContinueHelper::DoDatabaseWork");
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
// 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-02 06:35:17 +04:00
|
|
|
nsAutoCString query;
|
2011-11-08 03:37:19 +04:00
|
|
|
if (mCursor->mContinueToKey.IsUnset()) {
|
|
|
|
query.Assign(mCursor->mContinueQuery);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
query.Assign(mCursor->mContinueToQuery);
|
|
|
|
}
|
2010-12-10 05:15:00 +03:00
|
|
|
NS_ASSERTION(!query.IsEmpty(), "Bad query!");
|
|
|
|
|
2011-11-08 03:37:19 +04:00
|
|
|
query.AppendInt(mCount);
|
|
|
|
|
2010-12-10 05:15:00 +03: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-08 03:37:19 +04:00
|
|
|
NS_ASSERTION(mCount > 0, "Not ok!");
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasResult;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t index = 0; index < mCount; index++) {
|
2011-11-08 03:37:19 +04:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
if (!hasResult) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-10 05:15:00 +03:00
|
|
|
|
|
|
|
if (hasResult) {
|
|
|
|
rv = GatherResultsFromStatement(stmt);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else {
|
2011-11-03 19:57:30 +04:00
|
|
|
mKey.Unset();
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-01-27 04:53:02 +03:00
|
|
|
ContinueHelper::GetSuccessResult(JSContext* aCx,
|
2013-06-21 17:12:46 +04:00
|
|
|
JS::MutableHandle<JS::Value> aVal)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2012-06-01 21:21:12 +04:00
|
|
|
UpdateCursorState();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
if (mKey.IsUnset()) {
|
2013-06-21 17:12:46 +04:00
|
|
|
aVal.setNull();
|
2011-01-07 09:21:36 +03:00
|
|
|
}
|
|
|
|
else {
|
2012-06-01 21:21:12 +04:00
|
|
|
nsresult rv = WrapNative(aCx, mCursor, aVal);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2011-01-27 04:53:02 +03:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-10-03 23:05:20 +04:00
|
|
|
void
|
|
|
|
ContinueHelper::ReleaseMainThreadObjects()
|
|
|
|
{
|
|
|
|
IDBObjectStore::ClearCloneReadInfo(mCloneReadInfo);
|
|
|
|
CursorHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
nsresult
|
|
|
|
ContinueHelper::PackArgumentsForParentProcess(CursorRequestParams& aParams)
|
|
|
|
{
|
2013-03-16 10:58:50 +04:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(!IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
|
|
|
|
PROFILER_MAIN_THREAD_LABEL("IndexedDB",
|
|
|
|
"ContinueHelper::PackArgumentsForParentProcess");
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
ContinueParams params;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
params.key() = mCursor->mContinueToKey;
|
|
|
|
params.count() = uint32_t(mCount);
|
|
|
|
|
|
|
|
aParams = params;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-05 23:09:33 +04:00
|
|
|
AsyncConnectionHelper::ChildProcessSendResult
|
|
|
|
ContinueHelper::SendResponseToChildProcess(nsresult aResultCode)
|
2012-06-01 21:21:12 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
|
2013-03-16 10:58:50 +04:00
|
|
|
PROFILER_MAIN_THREAD_LABEL("IndexedDB",
|
|
|
|
"ContinueHelper::SendResponseToChildProcess");
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
IndexedDBRequestParentBase* actor = mRequest->GetActorParent();
|
2012-10-05 23:09:33 +04:00
|
|
|
NS_ASSERTION(actor, "How did we get this far without an actor?");
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2012-08-02 10:02:29 +04: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 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
ResponseValue response;
|
2012-06-01 21:21:12 +04:00
|
|
|
if (NS_FAILED(aResultCode)) {
|
|
|
|
response = aResultCode;
|
|
|
|
}
|
|
|
|
else {
|
2012-06-11 03:44:50 +04:00
|
|
|
ContinueResponse continueResponse;
|
2012-06-01 21:21:12 +04:00
|
|
|
continueResponse.key() = mKey;
|
|
|
|
continueResponse.objectKey() = mObjectKey;
|
|
|
|
continueResponse.cloneInfo() = mCloneReadInfo;
|
2012-08-02 10:02:29 +04:00
|
|
|
continueResponse.blobsParent().SwapElements(blobsParent);
|
2012-06-01 21:21:12 +04:00
|
|
|
response = continueResponse;
|
|
|
|
}
|
|
|
|
|
2012-11-10 07:29:07 +04:00
|
|
|
if (!actor->SendResponse(response)) {
|
2012-06-01 21:21:12 +04:00
|
|
|
return Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateCursorState();
|
|
|
|
|
|
|
|
return Success_Sent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueHelper::UnpackResponseFromParentProcess(
|
|
|
|
const ResponseValue& aResponseValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aResponseValue.type() == ResponseValue::TContinueResponse,
|
|
|
|
"Bad response type!");
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
const ContinueResponse& response = aResponseValue.get_ContinueResponse();
|
2012-06-01 21:21:12 +04: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-10 05:15:00 +03:00
|
|
|
}
|
2010-09-10 08:54:25 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
IDBObjectStore::ConvertActorsToBlobs(response.blobsChild(),
|
|
|
|
mCloneReadInfo.mFiles);
|
2011-01-27 04:53:02 +03:00
|
|
|
return NS_OK;
|
2010-12-10 05:15:00 +03: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 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
// Bind current key.
|
|
|
|
const Key& currentKey = mCursor->mContinueToKey.IsUnset() ?
|
|
|
|
mCursor->mKey :
|
|
|
|
mCursor->mContinueToKey;
|
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
rv = currentKey.BindToStatement(aStatement, currentKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-10 05:15:00 +03:00
|
|
|
|
|
|
|
// Bind range key if it is specified.
|
|
|
|
const Key& rangeKey = mCursor->mRangeKey;
|
|
|
|
|
|
|
|
if (!rangeKey.IsUnset()) {
|
2011-11-03 19:57:30 +04:00
|
|
|
rv = rangeKey.BindToStatement(aStatement, rangeKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueObjectStoreHelper::GatherResultsFromStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
|
|
|
// Figure out what kind of key we have next.
|
2011-11-03 19:57:30 +04:00
|
|
|
nsresult rv = mKey.SetFromStatement(aStatement, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
rv = IDBObjectStore::GetStructuredCloneReadInfoFromStatement(aStatement, 1, 2,
|
2012-06-03 20:33:52 +04:00
|
|
|
mDatabase, mCloneReadInfo);
|
2010-12-21 19:02:04 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-10 05:15:00 +03: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 19:57:30 +04:00
|
|
|
rv = currentKey.BindToStatement(aStatement, currentKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
// Bind range key if it is specified.
|
|
|
|
if (!mCursor->mRangeKey.IsUnset()) {
|
|
|
|
NS_NAMED_LITERAL_CSTRING(rangeKeyName, "range_key");
|
2011-11-03 19:57:30 +04:00
|
|
|
rv = mCursor->mRangeKey.BindToStatement(aStatement, rangeKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
// Bind object key if duplicates are allowed and we're not continuing to a
|
|
|
|
// specific key.
|
2012-03-13 08:44:45 +04:00
|
|
|
if ((mCursor->mDirection == IDBCursor::NEXT ||
|
|
|
|
mCursor->mDirection == IDBCursor::PREV) &&
|
2010-12-10 05:15:00 +03:00
|
|
|
mCursor->mContinueToKey.IsUnset()) {
|
2010-12-16 00:21:07 +03:00
|
|
|
NS_ASSERTION(!mCursor->mObjectKey.IsUnset(), "Bad key!");
|
2010-12-10 05:15:00 +03:00
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(objectKeyName, "object_key");
|
2011-11-03 19:57:30 +04:00
|
|
|
rv = mCursor->mObjectKey.BindToStatement(aStatement, objectKeyName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-10 05:15:00 +03:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueIndexHelper::GatherResultsFromStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
2011-11-03 19:57:30 +04:00
|
|
|
nsresult rv = mKey.SetFromStatement(aStatement, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-03 05:57:48 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
rv = mObjectKey.SetFromStatement(aStatement, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-11-16 00:49:49 +03:00
|
|
|
|
2010-12-10 05:15:00 +03:00
|
|
|
nsresult
|
|
|
|
ContinueIndexObjectHelper::GatherResultsFromStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
2011-11-03 19:57:30 +04:00
|
|
|
nsresult rv = mKey.SetFromStatement(aStatement, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-03 05:57:48 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
rv = mObjectKey.SetFromStatement(aStatement, 1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-10 05:15:00 +03:00
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
rv = IDBObjectStore::GetStructuredCloneReadInfoFromStatement(aStatement, 2, 3,
|
2012-06-03 20:33:52 +04:00
|
|
|
mDatabase, mCloneReadInfo);
|
2010-12-21 19:02:04 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-11-16 00:49:49 +03:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|