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 "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"
|
2013-03-15 23:58:50 -07:00
|
|
|
#include "ProfilerHelpers.h"
|
2014-01-27 16:37:05 -08:00
|
|
|
#include "ReportInternalError.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"
|
2013-07-31 15:28:13 -07:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2013-08-22 22:17:10 -07:00
|
|
|
#include "mozilla/dom/UnionTypes.h"
|
2012-06-01 10:21:12 -07:00
|
|
|
|
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;
|
2013-07-31 15:28:13 -07:00
|
|
|
using mozilla::dom::Optional;
|
2013-09-17 08:16:02 -07:00
|
|
|
using mozilla::dom::OwningIDBObjectStoreOrIDBIndex;
|
2013-07-31 15:28:13 -07:00
|
|
|
using mozilla::ErrorResult;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-07-18 10:59:53 -07:00
|
|
|
static_assert(sizeof(size_t) >= sizeof(IDBCursor::Direction),
|
2013-09-25 16:11:47 -07:00
|
|
|
"Relying on conversion between size_t and IDBCursor::Direction");
|
2012-06-01 10:21:12 -07:00
|
|
|
|
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:
|
2013-09-25 16:11:47 -07:00
|
|
|
virtual ~CursorHelper()
|
|
|
|
{ }
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
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
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aCursor);
|
|
|
|
MOZ_ASSERT(aCount > 0);
|
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,
|
2013-09-25 16:11:47 -07:00
|
|
|
JS::MutableHandle<JS::Value> aVal)
|
|
|
|
MOZ_OVERRIDE;
|
2012-06-01 10:21:12 -07:00
|
|
|
|
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:
|
2013-09-25 16:11:47 -07:00
|
|
|
virtual ~ContinueHelper()
|
|
|
|
{
|
|
|
|
IDBObjectStore::ClearCloneReadInfo(mCloneReadInfo);
|
|
|
|
}
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
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;
|
2013-09-25 16:11:47 -07:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mCursor->mType == IDBCursor::OBJECTSTORE ||
|
|
|
|
mCursor->mType == IDBCursor::OBJECTSTOREKEY ||
|
|
|
|
!mObjectKey.IsUnset());
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
// Set new values.
|
|
|
|
mCursor->mKey = mKey;
|
|
|
|
mCursor->mObjectKey = mObjectKey;
|
|
|
|
mCursor->mContinueToKey.Unset();
|
|
|
|
|
2014-01-31 18:50:07 -08:00
|
|
|
mCursor->mCloneReadInfo = Move(mCloneReadInfo);
|
2012-06-01 10:21:12 -07:00
|
|
|
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
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
protected:
|
|
|
|
virtual ~ContinueObjectStoreHelper()
|
|
|
|
{ }
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
private:
|
|
|
|
nsresult BindArgumentsToStatement(mozIStorageStatement* aStatement);
|
|
|
|
nsresult GatherResultsFromStatement(mozIStorageStatement* aStatement);
|
|
|
|
};
|
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
class ContinueObjectStoreKeyHelper : public ContinueObjectStoreHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ContinueObjectStoreKeyHelper(IDBCursor* aCursor,
|
|
|
|
uint32_t aCount)
|
|
|
|
: ContinueObjectStoreHelper(aCursor, aCount)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~ContinueObjectStoreKeyHelper()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
GatherResultsFromStatement(mozIStorageStatement* aStatement) MOZ_OVERRIDE;
|
|
|
|
};
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
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
|
|
|
{ }
|
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
protected:
|
|
|
|
virtual ~ContinueIndexHelper()
|
|
|
|
{ }
|
|
|
|
|
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:
|
2013-09-25 16:11:47 -07:00
|
|
|
virtual ~ContinueIndexObjectHelper()
|
|
|
|
{ }
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
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,
|
2014-01-31 18:50:07 -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;
|
2014-01-31 18:50:07 -08:00
|
|
|
cursor->mCloneReadInfo = Move(aCloneReadInfo);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
// static
|
|
|
|
already_AddRefed<IDBCursor>
|
|
|
|
IDBCursor::Create(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBObjectStore* aObjectStore,
|
|
|
|
Direction aDirection,
|
|
|
|
const Key& aRangeKey,
|
|
|
|
const nsACString& aContinueQuery,
|
|
|
|
const nsACString& aContinueToQuery,
|
|
|
|
const Key& aKey)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
MOZ_ASSERT(!aKey.IsUnset());
|
|
|
|
|
|
|
|
nsRefPtr<IDBCursor> cursor =
|
|
|
|
IDBCursor::CreateCommon(aRequest, aTransaction, aObjectStore, aDirection,
|
|
|
|
aRangeKey, aContinueQuery, aContinueToQuery);
|
|
|
|
NS_ASSERTION(cursor, "This shouldn't fail!");
|
|
|
|
|
|
|
|
cursor->mObjectStore = aObjectStore;
|
|
|
|
cursor->mType = OBJECTSTOREKEY;
|
|
|
|
cursor->mKey = aKey;
|
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
// 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,
|
2014-01-31 18:50:07 -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;
|
2014-01-31 18:50:07 -08:00
|
|
|
cursor->mCloneReadInfo = Move(aCloneReadInfo);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
return cursor.forget();
|
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:36 -07: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:
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSUME_UNREACHABLE("Unknown direction!");
|
2013-07-31 08:48:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::HoldJSObjects(cursor.get());
|
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!");
|
2013-07-31 15:28:13 -07:00
|
|
|
|
|
|
|
SetIsDOMBinding();
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
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;
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::DropJSObjects(this);
|
2012-11-27 17:37:57 -08:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
void
|
|
|
|
IDBCursor::ContinueInternal(const Key& aKey, int32_t aCount, ErrorResult& aRv)
|
2011-11-07 15:37:19 -08:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aCount > 0);
|
2011-11-07 15:37:19 -08:00
|
|
|
|
|
|
|
if (!mTransaction->IsOpen()) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return;
|
2011-11-07 15:37:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHaveValue || mContinueCalled) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return;
|
2011-11-07 15:37:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
mContinueToKey = aKey;
|
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(mRequest->ReadyState() == IDBRequestReadyState::Done);
|
2011-11-07 15:37:19 -08:00
|
|
|
|
|
|
|
mRequest->Reset();
|
|
|
|
|
|
|
|
nsRefPtr<ContinueHelper> helper;
|
|
|
|
switch (mType) {
|
|
|
|
case OBJECTSTORE:
|
|
|
|
helper = new ContinueObjectStoreHelper(this, aCount);
|
|
|
|
break;
|
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
case OBJECTSTOREKEY:
|
|
|
|
helper = new ContinueObjectStoreKeyHelper(this, aCount);
|
|
|
|
break;
|
|
|
|
|
2011-11-07 15:37:19 -08:00
|
|
|
case INDEXKEY:
|
|
|
|
helper = new ContinueIndexHelper(this, aCount);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INDEXOBJECT:
|
|
|
|
helper = new ContinueIndexObjectHelper(this, aCount);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSUME_UNREACHABLE("Unknown cursor type!");
|
2011-11-07 15:37:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = helper->DispatchToTransactionPool();
|
2013-07-31 15:28:13 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_WARNING("Failed to dispatch!");
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2011-11-07 15:37:19 -08:00
|
|
|
|
|
|
|
mContinueCalled = true;
|
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBCursor)
|
|
|
|
|
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)
|
2013-07-31 15:28:13 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
2014-04-27 19:32:05 -07:00
|
|
|
NS_ASSERTION(tmp->mHaveCachedKey || tmp->mCachedKey.isUndefined(),
|
2011-11-03 08:57:30 -07:00
|
|
|
"Should have a cached key");
|
2011-02-10 23:47:00 -08:00
|
|
|
NS_ASSERTION(tmp->mHaveCachedPrimaryKey ||
|
2014-04-27 19:32:05 -07:00
|
|
|
tmp->mCachedPrimaryKey.isUndefined(),
|
2011-02-10 23:47:00 -08:00
|
|
|
"Should have a cached primary key");
|
2014-04-27 19:32:05 -07:00
|
|
|
NS_ASSERTION(tmp->mHaveCachedValue || tmp->mCachedValue.isUndefined(),
|
2011-02-10 23:47:00 -08:00
|
|
|
"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)
|
2013-07-31 15:28:13 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
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)
|
2013-07-31 15:28:13 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
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
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
IDBCursor::WrapObject(JSContext* aCx)
|
2013-07-31 15:28:13 -07:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
switch (mType) {
|
|
|
|
case OBJECTSTORE:
|
|
|
|
case INDEXOBJECT:
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return IDBCursorWithValueBinding::Wrap(aCx, this);
|
2013-09-25 16:11:47 -07:00
|
|
|
|
|
|
|
case OBJECTSTOREKEY:
|
|
|
|
case INDEXKEY:
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return IDBCursorBinding::Wrap(aCx, this);
|
2013-09-25 16:11:47 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_ASSUME_UNREACHABLE("Bad type!");
|
|
|
|
}
|
2013-07-31 15:28:13 -07:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
mozilla::dom::IDBCursorDirection
|
|
|
|
IDBCursor::GetDirection() const
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-03-13 13:25:05 -07:00
|
|
|
switch (mDirection) {
|
2012-03-12 21:44:45 -07:00
|
|
|
case NEXT:
|
2013-07-31 15:28:13 -07:00
|
|
|
return mozilla::dom::IDBCursorDirection::Next;
|
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
case NEXT_UNIQUE:
|
2013-07-31 15:28:13 -07:00
|
|
|
return mozilla::dom::IDBCursorDirection::Nextunique;
|
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
case PREV:
|
2013-07-31 15:28:13 -07:00
|
|
|
return mozilla::dom::IDBCursorDirection::Prev;
|
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
case PREV_UNIQUE:
|
2013-07-31 15:28:13 -07:00
|
|
|
return mozilla::dom::IDBCursorDirection::Prevunique;
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
default:
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSUME_UNREACHABLE("Bad direction!");
|
2012-03-12 21:44:45 -07:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-08-22 22:17:10 -07:00
|
|
|
void
|
2013-09-17 08:16:02 -07:00
|
|
|
IDBCursor::GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const
|
2010-12-09 18:14:09 -08:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-09-25 16:11:47 -07:00
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
switch (mType) {
|
|
|
|
case OBJECTSTORE:
|
|
|
|
case OBJECTSTOREKEY:
|
|
|
|
MOZ_ASSERT(mObjectStore);
|
|
|
|
aSource.SetAsIDBObjectStore() = mObjectStore;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INDEXKEY:
|
|
|
|
case INDEXOBJECT:
|
|
|
|
MOZ_ASSERT(mIndex);
|
|
|
|
aSource.SetAsIDBIndex() = mIndex;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_ASSUME_UNREACHABLE("Bad type!");
|
2013-07-31 15:28:13 -07:00
|
|
|
}
|
2010-12-09 18:14:09 -08:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
JS::Value
|
|
|
|
IDBCursor::GetKey(JSContext* aCx, ErrorResult& aRv)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mKey.IsUnset() || !mHaveValue);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!mHaveValue) {
|
2013-07-31 15:28:13 -07:00
|
|
|
return JSVAL_VOID;
|
2011-11-03 08:57:30 -07:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!mHaveCachedKey) {
|
|
|
|
if (!mRooted) {
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::HoldJSObjects(this);
|
2011-11-03 08:57:30 -07:00
|
|
|
mRooted = true;
|
2011-11-02 18:57:48 -07:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv = mKey.ToJSVal(aCx, mCachedKey);
|
|
|
|
ENSURE_SUCCESS(aRv, JSVAL_VOID);
|
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
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
return mCachedKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
JS::Value
|
|
|
|
IDBCursor::GetPrimaryKey(JSContext* aCx, ErrorResult& aRv)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
if (!mHaveValue) {
|
2013-07-31 15:28:13 -07:00
|
|
|
return JSVAL_VOID;
|
2011-01-06 22:21:36 -08:00
|
|
|
}
|
|
|
|
|
2011-02-10 23:47:00 -08:00
|
|
|
if (!mHaveCachedPrimaryKey) {
|
|
|
|
if (!mRooted) {
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::HoldJSObjects(this);
|
2011-02-10 23:47:00 -08:00
|
|
|
mRooted = true;
|
|
|
|
}
|
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
const Key& key =
|
|
|
|
(mType == OBJECTSTORE || mType == OBJECTSTOREKEY) ? mKey : mObjectKey;
|
|
|
|
MOZ_ASSERT(!key.IsUnset());
|
2011-11-03 08:57:30 -07:00
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv = key.ToJSVal(aCx, mCachedPrimaryKey);
|
|
|
|
ENSURE_SUCCESS(aRv, JSVAL_VOID);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-02-10 23:47:00 -08:00
|
|
|
mHaveCachedPrimaryKey = true;
|
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
return mCachedPrimaryKey;
|
2011-02-10 23:47:00 -08:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
JS::Value
|
|
|
|
IDBCursor::GetValue(JSContext* aCx, ErrorResult& aRv)
|
2011-02-10 23:47:00 -08:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mType == OBJECTSTORE || mType == INDEXOBJECT);
|
2011-02-10 23:47:00 -08:00
|
|
|
|
|
|
|
if (!mHaveValue) {
|
2013-07-31 15:28:13 -07:00
|
|
|
return JSVAL_VOID;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHaveCachedValue) {
|
2011-02-10 23:47:00 -08:00
|
|
|
if (!mRooted) {
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::HoldJSObjects(this);
|
2011-02-10 23:47:00 -08:00
|
|
|
mRooted = true;
|
2010-09-13 15:32:56 -07:00
|
|
|
}
|
|
|
|
|
2013-05-02 02:12:47 -07:00
|
|
|
JS::Rooted<JS::Value> val(aCx);
|
2013-06-21 06:12:46 -07:00
|
|
|
if (!IDBObjectStore::DeserializeValue(aCx, mCloneReadInfo, &val)) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
|
|
|
|
return JSVAL_VOID;
|
2010-12-21 08:02:04 -08:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
return mCachedValue;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
void
|
|
|
|
IDBCursor::Continue(JSContext* aCx,
|
2014-02-19 07:13:38 -08:00
|
|
|
JS::Handle<JS::Value> aKey,
|
2013-07-31 15:28:13 -07:00
|
|
|
ErrorResult &aRv)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
Key key;
|
2014-02-19 07:13:38 -08:00
|
|
|
aRv = key.SetFromJSVal(aCx, aKey);
|
|
|
|
ENSURE_SUCCESS_VOID(aRv);
|
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) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return;
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
|
|
|
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) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return;
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
|
|
|
break;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
default:
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSUME_UNREACHABLE("Unknown direction type!");
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
ContinueInternal(key, 1, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
2013-03-15 23:58:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef IDB_PROFILER_USE_MARKS
|
2013-09-25 16:11:47 -07:00
|
|
|
if (mType == OBJECTSTORE || mType == OBJECTSTOREKEY) {
|
2013-03-15 23:58:50 -07:00
|
|
|
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 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
IDBCursor::Update(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
|
|
|
ErrorResult& aRv)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-15 13:21:17 -08:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2010-12-15 13:21:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTransaction->IsWriteAllowed()) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR);
|
|
|
|
return nullptr;
|
2010-12-15 13:21:14 -08:00
|
|
|
}
|
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
if (!mHaveValue || mType == OBJECTSTOREKEY || mType == INDEXKEY) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(mObjectStore);
|
|
|
|
MOZ_ASSERT(!mKey.IsUnset());
|
|
|
|
MOZ_ASSERT(mType == OBJECTSTORE || mType == INDEXOBJECT);
|
|
|
|
MOZ_ASSERT_IF(mType == INDEXOBJECT, !mObjectKey.IsUnset());
|
2010-12-15 13:21:11 -08:00
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
const Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
nsRefPtr<IDBRequest> request;
|
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
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv = keyPath.ExtractKey(aCx, aValue, key);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-15 13:21:11 -08:00
|
|
|
if (key != objectKey) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return nullptr;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2014-02-19 07:13:38 -08:00
|
|
|
request = mObjectStore->Put(aCx, aValue, JS::UndefinedHandleValue, aRv);
|
2013-07-31 15:28:13 -07:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2013-03-15 23:58:50 -07:00
|
|
|
}
|
2013-03-15 23:58:50 -07:00
|
|
|
}
|
2013-03-15 23:58:50 -07:00
|
|
|
else {
|
2013-05-02 02:12:47 -07:00
|
|
|
JS::Rooted<JS::Value> keyVal(aCx);
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv = objectKey.ToJSVal(aCx, &keyVal);
|
|
|
|
ENSURE_SUCCESS(aRv, nullptr);
|
2013-03-15 23:58:50 -07:00
|
|
|
|
2014-02-19 07:13:38 -08:00
|
|
|
request = mObjectStore->Put(aCx, aValue, keyVal, aRv);
|
2013-07-31 15:28:13 -07:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
2013-03-15 23:58:50 -07: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 12:46:08 -07:00
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
return request.forget();
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
IDBCursor::Delete(JSContext* aCx, ErrorResult& aRv)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-12-15 13:21:17 -08:00
|
|
|
if (!mTransaction->IsOpen()) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
2010-12-15 13:21:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTransaction->IsWriteAllowed()) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR);
|
|
|
|
return nullptr;
|
2010-12-15 13:21:14 -08:00
|
|
|
}
|
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
if (!mHaveValue || mType == OBJECTSTOREKEY || mType == INDEXKEY) {
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(mObjectStore);
|
|
|
|
MOZ_ASSERT(mType == OBJECTSTORE || mType == INDEXOBJECT);
|
|
|
|
MOZ_ASSERT(!mKey.IsUnset());
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-09-25 16:11:47 -07:00
|
|
|
const Key& objectKey = (mType == OBJECTSTORE) ? mKey : mObjectKey;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-05-02 02:12:47 -07:00
|
|
|
JS::Rooted<JS::Value> key(aCx);
|
2013-07-31 15:28:13 -07:00
|
|
|
aRv = objectKey.ToJSVal(aCx, &key);
|
|
|
|
ENSURE_SUCCESS(aRv, nullptr);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
nsRefPtr<IDBRequest> request = mObjectStore->Delete(aCx, key, aRv);
|
2013-09-25 16:11:47 -07:00
|
|
|
ENSURE_SUCCESS(aRv, nullptr);
|
2013-03-15 23:58:50 -07:00
|
|
|
|
|
|
|
#ifdef IDB_PROFILER_USE_MARKS
|
|
|
|
{
|
2013-07-31 15:28:13 -07:00
|
|
|
uint64_t requestSerial = request->GetSerialNumber();
|
2013-03-15 23:58:50 -07: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-07-31 15:28:13 -07:00
|
|
|
return request.forget();
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
void
|
|
|
|
IDBCursor::Advance(uint32_t aCount, ErrorResult &aRv)
|
2011-11-07 15:37:19 -08:00
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-11-07 15:37:19 -08:00
|
|
|
|
2013-07-31 15:28:13 -07:00
|
|
|
if (aCount < 1) {
|
|
|
|
aRv.ThrowTypeError(MSG_INVALID_ADVANCE_COUNT);
|
|
|
|
return;
|
2011-11-07 15:37:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Key key;
|
2013-07-31 15:28:13 -07:00
|
|
|
ContinueInternal(key, int32_t(aCount), aRv);
|
|
|
|
ENSURE_SUCCESS_VOID(aRv);
|
2013-03-15 23:58:50 -07:00
|
|
|
|
|
|
|
#ifdef IDB_PROFILER_USE_MARKS
|
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
if (mType == OBJECTSTORE || mType == OBJECTSTOREKEY) {
|
2013-03-15 23:58:50 -07:00
|
|
|
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-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)
|
|
|
|
{
|
2013-03-15 23:58:50 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
PROFILER_MAIN_THREAD_LABEL("IndexedDB", "CursorHelper::Dispatch");
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
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()) {
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
2012-11-09 19:29:07 -08:00
|
|
|
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);
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
NoDispatchEventTarget target;
|
|
|
|
rv = AsyncConnectionHelper::Dispatch(&target);
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2013-03-15 23:58:50 -07:00
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
|
|
|
|
PROFILER_LABEL("IndexedDB", "ContinueHelper::DoDatabaseWork");
|
|
|
|
|
2010-12-09 18:15:00 -08: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-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);
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-12-09 18:15:00 -08:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
|
|
|
nsresult rv = BindArgumentsToStatement(stmt);
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-12-09 18:15:00 -08:00
|
|
|
|
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);
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2011-11-07 15:37:19 -08:00
|
|
|
|
|
|
|
if (!hasResult) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-09 18:15:00 -08:00
|
|
|
|
|
|
|
if (hasResult) {
|
|
|
|
rv = GatherResultsFromStatement(stmt);
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-12-09 18:15:00 -08:00
|
|
|
}
|
|
|
|
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,
|
2013-06-21 06:12:46 -07:00
|
|
|
JS::MutableHandle<JS::Value> 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()) {
|
2013-06-21 06:12:46 -07:00
|
|
|
aVal.setNull();
|
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)
|
|
|
|
{
|
2013-03-15 23:58:50 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(!IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
|
|
|
|
PROFILER_MAIN_THREAD_LABEL("IndexedDB",
|
|
|
|
"ContinueHelper::PackArgumentsForParentProcess");
|
|
|
|
|
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!");
|
|
|
|
|
2013-03-15 23:58:50 -07:00
|
|
|
PROFILER_MAIN_THREAD_LABEL("IndexedDB",
|
|
|
|
"ContinueHelper::SendResponseToChildProcess");
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
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)) {
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_WARNING("Failed to copy clone buffer!");
|
2012-06-01 10:21:12 -07:00
|
|
|
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)
|
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aStatement);
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
// Bind object store id.
|
|
|
|
nsresult rv = aStatement->BindInt64ByName(NS_LITERAL_CSTRING("id"),
|
|
|
|
mCursor->mObjectStore->Id());
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-12-09 18:15:00 -08:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2013-09-25 16:11:47 -07:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aStatement);
|
|
|
|
|
2010-12-09 18:15:00 -08:00
|
|
|
// 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,
|
2013-09-25 16:11:47 -07:00
|
|
|
mDatabase,
|
|
|
|
mCloneReadInfo);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ContinueObjectStoreKeyHelper::GatherResultsFromStatement(
|
|
|
|
mozIStorageStatement* aStatement)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aStatement);
|
|
|
|
|
|
|
|
nsresult rv = mKey.SetFromStatement(aStatement, 0);
|
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());
|
2014-01-27 16:37:05 -08:00
|
|
|
IDB_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-12-09 18:15:00 -08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|