2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-09-26 23:21:57 +00: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/. */
|
|
|
|
|
|
|
|
#include "ActorsChild.h"
|
|
|
|
|
|
|
|
#include "BackgroundChildImpl.h"
|
|
|
|
#include "IDBDatabase.h"
|
|
|
|
#include "IDBEvents.h"
|
|
|
|
#include "IDBFactory.h"
|
|
|
|
#include "IDBIndex.h"
|
2015-09-09 11:15:05 +00:00
|
|
|
#include "IDBMutableFile.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "IDBObjectStore.h"
|
|
|
|
#include "IDBMutableFile.h"
|
|
|
|
#include "IDBRequest.h"
|
|
|
|
#include "IDBTransaction.h"
|
|
|
|
#include "IndexedDatabase.h"
|
|
|
|
#include "IndexedDatabaseInlines.h"
|
|
|
|
#include "mozilla/BasicEvents.h"
|
|
|
|
#include "mozilla/Maybe.h"
|
2014-12-17 06:26:15 +00:00
|
|
|
#include "mozilla/TypeTraits.h"
|
2015-04-10 16:10:00 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
|
|
|
#include "mozilla/dom/TabChild.h"
|
|
|
|
#include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseFileChild.h"
|
|
|
|
#include "mozilla/dom/indexedDB/PIndexedDBPermissionRequestChild.h"
|
|
|
|
#include "mozilla/dom/ipc/BlobChild.h"
|
|
|
|
#include "mozilla/ipc/BackgroundUtils.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIBFCacheEntry.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIEventTarget.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsTraceRefcnt.h"
|
|
|
|
#include "PermissionRequestBase.h"
|
|
|
|
#include "ProfilerHelpers.h"
|
|
|
|
#include "ReportInternalError.h"
|
2015-05-06 08:07:57 +00:00
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
#include "WorkerRunnable.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include "IndexedDatabaseManager.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define GC_ON_IPC_MESSAGES 0
|
|
|
|
|
|
|
|
#if defined(DEBUG) || GC_ON_IPC_MESSAGES
|
|
|
|
|
|
|
|
#include "js/GCAPI.h"
|
|
|
|
#include "nsJSEnvironment.h"
|
|
|
|
|
|
|
|
#define BUILD_GC_ON_IPC_MESSAGES
|
|
|
|
|
|
|
|
#endif // DEBUG || GC_ON_IPC_MESSAGES
|
|
|
|
|
|
|
|
namespace mozilla {
|
2015-05-06 08:07:57 +00:00
|
|
|
|
|
|
|
using ipc::PrincipalInfo;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
namespace dom {
|
2015-05-06 08:07:57 +00:00
|
|
|
|
|
|
|
using namespace workers;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
namespace indexedDB {
|
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* ThreadLocal
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ThreadLocal::ThreadLocal(const nsID& aBackgroundChildLoggingId)
|
|
|
|
: mLoggingInfo(aBackgroundChildLoggingId, 1, -1, 1)
|
|
|
|
, mCurrentTransaction(0)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mOwningThread(PR_GetCurrentThread())
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwningThread);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(mozilla::dom::indexedDB::ThreadLocal);
|
2015-04-30 18:59:36 +00:00
|
|
|
|
|
|
|
// NSID_LENGTH counts the null terminator, SetLength() does not.
|
|
|
|
mLoggingIdString.SetLength(NSID_LENGTH - 1);
|
|
|
|
|
|
|
|
aBackgroundChildLoggingId.ToProvidedString(
|
|
|
|
*reinterpret_cast<char(*)[NSID_LENGTH]>(mLoggingIdString.BeginWriting()));
|
2014-10-16 04:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadLocal::~ThreadLocal()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(mozilla::dom::indexedDB::ThreadLocal);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadLocal::AssertIsOnOwningThread() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == mOwningThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Helpers
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void
|
|
|
|
MaybeCollectGarbageOnIPCMessage()
|
|
|
|
{
|
|
|
|
#ifdef BUILD_GC_ON_IPC_MESSAGES
|
|
|
|
static const bool kCollectGarbageOnIPCMessages =
|
|
|
|
#if GC_ON_IPC_MESSAGES
|
|
|
|
true;
|
|
|
|
#else
|
|
|
|
false;
|
|
|
|
#endif // GC_ON_IPC_MESSAGES
|
|
|
|
|
|
|
|
if (!kCollectGarbageOnIPCMessages) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool haveWarnedAboutGC = false;
|
|
|
|
static bool haveWarnedAboutNonMainThread = false;
|
|
|
|
|
|
|
|
if (!haveWarnedAboutGC) {
|
|
|
|
haveWarnedAboutGC = true;
|
|
|
|
NS_WARNING("IndexedDB child actor GC debugging enabled!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
if (!haveWarnedAboutNonMainThread) {
|
|
|
|
haveWarnedAboutNonMainThread = true;
|
|
|
|
NS_WARNING("Don't know how to GC on a non-main thread yet.");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJSContext::GarbageCollectNow(JS::gcreason::DOM_IPC);
|
|
|
|
nsJSContext::CycleCollectNow();
|
|
|
|
#endif // BUILD_GC_ON_IPC_MESSAGES
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class MOZ_STACK_CLASS AutoSetCurrentTransaction final
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
typedef mozilla::ipc::BackgroundChildImpl BackgroundChildImpl;
|
|
|
|
|
|
|
|
IDBTransaction* const mTransaction;
|
|
|
|
IDBTransaction* mPreviousTransaction;
|
2014-10-16 04:56:52 +00:00
|
|
|
ThreadLocal* mThreadLocal;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AutoSetCurrentTransaction(IDBTransaction* aTransaction)
|
|
|
|
: mTransaction(aTransaction)
|
|
|
|
, mPreviousTransaction(nullptr)
|
2014-10-16 04:56:52 +00:00
|
|
|
, mThreadLocal(nullptr)
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
if (aTransaction) {
|
|
|
|
BackgroundChildImpl::ThreadLocal* threadLocal =
|
|
|
|
BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
|
|
|
MOZ_ASSERT(threadLocal);
|
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
// Hang onto this for resetting later.
|
|
|
|
mThreadLocal = threadLocal->mIndexedDBThreadLocal;
|
|
|
|
MOZ_ASSERT(mThreadLocal);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
// Save the current value.
|
2014-10-16 04:56:52 +00:00
|
|
|
mPreviousTransaction = mThreadLocal->GetCurrentTransaction();
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
// Set the new value.
|
2014-10-16 04:56:52 +00:00
|
|
|
mThreadLocal->SetCurrentTransaction(aTransaction);
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSetCurrentTransaction()
|
|
|
|
{
|
2014-10-16 04:56:52 +00:00
|
|
|
MOZ_ASSERT_IF(mThreadLocal, mTransaction);
|
|
|
|
MOZ_ASSERT_IF(mThreadLocal,
|
|
|
|
mThreadLocal->GetCurrentTransaction() == mTransaction);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
if (mThreadLocal) {
|
2014-09-26 23:21:57 +00:00
|
|
|
// Reset old value.
|
2014-10-16 04:56:52 +00:00
|
|
|
mThreadLocal->SetCurrentTransaction(mPreviousTransaction);
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBTransaction*
|
|
|
|
Transaction() const
|
|
|
|
{
|
|
|
|
return mTransaction;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class MOZ_STACK_CLASS ResultHelper final
|
2014-09-26 23:21:57 +00:00
|
|
|
: public IDBRequest::ResultCallback
|
|
|
|
{
|
|
|
|
IDBRequest* mRequest;
|
|
|
|
AutoSetCurrentTransaction mAutoTransaction;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
2014-12-17 06:26:15 +00:00
|
|
|
IDBDatabase* mDatabase;
|
|
|
|
IDBCursor* mCursor;
|
|
|
|
IDBMutableFile* mMutableFile;
|
2014-09-26 23:21:57 +00:00
|
|
|
StructuredCloneReadInfo* mStructuredClone;
|
|
|
|
const nsTArray<StructuredCloneReadInfo>* mStructuredCloneArray;
|
|
|
|
const Key* mKey;
|
|
|
|
const nsTArray<Key>* mKeyArray;
|
|
|
|
const JS::Value* mJSVal;
|
|
|
|
const JS::Handle<JS::Value>* mJSValHandle;
|
|
|
|
} mResult;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2014-12-17 06:26:15 +00:00
|
|
|
ResultTypeDatabase,
|
|
|
|
ResultTypeCursor,
|
|
|
|
ResultTypeMutableFile,
|
2014-09-26 23:21:57 +00:00
|
|
|
ResultTypeStructuredClone,
|
|
|
|
ResultTypeStructuredCloneArray,
|
|
|
|
ResultTypeKey,
|
|
|
|
ResultTypeKeyArray,
|
|
|
|
ResultTypeJSVal,
|
|
|
|
ResultTypeJSValHandle,
|
|
|
|
} mResultType;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ResultHelper(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
2014-12-17 06:26:15 +00:00
|
|
|
IDBDatabase* aResult)
|
2014-09-26 23:21:57 +00:00
|
|
|
: mRequest(aRequest)
|
|
|
|
, mAutoTransaction(aTransaction)
|
2014-12-17 06:26:15 +00:00
|
|
|
, mResultType(ResultTypeDatabase)
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
mResult.mDatabase = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBCursor* aResult)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mAutoTransaction(aTransaction)
|
|
|
|
, mResultType(ResultTypeCursor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
|
|
|
|
mResult.mCursor = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
IDBMutableFile* aResult)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mAutoTransaction(aTransaction)
|
|
|
|
, mResultType(ResultTypeMutableFile)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
|
|
|
|
mResult.mMutableFile = aResult;
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
StructuredCloneReadInfo* aResult)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mAutoTransaction(aTransaction)
|
|
|
|
, mResultType(ResultTypeStructuredClone)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
|
|
|
mResult.mStructuredClone = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
const nsTArray<StructuredCloneReadInfo>* aResult)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mAutoTransaction(aTransaction)
|
|
|
|
, mResultType(ResultTypeStructuredCloneArray)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
|
|
|
mResult.mStructuredCloneArray = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
const Key* aResult)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mAutoTransaction(aTransaction)
|
|
|
|
, mResultType(ResultTypeKey)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
|
|
|
mResult.mKey = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
const nsTArray<Key>* aResult)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mAutoTransaction(aTransaction)
|
|
|
|
, mResultType(ResultTypeKeyArray)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
|
|
|
mResult.mKeyArray = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
const JS::Value* aResult)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mAutoTransaction(aTransaction)
|
|
|
|
, mResultType(ResultTypeJSVal)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
MOZ_ASSERT(!aResult->isGCThing());
|
|
|
|
|
|
|
|
mResult.mJSVal = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper(IDBRequest* aRequest,
|
|
|
|
IDBTransaction* aTransaction,
|
|
|
|
const JS::Handle<JS::Value>* aResult)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mAutoTransaction(aTransaction)
|
|
|
|
, mResultType(ResultTypeJSValHandle)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
|
|
|
|
mResult.mJSValHandle = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBRequest*
|
|
|
|
Request() const
|
|
|
|
{
|
|
|
|
return mRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBTransaction*
|
|
|
|
Transaction() const
|
|
|
|
{
|
|
|
|
return mAutoTransaction.Transaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsresult
|
2015-03-21 16:28:04 +00:00
|
|
|
GetResult(JSContext* aCx, JS::MutableHandle<JS::Value> aResult) override
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCx);
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
switch (mResultType) {
|
2014-12-17 06:26:15 +00:00
|
|
|
case ResultTypeDatabase:
|
|
|
|
return GetResult(aCx, mResult.mDatabase, aResult);
|
|
|
|
|
|
|
|
case ResultTypeCursor:
|
|
|
|
return GetResult(aCx, mResult.mCursor, aResult);
|
|
|
|
|
|
|
|
case ResultTypeMutableFile:
|
|
|
|
return GetResult(aCx, mResult.mMutableFile, aResult);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
case ResultTypeStructuredClone:
|
|
|
|
return GetResult(aCx, mResult.mStructuredClone, aResult);
|
|
|
|
|
|
|
|
case ResultTypeStructuredCloneArray:
|
|
|
|
return GetResult(aCx, mResult.mStructuredCloneArray, aResult);
|
|
|
|
|
|
|
|
case ResultTypeKey:
|
|
|
|
return GetResult(aCx, mResult.mKey, aResult);
|
|
|
|
|
|
|
|
case ResultTypeKeyArray:
|
|
|
|
return GetResult(aCx, mResult.mKeyArray, aResult);
|
|
|
|
|
|
|
|
case ResultTypeJSVal:
|
|
|
|
aResult.set(*mResult.mJSVal);
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case ResultTypeJSValHandle:
|
|
|
|
aResult.set(*mResult.mJSValHandle);
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown result type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-12-17 06:26:15 +00:00
|
|
|
template <class T>
|
|
|
|
typename EnableIf<IsSame<T, IDBDatabase>::value ||
|
|
|
|
IsSame<T, IDBCursor>::value ||
|
|
|
|
IsSame<T, IDBMutableFile>::value,
|
|
|
|
nsresult>::Type
|
2014-09-26 23:21:57 +00:00
|
|
|
GetResult(JSContext* aCx,
|
2014-12-17 06:26:15 +00:00
|
|
|
T* aDOMObject,
|
2014-09-26 23:21:57 +00:00
|
|
|
JS::MutableHandle<JS::Value> aResult)
|
|
|
|
{
|
2014-12-17 06:26:15 +00:00
|
|
|
if (!aDOMObject) {
|
2014-09-26 23:21:57 +00:00
|
|
|
aResult.setNull();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
bool ok = GetOrCreateDOMReflector(aCx, aDOMObject, aResult);
|
|
|
|
if (NS_WARN_IF(!ok)) {
|
2014-09-26 23:21:57 +00:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetResult(JSContext* aCx,
|
|
|
|
StructuredCloneReadInfo* aCloneInfo,
|
|
|
|
JS::MutableHandle<JS::Value> aResult)
|
|
|
|
{
|
|
|
|
bool ok = IDBObjectStore::DeserializeValue(aCx, *aCloneInfo, aResult);
|
|
|
|
|
|
|
|
aCloneInfo->mCloneBuffer.clear();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!ok)) {
|
|
|
|
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetResult(JSContext* aCx,
|
|
|
|
const nsTArray<StructuredCloneReadInfo>* aCloneInfos,
|
|
|
|
JS::MutableHandle<JS::Value> aResult)
|
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, 0));
|
|
|
|
if (NS_WARN_IF(!array)) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aCloneInfos->IsEmpty()) {
|
|
|
|
const uint32_t count = aCloneInfos->Length();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!JS_SetArrayLength(aCx, array, count))) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < count; index++) {
|
|
|
|
auto& cloneInfo =
|
|
|
|
const_cast<StructuredCloneReadInfo&>(aCloneInfos->ElementAt(index));
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
|
|
|
|
nsresult rv = GetResult(aCx, &cloneInfo, &value);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-03-02 13:31:15 +00:00
|
|
|
if (NS_WARN_IF(!JS_DefineElement(aCx, array, index, value,
|
|
|
|
JSPROP_ENUMERATE))) {
|
2014-09-26 23:21:57 +00:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.setObject(*array);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetResult(JSContext* aCx,
|
|
|
|
const Key* aKey,
|
|
|
|
JS::MutableHandle<JS::Value> aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = aKey->ToJSVal(aCx, aResult);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetResult(JSContext* aCx,
|
|
|
|
const nsTArray<Key>* aKeys,
|
|
|
|
JS::MutableHandle<JS::Value> aResult)
|
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, 0));
|
|
|
|
if (NS_WARN_IF(!array)) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aKeys->IsEmpty()) {
|
|
|
|
const uint32_t count = aKeys->Length();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!JS_SetArrayLength(aCx, array, count))) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < count; index++) {
|
|
|
|
const Key& key = aKeys->ElementAt(index);
|
|
|
|
MOZ_ASSERT(!key.IsUnset());
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
|
|
|
|
nsresult rv = GetResult(aCx, &key, &value);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-03-02 13:31:15 +00:00
|
|
|
if (NS_WARN_IF(!JS_DefineElement(aCx, array, index, value,
|
|
|
|
JSPROP_ENUMERATE))) {
|
2014-09-26 23:21:57 +00:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.setObject(*array);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class PermissionRequestMainProcessHelper final
|
2014-09-26 23:21:57 +00:00
|
|
|
: public PermissionRequestBase
|
|
|
|
{
|
|
|
|
BackgroundFactoryRequestChild* mActor;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBFactory> mFactory;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
PermissionRequestMainProcessHelper(BackgroundFactoryRequestChild* aActor,
|
|
|
|
IDBFactory* aFactory,
|
2015-04-10 16:10:00 +00:00
|
|
|
Element* aOwnerElement,
|
2014-09-26 23:21:57 +00:00
|
|
|
nsIPrincipal* aPrincipal)
|
2015-04-10 16:10:00 +00:00
|
|
|
: PermissionRequestBase(aOwnerElement, aPrincipal)
|
2014-09-26 23:21:57 +00:00
|
|
|
, mActor(aActor)
|
|
|
|
, mFactory(aFactory)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
aActor->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~PermissionRequestMainProcessHelper()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual void
|
2015-03-21 16:28:04 +00:00
|
|
|
OnPromptComplete(PermissionValue aPermissionValue) override;
|
2014-09-26 23:21:57 +00:00
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class PermissionRequestChildProcessActor final
|
2014-09-26 23:21:57 +00:00
|
|
|
: public PIndexedDBPermissionRequestChild
|
|
|
|
{
|
|
|
|
BackgroundFactoryRequestChild* mActor;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBFactory> mFactory;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
PermissionRequestChildProcessActor(BackgroundFactoryRequestChild* aActor,
|
|
|
|
IDBFactory* aFactory)
|
|
|
|
: mActor(aActor)
|
|
|
|
, mFactory(aFactory)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
aActor->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~PermissionRequestChildProcessActor()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual bool
|
2015-03-21 16:28:04 +00:00
|
|
|
Recv__delete__(const uint32_t& aPermission) override;
|
2014-09-26 23:21:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ConvertActorsToBlobs(IDBDatabase* aDatabase,
|
|
|
|
const SerializedStructuredCloneReadInfo& aCloneReadInfo,
|
|
|
|
nsTArray<StructuredCloneFile>& aFiles)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aFiles.IsEmpty());
|
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
const nsTArray<BlobOrMutableFile>& blobs = aCloneReadInfo.blobs();
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
if (!blobs.IsEmpty()) {
|
|
|
|
const uint32_t count = blobs.Length();
|
|
|
|
aFiles.SetCapacity(count);
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < count; index++) {
|
2015-09-09 11:15:05 +00:00
|
|
|
const BlobOrMutableFile& blobOrMutableFile = blobs[index];
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
switch (blobOrMutableFile.type()) {
|
|
|
|
case BlobOrMutableFile::TPBlobChild: {
|
|
|
|
auto* actor =
|
|
|
|
static_cast<BlobChild*>(blobOrMutableFile.get_PBlobChild());
|
2014-10-08 16:15:22 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<BlobImpl> blobImpl = actor->GetBlobImpl();
|
2015-09-09 11:15:05 +00:00
|
|
|
MOZ_ASSERT(blobImpl);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Blob> blob = Blob::Create(aDatabase->GetOwner(), blobImpl);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
aDatabase->NoteReceivedBlob(blob);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
StructuredCloneFile* file = aFiles.AppendElement();
|
|
|
|
MOZ_ASSERT(file);
|
|
|
|
|
|
|
|
file->mMutable = false;
|
|
|
|
file->mBlob.swap(blob);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BlobOrMutableFile::TNullableMutableFile: {
|
|
|
|
const NullableMutableFile& nullableMutableFile =
|
|
|
|
blobOrMutableFile.get_NullableMutableFile();
|
|
|
|
|
|
|
|
switch (nullableMutableFile.type()) {
|
|
|
|
case NullableMutableFile::Tnull_t: {
|
|
|
|
StructuredCloneFile* file = aFiles.AppendElement();
|
|
|
|
MOZ_ASSERT(file);
|
|
|
|
|
|
|
|
file->mMutable = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NullableMutableFile::TPBackgroundMutableFileChild: {
|
|
|
|
auto* actor =
|
|
|
|
static_cast<BackgroundMutableFileChild*>(
|
|
|
|
nullableMutableFile.get_PBackgroundMutableFileChild());
|
|
|
|
MOZ_ASSERT(actor);
|
|
|
|
|
|
|
|
actor->EnsureDOMObject();
|
|
|
|
|
|
|
|
auto* mutableFile =
|
|
|
|
static_cast<IDBMutableFile*>(actor->GetDOMObject());
|
|
|
|
MOZ_ASSERT(mutableFile);
|
|
|
|
|
|
|
|
StructuredCloneFile* file = aFiles.AppendElement();
|
|
|
|
MOZ_ASSERT(file);
|
|
|
|
|
|
|
|
file->mMutable = true;
|
|
|
|
file->mMutableFile = mutableFile;
|
|
|
|
|
|
|
|
actor->ReleaseDOMObject();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DispatchErrorEvent(IDBRequest* aRequest,
|
|
|
|
nsresult aErrorCode,
|
|
|
|
IDBTransaction* aTransaction = nullptr,
|
|
|
|
nsIDOMEvent* aEvent = nullptr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
aRequest->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aErrorCode));
|
|
|
|
MOZ_ASSERT(NS_ERROR_GET_MODULE(aErrorCode) == NS_ERROR_MODULE_DOM_INDEXEDDB);
|
|
|
|
|
|
|
|
PROFILER_LABEL("IndexedDB",
|
|
|
|
"DispatchErrorEvent",
|
|
|
|
js::ProfileEntry::Category::STORAGE);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBRequest> request = aRequest;
|
|
|
|
RefPtr<IDBTransaction> transaction = aTransaction;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
request->SetError(aErrorCode);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> errorEvent;
|
|
|
|
if (!aEvent) {
|
|
|
|
// Make an error event and fire it at the target.
|
|
|
|
errorEvent = CreateGenericEvent(request,
|
|
|
|
nsDependentString(kErrorEventType),
|
|
|
|
eDoesBubble,
|
|
|
|
eCancelable);
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(errorEvent);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
aEvent = errorEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<AutoSetCurrentTransaction> asct;
|
|
|
|
if (aTransaction) {
|
|
|
|
asct.emplace(aTransaction);
|
|
|
|
}
|
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
if (transaction) {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"Firing %s event with error 0x%x",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: %s (0x%x)",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(aEvent, kErrorEventType),
|
|
|
|
aErrorCode);
|
|
|
|
} else {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Request[%llu]: "
|
|
|
|
"Firing %s event with error 0x%x",
|
|
|
|
"IndexedDB %s: C R[%llu]: %s (0x%x)",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(aEvent, kErrorEventType),
|
|
|
|
aErrorCode);
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool doDefault;
|
|
|
|
nsresult rv = request->DispatchEvent(aEvent, &doDefault);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!transaction || transaction->IsOpen() || transaction->IsAborted());
|
|
|
|
|
|
|
|
if (transaction && transaction->IsOpen()) {
|
|
|
|
WidgetEvent* internalEvent = aEvent->GetInternalNSEvent();
|
|
|
|
MOZ_ASSERT(internalEvent);
|
|
|
|
|
|
|
|
if (internalEvent->mFlags.mExceptionHasBeenRisen) {
|
|
|
|
transaction->Abort(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
|
|
|
|
} else if (doDefault) {
|
|
|
|
transaction->Abort(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:03:01 +00:00
|
|
|
void
|
|
|
|
DispatchSuccessEvent(ResultHelper* aResultHelper,
|
|
|
|
nsIDOMEvent* aEvent = nullptr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aResultHelper);
|
|
|
|
|
|
|
|
PROFILER_LABEL("IndexedDB",
|
|
|
|
"DispatchSuccessEvent",
|
|
|
|
js::ProfileEntry::Category::STORAGE);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBRequest> request = aResultHelper->Request();
|
2014-11-20 03:03:01 +00:00
|
|
|
MOZ_ASSERT(request);
|
|
|
|
request->AssertIsOnOwningThread();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBTransaction> transaction = aResultHelper->Transaction();
|
2014-11-20 03:03:01 +00:00
|
|
|
|
|
|
|
if (transaction && transaction->IsAborted()) {
|
|
|
|
DispatchErrorEvent(request, transaction->AbortCode(), transaction);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> successEvent;
|
|
|
|
if (!aEvent) {
|
|
|
|
successEvent = CreateGenericEvent(request,
|
|
|
|
nsDependentString(kSuccessEventType),
|
|
|
|
eDoesNotBubble,
|
|
|
|
eNotCancelable);
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(successEvent);
|
2014-11-20 03:03:01 +00:00
|
|
|
|
|
|
|
aEvent = successEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
request->SetResultCallback(aResultHelper);
|
|
|
|
|
|
|
|
MOZ_ASSERT(aEvent);
|
|
|
|
MOZ_ASSERT_IF(transaction, transaction->IsOpen());
|
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
if (transaction) {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"Firing %s event",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: %s",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(aEvent, kSuccessEventType));
|
|
|
|
} else {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Request[%llu]: Firing %s event",
|
|
|
|
"IndexedDB %s: C R[%llu]: %s",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(aEvent, kSuccessEventType));
|
|
|
|
}
|
|
|
|
|
2014-11-20 03:03:01 +00:00
|
|
|
bool dummy;
|
|
|
|
nsresult rv = request->DispatchEvent(aEvent, &dummy);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT_IF(transaction,
|
|
|
|
transaction->IsOpen() || transaction->IsAborted());
|
|
|
|
|
|
|
|
WidgetEvent* internalEvent = aEvent->GetInternalNSEvent();
|
|
|
|
MOZ_ASSERT(internalEvent);
|
|
|
|
|
|
|
|
if (transaction &&
|
|
|
|
transaction->IsOpen() &&
|
|
|
|
internalEvent->mFlags.mExceptionHasBeenRisen) {
|
|
|
|
transaction->Abort(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 08:07:57 +00:00
|
|
|
class WorkerPermissionChallenge;
|
|
|
|
|
|
|
|
// This class calles WorkerPermissionChallenge::OperationCompleted() in the
|
|
|
|
// worker thread.
|
2015-09-08 08:11:36 +00:00
|
|
|
class WorkerPermissionOperationCompleted final : public WorkerControlRunnable
|
2015-05-06 08:07:57 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<WorkerPermissionChallenge> mChallenge;
|
2015-05-06 08:07:57 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
WorkerPermissionOperationCompleted(WorkerPrivate* aWorkerPrivate,
|
|
|
|
WorkerPermissionChallenge* aChallenge)
|
2015-09-08 08:11:36 +00:00
|
|
|
: WorkerControlRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
|
2015-05-06 08:07:57 +00:00
|
|
|
, mChallenge(aChallenge)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class used to do prompting in the main thread and main process.
|
|
|
|
class WorkerPermissionRequest final : public PermissionRequestBase
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<WorkerPermissionChallenge> mChallenge;
|
2015-05-06 08:07:57 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
WorkerPermissionRequest(Element* aElement,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
WorkerPermissionChallenge* aChallenge)
|
|
|
|
: PermissionRequestBase(aElement, aPrincipal)
|
|
|
|
, mChallenge(aChallenge)
|
|
|
|
{
|
2015-07-04 01:29:00 +00:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2015-05-06 08:07:57 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aChallenge);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~WorkerPermissionRequest()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
OnPromptComplete(PermissionValue aPermissionValue) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class is used in the main thread of all child processes.
|
|
|
|
class WorkerPermissionRequestChildProcessActor final
|
|
|
|
: public PIndexedDBPermissionRequestChild
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<WorkerPermissionChallenge> mChallenge;
|
2015-05-06 08:07:57 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit WorkerPermissionRequestChildProcessActor(
|
|
|
|
WorkerPermissionChallenge* aChallenge)
|
|
|
|
: mChallenge(aChallenge)
|
|
|
|
{
|
2015-07-04 01:29:00 +00:00
|
|
|
MOZ_ASSERT(!XRE_IsParentProcess());
|
2015-05-06 08:07:57 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aChallenge);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~WorkerPermissionRequestChildProcessActor()
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
Recv__delete__(const uint32_t& aPermission) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WorkerPermissionChallenge final : public nsRunnable
|
|
|
|
, public WorkerFeature
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WorkerPermissionChallenge(WorkerPrivate* aWorkerPrivate,
|
|
|
|
BackgroundFactoryRequestChild* aActor,
|
|
|
|
IDBFactory* aFactory,
|
|
|
|
const PrincipalInfo& aPrincipalInfo)
|
|
|
|
: mWorkerPrivate(aWorkerPrivate)
|
|
|
|
, mActor(aActor)
|
|
|
|
, mFactory(aFactory)
|
|
|
|
, mPrincipalInfo(aPrincipalInfo)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWorkerPrivate);
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
Run() override
|
|
|
|
{
|
|
|
|
bool completed = RunInternal();
|
|
|
|
if (completed) {
|
|
|
|
OperationCompleted();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
Notify(JSContext* aCx, workers::Status aStatus) override
|
|
|
|
{
|
|
|
|
// We don't care about the notification. We just want to keep the
|
|
|
|
// mWorkerPrivate alive.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OperationCompleted()
|
|
|
|
{
|
|
|
|
if (NS_IsMainThread()) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<WorkerPermissionOperationCompleted> runnable =
|
2015-05-06 08:07:57 +00:00
|
|
|
new WorkerPermissionOperationCompleted(mWorkerPrivate, this);
|
|
|
|
|
2015-09-08 08:11:36 +00:00
|
|
|
MOZ_ALWAYS_TRUE(runnable->Dispatch(nullptr));
|
2015-05-06 08:07:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mActor);
|
|
|
|
mActor->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBFactory> factory;
|
2015-05-06 08:07:57 +00:00
|
|
|
mFactory.swap(factory);
|
|
|
|
|
|
|
|
mActor->SendPermissionRetry();
|
|
|
|
mActor = nullptr;
|
|
|
|
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
JSContext* cx = mWorkerPrivate->GetJSContext();
|
|
|
|
mWorkerPrivate->RemoveFeature(cx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool
|
|
|
|
RunInternal()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// Walk up to our containing page
|
|
|
|
WorkerPrivate* wp = mWorkerPrivate;
|
|
|
|
while (wp->GetParent()) {
|
|
|
|
wp = wp->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindow* window = wp->GetWindow();
|
|
|
|
if (!window) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPrincipal> principal =
|
|
|
|
mozilla::ipc::PrincipalInfoToPrincipal(mPrincipalInfo, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-04 01:29:00 +00:00
|
|
|
if (XRE_IsParentProcess()) {
|
2015-05-06 08:07:57 +00:00
|
|
|
nsCOMPtr<Element> ownerElement =
|
|
|
|
do_QueryInterface(window->GetChromeEventHandler());
|
|
|
|
if (NS_WARN_IF(!ownerElement)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<WorkerPermissionRequest> helper =
|
2015-05-06 08:07:57 +00:00
|
|
|
new WorkerPermissionRequest(ownerElement, principal, this);
|
|
|
|
|
|
|
|
PermissionRequestBase::PermissionValue permission;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(helper->PromptIfNeeded(&permission)))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(permission == PermissionRequestBase::kPermissionAllowed ||
|
|
|
|
permission == PermissionRequestBase::kPermissionDenied ||
|
|
|
|
permission == PermissionRequestBase::kPermissionPrompt);
|
|
|
|
|
|
|
|
return permission != PermissionRequestBase::kPermissionPrompt;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabChild* tabChild = TabChild::GetFrom(window);
|
|
|
|
MOZ_ASSERT(tabChild);
|
|
|
|
|
|
|
|
IPC::Principal ipcPrincipal(principal);
|
|
|
|
|
|
|
|
auto* actor = new WorkerPermissionRequestChildProcessActor(this);
|
|
|
|
tabChild->SendPIndexedDBPermissionRequestConstructor(actor, ipcPrincipal);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
BackgroundFactoryRequestChild* mActor;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBFactory> mFactory;
|
2015-05-06 08:07:57 +00:00
|
|
|
PrincipalInfo mPrincipalInfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkerPermissionRequest::OnPromptComplete(PermissionValue aPermissionValue)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mChallenge->OperationCompleted();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WorkerPermissionOperationCompleted::WorkerRun(JSContext* aCx,
|
|
|
|
WorkerPrivate* aWorkerPrivate)
|
|
|
|
{
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
mChallenge->OperationCompleted();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WorkerPermissionRequestChildProcessActor::Recv__delete__(
|
|
|
|
const uint32_t& /* aPermission */)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mChallenge->OperationCompleted();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Local class implementations
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
PermissionRequestMainProcessHelper::OnPromptComplete(
|
|
|
|
PermissionValue aPermissionValue)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mActor);
|
|
|
|
mActor->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
mActor->SendPermissionRetry();
|
|
|
|
|
|
|
|
mActor = nullptr;
|
|
|
|
mFactory = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PermissionRequestChildProcessActor::Recv__delete__(
|
|
|
|
const uint32_t& /* aPermission */)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mActor);
|
|
|
|
mActor->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mFactory);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBFactory> factory;
|
2014-09-26 23:21:57 +00:00
|
|
|
mFactory.swap(factory);
|
|
|
|
|
|
|
|
mActor->SendPermissionRetry();
|
|
|
|
mActor = nullptr;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundRequestChildBase
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundRequestChildBase::BackgroundRequestChildBase(IDBRequest* aRequest)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
aRequest->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundRequestChildBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundRequestChildBase::~BackgroundRequestChildBase()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundRequestChildBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundRequestChildBase::AssertIsOnOwningThread() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
mRequest->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundFactoryChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundFactoryChild::BackgroundFactoryChild(IDBFactory* aFactory)
|
|
|
|
: mFactory(aFactory)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mOwningThread(NS_GetCurrentThread())
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
aFactory->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundFactoryChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundFactoryChild::~BackgroundFactoryChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundFactoryChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundFactoryChild::AssertIsOnOwningThread() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwningThread);
|
|
|
|
|
|
|
|
bool current;
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(¤t)));
|
|
|
|
MOZ_ASSERT(current);
|
|
|
|
}
|
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
nsIEventTarget*
|
|
|
|
BackgroundFactoryChild::OwningThread() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwningThread);
|
|
|
|
return mOwningThread;
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundFactoryChild::SendDeleteMeInternal()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mFactory) {
|
|
|
|
mFactory->ClearBackgroundActor();
|
|
|
|
mFactory = nullptr;
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(PBackgroundIDBFactoryChild::SendDeleteMe());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundFactoryChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (mFactory) {
|
|
|
|
mFactory->ClearBackgroundActor();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mFactory = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PBackgroundIDBFactoryRequestChild*
|
|
|
|
BackgroundFactoryChild::AllocPBackgroundIDBFactoryRequestChild(
|
|
|
|
const FactoryRequestParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("PBackgroundIDBFactoryRequestChild actors should be manually "
|
|
|
|
"constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundFactoryChild::DeallocPBackgroundIDBFactoryRequestChild(
|
|
|
|
PBackgroundIDBFactoryRequestChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundFactoryRequestChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBackgroundIDBDatabaseChild*
|
|
|
|
BackgroundFactoryChild::AllocPBackgroundIDBDatabaseChild(
|
|
|
|
const DatabaseSpec& aSpec,
|
|
|
|
PBackgroundIDBFactoryRequestChild* aRequest)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
auto request = static_cast<BackgroundFactoryRequestChild*>(aRequest);
|
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
|
|
|
return new BackgroundDatabaseChild(aSpec, request);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundFactoryChild::DeallocPBackgroundIDBDatabaseChild(
|
|
|
|
PBackgroundIDBDatabaseChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundDatabaseChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundFactoryRequestChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundFactoryRequestChild::BackgroundFactoryRequestChild(
|
|
|
|
IDBFactory* aFactory,
|
|
|
|
IDBOpenDBRequest* aOpenRequest,
|
|
|
|
bool aIsDeleteOp,
|
|
|
|
uint64_t aRequestedVersion)
|
|
|
|
: BackgroundRequestChildBase(aOpenRequest)
|
|
|
|
, mFactory(aFactory)
|
|
|
|
, mRequestedVersion(aRequestedVersion)
|
|
|
|
, mIsDeleteOp(aIsDeleteOp)
|
|
|
|
{
|
|
|
|
// Can't assert owning thread here because IPDL has not yet set our manager!
|
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
aFactory->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aOpenRequest);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundFactoryRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundFactoryRequestChild::~BackgroundFactoryRequestChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundFactoryRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBOpenDBRequest*
|
|
|
|
BackgroundFactoryRequestChild::GetOpenDBRequest() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2015-11-22 09:43:09 +00:00
|
|
|
return static_cast<IDBOpenDBRequest*>(mRequest.get());
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundFactoryRequestChild::HandleResponse(nsresult aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aResponse));
|
|
|
|
MOZ_ASSERT(NS_ERROR_GET_MODULE(aResponse) == NS_ERROR_MODULE_DOM_INDEXEDDB);
|
|
|
|
|
|
|
|
mRequest->Reset();
|
|
|
|
|
|
|
|
DispatchErrorEvent(mRequest, aResponse);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundFactoryRequestChild::HandleResponse(
|
|
|
|
const OpenDatabaseRequestResponse& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mRequest->Reset();
|
|
|
|
|
|
|
|
auto databaseActor =
|
|
|
|
static_cast<BackgroundDatabaseChild*>(aResponse.databaseChild());
|
|
|
|
MOZ_ASSERT(databaseActor);
|
|
|
|
|
|
|
|
IDBDatabase* database = databaseActor->GetDOMObject();
|
2015-06-20 16:08:30 +00:00
|
|
|
if (!database) {
|
|
|
|
databaseActor->EnsureDOMObject();
|
|
|
|
|
|
|
|
database = databaseActor->GetDOMObject();
|
|
|
|
MOZ_ASSERT(database);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!database->IsClosed());
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-06-20 16:08:30 +00:00
|
|
|
if (database->IsClosed()) {
|
|
|
|
// If the database was closed already, which is only possible if we fired an
|
|
|
|
// "upgradeneeded" event, then we shouldn't fire a "success" event here.
|
|
|
|
// Instead we fire an error event with AbortErr.
|
|
|
|
DispatchErrorEvent(mRequest, NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
|
|
|
|
} else {
|
|
|
|
ResultHelper helper(mRequest, nullptr, database);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-06-20 16:08:30 +00:00
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
databaseActor->ReleaseDOMObject();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundFactoryRequestChild::HandleResponse(
|
|
|
|
const DeleteDatabaseRequestResponse& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, nullptr, &JS::UndefinedHandleValue);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> successEvent =
|
|
|
|
IDBVersionChangeEvent::Create(mRequest,
|
|
|
|
nsDependentString(kSuccessEventType),
|
|
|
|
aResponse.previousVersion());
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(successEvent);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper, successEvent);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundFactoryRequestChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
if (aWhy != Deletion) {
|
|
|
|
IDBOpenDBRequest* openRequest = GetOpenDBRequest();
|
|
|
|
if (openRequest) {
|
|
|
|
openRequest->NoteComplete();
|
|
|
|
}
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundFactoryRequestChild::Recv__delete__(
|
|
|
|
const FactoryRequestResponse& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
bool result;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
switch (aResponse.type()) {
|
|
|
|
case FactoryRequestResponse::Tnsresult:
|
2014-12-17 06:26:15 +00:00
|
|
|
result = HandleResponse(aResponse.get_nsresult());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
case FactoryRequestResponse::TOpenDatabaseRequestResponse:
|
2014-12-17 06:26:15 +00:00
|
|
|
result = HandleResponse(aResponse.get_OpenDatabaseRequestResponse());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
case FactoryRequestResponse::TDeleteDatabaseRequestResponse:
|
2014-12-17 06:26:15 +00:00
|
|
|
result = HandleResponse(aResponse.get_DeleteDatabaseRequestResponse());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown response type!");
|
|
|
|
}
|
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
IDBOpenDBRequest* request = GetOpenDBRequest();
|
|
|
|
MOZ_ASSERT(request);
|
2015-03-02 13:31:15 +00:00
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
request->NoteComplete();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!result)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundFactoryRequestChild::RecvPermissionChallenge(
|
|
|
|
const PrincipalInfo& aPrincipalInfo)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (!NS_IsMainThread()) {
|
2015-05-06 08:07:57 +00:00
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
workerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<WorkerPermissionChallenge> challenge =
|
2015-05-06 08:07:57 +00:00
|
|
|
new WorkerPermissionChallenge(workerPrivate, this, mFactory,
|
|
|
|
aPrincipalInfo);
|
|
|
|
|
|
|
|
JSContext* cx = workerPrivate->GetJSContext();
|
|
|
|
MOZ_ASSERT(cx);
|
|
|
|
|
2015-09-08 08:11:36 +00:00
|
|
|
if (NS_WARN_IF(!workerPrivate->AddFeature(cx, challenge))) {
|
2015-05-06 08:07:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(challenge)));
|
|
|
|
return true;
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPrincipal> principal =
|
|
|
|
mozilla::ipc::PrincipalInfoToPrincipal(aPrincipalInfo, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-04 01:29:00 +00:00
|
|
|
if (XRE_IsParentProcess()) {
|
2014-09-26 23:21:57 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = mFactory->GetParentObject();
|
|
|
|
MOZ_ASSERT(window);
|
|
|
|
|
2015-04-10 16:10:00 +00:00
|
|
|
nsCOMPtr<Element> ownerElement =
|
|
|
|
do_QueryInterface(window->GetChromeEventHandler());
|
|
|
|
if (NS_WARN_IF(!ownerElement)) {
|
2015-09-08 08:11:36 +00:00
|
|
|
// If this fails, the page was navigated. Fail the permission check by
|
|
|
|
// forcing an immediate retry.
|
|
|
|
return SendPermissionRetry();
|
2015-04-10 16:10:00 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PermissionRequestMainProcessHelper> helper =
|
2015-04-10 16:10:00 +00:00
|
|
|
new PermissionRequestMainProcessHelper(this, mFactory, ownerElement, principal);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
PermissionRequestBase::PermissionValue permission;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(helper->PromptIfNeeded(&permission)))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(permission == PermissionRequestBase::kPermissionAllowed ||
|
|
|
|
permission == PermissionRequestBase::kPermissionDenied ||
|
|
|
|
permission == PermissionRequestBase::kPermissionPrompt);
|
|
|
|
|
|
|
|
if (permission != PermissionRequestBase::kPermissionPrompt) {
|
|
|
|
SendPermissionRetry();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TabChild> tabChild = mFactory->GetTabChild();
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(tabChild);
|
|
|
|
|
|
|
|
IPC::Principal ipcPrincipal(principal);
|
|
|
|
|
|
|
|
auto* actor = new PermissionRequestChildProcessActor(this, mFactory);
|
|
|
|
|
|
|
|
tabChild->SendPIndexedDBPermissionRequestConstructor(actor, ipcPrincipal);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundFactoryRequestChild::RecvBlocked(const uint64_t& aCurrentVersion)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
const nsDependentString type(kBlockedEventType);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> blockedEvent;
|
|
|
|
if (mIsDeleteOp) {
|
|
|
|
blockedEvent =
|
|
|
|
IDBVersionChangeEvent::Create(mRequest, type, aCurrentVersion);
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(blockedEvent);
|
2014-09-26 23:21:57 +00:00
|
|
|
} else {
|
|
|
|
blockedEvent =
|
|
|
|
IDBVersionChangeEvent::Create(mRequest,
|
|
|
|
type,
|
|
|
|
aCurrentVersion,
|
|
|
|
mRequestedVersion);
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(blockedEvent);
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBRequest> kungFuDeathGrip = mRequest;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Request[%llu]: Firing \"blocked\" event",
|
|
|
|
"IndexedDB %s: C R[%llu]: \"blocked\"",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
mRequest->LoggingSerialNumber());
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool dummy;
|
|
|
|
if (NS_FAILED(mRequest->DispatchEvent(blockedEvent, &dummy))) {
|
|
|
|
NS_WARNING("Failed to dispatch event!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundDatabaseChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundDatabaseChild::BackgroundDatabaseChild(
|
|
|
|
const DatabaseSpec& aSpec,
|
|
|
|
BackgroundFactoryRequestChild* aOpenRequestActor)
|
|
|
|
: mSpec(new DatabaseSpec(aSpec))
|
|
|
|
, mOpenRequestActor(aOpenRequestActor)
|
|
|
|
, mDatabase(nullptr)
|
|
|
|
{
|
|
|
|
// Can't assert owning thread here because IPDL has not yet set our manager!
|
|
|
|
MOZ_ASSERT(aOpenRequestActor);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundDatabaseChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundDatabaseChild::~BackgroundDatabaseChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundDatabaseChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundDatabaseChild::SendDeleteMeInternal()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mTemporaryStrongDatabase);
|
|
|
|
MOZ_ASSERT(!mOpenRequestActor);
|
|
|
|
|
|
|
|
if (mDatabase) {
|
|
|
|
mDatabase->ClearBackgroundActor();
|
|
|
|
mDatabase = nullptr;
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(PBackgroundIDBDatabaseChild::SendDeleteMe());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundDatabaseChild::EnsureDOMObject()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mOpenRequestActor);
|
|
|
|
|
|
|
|
if (mTemporaryStrongDatabase) {
|
|
|
|
MOZ_ASSERT(!mSpec);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mSpec);
|
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
auto request = mOpenRequestActor->GetOpenDBRequest();
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
|
|
|
auto factory =
|
|
|
|
static_cast<BackgroundFactoryChild*>(Manager())->GetDOMObject();
|
|
|
|
MOZ_ASSERT(factory);
|
|
|
|
|
|
|
|
mTemporaryStrongDatabase =
|
|
|
|
IDBDatabase::Create(request, factory, this, mSpec);
|
|
|
|
|
|
|
|
MOZ_ASSERT(mTemporaryStrongDatabase);
|
|
|
|
mTemporaryStrongDatabase->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mDatabase = mTemporaryStrongDatabase;
|
|
|
|
mSpec.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundDatabaseChild::ReleaseDOMObject()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTemporaryStrongDatabase);
|
|
|
|
mTemporaryStrongDatabase->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mOpenRequestActor);
|
|
|
|
MOZ_ASSERT(mDatabase == mTemporaryStrongDatabase);
|
|
|
|
|
|
|
|
mOpenRequestActor = nullptr;
|
|
|
|
|
|
|
|
// This may be the final reference to the IDBDatabase object so we may end up
|
|
|
|
// calling SendDeleteMeInternal() here. Make sure everything is cleaned up
|
|
|
|
// properly before proceeding.
|
|
|
|
mTemporaryStrongDatabase = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundDatabaseChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (mDatabase) {
|
|
|
|
mDatabase->ClearBackgroundActor();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mDatabase = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PBackgroundIDBDatabaseFileChild*
|
|
|
|
BackgroundDatabaseChild::AllocPBackgroundIDBDatabaseFileChild(
|
|
|
|
PBlobChild* aBlobChild)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("PBackgroundIDBFileChild actors should be manually constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundDatabaseChild::DeallocPBackgroundIDBDatabaseFileChild(
|
|
|
|
PBackgroundIDBDatabaseFileChild* aActor)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
PBackgroundIDBDatabaseRequestChild*
|
|
|
|
BackgroundDatabaseChild::AllocPBackgroundIDBDatabaseRequestChild(
|
|
|
|
const DatabaseRequestParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("PBackgroundIDBDatabaseRequestChild actors should be manually "
|
|
|
|
"constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundDatabaseChild::DeallocPBackgroundIDBDatabaseRequestChild(
|
|
|
|
PBackgroundIDBDatabaseRequestChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundDatabaseRequestChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
PBackgroundIDBTransactionChild*
|
|
|
|
BackgroundDatabaseChild::AllocPBackgroundIDBTransactionChild(
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
const Mode& aMode)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("PBackgroundIDBTransactionChild actors should be manually "
|
|
|
|
"constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundDatabaseChild::DeallocPBackgroundIDBTransactionChild(
|
|
|
|
PBackgroundIDBTransactionChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundTransactionChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBackgroundIDBVersionChangeTransactionChild*
|
|
|
|
BackgroundDatabaseChild::AllocPBackgroundIDBVersionChangeTransactionChild(
|
|
|
|
const uint64_t& aCurrentVersion,
|
|
|
|
const uint64_t& aRequestedVersion,
|
|
|
|
const int64_t& aNextObjectStoreId,
|
|
|
|
const int64_t& aNextIndexId)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
IDBOpenDBRequest* request = mOpenRequestActor->GetOpenDBRequest();
|
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
|
|
|
return new BackgroundVersionChangeTransactionChild(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundDatabaseChild::RecvPBackgroundIDBVersionChangeTransactionConstructor(
|
|
|
|
PBackgroundIDBVersionChangeTransactionChild* aActor,
|
|
|
|
const uint64_t& aCurrentVersion,
|
|
|
|
const uint64_t& aRequestedVersion,
|
|
|
|
const int64_t& aNextObjectStoreId,
|
|
|
|
const int64_t& aNextIndexId)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
MOZ_ASSERT(mOpenRequestActor);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
EnsureDOMObject();
|
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
auto* actor = static_cast<BackgroundVersionChangeTransactionChild*>(aActor);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBOpenDBRequest> request = mOpenRequestActor->GetOpenDBRequest();
|
2014-11-14 02:20:38 +00:00
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBTransaction> transaction =
|
2014-11-14 02:20:38 +00:00
|
|
|
IDBTransaction::CreateVersionChange(mDatabase,
|
|
|
|
actor,
|
|
|
|
request,
|
|
|
|
aNextObjectStoreId,
|
2014-09-26 23:21:57 +00:00
|
|
|
aNextIndexId);
|
|
|
|
if (NS_WARN_IF(!transaction)) {
|
2014-12-17 06:26:15 +00:00
|
|
|
// This can happen if we receive events after a worker has begun its
|
|
|
|
// shutdown process.
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
|
|
|
// Report this to the console.
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(aActor->SendDeleteMe());
|
|
|
|
return true;
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
transaction->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
actor->SetDOMTransaction(transaction);
|
|
|
|
|
|
|
|
mDatabase->EnterSetVersionTransaction(aRequestedVersion);
|
|
|
|
|
|
|
|
request->SetTransaction(transaction);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> upgradeNeededEvent =
|
|
|
|
IDBVersionChangeEvent::Create(request,
|
|
|
|
nsDependentString(kUpgradeNeededEventType),
|
|
|
|
aCurrentVersion,
|
|
|
|
aRequestedVersion);
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(upgradeNeededEvent);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
ResultHelper helper(request, transaction, mDatabase);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper, upgradeNeededEvent);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundDatabaseChild::DeallocPBackgroundIDBVersionChangeTransactionChild(
|
|
|
|
PBackgroundIDBVersionChangeTransactionChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundVersionChangeTransactionChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
PBackgroundMutableFileChild*
|
|
|
|
BackgroundDatabaseChild::AllocPBackgroundMutableFileChild(const nsString& aName,
|
|
|
|
const nsString& aType)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIThread> owningThread = do_QueryInterface(OwningThread());
|
|
|
|
|
|
|
|
PRThread* owningPRThread;
|
|
|
|
owningThread->GetPRThread(&owningPRThread);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return new BackgroundMutableFileChild(DEBUGONLY(owningPRThread,)
|
|
|
|
aName,
|
|
|
|
aType);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundDatabaseChild::DeallocPBackgroundMutableFileChild(
|
|
|
|
PBackgroundMutableFileChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundMutableFileChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool
|
|
|
|
BackgroundDatabaseChild::RecvVersionChange(const uint64_t& aOldVersion,
|
|
|
|
const NullableVersion& aNewVersion)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (!mDatabase || mDatabase->IsClosed()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBDatabase> kungFuDeathGrip = mDatabase;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
// Handle bfcache'd windows.
|
|
|
|
if (nsPIDOMWindow* owner = mDatabase->GetOwner()) {
|
|
|
|
// The database must be closed if the window is already frozen.
|
|
|
|
bool shouldAbortAndClose = owner->IsFrozen();
|
|
|
|
|
|
|
|
// Anything in the bfcache has to be evicted and then we have to close the
|
|
|
|
// database also.
|
|
|
|
if (nsCOMPtr<nsIDocument> doc = owner->GetExtantDoc()) {
|
|
|
|
if (nsCOMPtr<nsIBFCacheEntry> bfCacheEntry = doc->GetBFCacheEntry()) {
|
|
|
|
bfCacheEntry->RemoveFromBFCacheSync();
|
|
|
|
shouldAbortAndClose = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldAbortAndClose) {
|
|
|
|
// Invalidate() doesn't close the database in the parent, so we have
|
|
|
|
// to call Close() and AbortTransactions() manually.
|
2014-11-14 02:20:38 +00:00
|
|
|
mDatabase->AbortTransactions(/* aShouldWarn */ false);
|
2014-09-26 23:21:57 +00:00
|
|
|
mDatabase->Close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise fire a versionchange event.
|
|
|
|
const nsDependentString type(kVersionChangeEventType);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> versionChangeEvent;
|
|
|
|
|
|
|
|
switch (aNewVersion.type()) {
|
|
|
|
case NullableVersion::Tnull_t:
|
|
|
|
versionChangeEvent =
|
|
|
|
IDBVersionChangeEvent::Create(mDatabase, type, aOldVersion);
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(versionChangeEvent);
|
2014-09-26 23:21:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NullableVersion::Tuint64_t:
|
|
|
|
versionChangeEvent =
|
|
|
|
IDBVersionChangeEvent::Create(mDatabase,
|
|
|
|
type,
|
|
|
|
aOldVersion,
|
|
|
|
aNewVersion.get_uint64_t());
|
2014-12-17 06:26:15 +00:00
|
|
|
MOZ_ASSERT(versionChangeEvent);
|
2014-09-26 23:21:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child : Firing \"versionchange\" event",
|
|
|
|
"IndexedDB %s: C: IDBDatabase \"versionchange\" event",
|
|
|
|
IDB_LOG_ID_STRING());
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool dummy;
|
|
|
|
if (NS_FAILED(mDatabase->DispatchEvent(versionChangeEvent, &dummy))) {
|
|
|
|
NS_WARNING("Failed to dispatch event!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDatabase->IsClosed()) {
|
|
|
|
SendBlocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundDatabaseChild::RecvInvalidate()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (mDatabase) {
|
|
|
|
mDatabase->Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundDatabaseRequestChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundDatabaseRequestChild::BackgroundDatabaseRequestChild(
|
|
|
|
IDBDatabase* aDatabase,
|
|
|
|
IDBRequest* aRequest)
|
|
|
|
: BackgroundRequestChildBase(aRequest)
|
|
|
|
, mDatabase(aDatabase)
|
|
|
|
{
|
|
|
|
// Can't assert owning thread here because IPDL has not yet set our manager!
|
|
|
|
MOZ_ASSERT(aDatabase);
|
|
|
|
aDatabase->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundDatabaseRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundDatabaseRequestChild::~BackgroundDatabaseRequestChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundDatabaseRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundDatabaseRequestChild::HandleResponse(nsresult aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aResponse));
|
|
|
|
MOZ_ASSERT(NS_ERROR_GET_MODULE(aResponse) == NS_ERROR_MODULE_DOM_INDEXEDDB);
|
|
|
|
|
|
|
|
mRequest->Reset();
|
|
|
|
|
|
|
|
DispatchErrorEvent(mRequest, aResponse);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundDatabaseRequestChild::HandleResponse(
|
|
|
|
const CreateFileRequestResponse& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mRequest->Reset();
|
|
|
|
|
|
|
|
auto mutableFileActor =
|
|
|
|
static_cast<BackgroundMutableFileChild*>(aResponse.mutableFileChild());
|
|
|
|
MOZ_ASSERT(mutableFileActor);
|
|
|
|
|
|
|
|
mutableFileActor->EnsureDOMObject();
|
|
|
|
|
|
|
|
auto mutableFile =
|
|
|
|
static_cast<IDBMutableFile*>(mutableFileActor->GetDOMObject());
|
|
|
|
MOZ_ASSERT(mutableFile);
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, nullptr, mutableFile);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
|
|
|
|
mutableFileActor->ReleaseDOMObject();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundDatabaseRequestChild::Recv__delete__(
|
|
|
|
const DatabaseRequestResponse& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
switch (aResponse.type()) {
|
|
|
|
case DatabaseRequestResponse::Tnsresult:
|
|
|
|
return HandleResponse(aResponse.get_nsresult());
|
|
|
|
|
|
|
|
case DatabaseRequestResponse::TCreateFileRequestResponse:
|
|
|
|
return HandleResponse(aResponse.get_CreateFileRequestResponse());
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown response type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundTransactionBase
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundTransactionBase::BackgroundTransactionBase()
|
|
|
|
: mTransaction(nullptr)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundTransactionBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundTransactionBase::BackgroundTransactionBase(
|
|
|
|
IDBTransaction* aTransaction)
|
|
|
|
: mTemporaryStrongTransaction(aTransaction)
|
|
|
|
, mTransaction(aTransaction)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTransaction);
|
|
|
|
aTransaction->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundTransactionBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundTransactionBase::~BackgroundTransactionBase()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundTransactionBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundTransactionBase::AssertIsOnOwningThread() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
mTransaction->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundTransactionBase::NoteActorDestroyed()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT_IF(mTemporaryStrongTransaction, mTransaction);
|
|
|
|
|
|
|
|
if (mTransaction) {
|
|
|
|
mTransaction->ClearBackgroundActor();
|
|
|
|
|
|
|
|
// Normally this would be DEBUG-only but NoteActorDestroyed is also called
|
|
|
|
// from SendDeleteMeInternal. In that case we're going to receive an actual
|
|
|
|
// ActorDestroy call later and we don't want to touch a dead object.
|
|
|
|
mTemporaryStrongTransaction = nullptr;
|
|
|
|
mTransaction = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundTransactionBase::SetDOMTransaction(IDBTransaction* aTransaction)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aTransaction);
|
|
|
|
aTransaction->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mTemporaryStrongTransaction);
|
|
|
|
MOZ_ASSERT(!mTransaction);
|
|
|
|
|
|
|
|
mTemporaryStrongTransaction = aTransaction;
|
|
|
|
mTransaction = aTransaction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundTransactionBase::NoteComplete()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT_IF(mTransaction, mTemporaryStrongTransaction);
|
|
|
|
|
|
|
|
mTemporaryStrongTransaction = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundTransactionChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundTransactionChild::BackgroundTransactionChild(
|
|
|
|
IDBTransaction* aTransaction)
|
|
|
|
: BackgroundTransactionBase(aTransaction)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTransaction);
|
|
|
|
aTransaction->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundTransactionChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundTransactionChild::~BackgroundTransactionChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundTransactionChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundTransactionChild::AssertIsOnOwningThread() const
|
|
|
|
{
|
|
|
|
static_cast<BackgroundDatabaseChild*>(Manager())->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundTransactionChild::SendDeleteMeInternal()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mTransaction) {
|
|
|
|
NoteActorDestroyed();
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(PBackgroundIDBTransactionChild::SendDeleteMe());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundTransactionChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
NoteActorDestroyed();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundTransactionChild::RecvComplete(const nsresult& aResult)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
mTransaction->FireCompleteOrAbortEvents(aResult);
|
|
|
|
|
|
|
|
NoteComplete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBackgroundIDBRequestChild*
|
|
|
|
BackgroundTransactionChild::AllocPBackgroundIDBRequestChild(
|
|
|
|
const RequestParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("PBackgroundIDBRequestChild actors should be manually "
|
|
|
|
"constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundTransactionChild::DeallocPBackgroundIDBRequestChild(
|
|
|
|
PBackgroundIDBRequestChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundRequestChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBackgroundIDBCursorChild*
|
|
|
|
BackgroundTransactionChild::AllocPBackgroundIDBCursorChild(
|
|
|
|
const OpenCursorParams& aParams)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_CRASH("PBackgroundIDBCursorChild actors should be manually constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundTransactionChild::DeallocPBackgroundIDBCursorChild(
|
|
|
|
PBackgroundIDBCursorChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundCursorChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundVersionChangeTransactionChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundVersionChangeTransactionChild::
|
|
|
|
BackgroundVersionChangeTransactionChild(IDBOpenDBRequest* aOpenDBRequest)
|
|
|
|
: mOpenDBRequest(aOpenDBRequest)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aOpenDBRequest);
|
|
|
|
aOpenDBRequest->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundVersionChangeTransactionChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundVersionChangeTransactionChild::
|
|
|
|
~BackgroundVersionChangeTransactionChild()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundVersionChangeTransactionChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundVersionChangeTransactionChild::AssertIsOnOwningThread() const
|
|
|
|
{
|
|
|
|
static_cast<BackgroundDatabaseChild*>(Manager())->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void
|
2014-12-17 06:26:15 +00:00
|
|
|
BackgroundVersionChangeTransactionChild::SendDeleteMeInternal(
|
|
|
|
bool aFailedConstructor)
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
if (mTransaction || aFailedConstructor) {
|
2014-09-26 23:21:57 +00:00
|
|
|
NoteActorDestroyed();
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(PBackgroundIDBVersionChangeTransactionChild::
|
|
|
|
SendDeleteMe());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundVersionChangeTransactionChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
mOpenDBRequest = nullptr;
|
|
|
|
|
|
|
|
NoteActorDestroyed();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundVersionChangeTransactionChild::RecvComplete(const nsresult& aResult)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (!mTransaction) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mOpenDBRequest);
|
|
|
|
|
|
|
|
IDBDatabase* database = mTransaction->Database();
|
|
|
|
MOZ_ASSERT(database);
|
|
|
|
|
|
|
|
database->ExitSetVersionTransaction();
|
|
|
|
|
|
|
|
if (NS_FAILED(aResult)) {
|
|
|
|
database->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
mTransaction->FireCompleteOrAbortEvents(aResult);
|
|
|
|
|
|
|
|
mOpenDBRequest->SetTransaction(nullptr);
|
|
|
|
mOpenDBRequest = nullptr;
|
|
|
|
|
|
|
|
NoteComplete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBackgroundIDBRequestChild*
|
|
|
|
BackgroundVersionChangeTransactionChild::AllocPBackgroundIDBRequestChild(
|
|
|
|
const RequestParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("PBackgroundIDBRequestChild actors should be manually "
|
|
|
|
"constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundVersionChangeTransactionChild::DeallocPBackgroundIDBRequestChild(
|
|
|
|
PBackgroundIDBRequestChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundRequestChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBackgroundIDBCursorChild*
|
|
|
|
BackgroundVersionChangeTransactionChild::AllocPBackgroundIDBCursorChild(
|
|
|
|
const OpenCursorParams& aParams)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_CRASH("PBackgroundIDBCursorChild actors should be manually constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundVersionChangeTransactionChild::DeallocPBackgroundIDBCursorChild(
|
|
|
|
PBackgroundIDBCursorChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundCursorChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundMutableFileChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundMutableFileChild::BackgroundMutableFileChild(
|
|
|
|
DEBUGONLY(PRThread* aOwningThread,)
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsAString& aType)
|
|
|
|
: BackgroundMutableFileChildBase(DEBUGONLY(aOwningThread))
|
|
|
|
, mName(aName)
|
|
|
|
, mType(aType)
|
|
|
|
{
|
|
|
|
// Can't assert owning thread here because IPDL has not yet set our manager!
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundMutableFileChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundMutableFileChild::~BackgroundMutableFileChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundMutableFileChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<MutableFileBase>
|
|
|
|
BackgroundMutableFileChild::CreateMutableFile()
|
|
|
|
{
|
|
|
|
auto database =
|
|
|
|
static_cast<BackgroundDatabaseChild*>(Manager())->GetDOMObject();
|
|
|
|
MOZ_ASSERT(database);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBMutableFile> mutableFile =
|
2015-09-09 11:15:05 +00:00
|
|
|
new IDBMutableFile(database, this, mName, mType);
|
|
|
|
|
|
|
|
return mutableFile.forget();
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundRequestChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundRequestChild::BackgroundRequestChild(IDBRequest* aRequest)
|
|
|
|
: BackgroundRequestChildBase(aRequest)
|
|
|
|
, mTransaction(aRequest->GetTransaction())
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
mTransaction->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundRequestChild::~BackgroundRequestChild()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2015-03-18 21:20:59 +00:00
|
|
|
MOZ_ASSERT(!mTransaction);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundRequestChild::HandleResponse(nsresult aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aResponse));
|
|
|
|
MOZ_ASSERT(NS_ERROR_GET_MODULE(aResponse) == NS_ERROR_MODULE_DOM_INDEXEDDB);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
|
|
|
|
DispatchErrorEvent(mRequest, aResponse, mTransaction);
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
BackgroundRequestChild::HandleResponse(const Key& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &aResponse);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
BackgroundRequestChild::HandleResponse(const nsTArray<Key>& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &aResponse);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
BackgroundRequestChild::HandleResponse(
|
|
|
|
const SerializedStructuredCloneReadInfo& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
// XXX Fix this somehow...
|
|
|
|
auto& serializedCloneInfo =
|
|
|
|
const_cast<SerializedStructuredCloneReadInfo&>(aResponse);
|
|
|
|
|
|
|
|
StructuredCloneReadInfo cloneReadInfo(Move(serializedCloneInfo));
|
|
|
|
|
|
|
|
ConvertActorsToBlobs(mTransaction->Database(),
|
|
|
|
aResponse,
|
|
|
|
cloneReadInfo.mFiles);
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &cloneReadInfo);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
BackgroundRequestChild::HandleResponse(
|
|
|
|
const nsTArray<SerializedStructuredCloneReadInfo>& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
nsTArray<StructuredCloneReadInfo> cloneReadInfos;
|
|
|
|
|
|
|
|
if (!aResponse.IsEmpty()) {
|
|
|
|
const uint32_t count = aResponse.Length();
|
|
|
|
|
|
|
|
cloneReadInfos.SetCapacity(count);
|
|
|
|
|
|
|
|
IDBDatabase* database = mTransaction->Database();
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < count; index++) {
|
|
|
|
// XXX Fix this somehow...
|
|
|
|
auto& serializedCloneInfo =
|
|
|
|
const_cast<SerializedStructuredCloneReadInfo&>(aResponse[index]);
|
|
|
|
|
|
|
|
StructuredCloneReadInfo* cloneReadInfo = cloneReadInfos.AppendElement();
|
|
|
|
|
2015-09-05 04:47:07 +00:00
|
|
|
// Get the files
|
|
|
|
nsTArray<StructuredCloneFile> files;
|
|
|
|
ConvertActorsToBlobs(database, serializedCloneInfo, files);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-09-05 04:47:07 +00:00
|
|
|
// Move relevant data into the cloneReadInfo
|
|
|
|
*cloneReadInfo = Move(serializedCloneInfo);
|
|
|
|
cloneReadInfo->mFiles = Move(files);
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &cloneReadInfos);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
BackgroundRequestChild::HandleResponse(JS::Handle<JS::Value> aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &aResponse);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
BackgroundRequestChild::HandleResponse(uint64_t aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
JS::Value response(JS::NumberValue(aResponse));
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &response);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundRequestChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
if (mTransaction) {
|
|
|
|
mTransaction->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mTransaction->OnRequestFinished(/* aActorDestroyedNormally */
|
|
|
|
aWhy == Deletion);
|
|
|
|
#ifdef DEBUG
|
|
|
|
mTransaction = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundRequestChild::Recv__delete__(const RequestResponse& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (mTransaction->IsAborted()) {
|
2015-03-18 21:20:59 +00:00
|
|
|
// Always fire an "error" event with ABORT_ERR if the transaction was
|
|
|
|
// aborted, even if the request succeeded or failed with another error.
|
|
|
|
HandleResponse(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
|
|
|
|
} else {
|
|
|
|
switch (aResponse.type()) {
|
|
|
|
case RequestResponse::Tnsresult:
|
|
|
|
HandleResponse(aResponse.get_nsresult());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TObjectStoreAddResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreAddResponse().key());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TObjectStorePutResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStorePutResponse().key());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TObjectStoreGetResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreGetResponse().cloneInfo());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TObjectStoreGetAllResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreGetAllResponse().cloneInfos());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TObjectStoreGetAllKeysResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreGetAllKeysResponse().keys());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TObjectStoreDeleteResponse:
|
|
|
|
HandleResponse(JS::UndefinedHandleValue);
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TObjectStoreClearResponse:
|
|
|
|
HandleResponse(JS::UndefinedHandleValue);
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TObjectStoreCountResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreCountResponse().count());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TIndexGetResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexGetResponse().cloneInfo());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TIndexGetKeyResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexGetKeyResponse().key());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TIndexGetAllResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexGetAllResponse().cloneInfos());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TIndexGetAllKeysResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexGetAllKeysResponse().keys());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
case RequestResponse::TIndexCountResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexCountResponse().count());
|
|
|
|
break;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown response type!");
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
mTransaction->OnRequestFinished(/* aActorDestroyedNormally */ true);
|
|
|
|
|
|
|
|
// Null this out so that we don't try to call OnRequestFinished() again in
|
|
|
|
// ActorDestroy.
|
|
|
|
mTransaction = nullptr;
|
|
|
|
|
|
|
|
return true;
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundCursorChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
2015-06-09 14:57:19 +00:00
|
|
|
class BackgroundCursorChild::DelayedActionRunnable final
|
2014-12-17 06:26:15 +00:00
|
|
|
: public nsICancelableRunnable
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
2015-06-09 14:57:19 +00:00
|
|
|
using ActionFunc = void (BackgroundCursorChild::*)();
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
BackgroundCursorChild* mActor;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBRequest> mRequest;
|
2015-06-09 14:57:19 +00:00
|
|
|
ActionFunc mActionFunc;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
public:
|
2014-12-17 06:26:15 +00:00
|
|
|
explicit
|
2015-06-09 14:57:19 +00:00
|
|
|
DelayedActionRunnable(BackgroundCursorChild* aActor, ActionFunc aActionFunc)
|
2014-09-26 23:21:57 +00:00
|
|
|
: mActor(aActor)
|
|
|
|
, mRequest(aActor->mRequest)
|
2015-06-09 14:57:19 +00:00
|
|
|
, mActionFunc(aActionFunc)
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
aActor->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
2015-06-09 14:57:19 +00:00
|
|
|
MOZ_ASSERT(mActionFunc);
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Does not need to be threadsafe since this only runs on one thread.
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
private:
|
2015-06-09 14:57:19 +00:00
|
|
|
~DelayedActionRunnable()
|
2014-09-26 23:21:57 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_DECL_NSIRUNNABLE
|
2014-12-17 06:26:15 +00:00
|
|
|
NS_DECL_NSICANCELABLERUNNABLE
|
2014-09-26 23:21:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BackgroundCursorChild::BackgroundCursorChild(IDBRequest* aRequest,
|
|
|
|
IDBObjectStore* aObjectStore,
|
|
|
|
Direction aDirection)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mTransaction(aRequest->GetTransaction())
|
|
|
|
, mObjectStore(aObjectStore)
|
|
|
|
, mIndex(nullptr)
|
|
|
|
, mCursor(nullptr)
|
|
|
|
, mStrongRequest(aRequest)
|
|
|
|
, mDirection(aDirection)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
aObjectStore->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundCursorChild);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mOwningThread = PR_GetCurrentThread();
|
|
|
|
MOZ_ASSERT(mOwningThread);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundCursorChild::BackgroundCursorChild(IDBRequest* aRequest,
|
|
|
|
IDBIndex* aIndex,
|
|
|
|
Direction aDirection)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
, mTransaction(aRequest->GetTransaction())
|
|
|
|
, mObjectStore(nullptr)
|
|
|
|
, mIndex(aIndex)
|
|
|
|
, mCursor(nullptr)
|
|
|
|
, mStrongRequest(aRequest)
|
|
|
|
, mDirection(aDirection)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIndex);
|
|
|
|
aIndex->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundCursorChild);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mOwningThread = PR_GetCurrentThread();
|
|
|
|
MOZ_ASSERT(mOwningThread);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundCursorChild::~BackgroundCursorChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundCursorChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundCursorChild::AssertIsOnOwningThread() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwningThread == PR_GetCurrentThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void
|
2015-08-19 21:59:28 +00:00
|
|
|
BackgroundCursorChild::SendContinueInternal(const CursorRequestParams& aParams,
|
|
|
|
const Key& aKey)
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(mCursor);
|
|
|
|
MOZ_ASSERT(!mStrongRequest);
|
|
|
|
MOZ_ASSERT(!mStrongCursor);
|
|
|
|
|
|
|
|
// Make sure all our DOM objects stay alive.
|
|
|
|
mStrongCursor = mCursor;
|
|
|
|
|
|
|
|
MOZ_ASSERT(mRequest->ReadyState() == IDBRequestReadyState::Done);
|
|
|
|
mRequest->Reset();
|
|
|
|
|
|
|
|
mTransaction->OnNewRequest();
|
|
|
|
|
2015-08-19 21:59:29 +00:00
|
|
|
CursorRequestParams params = aParams;
|
|
|
|
Key key = aKey;
|
|
|
|
|
|
|
|
switch (params.type()) {
|
|
|
|
case CursorRequestParams::TContinueParams: {
|
|
|
|
if (key.IsUnset()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (!mCachedResponses.IsEmpty()) {
|
|
|
|
if (mCachedResponses[0].mKey == key) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mCachedResponses.RemoveElementAt(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CursorRequestParams::TAdvanceParams: {
|
|
|
|
uint32_t& advanceCount = params.get_AdvanceParams().count();
|
|
|
|
while (advanceCount > 1 && !mCachedResponses.IsEmpty()) {
|
|
|
|
key = mCachedResponses[0].mKey;
|
|
|
|
mCachedResponses.RemoveElementAt(0);
|
|
|
|
--advanceCount;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mCachedResponses.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIRunnable> continueRunnable = new DelayedActionRunnable(
|
|
|
|
this, &BackgroundCursorChild::SendDelayedContinueInternal);
|
|
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToCurrentThread(continueRunnable)));
|
|
|
|
} else {
|
|
|
|
MOZ_ALWAYS_TRUE(PBackgroundIDBCursorChild::SendContinue(params, key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundCursorChild::SendDelayedContinueInternal()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(mCursor);
|
|
|
|
MOZ_ASSERT(mStrongCursor);
|
|
|
|
MOZ_ASSERT(!mCachedResponses.IsEmpty());
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBCursor> cursor;
|
2015-08-19 21:59:29 +00:00
|
|
|
mStrongCursor.swap(cursor);
|
|
|
|
|
|
|
|
auto& item = mCachedResponses[0];
|
|
|
|
mCursor->Reset(Move(item.mKey), Move(item.mCloneInfo));
|
|
|
|
mCachedResponses.RemoveElementAt(0);
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, mCursor);
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
|
|
|
|
mTransaction->OnRequestFinished(/* aActorDestroyedNormally */ true);
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundCursorChild::SendDeleteMeInternal()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mStrongRequest);
|
|
|
|
MOZ_ASSERT(!mStrongCursor);
|
|
|
|
|
|
|
|
mRequest = nullptr;
|
|
|
|
mTransaction = nullptr;
|
|
|
|
mObjectStore = nullptr;
|
|
|
|
mIndex = nullptr;
|
|
|
|
|
|
|
|
if (mCursor) {
|
|
|
|
mCursor->ClearBackgroundActor();
|
|
|
|
mCursor = nullptr;
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(PBackgroundIDBCursorChild::SendDeleteMe());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 21:59:29 +00:00
|
|
|
void
|
|
|
|
BackgroundCursorChild::InvalidateCachedResponses()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mCachedResponses.Clear();
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
BackgroundCursorChild::HandleResponse(nsresult aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aResponse));
|
|
|
|
MOZ_ASSERT(NS_ERROR_GET_MODULE(aResponse) == NS_ERROR_MODULE_DOM_INDEXEDDB);
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(!mStrongRequest);
|
|
|
|
MOZ_ASSERT(!mStrongCursor);
|
|
|
|
|
|
|
|
DispatchErrorEvent(mRequest, aResponse, mTransaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundCursorChild::HandleResponse(const void_t& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(!mStrongRequest);
|
|
|
|
MOZ_ASSERT(!mStrongCursor);
|
|
|
|
|
|
|
|
if (mCursor) {
|
|
|
|
mCursor->Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &JS::NullHandleValue);
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
|
|
|
|
if (!mCursor) {
|
2015-06-09 14:57:19 +00:00
|
|
|
nsCOMPtr<nsIRunnable> deleteRunnable = new DelayedActionRunnable(
|
|
|
|
this, &BackgroundCursorChild::SendDeleteMeInternal);
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToCurrentThread(deleteRunnable)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundCursorChild::HandleResponse(
|
2015-08-19 21:59:25 +00:00
|
|
|
const nsTArray<ObjectStoreCursorResponse>& aResponses)
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(mObjectStore);
|
|
|
|
MOZ_ASSERT(!mStrongRequest);
|
|
|
|
MOZ_ASSERT(!mStrongCursor);
|
|
|
|
|
2015-08-19 21:59:25 +00:00
|
|
|
MOZ_ASSERT(aResponses.Length() == 1);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-08-19 21:59:25 +00:00
|
|
|
// XXX Fix this somehow...
|
|
|
|
auto& responses =
|
|
|
|
const_cast<nsTArray<ObjectStoreCursorResponse>&>(aResponses);
|
|
|
|
|
|
|
|
for (ObjectStoreCursorResponse& response : responses) {
|
|
|
|
StructuredCloneReadInfo cloneReadInfo(Move(response.cloneInfo()));
|
|
|
|
cloneReadInfo.mDatabase = mTransaction->Database();
|
|
|
|
|
|
|
|
ConvertActorsToBlobs(mTransaction->Database(),
|
|
|
|
response.cloneInfo(),
|
|
|
|
cloneReadInfo.mFiles);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBCursor> newCursor;
|
2015-08-19 21:59:25 +00:00
|
|
|
|
|
|
|
if (mCursor) {
|
2015-08-19 21:59:29 +00:00
|
|
|
if (mCursor->IsContinueCalled()) {
|
|
|
|
mCursor->Reset(Move(response.key()), Move(cloneReadInfo));
|
|
|
|
} else {
|
|
|
|
CachedResponse cachedResponse;
|
|
|
|
cachedResponse.mKey = Move(response.key());
|
|
|
|
cachedResponse.mCloneInfo = Move(cloneReadInfo);
|
|
|
|
mCachedResponses.AppendElement(Move(cachedResponse));
|
|
|
|
}
|
2015-08-19 21:59:25 +00:00
|
|
|
} else {
|
|
|
|
newCursor = IDBCursor::Create(this,
|
|
|
|
Move(response.key()),
|
|
|
|
Move(cloneReadInfo));
|
|
|
|
mCursor = newCursor;
|
|
|
|
}
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, mCursor);
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundCursorChild::HandleResponse(
|
|
|
|
const ObjectStoreKeyCursorResponse& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(mObjectStore);
|
|
|
|
MOZ_ASSERT(!mStrongRequest);
|
|
|
|
MOZ_ASSERT(!mStrongCursor);
|
|
|
|
|
|
|
|
// XXX Fix this somehow...
|
|
|
|
auto& response = const_cast<ObjectStoreKeyCursorResponse&>(aResponse);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBCursor> newCursor;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
if (mCursor) {
|
|
|
|
mCursor->Reset(Move(response.key()));
|
|
|
|
} else {
|
2014-11-08 00:42:53 +00:00
|
|
|
newCursor = IDBCursor::Create(this, Move(response.key()));
|
2014-09-26 23:21:57 +00:00
|
|
|
mCursor = newCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, mCursor);
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundCursorChild::HandleResponse(const IndexCursorResponse& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(mIndex);
|
|
|
|
MOZ_ASSERT(!mStrongRequest);
|
|
|
|
MOZ_ASSERT(!mStrongCursor);
|
|
|
|
|
|
|
|
// XXX Fix this somehow...
|
|
|
|
auto& response = const_cast<IndexCursorResponse&>(aResponse);
|
|
|
|
|
|
|
|
StructuredCloneReadInfo cloneReadInfo(Move(response.cloneInfo()));
|
2015-06-11 09:49:51 +00:00
|
|
|
cloneReadInfo.mDatabase = mTransaction->Database();
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
ConvertActorsToBlobs(mTransaction->Database(),
|
|
|
|
aResponse.cloneInfo(),
|
|
|
|
cloneReadInfo.mFiles);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBCursor> newCursor;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
if (mCursor) {
|
|
|
|
mCursor->Reset(Move(response.key()),
|
2015-09-04 19:12:44 +00:00
|
|
|
Move(response.sortKey()),
|
2014-09-26 23:21:57 +00:00
|
|
|
Move(response.objectKey()),
|
|
|
|
Move(cloneReadInfo));
|
|
|
|
} else {
|
2014-11-08 00:42:53 +00:00
|
|
|
newCursor = IDBCursor::Create(this,
|
2014-09-26 23:21:57 +00:00
|
|
|
Move(response.key()),
|
2015-09-04 19:12:44 +00:00
|
|
|
Move(response.sortKey()),
|
2014-09-26 23:21:57 +00:00
|
|
|
Move(response.objectKey()),
|
|
|
|
Move(cloneReadInfo));
|
|
|
|
mCursor = newCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, mCursor);
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundCursorChild::HandleResponse(const IndexKeyCursorResponse& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(mIndex);
|
|
|
|
MOZ_ASSERT(!mStrongRequest);
|
|
|
|
MOZ_ASSERT(!mStrongCursor);
|
|
|
|
|
|
|
|
// XXX Fix this somehow...
|
|
|
|
auto& response = const_cast<IndexKeyCursorResponse&>(aResponse);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBCursor> newCursor;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
if (mCursor) {
|
2015-09-04 19:12:44 +00:00
|
|
|
mCursor->Reset(Move(response.key()),
|
|
|
|
Move(response.sortKey()),
|
|
|
|
Move(response.objectKey()));
|
2014-09-26 23:21:57 +00:00
|
|
|
} else {
|
2014-11-08 00:42:53 +00:00
|
|
|
newCursor = IDBCursor::Create(this,
|
2014-09-26 23:21:57 +00:00
|
|
|
Move(response.key()),
|
2015-09-04 19:12:44 +00:00
|
|
|
Move(response.sortKey()),
|
2014-09-26 23:21:57 +00:00
|
|
|
Move(response.objectKey()));
|
|
|
|
mCursor = newCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, mCursor);
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundCursorChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT_IF(aWhy == Deletion, !mStrongRequest);
|
|
|
|
MOZ_ASSERT_IF(aWhy == Deletion, !mStrongCursor);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (mStrongRequest && !mStrongCursor && mTransaction) {
|
2015-03-18 21:20:59 +00:00
|
|
|
mTransaction->OnRequestFinished(/* aActorDestroyedNormally */
|
|
|
|
aWhy == Deletion);
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mCursor) {
|
|
|
|
mCursor->ClearBackgroundActor();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mCursor = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mRequest = nullptr;
|
|
|
|
mTransaction = nullptr;
|
|
|
|
mObjectStore = nullptr;
|
|
|
|
mIndex = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundCursorChild::RecvResponse(const CursorResponse& aResponse)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aResponse.type() != CursorResponse::T__None);
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT_IF(mCursor, mStrongCursor);
|
2014-11-08 00:42:53 +00:00
|
|
|
MOZ_ASSERT_IF(!mCursor, mStrongRequest);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBRequest> request;
|
2014-09-26 23:21:57 +00:00
|
|
|
mStrongRequest.swap(request);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBCursor> cursor;
|
2014-09-26 23:21:57 +00:00
|
|
|
mStrongCursor.swap(cursor);
|
|
|
|
|
|
|
|
switch (aResponse.type()) {
|
|
|
|
case CursorResponse::Tnsresult:
|
|
|
|
HandleResponse(aResponse.get_nsresult());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CursorResponse::Tvoid_t:
|
|
|
|
HandleResponse(aResponse.get_void_t());
|
|
|
|
break;
|
|
|
|
|
2015-08-19 21:59:25 +00:00
|
|
|
case CursorResponse::TArrayOfObjectStoreCursorResponse:
|
|
|
|
HandleResponse(aResponse.get_ArrayOfObjectStoreCursorResponse());
|
2014-09-26 23:21:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CursorResponse::TObjectStoreKeyCursorResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreKeyCursorResponse());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CursorResponse::TIndexCursorResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexCursorResponse());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CursorResponse::TIndexKeyCursorResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexKeyCursorResponse());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:20:59 +00:00
|
|
|
mTransaction->OnRequestFinished(/* aActorDestroyedNormally */ true);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:57:19 +00:00
|
|
|
NS_IMPL_ISUPPORTS(BackgroundCursorChild::DelayedActionRunnable,
|
2014-12-17 06:26:15 +00:00
|
|
|
nsIRunnable,
|
|
|
|
nsICancelableRunnable)
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BackgroundCursorChild::
|
2015-06-09 14:57:19 +00:00
|
|
|
DelayedActionRunnable::Run()
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mActor);
|
|
|
|
mActor->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
2015-06-09 14:57:19 +00:00
|
|
|
MOZ_ASSERT(mActionFunc);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-06-09 14:57:19 +00:00
|
|
|
(mActor->*mActionFunc)();
|
2014-09-26 23:21:57 +00:00
|
|
|
|
|
|
|
mActor = nullptr;
|
|
|
|
mRequest = nullptr;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
BackgroundCursorChild::
|
2015-06-09 14:57:19 +00:00
|
|
|
DelayedActionRunnable::Cancel()
|
2014-12-17 06:26:15 +00:00
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!mActor)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This must always run to clean up our state.
|
|
|
|
Run();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-08-19 21:59:29 +00:00
|
|
|
BackgroundCursorChild::CachedResponse::CachedResponse()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundCursorChild::CachedResponse::CachedResponse(CachedResponse&& aOther)
|
|
|
|
: mKey(Move(aOther.mKey))
|
|
|
|
{
|
|
|
|
mCloneInfo = Move(aOther.mCloneInfo);
|
|
|
|
}
|
|
|
|
|
2015-11-22 09:44:33 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundUtilsChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundUtilsChild::BackgroundUtilsChild(IndexedDatabaseManager* aManager)
|
|
|
|
: mManager(aManager)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mOwningThread(NS_GetCurrentThread())
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aManager);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundUtilsChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundUtilsChild::~BackgroundUtilsChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundUtilsChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundUtilsChild::AssertIsOnOwningThread() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwningThread);
|
|
|
|
|
|
|
|
bool current;
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(¤t)));
|
|
|
|
MOZ_ASSERT(current);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundUtilsChild::SendDeleteMeInternal()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mManager) {
|
|
|
|
mManager->ClearBackgroundActor();
|
|
|
|
mManager = nullptr;
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(PBackgroundIndexedDBUtilsChild::SendDeleteMe());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BackgroundUtilsChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mManager) {
|
|
|
|
mManager->ClearBackgroundActor();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mManager = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|