1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/ipc/IndexedDBParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,2258 @@ 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 + 1.9 +#include "IndexedDBParent.h" 1.10 + 1.11 +#include "nsIDOMEvent.h" 1.12 +#include "nsIDOMFile.h" 1.13 +#include "nsIXPConnect.h" 1.14 + 1.15 +#include "mozilla/AppProcessChecker.h" 1.16 +#include "mozilla/Assertions.h" 1.17 +#include "mozilla/Attributes.h" 1.18 +#include "mozilla/dom/ContentParent.h" 1.19 +#include "mozilla/dom/IDBDatabaseBinding.h" 1.20 +#include "mozilla/dom/ipc/Blob.h" 1.21 +#include "mozilla/dom/TabParent.h" 1.22 +#include "mozilla/unused.h" 1.23 +#include "nsCxPusher.h" 1.24 + 1.25 +#include "AsyncConnectionHelper.h" 1.26 +#include "DatabaseInfo.h" 1.27 +#include "IDBDatabase.h" 1.28 +#include "IDBEvents.h" 1.29 +#include "IDBFactory.h" 1.30 +#include "IDBIndex.h" 1.31 +#include "IDBKeyRange.h" 1.32 +#include "IDBObjectStore.h" 1.33 +#include "IDBTransaction.h" 1.34 + 1.35 +#define CHROME_ORIGIN "chrome" 1.36 +#define PERMISSION_PREFIX "indexedDB-chrome-" 1.37 +#define PERMISSION_SUFFIX_READ "-read" 1.38 +#define PERMISSION_SUFFIX_WRITE "-write" 1.39 + 1.40 +USING_INDEXEDDB_NAMESPACE 1.41 + 1.42 +using namespace mozilla; 1.43 +using namespace mozilla::dom; 1.44 + 1.45 +/******************************************************************************* 1.46 + * AutoSetCurrentTransaction 1.47 + ******************************************************************************/ 1.48 + 1.49 +AutoSetCurrentTransaction::AutoSetCurrentTransaction( 1.50 + IDBTransaction* aTransaction) 1.51 +{ 1.52 + MOZ_ASSERT(aTransaction); 1.53 + AsyncConnectionHelper::SetCurrentTransaction(aTransaction); 1.54 +} 1.55 + 1.56 +AutoSetCurrentTransaction::~AutoSetCurrentTransaction() 1.57 +{ 1.58 + AsyncConnectionHelper::SetCurrentTransaction(nullptr); 1.59 +} 1.60 + 1.61 +/******************************************************************************* 1.62 + * IndexedDBParent 1.63 + ******************************************************************************/ 1.64 + 1.65 +IndexedDBParent::IndexedDBParent(ContentParent* aContentParent) 1.66 +: mManagerContent(aContentParent), mManagerTab(nullptr), mDisconnected(false) 1.67 +{ 1.68 + MOZ_COUNT_CTOR(IndexedDBParent); 1.69 + MOZ_ASSERT(aContentParent); 1.70 +} 1.71 + 1.72 +IndexedDBParent::IndexedDBParent(TabParent* aTabParent) 1.73 +: mManagerContent(nullptr), mManagerTab(aTabParent), mDisconnected(false) 1.74 +{ 1.75 + MOZ_COUNT_CTOR(IndexedDBParent); 1.76 + MOZ_ASSERT(aTabParent); 1.77 +} 1.78 + 1.79 +IndexedDBParent::~IndexedDBParent() 1.80 +{ 1.81 + MOZ_COUNT_DTOR(IndexedDBParent); 1.82 +} 1.83 + 1.84 +void 1.85 +IndexedDBParent::Disconnect() 1.86 +{ 1.87 + if (mDisconnected) { 1.88 + return; 1.89 + } 1.90 + 1.91 + mDisconnected = true; 1.92 + 1.93 + const InfallibleTArray<PIndexedDBDatabaseParent*>& databases = 1.94 + ManagedPIndexedDBDatabaseParent(); 1.95 + for (uint32_t i = 0; i < databases.Length(); ++i) { 1.96 + static_cast<IndexedDBDatabaseParent*>(databases[i])->Disconnect(); 1.97 + } 1.98 +} 1.99 + 1.100 +bool 1.101 +IndexedDBParent::CheckReadPermission(const nsAString& aDatabaseName) 1.102 +{ 1.103 + NS_NAMED_LITERAL_CSTRING(permission, PERMISSION_SUFFIX_READ); 1.104 + return CheckPermissionInternal(aDatabaseName, permission); 1.105 +} 1.106 + 1.107 +bool 1.108 +IndexedDBParent::CheckWritePermission(const nsAString& aDatabaseName) 1.109 +{ 1.110 + // Write permission assumes read permission is granted as well. 1.111 + MOZ_ASSERT(CheckReadPermission(aDatabaseName)); 1.112 + 1.113 + NS_NAMED_LITERAL_CSTRING(permission, PERMISSION_SUFFIX_WRITE); 1.114 + return CheckPermissionInternal(aDatabaseName, permission); 1.115 +} 1.116 + 1.117 +mozilla::ipc::IProtocol* 1.118 +IndexedDBParent::CloneProtocol(Channel* aChannel, 1.119 + mozilla::ipc::ProtocolCloneContext* aCtx) 1.120 +{ 1.121 + MOZ_ASSERT(mManagerContent != nullptr); 1.122 + MOZ_ASSERT(mManagerTab == nullptr); 1.123 + MOZ_ASSERT(!mDisconnected); 1.124 + MOZ_ASSERT(IndexedDatabaseManager::Get()); 1.125 + MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess()); 1.126 + 1.127 + ContentParent* contentParent = aCtx->GetContentParent(); 1.128 + nsAutoPtr<PIndexedDBParent> actor(contentParent->AllocPIndexedDBParent()); 1.129 + if (!actor || !contentParent->RecvPIndexedDBConstructor(actor)) { 1.130 + return nullptr; 1.131 + } 1.132 + return actor.forget(); 1.133 +} 1.134 + 1.135 +bool 1.136 +IndexedDBParent::CheckPermissionInternal(const nsAString& aDatabaseName, 1.137 + const nsACString& aPermission) 1.138 +{ 1.139 + MOZ_ASSERT(!mASCIIOrigin.IsEmpty()); 1.140 + MOZ_ASSERT(mManagerContent || mManagerTab); 1.141 + 1.142 + if (mASCIIOrigin.EqualsLiteral(CHROME_ORIGIN)) { 1.143 + nsAutoCString fullPermission = 1.144 + NS_LITERAL_CSTRING(PERMISSION_PREFIX) + 1.145 + NS_ConvertUTF16toUTF8(aDatabaseName) + 1.146 + aPermission; 1.147 + 1.148 + if ((mManagerContent && 1.149 + !AssertAppProcessPermission(mManagerContent, fullPermission.get())) || 1.150 + (mManagerTab && 1.151 + !AssertAppProcessPermission(mManagerTab, fullPermission.get()))) { 1.152 + return false; 1.153 + } 1.154 + } 1.155 + 1.156 + return true; 1.157 +} 1.158 + 1.159 +void 1.160 +IndexedDBParent::ActorDestroy(ActorDestroyReason aWhy) 1.161 +{ 1.162 + // Nothing really needs to be done here... 1.163 +} 1.164 + 1.165 +bool 1.166 +IndexedDBParent::RecvPIndexedDBDatabaseConstructor( 1.167 + PIndexedDBDatabaseParent* aActor, 1.168 + const nsString& aName, 1.169 + const uint64_t& aVersion, 1.170 + const PersistenceType& aPersistenceType) 1.171 +{ 1.172 + if (!CheckReadPermission(aName)) { 1.173 + return false; 1.174 + } 1.175 + 1.176 + if (IsDisconnected()) { 1.177 + // We're shutting down, ignore this request. 1.178 + return true; 1.179 + } 1.180 + 1.181 + if (!mFactory) { 1.182 + return true; 1.183 + } 1.184 + 1.185 + nsRefPtr<IDBOpenDBRequest> request; 1.186 + nsresult rv = mFactory->OpenInternal(aName, aVersion, aPersistenceType, false, 1.187 + getter_AddRefs(request)); 1.188 + NS_ENSURE_SUCCESS(rv, false); 1.189 + 1.190 + IndexedDBDatabaseParent* actor = 1.191 + static_cast<IndexedDBDatabaseParent*>(aActor); 1.192 + 1.193 + rv = actor->SetOpenRequest(request); 1.194 + NS_ENSURE_SUCCESS(rv, false); 1.195 + 1.196 + return true; 1.197 +} 1.198 + 1.199 +bool 1.200 +IndexedDBParent::RecvPIndexedDBDeleteDatabaseRequestConstructor( 1.201 + PIndexedDBDeleteDatabaseRequestParent* aActor, 1.202 + const nsString& aName, 1.203 + const PersistenceType& aPersistenceType) 1.204 +{ 1.205 + if (!CheckWritePermission(aName)) { 1.206 + return false; 1.207 + } 1.208 + 1.209 + if (IsDisconnected()) { 1.210 + // We're shutting down, ignore this request. 1.211 + return true; 1.212 + } 1.213 + 1.214 + if (!mFactory) { 1.215 + return true; 1.216 + } 1.217 + 1.218 + IndexedDBDeleteDatabaseRequestParent* actor = 1.219 + static_cast<IndexedDBDeleteDatabaseRequestParent*>(aActor); 1.220 + 1.221 + nsRefPtr<IDBOpenDBRequest> request; 1.222 + 1.223 + nsresult rv = mFactory->OpenInternal(aName, 0, aPersistenceType, true, 1.224 + getter_AddRefs(request)); 1.225 + NS_ENSURE_SUCCESS(rv, false); 1.226 + 1.227 + rv = actor->SetOpenRequest(request); 1.228 + NS_ENSURE_SUCCESS(rv, false); 1.229 + 1.230 + return true; 1.231 +} 1.232 + 1.233 +PIndexedDBDatabaseParent* 1.234 +IndexedDBParent::AllocPIndexedDBDatabaseParent( 1.235 + const nsString& aName, 1.236 + const uint64_t& aVersion, 1.237 + const PersistenceType& aPersistenceType) 1.238 +{ 1.239 + return new IndexedDBDatabaseParent(); 1.240 +} 1.241 + 1.242 +bool 1.243 +IndexedDBParent::DeallocPIndexedDBDatabaseParent(PIndexedDBDatabaseParent* aActor) 1.244 +{ 1.245 + delete aActor; 1.246 + return true; 1.247 +} 1.248 + 1.249 +PIndexedDBDeleteDatabaseRequestParent* 1.250 +IndexedDBParent::AllocPIndexedDBDeleteDatabaseRequestParent( 1.251 + const nsString& aName, 1.252 + const PersistenceType& aPersistenceType) 1.253 +{ 1.254 + return new IndexedDBDeleteDatabaseRequestParent(mFactory); 1.255 +} 1.256 + 1.257 +bool 1.258 +IndexedDBParent::DeallocPIndexedDBDeleteDatabaseRequestParent( 1.259 + PIndexedDBDeleteDatabaseRequestParent* aActor) 1.260 +{ 1.261 + delete aActor; 1.262 + return true; 1.263 +} 1.264 + 1.265 +/******************************************************************************* 1.266 + * IndexedDBDatabaseParent 1.267 + ******************************************************************************/ 1.268 + 1.269 +IndexedDBDatabaseParent::IndexedDBDatabaseParent() 1.270 +: mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()) 1.271 +{ 1.272 + MOZ_COUNT_CTOR(IndexedDBDatabaseParent); 1.273 +} 1.274 + 1.275 +IndexedDBDatabaseParent::~IndexedDBDatabaseParent() 1.276 +{ 1.277 + MOZ_COUNT_DTOR(IndexedDBDatabaseParent); 1.278 +} 1.279 + 1.280 +nsresult 1.281 +IndexedDBDatabaseParent::SetOpenRequest(IDBOpenDBRequest* aRequest) 1.282 +{ 1.283 + MOZ_ASSERT(aRequest); 1.284 + MOZ_ASSERT(!mOpenRequest); 1.285 + 1.286 + nsresult rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(SUCCESS_EVT_STR), 1.287 + mEventListener, false); 1.288 + NS_ENSURE_SUCCESS(rv, rv); 1.289 + 1.290 + rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR), 1.291 + mEventListener, false); 1.292 + NS_ENSURE_SUCCESS(rv, rv); 1.293 + 1.294 + rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(BLOCKED_EVT_STR), 1.295 + mEventListener, false); 1.296 + NS_ENSURE_SUCCESS(rv, rv); 1.297 + 1.298 + rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(UPGRADENEEDED_EVT_STR), 1.299 + mEventListener, false); 1.300 + NS_ENSURE_SUCCESS(rv, rv); 1.301 + 1.302 + mOpenRequest = aRequest; 1.303 + return NS_OK; 1.304 +} 1.305 + 1.306 +nsresult 1.307 +IndexedDBDatabaseParent::HandleEvent(nsIDOMEvent* aEvent) 1.308 +{ 1.309 + MOZ_ASSERT(aEvent); 1.310 + 1.311 + if (IsDisconnected()) { 1.312 + // We're shutting down, ignore this event. 1.313 + return NS_OK; 1.314 + } 1.315 + 1.316 + nsString type; 1.317 + nsresult rv = aEvent->GetType(type); 1.318 + NS_ENSURE_SUCCESS(rv, rv); 1.319 + 1.320 + nsCOMPtr<EventTarget> target = aEvent->InternalDOMEvent()->GetTarget(); 1.321 + 1.322 + if (mDatabase && 1.323 + SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*, 1.324 + mDatabase))) { 1.325 + rv = HandleDatabaseEvent(aEvent, type); 1.326 + NS_ENSURE_SUCCESS(rv, rv); 1.327 + 1.328 + return NS_OK; 1.329 + } 1.330 + 1.331 + if (mOpenRequest && 1.332 + SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*, 1.333 + mOpenRequest))) { 1.334 + rv = HandleRequestEvent(aEvent, type); 1.335 + NS_ENSURE_SUCCESS(rv, rv); 1.336 + 1.337 + return NS_OK; 1.338 + } 1.339 + 1.340 + MOZ_CRASH("Unexpected message!"); 1.341 +} 1.342 + 1.343 +void 1.344 +IndexedDBDatabaseParent::Disconnect() 1.345 +{ 1.346 + if (mDatabase) { 1.347 + mDatabase->DisconnectFromActorParent(); 1.348 + } 1.349 +} 1.350 + 1.351 +bool 1.352 +IndexedDBDatabaseParent::CheckWritePermission(const nsAString& aDatabaseName) 1.353 +{ 1.354 + IndexedDBParent* manager = static_cast<IndexedDBParent*>(Manager()); 1.355 + MOZ_ASSERT(manager); 1.356 + 1.357 + return manager->CheckWritePermission(aDatabaseName); 1.358 +} 1.359 + 1.360 +void 1.361 +IndexedDBDatabaseParent::Invalidate() 1.362 +{ 1.363 + MOZ_ASSERT(mDatabase); 1.364 + 1.365 + if (!IsDisconnected()) { 1.366 + mozilla::unused << SendInvalidate(); 1.367 + } 1.368 +} 1.369 + 1.370 +nsresult 1.371 +IndexedDBDatabaseParent::HandleRequestEvent(nsIDOMEvent* aEvent, 1.372 + const nsAString& aType) 1.373 +{ 1.374 + MOZ_ASSERT(mOpenRequest); 1.375 + MOZ_ASSERT(!IsDisconnected()); 1.376 + 1.377 + nsresult rv; 1.378 + 1.379 + if (aType.EqualsLiteral(ERROR_EVT_STR)) { 1.380 + nsRefPtr<IDBOpenDBRequest> request; 1.381 + mOpenRequest.swap(request); 1.382 + 1.383 + rv = request->GetErrorCode(); 1.384 + MOZ_ASSERT(NS_FAILED(rv)); 1.385 + 1.386 + if (!SendError(rv)) { 1.387 + return NS_ERROR_FAILURE; 1.388 + } 1.389 + 1.390 + rv = aEvent->PreventDefault(); 1.391 + NS_ENSURE_SUCCESS(rv, rv); 1.392 + 1.393 + return NS_OK; 1.394 + } 1.395 + 1.396 + if (aType.EqualsLiteral(BLOCKED_EVT_STR)) { 1.397 + MOZ_ASSERT(!mDatabase); 1.398 + 1.399 + nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent); 1.400 + NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE); 1.401 + 1.402 + uint64_t oldVersion = changeEvent->OldVersion(); 1.403 + 1.404 + if (!SendBlocked(oldVersion)) { 1.405 + return NS_ERROR_FAILURE; 1.406 + } 1.407 + 1.408 + return NS_OK; 1.409 + } 1.410 + 1.411 + AutoSafeJSContext cx; 1.412 + 1.413 + ErrorResult error; 1.414 + JS::Rooted<JS::Value> result(cx); 1.415 + mOpenRequest->GetResult(cx, &result, error); 1.416 + ENSURE_SUCCESS(error, error.ErrorCode()); 1.417 + 1.418 + MOZ_ASSERT(!JSVAL_IS_PRIMITIVE(result)); 1.419 + 1.420 + IDBDatabase *database; 1.421 + rv = UNWRAP_OBJECT(IDBDatabase, &result.toObject(), database); 1.422 + if (NS_FAILED(rv)) { 1.423 + NS_WARNING("Didn't get the object we expected!"); 1.424 + return rv; 1.425 + } 1.426 + 1.427 + DatabaseInfo* dbInfo = database->Info(); 1.428 + MOZ_ASSERT(dbInfo); 1.429 + 1.430 + nsAutoTArray<nsString, 20> objectStoreNames; 1.431 + if (!dbInfo->GetObjectStoreNames(objectStoreNames)) { 1.432 + MOZ_CRASH("This should never fail!"); 1.433 + } 1.434 + 1.435 + InfallibleTArray<ObjectStoreInfoGuts> objectStoreInfos; 1.436 + if (!objectStoreNames.IsEmpty()) { 1.437 + uint32_t length = objectStoreNames.Length(); 1.438 + 1.439 + objectStoreInfos.SetCapacity(length); 1.440 + 1.441 + for (uint32_t i = 0; i < length; i++) { 1.442 + ObjectStoreInfo* osInfo = dbInfo->GetObjectStore(objectStoreNames[i]); 1.443 + MOZ_ASSERT(osInfo); 1.444 + 1.445 + objectStoreInfos.AppendElement(*osInfo); 1.446 + } 1.447 + } 1.448 + 1.449 + if (aType.EqualsLiteral(SUCCESS_EVT_STR)) { 1.450 + nsRefPtr<IDBOpenDBRequest> request; 1.451 + mOpenRequest.swap(request); 1.452 + 1.453 + EventTarget* target = static_cast<EventTarget*>(database); 1.454 + 1.455 +#ifdef DEBUG 1.456 + { 1.457 + nsresult rvDEBUG = 1.458 + target->AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR), 1.459 + mEventListener, false); 1.460 + NS_WARN_IF_FALSE(NS_SUCCEEDED(rvDEBUG), "Failed to add error listener!"); 1.461 + } 1.462 +#endif 1.463 + 1.464 + NS_NAMED_LITERAL_STRING(versionChange, VERSIONCHANGE_EVT_STR); 1.465 + rv = target->AddEventListener(versionChange, mEventListener, false); 1.466 + NS_ENSURE_SUCCESS(rv, rv); 1.467 + 1.468 + if (!SendSuccess(*dbInfo, objectStoreInfos)) { 1.469 + return NS_ERROR_FAILURE; 1.470 + } 1.471 + 1.472 + MOZ_ASSERT(!mDatabase || mDatabase == database); 1.473 + 1.474 + if (!mDatabase) { 1.475 + database->SetActor(this); 1.476 + mDatabase = database; 1.477 + } 1.478 + 1.479 + return NS_OK; 1.480 + } 1.481 + 1.482 + if (aType.EqualsLiteral(UPGRADENEEDED_EVT_STR)) { 1.483 + MOZ_ASSERT(!mDatabase); 1.484 + 1.485 + IDBTransaction* transaction = 1.486 + AsyncConnectionHelper::GetCurrentTransaction(); 1.487 + MOZ_ASSERT(transaction); 1.488 + 1.489 + if (!CheckWritePermission(database->Name())) { 1.490 + // If we get here then the child process is either dead or in the process 1.491 + // of being killed. Abort the transaction now to prevent any changes to 1.492 + // the database. 1.493 + ErrorResult rv; 1.494 + transaction->Abort(rv); 1.495 + if (rv.Failed()) { 1.496 + NS_WARNING("Failed to abort transaction!"); 1.497 + } 1.498 + return NS_ERROR_FAILURE; 1.499 + } 1.500 + 1.501 + nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent); 1.502 + NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE); 1.503 + 1.504 + uint64_t oldVersion = changeEvent->OldVersion(); 1.505 + 1.506 + nsAutoPtr<IndexedDBVersionChangeTransactionParent> actor( 1.507 + new IndexedDBVersionChangeTransactionParent()); 1.508 + 1.509 + rv = actor->SetTransaction(transaction); 1.510 + NS_ENSURE_SUCCESS(rv, rv); 1.511 + 1.512 + VersionChangeTransactionParams versionChangeParams; 1.513 + versionChangeParams.dbInfo() = *dbInfo; 1.514 + versionChangeParams.osInfo() = objectStoreInfos; 1.515 + versionChangeParams.oldVersion() = oldVersion; 1.516 + 1.517 + if (!SendPIndexedDBTransactionConstructor(actor.forget(), 1.518 + versionChangeParams)) { 1.519 + return NS_ERROR_FAILURE; 1.520 + } 1.521 + 1.522 + database->SetActor(this); 1.523 + mDatabase = database; 1.524 + 1.525 + return NS_OK; 1.526 + } 1.527 + 1.528 + MOZ_CRASH("Unexpected message type!"); 1.529 +} 1.530 + 1.531 +nsresult 1.532 +IndexedDBDatabaseParent::HandleDatabaseEvent(nsIDOMEvent* aEvent, 1.533 + const nsAString& aType) 1.534 +{ 1.535 + MOZ_ASSERT(mDatabase); 1.536 + MOZ_ASSERT(!aType.EqualsLiteral(ERROR_EVT_STR), 1.537 + "Should never get error events in the parent process!"); 1.538 + MOZ_ASSERT(!IsDisconnected()); 1.539 + 1.540 + if (aType.EqualsLiteral(VERSIONCHANGE_EVT_STR)) { 1.541 + AutoSafeJSContext cx; 1.542 + NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE); 1.543 + 1.544 + nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent); 1.545 + NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE); 1.546 + 1.547 + uint64_t oldVersion = changeEvent->OldVersion(); 1.548 + 1.549 + Nullable<uint64_t> newVersionVal = changeEvent->GetNewVersion(); 1.550 + 1.551 + uint64_t newVersion; 1.552 + if (newVersionVal.IsNull()) { 1.553 + newVersion = 0; 1.554 + } 1.555 + else { 1.556 + newVersion = newVersionVal.Value(); 1.557 + } 1.558 + 1.559 + if (!SendVersionChange(oldVersion, newVersion)) { 1.560 + return NS_ERROR_FAILURE; 1.561 + } 1.562 + 1.563 + return NS_OK; 1.564 + } 1.565 + 1.566 + MOZ_CRASH("Unexpected message type!"); 1.567 +} 1.568 + 1.569 +void 1.570 +IndexedDBDatabaseParent::ActorDestroy(ActorDestroyReason aWhy) 1.571 +{ 1.572 + if (mDatabase) { 1.573 + mDatabase->SetActor(static_cast<IndexedDBDatabaseParent*>(nullptr)); 1.574 + mDatabase->InvalidateInternal(/* aIsDead */ true); 1.575 + } 1.576 +} 1.577 + 1.578 +bool 1.579 +IndexedDBDatabaseParent::RecvClose(const bool& aUnlinked) 1.580 +{ 1.581 + MOZ_ASSERT(mDatabase); 1.582 + 1.583 + if (IsDisconnected()) { 1.584 + // We're shutting down, ignore this request. 1.585 + return true; 1.586 + } 1.587 + 1.588 + mDatabase->CloseInternal(aUnlinked); 1.589 + return true; 1.590 +} 1.591 + 1.592 +bool 1.593 +IndexedDBDatabaseParent::RecvPIndexedDBTransactionConstructor( 1.594 + PIndexedDBTransactionParent* aActor, 1.595 + const TransactionParams& aParams) 1.596 +{ 1.597 + MOZ_ASSERT(aParams.type() == 1.598 + TransactionParams::TNormalTransactionParams); 1.599 + MOZ_ASSERT(!mOpenRequest); 1.600 + 1.601 + if (IsDisconnected()) { 1.602 + // We're shutting down, ignore this request. 1.603 + return true; 1.604 + } 1.605 + 1.606 + if (!mDatabase) { 1.607 + return true; 1.608 + } 1.609 + 1.610 + IndexedDBTransactionParent* actor = 1.611 + static_cast<IndexedDBTransactionParent*>(aActor); 1.612 + 1.613 + const NormalTransactionParams& params = aParams.get_NormalTransactionParams(); 1.614 + 1.615 + if (params.mode() != IDBTransaction::READ_ONLY && 1.616 + !CheckWritePermission(mDatabase->Name())) { 1.617 + return false; 1.618 + } 1.619 + 1.620 + if (mDatabase->IsClosed()) { 1.621 + // If the window was navigated then we won't be able to do anything here. 1.622 + return true; 1.623 + } 1.624 + 1.625 + Sequence<nsString> storesToOpen; 1.626 + storesToOpen.AppendElements(params.names()); 1.627 + 1.628 + nsRefPtr<IDBTransaction> transaction = 1.629 + IDBTransaction::Create(mDatabase, storesToOpen, params.mode(), false); 1.630 + NS_ENSURE_TRUE(transaction, false); 1.631 + 1.632 + nsresult rv = actor->SetTransaction(transaction); 1.633 + NS_ENSURE_SUCCESS(rv, false); 1.634 + 1.635 + return true; 1.636 +} 1.637 + 1.638 +PIndexedDBTransactionParent* 1.639 +IndexedDBDatabaseParent::AllocPIndexedDBTransactionParent( 1.640 + const TransactionParams& aParams) 1.641 +{ 1.642 + MOZ_ASSERT(aParams.type() == 1.643 + TransactionParams::TNormalTransactionParams); 1.644 + return new IndexedDBTransactionParent(); 1.645 +} 1.646 + 1.647 +bool 1.648 +IndexedDBDatabaseParent::DeallocPIndexedDBTransactionParent( 1.649 + PIndexedDBTransactionParent* aActor) 1.650 +{ 1.651 + delete aActor; 1.652 + return true; 1.653 +} 1.654 + 1.655 +/******************************************************************************* 1.656 + * IndexedDBTransactionParent 1.657 + ******************************************************************************/ 1.658 + 1.659 +IndexedDBTransactionParent::IndexedDBTransactionParent() 1.660 +: mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()), 1.661 + mArtificialRequestCount(false) 1.662 +{ 1.663 + MOZ_COUNT_CTOR(IndexedDBTransactionParent); 1.664 +} 1.665 + 1.666 +IndexedDBTransactionParent::~IndexedDBTransactionParent() 1.667 +{ 1.668 + MOZ_COUNT_DTOR(IndexedDBTransactionParent); 1.669 +} 1.670 + 1.671 +nsresult 1.672 +IndexedDBTransactionParent::SetTransaction(IDBTransaction* aTransaction) 1.673 +{ 1.674 + MOZ_ASSERT(aTransaction); 1.675 + MOZ_ASSERT(!mTransaction); 1.676 + 1.677 + EventTarget* target = static_cast<EventTarget*>(aTransaction); 1.678 + 1.679 + NS_NAMED_LITERAL_STRING(complete, COMPLETE_EVT_STR); 1.680 + nsresult rv = target->AddEventListener(complete, mEventListener, false); 1.681 + NS_ENSURE_SUCCESS(rv, rv); 1.682 + 1.683 + rv = target->AddEventListener(NS_LITERAL_STRING(ABORT_EVT_STR), 1.684 + mEventListener, false); 1.685 + NS_ENSURE_SUCCESS(rv, rv); 1.686 + 1.687 + aTransaction->OnNewRequest(); 1.688 + mArtificialRequestCount = true; 1.689 + 1.690 + aTransaction->SetActor(this); 1.691 + 1.692 + mTransaction = aTransaction; 1.693 + return NS_OK; 1.694 +} 1.695 + 1.696 +nsresult 1.697 +IndexedDBTransactionParent::HandleEvent(nsIDOMEvent* aEvent) 1.698 +{ 1.699 + MOZ_ASSERT(aEvent); 1.700 + 1.701 + if (IsDisconnected()) { 1.702 + // We're shutting down, ignore this event. 1.703 + return NS_OK; 1.704 + } 1.705 + 1.706 + nsString type; 1.707 + nsresult rv = aEvent->GetType(type); 1.708 + NS_ENSURE_SUCCESS(rv, rv); 1.709 + 1.710 + CompleteParams params; 1.711 + 1.712 + if (type.EqualsLiteral(COMPLETE_EVT_STR)) { 1.713 + params = CompleteResult(); 1.714 + } 1.715 + else if (type.EqualsLiteral(ABORT_EVT_STR)) { 1.716 +#ifdef DEBUG 1.717 + { 1.718 + nsCOMPtr<EventTarget> target = aEvent->InternalDOMEvent()->GetTarget(); 1.719 + MOZ_ASSERT(SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*, 1.720 + mTransaction))); 1.721 + } 1.722 +#endif 1.723 + params = AbortResult(mTransaction->GetAbortCode()); 1.724 + } 1.725 + else { 1.726 + NS_WARNING("Unknown message type!"); 1.727 + return NS_ERROR_UNEXPECTED; 1.728 + } 1.729 + 1.730 + if (!SendComplete(params)) { 1.731 + return NS_ERROR_FAILURE; 1.732 + } 1.733 + 1.734 + return NS_OK; 1.735 +} 1.736 + 1.737 +void 1.738 +IndexedDBTransactionParent::ActorDestroy(ActorDestroyReason aWhy) 1.739 +{ 1.740 + if (mTransaction) { 1.741 + if (mArtificialRequestCount) { 1.742 + // The transaction never completed and now the child side is dead. Abort 1.743 + // here to be safe. 1.744 + ErrorResult rv; 1.745 + mTransaction->Abort(rv); 1.746 + 1.747 + mTransaction->OnRequestFinished(); 1.748 +#ifdef DEBUG 1.749 + mArtificialRequestCount = false; 1.750 +#endif 1.751 + } 1.752 + mTransaction->SetActor(static_cast<IndexedDBTransactionParent*>(nullptr)); 1.753 + } 1.754 +} 1.755 + 1.756 +bool 1.757 +IndexedDBTransactionParent::RecvAbort(const nsresult& aAbortCode) 1.758 +{ 1.759 + MOZ_ASSERT(mTransaction); 1.760 + 1.761 + if (IsDisconnected()) { 1.762 + // We're shutting down, ignore this request. 1.763 + return true; 1.764 + } 1.765 + 1.766 + mTransaction->Abort(aAbortCode); 1.767 + return true; 1.768 +} 1.769 + 1.770 +bool 1.771 +IndexedDBTransactionParent::RecvAllRequestsFinished() 1.772 +{ 1.773 + MOZ_ASSERT(mTransaction); 1.774 + MOZ_ASSERT(mArtificialRequestCount); 1.775 + 1.776 + if (IsDisconnected()) { 1.777 + // We're shutting down, ignore this request. 1.778 + return true; 1.779 + } 1.780 + 1.781 + mTransaction->OnRequestFinished(); 1.782 + mArtificialRequestCount = false; 1.783 + 1.784 + return true; 1.785 +} 1.786 + 1.787 +bool 1.788 +IndexedDBTransactionParent::RecvDeleteObjectStore(const nsString& aName) 1.789 +{ 1.790 + MOZ_CRASH("Should be overridden, don't call me!"); 1.791 +} 1.792 + 1.793 +bool 1.794 +IndexedDBTransactionParent::RecvPIndexedDBObjectStoreConstructor( 1.795 + PIndexedDBObjectStoreParent* aActor, 1.796 + const ObjectStoreConstructorParams& aParams) 1.797 +{ 1.798 + if (IsDisconnected()) { 1.799 + // We're shutting down, ignore this request. 1.800 + return true; 1.801 + } 1.802 + 1.803 + if (!mTransaction) { 1.804 + return true; 1.805 + } 1.806 + 1.807 + IndexedDBObjectStoreParent* actor = 1.808 + static_cast<IndexedDBObjectStoreParent*>(aActor); 1.809 + 1.810 + if (aParams.type() == 1.811 + ObjectStoreConstructorParams::TGetObjectStoreParams) { 1.812 + const GetObjectStoreParams& params = aParams.get_GetObjectStoreParams(); 1.813 + const nsString& name = params.name(); 1.814 + 1.815 + nsRefPtr<IDBObjectStore> objectStore; 1.816 + 1.817 + { 1.818 + AutoSetCurrentTransaction asct(mTransaction); 1.819 + 1.820 + ErrorResult rv; 1.821 + objectStore = mTransaction->ObjectStore(name, rv); 1.822 + ENSURE_SUCCESS(rv, false); 1.823 + 1.824 + actor->SetObjectStore(objectStore); 1.825 + } 1.826 + 1.827 + objectStore->SetActor(actor); 1.828 + return true; 1.829 + } 1.830 + 1.831 + if (aParams.type() == 1.832 + ObjectStoreConstructorParams::TCreateObjectStoreParams) { 1.833 + MOZ_CRASH("Should be overridden, don't call me!"); 1.834 + } 1.835 + 1.836 + MOZ_CRASH("Unknown param type!"); 1.837 +} 1.838 + 1.839 +PIndexedDBObjectStoreParent* 1.840 +IndexedDBTransactionParent::AllocPIndexedDBObjectStoreParent( 1.841 + const ObjectStoreConstructorParams& aParams) 1.842 +{ 1.843 + return new IndexedDBObjectStoreParent(); 1.844 +} 1.845 + 1.846 +bool 1.847 +IndexedDBTransactionParent::DeallocPIndexedDBObjectStoreParent( 1.848 + PIndexedDBObjectStoreParent* aActor) 1.849 +{ 1.850 + delete aActor; 1.851 + return true; 1.852 +} 1.853 + 1.854 +/******************************************************************************* 1.855 + * IndexedDBVersionChangeTransactionParent 1.856 + ******************************************************************************/ 1.857 + 1.858 +IndexedDBVersionChangeTransactionParent:: 1.859 + IndexedDBVersionChangeTransactionParent() 1.860 +{ 1.861 + MOZ_COUNT_CTOR(IndexedDBVersionChangeTransactionParent); 1.862 +} 1.863 + 1.864 +IndexedDBVersionChangeTransactionParent:: 1.865 + ~IndexedDBVersionChangeTransactionParent() 1.866 +{ 1.867 + MOZ_COUNT_DTOR(IndexedDBVersionChangeTransactionParent); 1.868 +} 1.869 + 1.870 +bool 1.871 +IndexedDBVersionChangeTransactionParent::RecvDeleteObjectStore( 1.872 + const nsString& aName) 1.873 +{ 1.874 + MOZ_ASSERT(!mTransaction || 1.875 + mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE); 1.876 + 1.877 + if (IsDisconnected()) { 1.878 + // We're shutting down, ignore this request. 1.879 + return true; 1.880 + } 1.881 + 1.882 + if (!mTransaction) { 1.883 + return true; 1.884 + } 1.885 + 1.886 + if (mTransaction->Database()->IsInvalidated()) { 1.887 + // If we've invalidated this database in the parent then we should bail out 1.888 + // now to avoid logic problems that could force-kill the child. 1.889 + return true; 1.890 + } 1.891 + 1.892 + IDBDatabase* db = mTransaction->Database(); 1.893 + MOZ_ASSERT(db); 1.894 + 1.895 + ErrorResult rv; 1.896 + 1.897 + { 1.898 + AutoSetCurrentTransaction asct(mTransaction); 1.899 + db->DeleteObjectStore(aName, rv); 1.900 + } 1.901 + 1.902 + ENSURE_SUCCESS(rv, false); 1.903 + return true; 1.904 +} 1.905 + 1.906 +bool 1.907 +IndexedDBVersionChangeTransactionParent::RecvPIndexedDBObjectStoreConstructor( 1.908 + PIndexedDBObjectStoreParent* aActor, 1.909 + const ObjectStoreConstructorParams& aParams) 1.910 +{ 1.911 + if (IsDisconnected()) { 1.912 + // We're shutting down, ignore this request. 1.913 + return true; 1.914 + } 1.915 + 1.916 + if (!mTransaction) { 1.917 + return true; 1.918 + } 1.919 + 1.920 + if (mTransaction->Database()->IsInvalidated()) { 1.921 + // If we've invalidated this database in the parent then we should bail out 1.922 + // now to avoid logic problems that could force-kill the child. 1.923 + return true; 1.924 + } 1.925 + 1.926 + IndexedDBObjectStoreParent* actor = 1.927 + static_cast<IndexedDBObjectStoreParent*>(aActor); 1.928 + 1.929 + if (aParams.type() == 1.930 + ObjectStoreConstructorParams::TCreateObjectStoreParams) { 1.931 + MOZ_ASSERT(mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE); 1.932 + 1.933 + const CreateObjectStoreParams& params = 1.934 + aParams.get_CreateObjectStoreParams(); 1.935 + 1.936 + const ObjectStoreInfoGuts& info = params.info(); 1.937 + 1.938 + IDBDatabase* db = mTransaction->Database(); 1.939 + MOZ_ASSERT(db); 1.940 + 1.941 + nsRefPtr<IDBObjectStore> objectStore; 1.942 + 1.943 + ErrorResult rv; 1.944 + 1.945 + { 1.946 + AutoSetCurrentTransaction asct(mTransaction); 1.947 + 1.948 + objectStore = db->CreateObjectStoreInternal(mTransaction, info, rv); 1.949 + } 1.950 + 1.951 + ENSURE_SUCCESS(rv, false); 1.952 + 1.953 + actor->SetObjectStore(objectStore); 1.954 + objectStore->SetActor(actor); 1.955 + return true; 1.956 + } 1.957 + 1.958 + return 1.959 + IndexedDBTransactionParent::RecvPIndexedDBObjectStoreConstructor(aActor, 1.960 + aParams); 1.961 +} 1.962 + 1.963 +PIndexedDBObjectStoreParent* 1.964 +IndexedDBVersionChangeTransactionParent::AllocPIndexedDBObjectStoreParent( 1.965 + const ObjectStoreConstructorParams& aParams) 1.966 +{ 1.967 + if (aParams.type() == 1.968 + ObjectStoreConstructorParams::TCreateObjectStoreParams || 1.969 + mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE) { 1.970 + return new IndexedDBVersionChangeObjectStoreParent(); 1.971 + } 1.972 + 1.973 + return IndexedDBTransactionParent::AllocPIndexedDBObjectStoreParent(aParams); 1.974 +} 1.975 + 1.976 +/******************************************************************************* 1.977 + * IndexedDBCursorParent 1.978 + ******************************************************************************/ 1.979 + 1.980 +IndexedDBCursorParent::IndexedDBCursorParent(IDBCursor* aCursor) 1.981 +: mCursor(aCursor) 1.982 +{ 1.983 + MOZ_COUNT_CTOR(IndexedDBCursorParent); 1.984 + MOZ_ASSERT(aCursor); 1.985 + aCursor->SetActor(this); 1.986 +} 1.987 + 1.988 +IndexedDBCursorParent::~IndexedDBCursorParent() 1.989 +{ 1.990 + MOZ_COUNT_DTOR(IndexedDBCursorParent); 1.991 +} 1.992 + 1.993 +bool 1.994 +IndexedDBCursorParent::IsDisconnected() const 1.995 +{ 1.996 + MOZ_ASSERT(mCursor); 1.997 + return mCursor->Transaction()->GetActorParent()->IsDisconnected(); 1.998 +} 1.999 + 1.1000 +void 1.1001 +IndexedDBCursorParent::ActorDestroy(ActorDestroyReason aWhy) 1.1002 +{ 1.1003 + MOZ_ASSERT(mCursor); 1.1004 + mCursor->SetActor(static_cast<IndexedDBCursorParent*>(nullptr)); 1.1005 +} 1.1006 + 1.1007 +bool 1.1008 +IndexedDBCursorParent::RecvPIndexedDBRequestConstructor( 1.1009 + PIndexedDBRequestParent* aActor, 1.1010 + const CursorRequestParams& aParams) 1.1011 +{ 1.1012 + MOZ_ASSERT(mCursor); 1.1013 + 1.1014 + if (IsDisconnected()) { 1.1015 + // We're shutting down, ignore this request. 1.1016 + return true; 1.1017 + } 1.1018 + 1.1019 + IndexedDBCursorRequestParent* actor = 1.1020 + static_cast<IndexedDBCursorRequestParent*>(aActor); 1.1021 + 1.1022 + if (mCursor->Transaction()->Database()->IsInvalidated()) { 1.1023 + // If we've invalidated this database in the parent then we should bail out 1.1024 + // now to avoid logic problems that could force-kill the child. 1.1025 + return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); 1.1026 + } 1.1027 + 1.1028 + switch (aParams.type()) { 1.1029 + case CursorRequestParams::TContinueParams: 1.1030 + return actor->Continue(aParams.get_ContinueParams()); 1.1031 + 1.1032 + default: 1.1033 + MOZ_CRASH("Unknown type!"); 1.1034 + } 1.1035 + 1.1036 + MOZ_CRASH("Should never get here!"); 1.1037 +} 1.1038 + 1.1039 +PIndexedDBRequestParent* 1.1040 +IndexedDBCursorParent::AllocPIndexedDBRequestParent( 1.1041 + const CursorRequestParams& aParams) 1.1042 +{ 1.1043 + MOZ_ASSERT(mCursor); 1.1044 + return new IndexedDBCursorRequestParent(mCursor, aParams.type()); 1.1045 +} 1.1046 + 1.1047 +bool 1.1048 +IndexedDBCursorParent::DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) 1.1049 +{ 1.1050 + delete aActor; 1.1051 + return true; 1.1052 +} 1.1053 + 1.1054 +/******************************************************************************* 1.1055 + * IndexedDBObjectStoreParent 1.1056 + ******************************************************************************/ 1.1057 + 1.1058 +IndexedDBObjectStoreParent::IndexedDBObjectStoreParent() 1.1059 +{ 1.1060 + MOZ_COUNT_CTOR(IndexedDBObjectStoreParent); 1.1061 +} 1.1062 + 1.1063 +IndexedDBObjectStoreParent::~IndexedDBObjectStoreParent() 1.1064 +{ 1.1065 + MOZ_COUNT_DTOR(IndexedDBObjectStoreParent); 1.1066 +} 1.1067 + 1.1068 +void 1.1069 +IndexedDBObjectStoreParent::SetObjectStore(IDBObjectStore* aObjectStore) 1.1070 +{ 1.1071 + // Sadly can't assert aObjectStore here... 1.1072 + MOZ_ASSERT(!mObjectStore); 1.1073 + 1.1074 + mObjectStore = aObjectStore; 1.1075 +} 1.1076 + 1.1077 +void 1.1078 +IndexedDBObjectStoreParent::ActorDestroy(ActorDestroyReason aWhy) 1.1079 +{ 1.1080 + if (mObjectStore) { 1.1081 + mObjectStore->SetActor(static_cast<IndexedDBObjectStoreParent*>(nullptr)); 1.1082 + } 1.1083 +} 1.1084 + 1.1085 +bool 1.1086 +IndexedDBObjectStoreParent::RecvDeleteIndex(const nsString& aName) 1.1087 +{ 1.1088 + MOZ_CRASH("Should be overridden, don't call me!"); 1.1089 +} 1.1090 + 1.1091 +bool 1.1092 +IndexedDBObjectStoreParent::RecvPIndexedDBRequestConstructor( 1.1093 + PIndexedDBRequestParent* aActor, 1.1094 + const ObjectStoreRequestParams& aParams) 1.1095 +{ 1.1096 + if (IsDisconnected()) { 1.1097 + // We're shutting down, ignore this request. 1.1098 + return true; 1.1099 + } 1.1100 + 1.1101 + if (!mObjectStore) { 1.1102 + return true; 1.1103 + } 1.1104 + 1.1105 + IndexedDBObjectStoreRequestParent* actor = 1.1106 + static_cast<IndexedDBObjectStoreRequestParent*>(aActor); 1.1107 + 1.1108 + if (mObjectStore->Transaction()->Database()->IsInvalidated()) { 1.1109 + // If we've invalidated this database in the parent then we should bail out 1.1110 + // now to avoid logic problems that could force-kill the child. 1.1111 + return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); 1.1112 + } 1.1113 + 1.1114 + switch (aParams.type()) { 1.1115 + case ObjectStoreRequestParams::TGetParams: 1.1116 + return actor->Get(aParams.get_GetParams()); 1.1117 + 1.1118 + case ObjectStoreRequestParams::TGetAllParams: 1.1119 + return actor->GetAll(aParams.get_GetAllParams()); 1.1120 + 1.1121 + case ObjectStoreRequestParams::TGetAllKeysParams: 1.1122 + return actor->GetAllKeys(aParams.get_GetAllKeysParams()); 1.1123 + 1.1124 + case ObjectStoreRequestParams::TAddParams: 1.1125 + return actor->Add(aParams.get_AddParams()); 1.1126 + 1.1127 + case ObjectStoreRequestParams::TPutParams: 1.1128 + return actor->Put(aParams.get_PutParams()); 1.1129 + 1.1130 + case ObjectStoreRequestParams::TDeleteParams: 1.1131 + return actor->Delete(aParams.get_DeleteParams()); 1.1132 + 1.1133 + case ObjectStoreRequestParams::TClearParams: 1.1134 + return actor->Clear(aParams.get_ClearParams()); 1.1135 + 1.1136 + case ObjectStoreRequestParams::TCountParams: 1.1137 + return actor->Count(aParams.get_CountParams()); 1.1138 + 1.1139 + case ObjectStoreRequestParams::TOpenCursorParams: 1.1140 + return actor->OpenCursor(aParams.get_OpenCursorParams()); 1.1141 + 1.1142 + case ObjectStoreRequestParams::TOpenKeyCursorParams: 1.1143 + return actor->OpenKeyCursor(aParams.get_OpenKeyCursorParams()); 1.1144 + 1.1145 + default: 1.1146 + MOZ_CRASH("Unknown type!"); 1.1147 + } 1.1148 + 1.1149 + MOZ_CRASH("Should never get here!"); 1.1150 +} 1.1151 + 1.1152 +bool 1.1153 +IndexedDBObjectStoreParent::RecvPIndexedDBIndexConstructor( 1.1154 + PIndexedDBIndexParent* aActor, 1.1155 + const IndexConstructorParams& aParams) 1.1156 +{ 1.1157 + if (IsDisconnected()) { 1.1158 + // We're shutting down, ignore this request. 1.1159 + return true; 1.1160 + } 1.1161 + 1.1162 + if (!mObjectStore) { 1.1163 + return true; 1.1164 + } 1.1165 + 1.1166 + IndexedDBIndexParent* actor = static_cast<IndexedDBIndexParent*>(aActor); 1.1167 + 1.1168 + if (aParams.type() == IndexConstructorParams::TGetIndexParams) { 1.1169 + const GetIndexParams& params = aParams.get_GetIndexParams(); 1.1170 + const nsString& name = params.name(); 1.1171 + 1.1172 + nsRefPtr<IDBIndex> index; 1.1173 + 1.1174 + { 1.1175 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1176 + 1.1177 + ErrorResult rv; 1.1178 + index = mObjectStore->Index(name, rv); 1.1179 + ENSURE_SUCCESS(rv, false); 1.1180 + 1.1181 + actor->SetIndex(index); 1.1182 + } 1.1183 + 1.1184 + index->SetActor(actor); 1.1185 + return true; 1.1186 + } 1.1187 + 1.1188 + if (aParams.type() == IndexConstructorParams::TCreateIndexParams) { 1.1189 + MOZ_CRASH("Should be overridden, don't call me!"); 1.1190 + } 1.1191 + 1.1192 + MOZ_CRASH("Unknown param type!"); 1.1193 +} 1.1194 + 1.1195 +PIndexedDBRequestParent* 1.1196 +IndexedDBObjectStoreParent::AllocPIndexedDBRequestParent( 1.1197 + const ObjectStoreRequestParams& aParams) 1.1198 +{ 1.1199 + return new IndexedDBObjectStoreRequestParent(mObjectStore, aParams.type()); 1.1200 +} 1.1201 + 1.1202 +bool 1.1203 +IndexedDBObjectStoreParent::DeallocPIndexedDBRequestParent( 1.1204 + PIndexedDBRequestParent* aActor) 1.1205 +{ 1.1206 + delete aActor; 1.1207 + return true; 1.1208 +} 1.1209 + 1.1210 +PIndexedDBIndexParent* 1.1211 +IndexedDBObjectStoreParent::AllocPIndexedDBIndexParent( 1.1212 + const IndexConstructorParams& aParams) 1.1213 +{ 1.1214 + return new IndexedDBIndexParent(); 1.1215 +} 1.1216 + 1.1217 +bool 1.1218 +IndexedDBObjectStoreParent::DeallocPIndexedDBIndexParent( 1.1219 + PIndexedDBIndexParent* aActor) 1.1220 +{ 1.1221 + delete aActor; 1.1222 + return true; 1.1223 +} 1.1224 + 1.1225 +PIndexedDBCursorParent* 1.1226 +IndexedDBObjectStoreParent::AllocPIndexedDBCursorParent( 1.1227 + const ObjectStoreCursorConstructorParams& aParams) 1.1228 +{ 1.1229 + MOZ_CRASH("Caller is supposed to manually construct a cursor!"); 1.1230 +} 1.1231 + 1.1232 +bool 1.1233 +IndexedDBObjectStoreParent::DeallocPIndexedDBCursorParent( 1.1234 + PIndexedDBCursorParent* aActor) 1.1235 +{ 1.1236 + delete aActor; 1.1237 + return true; 1.1238 +} 1.1239 + 1.1240 +/******************************************************************************* 1.1241 + * IndexedDBVersionChangeObjectStoreParent 1.1242 + ******************************************************************************/ 1.1243 + 1.1244 +IndexedDBVersionChangeObjectStoreParent:: 1.1245 + IndexedDBVersionChangeObjectStoreParent() 1.1246 +{ 1.1247 + MOZ_COUNT_CTOR(IndexedDBVersionChangeObjectStoreParent); 1.1248 +} 1.1249 + 1.1250 +IndexedDBVersionChangeObjectStoreParent:: 1.1251 + ~IndexedDBVersionChangeObjectStoreParent() 1.1252 +{ 1.1253 + MOZ_COUNT_DTOR(IndexedDBVersionChangeObjectStoreParent); 1.1254 +} 1.1255 + 1.1256 +bool 1.1257 +IndexedDBVersionChangeObjectStoreParent::RecvDeleteIndex(const nsString& aName) 1.1258 +{ 1.1259 + MOZ_ASSERT(!mObjectStore || 1.1260 + mObjectStore->Transaction()->GetMode() == 1.1261 + IDBTransaction::VERSION_CHANGE); 1.1262 + 1.1263 + if (IsDisconnected()) { 1.1264 + // We're shutting down, ignore this request. 1.1265 + return true; 1.1266 + } 1.1267 + 1.1268 + if (!mObjectStore) { 1.1269 + return true; 1.1270 + } 1.1271 + 1.1272 + if (mObjectStore->Transaction()->Database()->IsInvalidated()) { 1.1273 + // If we've invalidated this database in the parent then we should bail out 1.1274 + // now to avoid logic problems that could force-kill the child. 1.1275 + return true; 1.1276 + } 1.1277 + 1.1278 + ErrorResult rv; 1.1279 + 1.1280 + { 1.1281 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1282 + 1.1283 + mObjectStore->DeleteIndex(aName, rv); 1.1284 + } 1.1285 + 1.1286 + ENSURE_SUCCESS(rv, false); 1.1287 + return true; 1.1288 +} 1.1289 + 1.1290 +bool 1.1291 +IndexedDBVersionChangeObjectStoreParent::RecvPIndexedDBIndexConstructor( 1.1292 + PIndexedDBIndexParent* aActor, 1.1293 + const IndexConstructorParams& aParams) 1.1294 +{ 1.1295 + if (IsDisconnected()) { 1.1296 + // We're shutting down, ignore this request. 1.1297 + return true; 1.1298 + } 1.1299 + 1.1300 + if (!mObjectStore) { 1.1301 + return true; 1.1302 + } 1.1303 + 1.1304 + if (mObjectStore->Transaction()->Database()->IsInvalidated()) { 1.1305 + // If we've invalidated this database in the parent then we should bail out 1.1306 + // now to avoid logic problems that could force-kill the child. 1.1307 + return true; 1.1308 + } 1.1309 + 1.1310 + IndexedDBIndexParent* actor = static_cast<IndexedDBIndexParent*>(aActor); 1.1311 + 1.1312 + if (aParams.type() == IndexConstructorParams::TCreateIndexParams) { 1.1313 + MOZ_ASSERT(mObjectStore->Transaction()->GetMode() == 1.1314 + IDBTransaction::VERSION_CHANGE); 1.1315 + 1.1316 + const CreateIndexParams& params = aParams.get_CreateIndexParams(); 1.1317 + const IndexInfo& info = params.info(); 1.1318 + 1.1319 + nsRefPtr<IDBIndex> index; 1.1320 + 1.1321 + { 1.1322 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1323 + 1.1324 + ErrorResult rv; 1.1325 + index = mObjectStore->CreateIndexInternal(info, rv); 1.1326 + ENSURE_SUCCESS(rv, false); 1.1327 + } 1.1328 + 1.1329 + actor->SetIndex(index); 1.1330 + index->SetActor(actor); 1.1331 + return true; 1.1332 + } 1.1333 + 1.1334 + return IndexedDBObjectStoreParent::RecvPIndexedDBIndexConstructor(aActor, 1.1335 + aParams); 1.1336 +} 1.1337 + 1.1338 +/******************************************************************************* 1.1339 + * IndexedDBIndexParent 1.1340 + ******************************************************************************/ 1.1341 + 1.1342 +IndexedDBIndexParent::IndexedDBIndexParent() 1.1343 +{ 1.1344 + MOZ_COUNT_CTOR(IndexedDBIndexParent); 1.1345 +} 1.1346 + 1.1347 +IndexedDBIndexParent::~IndexedDBIndexParent() 1.1348 +{ 1.1349 + MOZ_COUNT_DTOR(IndexedDBIndexParent); 1.1350 +} 1.1351 + 1.1352 +void 1.1353 +IndexedDBIndexParent::SetIndex(IDBIndex* aIndex) 1.1354 +{ 1.1355 + MOZ_ASSERT(aIndex); 1.1356 + MOZ_ASSERT(!mIndex); 1.1357 + 1.1358 + mIndex = aIndex; 1.1359 +} 1.1360 + 1.1361 +void 1.1362 +IndexedDBIndexParent::ActorDestroy(ActorDestroyReason aWhy) 1.1363 +{ 1.1364 + if (mIndex) { 1.1365 + mIndex->SetActor(static_cast<IndexedDBIndexParent*>(nullptr)); 1.1366 + } 1.1367 +} 1.1368 + 1.1369 +bool 1.1370 +IndexedDBIndexParent::RecvPIndexedDBRequestConstructor( 1.1371 + PIndexedDBRequestParent* aActor, 1.1372 + const IndexRequestParams& aParams) 1.1373 +{ 1.1374 + if (IsDisconnected()) { 1.1375 + // We're shutting down, ignore this request. 1.1376 + return true; 1.1377 + } 1.1378 + 1.1379 + if (!mIndex) { 1.1380 + return true; 1.1381 + } 1.1382 + 1.1383 + IndexedDBIndexRequestParent* actor = 1.1384 + static_cast<IndexedDBIndexRequestParent*>(aActor); 1.1385 + 1.1386 + if (mIndex->ObjectStore()->Transaction()->Database()->IsInvalidated()) { 1.1387 + // If we've invalidated this database in the parent then we should bail out 1.1388 + // now to avoid logic problems that could force-kill the child. 1.1389 + return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); 1.1390 + } 1.1391 + 1.1392 + switch (aParams.type()) { 1.1393 + case IndexRequestParams::TGetParams: 1.1394 + return actor->Get(aParams.get_GetParams()); 1.1395 + 1.1396 + case IndexRequestParams::TGetKeyParams: 1.1397 + return actor->GetKey(aParams.get_GetKeyParams()); 1.1398 + 1.1399 + case IndexRequestParams::TGetAllParams: 1.1400 + return actor->GetAll(aParams.get_GetAllParams()); 1.1401 + 1.1402 + case IndexRequestParams::TGetAllKeysParams: 1.1403 + return actor->GetAllKeys(aParams.get_GetAllKeysParams()); 1.1404 + 1.1405 + case IndexRequestParams::TCountParams: 1.1406 + return actor->Count(aParams.get_CountParams()); 1.1407 + 1.1408 + case IndexRequestParams::TOpenCursorParams: 1.1409 + return actor->OpenCursor(aParams.get_OpenCursorParams()); 1.1410 + 1.1411 + case IndexRequestParams::TOpenKeyCursorParams: 1.1412 + return actor->OpenKeyCursor(aParams.get_OpenKeyCursorParams()); 1.1413 + 1.1414 + default: 1.1415 + MOZ_CRASH("Unknown type!"); 1.1416 + } 1.1417 + 1.1418 + MOZ_CRASH("Should never get here!"); 1.1419 +} 1.1420 + 1.1421 +PIndexedDBRequestParent* 1.1422 +IndexedDBIndexParent::AllocPIndexedDBRequestParent(const IndexRequestParams& aParams) 1.1423 +{ 1.1424 + return new IndexedDBIndexRequestParent(mIndex, aParams.type()); 1.1425 +} 1.1426 + 1.1427 +bool 1.1428 +IndexedDBIndexParent::DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) 1.1429 +{ 1.1430 + delete aActor; 1.1431 + return true; 1.1432 +} 1.1433 + 1.1434 +PIndexedDBCursorParent* 1.1435 +IndexedDBIndexParent::AllocPIndexedDBCursorParent( 1.1436 + const IndexCursorConstructorParams& aParams) 1.1437 +{ 1.1438 + MOZ_CRASH("Caller is supposed to manually construct a cursor!"); 1.1439 +} 1.1440 + 1.1441 +bool 1.1442 +IndexedDBIndexParent::DeallocPIndexedDBCursorParent(PIndexedDBCursorParent* aActor) 1.1443 +{ 1.1444 + delete aActor; 1.1445 + return true; 1.1446 +} 1.1447 + 1.1448 +/******************************************************************************* 1.1449 + * IndexedDBRequestParentBase 1.1450 + ******************************************************************************/ 1.1451 + 1.1452 +IndexedDBRequestParentBase::IndexedDBRequestParentBase() 1.1453 +{ 1.1454 + MOZ_COUNT_CTOR(IndexedDBRequestParentBase); 1.1455 +} 1.1456 + 1.1457 +IndexedDBRequestParentBase::~IndexedDBRequestParentBase() 1.1458 +{ 1.1459 + MOZ_COUNT_DTOR(IndexedDBRequestParentBase); 1.1460 +} 1.1461 + 1.1462 +void 1.1463 +IndexedDBRequestParentBase::ActorDestroy(ActorDestroyReason aWhy) 1.1464 +{ 1.1465 + if (mRequest) { 1.1466 + mRequest->SetActor(nullptr); 1.1467 + } 1.1468 +} 1.1469 + 1.1470 +/******************************************************************************* 1.1471 + * IndexedDBObjectStoreRequestParent 1.1472 + ******************************************************************************/ 1.1473 + 1.1474 +IndexedDBObjectStoreRequestParent::IndexedDBObjectStoreRequestParent( 1.1475 + IDBObjectStore* aObjectStore, 1.1476 + RequestType aRequestType) 1.1477 +: mObjectStore(aObjectStore), mRequestType(aRequestType) 1.1478 +{ 1.1479 + MOZ_COUNT_CTOR(IndexedDBObjectStoreRequestParent); 1.1480 + // Sadly can't assert aObjectStore here... 1.1481 + MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && 1.1482 + aRequestType <= ParamsUnionType::T__Last); 1.1483 +} 1.1484 + 1.1485 +IndexedDBObjectStoreRequestParent::~IndexedDBObjectStoreRequestParent() 1.1486 +{ 1.1487 + MOZ_COUNT_DTOR(IndexedDBObjectStoreRequestParent); 1.1488 +} 1.1489 + 1.1490 +void 1.1491 +IndexedDBObjectStoreRequestParent::ConvertBlobActors( 1.1492 + const InfallibleTArray<PBlobParent*>& aActors, 1.1493 + nsTArray<nsCOMPtr<nsIDOMBlob> >& aBlobs) 1.1494 +{ 1.1495 + MOZ_ASSERT(aBlobs.IsEmpty()); 1.1496 + MOZ_ASSERT(mObjectStore); 1.1497 + 1.1498 + if (!aActors.IsEmpty()) { 1.1499 + // Walk the chain to get to ContentParent. 1.1500 + MOZ_ASSERT(mObjectStore->Transaction()->Database()->GetContentParent()); 1.1501 + 1.1502 + uint32_t length = aActors.Length(); 1.1503 + aBlobs.SetCapacity(length); 1.1504 + 1.1505 + for (uint32_t index = 0; index < length; index++) { 1.1506 + BlobParent* actor = static_cast<BlobParent*>(aActors[index]); 1.1507 + nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob(); 1.1508 + aBlobs.AppendElement(blob); 1.1509 + } 1.1510 + } 1.1511 +} 1.1512 + 1.1513 +bool 1.1514 +IndexedDBObjectStoreRequestParent::IsDisconnected() 1.1515 +{ 1.1516 + MOZ_ASSERT(mObjectStore); 1.1517 + MOZ_ASSERT(mObjectStore->GetActorParent()); 1.1518 + return mObjectStore->GetActorParent()->IsDisconnected(); 1.1519 +} 1.1520 + 1.1521 +bool 1.1522 +IndexedDBObjectStoreRequestParent::Get(const GetParams& aParams) 1.1523 +{ 1.1524 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams); 1.1525 + MOZ_ASSERT(mObjectStore); 1.1526 + 1.1527 + nsRefPtr<IDBRequest> request; 1.1528 + 1.1529 + nsRefPtr<IDBKeyRange> keyRange = 1.1530 + IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); 1.1531 + MOZ_ASSERT(keyRange); 1.1532 + 1.1533 + { 1.1534 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1535 + 1.1536 + ErrorResult rv; 1.1537 + request = mObjectStore->GetInternal(keyRange, rv); 1.1538 + ENSURE_SUCCESS(rv, false); 1.1539 + } 1.1540 + 1.1541 + request->SetActor(this); 1.1542 + mRequest.swap(request); 1.1543 + 1.1544 + return true; 1.1545 +} 1.1546 + 1.1547 +bool 1.1548 +IndexedDBObjectStoreRequestParent::GetAll(const GetAllParams& aParams) 1.1549 +{ 1.1550 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams); 1.1551 + MOZ_ASSERT(mObjectStore); 1.1552 + 1.1553 + nsRefPtr<IDBRequest> request; 1.1554 + 1.1555 + const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); 1.1556 + 1.1557 + nsRefPtr<IDBKeyRange> keyRange; 1.1558 + 1.1559 + switch (keyRangeUnion.type()) { 1.1560 + case ipc::OptionalKeyRange::TKeyRange: 1.1561 + keyRange = 1.1562 + IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); 1.1563 + break; 1.1564 + 1.1565 + case ipc::OptionalKeyRange::Tvoid_t: 1.1566 + break; 1.1567 + 1.1568 + default: 1.1569 + MOZ_CRASH("Unknown param type!"); 1.1570 + } 1.1571 + 1.1572 + { 1.1573 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1574 + 1.1575 + ErrorResult rv; 1.1576 + request = mObjectStore->GetAllInternal(keyRange, aParams.limit(), rv); 1.1577 + ENSURE_SUCCESS(rv, false); 1.1578 + } 1.1579 + 1.1580 + request->SetActor(this); 1.1581 + mRequest.swap(request); 1.1582 + return true; 1.1583 +} 1.1584 + 1.1585 +bool 1.1586 +IndexedDBObjectStoreRequestParent::GetAllKeys(const GetAllKeysParams& aParams) 1.1587 +{ 1.1588 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams); 1.1589 + MOZ_ASSERT(mObjectStore); 1.1590 + 1.1591 + nsRefPtr<IDBRequest> request; 1.1592 + 1.1593 + const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); 1.1594 + 1.1595 + nsRefPtr<IDBKeyRange> keyRange; 1.1596 + 1.1597 + switch (keyRangeUnion.type()) { 1.1598 + case ipc::OptionalKeyRange::TKeyRange: 1.1599 + keyRange = 1.1600 + IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); 1.1601 + break; 1.1602 + 1.1603 + case ipc::OptionalKeyRange::Tvoid_t: 1.1604 + break; 1.1605 + 1.1606 + default: 1.1607 + MOZ_CRASH("Unknown param type!"); 1.1608 + } 1.1609 + 1.1610 + { 1.1611 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1612 + 1.1613 + ErrorResult rv; 1.1614 + request = mObjectStore->GetAllKeysInternal(keyRange, aParams.limit(), rv); 1.1615 + ENSURE_SUCCESS(rv, false); 1.1616 + } 1.1617 + 1.1618 + request->SetActor(this); 1.1619 + mRequest.swap(request); 1.1620 + return true; 1.1621 +} 1.1622 + 1.1623 +bool 1.1624 +IndexedDBObjectStoreRequestParent::Add(const AddParams& aParams) 1.1625 +{ 1.1626 + MOZ_ASSERT(mRequestType == ParamsUnionType::TAddParams); 1.1627 + MOZ_ASSERT(mObjectStore); 1.1628 + 1.1629 + ipc::AddPutParams params = aParams.commonParams(); 1.1630 + 1.1631 + nsTArray<nsCOMPtr<nsIDOMBlob> > blobs; 1.1632 + ConvertBlobActors(params.blobsParent(), blobs); 1.1633 + 1.1634 + nsRefPtr<IDBRequest> request; 1.1635 + 1.1636 + { 1.1637 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1638 + 1.1639 + nsresult rv = 1.1640 + mObjectStore->AddOrPutInternal(params.cloneInfo(), params.key(), 1.1641 + params.indexUpdateInfos(), blobs, false, 1.1642 + getter_AddRefs(request)); 1.1643 + NS_ENSURE_SUCCESS(rv, false); 1.1644 + } 1.1645 + 1.1646 + request->SetActor(this); 1.1647 + mRequest.swap(request); 1.1648 + return true; 1.1649 +} 1.1650 + 1.1651 +bool 1.1652 +IndexedDBObjectStoreRequestParent::Put(const PutParams& aParams) 1.1653 +{ 1.1654 + MOZ_ASSERT(mRequestType == ParamsUnionType::TPutParams); 1.1655 + MOZ_ASSERT(mObjectStore); 1.1656 + 1.1657 + ipc::AddPutParams params = aParams.commonParams(); 1.1658 + 1.1659 + nsTArray<nsCOMPtr<nsIDOMBlob> > blobs; 1.1660 + ConvertBlobActors(params.blobsParent(), blobs); 1.1661 + 1.1662 + nsRefPtr<IDBRequest> request; 1.1663 + 1.1664 + { 1.1665 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1666 + 1.1667 + nsresult rv = 1.1668 + mObjectStore->AddOrPutInternal(params.cloneInfo(), params.key(), 1.1669 + params.indexUpdateInfos(), blobs, true, 1.1670 + getter_AddRefs(request)); 1.1671 + NS_ENSURE_SUCCESS(rv, false); 1.1672 + } 1.1673 + 1.1674 + request->SetActor(this); 1.1675 + mRequest.swap(request); 1.1676 + return true; 1.1677 +} 1.1678 + 1.1679 +bool 1.1680 +IndexedDBObjectStoreRequestParent::Delete(const DeleteParams& aParams) 1.1681 +{ 1.1682 + MOZ_ASSERT(mRequestType == ParamsUnionType::TDeleteParams); 1.1683 + MOZ_ASSERT(mObjectStore); 1.1684 + 1.1685 + nsRefPtr<IDBRequest> request; 1.1686 + 1.1687 + nsRefPtr<IDBKeyRange> keyRange = 1.1688 + IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); 1.1689 + MOZ_ASSERT(keyRange); 1.1690 + 1.1691 + { 1.1692 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1693 + 1.1694 + ErrorResult rv; 1.1695 + request = mObjectStore->DeleteInternal(keyRange, rv); 1.1696 + ENSURE_SUCCESS(rv, false); 1.1697 + } 1.1698 + 1.1699 + request->SetActor(this); 1.1700 + mRequest.swap(request); 1.1701 + return true; 1.1702 +} 1.1703 + 1.1704 +bool 1.1705 +IndexedDBObjectStoreRequestParent::Clear(const ClearParams& aParams) 1.1706 +{ 1.1707 + MOZ_ASSERT(mRequestType == ParamsUnionType::TClearParams); 1.1708 + MOZ_ASSERT(mObjectStore); 1.1709 + 1.1710 + nsRefPtr<IDBRequest> request; 1.1711 + 1.1712 + { 1.1713 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1714 + 1.1715 + ErrorResult rv; 1.1716 + request = mObjectStore->Clear(rv); 1.1717 + ENSURE_SUCCESS(rv, false); 1.1718 + } 1.1719 + 1.1720 + request->SetActor(this); 1.1721 + mRequest.swap(request); 1.1722 + return true; 1.1723 +} 1.1724 + 1.1725 +bool 1.1726 +IndexedDBObjectStoreRequestParent::Count(const CountParams& aParams) 1.1727 +{ 1.1728 + MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams); 1.1729 + MOZ_ASSERT(mObjectStore); 1.1730 + 1.1731 + const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); 1.1732 + 1.1733 + nsRefPtr<IDBKeyRange> keyRange; 1.1734 + 1.1735 + switch (keyRangeUnion.type()) { 1.1736 + case ipc::OptionalKeyRange::TKeyRange: 1.1737 + keyRange = 1.1738 + IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); 1.1739 + break; 1.1740 + 1.1741 + case ipc::OptionalKeyRange::Tvoid_t: 1.1742 + break; 1.1743 + 1.1744 + default: 1.1745 + MOZ_CRASH("Unknown param type!"); 1.1746 + } 1.1747 + 1.1748 + nsRefPtr<IDBRequest> request; 1.1749 + 1.1750 + { 1.1751 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1752 + 1.1753 + ErrorResult rv; 1.1754 + request = mObjectStore->CountInternal(keyRange, rv); 1.1755 + ENSURE_SUCCESS(rv, false); 1.1756 + } 1.1757 + 1.1758 + request->SetActor(this); 1.1759 + mRequest.swap(request); 1.1760 + return true; 1.1761 +} 1.1762 + 1.1763 +bool 1.1764 +IndexedDBObjectStoreRequestParent::OpenCursor(const OpenCursorParams& aParams) 1.1765 +{ 1.1766 + MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams); 1.1767 + MOZ_ASSERT(mObjectStore); 1.1768 + 1.1769 + const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); 1.1770 + 1.1771 + nsRefPtr<IDBKeyRange> keyRange; 1.1772 + 1.1773 + switch (keyRangeUnion.type()) { 1.1774 + case ipc::OptionalKeyRange::TKeyRange: 1.1775 + keyRange = 1.1776 + IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); 1.1777 + break; 1.1778 + 1.1779 + case ipc::OptionalKeyRange::Tvoid_t: 1.1780 + break; 1.1781 + 1.1782 + default: 1.1783 + MOZ_CRASH("Unknown param type!"); 1.1784 + } 1.1785 + 1.1786 + size_t direction = static_cast<size_t>(aParams.direction()); 1.1787 + 1.1788 + nsRefPtr<IDBRequest> request; 1.1789 + 1.1790 + { 1.1791 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1792 + 1.1793 + ErrorResult rv; 1.1794 + request = mObjectStore->OpenCursorInternal(keyRange, direction, rv); 1.1795 + ENSURE_SUCCESS(rv, false); 1.1796 + } 1.1797 + 1.1798 + request->SetActor(this); 1.1799 + mRequest.swap(request); 1.1800 + return true; 1.1801 +} 1.1802 + 1.1803 +bool 1.1804 +IndexedDBObjectStoreRequestParent::OpenKeyCursor( 1.1805 + const OpenKeyCursorParams& aParams) 1.1806 +{ 1.1807 + MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenKeyCursorParams); 1.1808 + MOZ_ASSERT(mObjectStore); 1.1809 + 1.1810 + const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); 1.1811 + 1.1812 + nsRefPtr<IDBKeyRange> keyRange; 1.1813 + 1.1814 + switch (keyRangeUnion.type()) { 1.1815 + case ipc::OptionalKeyRange::TKeyRange: 1.1816 + keyRange = 1.1817 + IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); 1.1818 + break; 1.1819 + 1.1820 + case ipc::OptionalKeyRange::Tvoid_t: 1.1821 + break; 1.1822 + 1.1823 + default: 1.1824 + MOZ_CRASH("Unknown param type!"); 1.1825 + } 1.1826 + 1.1827 + size_t direction = static_cast<size_t>(aParams.direction()); 1.1828 + 1.1829 + nsRefPtr<IDBRequest> request; 1.1830 + 1.1831 + { 1.1832 + AutoSetCurrentTransaction asct(mObjectStore->Transaction()); 1.1833 + 1.1834 + ErrorResult rv; 1.1835 + request = mObjectStore->OpenKeyCursorInternal(keyRange, direction, rv); 1.1836 + ENSURE_SUCCESS(rv, false); 1.1837 + } 1.1838 + 1.1839 + request->SetActor(this); 1.1840 + mRequest.swap(request); 1.1841 + return true; 1.1842 +} 1.1843 + 1.1844 +/******************************************************************************* 1.1845 + * IndexedDBIndexRequestParent 1.1846 + ******************************************************************************/ 1.1847 + 1.1848 +IndexedDBIndexRequestParent::IndexedDBIndexRequestParent( 1.1849 + IDBIndex* aIndex, 1.1850 + RequestType aRequestType) 1.1851 +: mIndex(aIndex), mRequestType(aRequestType) 1.1852 +{ 1.1853 + MOZ_COUNT_CTOR(IndexedDBIndexRequestParent); 1.1854 + // Sadly can't assert aIndex here... 1.1855 + MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && 1.1856 + aRequestType <= ParamsUnionType::T__Last); 1.1857 +} 1.1858 + 1.1859 +IndexedDBIndexRequestParent::~IndexedDBIndexRequestParent() 1.1860 +{ 1.1861 + MOZ_COUNT_DTOR(IndexedDBIndexRequestParent); 1.1862 +} 1.1863 + 1.1864 +bool 1.1865 +IndexedDBIndexRequestParent::IsDisconnected() 1.1866 +{ 1.1867 + MOZ_ASSERT(mIndex); 1.1868 + MOZ_ASSERT(mIndex->GetActorParent()); 1.1869 + return mIndex->GetActorParent()->IsDisconnected(); 1.1870 +} 1.1871 + 1.1872 +bool 1.1873 +IndexedDBIndexRequestParent::Get(const GetParams& aParams) 1.1874 +{ 1.1875 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams); 1.1876 + MOZ_ASSERT(mIndex); 1.1877 + 1.1878 + nsRefPtr<IDBRequest> request; 1.1879 + 1.1880 + nsRefPtr<IDBKeyRange> keyRange = 1.1881 + IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); 1.1882 + MOZ_ASSERT(keyRange); 1.1883 + 1.1884 + { 1.1885 + AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); 1.1886 + 1.1887 + ErrorResult rv; 1.1888 + request = mIndex->GetInternal(keyRange, rv); 1.1889 + ENSURE_SUCCESS(rv, false); 1.1890 + } 1.1891 + 1.1892 + request->SetActor(this); 1.1893 + mRequest.swap(request); 1.1894 + return true; 1.1895 +} 1.1896 + 1.1897 +bool 1.1898 +IndexedDBIndexRequestParent::GetKey(const GetKeyParams& aParams) 1.1899 +{ 1.1900 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetKeyParams); 1.1901 + MOZ_ASSERT(mIndex); 1.1902 + 1.1903 + nsRefPtr<IDBRequest> request; 1.1904 + 1.1905 + nsRefPtr<IDBKeyRange> keyRange = 1.1906 + IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); 1.1907 + MOZ_ASSERT(keyRange); 1.1908 + 1.1909 + { 1.1910 + AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); 1.1911 + 1.1912 + ErrorResult rv; 1.1913 + request = mIndex->GetKeyInternal(keyRange, rv); 1.1914 + ENSURE_SUCCESS(rv, false); 1.1915 + } 1.1916 + 1.1917 + request->SetActor(this); 1.1918 + mRequest.swap(request); 1.1919 + return true; 1.1920 +} 1.1921 + 1.1922 +bool 1.1923 +IndexedDBIndexRequestParent::GetAll(const GetAllParams& aParams) 1.1924 +{ 1.1925 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams); 1.1926 + MOZ_ASSERT(mIndex); 1.1927 + 1.1928 + nsRefPtr<IDBRequest> request; 1.1929 + 1.1930 + const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); 1.1931 + 1.1932 + nsRefPtr<IDBKeyRange> keyRange; 1.1933 + 1.1934 + switch (keyRangeUnion.type()) { 1.1935 + case ipc::OptionalKeyRange::TKeyRange: 1.1936 + keyRange = 1.1937 + IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); 1.1938 + break; 1.1939 + 1.1940 + case ipc::OptionalKeyRange::Tvoid_t: 1.1941 + break; 1.1942 + 1.1943 + default: 1.1944 + MOZ_CRASH("Unknown param type!"); 1.1945 + } 1.1946 + 1.1947 + { 1.1948 + AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); 1.1949 + 1.1950 + ErrorResult rv; 1.1951 + request = mIndex->GetAllInternal(keyRange, aParams.limit(), rv); 1.1952 + ENSURE_SUCCESS(rv, false); 1.1953 + } 1.1954 + 1.1955 + request->SetActor(this); 1.1956 + mRequest.swap(request); 1.1957 + return true; 1.1958 +} 1.1959 + 1.1960 +bool 1.1961 +IndexedDBIndexRequestParent::GetAllKeys(const GetAllKeysParams& aParams) 1.1962 +{ 1.1963 + MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams); 1.1964 + MOZ_ASSERT(mIndex); 1.1965 + 1.1966 + nsRefPtr<IDBRequest> request; 1.1967 + 1.1968 + const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); 1.1969 + 1.1970 + nsRefPtr<IDBKeyRange> keyRange; 1.1971 + 1.1972 + switch (keyRangeUnion.type()) { 1.1973 + case ipc::OptionalKeyRange::TKeyRange: 1.1974 + keyRange = 1.1975 + IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); 1.1976 + break; 1.1977 + 1.1978 + case ipc::OptionalKeyRange::Tvoid_t: 1.1979 + break; 1.1980 + 1.1981 + default: 1.1982 + MOZ_CRASH("Unknown param type!"); 1.1983 + } 1.1984 + 1.1985 + { 1.1986 + AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); 1.1987 + 1.1988 + ErrorResult rv; 1.1989 + request = mIndex->GetAllKeysInternal(keyRange, aParams.limit(), rv); 1.1990 + ENSURE_SUCCESS(rv, false); 1.1991 + } 1.1992 + 1.1993 + request->SetActor(this); 1.1994 + mRequest.swap(request); 1.1995 + return true; 1.1996 +} 1.1997 + 1.1998 +bool 1.1999 +IndexedDBIndexRequestParent::Count(const CountParams& aParams) 1.2000 +{ 1.2001 + MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams); 1.2002 + MOZ_ASSERT(mIndex); 1.2003 + 1.2004 + const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); 1.2005 + 1.2006 + nsRefPtr<IDBKeyRange> keyRange; 1.2007 + 1.2008 + switch (keyRangeUnion.type()) { 1.2009 + case ipc::OptionalKeyRange::TKeyRange: 1.2010 + keyRange = 1.2011 + IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); 1.2012 + break; 1.2013 + 1.2014 + case ipc::OptionalKeyRange::Tvoid_t: 1.2015 + break; 1.2016 + 1.2017 + default: 1.2018 + MOZ_CRASH("Unknown param type!"); 1.2019 + } 1.2020 + 1.2021 + nsRefPtr<IDBRequest> request; 1.2022 + 1.2023 + { 1.2024 + AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); 1.2025 + 1.2026 + ErrorResult rv; 1.2027 + request = mIndex->CountInternal(keyRange, rv); 1.2028 + ENSURE_SUCCESS(rv, false); 1.2029 + } 1.2030 + 1.2031 + request->SetActor(this); 1.2032 + mRequest.swap(request); 1.2033 + return true; 1.2034 +} 1.2035 + 1.2036 +bool 1.2037 +IndexedDBIndexRequestParent::OpenCursor(const OpenCursorParams& aParams) 1.2038 +{ 1.2039 + MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams); 1.2040 + MOZ_ASSERT(mIndex); 1.2041 + 1.2042 + const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); 1.2043 + 1.2044 + nsRefPtr<IDBKeyRange> keyRange; 1.2045 + 1.2046 + switch (keyRangeUnion.type()) { 1.2047 + case ipc::OptionalKeyRange::TKeyRange: 1.2048 + keyRange = 1.2049 + IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); 1.2050 + break; 1.2051 + 1.2052 + case ipc::OptionalKeyRange::Tvoid_t: 1.2053 + break; 1.2054 + 1.2055 + default: 1.2056 + MOZ_CRASH("Unknown param type!"); 1.2057 + } 1.2058 + 1.2059 + size_t direction = static_cast<size_t>(aParams.direction()); 1.2060 + 1.2061 + nsRefPtr<IDBRequest> request; 1.2062 + 1.2063 + { 1.2064 + AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); 1.2065 + 1.2066 + nsresult rv = 1.2067 + mIndex->OpenCursorInternal(keyRange, direction, getter_AddRefs(request)); 1.2068 + NS_ENSURE_SUCCESS(rv, false); 1.2069 + } 1.2070 + 1.2071 + request->SetActor(this); 1.2072 + mRequest.swap(request); 1.2073 + return true; 1.2074 +} 1.2075 + 1.2076 +bool 1.2077 +IndexedDBIndexRequestParent::OpenKeyCursor(const OpenKeyCursorParams& aParams) 1.2078 +{ 1.2079 + MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenKeyCursorParams); 1.2080 + MOZ_ASSERT(mIndex); 1.2081 + 1.2082 + const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); 1.2083 + 1.2084 + nsRefPtr<IDBKeyRange> keyRange; 1.2085 + 1.2086 + switch (keyRangeUnion.type()) { 1.2087 + case ipc::OptionalKeyRange::TKeyRange: 1.2088 + keyRange = 1.2089 + IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); 1.2090 + break; 1.2091 + 1.2092 + case ipc::OptionalKeyRange::Tvoid_t: 1.2093 + break; 1.2094 + 1.2095 + default: 1.2096 + MOZ_CRASH("Unknown param type!"); 1.2097 + } 1.2098 + 1.2099 + size_t direction = static_cast<size_t>(aParams.direction()); 1.2100 + 1.2101 + nsRefPtr<IDBRequest> request; 1.2102 + 1.2103 + { 1.2104 + AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); 1.2105 + 1.2106 + ErrorResult rv; 1.2107 + request = mIndex->OpenKeyCursorInternal(keyRange, direction, rv); 1.2108 + ENSURE_SUCCESS(rv, false); 1.2109 + } 1.2110 + 1.2111 + request->SetActor(this); 1.2112 + mRequest.swap(request); 1.2113 + return true; 1.2114 +} 1.2115 + 1.2116 +/******************************************************************************* 1.2117 + * IndexedDBCursorRequestParent 1.2118 + ******************************************************************************/ 1.2119 + 1.2120 +IndexedDBCursorRequestParent::IndexedDBCursorRequestParent( 1.2121 + IDBCursor* aCursor, 1.2122 + RequestType aRequestType) 1.2123 +: mCursor(aCursor), mRequestType(aRequestType) 1.2124 +{ 1.2125 + MOZ_COUNT_CTOR(IndexedDBCursorRequestParent); 1.2126 + MOZ_ASSERT(aCursor); 1.2127 + MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && 1.2128 + aRequestType <= ParamsUnionType::T__Last); 1.2129 +} 1.2130 + 1.2131 +IndexedDBCursorRequestParent::~IndexedDBCursorRequestParent() 1.2132 +{ 1.2133 + MOZ_COUNT_DTOR(IndexedDBCursorRequestParent); 1.2134 +} 1.2135 + 1.2136 +bool 1.2137 +IndexedDBCursorRequestParent::IsDisconnected() 1.2138 +{ 1.2139 + MOZ_ASSERT(mCursor); 1.2140 + MOZ_ASSERT(mCursor->GetActorParent()); 1.2141 + return mCursor->GetActorParent()->IsDisconnected(); 1.2142 +} 1.2143 + 1.2144 +bool 1.2145 +IndexedDBCursorRequestParent::Continue(const ContinueParams& aParams) 1.2146 +{ 1.2147 + MOZ_ASSERT(mCursor); 1.2148 + MOZ_ASSERT(mRequestType == ParamsUnionType::TContinueParams); 1.2149 + 1.2150 + { 1.2151 + AutoSetCurrentTransaction asct(mCursor->Transaction()); 1.2152 + 1.2153 + ErrorResult rv; 1.2154 + mCursor->ContinueInternal(aParams.key(), aParams.count(), rv); 1.2155 + ENSURE_SUCCESS(rv, false); 1.2156 + } 1.2157 + 1.2158 + mRequest = mCursor->Request(); 1.2159 + MOZ_ASSERT(mRequest); 1.2160 + 1.2161 + mRequest->SetActor(this); 1.2162 + return true; 1.2163 +} 1.2164 + 1.2165 +/******************************************************************************* 1.2166 + * IndexedDBDeleteDatabaseRequestParent 1.2167 + ******************************************************************************/ 1.2168 + 1.2169 +IndexedDBDeleteDatabaseRequestParent::IndexedDBDeleteDatabaseRequestParent( 1.2170 + IDBFactory* aFactory) 1.2171 +: mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()), mFactory(aFactory) 1.2172 +{ 1.2173 + MOZ_COUNT_CTOR(IndexedDBDeleteDatabaseRequestParent); 1.2174 + MOZ_ASSERT(aFactory); 1.2175 +} 1.2176 + 1.2177 +IndexedDBDeleteDatabaseRequestParent::~IndexedDBDeleteDatabaseRequestParent() 1.2178 +{ 1.2179 + MOZ_COUNT_DTOR(IndexedDBDeleteDatabaseRequestParent); 1.2180 +} 1.2181 + 1.2182 +nsresult 1.2183 +IndexedDBDeleteDatabaseRequestParent::HandleEvent(nsIDOMEvent* aEvent) 1.2184 +{ 1.2185 + MOZ_ASSERT(aEvent); 1.2186 + 1.2187 + if (IsDisconnected()) { 1.2188 + // We're shutting down, ignore this event. 1.2189 + return NS_OK; 1.2190 + } 1.2191 + 1.2192 + nsString type; 1.2193 + nsresult rv = aEvent->GetType(type); 1.2194 + NS_ENSURE_SUCCESS(rv, rv); 1.2195 + 1.2196 + if (type.EqualsASCII(BLOCKED_EVT_STR)) { 1.2197 + nsCOMPtr<IDBVersionChangeEvent> event = do_QueryInterface(aEvent); 1.2198 + MOZ_ASSERT(event); 1.2199 + 1.2200 + uint64_t currentVersion = event->OldVersion(); 1.2201 + 1.2202 + if (!SendBlocked(currentVersion)) { 1.2203 + return NS_ERROR_FAILURE; 1.2204 + } 1.2205 + 1.2206 + return NS_OK; 1.2207 + } 1.2208 + 1.2209 +#ifdef DEBUG 1.2210 + if (type.EqualsASCII(SUCCESS_EVT_STR)) { 1.2211 + MOZ_ASSERT(NS_SUCCEEDED(mOpenRequest->GetErrorCode())); 1.2212 + } 1.2213 + else { 1.2214 + MOZ_ASSERT(type.EqualsASCII(ERROR_EVT_STR)); 1.2215 + MOZ_ASSERT(NS_FAILED(mOpenRequest->GetErrorCode())); 1.2216 + } 1.2217 +#endif 1.2218 + 1.2219 + if (!Send__delete__(this, mOpenRequest->GetErrorCode())) { 1.2220 + return NS_ERROR_FAILURE; 1.2221 + } 1.2222 + 1.2223 + return NS_OK; 1.2224 +} 1.2225 + 1.2226 +nsresult 1.2227 +IndexedDBDeleteDatabaseRequestParent::SetOpenRequest( 1.2228 + IDBOpenDBRequest* aOpenRequest) 1.2229 +{ 1.2230 + MOZ_ASSERT(aOpenRequest); 1.2231 + MOZ_ASSERT(!mOpenRequest); 1.2232 + 1.2233 + EventTarget* target = static_cast<EventTarget*>(aOpenRequest); 1.2234 + 1.2235 + nsresult rv = target->AddEventListener(NS_LITERAL_STRING(SUCCESS_EVT_STR), 1.2236 + mEventListener, false); 1.2237 + NS_ENSURE_SUCCESS(rv, rv); 1.2238 + 1.2239 + rv = target->AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR), 1.2240 + mEventListener, false); 1.2241 + NS_ENSURE_SUCCESS(rv, rv); 1.2242 + 1.2243 + rv = target->AddEventListener(NS_LITERAL_STRING(BLOCKED_EVT_STR), 1.2244 + mEventListener, false); 1.2245 + NS_ENSURE_SUCCESS(rv, rv); 1.2246 + 1.2247 + mOpenRequest = aOpenRequest; 1.2248 + return NS_OK; 1.2249 +} 1.2250 + 1.2251 +/******************************************************************************* 1.2252 + * WeakEventListener 1.2253 + ******************************************************************************/ 1.2254 + 1.2255 + NS_IMPL_ISUPPORTS(WeakEventListenerBase, nsIDOMEventListener) 1.2256 + 1.2257 + NS_IMETHODIMP 1.2258 + WeakEventListenerBase::HandleEvent(nsIDOMEvent* aEvent) 1.2259 +{ 1.2260 + MOZ_CRASH("This must be overridden!"); 1.2261 +}