1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/ipc/IndexedDBChild.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1382 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "base/basictypes.h" 1.9 + 1.10 +#include "IndexedDBChild.h" 1.11 + 1.12 +#include "nsIInputStream.h" 1.13 + 1.14 +#include "mozilla/Assertions.h" 1.15 +#include "mozilla/dom/ContentChild.h" 1.16 +#include "mozilla/dom/quota/Client.h" 1.17 +#include "mozilla/dom/quota/QuotaManager.h" 1.18 + 1.19 +#include "AsyncConnectionHelper.h" 1.20 +#include "DatabaseInfo.h" 1.21 +#include "IDBEvents.h" 1.22 +#include "IDBFactory.h" 1.23 +#include "IDBIndex.h" 1.24 +#include "IDBObjectStore.h" 1.25 +#include "IDBTransaction.h" 1.26 + 1.27 +USING_INDEXEDDB_NAMESPACE 1.28 + 1.29 +using namespace mozilla::dom; 1.30 +using mozilla::dom::quota::Client; 1.31 +using mozilla::dom::quota::QuotaManager; 1.32 + 1.33 +namespace { 1.34 + 1.35 +class IPCOpenDatabaseHelper : public AsyncConnectionHelper 1.36 +{ 1.37 +public: 1.38 + IPCOpenDatabaseHelper(IDBDatabase* aDatabase, IDBOpenDBRequest* aRequest) 1.39 + : AsyncConnectionHelper(aDatabase, aRequest) 1.40 + { 1.41 + MOZ_ASSERT(aRequest); 1.42 + } 1.43 + 1.44 + virtual nsresult UnpackResponseFromParentProcess( 1.45 + const ResponseValue& aResponseValue) 1.46 + MOZ_OVERRIDE; 1.47 + 1.48 + virtual ChildProcessSendResult 1.49 + SendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE; 1.50 + 1.51 + virtual nsresult 1.52 + GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE; 1.53 + 1.54 + virtual nsresult 1.55 + OnSuccess() MOZ_OVERRIDE 1.56 + { 1.57 + static_cast<IDBOpenDBRequest*>(mRequest.get())->SetTransaction(nullptr); 1.58 + return AsyncConnectionHelper::OnSuccess(); 1.59 + } 1.60 + 1.61 + virtual void 1.62 + OnError() MOZ_OVERRIDE 1.63 + { 1.64 + static_cast<IDBOpenDBRequest*>(mRequest.get())->SetTransaction(nullptr); 1.65 + AsyncConnectionHelper::OnError(); 1.66 + } 1.67 + 1.68 + virtual nsresult 1.69 + DoDatabaseWork(mozIStorageConnection* aConnection) MOZ_OVERRIDE; 1.70 +}; 1.71 + 1.72 +class IPCSetVersionHelper : public AsyncConnectionHelper 1.73 +{ 1.74 + nsRefPtr<IDBOpenDBRequest> mOpenRequest; 1.75 + uint64_t mOldVersion; 1.76 + uint64_t mRequestedVersion; 1.77 + 1.78 +public: 1.79 + IPCSetVersionHelper(IDBTransaction* aTransaction, IDBOpenDBRequest* aRequest, 1.80 + uint64_t aOldVersion, uint64_t aRequestedVersion) 1.81 + : AsyncConnectionHelper(aTransaction, aRequest), 1.82 + mOpenRequest(aRequest), mOldVersion(aOldVersion), 1.83 + mRequestedVersion(aRequestedVersion) 1.84 + { 1.85 + MOZ_ASSERT(aTransaction); 1.86 + MOZ_ASSERT(aRequest); 1.87 + } 1.88 + 1.89 + virtual nsresult UnpackResponseFromParentProcess( 1.90 + const ResponseValue& aResponseValue) 1.91 + MOZ_OVERRIDE; 1.92 + 1.93 + virtual ChildProcessSendResult 1.94 + SendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE; 1.95 + 1.96 + virtual nsresult 1.97 + DoDatabaseWork(mozIStorageConnection* aConnection) MOZ_OVERRIDE; 1.98 + 1.99 + virtual already_AddRefed<nsIDOMEvent> 1.100 + CreateSuccessEvent(mozilla::dom::EventTarget* aOwner) MOZ_OVERRIDE; 1.101 + 1.102 + virtual nsresult 1.103 + GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE; 1.104 +}; 1.105 + 1.106 +class IPCDeleteDatabaseHelper : public AsyncConnectionHelper 1.107 +{ 1.108 +public: 1.109 + IPCDeleteDatabaseHelper(IDBRequest* aRequest) 1.110 + : AsyncConnectionHelper(static_cast<IDBDatabase*>(nullptr), aRequest) 1.111 + { } 1.112 + 1.113 + virtual nsresult UnpackResponseFromParentProcess( 1.114 + const ResponseValue& aResponseValue) 1.115 + MOZ_OVERRIDE; 1.116 + 1.117 + virtual ChildProcessSendResult 1.118 + SendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE; 1.119 + 1.120 + virtual nsresult 1.121 + GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE; 1.122 + 1.123 + virtual nsresult 1.124 + DoDatabaseWork(mozIStorageConnection* aConnection) MOZ_OVERRIDE; 1.125 +}; 1.126 + 1.127 +class VersionChangeRunnable : public nsRunnable 1.128 +{ 1.129 + nsRefPtr<IDBDatabase> mDatabase; 1.130 + uint64_t mOldVersion; 1.131 + uint64_t mNewVersion; 1.132 + 1.133 +public: 1.134 + VersionChangeRunnable(IDBDatabase* aDatabase, const uint64_t& aOldVersion, 1.135 + const uint64_t& aNewVersion) 1.136 + : mDatabase(aDatabase), mOldVersion(aOldVersion), mNewVersion(aNewVersion) 1.137 + { 1.138 + MOZ_ASSERT(aDatabase); 1.139 + } 1.140 + 1.141 + NS_IMETHOD Run() MOZ_OVERRIDE 1.142 + { 1.143 + if (mDatabase->IsClosed()) { 1.144 + return NS_OK; 1.145 + } 1.146 + 1.147 + nsRefPtr<Event> event = 1.148 + IDBVersionChangeEvent::Create(mDatabase, mOldVersion, mNewVersion); 1.149 + MOZ_ASSERT(event); 1.150 + 1.151 + bool dummy; 1.152 + nsresult rv = mDatabase->DispatchEvent(event, &dummy); 1.153 + NS_ENSURE_SUCCESS(rv, rv); 1.154 + 1.155 + return NS_OK; 1.156 + } 1.157 +}; 1.158 + 1.159 +} // anonymous namespace 1.160 + 1.161 +/******************************************************************************* 1.162 + * IndexedDBChild 1.163 + ******************************************************************************/ 1.164 + 1.165 +IndexedDBChild::IndexedDBChild(const nsCString& aASCIIOrigin) 1.166 +: mFactory(nullptr), mASCIIOrigin(aASCIIOrigin) 1.167 +#ifdef DEBUG 1.168 + , mDisconnected(false) 1.169 +#endif 1.170 +{ 1.171 + MOZ_COUNT_CTOR(IndexedDBChild); 1.172 +} 1.173 + 1.174 +IndexedDBChild::~IndexedDBChild() 1.175 +{ 1.176 + MOZ_COUNT_DTOR(IndexedDBChild); 1.177 + MOZ_ASSERT(!mFactory); 1.178 +} 1.179 + 1.180 +void 1.181 +IndexedDBChild::SetFactory(IDBFactory* aFactory) 1.182 +{ 1.183 + MOZ_ASSERT(aFactory); 1.184 + MOZ_ASSERT(!mFactory); 1.185 + 1.186 + aFactory->SetActor(this); 1.187 + mFactory = aFactory; 1.188 +} 1.189 + 1.190 +void 1.191 +IndexedDBChild::Disconnect() 1.192 +{ 1.193 +#ifdef DEBUG 1.194 + MOZ_ASSERT(!mDisconnected); 1.195 + mDisconnected = true; 1.196 +#endif 1.197 + 1.198 + const InfallibleTArray<PIndexedDBDatabaseChild*>& databases = 1.199 + ManagedPIndexedDBDatabaseChild(); 1.200 + for (uint32_t i = 0; i < databases.Length(); ++i) { 1.201 + static_cast<IndexedDBDatabaseChild*>(databases[i])->Disconnect(); 1.202 + } 1.203 +} 1.204 + 1.205 +void 1.206 +IndexedDBChild::ActorDestroy(ActorDestroyReason aWhy) 1.207 +{ 1.208 + if (mFactory) { 1.209 + mFactory->SetActor(static_cast<IndexedDBChild*>(nullptr)); 1.210 +#ifdef DEBUG 1.211 + mFactory = nullptr; 1.212 +#endif 1.213 + } 1.214 +} 1.215 + 1.216 +PIndexedDBDatabaseChild* 1.217 +IndexedDBChild::AllocPIndexedDBDatabaseChild( 1.218 + const nsString& aName, 1.219 + const uint64_t& aVersion, 1.220 + const PersistenceType& aPersistenceType) 1.221 +{ 1.222 + return new IndexedDBDatabaseChild(aName, aVersion); 1.223 +} 1.224 + 1.225 +bool 1.226 +IndexedDBChild::DeallocPIndexedDBDatabaseChild(PIndexedDBDatabaseChild* aActor) 1.227 +{ 1.228 + delete aActor; 1.229 + return true; 1.230 +} 1.231 + 1.232 +PIndexedDBDeleteDatabaseRequestChild* 1.233 +IndexedDBChild::AllocPIndexedDBDeleteDatabaseRequestChild( 1.234 + const nsString& aName, 1.235 + const PersistenceType& aPersistenceType) 1.236 +{ 1.237 + MOZ_CRASH("Caller is supposed to manually construct a request!"); 1.238 +} 1.239 + 1.240 +bool 1.241 +IndexedDBChild::DeallocPIndexedDBDeleteDatabaseRequestChild( 1.242 + PIndexedDBDeleteDatabaseRequestChild* aActor) 1.243 +{ 1.244 + delete aActor; 1.245 + return true; 1.246 +} 1.247 + 1.248 +/******************************************************************************* 1.249 + * IndexedDBDatabaseChild 1.250 + ******************************************************************************/ 1.251 + 1.252 +IndexedDBDatabaseChild::IndexedDBDatabaseChild(const nsString& aName, 1.253 + uint64_t aVersion) 1.254 +: mDatabase(nullptr), mName(aName), mVersion(aVersion) 1.255 +{ 1.256 + MOZ_COUNT_CTOR(IndexedDBDatabaseChild); 1.257 +} 1.258 + 1.259 +IndexedDBDatabaseChild::~IndexedDBDatabaseChild() 1.260 +{ 1.261 + MOZ_COUNT_DTOR(IndexedDBDatabaseChild); 1.262 + MOZ_ASSERT(!mDatabase); 1.263 + MOZ_ASSERT(!mStrongDatabase); 1.264 +} 1.265 + 1.266 +void 1.267 +IndexedDBDatabaseChild::SetRequest(IDBOpenDBRequest* aRequest) 1.268 +{ 1.269 + MOZ_ASSERT(aRequest); 1.270 + MOZ_ASSERT(!mRequest); 1.271 + 1.272 + mRequest = aRequest; 1.273 +} 1.274 + 1.275 +void 1.276 +IndexedDBDatabaseChild::Disconnect() 1.277 +{ 1.278 + const InfallibleTArray<PIndexedDBTransactionChild*>& transactions = 1.279 + ManagedPIndexedDBTransactionChild(); 1.280 + for (uint32_t i = 0; i < transactions.Length(); ++i) { 1.281 + static_cast<IndexedDBTransactionChild*>(transactions[i])->Disconnect(); 1.282 + } 1.283 +} 1.284 + 1.285 +bool 1.286 +IndexedDBDatabaseChild::EnsureDatabase( 1.287 + IDBOpenDBRequest* aRequest, 1.288 + const DatabaseInfoGuts& aDBInfo, 1.289 + const InfallibleTArray<ObjectStoreInfoGuts>& aOSInfo) 1.290 +{ 1.291 + nsCString databaseId; 1.292 + if (mDatabase) { 1.293 + databaseId = mDatabase->Id(); 1.294 + } 1.295 + else { 1.296 + QuotaManager::GetStorageId(aDBInfo.persistenceType, aDBInfo.origin, 1.297 + Client::IDB, aDBInfo.name, databaseId); 1.298 + } 1.299 + MOZ_ASSERT(!databaseId.IsEmpty()); 1.300 + 1.301 + nsRefPtr<DatabaseInfo> dbInfo; 1.302 + if (DatabaseInfo::Get(databaseId, getter_AddRefs(dbInfo))) { 1.303 + dbInfo->version = aDBInfo.version; 1.304 + } 1.305 + else { 1.306 + nsRefPtr<DatabaseInfo> newInfo = new DatabaseInfo(); 1.307 + 1.308 + *static_cast<DatabaseInfoGuts*>(newInfo.get()) = aDBInfo; 1.309 + newInfo->id = databaseId; 1.310 + 1.311 + if (!DatabaseInfo::Put(newInfo)) { 1.312 + NS_WARNING("Out of memory!"); 1.313 + return false; 1.314 + } 1.315 + 1.316 + newInfo.swap(dbInfo); 1.317 + 1.318 + // This is more or less copied from IDBFactory::SetDatabaseMetadata. 1.319 + for (uint32_t i = 0; i < aOSInfo.Length(); i++) { 1.320 + nsRefPtr<ObjectStoreInfo> newInfo = new ObjectStoreInfo(); 1.321 + *static_cast<ObjectStoreInfoGuts*>(newInfo.get()) = aOSInfo[i]; 1.322 + 1.323 + if (!dbInfo->PutObjectStore(newInfo)) { 1.324 + NS_WARNING("Out of memory!"); 1.325 + return false; 1.326 + } 1.327 + } 1.328 + } 1.329 + 1.330 + if (!mDatabase) { 1.331 + nsRefPtr<IDBDatabase> database = 1.332 + IDBDatabase::Create(aRequest, aRequest->Factory(), dbInfo.forget(), 1.333 + aDBInfo.origin, nullptr, nullptr); 1.334 + if (!database) { 1.335 + NS_WARNING("Failed to create database!"); 1.336 + return false; 1.337 + } 1.338 + 1.339 + database->SetActor(this); 1.340 + 1.341 + mDatabase = database; 1.342 + mStrongDatabase = database.forget(); 1.343 + } 1.344 + 1.345 + return true; 1.346 +} 1.347 + 1.348 +void 1.349 +IndexedDBDatabaseChild::ActorDestroy(ActorDestroyReason aWhy) 1.350 +{ 1.351 + if (mDatabase) { 1.352 + mDatabase->SetActor(static_cast<IndexedDBDatabaseChild*>(nullptr)); 1.353 +#ifdef DEBUG 1.354 + mDatabase = nullptr; 1.355 +#endif 1.356 + } 1.357 +} 1.358 + 1.359 +bool 1.360 +IndexedDBDatabaseChild::RecvSuccess( 1.361 + const DatabaseInfoGuts& aDBInfo, 1.362 + const InfallibleTArray<ObjectStoreInfoGuts>& aOSInfo) 1.363 +{ 1.364 +#ifdef DEBUG 1.365 + { 1.366 + IndexedDBChild* manager = static_cast<IndexedDBChild*>(Manager()); 1.367 + MOZ_ASSERT(aDBInfo.origin == manager->ASCIIOrigin()); 1.368 + MOZ_ASSERT(aDBInfo.name == mName); 1.369 + MOZ_ASSERT(!mVersion || aDBInfo.version == mVersion); 1.370 + } 1.371 +#endif 1.372 + 1.373 + MOZ_ASSERT(mRequest); 1.374 + 1.375 + nsRefPtr<IDBOpenDBRequest> request; 1.376 + mRequest.swap(request); 1.377 + 1.378 + nsRefPtr<AsyncConnectionHelper> openHelper; 1.379 + mOpenHelper.swap(openHelper); 1.380 + 1.381 + if (!EnsureDatabase(request, aDBInfo, aOSInfo)) { 1.382 + return false; 1.383 + } 1.384 + 1.385 + MOZ_ASSERT(mStrongDatabase); 1.386 + nsRefPtr<IDBDatabase> database; 1.387 + mStrongDatabase.swap(database); 1.388 + 1.389 + if (openHelper) { 1.390 + request->Reset(); 1.391 + } 1.392 + else { 1.393 + openHelper = new IPCOpenDatabaseHelper(mDatabase, request); 1.394 + } 1.395 + 1.396 + ImmediateRunEventTarget target; 1.397 + if (NS_FAILED(openHelper->Dispatch(&target))) { 1.398 + NS_WARNING("Dispatch of IPCOpenDatabaseHelper failed!"); 1.399 + return false; 1.400 + } 1.401 + 1.402 + return true; 1.403 +} 1.404 + 1.405 +bool 1.406 +IndexedDBDatabaseChild::RecvError(const nsresult& aRv) 1.407 +{ 1.408 + MOZ_ASSERT(mRequest); 1.409 + 1.410 + nsRefPtr<IDBOpenDBRequest> request; 1.411 + mRequest.swap(request); 1.412 + 1.413 + nsRefPtr<IDBDatabase> database; 1.414 + mStrongDatabase.swap(database); 1.415 + 1.416 + nsRefPtr<AsyncConnectionHelper> openHelper; 1.417 + mOpenHelper.swap(openHelper); 1.418 + 1.419 + if (openHelper) { 1.420 + request->Reset(); 1.421 + } 1.422 + else { 1.423 + openHelper = new IPCOpenDatabaseHelper(nullptr, request); 1.424 + } 1.425 + 1.426 + openHelper->SetError(aRv); 1.427 + 1.428 + ImmediateRunEventTarget target; 1.429 + if (NS_FAILED(openHelper->Dispatch(&target))) { 1.430 + NS_WARNING("Dispatch of IPCOpenDatabaseHelper failed!"); 1.431 + return false; 1.432 + } 1.433 + 1.434 + return true; 1.435 +} 1.436 + 1.437 +bool 1.438 +IndexedDBDatabaseChild::RecvBlocked(const uint64_t& aOldVersion) 1.439 +{ 1.440 + MOZ_ASSERT(mRequest); 1.441 + MOZ_ASSERT(!mDatabase); 1.442 + 1.443 + nsCOMPtr<nsIRunnable> runnable = 1.444 + IDBVersionChangeEvent::CreateBlockedRunnable(mRequest, aOldVersion, mVersion); 1.445 + 1.446 + ImmediateRunEventTarget target; 1.447 + if (NS_FAILED(target.Dispatch(runnable, NS_DISPATCH_NORMAL))) { 1.448 + NS_WARNING("Dispatch of blocked event failed!"); 1.449 + } 1.450 + 1.451 + return true; 1.452 +} 1.453 + 1.454 +bool 1.455 +IndexedDBDatabaseChild::RecvVersionChange(const uint64_t& aOldVersion, 1.456 + const uint64_t& aNewVersion) 1.457 +{ 1.458 + MOZ_ASSERT(mDatabase); 1.459 + 1.460 + nsCOMPtr<nsIRunnable> runnable = 1.461 + new VersionChangeRunnable(mDatabase, aOldVersion, aNewVersion); 1.462 + 1.463 + ImmediateRunEventTarget target; 1.464 + if (NS_FAILED(target.Dispatch(runnable, NS_DISPATCH_NORMAL))) { 1.465 + NS_WARNING("Dispatch of versionchange event failed!"); 1.466 + } 1.467 + 1.468 + return true; 1.469 +} 1.470 + 1.471 +bool 1.472 +IndexedDBDatabaseChild::RecvInvalidate() 1.473 +{ 1.474 + if (mDatabase) { 1.475 + mDatabase->Invalidate(); 1.476 + } 1.477 + return true; 1.478 +} 1.479 + 1.480 +bool 1.481 +IndexedDBDatabaseChild::RecvPIndexedDBTransactionConstructor( 1.482 + PIndexedDBTransactionChild* aActor, 1.483 + const TransactionParams& aParams) 1.484 +{ 1.485 + // This only happens when the parent has created a version-change transaction 1.486 + // for us. 1.487 + 1.488 + IndexedDBTransactionChild* actor = 1.489 + static_cast<IndexedDBTransactionChild*>(aActor); 1.490 + MOZ_ASSERT(!actor->GetTransaction()); 1.491 + 1.492 + MOZ_ASSERT(aParams.type() == 1.493 + TransactionParams::TVersionChangeTransactionParams); 1.494 + 1.495 + const VersionChangeTransactionParams& params = 1.496 + aParams.get_VersionChangeTransactionParams(); 1.497 + 1.498 + const DatabaseInfoGuts& dbInfo = params.dbInfo(); 1.499 + const InfallibleTArray<ObjectStoreInfoGuts>& osInfo = params.osInfo(); 1.500 + uint64_t oldVersion = params.oldVersion(); 1.501 + 1.502 + MOZ_ASSERT(dbInfo.origin == 1.503 + static_cast<IndexedDBChild*>(Manager())->ASCIIOrigin()); 1.504 + MOZ_ASSERT(dbInfo.name == mName); 1.505 + MOZ_ASSERT(!mVersion || dbInfo.version == mVersion); 1.506 + MOZ_ASSERT(!mVersion || oldVersion < mVersion); 1.507 + 1.508 + MOZ_ASSERT(mRequest); 1.509 + MOZ_ASSERT(!mDatabase); 1.510 + MOZ_ASSERT(!mOpenHelper); 1.511 + 1.512 + if (!EnsureDatabase(mRequest, dbInfo, osInfo)) { 1.513 + return false; 1.514 + } 1.515 + 1.516 + nsRefPtr<IPCOpenDatabaseHelper> helper = 1.517 + new IPCOpenDatabaseHelper(mDatabase, mRequest); 1.518 + 1.519 + Sequence<nsString> storesToOpen; 1.520 + nsRefPtr<IDBTransaction> transaction = 1.521 + IDBTransaction::CreateInternal(mDatabase, storesToOpen, 1.522 + IDBTransaction::VERSION_CHANGE, false, true); 1.523 + NS_ENSURE_TRUE(transaction, false); 1.524 + 1.525 + nsRefPtr<IPCSetVersionHelper> versionHelper = 1.526 + new IPCSetVersionHelper(transaction, mRequest, oldVersion, mVersion); 1.527 + 1.528 + mDatabase->EnterSetVersionTransaction(); 1.529 + mDatabase->mPreviousDatabaseInfo->version = oldVersion; 1.530 + 1.531 + actor->SetTransaction(transaction); 1.532 + 1.533 + ImmediateRunEventTarget target; 1.534 + if (NS_FAILED(versionHelper->Dispatch(&target))) { 1.535 + NS_WARNING("Dispatch of IPCSetVersionHelper failed!"); 1.536 + return false; 1.537 + } 1.538 + 1.539 + mOpenHelper = helper.forget(); 1.540 + return true; 1.541 +} 1.542 + 1.543 +PIndexedDBTransactionChild* 1.544 +IndexedDBDatabaseChild::AllocPIndexedDBTransactionChild( 1.545 + const TransactionParams& aParams) 1.546 +{ 1.547 + MOZ_ASSERT(aParams.type() == 1.548 + TransactionParams::TVersionChangeTransactionParams); 1.549 + return new IndexedDBTransactionChild(); 1.550 +} 1.551 + 1.552 +bool 1.553 +IndexedDBDatabaseChild::DeallocPIndexedDBTransactionChild( 1.554 + PIndexedDBTransactionChild* aActor) 1.555 +{ 1.556 + delete aActor; 1.557 + return true; 1.558 +} 1.559 + 1.560 +/******************************************************************************* 1.561 + * IndexedDBTransactionChild 1.562 + ******************************************************************************/ 1.563 + 1.564 +IndexedDBTransactionChild::IndexedDBTransactionChild() 1.565 +: mTransaction(nullptr) 1.566 +{ 1.567 + MOZ_COUNT_CTOR(IndexedDBTransactionChild); 1.568 +} 1.569 + 1.570 +IndexedDBTransactionChild::~IndexedDBTransactionChild() 1.571 +{ 1.572 + MOZ_COUNT_DTOR(IndexedDBTransactionChild); 1.573 + MOZ_ASSERT(!mTransaction); 1.574 + MOZ_ASSERT(!mStrongTransaction); 1.575 +} 1.576 + 1.577 +void 1.578 +IndexedDBTransactionChild::SetTransaction(IDBTransaction* aTransaction) 1.579 +{ 1.580 + MOZ_ASSERT(aTransaction); 1.581 + MOZ_ASSERT(!mTransaction); 1.582 + 1.583 + aTransaction->SetActor(this); 1.584 + 1.585 + mTransaction = aTransaction; 1.586 + mStrongTransaction = aTransaction; 1.587 +} 1.588 + 1.589 +void 1.590 +IndexedDBTransactionChild::Disconnect() 1.591 +{ 1.592 + const InfallibleTArray<PIndexedDBObjectStoreChild*>& objectStores = 1.593 + ManagedPIndexedDBObjectStoreChild(); 1.594 + for (uint32_t i = 0; i < objectStores.Length(); ++i) { 1.595 + static_cast<IndexedDBObjectStoreChild*>(objectStores[i])->Disconnect(); 1.596 + } 1.597 +} 1.598 + 1.599 +void 1.600 +IndexedDBTransactionChild::FireCompleteEvent(nsresult aRv) 1.601 +{ 1.602 + MOZ_ASSERT(mTransaction); 1.603 + MOZ_ASSERT(mStrongTransaction); 1.604 + 1.605 + nsRefPtr<IDBTransaction> transaction; 1.606 + mStrongTransaction.swap(transaction); 1.607 + 1.608 + if (transaction->GetMode() == IDBTransaction::VERSION_CHANGE) { 1.609 + transaction->Database()->ExitSetVersionTransaction(); 1.610 + } 1.611 + 1.612 + nsRefPtr<CommitHelper> helper = new CommitHelper(transaction, aRv); 1.613 + 1.614 + ImmediateRunEventTarget target; 1.615 + if (NS_FAILED(target.Dispatch(helper, NS_DISPATCH_NORMAL))) { 1.616 + NS_WARNING("Dispatch of CommitHelper failed!"); 1.617 + } 1.618 +} 1.619 + 1.620 +void 1.621 +IndexedDBTransactionChild::ActorDestroy(ActorDestroyReason aWhy) 1.622 +{ 1.623 + if (mStrongTransaction) { 1.624 + // We're being torn down before we received a complete event from the parent 1.625 + // so fake one here. 1.626 + FireCompleteEvent(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); 1.627 + 1.628 + MOZ_ASSERT(!mStrongTransaction); 1.629 + } 1.630 + 1.631 + if (mTransaction) { 1.632 + mTransaction->SetActor(static_cast<IndexedDBTransactionChild*>(nullptr)); 1.633 +#ifdef DEBUG 1.634 + mTransaction = nullptr; 1.635 +#endif 1.636 + } 1.637 +} 1.638 + 1.639 +bool 1.640 +IndexedDBTransactionChild::RecvComplete(const CompleteParams& aParams) 1.641 +{ 1.642 + MOZ_ASSERT(mTransaction); 1.643 + MOZ_ASSERT(mStrongTransaction); 1.644 + 1.645 + nsresult resultCode; 1.646 + 1.647 + switch (aParams.type()) { 1.648 + case CompleteParams::TCompleteResult: 1.649 + resultCode = NS_OK; 1.650 + break; 1.651 + case CompleteParams::TAbortResult: 1.652 + resultCode = aParams.get_AbortResult().errorCode(); 1.653 + if (NS_SUCCEEDED(resultCode)) { 1.654 + resultCode = NS_ERROR_DOM_INDEXEDDB_ABORT_ERR; 1.655 + } 1.656 + break; 1.657 + 1.658 + default: 1.659 + MOZ_CRASH("Unknown union type!"); 1.660 + } 1.661 + 1.662 + FireCompleteEvent(resultCode); 1.663 + return true; 1.664 +} 1.665 + 1.666 +PIndexedDBObjectStoreChild* 1.667 +IndexedDBTransactionChild::AllocPIndexedDBObjectStoreChild( 1.668 + const ObjectStoreConstructorParams& aParams) 1.669 +{ 1.670 + MOZ_CRASH("Caller is supposed to manually construct an object store!"); 1.671 +} 1.672 + 1.673 +bool 1.674 +IndexedDBTransactionChild::DeallocPIndexedDBObjectStoreChild( 1.675 + PIndexedDBObjectStoreChild* aActor) 1.676 +{ 1.677 + delete aActor; 1.678 + return true; 1.679 +} 1.680 + 1.681 +/******************************************************************************* 1.682 + * IndexedDBObjectStoreChild 1.683 + ******************************************************************************/ 1.684 + 1.685 +IndexedDBObjectStoreChild::IndexedDBObjectStoreChild( 1.686 + IDBObjectStore* aObjectStore) 1.687 +: mObjectStore(aObjectStore) 1.688 +{ 1.689 + MOZ_COUNT_CTOR(IndexedDBObjectStoreChild); 1.690 + aObjectStore->SetActor(this); 1.691 +} 1.692 + 1.693 +IndexedDBObjectStoreChild::~IndexedDBObjectStoreChild() 1.694 +{ 1.695 + MOZ_COUNT_DTOR(IndexedDBObjectStoreChild); 1.696 + MOZ_ASSERT(!mObjectStore); 1.697 +} 1.698 + 1.699 +void 1.700 +IndexedDBObjectStoreChild::Disconnect() 1.701 +{ 1.702 + const InfallibleTArray<PIndexedDBRequestChild*>& requests = 1.703 + ManagedPIndexedDBRequestChild(); 1.704 + for (uint32_t i = 0; i < requests.Length(); ++i) { 1.705 + static_cast<IndexedDBRequestChildBase*>(requests[i])->Disconnect(); 1.706 + } 1.707 + 1.708 + const InfallibleTArray<PIndexedDBIndexChild*>& indexes = 1.709 + ManagedPIndexedDBIndexChild(); 1.710 + for (uint32_t i = 0; i < indexes.Length(); ++i) { 1.711 + static_cast<IndexedDBIndexChild*>(indexes[i])->Disconnect(); 1.712 + } 1.713 + 1.714 + const InfallibleTArray<PIndexedDBCursorChild*>& cursors = 1.715 + ManagedPIndexedDBCursorChild(); 1.716 + for (uint32_t i = 0; i < cursors.Length(); ++i) { 1.717 + static_cast<IndexedDBCursorChild*>(cursors[i])->Disconnect(); 1.718 + } 1.719 +} 1.720 + 1.721 +void 1.722 +IndexedDBObjectStoreChild::ActorDestroy(ActorDestroyReason aWhy) 1.723 +{ 1.724 + if (mObjectStore) { 1.725 + mObjectStore->SetActor(static_cast<IndexedDBObjectStoreChild*>(nullptr)); 1.726 +#ifdef DEBUG 1.727 + mObjectStore = nullptr; 1.728 +#endif 1.729 + } 1.730 +} 1.731 + 1.732 +bool 1.733 +IndexedDBObjectStoreChild::RecvPIndexedDBCursorConstructor( 1.734 + PIndexedDBCursorChild* aActor, 1.735 + const ObjectStoreCursorConstructorParams& aParams) 1.736 +{ 1.737 + IndexedDBCursorChild* actor = static_cast<IndexedDBCursorChild*>(aActor); 1.738 + 1.739 + IndexedDBObjectStoreRequestChild* requestActor = 1.740 + static_cast<IndexedDBObjectStoreRequestChild*>(aParams.requestChild()); 1.741 + NS_ASSERTION(requestActor, "Must have an actor here!"); 1.742 + 1.743 + nsRefPtr<IDBRequest> request = requestActor->GetRequest(); 1.744 + NS_ASSERTION(request, "Must have a request here!"); 1.745 + 1.746 + size_t direction = static_cast<size_t>(aParams.direction()); 1.747 + 1.748 + nsRefPtr<IDBCursor> cursor; 1.749 + nsresult rv; 1.750 + 1.751 + typedef ipc::OptionalStructuredCloneReadInfo CursorUnionType; 1.752 + 1.753 + switch (aParams.optionalCloneInfo().type()) { 1.754 + case CursorUnionType::TSerializedStructuredCloneReadInfo: { 1.755 + nsTArray<StructuredCloneFile> blobs; 1.756 + IDBObjectStore::ConvertActorsToBlobs(aParams.blobsChild(), blobs); 1.757 + 1.758 + const SerializedStructuredCloneReadInfo& cloneInfo = 1.759 + aParams.optionalCloneInfo().get_SerializedStructuredCloneReadInfo(); 1.760 + 1.761 + rv = mObjectStore->OpenCursorFromChildProcess(request, direction, 1.762 + aParams.key(), cloneInfo, 1.763 + blobs, 1.764 + getter_AddRefs(cursor)); 1.765 + NS_ENSURE_SUCCESS(rv, false); 1.766 + 1.767 + MOZ_ASSERT(blobs.IsEmpty(), "Should have swapped blob elements!"); 1.768 + } break; 1.769 + 1.770 + case CursorUnionType::Tvoid_t: 1.771 + MOZ_ASSERT(aParams.blobsChild().IsEmpty()); 1.772 + 1.773 + rv = mObjectStore->OpenCursorFromChildProcess(request, direction, 1.774 + aParams.key(), 1.775 + getter_AddRefs(cursor)); 1.776 + NS_ENSURE_SUCCESS(rv, false); 1.777 + break; 1.778 + 1.779 + default: 1.780 + MOZ_CRASH("Unknown union type!"); 1.781 + } 1.782 + 1.783 + actor->SetCursor(cursor); 1.784 + return true; 1.785 +} 1.786 + 1.787 +PIndexedDBRequestChild* 1.788 +IndexedDBObjectStoreChild::AllocPIndexedDBRequestChild( 1.789 + const ObjectStoreRequestParams& aParams) 1.790 +{ 1.791 + MOZ_CRASH("Caller is supposed to manually construct a request!"); 1.792 +} 1.793 + 1.794 +bool 1.795 +IndexedDBObjectStoreChild::DeallocPIndexedDBRequestChild( 1.796 + PIndexedDBRequestChild* aActor) 1.797 +{ 1.798 + delete aActor; 1.799 + return false; 1.800 +} 1.801 + 1.802 +PIndexedDBIndexChild* 1.803 +IndexedDBObjectStoreChild::AllocPIndexedDBIndexChild( 1.804 + const IndexConstructorParams& aParams) 1.805 +{ 1.806 + MOZ_CRASH("Caller is supposed to manually construct an index!"); 1.807 +} 1.808 + 1.809 +bool 1.810 +IndexedDBObjectStoreChild::DeallocPIndexedDBIndexChild(PIndexedDBIndexChild* aActor) 1.811 +{ 1.812 + delete aActor; 1.813 + return true; 1.814 +} 1.815 + 1.816 +PIndexedDBCursorChild* 1.817 +IndexedDBObjectStoreChild::AllocPIndexedDBCursorChild( 1.818 + const ObjectStoreCursorConstructorParams& aParams) 1.819 +{ 1.820 + return new IndexedDBCursorChild(); 1.821 +} 1.822 + 1.823 +bool 1.824 +IndexedDBObjectStoreChild::DeallocPIndexedDBCursorChild( 1.825 + PIndexedDBCursorChild* aActor) 1.826 +{ 1.827 + delete aActor; 1.828 + return true; 1.829 +} 1.830 + 1.831 +/******************************************************************************* 1.832 + * IndexedDBIndexChild 1.833 + ******************************************************************************/ 1.834 + 1.835 +IndexedDBIndexChild::IndexedDBIndexChild(IDBIndex* aIndex) 1.836 +: mIndex(aIndex) 1.837 +{ 1.838 + MOZ_COUNT_CTOR(IndexedDBIndexChild); 1.839 + aIndex->SetActor(this); 1.840 +} 1.841 + 1.842 +IndexedDBIndexChild::~IndexedDBIndexChild() 1.843 +{ 1.844 + MOZ_COUNT_DTOR(IndexedDBIndexChild); 1.845 + MOZ_ASSERT(!mIndex); 1.846 +} 1.847 + 1.848 +void 1.849 +IndexedDBIndexChild::Disconnect() 1.850 +{ 1.851 + const InfallibleTArray<PIndexedDBRequestChild*>& requests = 1.852 + ManagedPIndexedDBRequestChild(); 1.853 + for (uint32_t i = 0; i < requests.Length(); ++i) { 1.854 + static_cast<IndexedDBRequestChildBase*>(requests[i])->Disconnect(); 1.855 + } 1.856 + 1.857 + const InfallibleTArray<PIndexedDBCursorChild*>& cursors = 1.858 + ManagedPIndexedDBCursorChild(); 1.859 + for (uint32_t i = 0; i < cursors.Length(); ++i) { 1.860 + static_cast<IndexedDBCursorChild*>(cursors[i])->Disconnect(); 1.861 + } 1.862 +} 1.863 + 1.864 +void 1.865 +IndexedDBIndexChild::ActorDestroy(ActorDestroyReason aWhy) 1.866 +{ 1.867 + if (mIndex) { 1.868 + mIndex->SetActor(static_cast<IndexedDBIndexChild*>(nullptr)); 1.869 +#ifdef DEBUG 1.870 + mIndex = nullptr; 1.871 +#endif 1.872 + } 1.873 +} 1.874 + 1.875 +bool 1.876 +IndexedDBIndexChild::RecvPIndexedDBCursorConstructor( 1.877 + PIndexedDBCursorChild* aActor, 1.878 + const IndexCursorConstructorParams& aParams) 1.879 +{ 1.880 + IndexedDBCursorChild* actor = static_cast<IndexedDBCursorChild*>(aActor); 1.881 + 1.882 + IndexedDBObjectStoreRequestChild* requestActor = 1.883 + static_cast<IndexedDBObjectStoreRequestChild*>(aParams.requestChild()); 1.884 + NS_ASSERTION(requestActor, "Must have an actor here!"); 1.885 + 1.886 + nsRefPtr<IDBRequest> request = requestActor->GetRequest(); 1.887 + NS_ASSERTION(request, "Must have a request here!"); 1.888 + 1.889 + size_t direction = static_cast<size_t>(aParams.direction()); 1.890 + 1.891 + nsRefPtr<IDBCursor> cursor; 1.892 + nsresult rv; 1.893 + 1.894 + typedef ipc::OptionalStructuredCloneReadInfo CursorUnionType; 1.895 + 1.896 + switch (aParams.optionalCloneInfo().type()) { 1.897 + case CursorUnionType::TSerializedStructuredCloneReadInfo: { 1.898 + nsTArray<StructuredCloneFile> blobs; 1.899 + IDBObjectStore::ConvertActorsToBlobs(aParams.blobsChild(), blobs); 1.900 + 1.901 + const SerializedStructuredCloneReadInfo& cloneInfo = 1.902 + aParams.optionalCloneInfo().get_SerializedStructuredCloneReadInfo(); 1.903 + 1.904 + rv = mIndex->OpenCursorFromChildProcess(request, direction, aParams.key(), 1.905 + aParams.objectKey(), cloneInfo, 1.906 + blobs, 1.907 + getter_AddRefs(cursor)); 1.908 + NS_ENSURE_SUCCESS(rv, false); 1.909 + } break; 1.910 + 1.911 + case CursorUnionType::Tvoid_t: 1.912 + MOZ_ASSERT(aParams.blobsChild().IsEmpty()); 1.913 + 1.914 + rv = mIndex->OpenCursorFromChildProcess(request, direction, aParams.key(), 1.915 + aParams.objectKey(), 1.916 + getter_AddRefs(cursor)); 1.917 + NS_ENSURE_SUCCESS(rv, false); 1.918 + break; 1.919 + 1.920 + default: 1.921 + MOZ_CRASH("Unknown union type!"); 1.922 + } 1.923 + 1.924 + actor->SetCursor(cursor); 1.925 + return true; 1.926 +} 1.927 + 1.928 +PIndexedDBRequestChild* 1.929 +IndexedDBIndexChild::AllocPIndexedDBRequestChild(const IndexRequestParams& aParams) 1.930 +{ 1.931 + MOZ_CRASH("Caller is supposed to manually construct a request!"); 1.932 +} 1.933 + 1.934 +bool 1.935 +IndexedDBIndexChild::DeallocPIndexedDBRequestChild(PIndexedDBRequestChild* aActor) 1.936 +{ 1.937 + delete aActor; 1.938 + return true; 1.939 +} 1.940 + 1.941 +PIndexedDBCursorChild* 1.942 +IndexedDBIndexChild::AllocPIndexedDBCursorChild( 1.943 + const IndexCursorConstructorParams& aParams) 1.944 +{ 1.945 + return new IndexedDBCursorChild(); 1.946 +} 1.947 + 1.948 +bool 1.949 +IndexedDBIndexChild::DeallocPIndexedDBCursorChild(PIndexedDBCursorChild* aActor) 1.950 +{ 1.951 + delete aActor; 1.952 + return true; 1.953 +} 1.954 + 1.955 +/******************************************************************************* 1.956 + * IndexedDBCursorChild 1.957 + ******************************************************************************/ 1.958 + 1.959 +IndexedDBCursorChild::IndexedDBCursorChild() 1.960 +: mCursor(nullptr) 1.961 +{ 1.962 + MOZ_COUNT_CTOR(IndexedDBCursorChild); 1.963 +} 1.964 + 1.965 +IndexedDBCursorChild::~IndexedDBCursorChild() 1.966 +{ 1.967 + MOZ_COUNT_DTOR(IndexedDBCursorChild); 1.968 + MOZ_ASSERT(!mCursor); 1.969 + MOZ_ASSERT(!mStrongCursor); 1.970 +} 1.971 + 1.972 +void 1.973 +IndexedDBCursorChild::SetCursor(IDBCursor* aCursor) 1.974 +{ 1.975 + MOZ_ASSERT(aCursor); 1.976 + MOZ_ASSERT(!mCursor); 1.977 + 1.978 + aCursor->SetActor(this); 1.979 + 1.980 + mCursor = aCursor; 1.981 + mStrongCursor = aCursor; 1.982 +} 1.983 + 1.984 +void 1.985 +IndexedDBCursorChild::Disconnect() 1.986 +{ 1.987 + const InfallibleTArray<PIndexedDBRequestChild*>& requests = 1.988 + ManagedPIndexedDBRequestChild(); 1.989 + for (uint32_t i = 0; i < requests.Length(); ++i) { 1.990 + static_cast<IndexedDBRequestChildBase*>(requests[i])->Disconnect(); 1.991 + } 1.992 +} 1.993 + 1.994 +void 1.995 +IndexedDBCursorChild::ActorDestroy(ActorDestroyReason aWhy) 1.996 +{ 1.997 + if (mCursor) { 1.998 + mCursor->SetActor(static_cast<IndexedDBCursorChild*>(nullptr)); 1.999 +#ifdef DEBUG 1.1000 + mCursor = nullptr; 1.1001 +#endif 1.1002 + } 1.1003 +} 1.1004 + 1.1005 +PIndexedDBRequestChild* 1.1006 +IndexedDBCursorChild::AllocPIndexedDBRequestChild(const CursorRequestParams& aParams) 1.1007 +{ 1.1008 + MOZ_CRASH("Caller is supposed to manually construct a request!"); 1.1009 +} 1.1010 + 1.1011 +bool 1.1012 +IndexedDBCursorChild::DeallocPIndexedDBRequestChild(PIndexedDBRequestChild* aActor) 1.1013 +{ 1.1014 + delete aActor; 1.1015 + return true; 1.1016 +} 1.1017 + 1.1018 +/******************************************************************************* 1.1019 + * IndexedDBRequestChildBase 1.1020 + ******************************************************************************/ 1.1021 + 1.1022 +IndexedDBRequestChildBase::IndexedDBRequestChildBase( 1.1023 + AsyncConnectionHelper* aHelper) 1.1024 +: mHelper(aHelper) 1.1025 +{ 1.1026 + MOZ_COUNT_CTOR(IndexedDBRequestChildBase); 1.1027 +} 1.1028 + 1.1029 +IndexedDBRequestChildBase::~IndexedDBRequestChildBase() 1.1030 +{ 1.1031 + MOZ_COUNT_DTOR(IndexedDBRequestChildBase); 1.1032 +} 1.1033 + 1.1034 +IDBRequest* 1.1035 +IndexedDBRequestChildBase::GetRequest() const 1.1036 +{ 1.1037 + return mHelper ? mHelper->GetRequest() : nullptr; 1.1038 +} 1.1039 + 1.1040 +void 1.1041 +IndexedDBRequestChildBase::Disconnect() 1.1042 +{ 1.1043 + if (mHelper) { 1.1044 + IDBRequest* request = mHelper->GetRequest(); 1.1045 + 1.1046 + if (request->IsPending()) { 1.1047 + request->SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); 1.1048 + 1.1049 + IDBTransaction* transaction = mHelper->GetTransaction(); 1.1050 + if (transaction) { 1.1051 + transaction->OnRequestDisconnected(); 1.1052 + } 1.1053 + } 1.1054 + } 1.1055 +} 1.1056 + 1.1057 +bool 1.1058 +IndexedDBRequestChildBase::Recv__delete__(const ResponseValue& aResponse) 1.1059 +{ 1.1060 + MOZ_CRASH("This should be overridden!"); 1.1061 +} 1.1062 + 1.1063 +/******************************************************************************* 1.1064 + * IndexedDBObjectStoreRequestChild 1.1065 + ******************************************************************************/ 1.1066 + 1.1067 +IndexedDBObjectStoreRequestChild::IndexedDBObjectStoreRequestChild( 1.1068 + AsyncConnectionHelper* aHelper, 1.1069 + IDBObjectStore* aObjectStore, 1.1070 + RequestType aRequestType) 1.1071 +: IndexedDBRequestChildBase(aHelper), mObjectStore(aObjectStore), 1.1072 + mRequestType(aRequestType) 1.1073 +{ 1.1074 + MOZ_COUNT_CTOR(IndexedDBObjectStoreRequestChild); 1.1075 + MOZ_ASSERT(aHelper); 1.1076 + MOZ_ASSERT(aObjectStore); 1.1077 + MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && 1.1078 + aRequestType <= ParamsUnionType::T__Last); 1.1079 +} 1.1080 + 1.1081 +IndexedDBObjectStoreRequestChild::~IndexedDBObjectStoreRequestChild() 1.1082 +{ 1.1083 + MOZ_COUNT_DTOR(IndexedDBObjectStoreRequestChild); 1.1084 +} 1.1085 + 1.1086 +bool 1.1087 +IndexedDBObjectStoreRequestChild::Recv__delete__(const ResponseValue& aResponse) 1.1088 +{ 1.1089 + switch (aResponse.type()) { 1.1090 + case ResponseValue::Tnsresult: 1.1091 + break; 1.1092 + case ResponseValue::TGetResponse: 1.1093 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams); 1.1094 + break; 1.1095 + case ResponseValue::TGetAllResponse: 1.1096 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams); 1.1097 + break; 1.1098 + case ResponseValue::TGetAllKeysResponse: 1.1099 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams); 1.1100 + break; 1.1101 + case ResponseValue::TAddResponse: 1.1102 + MOZ_ASSERT(mRequestType == ParamsUnionType::TAddParams); 1.1103 + break; 1.1104 + case ResponseValue::TPutResponse: 1.1105 + MOZ_ASSERT(mRequestType == ParamsUnionType::TPutParams); 1.1106 + break; 1.1107 + case ResponseValue::TDeleteResponse: 1.1108 + MOZ_ASSERT(mRequestType == ParamsUnionType::TDeleteParams); 1.1109 + break; 1.1110 + case ResponseValue::TClearResponse: 1.1111 + MOZ_ASSERT(mRequestType == ParamsUnionType::TClearParams); 1.1112 + break; 1.1113 + case ResponseValue::TCountResponse: 1.1114 + MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams); 1.1115 + break; 1.1116 + case ResponseValue::TOpenCursorResponse: 1.1117 + MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams || 1.1118 + mRequestType == ParamsUnionType::TOpenKeyCursorParams); 1.1119 + break; 1.1120 + 1.1121 + default: 1.1122 + MOZ_CRASH("Received invalid response parameters!"); 1.1123 + } 1.1124 + 1.1125 + nsresult rv = mHelper->OnParentProcessRequestComplete(aResponse); 1.1126 + NS_ENSURE_SUCCESS(rv, false); 1.1127 + 1.1128 + return true; 1.1129 +} 1.1130 + 1.1131 +/******************************************************************************* 1.1132 + * IndexedDBIndexRequestChild 1.1133 + ******************************************************************************/ 1.1134 + 1.1135 +IndexedDBIndexRequestChild::IndexedDBIndexRequestChild( 1.1136 + AsyncConnectionHelper* aHelper, 1.1137 + IDBIndex* aIndex, 1.1138 + RequestType aRequestType) 1.1139 +: IndexedDBRequestChildBase(aHelper), mIndex(aIndex), mRequestType(aRequestType) 1.1140 +{ 1.1141 + MOZ_COUNT_CTOR(IndexedDBIndexRequestChild); 1.1142 + MOZ_ASSERT(aHelper); 1.1143 + MOZ_ASSERT(aIndex); 1.1144 + MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && 1.1145 + aRequestType <= ParamsUnionType::T__Last); 1.1146 +} 1.1147 + 1.1148 +IndexedDBIndexRequestChild::~IndexedDBIndexRequestChild() 1.1149 +{ 1.1150 + MOZ_COUNT_DTOR(IndexedDBIndexRequestChild); 1.1151 +} 1.1152 + 1.1153 +bool 1.1154 +IndexedDBIndexRequestChild::Recv__delete__(const ResponseValue& aResponse) 1.1155 +{ 1.1156 + switch (aResponse.type()) { 1.1157 + case ResponseValue::Tnsresult: 1.1158 + break; 1.1159 + case ResponseValue::TGetResponse: 1.1160 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams); 1.1161 + break; 1.1162 + case ResponseValue::TGetKeyResponse: 1.1163 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetKeyParams); 1.1164 + break; 1.1165 + case ResponseValue::TGetAllResponse: 1.1166 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams); 1.1167 + break; 1.1168 + case ResponseValue::TGetAllKeysResponse: 1.1169 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams); 1.1170 + break; 1.1171 + case ResponseValue::TCountResponse: 1.1172 + MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams); 1.1173 + break; 1.1174 + case ResponseValue::TOpenCursorResponse: 1.1175 + MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams || 1.1176 + mRequestType == ParamsUnionType::TOpenKeyCursorParams); 1.1177 + break; 1.1178 + 1.1179 + default: 1.1180 + MOZ_CRASH("Received invalid response parameters!"); 1.1181 + } 1.1182 + 1.1183 + nsresult rv = mHelper->OnParentProcessRequestComplete(aResponse); 1.1184 + NS_ENSURE_SUCCESS(rv, false); 1.1185 + 1.1186 + return true; 1.1187 +} 1.1188 + 1.1189 +/******************************************************************************* 1.1190 + * IndexedDBCursorRequestChild 1.1191 + ******************************************************************************/ 1.1192 + 1.1193 +IndexedDBCursorRequestChild::IndexedDBCursorRequestChild( 1.1194 + AsyncConnectionHelper* aHelper, 1.1195 + IDBCursor* aCursor, 1.1196 + RequestType aRequestType) 1.1197 +: IndexedDBRequestChildBase(aHelper), mCursor(aCursor), 1.1198 + mRequestType(aRequestType) 1.1199 +{ 1.1200 + MOZ_COUNT_CTOR(IndexedDBCursorRequestChild); 1.1201 + MOZ_ASSERT(aHelper); 1.1202 + MOZ_ASSERT(aCursor); 1.1203 + MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && 1.1204 + aRequestType <= ParamsUnionType::T__Last); 1.1205 +} 1.1206 + 1.1207 +IndexedDBCursorRequestChild::~IndexedDBCursorRequestChild() 1.1208 +{ 1.1209 + MOZ_COUNT_DTOR(IndexedDBCursorRequestChild); 1.1210 +} 1.1211 + 1.1212 +bool 1.1213 +IndexedDBCursorRequestChild::Recv__delete__(const ResponseValue& aResponse) 1.1214 +{ 1.1215 + switch (aResponse.type()) { 1.1216 + case ResponseValue::Tnsresult: 1.1217 + break; 1.1218 + case ResponseValue::TContinueResponse: 1.1219 + MOZ_ASSERT(mRequestType == ParamsUnionType::TContinueParams); 1.1220 + break; 1.1221 + 1.1222 + default: 1.1223 + MOZ_CRASH("Received invalid response parameters!"); 1.1224 + } 1.1225 + 1.1226 + nsresult rv = mHelper->OnParentProcessRequestComplete(aResponse); 1.1227 + NS_ENSURE_SUCCESS(rv, false); 1.1228 + 1.1229 + return true; 1.1230 +} 1.1231 + 1.1232 +/******************************************************************************* 1.1233 + * IndexedDBDeleteDatabaseRequestChild 1.1234 + ******************************************************************************/ 1.1235 + 1.1236 +IndexedDBDeleteDatabaseRequestChild::IndexedDBDeleteDatabaseRequestChild( 1.1237 + IDBFactory* aFactory, 1.1238 + IDBOpenDBRequest* aOpenRequest, 1.1239 + const nsACString& aDatabaseId) 1.1240 +: mFactory(aFactory), mOpenRequest(aOpenRequest), mDatabaseId(aDatabaseId) 1.1241 +{ 1.1242 + MOZ_COUNT_CTOR(IndexedDBDeleteDatabaseRequestChild); 1.1243 + MOZ_ASSERT(aFactory); 1.1244 + MOZ_ASSERT(aOpenRequest); 1.1245 + MOZ_ASSERT(!aDatabaseId.IsEmpty()); 1.1246 +} 1.1247 + 1.1248 +IndexedDBDeleteDatabaseRequestChild::~IndexedDBDeleteDatabaseRequestChild() 1.1249 +{ 1.1250 + MOZ_COUNT_DTOR(IndexedDBDeleteDatabaseRequestChild); 1.1251 +} 1.1252 + 1.1253 +bool 1.1254 +IndexedDBDeleteDatabaseRequestChild::Recv__delete__(const nsresult& aRv) 1.1255 +{ 1.1256 + nsRefPtr<IPCDeleteDatabaseHelper> helper = 1.1257 + new IPCDeleteDatabaseHelper(mOpenRequest); 1.1258 + 1.1259 + if (NS_SUCCEEDED(aRv)) { 1.1260 + DatabaseInfo::Remove(mDatabaseId); 1.1261 + } 1.1262 + else { 1.1263 + helper->SetError(aRv); 1.1264 + } 1.1265 + 1.1266 + ImmediateRunEventTarget target; 1.1267 + if (NS_FAILED(helper->Dispatch(&target))) { 1.1268 + NS_WARNING("Dispatch of IPCSetVersionHelper failed!"); 1.1269 + return false; 1.1270 + } 1.1271 + 1.1272 + return true; 1.1273 +} 1.1274 + 1.1275 +bool 1.1276 +IndexedDBDeleteDatabaseRequestChild::RecvBlocked( 1.1277 + const uint64_t& aCurrentVersion) 1.1278 +{ 1.1279 + MOZ_ASSERT(mOpenRequest); 1.1280 + 1.1281 + nsCOMPtr<nsIRunnable> runnable = 1.1282 + IDBVersionChangeEvent::CreateBlockedRunnable(mOpenRequest, 1.1283 + aCurrentVersion, 0); 1.1284 + 1.1285 + ImmediateRunEventTarget target; 1.1286 + if (NS_FAILED(target.Dispatch(runnable, NS_DISPATCH_NORMAL))) { 1.1287 + NS_WARNING("Dispatch of blocked event failed!"); 1.1288 + } 1.1289 + 1.1290 + return true; 1.1291 +} 1.1292 + 1.1293 +/******************************************************************************* 1.1294 + * Helpers 1.1295 + ******************************************************************************/ 1.1296 + 1.1297 +nsresult 1.1298 +IPCOpenDatabaseHelper::UnpackResponseFromParentProcess( 1.1299 + const ResponseValue& aResponseValue) 1.1300 +{ 1.1301 + NS_NOTREACHED("Should never get here!"); 1.1302 + return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; 1.1303 +} 1.1304 + 1.1305 +AsyncConnectionHelper::ChildProcessSendResult 1.1306 +IPCOpenDatabaseHelper::SendResponseToChildProcess(nsresult aResultCode) 1.1307 +{ 1.1308 + MOZ_CRASH("Don't call me!"); 1.1309 +} 1.1310 + 1.1311 +nsresult 1.1312 +IPCOpenDatabaseHelper::DoDatabaseWork(mozIStorageConnection* aConnection) 1.1313 +{ 1.1314 + MOZ_CRASH("Don't call me!"); 1.1315 +} 1.1316 + 1.1317 +nsresult 1.1318 +IPCOpenDatabaseHelper::GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) 1.1319 +{ 1.1320 + return WrapNative(aCx, NS_ISUPPORTS_CAST(EventTarget*, mDatabase), 1.1321 + aVal); 1.1322 +} 1.1323 + 1.1324 +nsresult 1.1325 +IPCSetVersionHelper::UnpackResponseFromParentProcess( 1.1326 + const ResponseValue& aResponseValue) 1.1327 +{ 1.1328 + NS_NOTREACHED("Should never get here!"); 1.1329 + return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; 1.1330 +} 1.1331 + 1.1332 +AsyncConnectionHelper::ChildProcessSendResult 1.1333 +IPCSetVersionHelper::SendResponseToChildProcess(nsresult aResultCode) 1.1334 +{ 1.1335 + MOZ_CRASH("Don't call me!"); 1.1336 +} 1.1337 + 1.1338 +nsresult 1.1339 +IPCSetVersionHelper::DoDatabaseWork(mozIStorageConnection* aConnection) 1.1340 +{ 1.1341 + MOZ_CRASH("Don't call me!"); 1.1342 +} 1.1343 + 1.1344 +already_AddRefed<nsIDOMEvent> 1.1345 +IPCSetVersionHelper::CreateSuccessEvent(mozilla::dom::EventTarget* aOwner) 1.1346 +{ 1.1347 + return IDBVersionChangeEvent::CreateUpgradeNeeded(aOwner, 1.1348 + mOldVersion, 1.1349 + mRequestedVersion); 1.1350 +} 1.1351 + 1.1352 +nsresult 1.1353 +IPCSetVersionHelper::GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) 1.1354 +{ 1.1355 + mOpenRequest->SetTransaction(mTransaction); 1.1356 + 1.1357 + return WrapNative(aCx, NS_ISUPPORTS_CAST(EventTarget*, mDatabase), 1.1358 + aVal); 1.1359 +} 1.1360 + 1.1361 +nsresult 1.1362 +IPCDeleteDatabaseHelper::UnpackResponseFromParentProcess( 1.1363 + const ResponseValue& aResponseValue) 1.1364 +{ 1.1365 + MOZ_CRASH("Don't call me!"); 1.1366 +} 1.1367 + 1.1368 +AsyncConnectionHelper::ChildProcessSendResult 1.1369 +IPCDeleteDatabaseHelper::SendResponseToChildProcess(nsresult aResultCode) 1.1370 +{ 1.1371 + MOZ_CRASH("Don't call me!"); 1.1372 +} 1.1373 + 1.1374 +nsresult 1.1375 +IPCDeleteDatabaseHelper::GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) 1.1376 +{ 1.1377 + aVal.setUndefined(); 1.1378 + return NS_OK; 1.1379 +} 1.1380 + 1.1381 +nsresult 1.1382 +IPCDeleteDatabaseHelper::DoDatabaseWork(mozIStorageConnection* aConnection) 1.1383 +{ 1.1384 + MOZ_CRASH("Don't call me!"); 1.1385 +}