2015-05-03 22:32:37 +03: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-27 03:21:57 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "ActorsChild.h"
|
|
|
|
|
|
|
|
#include "BackgroundChildImpl.h"
|
2017-06-07 13:36:42 +03:00
|
|
|
#include "FileSnapshot.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "IDBDatabase.h"
|
|
|
|
#include "IDBEvents.h"
|
|
|
|
#include "IDBFactory.h"
|
2017-06-07 13:36:42 +03:00
|
|
|
#include "IDBFileHandle.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "IDBIndex.h"
|
2015-09-09 14:15:05 +03:00
|
|
|
#include "IDBMutableFile.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "IDBObjectStore.h"
|
|
|
|
#include "IDBRequest.h"
|
|
|
|
#include "IDBTransaction.h"
|
|
|
|
#include "IndexedDatabase.h"
|
|
|
|
#include "IndexedDatabaseInlines.h"
|
2019-07-03 13:23:33 +03:00
|
|
|
#include <mozIIPCBlobInputStream.h>
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2017-02-24 00:23:45 +03:00
|
|
|
#include "mozilla/CycleCollectedJSRuntime.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/Maybe.h"
|
2019-07-03 13:23:33 +03:00
|
|
|
#include "mozilla/SnappyUncompressInputStream.h"
|
2014-12-17 09:26:15 +03:00
|
|
|
#include "mozilla/TypeTraits.h"
|
2015-04-10 19:10:00 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2018-04-20 19:53:17 +03:00
|
|
|
#include "mozilla/dom/Event.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
2019-04-10 01:39:01 +03:00
|
|
|
#include "mozilla/dom/BrowserChild.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseFileChild.h"
|
2017-05-23 08:50:33 +03:00
|
|
|
#include "mozilla/dom/IPCBlobUtils.h"
|
2019-04-26 21:01:08 +03:00
|
|
|
#include "mozilla/dom/PendingIPCBlobChild.h"
|
2018-01-31 10:25:30 +03:00
|
|
|
#include "mozilla/dom/WorkerPrivate.h"
|
|
|
|
#include "mozilla/dom/WorkerRunnable.h"
|
2017-06-16 15:11:03 +03:00
|
|
|
#include "mozilla/Encoding.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/ipc/BackgroundUtils.h"
|
2017-05-23 08:52:47 +03:00
|
|
|
#include "mozilla/TaskQueue.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
2017-05-23 08:52:47 +03:00
|
|
|
#include "nsIAsyncInputStream.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsIBFCacheEntry.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsIEventTarget.h"
|
2016-10-25 22:19:06 +03:00
|
|
|
#include "nsIFileStreams.h"
|
|
|
|
#include "nsNetCID.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsTraceRefcnt.h"
|
|
|
|
#include "PermissionRequestBase.h"
|
|
|
|
#include "ProfilerHelpers.h"
|
|
|
|
#include "ReportInternalError.h"
|
|
|
|
|
|
|
|
#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 11:07:57 +03:00
|
|
|
|
|
|
|
using ipc::PrincipalInfo;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace dom {
|
2015-05-06 11:07:57 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace indexedDB {
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Constants
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
const uint32_t kFileCopyBufferSize = 32768;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
/*******************************************************************************
|
|
|
|
* ThreadLocal
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ThreadLocal::ThreadLocal(const nsID& aBackgroundChildLoggingId)
|
|
|
|
: mLoggingInfo(aBackgroundChildLoggingId, 1, -1, 1),
|
2019-11-08 16:22:28 +03:00
|
|
|
mCurrentTransaction(nullptr) {
|
2014-10-16 08:56:52 +04:00
|
|
|
MOZ_COUNT_CTOR(mozilla::dom::indexedDB::ThreadLocal);
|
2015-04-30 21:59:36 +03: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 08:56:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadLocal::~ThreadLocal() {
|
|
|
|
MOZ_COUNT_DTOR(mozilla::dom::indexedDB::ThreadLocal);
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04: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;
|
|
|
|
}
|
|
|
|
|
2019-01-21 16:09:12 +03:00
|
|
|
nsJSContext::GarbageCollectNow(JS::GCReason::DOM_IPC);
|
2014-09-27 03:21:57 +04:00
|
|
|
nsJSContext::CycleCollectNow();
|
|
|
|
#endif // BUILD_GC_ON_IPC_MESSAGES
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class MOZ_STACK_CLASS AutoSetCurrentTransaction final {
|
2014-09-27 03:21:57 +04:00
|
|
|
typedef mozilla::ipc::BackgroundChildImpl BackgroundChildImpl;
|
|
|
|
|
|
|
|
IDBTransaction* const mTransaction;
|
|
|
|
IDBTransaction* mPreviousTransaction;
|
2014-10-16 08:56:52 +04:00
|
|
|
ThreadLocal* mThreadLocal;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AutoSetCurrentTransaction(IDBTransaction* aTransaction)
|
|
|
|
: mTransaction(aTransaction),
|
|
|
|
mPreviousTransaction(nullptr),
|
2014-10-16 08:56:52 +04:00
|
|
|
mThreadLocal(nullptr) {
|
2014-09-27 03:21:57 +04:00
|
|
|
if (aTransaction) {
|
|
|
|
BackgroundChildImpl::ThreadLocal* threadLocal =
|
|
|
|
BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
|
|
|
MOZ_ASSERT(threadLocal);
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
// Hang onto this for resetting later.
|
|
|
|
mThreadLocal = threadLocal->mIndexedDBThreadLocal;
|
|
|
|
MOZ_ASSERT(mThreadLocal);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
// Save the current value.
|
2014-10-16 08:56:52 +04:00
|
|
|
mPreviousTransaction = mThreadLocal->GetCurrentTransaction();
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
// Set the new value.
|
2014-10-16 08:56:52 +04:00
|
|
|
mThreadLocal->SetCurrentTransaction(aTransaction);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSetCurrentTransaction() {
|
2014-10-16 08:56:52 +04:00
|
|
|
MOZ_ASSERT_IF(mThreadLocal, mTransaction);
|
|
|
|
MOZ_ASSERT_IF(mThreadLocal,
|
|
|
|
mThreadLocal->GetCurrentTransaction() == mTransaction);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
if (mThreadLocal) {
|
2014-09-27 03:21:57 +04:00
|
|
|
// Reset old value.
|
2014-10-16 08:56:52 +04:00
|
|
|
mThreadLocal->SetCurrentTransaction(mPreviousTransaction);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBTransaction* Transaction() const { return mTransaction; }
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class MOZ_STACK_CLASS ResultHelper final : public IDBRequest::ResultCallback {
|
2019-10-03 10:56:45 +03:00
|
|
|
IDBRequest* const mRequest;
|
2014-09-27 03:21:57 +04:00
|
|
|
AutoSetCurrentTransaction mAutoTransaction;
|
|
|
|
|
|
|
|
union {
|
2014-12-17 09:26:15 +03:00
|
|
|
IDBDatabase* mDatabase;
|
|
|
|
IDBCursor* mCursor;
|
|
|
|
IDBMutableFile* mMutableFile;
|
2014-09-27 03:21:57 +04: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 09:26:15 +03:00
|
|
|
ResultTypeDatabase,
|
|
|
|
ResultTypeCursor,
|
|
|
|
ResultTypeMutableFile,
|
2014-09-27 03:21:57 +04:00
|
|
|
ResultTypeStructuredClone,
|
|
|
|
ResultTypeStructuredCloneArray,
|
|
|
|
ResultTypeKey,
|
|
|
|
ResultTypeKeyArray,
|
|
|
|
ResultTypeJSVal,
|
|
|
|
ResultTypeJSValHandle,
|
|
|
|
} mResultType;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ResultHelper(IDBRequest* aRequest, IDBTransaction* aTransaction,
|
2014-12-17 09:26:15 +03:00
|
|
|
IDBDatabase* aResult)
|
2014-09-27 03:21:57 +04:00
|
|
|
: mRequest(aRequest),
|
|
|
|
mAutoTransaction(aTransaction),
|
2014-12-17 09:26:15 +03:00
|
|
|
mResultType(ResultTypeDatabase) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
2014-12-17 09:26:15 +03: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-27 03:21:57 +04: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(); }
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult GetResult(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult) override {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aCx);
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
switch (mResultType) {
|
2014-12-17 09:26:15 +03: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-27 03:21:57 +04: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 09:26:15 +03:00
|
|
|
template <class T>
|
|
|
|
typename EnableIf<IsSame<T, IDBDatabase>::value ||
|
|
|
|
IsSame<T, IDBCursor>::value ||
|
|
|
|
IsSame<T, IDBMutableFile>::value,
|
|
|
|
nsresult>::Type
|
2014-09-27 03:21:57 +04:00
|
|
|
GetResult(JSContext* aCx, T* aDOMObject,
|
|
|
|
JS::MutableHandle<JS::Value> aResult) {
|
2014-12-17 09:26:15 +03:00
|
|
|
if (!aDOMObject) {
|
2014-09-27 03:21:57 +04:00
|
|
|
aResult.setNull();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const bool ok = GetOrCreateDOMReflector(aCx, aDOMObject, aResult);
|
2014-12-17 09:26:15 +03:00
|
|
|
if (NS_WARN_IF(!ok)) {
|
2014-09-27 03:21:57 +04: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) {
|
2019-10-03 10:56:45 +03:00
|
|
|
const bool ok = IDBObjectStore::DeserializeValue(aCx, *aCloneInfo, aResult);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const nsresult rv = GetResult(aCx, &cloneInfo, &value);
|
2014-09-27 03:21:57 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:31:15 +03:00
|
|
|
if (NS_WARN_IF(!JS_DefineElement(aCx, array, index, value,
|
|
|
|
JSPROP_ENUMERATE))) {
|
2014-09-27 03:21:57 +04: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) {
|
2019-10-03 10:56:45 +03:00
|
|
|
const nsresult rv = aKey->ToJSVal(aCx, aResult);
|
2014-09-27 03:21:57 +04:00
|
|
|
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);
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const nsresult rv = GetResult(aCx, &key, &value);
|
2014-09-27 03:21:57 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:31:15 +03:00
|
|
|
if (NS_WARN_IF(!JS_DefineElement(aCx, array, index, value,
|
|
|
|
JSPROP_ENUMERATE))) {
|
2014-09-27 03:21:57 +04:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.setObject(*array);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class PermissionRequestMainProcessHelper final : public PermissionRequestBase {
|
2014-09-27 03:21:57 +04:00
|
|
|
BackgroundFactoryRequestChild* mActor;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBFactory> mFactory;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
PermissionRequestMainProcessHelper(BackgroundFactoryRequestChild* aActor,
|
|
|
|
IDBFactory* aFactory,
|
2015-04-10 19:10:00 +03:00
|
|
|
Element* aOwnerElement,
|
2014-09-27 03:21:57 +04:00
|
|
|
nsIPrincipal* aPrincipal)
|
2015-04-10 19:10:00 +03:00
|
|
|
: PermissionRequestBase(aOwnerElement, aPrincipal),
|
2014-09-27 03:21:57 +04:00
|
|
|
mActor(aActor),
|
|
|
|
mFactory(aFactory) {
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
aActor->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-10-03 10:56:45 +03:00
|
|
|
~PermissionRequestMainProcessHelper() = default;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
private:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void OnPromptComplete(PermissionValue aPermissionValue) override;
|
2014-09-27 03:21:57 +04:00
|
|
|
};
|
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
auto DeserializeStructuredCloneFiles(
|
2016-10-25 22:19:06 +03:00
|
|
|
IDBDatabase* aDatabase,
|
|
|
|
const nsTArray<SerializedStructuredCloneFile>& aSerializedFiles,
|
2019-11-08 16:22:08 +03:00
|
|
|
bool aForPreprocess) {
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT_IF(aForPreprocess, aSerializedFiles.Length() == 1);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const auto count = aSerializedFiles.Length();
|
|
|
|
auto files = nsTArray<StructuredCloneFile>(count);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
for (const auto& serializedFile : aSerializedFiles) {
|
|
|
|
MOZ_ASSERT_IF(aForPreprocess, serializedFile.type() ==
|
|
|
|
StructuredCloneFile::eStructuredClone);
|
2019-07-03 13:23:33 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const BlobOrMutableFile& blobOrMutableFile = serializedFile.file();
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
switch (serializedFile.type()) {
|
|
|
|
case StructuredCloneFile::eBlob: {
|
|
|
|
MOZ_ASSERT(blobOrMutableFile.type() == BlobOrMutableFile::TIPCBlob);
|
2014-10-08 20:15:22 +04:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const IPCBlob& ipcBlob = blobOrMutableFile.get_IPCBlob();
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(ipcBlob);
|
|
|
|
MOZ_ASSERT(blobImpl);
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
RefPtr<Blob> blob = Blob::Create(aDatabase->GetOwnerGlobal(), blobImpl);
|
|
|
|
MOZ_ASSERT(blob);
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const DebugOnly<StructuredCloneFile*> file =
|
|
|
|
files.EmplaceBack(StructuredCloneFile::eBlob, std::move(blob));
|
|
|
|
MOZ_ASSERT(file);
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
break;
|
|
|
|
}
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
case StructuredCloneFile::eMutableFile: {
|
|
|
|
MOZ_ASSERT(blobOrMutableFile.type() == BlobOrMutableFile::Tnull_t ||
|
|
|
|
blobOrMutableFile.type() ==
|
|
|
|
BlobOrMutableFile::TPBackgroundMutableFileChild);
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
switch (blobOrMutableFile.type()) {
|
|
|
|
case BlobOrMutableFile::Tnull_t: {
|
|
|
|
const DebugOnly<StructuredCloneFile*> file =
|
|
|
|
files.EmplaceBack(StructuredCloneFile::eMutableFile);
|
|
|
|
MOZ_ASSERT(file);
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
break;
|
|
|
|
}
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
case BlobOrMutableFile::TPBackgroundMutableFileChild: {
|
|
|
|
auto* const actor = static_cast<BackgroundMutableFileChild*>(
|
|
|
|
blobOrMutableFile.get_PBackgroundMutableFileChild());
|
|
|
|
MOZ_ASSERT(actor);
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
actor->EnsureDOMObject();
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
auto* const mutableFile =
|
|
|
|
static_cast<IDBMutableFile*>(actor->GetDOMObject());
|
|
|
|
MOZ_ASSERT(mutableFile);
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const DebugOnly<StructuredCloneFile*> file =
|
|
|
|
files.EmplaceBack(mutableFile);
|
|
|
|
MOZ_ASSERT(file);
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
actor->ReleaseDOMObject();
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
break;
|
2015-09-09 14:15:05 +03:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here!");
|
2015-09-09 14:15:05 +03:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
case StructuredCloneFile::eStructuredClone: {
|
|
|
|
if (aForPreprocess) {
|
|
|
|
MOZ_ASSERT(blobOrMutableFile.type() == BlobOrMutableFile::TIPCBlob);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const IPCBlob& ipcBlob = blobOrMutableFile.get_IPCBlob();
|
2016-12-09 04:37:13 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(ipcBlob);
|
|
|
|
MOZ_ASSERT(blobImpl);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
RefPtr<Blob> blob =
|
|
|
|
Blob::Create(aDatabase->GetOwnerGlobal(), blobImpl);
|
|
|
|
MOZ_ASSERT(blob);
|
2016-10-25 22:18:58 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const DebugOnly<StructuredCloneFile*> file = files.EmplaceBack(
|
|
|
|
StructuredCloneFile::eStructuredClone, std::move(blob));
|
|
|
|
MOZ_ASSERT(file);
|
|
|
|
} else {
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(blobOrMutableFile.type() == BlobOrMutableFile::Tnull_t);
|
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const DebugOnly<StructuredCloneFile*> file =
|
|
|
|
files.EmplaceBack(StructuredCloneFile::eStructuredClone);
|
2018-08-08 20:13:16 +03:00
|
|
|
MOZ_ASSERT(file);
|
2019-11-08 16:22:08 +03:00
|
|
|
}
|
2018-08-08 20:13:16 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
break;
|
|
|
|
}
|
2019-07-03 13:23:33 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
case StructuredCloneFile::eWasmBytecode:
|
|
|
|
case StructuredCloneFile::eWasmCompiled: {
|
|
|
|
MOZ_ASSERT(blobOrMutableFile.type() == BlobOrMutableFile::Tnull_t);
|
2018-08-08 20:13:16 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const DebugOnly<StructuredCloneFile*> file =
|
|
|
|
files.EmplaceBack(serializedFile.type());
|
|
|
|
MOZ_ASSERT(file);
|
|
|
|
|
|
|
|
// Don't set mBlob, support for storing WebAssembly.Modules has been
|
|
|
|
// removed in bug 1469395. Support for de-serialization of
|
|
|
|
// WebAssembly.Modules has been removed in bug 1561876. Full removal
|
|
|
|
// is tracked in bug 1487479.
|
2018-08-08 20:13:16 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
break;
|
2015-09-09 14:15:05 +03:00
|
|
|
}
|
2019-11-08 16:22:08 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here!");
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
2019-11-08 16:22:08 +03:00
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
|
|
|
StructuredCloneReadInfo DeserializeStructuredCloneReadInfo(
|
|
|
|
SerializedStructuredCloneReadInfo&& aSerialized, IDBDatabase* aDatabase) {
|
|
|
|
return StructuredCloneReadInfo{
|
|
|
|
std::move(aSerialized.data().data),
|
|
|
|
DeserializeStructuredCloneFiles(aDatabase, aSerialized.files(),
|
|
|
|
/* aForPreprocess */ false),
|
|
|
|
aDatabase, aSerialized.hasPreprocessInfo()};
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchErrorEvent(IDBRequest* aRequest, nsresult aErrorCode,
|
|
|
|
IDBTransaction* aTransaction = nullptr,
|
2018-04-20 19:53:17 +03:00
|
|
|
Event* aEvent = nullptr) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
aRequest->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aErrorCode));
|
|
|
|
MOZ_ASSERT(NS_ERROR_GET_MODULE(aErrorCode) == NS_ERROR_MODULE_DOM_INDEXEDDB);
|
|
|
|
|
2018-05-19 00:55:18 +03:00
|
|
|
AUTO_PROFILER_LABEL("IndexedDB:DispatchErrorEvent", DOM);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const RefPtr<IDBRequest> request = aRequest;
|
|
|
|
const RefPtr<IDBTransaction> transaction = aTransaction;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
request->SetError(aErrorCode);
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
RefPtr<Event> errorEvent;
|
2014-09-27 03:21:57 +04:00
|
|
|
if (!aEvent) {
|
|
|
|
// Make an error event and fire it at the target.
|
|
|
|
errorEvent = CreateGenericEvent(request, nsDependentString(kErrorEventType),
|
|
|
|
eDoesBubble, eCancelable);
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(errorEvent);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
aEvent = errorEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<AutoSetCurrentTransaction> asct;
|
|
|
|
if (aTransaction) {
|
|
|
|
asct.emplace(aTransaction);
|
|
|
|
}
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
if (transaction) {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"Firing %s event with error 0x%x", "%s (0x%x)",
|
2014-10-16 08:56:52 +04:00
|
|
|
transaction->LoggingSerialNumber(), request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(aEvent, kErrorEventType), aErrorCode);
|
|
|
|
} else {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_REQUEST("Firing %s event with error 0x%x", "%s (0x%x)",
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(aEvent, kErrorEventType),
|
|
|
|
aErrorCode);
|
2014-10-16 08:56:52 +04:00
|
|
|
}
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
IgnoredErrorResult rv;
|
2019-10-03 10:56:45 +03:00
|
|
|
const bool doDefault =
|
|
|
|
request->DispatchEvent(*aEvent, CallerType::System, rv);
|
2018-04-05 20:42:41 +03:00
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
2014-09-27 03:21:57 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!transaction || transaction->IsOpen() || transaction->IsAborted());
|
|
|
|
|
2016-05-19 10:46:15 +03:00
|
|
|
// Do not abort the transaction here if this request is failed due to the
|
|
|
|
// abortion of its transaction to ensure that the correct error cause of
|
|
|
|
// the abort event be set in IDBTransaction::FireCompleteOrAbortEvents()
|
|
|
|
// later.
|
|
|
|
if (transaction && transaction->IsOpen() &&
|
|
|
|
aErrorCode != NS_ERROR_DOM_INDEXEDDB_ABORT_ERR) {
|
2019-10-03 10:56:45 +03:00
|
|
|
WidgetEvent* const internalEvent = aEvent->WidgetEventPtr();
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(internalEvent);
|
|
|
|
|
2016-05-09 08:16:42 +03:00
|
|
|
if (internalEvent->mFlags.mExceptionWasRaised) {
|
2014-09-27 03:21:57 +04:00
|
|
|
transaction->Abort(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
|
|
|
|
} else if (doDefault) {
|
|
|
|
transaction->Abort(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 06:03:01 +03:00
|
|
|
void DispatchSuccessEvent(ResultHelper* aResultHelper,
|
2018-04-20 19:53:17 +03:00
|
|
|
Event* aEvent = nullptr) {
|
2014-11-20 06:03:01 +03:00
|
|
|
MOZ_ASSERT(aResultHelper);
|
|
|
|
|
2018-05-19 00:55:18 +03:00
|
|
|
AUTO_PROFILER_LABEL("IndexedDB:DispatchSuccessEvent", DOM);
|
2014-11-20 06:03:01 +03:00
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const RefPtr<IDBRequest> request = aResultHelper->Request();
|
2014-11-20 06:03:01 +03:00
|
|
|
MOZ_ASSERT(request);
|
|
|
|
request->AssertIsOnOwningThread();
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const RefPtr<IDBTransaction> transaction = aResultHelper->Transaction();
|
2014-11-20 06:03:01 +03:00
|
|
|
|
|
|
|
if (transaction && transaction->IsAborted()) {
|
|
|
|
DispatchErrorEvent(request, transaction->AbortCode(), transaction);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
RefPtr<Event> successEvent;
|
2014-11-20 06:03:01 +03:00
|
|
|
if (!aEvent) {
|
|
|
|
successEvent =
|
|
|
|
CreateGenericEvent(request, nsDependentString(kSuccessEventType),
|
|
|
|
eDoesNotBubble, eNotCancelable);
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(successEvent);
|
2014-11-20 06:03:01 +03:00
|
|
|
|
|
|
|
aEvent = successEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
request->SetResultCallback(aResultHelper);
|
|
|
|
|
|
|
|
MOZ_ASSERT(aEvent);
|
|
|
|
MOZ_ASSERT_IF(transaction, transaction->IsOpen());
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
if (transaction) {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"Firing %s event", "%s", transaction->LoggingSerialNumber(),
|
|
|
|
request->LoggingSerialNumber(),
|
2014-10-16 08:56:52 +04:00
|
|
|
IDB_LOG_STRINGIFY(aEvent, kSuccessEventType));
|
|
|
|
} else {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_REQUEST("Firing %s event", "%s",
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(aEvent, kSuccessEventType));
|
2014-10-16 08:56:52 +04:00
|
|
|
}
|
|
|
|
|
2017-11-17 06:01:27 +03:00
|
|
|
MOZ_ASSERT_IF(transaction,
|
|
|
|
transaction->IsOpen() && !transaction->IsAborted());
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
IgnoredErrorResult rv;
|
2018-04-20 19:53:17 +03:00
|
|
|
request->DispatchEvent(*aEvent, rv);
|
2018-04-05 20:42:41 +03:00
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
2014-11-20 06:03:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
WidgetEvent* const internalEvent = aEvent->WidgetEventPtr();
|
2014-11-20 06:03:01 +03:00
|
|
|
MOZ_ASSERT(internalEvent);
|
|
|
|
|
2017-11-17 06:01:27 +03:00
|
|
|
if (transaction && transaction->IsOpen()) {
|
|
|
|
if (internalEvent->mFlags.mExceptionWasRaised) {
|
|
|
|
transaction->Abort(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
|
|
|
|
} else {
|
|
|
|
// To handle upgrade transaction.
|
|
|
|
transaction->Run();
|
|
|
|
}
|
2014-11-20 06:03:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-25 22:19:06 +03:00
|
|
|
PRFileDesc* GetFileDescriptorFromStream(nsIInputStream* aStream) {
|
|
|
|
MOZ_ASSERT(aStream);
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const nsCOMPtr<nsIFileMetadata> fileMetadata = do_QueryInterface(aStream);
|
2016-10-25 22:19:06 +03:00
|
|
|
if (NS_WARN_IF(!fileMetadata)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRFileDesc* fileDesc;
|
2019-10-03 10:56:45 +03:00
|
|
|
const nsresult rv = fileMetadata->GetFileDescriptor(&fileDesc);
|
2016-10-25 22:19:06 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(fileDesc);
|
|
|
|
|
|
|
|
return fileDesc;
|
|
|
|
}
|
|
|
|
|
2015-05-06 11:07:57 +03:00
|
|
|
class WorkerPermissionChallenge;
|
|
|
|
|
|
|
|
// This class calles WorkerPermissionChallenge::OperationCompleted() in the
|
|
|
|
// worker thread.
|
2015-09-08 11:11:36 +03:00
|
|
|
class WorkerPermissionOperationCompleted final : public WorkerControlRunnable {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerPermissionChallenge> mChallenge;
|
2015-05-06 11:07:57 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
WorkerPermissionOperationCompleted(WorkerPrivate* aWorkerPrivate,
|
|
|
|
WorkerPermissionChallenge* aChallenge)
|
2015-09-08 11:11:36 +03:00
|
|
|
: WorkerControlRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount),
|
2015-05-06 11:07:57 +03: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 08:24:48 +03:00
|
|
|
RefPtr<WorkerPermissionChallenge> mChallenge;
|
2015-05-06 11:07:57 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
WorkerPermissionRequest(Element* aElement, nsIPrincipal* aPrincipal,
|
|
|
|
WorkerPermissionChallenge* aChallenge)
|
|
|
|
: PermissionRequestBase(aElement, aPrincipal), mChallenge(aChallenge) {
|
2015-07-04 04:29:00 +03:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2015-05-06 11:07:57 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aChallenge);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~WorkerPermissionRequest() { MOZ_ASSERT(NS_IsMainThread()); }
|
|
|
|
|
|
|
|
virtual void OnPromptComplete(PermissionValue aPermissionValue) override;
|
|
|
|
};
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class WorkerPermissionChallenge final : public Runnable {
|
2015-05-06 11:07:57 +03:00
|
|
|
public:
|
|
|
|
WorkerPermissionChallenge(WorkerPrivate* aWorkerPrivate,
|
|
|
|
BackgroundFactoryRequestChild* aActor,
|
|
|
|
IDBFactory* aFactory,
|
|
|
|
const PrincipalInfo& aPrincipalInfo)
|
2017-01-13 11:40:58 +03:00
|
|
|
: Runnable("indexedDB::WorkerPermissionChallenge"),
|
|
|
|
mWorkerPrivate(aWorkerPrivate),
|
2015-05-06 11:07:57 +03:00
|
|
|
mActor(aActor),
|
|
|
|
mFactory(aFactory),
|
|
|
|
mPrincipalInfo(aPrincipalInfo) {
|
|
|
|
MOZ_ASSERT(mWorkerPrivate);
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
2016-07-04 09:19:10 +03:00
|
|
|
bool Dispatch() {
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
if (NS_WARN_IF(!mWorkerPrivate->ModifyBusyCountFromWorker(true))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-13 11:40:58 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(mWorkerPrivate->DispatchToMainThread(this)))) {
|
2016-07-04 09:19:10 +03:00
|
|
|
mWorkerPrivate->ModifyBusyCountFromWorker(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-06 11:07:57 +03:00
|
|
|
NS_IMETHOD
|
|
|
|
Run() override {
|
2019-10-03 10:56:45 +03:00
|
|
|
const bool completed = RunInternal();
|
2015-05-06 11:07:57 +03:00
|
|
|
if (completed) {
|
|
|
|
OperationCompleted();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OperationCompleted() {
|
|
|
|
if (NS_IsMainThread()) {
|
2019-10-03 10:56:45 +03:00
|
|
|
const RefPtr<WorkerPermissionOperationCompleted> runnable =
|
2015-05-06 11:07:57 +03:00
|
|
|
new WorkerPermissionOperationCompleted(mWorkerPrivate, this);
|
|
|
|
|
2016-02-26 23:23:12 +03:00
|
|
|
MOZ_ALWAYS_TRUE(runnable->Dispatch());
|
2015-05-06 11:07:57 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mActor);
|
|
|
|
mActor->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBFactory> factory;
|
2015-05-06 11:07:57 +03:00
|
|
|
mFactory.swap(factory);
|
|
|
|
|
|
|
|
mActor->SendPermissionRetry();
|
|
|
|
mActor = nullptr;
|
|
|
|
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2016-07-04 09:19:10 +03:00
|
|
|
mWorkerPrivate->ModifyBusyCountFromWorker(false);
|
2015-05-06 11:07:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool RunInternal() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// Walk up to our containing page
|
|
|
|
WorkerPrivate* wp = mWorkerPrivate;
|
|
|
|
while (wp->GetParent()) {
|
|
|
|
wp = wp->GetParent();
|
|
|
|
}
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
nsPIDOMWindowInner* const window = wp->GetWindow();
|
2015-05-06 11:07:57 +03:00
|
|
|
if (!window) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
2019-10-03 10:56:45 +03:00
|
|
|
const nsCOMPtr<nsIPrincipal> principal =
|
2015-05-06 11:07:57 +03:00
|
|
|
mozilla::ipc::PrincipalInfoToPrincipal(mPrincipalInfo, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2019-10-03 10:56:45 +03:00
|
|
|
const nsCOMPtr<Element> ownerElement =
|
2015-05-06 11:07:57 +03:00
|
|
|
do_QueryInterface(window->GetChromeEventHandler());
|
|
|
|
if (NS_WARN_IF(!ownerElement)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerPermissionRequest> helper =
|
2015-05-06 11:07:57 +03: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;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
BrowserChild* browserChild = BrowserChild::GetFrom(window);
|
|
|
|
MOZ_ASSERT(browserChild);
|
2015-05-06 11:07:57 +03:00
|
|
|
|
|
|
|
IPC::Principal ipcPrincipal(principal);
|
|
|
|
|
2019-03-22 22:14:01 +03:00
|
|
|
RefPtr<WorkerPermissionChallenge> self(this);
|
2019-04-10 01:39:01 +03:00
|
|
|
browserChild->SendIndexedDBPermissionRequest(ipcPrincipal)
|
2019-03-22 22:14:01 +03:00
|
|
|
->Then(
|
|
|
|
GetCurrentThreadSerialEventTarget(), __func__,
|
|
|
|
[self](const uint32_t& aPermission) { self->OperationCompleted(); },
|
|
|
|
[](const mozilla::ipc::ResponseRejectReason) {});
|
2015-05-06 11:07:57 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-10-03 10:56:45 +03:00
|
|
|
WorkerPrivate* const mWorkerPrivate;
|
2015-05-06 11:07:57 +03:00
|
|
|
BackgroundFactoryRequestChild* mActor;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBFactory> mFactory;
|
2019-10-03 10:56:45 +03:00
|
|
|
const PrincipalInfo mPrincipalInfo;
|
2015-05-06 11:07:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void WorkerPermissionRequest::OnPromptComplete(
|
|
|
|
PermissionValue aPermissionValue) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mChallenge->OperationCompleted();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WorkerPermissionOperationCompleted::WorkerRun(
|
|
|
|
JSContext* aCx, WorkerPrivate* aWorkerPrivate) {
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
mChallenge->OperationCompleted();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
class MOZ_STACK_CLASS AutoSetCurrentFileHandle final {
|
|
|
|
typedef mozilla::ipc::BackgroundChildImpl BackgroundChildImpl;
|
|
|
|
|
|
|
|
IDBFileHandle* const mFileHandle;
|
|
|
|
IDBFileHandle* mPreviousFileHandle;
|
|
|
|
IDBFileHandle** mThreadLocalSlot;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AutoSetCurrentFileHandle(IDBFileHandle* aFileHandle)
|
|
|
|
: mFileHandle(aFileHandle),
|
|
|
|
mPreviousFileHandle(nullptr),
|
|
|
|
mThreadLocalSlot(nullptr) {
|
|
|
|
if (aFileHandle) {
|
|
|
|
BackgroundChildImpl::ThreadLocal* threadLocal =
|
|
|
|
BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
|
|
|
MOZ_ASSERT(threadLocal);
|
|
|
|
|
|
|
|
// Hang onto this location for resetting later.
|
|
|
|
mThreadLocalSlot = &threadLocal->mCurrentFileHandle;
|
|
|
|
|
|
|
|
// Save the current value.
|
|
|
|
mPreviousFileHandle = *mThreadLocalSlot;
|
|
|
|
|
|
|
|
// Set the new value.
|
|
|
|
*mThreadLocalSlot = aFileHandle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSetCurrentFileHandle() {
|
|
|
|
MOZ_ASSERT_IF(mThreadLocalSlot, mFileHandle);
|
|
|
|
MOZ_ASSERT_IF(mThreadLocalSlot, *mThreadLocalSlot == mFileHandle);
|
|
|
|
|
|
|
|
if (mThreadLocalSlot) {
|
|
|
|
// Reset old value.
|
|
|
|
*mThreadLocalSlot = mPreviousFileHandle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBFileHandle* FileHandle() const { return mFileHandle; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class MOZ_STACK_CLASS FileHandleResultHelper final
|
|
|
|
: public IDBFileRequest::ResultCallback {
|
2019-10-03 10:56:45 +03:00
|
|
|
IDBFileRequest* const mFileRequest;
|
2017-06-07 13:36:42 +03:00
|
|
|
AutoSetCurrentFileHandle mAutoFileHandle;
|
|
|
|
|
|
|
|
union {
|
|
|
|
File* mFile;
|
|
|
|
const nsCString* mString;
|
|
|
|
const FileRequestMetadata* mMetadata;
|
|
|
|
const JS::Handle<JS::Value>* mJSValHandle;
|
|
|
|
} mResult;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ResultTypeFile,
|
|
|
|
ResultTypeString,
|
|
|
|
ResultTypeMetadata,
|
|
|
|
ResultTypeJSValHandle,
|
|
|
|
} mResultType;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FileHandleResultHelper(IDBFileRequest* aFileRequest,
|
|
|
|
IDBFileHandle* aFileHandle, File* aResult)
|
|
|
|
: mFileRequest(aFileRequest),
|
|
|
|
mAutoFileHandle(aFileHandle),
|
|
|
|
mResultType(ResultTypeFile) {
|
|
|
|
MOZ_ASSERT(aFileRequest);
|
|
|
|
MOZ_ASSERT(aFileHandle);
|
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
|
|
|
mResult.mFile = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileHandleResultHelper(IDBFileRequest* aFileRequest,
|
|
|
|
IDBFileHandle* aFileHandle, const nsCString* aResult)
|
|
|
|
: mFileRequest(aFileRequest),
|
|
|
|
mAutoFileHandle(aFileHandle),
|
|
|
|
mResultType(ResultTypeString) {
|
|
|
|
MOZ_ASSERT(aFileRequest);
|
|
|
|
MOZ_ASSERT(aFileHandle);
|
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
|
|
|
mResult.mString = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileHandleResultHelper(IDBFileRequest* aFileRequest,
|
|
|
|
IDBFileHandle* aFileHandle,
|
|
|
|
const FileRequestMetadata* aResult)
|
|
|
|
: mFileRequest(aFileRequest),
|
|
|
|
mAutoFileHandle(aFileHandle),
|
|
|
|
mResultType(ResultTypeMetadata) {
|
|
|
|
MOZ_ASSERT(aFileRequest);
|
|
|
|
MOZ_ASSERT(aFileHandle);
|
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
|
|
|
mResult.mMetadata = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileHandleResultHelper(IDBFileRequest* aFileRequest,
|
|
|
|
IDBFileHandle* aFileHandle,
|
|
|
|
const JS::Handle<JS::Value>* aResult)
|
|
|
|
: mFileRequest(aFileRequest),
|
|
|
|
mAutoFileHandle(aFileHandle),
|
|
|
|
mResultType(ResultTypeJSValHandle) {
|
|
|
|
MOZ_ASSERT(aFileRequest);
|
|
|
|
MOZ_ASSERT(aFileHandle);
|
|
|
|
MOZ_ASSERT(aResult);
|
|
|
|
|
|
|
|
mResult.mJSValHandle = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBFileRequest* FileRequest() const { return mFileRequest; }
|
|
|
|
|
|
|
|
IDBFileHandle* FileHandle() const { return mAutoFileHandle.FileHandle(); }
|
|
|
|
|
|
|
|
virtual nsresult GetResult(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aResult) override {
|
|
|
|
MOZ_ASSERT(aCx);
|
|
|
|
MOZ_ASSERT(mFileRequest);
|
|
|
|
|
|
|
|
switch (mResultType) {
|
|
|
|
case ResultTypeFile:
|
|
|
|
return GetResult(aCx, mResult.mFile, aResult);
|
|
|
|
|
|
|
|
case ResultTypeString:
|
|
|
|
return GetResult(aCx, mResult.mString, aResult);
|
|
|
|
|
|
|
|
case ResultTypeMetadata:
|
|
|
|
return GetResult(aCx, mResult.mMetadata, aResult);
|
|
|
|
|
|
|
|
case ResultTypeJSValHandle:
|
|
|
|
aResult.set(*mResult.mJSValHandle);
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown result type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult GetResult(JSContext* aCx, File* aFile,
|
|
|
|
JS::MutableHandle<JS::Value> aResult) {
|
2019-10-03 10:56:45 +03:00
|
|
|
const bool ok = GetOrCreateDOMReflector(aCx, aFile, aResult);
|
2017-06-07 13:36:42 +03:00
|
|
|
if (NS_WARN_IF(!ok)) {
|
|
|
|
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult GetResult(JSContext* aCx, const nsCString* aString,
|
|
|
|
JS::MutableHandle<JS::Value> aResult) {
|
|
|
|
const nsCString& data = *aString;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!mFileRequest->HasEncoding()) {
|
|
|
|
JS::Rooted<JSObject*> arrayBuffer(aCx);
|
|
|
|
rv = nsContentUtils::CreateArrayBuffer(aCx, data, arrayBuffer.address());
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.setObject(*arrayBuffer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-16 15:11:03 +03:00
|
|
|
// Try the API argument.
|
|
|
|
const Encoding* encoding = Encoding::ForLabel(mFileRequest->GetEncoding());
|
|
|
|
if (!encoding) {
|
|
|
|
// API argument failed. Since we are dealing with a file system file,
|
|
|
|
// we don't have a meaningful type attribute for the blob available,
|
|
|
|
// so proceeding to the next step, which is defaulting to UTF-8.
|
|
|
|
encoding = UTF_8_ENCODING;
|
2017-06-07 13:36:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsString tmpString;
|
2017-06-16 15:11:03 +03:00
|
|
|
Tie(rv, encoding) = encoding->Decode(data, tmpString);
|
2017-06-07 13:36:42 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!xpc::StringToJsval(aCx, tmpString, aResult))) {
|
|
|
|
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult GetResult(JSContext* aCx, const FileRequestMetadata* aMetadata,
|
|
|
|
JS::MutableHandle<JS::Value> aResult) {
|
|
|
|
JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
|
|
|
|
if (NS_WARN_IF(!obj)) {
|
|
|
|
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
2019-03-15 20:10:13 +03:00
|
|
|
const Maybe<uint64_t>& size = aMetadata->size();
|
|
|
|
if (size.isSome()) {
|
|
|
|
JS::Rooted<JS::Value> number(aCx, JS_NumberValue(size.value()));
|
2017-06-07 13:36:42 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(!JS_DefineProperty(aCx, obj, "size", number, 0))) {
|
|
|
|
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 20:10:13 +03:00
|
|
|
const Maybe<int64_t>& lastModified = aMetadata->lastModified();
|
|
|
|
if (lastModified.isSome()) {
|
2017-06-07 13:36:42 +03:00
|
|
|
JS::Rooted<JSObject*> date(
|
2019-03-15 20:10:13 +03:00
|
|
|
aCx, JS::NewDateObject(aCx, JS::TimeClip(lastModified.value())));
|
2017-06-07 13:36:42 +03:00
|
|
|
if (NS_WARN_IF(!date)) {
|
|
|
|
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!JS_DefineProperty(aCx, obj, "lastModified", date, 0))) {
|
|
|
|
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.setObject(*obj);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
already_AddRefed<File> ConvertActorToFile(
|
|
|
|
IDBFileHandle* aFileHandle, const FileRequestGetFileResponse& aResponse) {
|
2019-10-03 10:56:45 +03:00
|
|
|
auto* const actor = static_cast<PendingIPCBlobChild*>(aResponse.fileChild());
|
2017-06-07 13:36:42 +03:00
|
|
|
|
|
|
|
IDBMutableFile* mutableFile = aFileHandle->GetMutableFile();
|
|
|
|
MOZ_ASSERT(mutableFile);
|
|
|
|
|
|
|
|
const FileRequestMetadata& metadata = aResponse.metadata();
|
|
|
|
|
2019-03-15 20:10:13 +03:00
|
|
|
const Maybe<uint64_t>& size = metadata.size();
|
|
|
|
MOZ_ASSERT(size.isSome());
|
2017-06-07 13:36:42 +03:00
|
|
|
|
2019-03-15 20:10:13 +03:00
|
|
|
const Maybe<int64_t>& lastModified = metadata.lastModified();
|
|
|
|
MOZ_ASSERT(lastModified.isSome());
|
2017-06-07 13:36:42 +03:00
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const RefPtr<BlobImpl> blobImpl = actor->SetPendingInfoAndDeleteActor(
|
2019-03-15 20:10:13 +03:00
|
|
|
mutableFile->Name(), mutableFile->Type(), size.value(),
|
|
|
|
lastModified.value());
|
2017-06-07 13:36:42 +03:00
|
|
|
MOZ_ASSERT(blobImpl);
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const RefPtr<BlobImpl> blobImplSnapshot =
|
2017-06-07 13:36:42 +03:00
|
|
|
new BlobImplSnapshot(blobImpl, static_cast<IDBFileHandle*>(aFileHandle));
|
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
RefPtr<File> file =
|
|
|
|
File::Create(mutableFile->GetOwnerGlobal(), blobImplSnapshot);
|
2017-06-07 13:36:42 +03:00
|
|
|
return file.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchFileHandleErrorEvent(IDBFileRequest* aFileRequest,
|
|
|
|
nsresult aErrorCode,
|
|
|
|
IDBFileHandle* aFileHandle) {
|
|
|
|
MOZ_ASSERT(aFileRequest);
|
|
|
|
aFileRequest->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aErrorCode));
|
|
|
|
MOZ_ASSERT(NS_ERROR_GET_MODULE(aErrorCode) == NS_ERROR_MODULE_DOM_FILEHANDLE);
|
|
|
|
MOZ_ASSERT(aFileHandle);
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const RefPtr<IDBFileRequest> fileRequest = aFileRequest;
|
|
|
|
const RefPtr<IDBFileHandle> fileHandle = aFileHandle;
|
2017-06-07 13:36:42 +03:00
|
|
|
|
|
|
|
AutoSetCurrentFileHandle ascfh(aFileHandle);
|
|
|
|
|
|
|
|
fileRequest->FireError(aErrorCode);
|
|
|
|
|
|
|
|
MOZ_ASSERT(fileHandle->IsOpen() || fileHandle->IsAborted());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchFileHandleSuccessEvent(FileHandleResultHelper* aResultHelper) {
|
|
|
|
MOZ_ASSERT(aResultHelper);
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const RefPtr<IDBFileRequest> fileRequest = aResultHelper->FileRequest();
|
2017-06-07 13:36:42 +03:00
|
|
|
MOZ_ASSERT(fileRequest);
|
|
|
|
fileRequest->AssertIsOnOwningThread();
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const RefPtr<IDBFileHandle> fileHandle = aResultHelper->FileHandle();
|
2017-06-07 13:36:42 +03:00
|
|
|
MOZ_ASSERT(fileHandle);
|
|
|
|
|
|
|
|
if (fileHandle->IsAborted()) {
|
|
|
|
fileRequest->FireError(NS_ERROR_DOM_FILEHANDLE_ABORT_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(fileHandle->IsOpen());
|
|
|
|
|
|
|
|
fileRequest->SetResultCallback(aResultHelper);
|
|
|
|
|
|
|
|
MOZ_ASSERT(fileHandle->IsOpen() || fileHandle->IsAborted());
|
|
|
|
}
|
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
auto GetKeyOperator(const IDBCursor::Direction aDirection) {
|
|
|
|
switch (aDirection) {
|
|
|
|
case IDBCursor::NEXT:
|
|
|
|
case IDBCursor::NEXT_UNIQUE:
|
|
|
|
return &Key::operator>=;
|
|
|
|
case IDBCursor::PREV:
|
|
|
|
case IDBCursor::PREV_UNIQUE:
|
|
|
|
return &Key::operator<=;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2016-10-25 22:19:06 +03:00
|
|
|
/*******************************************************************************
|
|
|
|
* Actor class declarations
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
// CancelableRunnable is used to make workers happy.
|
|
|
|
class BackgroundRequestChild::PreprocessHelper final
|
|
|
|
: public CancelableRunnable,
|
2017-05-23 08:52:47 +03:00
|
|
|
public nsIInputStreamCallback,
|
2017-09-08 17:06:26 +03:00
|
|
|
public nsIFileMetadataCallback {
|
2019-07-03 13:23:33 +03:00
|
|
|
enum class State {
|
|
|
|
// Just created on the owning thread, dispatched to the thread pool. Next
|
|
|
|
// step is either Finishing if stream was ready to be read or
|
|
|
|
// WaitingForStreamReady if the stream is not ready.
|
|
|
|
Initial,
|
|
|
|
|
|
|
|
// Waiting for stream to be ready on a thread pool thread. Next state is
|
|
|
|
// Finishing.
|
|
|
|
WaitingForStreamReady,
|
2017-05-23 08:52:47 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
// Waiting to finish/finishing on the owning thread. Next step is Completed.
|
|
|
|
Finishing,
|
2017-05-23 08:52:47 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
// All done.
|
|
|
|
Completed
|
|
|
|
};
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
const nsCOMPtr<nsIEventTarget> mOwningEventTarget;
|
2017-05-23 08:52:47 +03:00
|
|
|
RefPtr<TaskQueue> mTaskQueue;
|
|
|
|
nsCOMPtr<nsIEventTarget> mTaskQueueEventTarget;
|
2019-07-03 13:23:33 +03:00
|
|
|
nsCOMPtr<nsIInputStream> mStream;
|
|
|
|
UniquePtr<JSStructuredCloneData> mCloneData;
|
|
|
|
BackgroundRequestChild* mActor;
|
2019-10-03 10:56:45 +03:00
|
|
|
const uint32_t mCloneDataIndex;
|
2016-10-25 22:19:06 +03:00
|
|
|
nsresult mResultCode;
|
2019-07-03 13:23:33 +03:00
|
|
|
State mState;
|
2016-10-25 22:19:06 +03:00
|
|
|
|
|
|
|
public:
|
2019-07-03 13:23:33 +03:00
|
|
|
PreprocessHelper(uint32_t aCloneDataIndex, BackgroundRequestChild* aActor)
|
2017-01-13 11:40:58 +03:00
|
|
|
: CancelableRunnable(
|
|
|
|
"indexedDB::BackgroundRequestChild::PreprocessHelper"),
|
2017-06-01 23:42:05 +03:00
|
|
|
mOwningEventTarget(aActor->GetActorEventTarget()),
|
2016-10-25 22:19:06 +03:00
|
|
|
mActor(aActor),
|
2019-07-03 13:23:33 +03:00
|
|
|
mCloneDataIndex(aCloneDataIndex),
|
|
|
|
mResultCode(NS_OK),
|
|
|
|
mState(State::Initial) {
|
2016-10-25 22:19:06 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
aActor->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsOnOwningThread() const {
|
2017-06-01 23:42:05 +03:00
|
|
|
MOZ_ASSERT(mOwningEventTarget);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
|
|
|
bool current;
|
2017-06-01 23:42:05 +03:00
|
|
|
return NS_SUCCEEDED(mOwningEventTarget->IsOnCurrentThread(¤t)) &&
|
|
|
|
current;
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AssertIsOnOwningThread() const { MOZ_ASSERT(IsOnOwningThread()); }
|
|
|
|
|
|
|
|
void ClearActor() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mActor = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsresult Init(const StructuredCloneFile& aFile);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
|
|
|
nsresult Dispatch();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~PreprocessHelper() {
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(mState == State::Initial || mState == State::Completed);
|
|
|
|
|
2017-05-23 08:52:47 +03:00
|
|
|
if (mTaskQueue) {
|
|
|
|
mTaskQueue->BeginShutdown();
|
|
|
|
}
|
|
|
|
}
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsresult Start();
|
2017-05-23 08:52:47 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsresult ProcessStream();
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
void Finish();
|
2017-09-08 17:06:26 +03:00
|
|
|
|
2017-05-23 08:52:47 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2016-10-25 22:19:06 +03:00
|
|
|
NS_DECL_NSIRUNNABLE
|
2017-05-23 08:52:47 +03:00
|
|
|
NS_DECL_NSIINPUTSTREAMCALLBACK
|
2017-09-08 17:06:26 +03:00
|
|
|
NS_DECL_NSIFILEMETADATACALLBACK
|
2016-10-25 22:19:06 +03:00
|
|
|
};
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
/*******************************************************************************
|
|
|
|
* Local class implementations
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
void PermissionRequestMainProcessHelper::OnPromptComplete(
|
|
|
|
PermissionValue aPermissionValue) {
|
|
|
|
MOZ_ASSERT(mActor);
|
|
|
|
mActor->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
mActor->SendPermissionRetry();
|
|
|
|
|
|
|
|
mActor = nullptr;
|
|
|
|
mFactory = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 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) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
aFactory->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundFactoryChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundFactoryChild::~BackgroundFactoryChild() {
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundFactoryChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2019-10-03 10:56:45 +03:00
|
|
|
auto* const request = static_cast<BackgroundFactoryRequestChild*>(aRequest);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
|
|
|
return new BackgroundDatabaseChild(aSpec, request);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundFactoryChild::DeallocPBackgroundIDBDatabaseChild(
|
|
|
|
PBackgroundIDBDatabaseChild* aActor) {
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundDatabaseChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-10 10:13:45 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
BackgroundFactoryChild::RecvPBackgroundIDBDatabaseConstructor(
|
|
|
|
PBackgroundIDBDatabaseChild* aActor, const DatabaseSpec& aSpec,
|
|
|
|
PBackgroundIDBFactoryRequestChild* aRequest) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
MOZ_ASSERT(aActor->GetActorEventTarget(),
|
|
|
|
"The event target shall be inherited from its manager actor.");
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundFactoryRequestChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundFactoryRequestChild::BackgroundFactoryRequestChild(
|
|
|
|
IDBFactory* aFactory, IDBOpenDBRequest* aOpenRequest, bool aIsDeleteOp,
|
|
|
|
uint64_t aRequestedVersion)
|
|
|
|
: BackgroundRequestChildBase(aOpenRequest),
|
|
|
|
mFactory(aFactory),
|
2017-10-30 09:13:40 +03:00
|
|
|
mDatabaseActor(nullptr),
|
2014-09-27 03:21:57 +04:00
|
|
|
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 12:43:09 +03:00
|
|
|
return static_cast<IDBOpenDBRequest*>(mRequest.get());
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2017-10-30 09:13:40 +03:00
|
|
|
void BackgroundFactoryRequestChild::SetDatabaseActor(
|
|
|
|
BackgroundDatabaseChild* aActor) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!aActor || !mDatabaseActor);
|
|
|
|
|
|
|
|
mDatabaseActor = aActor;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04: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);
|
|
|
|
|
2017-10-30 09:13:40 +03:00
|
|
|
if (mDatabaseActor) {
|
|
|
|
mDatabaseActor->ReleaseDOMObject();
|
|
|
|
MOZ_ASSERT(!mDatabaseActor);
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
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 19:08:30 +03:00
|
|
|
if (!database) {
|
|
|
|
databaseActor->EnsureDOMObject();
|
2017-10-30 09:13:40 +03:00
|
|
|
MOZ_ASSERT(mDatabaseActor);
|
2015-06-20 19:08:30 +03:00
|
|
|
|
|
|
|
database = databaseActor->GetDOMObject();
|
|
|
|
MOZ_ASSERT(database);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!database->IsClosed());
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2017-10-30 09:13:40 +03:00
|
|
|
MOZ_ASSERT(mDatabaseActor == databaseActor);
|
|
|
|
|
2015-06-20 19:08:30 +03: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-27 03:21:57 +04:00
|
|
|
|
2015-06-20 19:08:30 +03:00
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
databaseActor->ReleaseDOMObject();
|
2017-10-30 09:13:40 +03:00
|
|
|
MOZ_ASSERT(!mDatabaseActor);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundFactoryRequestChild::HandleResponse(
|
|
|
|
const DeleteDatabaseRequestResponse& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, nullptr, &JS::UndefinedHandleValue);
|
|
|
|
|
|
|
|
RefPtr<Event> successEvent = IDBVersionChangeEvent::Create(
|
|
|
|
mRequest, nsDependentString(kSuccessEventType),
|
|
|
|
aResponse.previousVersion());
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(successEvent);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper, successEvent);
|
|
|
|
|
2017-10-30 09:13:40 +03:00
|
|
|
MOZ_ASSERT(!mDatabaseActor);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundFactoryRequestChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
if (aWhy != Deletion) {
|
|
|
|
IDBOpenDBRequest* openRequest = GetOpenDBRequest();
|
|
|
|
if (openRequest) {
|
|
|
|
openRequest->NoteComplete();
|
|
|
|
}
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundFactoryRequestChild::Recv__delete__(
|
|
|
|
const FactoryRequestResponse& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
bool result;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
switch (aResponse.type()) {
|
|
|
|
case FactoryRequestResponse::Tnsresult:
|
2014-12-17 09:26:15 +03:00
|
|
|
result = HandleResponse(aResponse.get_nsresult());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
case FactoryRequestResponse::TOpenDatabaseRequestResponse:
|
2014-12-17 09:26:15 +03:00
|
|
|
result = HandleResponse(aResponse.get_OpenDatabaseRequestResponse());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
case FactoryRequestResponse::TDeleteDatabaseRequestResponse:
|
2014-12-17 09:26:15 +03:00
|
|
|
result = HandleResponse(aResponse.get_DeleteDatabaseRequestResponse());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown response type!");
|
|
|
|
}
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
IDBOpenDBRequest* request = GetOpenDBRequest();
|
|
|
|
MOZ_ASSERT(request);
|
2015-03-02 16:31:15 +03:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
request->NoteComplete();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!result)) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2014-12-17 09:26:15 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundFactoryRequestChild::RecvPermissionChallenge(
|
|
|
|
const PrincipalInfo& aPrincipalInfo) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (!NS_IsMainThread()) {
|
2015-05-06 11:07:57 +03:00
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
workerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerPermissionChallenge> challenge = new WorkerPermissionChallenge(
|
2015-05-06 11:07:57 +03:00
|
|
|
workerPrivate, this, mFactory, aPrincipalInfo);
|
2016-11-15 06:26:00 +03:00
|
|
|
if (!challenge->Dispatch()) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPrincipal> principal =
|
|
|
|
mozilla::ipc::PrincipalInfoToPrincipal(aPrincipalInfo, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2019-03-29 21:05:11 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = mFactory->GetParentObject();
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(window);
|
|
|
|
|
2015-04-10 19:10:00 +03:00
|
|
|
nsCOMPtr<Element> ownerElement =
|
|
|
|
do_QueryInterface(window->GetChromeEventHandler());
|
|
|
|
if (NS_WARN_IF(!ownerElement)) {
|
2015-09-08 11:11:36 +03:00
|
|
|
// If this fails, the page was navigated. Fail the permission check by
|
|
|
|
// forcing an immediate retry.
|
2016-11-15 06:26:00 +03:00
|
|
|
if (!SendPermissionRetry()) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
2015-04-10 19:10:00 +03:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PermissionRequestMainProcessHelper> helper =
|
2015-04-10 19:10:00 +03:00
|
|
|
new PermissionRequestMainProcessHelper(this, mFactory, ownerElement,
|
|
|
|
principal);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
PermissionRequestBase::PermissionValue permission;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(helper->PromptIfNeeded(&permission)))) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(permission == PermissionRequestBase::kPermissionAllowed ||
|
|
|
|
permission == PermissionRequestBase::kPermissionDenied ||
|
|
|
|
permission == PermissionRequestBase::kPermissionPrompt);
|
|
|
|
|
|
|
|
if (permission != PermissionRequestBase::kPermissionPrompt) {
|
|
|
|
SendPermissionRetry();
|
|
|
|
}
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
RefPtr<BrowserChild> browserChild = mFactory->GetBrowserChild();
|
|
|
|
MOZ_ASSERT(browserChild);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
IPC::Principal ipcPrincipal(principal);
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
browserChild->SendIndexedDBPermissionRequest(ipcPrincipal)
|
2019-03-22 22:14:01 +03:00
|
|
|
->Then(
|
|
|
|
GetCurrentThreadSerialEventTarget(), __func__,
|
|
|
|
[this](const uint32_t& aPermission) {
|
|
|
|
this->AssertIsOnOwningThread();
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
this->SendPermissionRetry();
|
|
|
|
},
|
|
|
|
[](const mozilla::ipc::ResponseRejectReason) {});
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundFactoryRequestChild::RecvBlocked(
|
|
|
|
const uint64_t& aCurrentVersion) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
const nsDependentString type(kBlockedEventType);
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
RefPtr<Event> blockedEvent;
|
2014-09-27 03:21:57 +04:00
|
|
|
if (mIsDeleteOp) {
|
|
|
|
blockedEvent =
|
|
|
|
IDBVersionChangeEvent::Create(mRequest, type, aCurrentVersion);
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(blockedEvent);
|
2014-09-27 03:21:57 +04:00
|
|
|
} else {
|
|
|
|
blockedEvent = IDBVersionChangeEvent::Create(
|
|
|
|
mRequest, type, aCurrentVersion, mRequestedVersion);
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(blockedEvent);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBRequest> kungFuDeathGrip = mRequest;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_REQUEST("Firing \"blocked\" event", "\"blocked\"",
|
|
|
|
kungFuDeathGrip->LoggingSerialNumber());
|
2014-10-16 08:56:52 +04:00
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
IgnoredErrorResult rv;
|
|
|
|
kungFuDeathGrip->DispatchEvent(*blockedEvent, rv);
|
|
|
|
if (rv.Failed()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_WARNING("Failed to dispatch event!");
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2017-06-07 08:55:00 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void BackgroundDatabaseChild::AssertIsOnOwningThread() const {
|
|
|
|
static_cast<BackgroundFactoryChild*>(Manager())->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
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 14:15:05 +03:00
|
|
|
auto request = mOpenRequestActor->GetOpenDBRequest();
|
2014-09-27 03:21:57 +04: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();
|
2017-10-30 09:13:40 +03:00
|
|
|
|
|
|
|
mOpenRequestActor->SetDatabaseActor(this);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundDatabaseChild::ReleaseDOMObject() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTemporaryStrongDatabase);
|
|
|
|
mTemporaryStrongDatabase->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mOpenRequestActor);
|
|
|
|
MOZ_ASSERT(mDatabase == mTemporaryStrongDatabase);
|
|
|
|
|
2017-10-30 09:13:40 +03:00
|
|
|
mOpenRequestActor->SetDatabaseActor(nullptr);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
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(
|
2017-05-23 08:50:33 +03:00
|
|
|
const IPCBlob& aIPCBlob) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_CRASH("PBackgroundIDBFileChild actors should be manually constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundDatabaseChild::DeallocPBackgroundIDBDatabaseFileChild(
|
|
|
|
PBackgroundIDBDatabaseFileChild* aActor) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 14:15:05 +03: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-27 03:21:57 +04: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);
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-09-27 03:21:57 +04:00
|
|
|
BackgroundDatabaseChild::RecvPBackgroundIDBVersionChangeTransactionConstructor(
|
|
|
|
PBackgroundIDBVersionChangeTransactionChild* aActor,
|
|
|
|
const uint64_t& aCurrentVersion, const uint64_t& aRequestedVersion,
|
|
|
|
const int64_t& aNextObjectStoreId, const int64_t& aNextIndexId) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
2017-02-10 10:13:45 +03:00
|
|
|
MOZ_ASSERT(aActor->GetActorEventTarget(),
|
|
|
|
"The event target shall be inherited from its manager actor.");
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mOpenRequestActor);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
EnsureDOMObject();
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
auto* actor = static_cast<BackgroundVersionChangeTransactionChild*>(aActor);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> request = mOpenRequestActor->GetOpenDBRequest();
|
2014-11-14 05:20:38 +03:00
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBTransaction> transaction = IDBTransaction::CreateVersionChange(
|
2014-11-14 05:20:38 +03:00
|
|
|
mDatabase, actor, request, aNextObjectStoreId, aNextIndexId);
|
2017-06-16 14:06:36 +03:00
|
|
|
MOZ_ASSERT(transaction);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
transaction->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
actor->SetDOMTransaction(transaction);
|
|
|
|
|
|
|
|
mDatabase->EnterSetVersionTransaction(aRequestedVersion);
|
|
|
|
|
|
|
|
request->SetTransaction(transaction);
|
|
|
|
|
2018-04-20 19:53:17 +03:00
|
|
|
RefPtr<Event> upgradeNeededEvent = IDBVersionChangeEvent::Create(
|
2014-09-27 03:21:57 +04:00
|
|
|
request, nsDependentString(kUpgradeNeededEventType), aCurrentVersion,
|
|
|
|
aRequestedVersion);
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(upgradeNeededEvent);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
ResultHelper helper(request, transaction, mDatabase);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper, upgradeNeededEvent);
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundDatabaseChild::
|
|
|
|
DeallocPBackgroundIDBVersionChangeTransactionChild(
|
|
|
|
PBackgroundIDBVersionChangeTransactionChild* aActor) {
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundVersionChangeTransactionChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
PBackgroundMutableFileChild*
|
|
|
|
BackgroundDatabaseChild::AllocPBackgroundMutableFileChild(
|
|
|
|
const nsString& aName, const nsString& aType) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
return new BackgroundMutableFileChild(aName, aType);
|
2015-09-09 14:15:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundDatabaseChild::DeallocPBackgroundMutableFileChild(
|
|
|
|
PBackgroundMutableFileChild* aActor) {
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundMutableFileChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mozilla::ipc::IPCResult BackgroundDatabaseChild::RecvVersionChange(
|
2019-03-15 20:10:29 +03:00
|
|
|
const uint64_t& aOldVersion, const Maybe<uint64_t>& aNewVersion) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (!mDatabase || mDatabase->IsClosed()) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBDatabase> kungFuDeathGrip = mDatabase;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
// Handle bfcache'd windows.
|
2016-08-24 21:12:09 +03:00
|
|
|
if (nsPIDOMWindowInner* owner = kungFuDeathGrip->GetOwner()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
// 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.
|
2019-01-02 16:05:23 +03:00
|
|
|
if (nsCOMPtr<Document> doc = owner->GetExtantDoc()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
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.
|
2016-08-24 21:12:09 +03:00
|
|
|
kungFuDeathGrip->AbortTransactions(/* aShouldWarn */ false);
|
|
|
|
kungFuDeathGrip->Close();
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise fire a versionchange event.
|
|
|
|
const nsDependentString type(kVersionChangeEventType);
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
RefPtr<Event> versionChangeEvent;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-03-15 20:10:29 +03:00
|
|
|
if (aNewVersion.isNothing()) {
|
|
|
|
versionChangeEvent =
|
|
|
|
IDBVersionChangeEvent::Create(kungFuDeathGrip, type, aOldVersion);
|
|
|
|
MOZ_ASSERT(versionChangeEvent);
|
|
|
|
} else {
|
|
|
|
versionChangeEvent = IDBVersionChangeEvent::Create(
|
|
|
|
kungFuDeathGrip, type, aOldVersion, aNewVersion.value());
|
|
|
|
MOZ_ASSERT(versionChangeEvent);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK("Child : Firing \"versionchange\" event",
|
|
|
|
"C: IDBDatabase \"versionchange\" event", IDB_LOG_ID_STRING());
|
2014-10-16 08:56:52 +04:00
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
IgnoredErrorResult rv;
|
|
|
|
kungFuDeathGrip->DispatchEvent(*versionChangeEvent, rv);
|
|
|
|
if (rv.Failed()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_WARNING("Failed to dispatch event!");
|
|
|
|
}
|
|
|
|
|
2016-08-24 21:12:09 +03:00
|
|
|
if (!kungFuDeathGrip->IsClosed()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
SendBlocked();
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundDatabaseChild::RecvInvalidate() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (mDatabase) {
|
|
|
|
mDatabase->Invalidate();
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2016-05-31 13:08:20 +03:00
|
|
|
BackgroundDatabaseChild::RecvCloseAfterInvalidationComplete() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (mDatabase) {
|
|
|
|
mDatabase->DispatchTrustedEvent(nsDependentString(kCloseEventType));
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2016-05-31 13:08:20 +03:00
|
|
|
}
|
|
|
|
|
2015-09-09 14:15:05 +03: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundDatabaseRequestChild::Recv__delete__(
|
|
|
|
const DatabaseRequestResponse& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
switch (aResponse.type()) {
|
|
|
|
case DatabaseRequestResponse::Tnsresult:
|
2016-11-15 06:26:00 +03:00
|
|
|
if (!HandleResponse(aResponse.get_nsresult())) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
2015-09-09 14:15:05 +03:00
|
|
|
|
|
|
|
case DatabaseRequestResponse::TCreateFileRequestResponse:
|
2016-11-15 06:26:00 +03:00
|
|
|
if (!HandleResponse(aResponse.get_CreateFileRequestResponse())) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
2015-09-09 14:15:05 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown response type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04: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();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundTransactionChild::RecvComplete(
|
|
|
|
const nsresult& aResult) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
mTransaction->FireCompleteOrAbortEvents(aResult);
|
|
|
|
|
|
|
|
NoteComplete();
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
void BackgroundVersionChangeTransactionChild::SendDeleteMeInternal(
|
|
|
|
bool aFailedConstructor) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
if (mTransaction || aFailedConstructor) {
|
2014-09-27 03:21:57 +04:00
|
|
|
NoteActorDestroyed();
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
PBackgroundIDBVersionChangeTransactionChild::SendDeleteMe());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundVersionChangeTransactionChild::ActorDestroy(
|
|
|
|
ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
mOpenDBRequest = nullptr;
|
|
|
|
|
|
|
|
NoteActorDestroyed();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundVersionChangeTransactionChild::RecvComplete(
|
|
|
|
const nsresult& aResult) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (!mTransaction) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mOpenDBRequest);
|
|
|
|
|
|
|
|
IDBDatabase* database = mTransaction->Database();
|
|
|
|
MOZ_ASSERT(database);
|
|
|
|
|
|
|
|
database->ExitSetVersionTransaction();
|
|
|
|
|
|
|
|
if (NS_FAILED(aResult)) {
|
|
|
|
database->Close();
|
|
|
|
}
|
|
|
|
|
2019-05-30 05:53:07 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> request = mOpenDBRequest;
|
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mTransaction->FireCompleteOrAbortEvents(aResult);
|
|
|
|
|
2019-05-30 05:53:07 +03:00
|
|
|
request->SetTransaction(nullptr);
|
|
|
|
request = nullptr;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mOpenDBRequest = nullptr;
|
|
|
|
|
|
|
|
NoteComplete();
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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 14:15:05 +03:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundMutableFileChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
BackgroundMutableFileChild::BackgroundMutableFileChild(const nsAString& aName,
|
|
|
|
const nsAString& aType)
|
|
|
|
: mMutableFile(nullptr), mName(aName), mType(aType) {
|
2015-09-09 14:15:05 +03:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void BackgroundMutableFileChild::AssertIsOnOwningThread() const {
|
|
|
|
static_cast<BackgroundDatabaseChild*>(Manager())->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void BackgroundMutableFileChild::EnsureDOMObject() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mTemporaryStrongMutableFile) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
auto database =
|
|
|
|
static_cast<BackgroundDatabaseChild*>(Manager())->GetDOMObject();
|
|
|
|
MOZ_ASSERT(database);
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
mTemporaryStrongMutableFile =
|
2015-09-09 14:15:05 +03:00
|
|
|
new IDBMutableFile(database, this, mName, mType);
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
MOZ_ASSERT(mTemporaryStrongMutableFile);
|
|
|
|
mTemporaryStrongMutableFile->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mMutableFile = mTemporaryStrongMutableFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundMutableFileChild::ReleaseDOMObject() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTemporaryStrongMutableFile);
|
|
|
|
mTemporaryStrongMutableFile->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mMutableFile == mTemporaryStrongMutableFile);
|
|
|
|
|
|
|
|
mTemporaryStrongMutableFile = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundMutableFileChild::SendDeleteMeInternal() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mTemporaryStrongMutableFile);
|
|
|
|
|
|
|
|
if (mMutableFile) {
|
|
|
|
mMutableFile->ClearBackgroundActor();
|
|
|
|
mMutableFile = nullptr;
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(PBackgroundMutableFileChild::SendDeleteMe());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundMutableFileChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mMutableFile) {
|
|
|
|
mMutableFile->ClearBackgroundActor();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mMutableFile = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PBackgroundFileHandleChild*
|
|
|
|
BackgroundMutableFileChild::AllocPBackgroundFileHandleChild(
|
|
|
|
const FileMode& aMode) {
|
|
|
|
MOZ_CRASH(
|
|
|
|
"PBackgroundFileHandleChild actors should be manually "
|
|
|
|
"constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundMutableFileChild::DeallocPBackgroundFileHandleChild(
|
|
|
|
PBackgroundFileHandleChild* aActor) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundFileHandleChild*>(aActor);
|
|
|
|
return true;
|
2015-09-09 14:15:05 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundRequestChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundRequestChild::BackgroundRequestChild(IDBRequest* aRequest)
|
|
|
|
: BackgroundRequestChildBase(aRequest),
|
|
|
|
mTransaction(aRequest->GetTransaction()),
|
2016-10-26 07:51:33 +03:00
|
|
|
mRunningPreprocessHelpers(0),
|
2019-07-03 13:23:33 +03:00
|
|
|
mCurrentCloneDataIndex(0),
|
2016-10-26 07:51:33 +03:00
|
|
|
mPreprocessResultCode(NS_OK),
|
|
|
|
mGetAll(false) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
mTransaction->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundRequestChild::~BackgroundRequestChild() {
|
|
|
|
AssertIsOnOwningThread();
|
2015-03-19 00:20:59 +03:00
|
|
|
MOZ_ASSERT(!mTransaction);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundRequestChild);
|
|
|
|
}
|
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
void BackgroundRequestChild::MaybeSendContinue() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRunningPreprocessHelpers > 0);
|
|
|
|
|
|
|
|
if (--mRunningPreprocessHelpers == 0) {
|
|
|
|
PreprocessResponse response;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mPreprocessResultCode)) {
|
|
|
|
if (mGetAll) {
|
|
|
|
response = ObjectStoreGetAllPreprocessResponse();
|
|
|
|
} else {
|
|
|
|
response = ObjectStoreGetPreprocessResponse();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
response = mPreprocessResultCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(SendContinue(response));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-25 22:19:06 +03:00
|
|
|
void BackgroundRequestChild::OnPreprocessFinished(
|
2019-07-03 13:23:33 +03:00
|
|
|
uint32_t aCloneDataIndex, UniquePtr<JSStructuredCloneData> aCloneData) {
|
2016-10-25 22:19:06 +03:00
|
|
|
AssertIsOnOwningThread();
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(aCloneDataIndex < mPreprocessHelpers.Length());
|
|
|
|
MOZ_ASSERT(aCloneData);
|
|
|
|
MOZ_ASSERT(mPreprocessHelpers[aCloneDataIndex]);
|
|
|
|
MOZ_ASSERT(!mCloneDatas[aCloneDataIndex]);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
mCloneDatas[aCloneDataIndex] = std::move(aCloneData);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
MaybeSendContinue();
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
mPreprocessHelpers[aCloneDataIndex] = nullptr;
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
void BackgroundRequestChild::OnPreprocessFailed(uint32_t aCloneDataIndex,
|
2016-10-26 07:51:33 +03:00
|
|
|
nsresult aErrorCode) {
|
2016-10-25 22:19:06 +03:00
|
|
|
AssertIsOnOwningThread();
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(aCloneDataIndex < mPreprocessHelpers.Length());
|
2016-10-25 22:19:06 +03:00
|
|
|
MOZ_ASSERT(NS_FAILED(aErrorCode));
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(mPreprocessHelpers[aCloneDataIndex]);
|
|
|
|
MOZ_ASSERT(!mCloneDatas[aCloneDataIndex]);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
if (NS_SUCCEEDED(mPreprocessResultCode)) {
|
|
|
|
mPreprocessResultCode = aErrorCode;
|
|
|
|
}
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
MaybeSendContinue();
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
mPreprocessHelpers[aCloneDataIndex] = nullptr;
|
2016-10-26 07:51:33 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
UniquePtr<JSStructuredCloneData> BackgroundRequestChild::GetNextCloneData() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mCurrentCloneDataIndex < mCloneDatas.Length());
|
|
|
|
MOZ_ASSERT(mCloneDatas[mCurrentCloneDataIndex]);
|
|
|
|
|
|
|
|
UniquePtr<JSStructuredCloneData> cloneData;
|
|
|
|
mCloneDatas[mCurrentCloneDataIndex++].swap(cloneData);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
return cloneData;
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundRequestChild::HandleResponse(const Key& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &aResponse);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundRequestChild::HandleResponse(const nsTArray<Key>& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &aResponse);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundRequestChild::HandleResponse(
|
|
|
|
const SerializedStructuredCloneReadInfo& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
// XXX Fix this somehow...
|
|
|
|
auto& serializedCloneInfo =
|
|
|
|
const_cast<SerializedStructuredCloneReadInfo&>(aResponse);
|
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
auto cloneReadInfo = DeserializeStructuredCloneReadInfo(
|
|
|
|
std::move(serializedCloneInfo), mTransaction->Database());
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
if (cloneReadInfo.mHasPreprocessInfo) {
|
|
|
|
UniquePtr<JSStructuredCloneData> cloneData = GetNextCloneData();
|
|
|
|
cloneReadInfo.mData = std::move(*cloneData);
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
ResultHelper helper(mRequest, mTransaction, &cloneReadInfo);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void 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();
|
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
// Move relevant data into the cloneReadInfo
|
2019-11-08 16:22:08 +03:00
|
|
|
*cloneReadInfo = DeserializeStructuredCloneReadInfo(
|
|
|
|
std::move(serializedCloneInfo), database);
|
2019-07-03 13:23:33 +03:00
|
|
|
|
|
|
|
if (cloneReadInfo->mHasPreprocessInfo) {
|
|
|
|
UniquePtr<JSStructuredCloneData> cloneData = GetNextCloneData();
|
|
|
|
cloneReadInfo->mData = std::move(*cloneData);
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &cloneReadInfos);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundRequestChild::HandleResponse(JS::Handle<JS::Value> aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &aResponse);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundRequestChild::HandleResponse(uint64_t aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
JS::Value response(JS::NumberValue(aResponse));
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, &response);
|
|
|
|
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
nsresult BackgroundRequestChild::HandlePreprocess(
|
2019-07-03 13:23:33 +03:00
|
|
|
const PreprocessInfo& aPreprocessInfo) {
|
2019-11-20 16:26:16 +03:00
|
|
|
return HandlePreprocessInternal(
|
|
|
|
AutoTArray<PreprocessInfo, 1>{aPreprocessInfo});
|
|
|
|
}
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2019-11-20 16:26:16 +03:00
|
|
|
nsresult BackgroundRequestChild::HandlePreprocess(
|
|
|
|
const nsTArray<PreprocessInfo>& aPreprocessInfos) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
mGetAll = true;
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2019-11-20 16:26:16 +03:00
|
|
|
return HandlePreprocessInternal(aPreprocessInfos);
|
2016-10-26 07:51:33 +03:00
|
|
|
}
|
|
|
|
|
2019-11-20 16:26:16 +03:00
|
|
|
nsresult BackgroundRequestChild::HandlePreprocessInternal(
|
2019-07-03 13:23:33 +03:00
|
|
|
const nsTArray<PreprocessInfo>& aPreprocessInfos) {
|
2016-10-26 07:51:33 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
IDBDatabase* database = mTransaction->Database();
|
|
|
|
|
|
|
|
uint32_t count = aPreprocessInfos.Length();
|
|
|
|
|
|
|
|
mPreprocessHelpers.SetLength(count);
|
|
|
|
|
|
|
|
// TODO: Since we use the stream transport service, this can spawn 25 threads
|
|
|
|
// and has the potential to cause some annoying browser hiccups.
|
|
|
|
// Consider using a single thread or a very small threadpool.
|
|
|
|
for (uint32_t index = 0; index < count; index++) {
|
2019-07-03 13:23:33 +03:00
|
|
|
const PreprocessInfo& preprocessInfo = aPreprocessInfos[index];
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2019-11-08 16:22:08 +03:00
|
|
|
const auto files =
|
|
|
|
DeserializeStructuredCloneFiles(database, preprocessInfo.files(),
|
|
|
|
/* aForPreprocess */ true);
|
2019-07-03 13:23:33 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(files.Length() == 1);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
|
|
|
RefPtr<PreprocessHelper>& preprocessHelper = mPreprocessHelpers[index];
|
|
|
|
preprocessHelper = new PreprocessHelper(index, this);
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsresult rv = preprocessHelper->Init(files[0]);
|
2016-10-26 07:51:33 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = preprocessHelper->Dispatch();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRunningPreprocessHelpers++;
|
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
mCloneDatas.SetLength(count);
|
2016-10-26 07:51:33 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void BackgroundRequestChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
for (uint32_t count = mPreprocessHelpers.Length(), index = 0; index < count;
|
|
|
|
index++) {
|
|
|
|
RefPtr<PreprocessHelper>& preprocessHelper = mPreprocessHelpers[index];
|
|
|
|
|
|
|
|
if (preprocessHelper) {
|
|
|
|
preprocessHelper->ClearActor();
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
preprocessHelper = nullptr;
|
|
|
|
}
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
if (mTransaction) {
|
|
|
|
mTransaction->AssertIsOnOwningThread();
|
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
mTransaction->OnRequestFinished(/* aRequestCompletedSuccessfully */
|
2015-03-19 00:20:59 +03:00
|
|
|
aWhy == Deletion);
|
|
|
|
#ifdef DEBUG
|
|
|
|
mTransaction = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundRequestChild::Recv__delete__(
|
|
|
|
const RequestResponse& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (mTransaction->IsAborted()) {
|
2015-03-19 00:20:59 +03: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-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TObjectStoreAddResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreAddResponse().key());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TObjectStorePutResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStorePutResponse().key());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TObjectStoreGetResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreGetResponse().cloneInfo());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2016-07-21 11:31:59 +03:00
|
|
|
case RequestResponse::TObjectStoreGetKeyResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreGetKeyResponse().key());
|
|
|
|
break;
|
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TObjectStoreGetAllResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreGetAllResponse().cloneInfos());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TObjectStoreGetAllKeysResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreGetAllKeysResponse().keys());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TObjectStoreDeleteResponse:
|
|
|
|
HandleResponse(JS::UndefinedHandleValue);
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TObjectStoreClearResponse:
|
|
|
|
HandleResponse(JS::UndefinedHandleValue);
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TObjectStoreCountResponse:
|
|
|
|
HandleResponse(aResponse.get_ObjectStoreCountResponse().count());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TIndexGetResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexGetResponse().cloneInfo());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TIndexGetKeyResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexGetKeyResponse().key());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TIndexGetAllResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexGetAllResponse().cloneInfos());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TIndexGetAllKeysResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexGetAllKeysResponse().keys());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
case RequestResponse::TIndexCountResponse:
|
|
|
|
HandleResponse(aResponse.get_IndexCountResponse().count());
|
|
|
|
break;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown response type!");
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
mTransaction->OnRequestFinished(/* aRequestCompletedSuccessfully */ true);
|
2015-03-19 00:20:59 +03:00
|
|
|
|
|
|
|
// Null this out so that we don't try to call OnRequestFinished() again in
|
|
|
|
// ActorDestroy.
|
|
|
|
mTransaction = nullptr;
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2016-10-25 22:19:06 +03:00
|
|
|
mozilla::ipc::IPCResult BackgroundRequestChild::RecvPreprocess(
|
|
|
|
const PreprocessParams& aParams) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
nsresult rv;
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
switch (aParams.type()) {
|
|
|
|
case PreprocessParams::TObjectStoreGetPreprocessParams: {
|
|
|
|
ObjectStoreGetPreprocessParams params =
|
|
|
|
aParams.get_ObjectStoreGetPreprocessParams();
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
rv = HandlePreprocess(params.preprocessInfo());
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
case PreprocessParams::TObjectStoreGetAllPreprocessParams: {
|
|
|
|
ObjectStoreGetAllPreprocessParams params =
|
|
|
|
aParams.get_ObjectStoreGetAllPreprocessParams();
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2016-10-26 07:51:33 +03:00
|
|
|
rv = HandlePreprocess(params.preprocessInfos());
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown params type!");
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2016-11-15 06:26:00 +03:00
|
|
|
if (!SendContinue(rv)) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult BackgroundRequestChild::PreprocessHelper::Init(
|
2019-07-03 13:23:33 +03:00
|
|
|
const StructuredCloneFile& aFile) {
|
2016-10-25 22:19:06 +03:00
|
|
|
AssertIsOnOwningThread();
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(aFile.mBlob);
|
|
|
|
MOZ_ASSERT(aFile.mType == StructuredCloneFile::eStructuredClone);
|
|
|
|
MOZ_ASSERT(mState == State::Initial);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
// The stream transport service is used for asynchronous processing. It has a
|
|
|
|
// threadpool with a high cap of 25 threads. Fortunately, the service can be
|
|
|
|
// used on workers too.
|
|
|
|
nsCOMPtr<nsIEventTarget> target =
|
|
|
|
do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
|
|
|
MOZ_ASSERT(target);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
// We use a TaskQueue here in order to be sure that the events are dispatched
|
|
|
|
// in the correct order. This is not guaranteed in case we use the I/O thread
|
|
|
|
// directly.
|
|
|
|
mTaskQueue = new TaskQueue(target.forget());
|
|
|
|
mTaskQueueEventTarget = mTaskQueue->WrapAsEventTarget();
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
ErrorResult errorResult;
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
|
|
|
aFile.mBlob->CreateInputStream(getter_AddRefs(stream), errorResult);
|
|
|
|
if (NS_WARN_IF(errorResult.Failed())) {
|
|
|
|
return errorResult.StealNSResult();
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
mStream = std::move(stream);
|
|
|
|
|
|
|
|
mCloneData = MakeUnique<JSStructuredCloneData>(
|
|
|
|
JS::StructuredCloneScope::DifferentProcessForIndexedDB);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult BackgroundRequestChild::PreprocessHelper::Dispatch() {
|
|
|
|
AssertIsOnOwningThread();
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(mState == State::Initial);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2017-05-23 08:52:47 +03:00
|
|
|
nsresult rv = mTaskQueueEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
|
2016-10-25 22:19:06 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsresult BackgroundRequestChild::PreprocessHelper::Start() {
|
|
|
|
MOZ_ASSERT(!IsOnOwningThread());
|
|
|
|
MOZ_ASSERT(mStream);
|
|
|
|
MOZ_ASSERT(mState == State::Initial);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsresult rv;
|
2016-10-26 07:51:33 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
PRFileDesc* fileDesc = GetFileDescriptorFromStream(mStream);
|
|
|
|
if (fileDesc) {
|
|
|
|
rv = ProcessStream();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
2019-07-03 13:23:33 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
mState = State::WaitingForStreamReady;
|
2019-06-04 21:43:02 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsCOMPtr<nsIAsyncFileMetadata> asyncFileMetadata = do_QueryInterface(mStream);
|
|
|
|
if (asyncFileMetadata) {
|
|
|
|
rv = asyncFileMetadata->AsyncFileMetadataWait(this, mTaskQueueEventTarget);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2019-06-04 21:43:02 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
return NS_OK;
|
2019-06-04 21:43:02 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(mStream);
|
|
|
|
if (!asyncStream) {
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
2019-06-04 21:43:02 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
rv = asyncStream->AsyncWait(this, 0, 0, mTaskQueueEventTarget);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2019-06-04 21:43:02 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
return NS_OK;
|
2019-06-04 21:43:02 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsresult BackgroundRequestChild::PreprocessHelper::ProcessStream() {
|
2016-10-25 22:19:06 +03:00
|
|
|
MOZ_ASSERT(!IsOnOwningThread());
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(mStream);
|
|
|
|
MOZ_ASSERT(mState == State::Initial ||
|
|
|
|
mState == State::WaitingForStreamReady);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
// We need to get the internal stream (which is an nsFileInputStream) because
|
|
|
|
// SnappyUncompressInputStream doesn't support reading from async input
|
|
|
|
// streams.
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsCOMPtr<mozIIPCBlobInputStream> blobInputStream = do_QueryInterface(mStream);
|
|
|
|
MOZ_ASSERT(blobInputStream);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsCOMPtr<nsIInputStream> internalInputStream =
|
|
|
|
blobInputStream->GetInternalStream();
|
|
|
|
MOZ_ASSERT(internalInputStream);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
RefPtr<SnappyUncompressInputStream> snappyInputStream =
|
|
|
|
new SnappyUncompressInputStream(internalInputStream);
|
2019-06-04 21:43:02 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
nsresult rv;
|
2017-05-23 08:52:47 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
do {
|
|
|
|
char buffer[kFileCopyBufferSize];
|
2017-05-23 08:52:47 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
uint32_t numRead;
|
|
|
|
rv = snappyInputStream->Read(buffer, sizeof(buffer), &numRead);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
break;
|
|
|
|
}
|
2017-05-23 08:52:47 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
if (!numRead) {
|
|
|
|
break;
|
|
|
|
}
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
if (NS_WARN_IF(!mCloneData->AppendBytes(buffer, numRead))) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
2017-09-08 17:06:26 +03:00
|
|
|
}
|
2019-07-03 13:23:33 +03:00
|
|
|
} while (true);
|
2017-09-08 17:06:26 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2017-09-08 17:06:26 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
mState = State::Finishing;
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
rv = mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
|
2017-05-23 08:52:47 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2016-10-25 22:19:06 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
void BackgroundRequestChild::PreprocessHelper::Finish() {
|
|
|
|
AssertIsOnOwningThread();
|
2017-05-23 08:52:47 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
if (mActor) {
|
|
|
|
if (NS_SUCCEEDED(mResultCode)) {
|
|
|
|
mActor->OnPreprocessFinished(mCloneDataIndex, std::move(mCloneData));
|
2017-05-23 08:52:47 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(!mCloneData);
|
|
|
|
} else {
|
|
|
|
mActor->OnPreprocessFailed(mCloneDataIndex, mResultCode);
|
|
|
|
}
|
2017-05-23 08:52:47 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
mState = State::Completed;
|
2017-05-23 08:52:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(BackgroundRequestChild::PreprocessHelper,
|
2017-09-08 17:06:26 +03:00
|
|
|
CancelableRunnable, nsIInputStreamCallback,
|
|
|
|
nsIFileMetadataCallback)
|
2017-05-23 08:52:47 +03:00
|
|
|
|
2016-10-25 22:19:06 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
BackgroundRequestChild::PreprocessHelper::Run() {
|
2019-07-03 13:23:33 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
switch (mState) {
|
|
|
|
case State::Initial:
|
|
|
|
rv = Start();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::WaitingForStreamReady:
|
|
|
|
rv = ProcessStream();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::Finishing:
|
|
|
|
Finish();
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad state!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)) && mState != State::Finishing) {
|
|
|
|
if (NS_SUCCEEDED(mResultCode)) {
|
|
|
|
mResultCode = rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must set mState before dispatching otherwise we will race with the owning
|
|
|
|
// thread.
|
|
|
|
mState = State::Finishing;
|
|
|
|
|
|
|
|
if (IsOnOwningThread()) {
|
|
|
|
Finish();
|
|
|
|
} else {
|
|
|
|
MOZ_ALWAYS_SUCCEEDS(
|
|
|
|
mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
|
|
|
|
}
|
2017-05-23 08:52:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BackgroundRequestChild::PreprocessHelper::OnInputStreamReady(
|
|
|
|
nsIAsyncInputStream* aStream) {
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(!IsOnOwningThread());
|
|
|
|
MOZ_ASSERT(mState == State::WaitingForStreamReady);
|
|
|
|
|
|
|
|
MOZ_ALWAYS_SUCCEEDS(this->Run());
|
|
|
|
|
|
|
|
return NS_OK;
|
2017-09-08 17:06:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BackgroundRequestChild::PreprocessHelper::OnFileMetadataReady(
|
|
|
|
nsIAsyncFileMetadata* aObject) {
|
2017-05-23 08:52:47 +03:00
|
|
|
MOZ_ASSERT(!IsOnOwningThread());
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ASSERT(mState == State::WaitingForStreamReady);
|
2016-10-25 22:19:06 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(this->Run());
|
2017-05-23 08:52:47 +03:00
|
|
|
|
2019-07-03 13:23:33 +03:00
|
|
|
return NS_OK;
|
2016-10-25 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundCursorChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-11-05 17:40:35 +03:00
|
|
|
BackgroundCursorChild::CachedResponse::CachedResponse(
|
|
|
|
Key aKey, StructuredCloneReadInfo&& aCloneInfo)
|
|
|
|
: mKey{std::move(aKey)}, mCloneInfo{std::move(aCloneInfo)} {}
|
|
|
|
|
|
|
|
BackgroundCursorChild::CachedResponse::CachedResponse(
|
|
|
|
Key aKey, Key aLocaleAwareKey, Key aObjectStoreKey,
|
|
|
|
StructuredCloneReadInfo&& aCloneInfo)
|
|
|
|
: mKey{std::move(aKey)},
|
|
|
|
mLocaleAwareKey{std::move(aLocaleAwareKey)},
|
|
|
|
mObjectStoreKey{std::move(aObjectStoreKey)},
|
|
|
|
mCloneInfo{std::move(aCloneInfo)} {}
|
|
|
|
|
2019-11-05 17:40:31 +03:00
|
|
|
BackgroundCursorChild::CachedResponse::CachedResponse(Key aKey)
|
|
|
|
: mKey{std::move(aKey)} {}
|
|
|
|
|
|
|
|
BackgroundCursorChild::CachedResponse::CachedResponse(Key aKey,
|
|
|
|
Key aLocaleAwareKey,
|
|
|
|
Key aObjectStoreKey)
|
|
|
|
: mKey{std::move(aKey)},
|
|
|
|
mLocaleAwareKey{std::move(aLocaleAwareKey)},
|
|
|
|
mObjectStoreKey{std::move(aObjectStoreKey)} {}
|
|
|
|
|
2016-04-11 21:40:06 +03:00
|
|
|
// Does not need to be threadsafe since this only runs on one thread, but
|
2016-04-11 21:40:06 +03:00
|
|
|
// inheriting from CancelableRunnable is easy.
|
2015-06-09 17:57:19 +03:00
|
|
|
class BackgroundCursorChild::DelayedActionRunnable final
|
2016-04-11 21:40:06 +03:00
|
|
|
: public CancelableRunnable {
|
2015-06-09 17:57:19 +03:00
|
|
|
using ActionFunc = void (BackgroundCursorChild::*)();
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
BackgroundCursorChild* mActor;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBRequest> mRequest;
|
2015-06-09 17:57:19 +03:00
|
|
|
ActionFunc mActionFunc;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
public:
|
2015-06-09 17:57:19 +03:00
|
|
|
explicit DelayedActionRunnable(BackgroundCursorChild* aActor,
|
|
|
|
ActionFunc aActionFunc)
|
2017-01-13 11:40:58 +03:00
|
|
|
: CancelableRunnable(
|
|
|
|
"indexedDB::BackgroundCursorChild::DelayedActionRunnable"),
|
|
|
|
mActor(aActor),
|
2014-09-27 03:21:57 +04:00
|
|
|
mRequest(aActor->mRequest),
|
2015-06-09 17:57:19 +03:00
|
|
|
mActionFunc(aActionFunc) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
aActor->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
2015-06-09 17:57:19 +03:00
|
|
|
MOZ_ASSERT(mActionFunc);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-11-08 16:22:28 +03:00
|
|
|
~DelayedActionRunnable() = default;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
NS_DECL_NSIRUNNABLE
|
2016-04-11 21:40:06 +03:00
|
|
|
nsresult Cancel() override;
|
2014-09-27 03:21:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
BackgroundCursorChild::BackgroundCursorChild(IDBRequest* aRequest,
|
|
|
|
IDBObjectStore* aObjectStore,
|
|
|
|
Direction aDirection)
|
|
|
|
: mRequest(aRequest),
|
|
|
|
mTransaction(aRequest->GetTransaction()),
|
|
|
|
mObjectStore(aObjectStore),
|
|
|
|
mIndex(nullptr),
|
|
|
|
mCursor(nullptr),
|
|
|
|
mStrongRequest(aRequest),
|
2019-11-14 19:14:02 +03:00
|
|
|
mDirection(aDirection),
|
|
|
|
mInFlightResponseInvalidationNeeded(false) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aObjectStore);
|
|
|
|
aObjectStore->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundCursorChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundCursorChild::BackgroundCursorChild(IDBRequest* aRequest,
|
|
|
|
IDBIndex* aIndex,
|
|
|
|
Direction aDirection)
|
|
|
|
: mRequest(aRequest),
|
|
|
|
mTransaction(aRequest->GetTransaction()),
|
|
|
|
mObjectStore(nullptr),
|
|
|
|
mIndex(aIndex),
|
|
|
|
mCursor(nullptr),
|
|
|
|
mStrongRequest(aRequest),
|
2019-11-14 19:14:02 +03:00
|
|
|
mDirection(aDirection),
|
|
|
|
mInFlightResponseInvalidationNeeded(false) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aIndex);
|
|
|
|
aIndex->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundCursorChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundCursorChild::~BackgroundCursorChild() {
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundCursorChild);
|
|
|
|
}
|
|
|
|
|
2016-07-26 13:51:19 +03:00
|
|
|
void BackgroundCursorChild::SendContinueInternal(
|
2019-11-05 17:40:35 +03:00
|
|
|
const CursorRequestParams& aParams, const Key& aCurrentKey,
|
|
|
|
const Key& aCurrentObjectStoreKey) {
|
2014-09-27 03:21:57 +04: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();
|
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
CursorRequestParams params = aParams;
|
|
|
|
Key currentKey = aCurrentKey;
|
2019-11-05 17:40:35 +03:00
|
|
|
Key currentObjectStoreKey = aCurrentObjectStoreKey;
|
2019-11-05 17:40:37 +03:00
|
|
|
|
|
|
|
switch (params.type()) {
|
|
|
|
case CursorRequestParams::TContinueParams: {
|
|
|
|
const auto& key = params.get_ContinueParams().key();
|
|
|
|
if (key.IsUnset()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-05 19:46:10 +03:00
|
|
|
// Discard cache entries before the target key.
|
|
|
|
DiscardCachedResponses(
|
|
|
|
[&key, isLocaleAware = mCursor->IsLocaleAware(),
|
|
|
|
keyOperator = GetKeyOperator(mDirection),
|
|
|
|
transactionSerialNumber = mTransaction->LoggingSerialNumber(),
|
|
|
|
requestSerialNumber = mRequest->LoggingSerialNumber()](
|
|
|
|
const auto& currentCachedResponse) {
|
|
|
|
// This duplicates the logic from the parent. We could avoid this
|
|
|
|
// duplication if we invalidated the cached records always for any
|
|
|
|
// continue-with-key operation, but would lose the benefits of
|
|
|
|
// preloading then.
|
|
|
|
const auto& cachedSortKey =
|
|
|
|
isLocaleAware ? currentCachedResponse.mLocaleAwareKey
|
|
|
|
: currentCachedResponse.mKey;
|
|
|
|
const bool discard = !(cachedSortKey.*keyOperator)(key);
|
|
|
|
if (discard) {
|
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"PRELOAD: Continue to key %s, discarding cached key %s/%s",
|
|
|
|
"Continue, discarding", transactionSerialNumber,
|
|
|
|
requestSerialNumber, key.GetBuffer().get(),
|
|
|
|
cachedSortKey.GetBuffer().get(),
|
|
|
|
currentCachedResponse.mObjectStoreKey.GetBuffer().get());
|
|
|
|
} else {
|
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"PRELOAD: Continue to key %s, keeping cached key %s/%s and "
|
|
|
|
"further",
|
|
|
|
"Continue, keeping", transactionSerialNumber,
|
|
|
|
requestSerialNumber, key.GetBuffer().get(),
|
|
|
|
cachedSortKey.GetBuffer().get(),
|
|
|
|
currentCachedResponse.mObjectStoreKey.GetBuffer().get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return discard;
|
|
|
|
});
|
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CursorRequestParams::TContinuePrimaryKeyParams:
|
|
|
|
// TODO: Implement preloading for this case
|
|
|
|
InvalidateCachedResponses();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CursorRequestParams::TAdvanceParams: {
|
|
|
|
uint32_t& advanceCount = params.get_AdvanceParams().count();
|
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"PRELOAD: Advancing %" PRIu32 " records", "Advancing",
|
|
|
|
mTransaction->LoggingSerialNumber(), mRequest->LoggingSerialNumber(),
|
|
|
|
advanceCount);
|
|
|
|
|
2019-11-05 19:46:10 +03:00
|
|
|
// Discard cache entries.
|
|
|
|
DiscardCachedResponses(
|
|
|
|
[&advanceCount, ¤tKey,
|
|
|
|
¤tObjectStoreKey](const auto& currentCachedResponse) {
|
|
|
|
const bool res = advanceCount > 1;
|
|
|
|
if (res) {
|
|
|
|
--advanceCount;
|
|
|
|
|
|
|
|
// TODO: We only need to update currentKey on the last entry, the
|
|
|
|
// others are overwritten in the next iteration anyway.
|
|
|
|
currentKey = currentCachedResponse.mKey;
|
|
|
|
currentObjectStoreKey = currentCachedResponse.mObjectStoreKey;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
});
|
2019-11-05 17:40:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mCachedResponses.empty()) {
|
|
|
|
// We need to remove the response here from mCachedResponses, since when
|
|
|
|
// requests are interleaved, other events may be processed before
|
|
|
|
// CompleteContinueRequestFromCache, which may modify mCachedResponses.
|
|
|
|
mDelayedResponses.emplace_back(std::move(mCachedResponses.front()));
|
|
|
|
mCachedResponses.pop_front();
|
|
|
|
|
|
|
|
// We cannot send the response right away, as we must preserve the request
|
|
|
|
// order. Dispatching a DelayedActionRunnable only partially addresses this.
|
|
|
|
// This is accompanied by invalidating cached entries at proper locations to
|
|
|
|
// make it correct. To avoid this, further changes are necessary, see Bug
|
|
|
|
// 1580499.
|
|
|
|
nsCOMPtr<nsIRunnable> continueRunnable = new DelayedActionRunnable(
|
|
|
|
this, &BackgroundCursorChild::CompleteContinueRequestFromCache);
|
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
NS_SUCCEEDED(NS_DispatchToCurrentThread(continueRunnable.forget())));
|
|
|
|
|
|
|
|
// TODO: Could we preload further entries in the background when the size of
|
|
|
|
// mCachedResponses falls under some threshold? Or does the response
|
|
|
|
// handling model disallow this?
|
|
|
|
} else {
|
2019-11-05 17:40:35 +03:00
|
|
|
MOZ_ALWAYS_TRUE(PBackgroundIDBCursorChild::SendContinue(
|
|
|
|
params, currentKey, currentObjectStoreKey));
|
2019-11-05 17:40:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundCursorChild::CompleteContinueRequestFromCache() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(mCursor);
|
|
|
|
MOZ_ASSERT(mStrongCursor);
|
|
|
|
MOZ_ASSERT(!mDelayedResponses.empty());
|
|
|
|
|
|
|
|
RefPtr<IDBCursor> cursor;
|
|
|
|
mStrongCursor.swap(cursor);
|
|
|
|
|
|
|
|
auto& item = mDelayedResponses.front();
|
2019-11-05 17:40:35 +03:00
|
|
|
switch (mCursor->GetType()) {
|
|
|
|
case IDBCursor::Type_ObjectStore:
|
|
|
|
mCursor->Reset(std::move(item.mKey), std::move(item.mCloneInfo));
|
|
|
|
break;
|
|
|
|
case IDBCursor::Type_Index:
|
|
|
|
mCursor->Reset(std::move(item.mKey), std::move(item.mLocaleAwareKey),
|
|
|
|
std::move(item.mObjectStoreKey),
|
|
|
|
std::move(item.mCloneInfo));
|
|
|
|
break;
|
2019-11-05 17:40:31 +03:00
|
|
|
case IDBCursor::Type_ObjectStoreKey:
|
|
|
|
mCursor->Reset(std::move(item.mKey));
|
|
|
|
break;
|
|
|
|
case IDBCursor::Type_IndexKey:
|
|
|
|
mCursor->Reset(std::move(item.mKey), std::move(item.mLocaleAwareKey),
|
|
|
|
std::move(item.mObjectStoreKey));
|
|
|
|
break;
|
2019-11-05 17:40:35 +03:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here.");
|
|
|
|
}
|
2019-11-05 17:40:37 +03:00
|
|
|
mDelayedResponses.pop_front();
|
|
|
|
|
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"PRELOAD: Consumed 1 cached response, %zu cached responses remaining",
|
|
|
|
"Consumed cached response", mTransaction->LoggingSerialNumber(),
|
|
|
|
mRequest->LoggingSerialNumber(),
|
|
|
|
mDelayedResponses.size() + mCachedResponses.size());
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, mCursor);
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
|
|
|
|
mTransaction->OnRequestFinished(/* aRequestCompletedSuccessfully */ true);
|
2014-09-27 03:21:57 +04: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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
void BackgroundCursorChild::InvalidateCachedResponses() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
// TODO: With more information on the reason for the invalidation, we might
|
|
|
|
// only selectively invalidate cached responses. If the reason is an updated
|
|
|
|
// value, we do not need to care for key-only cursors. If the key of the
|
|
|
|
// changed entry is not in the remaining range of the cursor, we also do not
|
|
|
|
// need to care, etc.
|
|
|
|
|
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"PRELOAD: Invalidating all %zu cached responses", "Invalidating",
|
|
|
|
mTransaction->LoggingSerialNumber(), mRequest->LoggingSerialNumber(),
|
|
|
|
mCachedResponses.size());
|
|
|
|
|
|
|
|
mCachedResponses.clear();
|
2019-11-14 19:14:02 +03:00
|
|
|
|
|
|
|
// We only hold a strong cursor reference in mStrongCursor when
|
|
|
|
// continue()/similar has been called. In those cases we expect a response
|
|
|
|
// that will be received in the future, and it may include prefetched data
|
|
|
|
// that needs to be discarded.
|
|
|
|
if (mStrongCursor) {
|
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"PRELOAD: Setting flag to invalidate in-flight responses",
|
|
|
|
"Set flag to invalidate in-flight responses",
|
|
|
|
mTransaction->LoggingSerialNumber(), mRequest->LoggingSerialNumber());
|
|
|
|
|
|
|
|
mInFlightResponseInvalidationNeeded = true;
|
|
|
|
}
|
2019-11-05 17:40:37 +03:00
|
|
|
}
|
|
|
|
|
2019-11-05 19:46:10 +03:00
|
|
|
template <typename Condition>
|
|
|
|
void BackgroundCursorChild::DiscardCachedResponses(
|
|
|
|
const Condition& aConditionFunc) {
|
|
|
|
size_t discardedCount = 0;
|
|
|
|
while (!mCachedResponses.empty() &&
|
|
|
|
aConditionFunc(mCachedResponses.front())) {
|
|
|
|
mCachedResponses.pop_front();
|
|
|
|
++discardedCount;
|
|
|
|
}
|
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"PRELOAD: Discarded %zu cached responses, %zu remaining", "Discarded",
|
|
|
|
mTransaction->LoggingSerialNumber(), mRequest->LoggingSerialNumber(),
|
|
|
|
discardedCount, mCachedResponses.size());
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04: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 17:57:19 +03:00
|
|
|
nsCOMPtr<nsIRunnable> deleteRunnable = new DelayedActionRunnable(
|
|
|
|
this, &BackgroundCursorChild::SendDeleteMeInternal);
|
2017-01-13 11:40:58 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(this->GetActorEventTarget()->Dispatch(
|
|
|
|
deleteRunnable.forget(), NS_DISPATCH_NORMAL));
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 19:46:23 +03:00
|
|
|
template <typename... Args>
|
2019-11-05 19:46:31 +03:00
|
|
|
void BackgroundCursorChild::HandleIndividualCursorResponse(
|
|
|
|
const bool aUseAsCurrentResult, Args&&... aArgs) {
|
2019-11-05 19:46:23 +03:00
|
|
|
if (mCursor) {
|
2019-11-05 19:46:31 +03:00
|
|
|
if (aUseAsCurrentResult) {
|
2019-11-05 19:46:23 +03:00
|
|
|
mCursor->Reset(std::forward<Args>(aArgs)...);
|
|
|
|
} else {
|
|
|
|
mCachedResponses.emplace_back(std::forward<Args>(aArgs)...);
|
|
|
|
}
|
|
|
|
} else {
|
2019-11-05 19:46:31 +03:00
|
|
|
MOZ_ASSERT(aUseAsCurrentResult);
|
|
|
|
|
2019-11-05 19:46:23 +03:00
|
|
|
// TODO: This looks particularly dangerous to me. Why do we need to
|
|
|
|
// have an extra newCursor of type RefPtr? Why can't we directly
|
|
|
|
// assign to mCursor? Why is mCursor not a RefPtr?
|
|
|
|
RefPtr<IDBCursor> newCursor =
|
|
|
|
IDBCursor::Create(this, std::forward<Args>(aArgs)...);
|
|
|
|
mCursor = newCursor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 17:40:35 +03:00
|
|
|
template <typename T, typename Func>
|
|
|
|
void BackgroundCursorChild::HandleMultipleCursorResponses(
|
|
|
|
const nsTArray<T>& aResponses, const Func& aHandleRecord) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
MOZ_ASSERT(mTransaction);
|
|
|
|
MOZ_ASSERT(!mStrongRequest);
|
|
|
|
MOZ_ASSERT(!mStrongCursor);
|
2019-11-05 17:40:35 +03:00
|
|
|
MOZ_ASSERT(aResponses.Length() > 0);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"PRELOAD: Received %zu cursor responses", "Received",
|
|
|
|
mTransaction->LoggingSerialNumber(), mRequest->LoggingSerialNumber(),
|
|
|
|
aResponses.Length());
|
|
|
|
MOZ_ASSERT_IF(aResponses.Length() > 1, mCachedResponses.empty());
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-08-20 00:59:25 +03:00
|
|
|
// XXX Fix this somehow...
|
2019-11-05 17:40:35 +03:00
|
|
|
auto& responses = const_cast<nsTArray<T>&>(aResponses);
|
2015-08-20 00:59:25 +03:00
|
|
|
|
2019-11-05 19:46:31 +03:00
|
|
|
bool isFirst = true;
|
2019-11-05 17:40:35 +03:00
|
|
|
for (auto& response : responses) {
|
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"PRELOAD: Processing response for key %s", "Processing",
|
|
|
|
mTransaction->LoggingSerialNumber(), mRequest->LoggingSerialNumber(),
|
|
|
|
response.key().GetBuffer().get());
|
2019-11-05 17:34:22 +03:00
|
|
|
|
2019-11-05 19:46:31 +03:00
|
|
|
// TODO: At the moment, we only send a cursor request to the parent if
|
|
|
|
// requested by the user code. Therefore, the first result is always used as
|
|
|
|
// the current result, and the potential extra results are cached. If we
|
|
|
|
// extended this towards preloading in the background, all results might
|
|
|
|
// need to be cached.
|
|
|
|
aHandleRecord(/* aUseAsCurrentResult */ isFirst, response);
|
|
|
|
isFirst = false;
|
2019-11-14 19:14:02 +03:00
|
|
|
|
|
|
|
if (mInFlightResponseInvalidationNeeded) {
|
|
|
|
IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
|
|
|
|
"PRELOAD: Discarding remaining responses since "
|
|
|
|
"mInFlightResponseInvalidationNeeded is set",
|
|
|
|
"Discarding responses", mTransaction->LoggingSerialNumber(),
|
|
|
|
mRequest->LoggingSerialNumber());
|
|
|
|
|
|
|
|
mInFlightResponseInvalidationNeeded = false;
|
|
|
|
break;
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultHelper helper(mRequest, mTransaction, mCursor);
|
|
|
|
DispatchSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
2019-11-05 17:40:35 +03:00
|
|
|
void BackgroundCursorChild::HandleResponse(
|
|
|
|
const nsTArray<ObjectStoreCursorResponse>& aResponses) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mObjectStore);
|
2019-11-08 16:22:08 +03:00
|
|
|
MOZ_ASSERT(mTransaction);
|
2019-11-05 17:40:35 +03:00
|
|
|
|
|
|
|
HandleMultipleCursorResponses(
|
2019-11-05 19:46:31 +03:00
|
|
|
aResponses, [this](const bool useAsCurrentResult,
|
|
|
|
ObjectStoreCursorResponse& response) {
|
2019-11-05 17:40:35 +03:00
|
|
|
// TODO: Maybe move the deserialization of the clone-read-info into the
|
|
|
|
// cursor, so that it is only done for records actually accessed, which
|
|
|
|
// might not be the case for all cached records.
|
2019-11-05 19:46:23 +03:00
|
|
|
HandleIndividualCursorResponse(
|
2019-11-05 19:46:31 +03:00
|
|
|
useAsCurrentResult, std::move(response.key()),
|
2019-11-08 16:22:08 +03:00
|
|
|
DeserializeStructuredCloneReadInfo(std::move(response.cloneInfo()),
|
|
|
|
mTransaction->Database()));
|
2019-11-05 17:40:35 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-05 15:45:48 +03:00
|
|
|
void BackgroundCursorChild::HandleResponse(
|
2019-11-05 17:40:31 +03:00
|
|
|
const nsTArray<ObjectStoreKeyCursorResponse>& aResponses) {
|
2019-11-05 15:45:48 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mObjectStore);
|
2019-11-05 17:34:22 +03:00
|
|
|
|
2019-11-05 17:40:31 +03:00
|
|
|
HandleMultipleCursorResponses(
|
2019-11-05 19:46:31 +03:00
|
|
|
aResponses, [this](const bool useAsCurrentResult,
|
|
|
|
ObjectStoreKeyCursorResponse& response) {
|
|
|
|
HandleIndividualCursorResponse(useAsCurrentResult,
|
|
|
|
std::move(response.key()));
|
2019-11-05 17:40:31 +03:00
|
|
|
});
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundCursorChild::HandleResponse(
|
2019-11-05 17:40:35 +03:00
|
|
|
const nsTArray<IndexCursorResponse>& aResponses) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mIndex);
|
2019-11-08 16:22:08 +03:00
|
|
|
MOZ_ASSERT(mTransaction);
|
2019-11-05 17:34:22 +03:00
|
|
|
|
2019-11-05 19:46:23 +03:00
|
|
|
HandleMultipleCursorResponses(
|
2019-11-05 19:46:31 +03:00
|
|
|
aResponses,
|
|
|
|
[this](const bool useAsCurrentResult, IndexCursorResponse& response) {
|
2019-11-05 19:46:23 +03:00
|
|
|
HandleIndividualCursorResponse(
|
2019-11-05 19:46:31 +03:00
|
|
|
useAsCurrentResult, std::move(response.key()),
|
|
|
|
std::move(response.sortKey()), std::move(response.objectKey()),
|
2019-11-08 16:22:08 +03:00
|
|
|
DeserializeStructuredCloneReadInfo(std::move(response.cloneInfo()),
|
|
|
|
mTransaction->Database()));
|
2019-11-05 19:46:23 +03:00
|
|
|
});
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundCursorChild::HandleResponse(
|
2019-11-05 17:40:31 +03:00
|
|
|
const nsTArray<IndexKeyCursorResponse>& aResponses) {
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mIndex);
|
2019-11-05 17:34:22 +03:00
|
|
|
|
2019-11-05 17:40:31 +03:00
|
|
|
HandleMultipleCursorResponses(
|
2019-11-05 19:46:31 +03:00
|
|
|
aResponses,
|
|
|
|
[this](const bool useAsCurrentResult, IndexKeyCursorResponse& response) {
|
|
|
|
HandleIndividualCursorResponse(
|
|
|
|
useAsCurrentResult, std::move(response.key()),
|
|
|
|
std::move(response.sortKey()), std::move(response.objectKey()));
|
2019-11-05 17:40:31 +03:00
|
|
|
});
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundCursorChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT_IF(aWhy == Deletion, !mStrongRequest);
|
|
|
|
MOZ_ASSERT_IF(aWhy == Deletion, !mStrongCursor);
|
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
|
|
|
if (mStrongRequest && !mStrongCursor && mTransaction) {
|
2019-11-05 17:40:37 +03:00
|
|
|
mTransaction->OnRequestFinished(/* aRequestCompletedSuccessfully */
|
2015-03-19 00:20:59 +03:00
|
|
|
aWhy == Deletion);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mCursor) {
|
|
|
|
mCursor->ClearBackgroundActor();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mCursor = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mRequest = nullptr;
|
|
|
|
mTransaction = nullptr;
|
|
|
|
mObjectStore = nullptr;
|
|
|
|
mIndex = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult 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 03:42:53 +03:00
|
|
|
MOZ_ASSERT_IF(!mCursor, mStrongRequest);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
MaybeCollectGarbageOnIPCMessage();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBRequest> request;
|
2014-09-27 03:21:57 +04:00
|
|
|
mStrongRequest.swap(request);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBCursor> cursor;
|
2014-09-27 03:21:57 +04:00
|
|
|
mStrongCursor.swap(cursor);
|
|
|
|
|
2018-12-20 16:39:46 +03:00
|
|
|
RefPtr<IDBTransaction> transaction = mTransaction;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
switch (aResponse.type()) {
|
|
|
|
case CursorResponse::Tnsresult:
|
|
|
|
HandleResponse(aResponse.get_nsresult());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CursorResponse::Tvoid_t:
|
|
|
|
HandleResponse(aResponse.get_void_t());
|
|
|
|
break;
|
|
|
|
|
2015-08-20 00:59:25 +03:00
|
|
|
case CursorResponse::TArrayOfObjectStoreCursorResponse:
|
|
|
|
HandleResponse(aResponse.get_ArrayOfObjectStoreCursorResponse());
|
2014-09-27 03:21:57 +04:00
|
|
|
break;
|
|
|
|
|
2019-11-05 17:40:31 +03:00
|
|
|
case CursorResponse::TArrayOfObjectStoreKeyCursorResponse:
|
|
|
|
HandleResponse(aResponse.get_ArrayOfObjectStoreKeyCursorResponse());
|
2014-09-27 03:21:57 +04:00
|
|
|
break;
|
|
|
|
|
2019-11-05 17:40:35 +03:00
|
|
|
case CursorResponse::TArrayOfIndexCursorResponse:
|
|
|
|
HandleResponse(aResponse.get_ArrayOfIndexCursorResponse());
|
2014-09-27 03:21:57 +04:00
|
|
|
break;
|
|
|
|
|
2019-11-05 17:40:31 +03:00
|
|
|
case CursorResponse::TArrayOfIndexKeyCursorResponse:
|
|
|
|
HandleResponse(aResponse.get_ArrayOfIndexKeyCursorResponse());
|
2014-09-27 03:21:57 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
2019-11-05 17:40:37 +03:00
|
|
|
transaction->OnRequestFinished(/* aRequestCompletedSuccessfully */ true);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-06-09 17:57:19 +03:00
|
|
|
BackgroundCursorChild::DelayedActionRunnable::Run() {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mActor);
|
|
|
|
mActor->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
2015-06-09 17:57:19 +03:00
|
|
|
MOZ_ASSERT(mActionFunc);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-06-09 17:57:19 +03:00
|
|
|
(mActor->*mActionFunc)();
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
mActor = nullptr;
|
|
|
|
mRequest = nullptr;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-09 17:57:19 +03:00
|
|
|
nsresult BackgroundCursorChild::DelayedActionRunnable::Cancel() {
|
2014-12-17 09:26:15 +03:00
|
|
|
if (NS_WARN_IF(!mActor)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This must always run to clean up our state.
|
|
|
|
Run();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundFileHandleChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundFileHandleChild::BackgroundFileHandleChild(IDBFileHandle* aFileHandle)
|
|
|
|
: mTemporaryStrongFileHandle(aFileHandle), mFileHandle(aFileHandle) {
|
|
|
|
MOZ_ASSERT(aFileHandle);
|
|
|
|
aFileHandle->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(BackgroundFileHandleChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundFileHandleChild::~BackgroundFileHandleChild() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(BackgroundFileHandleChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void BackgroundFileHandleChild::AssertIsOnOwningThread() const {
|
|
|
|
static_cast<BackgroundMutableFileChild*>(Manager())->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void BackgroundFileHandleChild::SendDeleteMeInternal() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mFileHandle) {
|
|
|
|
NoteActorDestroyed();
|
|
|
|
|
|
|
|
MOZ_ALWAYS_TRUE(PBackgroundFileHandleChild::SendDeleteMe());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundFileHandleChild::NoteActorDestroyed() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT_IF(mTemporaryStrongFileHandle, mFileHandle);
|
|
|
|
|
|
|
|
if (mFileHandle) {
|
|
|
|
mFileHandle->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.
|
|
|
|
mTemporaryStrongFileHandle = nullptr;
|
|
|
|
mFileHandle = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundFileHandleChild::NoteComplete() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT_IF(mFileHandle, mTemporaryStrongFileHandle);
|
|
|
|
|
|
|
|
mTemporaryStrongFileHandle = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundFileHandleChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
NoteActorDestroyed();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundFileHandleChild::RecvComplete(
|
|
|
|
const bool& aAborted) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mFileHandle);
|
|
|
|
|
|
|
|
mFileHandle->FireCompleteOrAbortEvents(aAborted);
|
|
|
|
|
|
|
|
NoteComplete();
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
PBackgroundFileRequestChild*
|
|
|
|
BackgroundFileHandleChild::AllocPBackgroundFileRequestChild(
|
|
|
|
const FileRequestParams& aParams) {
|
|
|
|
MOZ_CRASH(
|
|
|
|
"PBackgroundFileRequestChild actors should be manually "
|
|
|
|
"constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundFileHandleChild::DeallocPBackgroundFileRequestChild(
|
|
|
|
PBackgroundFileRequestChild* aActor) {
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<BackgroundFileRequestChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundFileRequestChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundFileRequestChild::BackgroundFileRequestChild(
|
|
|
|
IDBFileRequest* aFileRequest)
|
|
|
|
: mFileRequest(aFileRequest),
|
|
|
|
mFileHandle(aFileRequest->GetFileHandle()),
|
|
|
|
mActorDestroyed(false) {
|
|
|
|
MOZ_ASSERT(aFileRequest);
|
|
|
|
aFileRequest->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mFileHandle);
|
|
|
|
mFileHandle->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(BackgroundFileRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundFileRequestChild::~BackgroundFileRequestChild() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mFileHandle);
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(BackgroundFileRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void BackgroundFileRequestChild::AssertIsOnOwningThread() const {
|
|
|
|
MOZ_ASSERT(mFileRequest);
|
|
|
|
mFileRequest->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void BackgroundFileRequestChild::HandleResponse(nsresult aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aResponse));
|
|
|
|
MOZ_ASSERT(NS_ERROR_GET_MODULE(aResponse) == NS_ERROR_MODULE_DOM_FILEHANDLE);
|
|
|
|
MOZ_ASSERT(mFileHandle);
|
|
|
|
|
|
|
|
DispatchFileHandleErrorEvent(mFileRequest, aResponse, mFileHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundFileRequestChild::HandleResponse(
|
|
|
|
const FileRequestGetFileResponse& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
RefPtr<File> file = ConvertActorToFile(mFileHandle, aResponse);
|
|
|
|
|
|
|
|
FileHandleResultHelper helper(mFileRequest, mFileHandle, file);
|
|
|
|
|
|
|
|
DispatchFileHandleSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundFileRequestChild::HandleResponse(const nsCString& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
FileHandleResultHelper helper(mFileRequest, mFileHandle, &aResponse);
|
|
|
|
|
|
|
|
DispatchFileHandleSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundFileRequestChild::HandleResponse(
|
|
|
|
const FileRequestMetadata& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
FileHandleResultHelper helper(mFileRequest, mFileHandle, &aResponse);
|
|
|
|
|
|
|
|
DispatchFileHandleSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundFileRequestChild::HandleResponse(
|
|
|
|
JS::Handle<JS::Value> aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
FileHandleResultHelper helper(mFileRequest, mFileHandle, &aResponse);
|
|
|
|
|
|
|
|
DispatchFileHandleSuccessEvent(&helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundFileRequestChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mActorDestroyed);
|
|
|
|
|
|
|
|
mActorDestroyed = true;
|
|
|
|
|
|
|
|
if (mFileHandle) {
|
|
|
|
mFileHandle->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mFileHandle->OnRequestFinished(/* aActorDestroyedNormally */
|
|
|
|
aWhy == Deletion);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mFileHandle = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundFileRequestChild::Recv__delete__(
|
|
|
|
const FileRequestResponse& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mFileRequest);
|
|
|
|
MOZ_ASSERT(mFileHandle);
|
|
|
|
|
|
|
|
if (mFileHandle->IsAborted()) {
|
|
|
|
// Always handle an "error" with ABORT_ERR if the file handle was aborted,
|
|
|
|
// even if the request succeeded or failed with another error.
|
|
|
|
HandleResponse(NS_ERROR_DOM_FILEHANDLE_ABORT_ERR);
|
|
|
|
} else {
|
|
|
|
switch (aResponse.type()) {
|
|
|
|
case FileRequestResponse::Tnsresult:
|
|
|
|
HandleResponse(aResponse.get_nsresult());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileRequestResponse::TFileRequestGetFileResponse:
|
|
|
|
HandleResponse(aResponse.get_FileRequestGetFileResponse());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileRequestResponse::TFileRequestReadResponse:
|
|
|
|
HandleResponse(aResponse.get_FileRequestReadResponse().data());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileRequestResponse::TFileRequestWriteResponse:
|
|
|
|
HandleResponse(JS::UndefinedHandleValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileRequestResponse::TFileRequestTruncateResponse:
|
|
|
|
HandleResponse(JS::UndefinedHandleValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileRequestResponse::TFileRequestFlushResponse:
|
|
|
|
HandleResponse(JS::UndefinedHandleValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileRequestResponse::TFileRequestGetMetadataResponse:
|
|
|
|
HandleResponse(
|
|
|
|
aResponse.get_FileRequestGetMetadataResponse().metadata());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown response type!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mFileHandle->OnRequestFinished(/* aActorDestroyedNormally */ true);
|
|
|
|
|
|
|
|
// Null this out so that we don't try to call OnRequestFinished() again in
|
|
|
|
// ActorDestroy.
|
|
|
|
mFileHandle = nullptr;
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BackgroundFileRequestChild::RecvProgress(
|
|
|
|
const uint64_t& aProgress, const uint64_t& aProgressMax) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mFileRequest);
|
|
|
|
|
|
|
|
mFileRequest->FireProgressEvent(aProgress, aProgressMax);
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2015-11-22 12:44:33 +03:00
|
|
|
/*******************************************************************************
|
|
|
|
* BackgroundUtilsChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BackgroundUtilsChild::BackgroundUtilsChild(IndexedDatabaseManager* aManager)
|
|
|
|
: mManager(aManager) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aManager);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(indexedDB::BackgroundUtilsChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundUtilsChild::~BackgroundUtilsChild() {
|
|
|
|
MOZ_COUNT_DTOR(indexedDB::BackgroundUtilsChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-27 03:21:57 +04:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|