Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | |
michael@0 | 6 | #include "IndexedDBParent.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIDOMEvent.h" |
michael@0 | 9 | #include "nsIDOMFile.h" |
michael@0 | 10 | #include "nsIXPConnect.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "mozilla/AppProcessChecker.h" |
michael@0 | 13 | #include "mozilla/Assertions.h" |
michael@0 | 14 | #include "mozilla/Attributes.h" |
michael@0 | 15 | #include "mozilla/dom/ContentParent.h" |
michael@0 | 16 | #include "mozilla/dom/IDBDatabaseBinding.h" |
michael@0 | 17 | #include "mozilla/dom/ipc/Blob.h" |
michael@0 | 18 | #include "mozilla/dom/TabParent.h" |
michael@0 | 19 | #include "mozilla/unused.h" |
michael@0 | 20 | #include "nsCxPusher.h" |
michael@0 | 21 | |
michael@0 | 22 | #include "AsyncConnectionHelper.h" |
michael@0 | 23 | #include "DatabaseInfo.h" |
michael@0 | 24 | #include "IDBDatabase.h" |
michael@0 | 25 | #include "IDBEvents.h" |
michael@0 | 26 | #include "IDBFactory.h" |
michael@0 | 27 | #include "IDBIndex.h" |
michael@0 | 28 | #include "IDBKeyRange.h" |
michael@0 | 29 | #include "IDBObjectStore.h" |
michael@0 | 30 | #include "IDBTransaction.h" |
michael@0 | 31 | |
michael@0 | 32 | #define CHROME_ORIGIN "chrome" |
michael@0 | 33 | #define PERMISSION_PREFIX "indexedDB-chrome-" |
michael@0 | 34 | #define PERMISSION_SUFFIX_READ "-read" |
michael@0 | 35 | #define PERMISSION_SUFFIX_WRITE "-write" |
michael@0 | 36 | |
michael@0 | 37 | USING_INDEXEDDB_NAMESPACE |
michael@0 | 38 | |
michael@0 | 39 | using namespace mozilla; |
michael@0 | 40 | using namespace mozilla::dom; |
michael@0 | 41 | |
michael@0 | 42 | /******************************************************************************* |
michael@0 | 43 | * AutoSetCurrentTransaction |
michael@0 | 44 | ******************************************************************************/ |
michael@0 | 45 | |
michael@0 | 46 | AutoSetCurrentTransaction::AutoSetCurrentTransaction( |
michael@0 | 47 | IDBTransaction* aTransaction) |
michael@0 | 48 | { |
michael@0 | 49 | MOZ_ASSERT(aTransaction); |
michael@0 | 50 | AsyncConnectionHelper::SetCurrentTransaction(aTransaction); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | AutoSetCurrentTransaction::~AutoSetCurrentTransaction() |
michael@0 | 54 | { |
michael@0 | 55 | AsyncConnectionHelper::SetCurrentTransaction(nullptr); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | /******************************************************************************* |
michael@0 | 59 | * IndexedDBParent |
michael@0 | 60 | ******************************************************************************/ |
michael@0 | 61 | |
michael@0 | 62 | IndexedDBParent::IndexedDBParent(ContentParent* aContentParent) |
michael@0 | 63 | : mManagerContent(aContentParent), mManagerTab(nullptr), mDisconnected(false) |
michael@0 | 64 | { |
michael@0 | 65 | MOZ_COUNT_CTOR(IndexedDBParent); |
michael@0 | 66 | MOZ_ASSERT(aContentParent); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | IndexedDBParent::IndexedDBParent(TabParent* aTabParent) |
michael@0 | 70 | : mManagerContent(nullptr), mManagerTab(aTabParent), mDisconnected(false) |
michael@0 | 71 | { |
michael@0 | 72 | MOZ_COUNT_CTOR(IndexedDBParent); |
michael@0 | 73 | MOZ_ASSERT(aTabParent); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | IndexedDBParent::~IndexedDBParent() |
michael@0 | 77 | { |
michael@0 | 78 | MOZ_COUNT_DTOR(IndexedDBParent); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | void |
michael@0 | 82 | IndexedDBParent::Disconnect() |
michael@0 | 83 | { |
michael@0 | 84 | if (mDisconnected) { |
michael@0 | 85 | return; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | mDisconnected = true; |
michael@0 | 89 | |
michael@0 | 90 | const InfallibleTArray<PIndexedDBDatabaseParent*>& databases = |
michael@0 | 91 | ManagedPIndexedDBDatabaseParent(); |
michael@0 | 92 | for (uint32_t i = 0; i < databases.Length(); ++i) { |
michael@0 | 93 | static_cast<IndexedDBDatabaseParent*>(databases[i])->Disconnect(); |
michael@0 | 94 | } |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | bool |
michael@0 | 98 | IndexedDBParent::CheckReadPermission(const nsAString& aDatabaseName) |
michael@0 | 99 | { |
michael@0 | 100 | NS_NAMED_LITERAL_CSTRING(permission, PERMISSION_SUFFIX_READ); |
michael@0 | 101 | return CheckPermissionInternal(aDatabaseName, permission); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | bool |
michael@0 | 105 | IndexedDBParent::CheckWritePermission(const nsAString& aDatabaseName) |
michael@0 | 106 | { |
michael@0 | 107 | // Write permission assumes read permission is granted as well. |
michael@0 | 108 | MOZ_ASSERT(CheckReadPermission(aDatabaseName)); |
michael@0 | 109 | |
michael@0 | 110 | NS_NAMED_LITERAL_CSTRING(permission, PERMISSION_SUFFIX_WRITE); |
michael@0 | 111 | return CheckPermissionInternal(aDatabaseName, permission); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | mozilla::ipc::IProtocol* |
michael@0 | 115 | IndexedDBParent::CloneProtocol(Channel* aChannel, |
michael@0 | 116 | mozilla::ipc::ProtocolCloneContext* aCtx) |
michael@0 | 117 | { |
michael@0 | 118 | MOZ_ASSERT(mManagerContent != nullptr); |
michael@0 | 119 | MOZ_ASSERT(mManagerTab == nullptr); |
michael@0 | 120 | MOZ_ASSERT(!mDisconnected); |
michael@0 | 121 | MOZ_ASSERT(IndexedDatabaseManager::Get()); |
michael@0 | 122 | MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess()); |
michael@0 | 123 | |
michael@0 | 124 | ContentParent* contentParent = aCtx->GetContentParent(); |
michael@0 | 125 | nsAutoPtr<PIndexedDBParent> actor(contentParent->AllocPIndexedDBParent()); |
michael@0 | 126 | if (!actor || !contentParent->RecvPIndexedDBConstructor(actor)) { |
michael@0 | 127 | return nullptr; |
michael@0 | 128 | } |
michael@0 | 129 | return actor.forget(); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | bool |
michael@0 | 133 | IndexedDBParent::CheckPermissionInternal(const nsAString& aDatabaseName, |
michael@0 | 134 | const nsACString& aPermission) |
michael@0 | 135 | { |
michael@0 | 136 | MOZ_ASSERT(!mASCIIOrigin.IsEmpty()); |
michael@0 | 137 | MOZ_ASSERT(mManagerContent || mManagerTab); |
michael@0 | 138 | |
michael@0 | 139 | if (mASCIIOrigin.EqualsLiteral(CHROME_ORIGIN)) { |
michael@0 | 140 | nsAutoCString fullPermission = |
michael@0 | 141 | NS_LITERAL_CSTRING(PERMISSION_PREFIX) + |
michael@0 | 142 | NS_ConvertUTF16toUTF8(aDatabaseName) + |
michael@0 | 143 | aPermission; |
michael@0 | 144 | |
michael@0 | 145 | if ((mManagerContent && |
michael@0 | 146 | !AssertAppProcessPermission(mManagerContent, fullPermission.get())) || |
michael@0 | 147 | (mManagerTab && |
michael@0 | 148 | !AssertAppProcessPermission(mManagerTab, fullPermission.get()))) { |
michael@0 | 149 | return false; |
michael@0 | 150 | } |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | return true; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | void |
michael@0 | 157 | IndexedDBParent::ActorDestroy(ActorDestroyReason aWhy) |
michael@0 | 158 | { |
michael@0 | 159 | // Nothing really needs to be done here... |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | bool |
michael@0 | 163 | IndexedDBParent::RecvPIndexedDBDatabaseConstructor( |
michael@0 | 164 | PIndexedDBDatabaseParent* aActor, |
michael@0 | 165 | const nsString& aName, |
michael@0 | 166 | const uint64_t& aVersion, |
michael@0 | 167 | const PersistenceType& aPersistenceType) |
michael@0 | 168 | { |
michael@0 | 169 | if (!CheckReadPermission(aName)) { |
michael@0 | 170 | return false; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | if (IsDisconnected()) { |
michael@0 | 174 | // We're shutting down, ignore this request. |
michael@0 | 175 | return true; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | if (!mFactory) { |
michael@0 | 179 | return true; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | nsRefPtr<IDBOpenDBRequest> request; |
michael@0 | 183 | nsresult rv = mFactory->OpenInternal(aName, aVersion, aPersistenceType, false, |
michael@0 | 184 | getter_AddRefs(request)); |
michael@0 | 185 | NS_ENSURE_SUCCESS(rv, false); |
michael@0 | 186 | |
michael@0 | 187 | IndexedDBDatabaseParent* actor = |
michael@0 | 188 | static_cast<IndexedDBDatabaseParent*>(aActor); |
michael@0 | 189 | |
michael@0 | 190 | rv = actor->SetOpenRequest(request); |
michael@0 | 191 | NS_ENSURE_SUCCESS(rv, false); |
michael@0 | 192 | |
michael@0 | 193 | return true; |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | bool |
michael@0 | 197 | IndexedDBParent::RecvPIndexedDBDeleteDatabaseRequestConstructor( |
michael@0 | 198 | PIndexedDBDeleteDatabaseRequestParent* aActor, |
michael@0 | 199 | const nsString& aName, |
michael@0 | 200 | const PersistenceType& aPersistenceType) |
michael@0 | 201 | { |
michael@0 | 202 | if (!CheckWritePermission(aName)) { |
michael@0 | 203 | return false; |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | if (IsDisconnected()) { |
michael@0 | 207 | // We're shutting down, ignore this request. |
michael@0 | 208 | return true; |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | if (!mFactory) { |
michael@0 | 212 | return true; |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | IndexedDBDeleteDatabaseRequestParent* actor = |
michael@0 | 216 | static_cast<IndexedDBDeleteDatabaseRequestParent*>(aActor); |
michael@0 | 217 | |
michael@0 | 218 | nsRefPtr<IDBOpenDBRequest> request; |
michael@0 | 219 | |
michael@0 | 220 | nsresult rv = mFactory->OpenInternal(aName, 0, aPersistenceType, true, |
michael@0 | 221 | getter_AddRefs(request)); |
michael@0 | 222 | NS_ENSURE_SUCCESS(rv, false); |
michael@0 | 223 | |
michael@0 | 224 | rv = actor->SetOpenRequest(request); |
michael@0 | 225 | NS_ENSURE_SUCCESS(rv, false); |
michael@0 | 226 | |
michael@0 | 227 | return true; |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | PIndexedDBDatabaseParent* |
michael@0 | 231 | IndexedDBParent::AllocPIndexedDBDatabaseParent( |
michael@0 | 232 | const nsString& aName, |
michael@0 | 233 | const uint64_t& aVersion, |
michael@0 | 234 | const PersistenceType& aPersistenceType) |
michael@0 | 235 | { |
michael@0 | 236 | return new IndexedDBDatabaseParent(); |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | bool |
michael@0 | 240 | IndexedDBParent::DeallocPIndexedDBDatabaseParent(PIndexedDBDatabaseParent* aActor) |
michael@0 | 241 | { |
michael@0 | 242 | delete aActor; |
michael@0 | 243 | return true; |
michael@0 | 244 | } |
michael@0 | 245 | |
michael@0 | 246 | PIndexedDBDeleteDatabaseRequestParent* |
michael@0 | 247 | IndexedDBParent::AllocPIndexedDBDeleteDatabaseRequestParent( |
michael@0 | 248 | const nsString& aName, |
michael@0 | 249 | const PersistenceType& aPersistenceType) |
michael@0 | 250 | { |
michael@0 | 251 | return new IndexedDBDeleteDatabaseRequestParent(mFactory); |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | bool |
michael@0 | 255 | IndexedDBParent::DeallocPIndexedDBDeleteDatabaseRequestParent( |
michael@0 | 256 | PIndexedDBDeleteDatabaseRequestParent* aActor) |
michael@0 | 257 | { |
michael@0 | 258 | delete aActor; |
michael@0 | 259 | return true; |
michael@0 | 260 | } |
michael@0 | 261 | |
michael@0 | 262 | /******************************************************************************* |
michael@0 | 263 | * IndexedDBDatabaseParent |
michael@0 | 264 | ******************************************************************************/ |
michael@0 | 265 | |
michael@0 | 266 | IndexedDBDatabaseParent::IndexedDBDatabaseParent() |
michael@0 | 267 | : mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()) |
michael@0 | 268 | { |
michael@0 | 269 | MOZ_COUNT_CTOR(IndexedDBDatabaseParent); |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | IndexedDBDatabaseParent::~IndexedDBDatabaseParent() |
michael@0 | 273 | { |
michael@0 | 274 | MOZ_COUNT_DTOR(IndexedDBDatabaseParent); |
michael@0 | 275 | } |
michael@0 | 276 | |
michael@0 | 277 | nsresult |
michael@0 | 278 | IndexedDBDatabaseParent::SetOpenRequest(IDBOpenDBRequest* aRequest) |
michael@0 | 279 | { |
michael@0 | 280 | MOZ_ASSERT(aRequest); |
michael@0 | 281 | MOZ_ASSERT(!mOpenRequest); |
michael@0 | 282 | |
michael@0 | 283 | nsresult rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(SUCCESS_EVT_STR), |
michael@0 | 284 | mEventListener, false); |
michael@0 | 285 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 286 | |
michael@0 | 287 | rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR), |
michael@0 | 288 | mEventListener, false); |
michael@0 | 289 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 290 | |
michael@0 | 291 | rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(BLOCKED_EVT_STR), |
michael@0 | 292 | mEventListener, false); |
michael@0 | 293 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 294 | |
michael@0 | 295 | rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(UPGRADENEEDED_EVT_STR), |
michael@0 | 296 | mEventListener, false); |
michael@0 | 297 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 298 | |
michael@0 | 299 | mOpenRequest = aRequest; |
michael@0 | 300 | return NS_OK; |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | nsresult |
michael@0 | 304 | IndexedDBDatabaseParent::HandleEvent(nsIDOMEvent* aEvent) |
michael@0 | 305 | { |
michael@0 | 306 | MOZ_ASSERT(aEvent); |
michael@0 | 307 | |
michael@0 | 308 | if (IsDisconnected()) { |
michael@0 | 309 | // We're shutting down, ignore this event. |
michael@0 | 310 | return NS_OK; |
michael@0 | 311 | } |
michael@0 | 312 | |
michael@0 | 313 | nsString type; |
michael@0 | 314 | nsresult rv = aEvent->GetType(type); |
michael@0 | 315 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 316 | |
michael@0 | 317 | nsCOMPtr<EventTarget> target = aEvent->InternalDOMEvent()->GetTarget(); |
michael@0 | 318 | |
michael@0 | 319 | if (mDatabase && |
michael@0 | 320 | SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*, |
michael@0 | 321 | mDatabase))) { |
michael@0 | 322 | rv = HandleDatabaseEvent(aEvent, type); |
michael@0 | 323 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 324 | |
michael@0 | 325 | return NS_OK; |
michael@0 | 326 | } |
michael@0 | 327 | |
michael@0 | 328 | if (mOpenRequest && |
michael@0 | 329 | SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*, |
michael@0 | 330 | mOpenRequest))) { |
michael@0 | 331 | rv = HandleRequestEvent(aEvent, type); |
michael@0 | 332 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 333 | |
michael@0 | 334 | return NS_OK; |
michael@0 | 335 | } |
michael@0 | 336 | |
michael@0 | 337 | MOZ_CRASH("Unexpected message!"); |
michael@0 | 338 | } |
michael@0 | 339 | |
michael@0 | 340 | void |
michael@0 | 341 | IndexedDBDatabaseParent::Disconnect() |
michael@0 | 342 | { |
michael@0 | 343 | if (mDatabase) { |
michael@0 | 344 | mDatabase->DisconnectFromActorParent(); |
michael@0 | 345 | } |
michael@0 | 346 | } |
michael@0 | 347 | |
michael@0 | 348 | bool |
michael@0 | 349 | IndexedDBDatabaseParent::CheckWritePermission(const nsAString& aDatabaseName) |
michael@0 | 350 | { |
michael@0 | 351 | IndexedDBParent* manager = static_cast<IndexedDBParent*>(Manager()); |
michael@0 | 352 | MOZ_ASSERT(manager); |
michael@0 | 353 | |
michael@0 | 354 | return manager->CheckWritePermission(aDatabaseName); |
michael@0 | 355 | } |
michael@0 | 356 | |
michael@0 | 357 | void |
michael@0 | 358 | IndexedDBDatabaseParent::Invalidate() |
michael@0 | 359 | { |
michael@0 | 360 | MOZ_ASSERT(mDatabase); |
michael@0 | 361 | |
michael@0 | 362 | if (!IsDisconnected()) { |
michael@0 | 363 | mozilla::unused << SendInvalidate(); |
michael@0 | 364 | } |
michael@0 | 365 | } |
michael@0 | 366 | |
michael@0 | 367 | nsresult |
michael@0 | 368 | IndexedDBDatabaseParent::HandleRequestEvent(nsIDOMEvent* aEvent, |
michael@0 | 369 | const nsAString& aType) |
michael@0 | 370 | { |
michael@0 | 371 | MOZ_ASSERT(mOpenRequest); |
michael@0 | 372 | MOZ_ASSERT(!IsDisconnected()); |
michael@0 | 373 | |
michael@0 | 374 | nsresult rv; |
michael@0 | 375 | |
michael@0 | 376 | if (aType.EqualsLiteral(ERROR_EVT_STR)) { |
michael@0 | 377 | nsRefPtr<IDBOpenDBRequest> request; |
michael@0 | 378 | mOpenRequest.swap(request); |
michael@0 | 379 | |
michael@0 | 380 | rv = request->GetErrorCode(); |
michael@0 | 381 | MOZ_ASSERT(NS_FAILED(rv)); |
michael@0 | 382 | |
michael@0 | 383 | if (!SendError(rv)) { |
michael@0 | 384 | return NS_ERROR_FAILURE; |
michael@0 | 385 | } |
michael@0 | 386 | |
michael@0 | 387 | rv = aEvent->PreventDefault(); |
michael@0 | 388 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 389 | |
michael@0 | 390 | return NS_OK; |
michael@0 | 391 | } |
michael@0 | 392 | |
michael@0 | 393 | if (aType.EqualsLiteral(BLOCKED_EVT_STR)) { |
michael@0 | 394 | MOZ_ASSERT(!mDatabase); |
michael@0 | 395 | |
michael@0 | 396 | nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent); |
michael@0 | 397 | NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE); |
michael@0 | 398 | |
michael@0 | 399 | uint64_t oldVersion = changeEvent->OldVersion(); |
michael@0 | 400 | |
michael@0 | 401 | if (!SendBlocked(oldVersion)) { |
michael@0 | 402 | return NS_ERROR_FAILURE; |
michael@0 | 403 | } |
michael@0 | 404 | |
michael@0 | 405 | return NS_OK; |
michael@0 | 406 | } |
michael@0 | 407 | |
michael@0 | 408 | AutoSafeJSContext cx; |
michael@0 | 409 | |
michael@0 | 410 | ErrorResult error; |
michael@0 | 411 | JS::Rooted<JS::Value> result(cx); |
michael@0 | 412 | mOpenRequest->GetResult(cx, &result, error); |
michael@0 | 413 | ENSURE_SUCCESS(error, error.ErrorCode()); |
michael@0 | 414 | |
michael@0 | 415 | MOZ_ASSERT(!JSVAL_IS_PRIMITIVE(result)); |
michael@0 | 416 | |
michael@0 | 417 | IDBDatabase *database; |
michael@0 | 418 | rv = UNWRAP_OBJECT(IDBDatabase, &result.toObject(), database); |
michael@0 | 419 | if (NS_FAILED(rv)) { |
michael@0 | 420 | NS_WARNING("Didn't get the object we expected!"); |
michael@0 | 421 | return rv; |
michael@0 | 422 | } |
michael@0 | 423 | |
michael@0 | 424 | DatabaseInfo* dbInfo = database->Info(); |
michael@0 | 425 | MOZ_ASSERT(dbInfo); |
michael@0 | 426 | |
michael@0 | 427 | nsAutoTArray<nsString, 20> objectStoreNames; |
michael@0 | 428 | if (!dbInfo->GetObjectStoreNames(objectStoreNames)) { |
michael@0 | 429 | MOZ_CRASH("This should never fail!"); |
michael@0 | 430 | } |
michael@0 | 431 | |
michael@0 | 432 | InfallibleTArray<ObjectStoreInfoGuts> objectStoreInfos; |
michael@0 | 433 | if (!objectStoreNames.IsEmpty()) { |
michael@0 | 434 | uint32_t length = objectStoreNames.Length(); |
michael@0 | 435 | |
michael@0 | 436 | objectStoreInfos.SetCapacity(length); |
michael@0 | 437 | |
michael@0 | 438 | for (uint32_t i = 0; i < length; i++) { |
michael@0 | 439 | ObjectStoreInfo* osInfo = dbInfo->GetObjectStore(objectStoreNames[i]); |
michael@0 | 440 | MOZ_ASSERT(osInfo); |
michael@0 | 441 | |
michael@0 | 442 | objectStoreInfos.AppendElement(*osInfo); |
michael@0 | 443 | } |
michael@0 | 444 | } |
michael@0 | 445 | |
michael@0 | 446 | if (aType.EqualsLiteral(SUCCESS_EVT_STR)) { |
michael@0 | 447 | nsRefPtr<IDBOpenDBRequest> request; |
michael@0 | 448 | mOpenRequest.swap(request); |
michael@0 | 449 | |
michael@0 | 450 | EventTarget* target = static_cast<EventTarget*>(database); |
michael@0 | 451 | |
michael@0 | 452 | #ifdef DEBUG |
michael@0 | 453 | { |
michael@0 | 454 | nsresult rvDEBUG = |
michael@0 | 455 | target->AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR), |
michael@0 | 456 | mEventListener, false); |
michael@0 | 457 | NS_WARN_IF_FALSE(NS_SUCCEEDED(rvDEBUG), "Failed to add error listener!"); |
michael@0 | 458 | } |
michael@0 | 459 | #endif |
michael@0 | 460 | |
michael@0 | 461 | NS_NAMED_LITERAL_STRING(versionChange, VERSIONCHANGE_EVT_STR); |
michael@0 | 462 | rv = target->AddEventListener(versionChange, mEventListener, false); |
michael@0 | 463 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 464 | |
michael@0 | 465 | if (!SendSuccess(*dbInfo, objectStoreInfos)) { |
michael@0 | 466 | return NS_ERROR_FAILURE; |
michael@0 | 467 | } |
michael@0 | 468 | |
michael@0 | 469 | MOZ_ASSERT(!mDatabase || mDatabase == database); |
michael@0 | 470 | |
michael@0 | 471 | if (!mDatabase) { |
michael@0 | 472 | database->SetActor(this); |
michael@0 | 473 | mDatabase = database; |
michael@0 | 474 | } |
michael@0 | 475 | |
michael@0 | 476 | return NS_OK; |
michael@0 | 477 | } |
michael@0 | 478 | |
michael@0 | 479 | if (aType.EqualsLiteral(UPGRADENEEDED_EVT_STR)) { |
michael@0 | 480 | MOZ_ASSERT(!mDatabase); |
michael@0 | 481 | |
michael@0 | 482 | IDBTransaction* transaction = |
michael@0 | 483 | AsyncConnectionHelper::GetCurrentTransaction(); |
michael@0 | 484 | MOZ_ASSERT(transaction); |
michael@0 | 485 | |
michael@0 | 486 | if (!CheckWritePermission(database->Name())) { |
michael@0 | 487 | // If we get here then the child process is either dead or in the process |
michael@0 | 488 | // of being killed. Abort the transaction now to prevent any changes to |
michael@0 | 489 | // the database. |
michael@0 | 490 | ErrorResult rv; |
michael@0 | 491 | transaction->Abort(rv); |
michael@0 | 492 | if (rv.Failed()) { |
michael@0 | 493 | NS_WARNING("Failed to abort transaction!"); |
michael@0 | 494 | } |
michael@0 | 495 | return NS_ERROR_FAILURE; |
michael@0 | 496 | } |
michael@0 | 497 | |
michael@0 | 498 | nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent); |
michael@0 | 499 | NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE); |
michael@0 | 500 | |
michael@0 | 501 | uint64_t oldVersion = changeEvent->OldVersion(); |
michael@0 | 502 | |
michael@0 | 503 | nsAutoPtr<IndexedDBVersionChangeTransactionParent> actor( |
michael@0 | 504 | new IndexedDBVersionChangeTransactionParent()); |
michael@0 | 505 | |
michael@0 | 506 | rv = actor->SetTransaction(transaction); |
michael@0 | 507 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 508 | |
michael@0 | 509 | VersionChangeTransactionParams versionChangeParams; |
michael@0 | 510 | versionChangeParams.dbInfo() = *dbInfo; |
michael@0 | 511 | versionChangeParams.osInfo() = objectStoreInfos; |
michael@0 | 512 | versionChangeParams.oldVersion() = oldVersion; |
michael@0 | 513 | |
michael@0 | 514 | if (!SendPIndexedDBTransactionConstructor(actor.forget(), |
michael@0 | 515 | versionChangeParams)) { |
michael@0 | 516 | return NS_ERROR_FAILURE; |
michael@0 | 517 | } |
michael@0 | 518 | |
michael@0 | 519 | database->SetActor(this); |
michael@0 | 520 | mDatabase = database; |
michael@0 | 521 | |
michael@0 | 522 | return NS_OK; |
michael@0 | 523 | } |
michael@0 | 524 | |
michael@0 | 525 | MOZ_CRASH("Unexpected message type!"); |
michael@0 | 526 | } |
michael@0 | 527 | |
michael@0 | 528 | nsresult |
michael@0 | 529 | IndexedDBDatabaseParent::HandleDatabaseEvent(nsIDOMEvent* aEvent, |
michael@0 | 530 | const nsAString& aType) |
michael@0 | 531 | { |
michael@0 | 532 | MOZ_ASSERT(mDatabase); |
michael@0 | 533 | MOZ_ASSERT(!aType.EqualsLiteral(ERROR_EVT_STR), |
michael@0 | 534 | "Should never get error events in the parent process!"); |
michael@0 | 535 | MOZ_ASSERT(!IsDisconnected()); |
michael@0 | 536 | |
michael@0 | 537 | if (aType.EqualsLiteral(VERSIONCHANGE_EVT_STR)) { |
michael@0 | 538 | AutoSafeJSContext cx; |
michael@0 | 539 | NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE); |
michael@0 | 540 | |
michael@0 | 541 | nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent); |
michael@0 | 542 | NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE); |
michael@0 | 543 | |
michael@0 | 544 | uint64_t oldVersion = changeEvent->OldVersion(); |
michael@0 | 545 | |
michael@0 | 546 | Nullable<uint64_t> newVersionVal = changeEvent->GetNewVersion(); |
michael@0 | 547 | |
michael@0 | 548 | uint64_t newVersion; |
michael@0 | 549 | if (newVersionVal.IsNull()) { |
michael@0 | 550 | newVersion = 0; |
michael@0 | 551 | } |
michael@0 | 552 | else { |
michael@0 | 553 | newVersion = newVersionVal.Value(); |
michael@0 | 554 | } |
michael@0 | 555 | |
michael@0 | 556 | if (!SendVersionChange(oldVersion, newVersion)) { |
michael@0 | 557 | return NS_ERROR_FAILURE; |
michael@0 | 558 | } |
michael@0 | 559 | |
michael@0 | 560 | return NS_OK; |
michael@0 | 561 | } |
michael@0 | 562 | |
michael@0 | 563 | MOZ_CRASH("Unexpected message type!"); |
michael@0 | 564 | } |
michael@0 | 565 | |
michael@0 | 566 | void |
michael@0 | 567 | IndexedDBDatabaseParent::ActorDestroy(ActorDestroyReason aWhy) |
michael@0 | 568 | { |
michael@0 | 569 | if (mDatabase) { |
michael@0 | 570 | mDatabase->SetActor(static_cast<IndexedDBDatabaseParent*>(nullptr)); |
michael@0 | 571 | mDatabase->InvalidateInternal(/* aIsDead */ true); |
michael@0 | 572 | } |
michael@0 | 573 | } |
michael@0 | 574 | |
michael@0 | 575 | bool |
michael@0 | 576 | IndexedDBDatabaseParent::RecvClose(const bool& aUnlinked) |
michael@0 | 577 | { |
michael@0 | 578 | MOZ_ASSERT(mDatabase); |
michael@0 | 579 | |
michael@0 | 580 | if (IsDisconnected()) { |
michael@0 | 581 | // We're shutting down, ignore this request. |
michael@0 | 582 | return true; |
michael@0 | 583 | } |
michael@0 | 584 | |
michael@0 | 585 | mDatabase->CloseInternal(aUnlinked); |
michael@0 | 586 | return true; |
michael@0 | 587 | } |
michael@0 | 588 | |
michael@0 | 589 | bool |
michael@0 | 590 | IndexedDBDatabaseParent::RecvPIndexedDBTransactionConstructor( |
michael@0 | 591 | PIndexedDBTransactionParent* aActor, |
michael@0 | 592 | const TransactionParams& aParams) |
michael@0 | 593 | { |
michael@0 | 594 | MOZ_ASSERT(aParams.type() == |
michael@0 | 595 | TransactionParams::TNormalTransactionParams); |
michael@0 | 596 | MOZ_ASSERT(!mOpenRequest); |
michael@0 | 597 | |
michael@0 | 598 | if (IsDisconnected()) { |
michael@0 | 599 | // We're shutting down, ignore this request. |
michael@0 | 600 | return true; |
michael@0 | 601 | } |
michael@0 | 602 | |
michael@0 | 603 | if (!mDatabase) { |
michael@0 | 604 | return true; |
michael@0 | 605 | } |
michael@0 | 606 | |
michael@0 | 607 | IndexedDBTransactionParent* actor = |
michael@0 | 608 | static_cast<IndexedDBTransactionParent*>(aActor); |
michael@0 | 609 | |
michael@0 | 610 | const NormalTransactionParams& params = aParams.get_NormalTransactionParams(); |
michael@0 | 611 | |
michael@0 | 612 | if (params.mode() != IDBTransaction::READ_ONLY && |
michael@0 | 613 | !CheckWritePermission(mDatabase->Name())) { |
michael@0 | 614 | return false; |
michael@0 | 615 | } |
michael@0 | 616 | |
michael@0 | 617 | if (mDatabase->IsClosed()) { |
michael@0 | 618 | // If the window was navigated then we won't be able to do anything here. |
michael@0 | 619 | return true; |
michael@0 | 620 | } |
michael@0 | 621 | |
michael@0 | 622 | Sequence<nsString> storesToOpen; |
michael@0 | 623 | storesToOpen.AppendElements(params.names()); |
michael@0 | 624 | |
michael@0 | 625 | nsRefPtr<IDBTransaction> transaction = |
michael@0 | 626 | IDBTransaction::Create(mDatabase, storesToOpen, params.mode(), false); |
michael@0 | 627 | NS_ENSURE_TRUE(transaction, false); |
michael@0 | 628 | |
michael@0 | 629 | nsresult rv = actor->SetTransaction(transaction); |
michael@0 | 630 | NS_ENSURE_SUCCESS(rv, false); |
michael@0 | 631 | |
michael@0 | 632 | return true; |
michael@0 | 633 | } |
michael@0 | 634 | |
michael@0 | 635 | PIndexedDBTransactionParent* |
michael@0 | 636 | IndexedDBDatabaseParent::AllocPIndexedDBTransactionParent( |
michael@0 | 637 | const TransactionParams& aParams) |
michael@0 | 638 | { |
michael@0 | 639 | MOZ_ASSERT(aParams.type() == |
michael@0 | 640 | TransactionParams::TNormalTransactionParams); |
michael@0 | 641 | return new IndexedDBTransactionParent(); |
michael@0 | 642 | } |
michael@0 | 643 | |
michael@0 | 644 | bool |
michael@0 | 645 | IndexedDBDatabaseParent::DeallocPIndexedDBTransactionParent( |
michael@0 | 646 | PIndexedDBTransactionParent* aActor) |
michael@0 | 647 | { |
michael@0 | 648 | delete aActor; |
michael@0 | 649 | return true; |
michael@0 | 650 | } |
michael@0 | 651 | |
michael@0 | 652 | /******************************************************************************* |
michael@0 | 653 | * IndexedDBTransactionParent |
michael@0 | 654 | ******************************************************************************/ |
michael@0 | 655 | |
michael@0 | 656 | IndexedDBTransactionParent::IndexedDBTransactionParent() |
michael@0 | 657 | : mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()), |
michael@0 | 658 | mArtificialRequestCount(false) |
michael@0 | 659 | { |
michael@0 | 660 | MOZ_COUNT_CTOR(IndexedDBTransactionParent); |
michael@0 | 661 | } |
michael@0 | 662 | |
michael@0 | 663 | IndexedDBTransactionParent::~IndexedDBTransactionParent() |
michael@0 | 664 | { |
michael@0 | 665 | MOZ_COUNT_DTOR(IndexedDBTransactionParent); |
michael@0 | 666 | } |
michael@0 | 667 | |
michael@0 | 668 | nsresult |
michael@0 | 669 | IndexedDBTransactionParent::SetTransaction(IDBTransaction* aTransaction) |
michael@0 | 670 | { |
michael@0 | 671 | MOZ_ASSERT(aTransaction); |
michael@0 | 672 | MOZ_ASSERT(!mTransaction); |
michael@0 | 673 | |
michael@0 | 674 | EventTarget* target = static_cast<EventTarget*>(aTransaction); |
michael@0 | 675 | |
michael@0 | 676 | NS_NAMED_LITERAL_STRING(complete, COMPLETE_EVT_STR); |
michael@0 | 677 | nsresult rv = target->AddEventListener(complete, mEventListener, false); |
michael@0 | 678 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 679 | |
michael@0 | 680 | rv = target->AddEventListener(NS_LITERAL_STRING(ABORT_EVT_STR), |
michael@0 | 681 | mEventListener, false); |
michael@0 | 682 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 683 | |
michael@0 | 684 | aTransaction->OnNewRequest(); |
michael@0 | 685 | mArtificialRequestCount = true; |
michael@0 | 686 | |
michael@0 | 687 | aTransaction->SetActor(this); |
michael@0 | 688 | |
michael@0 | 689 | mTransaction = aTransaction; |
michael@0 | 690 | return NS_OK; |
michael@0 | 691 | } |
michael@0 | 692 | |
michael@0 | 693 | nsresult |
michael@0 | 694 | IndexedDBTransactionParent::HandleEvent(nsIDOMEvent* aEvent) |
michael@0 | 695 | { |
michael@0 | 696 | MOZ_ASSERT(aEvent); |
michael@0 | 697 | |
michael@0 | 698 | if (IsDisconnected()) { |
michael@0 | 699 | // We're shutting down, ignore this event. |
michael@0 | 700 | return NS_OK; |
michael@0 | 701 | } |
michael@0 | 702 | |
michael@0 | 703 | nsString type; |
michael@0 | 704 | nsresult rv = aEvent->GetType(type); |
michael@0 | 705 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 706 | |
michael@0 | 707 | CompleteParams params; |
michael@0 | 708 | |
michael@0 | 709 | if (type.EqualsLiteral(COMPLETE_EVT_STR)) { |
michael@0 | 710 | params = CompleteResult(); |
michael@0 | 711 | } |
michael@0 | 712 | else if (type.EqualsLiteral(ABORT_EVT_STR)) { |
michael@0 | 713 | #ifdef DEBUG |
michael@0 | 714 | { |
michael@0 | 715 | nsCOMPtr<EventTarget> target = aEvent->InternalDOMEvent()->GetTarget(); |
michael@0 | 716 | MOZ_ASSERT(SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*, |
michael@0 | 717 | mTransaction))); |
michael@0 | 718 | } |
michael@0 | 719 | #endif |
michael@0 | 720 | params = AbortResult(mTransaction->GetAbortCode()); |
michael@0 | 721 | } |
michael@0 | 722 | else { |
michael@0 | 723 | NS_WARNING("Unknown message type!"); |
michael@0 | 724 | return NS_ERROR_UNEXPECTED; |
michael@0 | 725 | } |
michael@0 | 726 | |
michael@0 | 727 | if (!SendComplete(params)) { |
michael@0 | 728 | return NS_ERROR_FAILURE; |
michael@0 | 729 | } |
michael@0 | 730 | |
michael@0 | 731 | return NS_OK; |
michael@0 | 732 | } |
michael@0 | 733 | |
michael@0 | 734 | void |
michael@0 | 735 | IndexedDBTransactionParent::ActorDestroy(ActorDestroyReason aWhy) |
michael@0 | 736 | { |
michael@0 | 737 | if (mTransaction) { |
michael@0 | 738 | if (mArtificialRequestCount) { |
michael@0 | 739 | // The transaction never completed and now the child side is dead. Abort |
michael@0 | 740 | // here to be safe. |
michael@0 | 741 | ErrorResult rv; |
michael@0 | 742 | mTransaction->Abort(rv); |
michael@0 | 743 | |
michael@0 | 744 | mTransaction->OnRequestFinished(); |
michael@0 | 745 | #ifdef DEBUG |
michael@0 | 746 | mArtificialRequestCount = false; |
michael@0 | 747 | #endif |
michael@0 | 748 | } |
michael@0 | 749 | mTransaction->SetActor(static_cast<IndexedDBTransactionParent*>(nullptr)); |
michael@0 | 750 | } |
michael@0 | 751 | } |
michael@0 | 752 | |
michael@0 | 753 | bool |
michael@0 | 754 | IndexedDBTransactionParent::RecvAbort(const nsresult& aAbortCode) |
michael@0 | 755 | { |
michael@0 | 756 | MOZ_ASSERT(mTransaction); |
michael@0 | 757 | |
michael@0 | 758 | if (IsDisconnected()) { |
michael@0 | 759 | // We're shutting down, ignore this request. |
michael@0 | 760 | return true; |
michael@0 | 761 | } |
michael@0 | 762 | |
michael@0 | 763 | mTransaction->Abort(aAbortCode); |
michael@0 | 764 | return true; |
michael@0 | 765 | } |
michael@0 | 766 | |
michael@0 | 767 | bool |
michael@0 | 768 | IndexedDBTransactionParent::RecvAllRequestsFinished() |
michael@0 | 769 | { |
michael@0 | 770 | MOZ_ASSERT(mTransaction); |
michael@0 | 771 | MOZ_ASSERT(mArtificialRequestCount); |
michael@0 | 772 | |
michael@0 | 773 | if (IsDisconnected()) { |
michael@0 | 774 | // We're shutting down, ignore this request. |
michael@0 | 775 | return true; |
michael@0 | 776 | } |
michael@0 | 777 | |
michael@0 | 778 | mTransaction->OnRequestFinished(); |
michael@0 | 779 | mArtificialRequestCount = false; |
michael@0 | 780 | |
michael@0 | 781 | return true; |
michael@0 | 782 | } |
michael@0 | 783 | |
michael@0 | 784 | bool |
michael@0 | 785 | IndexedDBTransactionParent::RecvDeleteObjectStore(const nsString& aName) |
michael@0 | 786 | { |
michael@0 | 787 | MOZ_CRASH("Should be overridden, don't call me!"); |
michael@0 | 788 | } |
michael@0 | 789 | |
michael@0 | 790 | bool |
michael@0 | 791 | IndexedDBTransactionParent::RecvPIndexedDBObjectStoreConstructor( |
michael@0 | 792 | PIndexedDBObjectStoreParent* aActor, |
michael@0 | 793 | const ObjectStoreConstructorParams& aParams) |
michael@0 | 794 | { |
michael@0 | 795 | if (IsDisconnected()) { |
michael@0 | 796 | // We're shutting down, ignore this request. |
michael@0 | 797 | return true; |
michael@0 | 798 | } |
michael@0 | 799 | |
michael@0 | 800 | if (!mTransaction) { |
michael@0 | 801 | return true; |
michael@0 | 802 | } |
michael@0 | 803 | |
michael@0 | 804 | IndexedDBObjectStoreParent* actor = |
michael@0 | 805 | static_cast<IndexedDBObjectStoreParent*>(aActor); |
michael@0 | 806 | |
michael@0 | 807 | if (aParams.type() == |
michael@0 | 808 | ObjectStoreConstructorParams::TGetObjectStoreParams) { |
michael@0 | 809 | const GetObjectStoreParams& params = aParams.get_GetObjectStoreParams(); |
michael@0 | 810 | const nsString& name = params.name(); |
michael@0 | 811 | |
michael@0 | 812 | nsRefPtr<IDBObjectStore> objectStore; |
michael@0 | 813 | |
michael@0 | 814 | { |
michael@0 | 815 | AutoSetCurrentTransaction asct(mTransaction); |
michael@0 | 816 | |
michael@0 | 817 | ErrorResult rv; |
michael@0 | 818 | objectStore = mTransaction->ObjectStore(name, rv); |
michael@0 | 819 | ENSURE_SUCCESS(rv, false); |
michael@0 | 820 | |
michael@0 | 821 | actor->SetObjectStore(objectStore); |
michael@0 | 822 | } |
michael@0 | 823 | |
michael@0 | 824 | objectStore->SetActor(actor); |
michael@0 | 825 | return true; |
michael@0 | 826 | } |
michael@0 | 827 | |
michael@0 | 828 | if (aParams.type() == |
michael@0 | 829 | ObjectStoreConstructorParams::TCreateObjectStoreParams) { |
michael@0 | 830 | MOZ_CRASH("Should be overridden, don't call me!"); |
michael@0 | 831 | } |
michael@0 | 832 | |
michael@0 | 833 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 834 | } |
michael@0 | 835 | |
michael@0 | 836 | PIndexedDBObjectStoreParent* |
michael@0 | 837 | IndexedDBTransactionParent::AllocPIndexedDBObjectStoreParent( |
michael@0 | 838 | const ObjectStoreConstructorParams& aParams) |
michael@0 | 839 | { |
michael@0 | 840 | return new IndexedDBObjectStoreParent(); |
michael@0 | 841 | } |
michael@0 | 842 | |
michael@0 | 843 | bool |
michael@0 | 844 | IndexedDBTransactionParent::DeallocPIndexedDBObjectStoreParent( |
michael@0 | 845 | PIndexedDBObjectStoreParent* aActor) |
michael@0 | 846 | { |
michael@0 | 847 | delete aActor; |
michael@0 | 848 | return true; |
michael@0 | 849 | } |
michael@0 | 850 | |
michael@0 | 851 | /******************************************************************************* |
michael@0 | 852 | * IndexedDBVersionChangeTransactionParent |
michael@0 | 853 | ******************************************************************************/ |
michael@0 | 854 | |
michael@0 | 855 | IndexedDBVersionChangeTransactionParent:: |
michael@0 | 856 | IndexedDBVersionChangeTransactionParent() |
michael@0 | 857 | { |
michael@0 | 858 | MOZ_COUNT_CTOR(IndexedDBVersionChangeTransactionParent); |
michael@0 | 859 | } |
michael@0 | 860 | |
michael@0 | 861 | IndexedDBVersionChangeTransactionParent:: |
michael@0 | 862 | ~IndexedDBVersionChangeTransactionParent() |
michael@0 | 863 | { |
michael@0 | 864 | MOZ_COUNT_DTOR(IndexedDBVersionChangeTransactionParent); |
michael@0 | 865 | } |
michael@0 | 866 | |
michael@0 | 867 | bool |
michael@0 | 868 | IndexedDBVersionChangeTransactionParent::RecvDeleteObjectStore( |
michael@0 | 869 | const nsString& aName) |
michael@0 | 870 | { |
michael@0 | 871 | MOZ_ASSERT(!mTransaction || |
michael@0 | 872 | mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE); |
michael@0 | 873 | |
michael@0 | 874 | if (IsDisconnected()) { |
michael@0 | 875 | // We're shutting down, ignore this request. |
michael@0 | 876 | return true; |
michael@0 | 877 | } |
michael@0 | 878 | |
michael@0 | 879 | if (!mTransaction) { |
michael@0 | 880 | return true; |
michael@0 | 881 | } |
michael@0 | 882 | |
michael@0 | 883 | if (mTransaction->Database()->IsInvalidated()) { |
michael@0 | 884 | // If we've invalidated this database in the parent then we should bail out |
michael@0 | 885 | // now to avoid logic problems that could force-kill the child. |
michael@0 | 886 | return true; |
michael@0 | 887 | } |
michael@0 | 888 | |
michael@0 | 889 | IDBDatabase* db = mTransaction->Database(); |
michael@0 | 890 | MOZ_ASSERT(db); |
michael@0 | 891 | |
michael@0 | 892 | ErrorResult rv; |
michael@0 | 893 | |
michael@0 | 894 | { |
michael@0 | 895 | AutoSetCurrentTransaction asct(mTransaction); |
michael@0 | 896 | db->DeleteObjectStore(aName, rv); |
michael@0 | 897 | } |
michael@0 | 898 | |
michael@0 | 899 | ENSURE_SUCCESS(rv, false); |
michael@0 | 900 | return true; |
michael@0 | 901 | } |
michael@0 | 902 | |
michael@0 | 903 | bool |
michael@0 | 904 | IndexedDBVersionChangeTransactionParent::RecvPIndexedDBObjectStoreConstructor( |
michael@0 | 905 | PIndexedDBObjectStoreParent* aActor, |
michael@0 | 906 | const ObjectStoreConstructorParams& aParams) |
michael@0 | 907 | { |
michael@0 | 908 | if (IsDisconnected()) { |
michael@0 | 909 | // We're shutting down, ignore this request. |
michael@0 | 910 | return true; |
michael@0 | 911 | } |
michael@0 | 912 | |
michael@0 | 913 | if (!mTransaction) { |
michael@0 | 914 | return true; |
michael@0 | 915 | } |
michael@0 | 916 | |
michael@0 | 917 | if (mTransaction->Database()->IsInvalidated()) { |
michael@0 | 918 | // If we've invalidated this database in the parent then we should bail out |
michael@0 | 919 | // now to avoid logic problems that could force-kill the child. |
michael@0 | 920 | return true; |
michael@0 | 921 | } |
michael@0 | 922 | |
michael@0 | 923 | IndexedDBObjectStoreParent* actor = |
michael@0 | 924 | static_cast<IndexedDBObjectStoreParent*>(aActor); |
michael@0 | 925 | |
michael@0 | 926 | if (aParams.type() == |
michael@0 | 927 | ObjectStoreConstructorParams::TCreateObjectStoreParams) { |
michael@0 | 928 | MOZ_ASSERT(mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE); |
michael@0 | 929 | |
michael@0 | 930 | const CreateObjectStoreParams& params = |
michael@0 | 931 | aParams.get_CreateObjectStoreParams(); |
michael@0 | 932 | |
michael@0 | 933 | const ObjectStoreInfoGuts& info = params.info(); |
michael@0 | 934 | |
michael@0 | 935 | IDBDatabase* db = mTransaction->Database(); |
michael@0 | 936 | MOZ_ASSERT(db); |
michael@0 | 937 | |
michael@0 | 938 | nsRefPtr<IDBObjectStore> objectStore; |
michael@0 | 939 | |
michael@0 | 940 | ErrorResult rv; |
michael@0 | 941 | |
michael@0 | 942 | { |
michael@0 | 943 | AutoSetCurrentTransaction asct(mTransaction); |
michael@0 | 944 | |
michael@0 | 945 | objectStore = db->CreateObjectStoreInternal(mTransaction, info, rv); |
michael@0 | 946 | } |
michael@0 | 947 | |
michael@0 | 948 | ENSURE_SUCCESS(rv, false); |
michael@0 | 949 | |
michael@0 | 950 | actor->SetObjectStore(objectStore); |
michael@0 | 951 | objectStore->SetActor(actor); |
michael@0 | 952 | return true; |
michael@0 | 953 | } |
michael@0 | 954 | |
michael@0 | 955 | return |
michael@0 | 956 | IndexedDBTransactionParent::RecvPIndexedDBObjectStoreConstructor(aActor, |
michael@0 | 957 | aParams); |
michael@0 | 958 | } |
michael@0 | 959 | |
michael@0 | 960 | PIndexedDBObjectStoreParent* |
michael@0 | 961 | IndexedDBVersionChangeTransactionParent::AllocPIndexedDBObjectStoreParent( |
michael@0 | 962 | const ObjectStoreConstructorParams& aParams) |
michael@0 | 963 | { |
michael@0 | 964 | if (aParams.type() == |
michael@0 | 965 | ObjectStoreConstructorParams::TCreateObjectStoreParams || |
michael@0 | 966 | mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE) { |
michael@0 | 967 | return new IndexedDBVersionChangeObjectStoreParent(); |
michael@0 | 968 | } |
michael@0 | 969 | |
michael@0 | 970 | return IndexedDBTransactionParent::AllocPIndexedDBObjectStoreParent(aParams); |
michael@0 | 971 | } |
michael@0 | 972 | |
michael@0 | 973 | /******************************************************************************* |
michael@0 | 974 | * IndexedDBCursorParent |
michael@0 | 975 | ******************************************************************************/ |
michael@0 | 976 | |
michael@0 | 977 | IndexedDBCursorParent::IndexedDBCursorParent(IDBCursor* aCursor) |
michael@0 | 978 | : mCursor(aCursor) |
michael@0 | 979 | { |
michael@0 | 980 | MOZ_COUNT_CTOR(IndexedDBCursorParent); |
michael@0 | 981 | MOZ_ASSERT(aCursor); |
michael@0 | 982 | aCursor->SetActor(this); |
michael@0 | 983 | } |
michael@0 | 984 | |
michael@0 | 985 | IndexedDBCursorParent::~IndexedDBCursorParent() |
michael@0 | 986 | { |
michael@0 | 987 | MOZ_COUNT_DTOR(IndexedDBCursorParent); |
michael@0 | 988 | } |
michael@0 | 989 | |
michael@0 | 990 | bool |
michael@0 | 991 | IndexedDBCursorParent::IsDisconnected() const |
michael@0 | 992 | { |
michael@0 | 993 | MOZ_ASSERT(mCursor); |
michael@0 | 994 | return mCursor->Transaction()->GetActorParent()->IsDisconnected(); |
michael@0 | 995 | } |
michael@0 | 996 | |
michael@0 | 997 | void |
michael@0 | 998 | IndexedDBCursorParent::ActorDestroy(ActorDestroyReason aWhy) |
michael@0 | 999 | { |
michael@0 | 1000 | MOZ_ASSERT(mCursor); |
michael@0 | 1001 | mCursor->SetActor(static_cast<IndexedDBCursorParent*>(nullptr)); |
michael@0 | 1002 | } |
michael@0 | 1003 | |
michael@0 | 1004 | bool |
michael@0 | 1005 | IndexedDBCursorParent::RecvPIndexedDBRequestConstructor( |
michael@0 | 1006 | PIndexedDBRequestParent* aActor, |
michael@0 | 1007 | const CursorRequestParams& aParams) |
michael@0 | 1008 | { |
michael@0 | 1009 | MOZ_ASSERT(mCursor); |
michael@0 | 1010 | |
michael@0 | 1011 | if (IsDisconnected()) { |
michael@0 | 1012 | // We're shutting down, ignore this request. |
michael@0 | 1013 | return true; |
michael@0 | 1014 | } |
michael@0 | 1015 | |
michael@0 | 1016 | IndexedDBCursorRequestParent* actor = |
michael@0 | 1017 | static_cast<IndexedDBCursorRequestParent*>(aActor); |
michael@0 | 1018 | |
michael@0 | 1019 | if (mCursor->Transaction()->Database()->IsInvalidated()) { |
michael@0 | 1020 | // If we've invalidated this database in the parent then we should bail out |
michael@0 | 1021 | // now to avoid logic problems that could force-kill the child. |
michael@0 | 1022 | return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); |
michael@0 | 1023 | } |
michael@0 | 1024 | |
michael@0 | 1025 | switch (aParams.type()) { |
michael@0 | 1026 | case CursorRequestParams::TContinueParams: |
michael@0 | 1027 | return actor->Continue(aParams.get_ContinueParams()); |
michael@0 | 1028 | |
michael@0 | 1029 | default: |
michael@0 | 1030 | MOZ_CRASH("Unknown type!"); |
michael@0 | 1031 | } |
michael@0 | 1032 | |
michael@0 | 1033 | MOZ_CRASH("Should never get here!"); |
michael@0 | 1034 | } |
michael@0 | 1035 | |
michael@0 | 1036 | PIndexedDBRequestParent* |
michael@0 | 1037 | IndexedDBCursorParent::AllocPIndexedDBRequestParent( |
michael@0 | 1038 | const CursorRequestParams& aParams) |
michael@0 | 1039 | { |
michael@0 | 1040 | MOZ_ASSERT(mCursor); |
michael@0 | 1041 | return new IndexedDBCursorRequestParent(mCursor, aParams.type()); |
michael@0 | 1042 | } |
michael@0 | 1043 | |
michael@0 | 1044 | bool |
michael@0 | 1045 | IndexedDBCursorParent::DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) |
michael@0 | 1046 | { |
michael@0 | 1047 | delete aActor; |
michael@0 | 1048 | return true; |
michael@0 | 1049 | } |
michael@0 | 1050 | |
michael@0 | 1051 | /******************************************************************************* |
michael@0 | 1052 | * IndexedDBObjectStoreParent |
michael@0 | 1053 | ******************************************************************************/ |
michael@0 | 1054 | |
michael@0 | 1055 | IndexedDBObjectStoreParent::IndexedDBObjectStoreParent() |
michael@0 | 1056 | { |
michael@0 | 1057 | MOZ_COUNT_CTOR(IndexedDBObjectStoreParent); |
michael@0 | 1058 | } |
michael@0 | 1059 | |
michael@0 | 1060 | IndexedDBObjectStoreParent::~IndexedDBObjectStoreParent() |
michael@0 | 1061 | { |
michael@0 | 1062 | MOZ_COUNT_DTOR(IndexedDBObjectStoreParent); |
michael@0 | 1063 | } |
michael@0 | 1064 | |
michael@0 | 1065 | void |
michael@0 | 1066 | IndexedDBObjectStoreParent::SetObjectStore(IDBObjectStore* aObjectStore) |
michael@0 | 1067 | { |
michael@0 | 1068 | // Sadly can't assert aObjectStore here... |
michael@0 | 1069 | MOZ_ASSERT(!mObjectStore); |
michael@0 | 1070 | |
michael@0 | 1071 | mObjectStore = aObjectStore; |
michael@0 | 1072 | } |
michael@0 | 1073 | |
michael@0 | 1074 | void |
michael@0 | 1075 | IndexedDBObjectStoreParent::ActorDestroy(ActorDestroyReason aWhy) |
michael@0 | 1076 | { |
michael@0 | 1077 | if (mObjectStore) { |
michael@0 | 1078 | mObjectStore->SetActor(static_cast<IndexedDBObjectStoreParent*>(nullptr)); |
michael@0 | 1079 | } |
michael@0 | 1080 | } |
michael@0 | 1081 | |
michael@0 | 1082 | bool |
michael@0 | 1083 | IndexedDBObjectStoreParent::RecvDeleteIndex(const nsString& aName) |
michael@0 | 1084 | { |
michael@0 | 1085 | MOZ_CRASH("Should be overridden, don't call me!"); |
michael@0 | 1086 | } |
michael@0 | 1087 | |
michael@0 | 1088 | bool |
michael@0 | 1089 | IndexedDBObjectStoreParent::RecvPIndexedDBRequestConstructor( |
michael@0 | 1090 | PIndexedDBRequestParent* aActor, |
michael@0 | 1091 | const ObjectStoreRequestParams& aParams) |
michael@0 | 1092 | { |
michael@0 | 1093 | if (IsDisconnected()) { |
michael@0 | 1094 | // We're shutting down, ignore this request. |
michael@0 | 1095 | return true; |
michael@0 | 1096 | } |
michael@0 | 1097 | |
michael@0 | 1098 | if (!mObjectStore) { |
michael@0 | 1099 | return true; |
michael@0 | 1100 | } |
michael@0 | 1101 | |
michael@0 | 1102 | IndexedDBObjectStoreRequestParent* actor = |
michael@0 | 1103 | static_cast<IndexedDBObjectStoreRequestParent*>(aActor); |
michael@0 | 1104 | |
michael@0 | 1105 | if (mObjectStore->Transaction()->Database()->IsInvalidated()) { |
michael@0 | 1106 | // If we've invalidated this database in the parent then we should bail out |
michael@0 | 1107 | // now to avoid logic problems that could force-kill the child. |
michael@0 | 1108 | return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); |
michael@0 | 1109 | } |
michael@0 | 1110 | |
michael@0 | 1111 | switch (aParams.type()) { |
michael@0 | 1112 | case ObjectStoreRequestParams::TGetParams: |
michael@0 | 1113 | return actor->Get(aParams.get_GetParams()); |
michael@0 | 1114 | |
michael@0 | 1115 | case ObjectStoreRequestParams::TGetAllParams: |
michael@0 | 1116 | return actor->GetAll(aParams.get_GetAllParams()); |
michael@0 | 1117 | |
michael@0 | 1118 | case ObjectStoreRequestParams::TGetAllKeysParams: |
michael@0 | 1119 | return actor->GetAllKeys(aParams.get_GetAllKeysParams()); |
michael@0 | 1120 | |
michael@0 | 1121 | case ObjectStoreRequestParams::TAddParams: |
michael@0 | 1122 | return actor->Add(aParams.get_AddParams()); |
michael@0 | 1123 | |
michael@0 | 1124 | case ObjectStoreRequestParams::TPutParams: |
michael@0 | 1125 | return actor->Put(aParams.get_PutParams()); |
michael@0 | 1126 | |
michael@0 | 1127 | case ObjectStoreRequestParams::TDeleteParams: |
michael@0 | 1128 | return actor->Delete(aParams.get_DeleteParams()); |
michael@0 | 1129 | |
michael@0 | 1130 | case ObjectStoreRequestParams::TClearParams: |
michael@0 | 1131 | return actor->Clear(aParams.get_ClearParams()); |
michael@0 | 1132 | |
michael@0 | 1133 | case ObjectStoreRequestParams::TCountParams: |
michael@0 | 1134 | return actor->Count(aParams.get_CountParams()); |
michael@0 | 1135 | |
michael@0 | 1136 | case ObjectStoreRequestParams::TOpenCursorParams: |
michael@0 | 1137 | return actor->OpenCursor(aParams.get_OpenCursorParams()); |
michael@0 | 1138 | |
michael@0 | 1139 | case ObjectStoreRequestParams::TOpenKeyCursorParams: |
michael@0 | 1140 | return actor->OpenKeyCursor(aParams.get_OpenKeyCursorParams()); |
michael@0 | 1141 | |
michael@0 | 1142 | default: |
michael@0 | 1143 | MOZ_CRASH("Unknown type!"); |
michael@0 | 1144 | } |
michael@0 | 1145 | |
michael@0 | 1146 | MOZ_CRASH("Should never get here!"); |
michael@0 | 1147 | } |
michael@0 | 1148 | |
michael@0 | 1149 | bool |
michael@0 | 1150 | IndexedDBObjectStoreParent::RecvPIndexedDBIndexConstructor( |
michael@0 | 1151 | PIndexedDBIndexParent* aActor, |
michael@0 | 1152 | const IndexConstructorParams& aParams) |
michael@0 | 1153 | { |
michael@0 | 1154 | if (IsDisconnected()) { |
michael@0 | 1155 | // We're shutting down, ignore this request. |
michael@0 | 1156 | return true; |
michael@0 | 1157 | } |
michael@0 | 1158 | |
michael@0 | 1159 | if (!mObjectStore) { |
michael@0 | 1160 | return true; |
michael@0 | 1161 | } |
michael@0 | 1162 | |
michael@0 | 1163 | IndexedDBIndexParent* actor = static_cast<IndexedDBIndexParent*>(aActor); |
michael@0 | 1164 | |
michael@0 | 1165 | if (aParams.type() == IndexConstructorParams::TGetIndexParams) { |
michael@0 | 1166 | const GetIndexParams& params = aParams.get_GetIndexParams(); |
michael@0 | 1167 | const nsString& name = params.name(); |
michael@0 | 1168 | |
michael@0 | 1169 | nsRefPtr<IDBIndex> index; |
michael@0 | 1170 | |
michael@0 | 1171 | { |
michael@0 | 1172 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1173 | |
michael@0 | 1174 | ErrorResult rv; |
michael@0 | 1175 | index = mObjectStore->Index(name, rv); |
michael@0 | 1176 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1177 | |
michael@0 | 1178 | actor->SetIndex(index); |
michael@0 | 1179 | } |
michael@0 | 1180 | |
michael@0 | 1181 | index->SetActor(actor); |
michael@0 | 1182 | return true; |
michael@0 | 1183 | } |
michael@0 | 1184 | |
michael@0 | 1185 | if (aParams.type() == IndexConstructorParams::TCreateIndexParams) { |
michael@0 | 1186 | MOZ_CRASH("Should be overridden, don't call me!"); |
michael@0 | 1187 | } |
michael@0 | 1188 | |
michael@0 | 1189 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 1190 | } |
michael@0 | 1191 | |
michael@0 | 1192 | PIndexedDBRequestParent* |
michael@0 | 1193 | IndexedDBObjectStoreParent::AllocPIndexedDBRequestParent( |
michael@0 | 1194 | const ObjectStoreRequestParams& aParams) |
michael@0 | 1195 | { |
michael@0 | 1196 | return new IndexedDBObjectStoreRequestParent(mObjectStore, aParams.type()); |
michael@0 | 1197 | } |
michael@0 | 1198 | |
michael@0 | 1199 | bool |
michael@0 | 1200 | IndexedDBObjectStoreParent::DeallocPIndexedDBRequestParent( |
michael@0 | 1201 | PIndexedDBRequestParent* aActor) |
michael@0 | 1202 | { |
michael@0 | 1203 | delete aActor; |
michael@0 | 1204 | return true; |
michael@0 | 1205 | } |
michael@0 | 1206 | |
michael@0 | 1207 | PIndexedDBIndexParent* |
michael@0 | 1208 | IndexedDBObjectStoreParent::AllocPIndexedDBIndexParent( |
michael@0 | 1209 | const IndexConstructorParams& aParams) |
michael@0 | 1210 | { |
michael@0 | 1211 | return new IndexedDBIndexParent(); |
michael@0 | 1212 | } |
michael@0 | 1213 | |
michael@0 | 1214 | bool |
michael@0 | 1215 | IndexedDBObjectStoreParent::DeallocPIndexedDBIndexParent( |
michael@0 | 1216 | PIndexedDBIndexParent* aActor) |
michael@0 | 1217 | { |
michael@0 | 1218 | delete aActor; |
michael@0 | 1219 | return true; |
michael@0 | 1220 | } |
michael@0 | 1221 | |
michael@0 | 1222 | PIndexedDBCursorParent* |
michael@0 | 1223 | IndexedDBObjectStoreParent::AllocPIndexedDBCursorParent( |
michael@0 | 1224 | const ObjectStoreCursorConstructorParams& aParams) |
michael@0 | 1225 | { |
michael@0 | 1226 | MOZ_CRASH("Caller is supposed to manually construct a cursor!"); |
michael@0 | 1227 | } |
michael@0 | 1228 | |
michael@0 | 1229 | bool |
michael@0 | 1230 | IndexedDBObjectStoreParent::DeallocPIndexedDBCursorParent( |
michael@0 | 1231 | PIndexedDBCursorParent* aActor) |
michael@0 | 1232 | { |
michael@0 | 1233 | delete aActor; |
michael@0 | 1234 | return true; |
michael@0 | 1235 | } |
michael@0 | 1236 | |
michael@0 | 1237 | /******************************************************************************* |
michael@0 | 1238 | * IndexedDBVersionChangeObjectStoreParent |
michael@0 | 1239 | ******************************************************************************/ |
michael@0 | 1240 | |
michael@0 | 1241 | IndexedDBVersionChangeObjectStoreParent:: |
michael@0 | 1242 | IndexedDBVersionChangeObjectStoreParent() |
michael@0 | 1243 | { |
michael@0 | 1244 | MOZ_COUNT_CTOR(IndexedDBVersionChangeObjectStoreParent); |
michael@0 | 1245 | } |
michael@0 | 1246 | |
michael@0 | 1247 | IndexedDBVersionChangeObjectStoreParent:: |
michael@0 | 1248 | ~IndexedDBVersionChangeObjectStoreParent() |
michael@0 | 1249 | { |
michael@0 | 1250 | MOZ_COUNT_DTOR(IndexedDBVersionChangeObjectStoreParent); |
michael@0 | 1251 | } |
michael@0 | 1252 | |
michael@0 | 1253 | bool |
michael@0 | 1254 | IndexedDBVersionChangeObjectStoreParent::RecvDeleteIndex(const nsString& aName) |
michael@0 | 1255 | { |
michael@0 | 1256 | MOZ_ASSERT(!mObjectStore || |
michael@0 | 1257 | mObjectStore->Transaction()->GetMode() == |
michael@0 | 1258 | IDBTransaction::VERSION_CHANGE); |
michael@0 | 1259 | |
michael@0 | 1260 | if (IsDisconnected()) { |
michael@0 | 1261 | // We're shutting down, ignore this request. |
michael@0 | 1262 | return true; |
michael@0 | 1263 | } |
michael@0 | 1264 | |
michael@0 | 1265 | if (!mObjectStore) { |
michael@0 | 1266 | return true; |
michael@0 | 1267 | } |
michael@0 | 1268 | |
michael@0 | 1269 | if (mObjectStore->Transaction()->Database()->IsInvalidated()) { |
michael@0 | 1270 | // If we've invalidated this database in the parent then we should bail out |
michael@0 | 1271 | // now to avoid logic problems that could force-kill the child. |
michael@0 | 1272 | return true; |
michael@0 | 1273 | } |
michael@0 | 1274 | |
michael@0 | 1275 | ErrorResult rv; |
michael@0 | 1276 | |
michael@0 | 1277 | { |
michael@0 | 1278 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1279 | |
michael@0 | 1280 | mObjectStore->DeleteIndex(aName, rv); |
michael@0 | 1281 | } |
michael@0 | 1282 | |
michael@0 | 1283 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1284 | return true; |
michael@0 | 1285 | } |
michael@0 | 1286 | |
michael@0 | 1287 | bool |
michael@0 | 1288 | IndexedDBVersionChangeObjectStoreParent::RecvPIndexedDBIndexConstructor( |
michael@0 | 1289 | PIndexedDBIndexParent* aActor, |
michael@0 | 1290 | const IndexConstructorParams& aParams) |
michael@0 | 1291 | { |
michael@0 | 1292 | if (IsDisconnected()) { |
michael@0 | 1293 | // We're shutting down, ignore this request. |
michael@0 | 1294 | return true; |
michael@0 | 1295 | } |
michael@0 | 1296 | |
michael@0 | 1297 | if (!mObjectStore) { |
michael@0 | 1298 | return true; |
michael@0 | 1299 | } |
michael@0 | 1300 | |
michael@0 | 1301 | if (mObjectStore->Transaction()->Database()->IsInvalidated()) { |
michael@0 | 1302 | // If we've invalidated this database in the parent then we should bail out |
michael@0 | 1303 | // now to avoid logic problems that could force-kill the child. |
michael@0 | 1304 | return true; |
michael@0 | 1305 | } |
michael@0 | 1306 | |
michael@0 | 1307 | IndexedDBIndexParent* actor = static_cast<IndexedDBIndexParent*>(aActor); |
michael@0 | 1308 | |
michael@0 | 1309 | if (aParams.type() == IndexConstructorParams::TCreateIndexParams) { |
michael@0 | 1310 | MOZ_ASSERT(mObjectStore->Transaction()->GetMode() == |
michael@0 | 1311 | IDBTransaction::VERSION_CHANGE); |
michael@0 | 1312 | |
michael@0 | 1313 | const CreateIndexParams& params = aParams.get_CreateIndexParams(); |
michael@0 | 1314 | const IndexInfo& info = params.info(); |
michael@0 | 1315 | |
michael@0 | 1316 | nsRefPtr<IDBIndex> index; |
michael@0 | 1317 | |
michael@0 | 1318 | { |
michael@0 | 1319 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1320 | |
michael@0 | 1321 | ErrorResult rv; |
michael@0 | 1322 | index = mObjectStore->CreateIndexInternal(info, rv); |
michael@0 | 1323 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1324 | } |
michael@0 | 1325 | |
michael@0 | 1326 | actor->SetIndex(index); |
michael@0 | 1327 | index->SetActor(actor); |
michael@0 | 1328 | return true; |
michael@0 | 1329 | } |
michael@0 | 1330 | |
michael@0 | 1331 | return IndexedDBObjectStoreParent::RecvPIndexedDBIndexConstructor(aActor, |
michael@0 | 1332 | aParams); |
michael@0 | 1333 | } |
michael@0 | 1334 | |
michael@0 | 1335 | /******************************************************************************* |
michael@0 | 1336 | * IndexedDBIndexParent |
michael@0 | 1337 | ******************************************************************************/ |
michael@0 | 1338 | |
michael@0 | 1339 | IndexedDBIndexParent::IndexedDBIndexParent() |
michael@0 | 1340 | { |
michael@0 | 1341 | MOZ_COUNT_CTOR(IndexedDBIndexParent); |
michael@0 | 1342 | } |
michael@0 | 1343 | |
michael@0 | 1344 | IndexedDBIndexParent::~IndexedDBIndexParent() |
michael@0 | 1345 | { |
michael@0 | 1346 | MOZ_COUNT_DTOR(IndexedDBIndexParent); |
michael@0 | 1347 | } |
michael@0 | 1348 | |
michael@0 | 1349 | void |
michael@0 | 1350 | IndexedDBIndexParent::SetIndex(IDBIndex* aIndex) |
michael@0 | 1351 | { |
michael@0 | 1352 | MOZ_ASSERT(aIndex); |
michael@0 | 1353 | MOZ_ASSERT(!mIndex); |
michael@0 | 1354 | |
michael@0 | 1355 | mIndex = aIndex; |
michael@0 | 1356 | } |
michael@0 | 1357 | |
michael@0 | 1358 | void |
michael@0 | 1359 | IndexedDBIndexParent::ActorDestroy(ActorDestroyReason aWhy) |
michael@0 | 1360 | { |
michael@0 | 1361 | if (mIndex) { |
michael@0 | 1362 | mIndex->SetActor(static_cast<IndexedDBIndexParent*>(nullptr)); |
michael@0 | 1363 | } |
michael@0 | 1364 | } |
michael@0 | 1365 | |
michael@0 | 1366 | bool |
michael@0 | 1367 | IndexedDBIndexParent::RecvPIndexedDBRequestConstructor( |
michael@0 | 1368 | PIndexedDBRequestParent* aActor, |
michael@0 | 1369 | const IndexRequestParams& aParams) |
michael@0 | 1370 | { |
michael@0 | 1371 | if (IsDisconnected()) { |
michael@0 | 1372 | // We're shutting down, ignore this request. |
michael@0 | 1373 | return true; |
michael@0 | 1374 | } |
michael@0 | 1375 | |
michael@0 | 1376 | if (!mIndex) { |
michael@0 | 1377 | return true; |
michael@0 | 1378 | } |
michael@0 | 1379 | |
michael@0 | 1380 | IndexedDBIndexRequestParent* actor = |
michael@0 | 1381 | static_cast<IndexedDBIndexRequestParent*>(aActor); |
michael@0 | 1382 | |
michael@0 | 1383 | if (mIndex->ObjectStore()->Transaction()->Database()->IsInvalidated()) { |
michael@0 | 1384 | // If we've invalidated this database in the parent then we should bail out |
michael@0 | 1385 | // now to avoid logic problems that could force-kill the child. |
michael@0 | 1386 | return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); |
michael@0 | 1387 | } |
michael@0 | 1388 | |
michael@0 | 1389 | switch (aParams.type()) { |
michael@0 | 1390 | case IndexRequestParams::TGetParams: |
michael@0 | 1391 | return actor->Get(aParams.get_GetParams()); |
michael@0 | 1392 | |
michael@0 | 1393 | case IndexRequestParams::TGetKeyParams: |
michael@0 | 1394 | return actor->GetKey(aParams.get_GetKeyParams()); |
michael@0 | 1395 | |
michael@0 | 1396 | case IndexRequestParams::TGetAllParams: |
michael@0 | 1397 | return actor->GetAll(aParams.get_GetAllParams()); |
michael@0 | 1398 | |
michael@0 | 1399 | case IndexRequestParams::TGetAllKeysParams: |
michael@0 | 1400 | return actor->GetAllKeys(aParams.get_GetAllKeysParams()); |
michael@0 | 1401 | |
michael@0 | 1402 | case IndexRequestParams::TCountParams: |
michael@0 | 1403 | return actor->Count(aParams.get_CountParams()); |
michael@0 | 1404 | |
michael@0 | 1405 | case IndexRequestParams::TOpenCursorParams: |
michael@0 | 1406 | return actor->OpenCursor(aParams.get_OpenCursorParams()); |
michael@0 | 1407 | |
michael@0 | 1408 | case IndexRequestParams::TOpenKeyCursorParams: |
michael@0 | 1409 | return actor->OpenKeyCursor(aParams.get_OpenKeyCursorParams()); |
michael@0 | 1410 | |
michael@0 | 1411 | default: |
michael@0 | 1412 | MOZ_CRASH("Unknown type!"); |
michael@0 | 1413 | } |
michael@0 | 1414 | |
michael@0 | 1415 | MOZ_CRASH("Should never get here!"); |
michael@0 | 1416 | } |
michael@0 | 1417 | |
michael@0 | 1418 | PIndexedDBRequestParent* |
michael@0 | 1419 | IndexedDBIndexParent::AllocPIndexedDBRequestParent(const IndexRequestParams& aParams) |
michael@0 | 1420 | { |
michael@0 | 1421 | return new IndexedDBIndexRequestParent(mIndex, aParams.type()); |
michael@0 | 1422 | } |
michael@0 | 1423 | |
michael@0 | 1424 | bool |
michael@0 | 1425 | IndexedDBIndexParent::DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) |
michael@0 | 1426 | { |
michael@0 | 1427 | delete aActor; |
michael@0 | 1428 | return true; |
michael@0 | 1429 | } |
michael@0 | 1430 | |
michael@0 | 1431 | PIndexedDBCursorParent* |
michael@0 | 1432 | IndexedDBIndexParent::AllocPIndexedDBCursorParent( |
michael@0 | 1433 | const IndexCursorConstructorParams& aParams) |
michael@0 | 1434 | { |
michael@0 | 1435 | MOZ_CRASH("Caller is supposed to manually construct a cursor!"); |
michael@0 | 1436 | } |
michael@0 | 1437 | |
michael@0 | 1438 | bool |
michael@0 | 1439 | IndexedDBIndexParent::DeallocPIndexedDBCursorParent(PIndexedDBCursorParent* aActor) |
michael@0 | 1440 | { |
michael@0 | 1441 | delete aActor; |
michael@0 | 1442 | return true; |
michael@0 | 1443 | } |
michael@0 | 1444 | |
michael@0 | 1445 | /******************************************************************************* |
michael@0 | 1446 | * IndexedDBRequestParentBase |
michael@0 | 1447 | ******************************************************************************/ |
michael@0 | 1448 | |
michael@0 | 1449 | IndexedDBRequestParentBase::IndexedDBRequestParentBase() |
michael@0 | 1450 | { |
michael@0 | 1451 | MOZ_COUNT_CTOR(IndexedDBRequestParentBase); |
michael@0 | 1452 | } |
michael@0 | 1453 | |
michael@0 | 1454 | IndexedDBRequestParentBase::~IndexedDBRequestParentBase() |
michael@0 | 1455 | { |
michael@0 | 1456 | MOZ_COUNT_DTOR(IndexedDBRequestParentBase); |
michael@0 | 1457 | } |
michael@0 | 1458 | |
michael@0 | 1459 | void |
michael@0 | 1460 | IndexedDBRequestParentBase::ActorDestroy(ActorDestroyReason aWhy) |
michael@0 | 1461 | { |
michael@0 | 1462 | if (mRequest) { |
michael@0 | 1463 | mRequest->SetActor(nullptr); |
michael@0 | 1464 | } |
michael@0 | 1465 | } |
michael@0 | 1466 | |
michael@0 | 1467 | /******************************************************************************* |
michael@0 | 1468 | * IndexedDBObjectStoreRequestParent |
michael@0 | 1469 | ******************************************************************************/ |
michael@0 | 1470 | |
michael@0 | 1471 | IndexedDBObjectStoreRequestParent::IndexedDBObjectStoreRequestParent( |
michael@0 | 1472 | IDBObjectStore* aObjectStore, |
michael@0 | 1473 | RequestType aRequestType) |
michael@0 | 1474 | : mObjectStore(aObjectStore), mRequestType(aRequestType) |
michael@0 | 1475 | { |
michael@0 | 1476 | MOZ_COUNT_CTOR(IndexedDBObjectStoreRequestParent); |
michael@0 | 1477 | // Sadly can't assert aObjectStore here... |
michael@0 | 1478 | MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && |
michael@0 | 1479 | aRequestType <= ParamsUnionType::T__Last); |
michael@0 | 1480 | } |
michael@0 | 1481 | |
michael@0 | 1482 | IndexedDBObjectStoreRequestParent::~IndexedDBObjectStoreRequestParent() |
michael@0 | 1483 | { |
michael@0 | 1484 | MOZ_COUNT_DTOR(IndexedDBObjectStoreRequestParent); |
michael@0 | 1485 | } |
michael@0 | 1486 | |
michael@0 | 1487 | void |
michael@0 | 1488 | IndexedDBObjectStoreRequestParent::ConvertBlobActors( |
michael@0 | 1489 | const InfallibleTArray<PBlobParent*>& aActors, |
michael@0 | 1490 | nsTArray<nsCOMPtr<nsIDOMBlob> >& aBlobs) |
michael@0 | 1491 | { |
michael@0 | 1492 | MOZ_ASSERT(aBlobs.IsEmpty()); |
michael@0 | 1493 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1494 | |
michael@0 | 1495 | if (!aActors.IsEmpty()) { |
michael@0 | 1496 | // Walk the chain to get to ContentParent. |
michael@0 | 1497 | MOZ_ASSERT(mObjectStore->Transaction()->Database()->GetContentParent()); |
michael@0 | 1498 | |
michael@0 | 1499 | uint32_t length = aActors.Length(); |
michael@0 | 1500 | aBlobs.SetCapacity(length); |
michael@0 | 1501 | |
michael@0 | 1502 | for (uint32_t index = 0; index < length; index++) { |
michael@0 | 1503 | BlobParent* actor = static_cast<BlobParent*>(aActors[index]); |
michael@0 | 1504 | nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob(); |
michael@0 | 1505 | aBlobs.AppendElement(blob); |
michael@0 | 1506 | } |
michael@0 | 1507 | } |
michael@0 | 1508 | } |
michael@0 | 1509 | |
michael@0 | 1510 | bool |
michael@0 | 1511 | IndexedDBObjectStoreRequestParent::IsDisconnected() |
michael@0 | 1512 | { |
michael@0 | 1513 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1514 | MOZ_ASSERT(mObjectStore->GetActorParent()); |
michael@0 | 1515 | return mObjectStore->GetActorParent()->IsDisconnected(); |
michael@0 | 1516 | } |
michael@0 | 1517 | |
michael@0 | 1518 | bool |
michael@0 | 1519 | IndexedDBObjectStoreRequestParent::Get(const GetParams& aParams) |
michael@0 | 1520 | { |
michael@0 | 1521 | MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams); |
michael@0 | 1522 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1523 | |
michael@0 | 1524 | nsRefPtr<IDBRequest> request; |
michael@0 | 1525 | |
michael@0 | 1526 | nsRefPtr<IDBKeyRange> keyRange = |
michael@0 | 1527 | IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); |
michael@0 | 1528 | MOZ_ASSERT(keyRange); |
michael@0 | 1529 | |
michael@0 | 1530 | { |
michael@0 | 1531 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1532 | |
michael@0 | 1533 | ErrorResult rv; |
michael@0 | 1534 | request = mObjectStore->GetInternal(keyRange, rv); |
michael@0 | 1535 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1536 | } |
michael@0 | 1537 | |
michael@0 | 1538 | request->SetActor(this); |
michael@0 | 1539 | mRequest.swap(request); |
michael@0 | 1540 | |
michael@0 | 1541 | return true; |
michael@0 | 1542 | } |
michael@0 | 1543 | |
michael@0 | 1544 | bool |
michael@0 | 1545 | IndexedDBObjectStoreRequestParent::GetAll(const GetAllParams& aParams) |
michael@0 | 1546 | { |
michael@0 | 1547 | MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams); |
michael@0 | 1548 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1549 | |
michael@0 | 1550 | nsRefPtr<IDBRequest> request; |
michael@0 | 1551 | |
michael@0 | 1552 | const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
michael@0 | 1553 | |
michael@0 | 1554 | nsRefPtr<IDBKeyRange> keyRange; |
michael@0 | 1555 | |
michael@0 | 1556 | switch (keyRangeUnion.type()) { |
michael@0 | 1557 | case ipc::OptionalKeyRange::TKeyRange: |
michael@0 | 1558 | keyRange = |
michael@0 | 1559 | IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
michael@0 | 1560 | break; |
michael@0 | 1561 | |
michael@0 | 1562 | case ipc::OptionalKeyRange::Tvoid_t: |
michael@0 | 1563 | break; |
michael@0 | 1564 | |
michael@0 | 1565 | default: |
michael@0 | 1566 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 1567 | } |
michael@0 | 1568 | |
michael@0 | 1569 | { |
michael@0 | 1570 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1571 | |
michael@0 | 1572 | ErrorResult rv; |
michael@0 | 1573 | request = mObjectStore->GetAllInternal(keyRange, aParams.limit(), rv); |
michael@0 | 1574 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1575 | } |
michael@0 | 1576 | |
michael@0 | 1577 | request->SetActor(this); |
michael@0 | 1578 | mRequest.swap(request); |
michael@0 | 1579 | return true; |
michael@0 | 1580 | } |
michael@0 | 1581 | |
michael@0 | 1582 | bool |
michael@0 | 1583 | IndexedDBObjectStoreRequestParent::GetAllKeys(const GetAllKeysParams& aParams) |
michael@0 | 1584 | { |
michael@0 | 1585 | MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams); |
michael@0 | 1586 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1587 | |
michael@0 | 1588 | nsRefPtr<IDBRequest> request; |
michael@0 | 1589 | |
michael@0 | 1590 | const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
michael@0 | 1591 | |
michael@0 | 1592 | nsRefPtr<IDBKeyRange> keyRange; |
michael@0 | 1593 | |
michael@0 | 1594 | switch (keyRangeUnion.type()) { |
michael@0 | 1595 | case ipc::OptionalKeyRange::TKeyRange: |
michael@0 | 1596 | keyRange = |
michael@0 | 1597 | IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
michael@0 | 1598 | break; |
michael@0 | 1599 | |
michael@0 | 1600 | case ipc::OptionalKeyRange::Tvoid_t: |
michael@0 | 1601 | break; |
michael@0 | 1602 | |
michael@0 | 1603 | default: |
michael@0 | 1604 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 1605 | } |
michael@0 | 1606 | |
michael@0 | 1607 | { |
michael@0 | 1608 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1609 | |
michael@0 | 1610 | ErrorResult rv; |
michael@0 | 1611 | request = mObjectStore->GetAllKeysInternal(keyRange, aParams.limit(), rv); |
michael@0 | 1612 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1613 | } |
michael@0 | 1614 | |
michael@0 | 1615 | request->SetActor(this); |
michael@0 | 1616 | mRequest.swap(request); |
michael@0 | 1617 | return true; |
michael@0 | 1618 | } |
michael@0 | 1619 | |
michael@0 | 1620 | bool |
michael@0 | 1621 | IndexedDBObjectStoreRequestParent::Add(const AddParams& aParams) |
michael@0 | 1622 | { |
michael@0 | 1623 | MOZ_ASSERT(mRequestType == ParamsUnionType::TAddParams); |
michael@0 | 1624 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1625 | |
michael@0 | 1626 | ipc::AddPutParams params = aParams.commonParams(); |
michael@0 | 1627 | |
michael@0 | 1628 | nsTArray<nsCOMPtr<nsIDOMBlob> > blobs; |
michael@0 | 1629 | ConvertBlobActors(params.blobsParent(), blobs); |
michael@0 | 1630 | |
michael@0 | 1631 | nsRefPtr<IDBRequest> request; |
michael@0 | 1632 | |
michael@0 | 1633 | { |
michael@0 | 1634 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1635 | |
michael@0 | 1636 | nsresult rv = |
michael@0 | 1637 | mObjectStore->AddOrPutInternal(params.cloneInfo(), params.key(), |
michael@0 | 1638 | params.indexUpdateInfos(), blobs, false, |
michael@0 | 1639 | getter_AddRefs(request)); |
michael@0 | 1640 | NS_ENSURE_SUCCESS(rv, false); |
michael@0 | 1641 | } |
michael@0 | 1642 | |
michael@0 | 1643 | request->SetActor(this); |
michael@0 | 1644 | mRequest.swap(request); |
michael@0 | 1645 | return true; |
michael@0 | 1646 | } |
michael@0 | 1647 | |
michael@0 | 1648 | bool |
michael@0 | 1649 | IndexedDBObjectStoreRequestParent::Put(const PutParams& aParams) |
michael@0 | 1650 | { |
michael@0 | 1651 | MOZ_ASSERT(mRequestType == ParamsUnionType::TPutParams); |
michael@0 | 1652 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1653 | |
michael@0 | 1654 | ipc::AddPutParams params = aParams.commonParams(); |
michael@0 | 1655 | |
michael@0 | 1656 | nsTArray<nsCOMPtr<nsIDOMBlob> > blobs; |
michael@0 | 1657 | ConvertBlobActors(params.blobsParent(), blobs); |
michael@0 | 1658 | |
michael@0 | 1659 | nsRefPtr<IDBRequest> request; |
michael@0 | 1660 | |
michael@0 | 1661 | { |
michael@0 | 1662 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1663 | |
michael@0 | 1664 | nsresult rv = |
michael@0 | 1665 | mObjectStore->AddOrPutInternal(params.cloneInfo(), params.key(), |
michael@0 | 1666 | params.indexUpdateInfos(), blobs, true, |
michael@0 | 1667 | getter_AddRefs(request)); |
michael@0 | 1668 | NS_ENSURE_SUCCESS(rv, false); |
michael@0 | 1669 | } |
michael@0 | 1670 | |
michael@0 | 1671 | request->SetActor(this); |
michael@0 | 1672 | mRequest.swap(request); |
michael@0 | 1673 | return true; |
michael@0 | 1674 | } |
michael@0 | 1675 | |
michael@0 | 1676 | bool |
michael@0 | 1677 | IndexedDBObjectStoreRequestParent::Delete(const DeleteParams& aParams) |
michael@0 | 1678 | { |
michael@0 | 1679 | MOZ_ASSERT(mRequestType == ParamsUnionType::TDeleteParams); |
michael@0 | 1680 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1681 | |
michael@0 | 1682 | nsRefPtr<IDBRequest> request; |
michael@0 | 1683 | |
michael@0 | 1684 | nsRefPtr<IDBKeyRange> keyRange = |
michael@0 | 1685 | IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); |
michael@0 | 1686 | MOZ_ASSERT(keyRange); |
michael@0 | 1687 | |
michael@0 | 1688 | { |
michael@0 | 1689 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1690 | |
michael@0 | 1691 | ErrorResult rv; |
michael@0 | 1692 | request = mObjectStore->DeleteInternal(keyRange, rv); |
michael@0 | 1693 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1694 | } |
michael@0 | 1695 | |
michael@0 | 1696 | request->SetActor(this); |
michael@0 | 1697 | mRequest.swap(request); |
michael@0 | 1698 | return true; |
michael@0 | 1699 | } |
michael@0 | 1700 | |
michael@0 | 1701 | bool |
michael@0 | 1702 | IndexedDBObjectStoreRequestParent::Clear(const ClearParams& aParams) |
michael@0 | 1703 | { |
michael@0 | 1704 | MOZ_ASSERT(mRequestType == ParamsUnionType::TClearParams); |
michael@0 | 1705 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1706 | |
michael@0 | 1707 | nsRefPtr<IDBRequest> request; |
michael@0 | 1708 | |
michael@0 | 1709 | { |
michael@0 | 1710 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1711 | |
michael@0 | 1712 | ErrorResult rv; |
michael@0 | 1713 | request = mObjectStore->Clear(rv); |
michael@0 | 1714 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1715 | } |
michael@0 | 1716 | |
michael@0 | 1717 | request->SetActor(this); |
michael@0 | 1718 | mRequest.swap(request); |
michael@0 | 1719 | return true; |
michael@0 | 1720 | } |
michael@0 | 1721 | |
michael@0 | 1722 | bool |
michael@0 | 1723 | IndexedDBObjectStoreRequestParent::Count(const CountParams& aParams) |
michael@0 | 1724 | { |
michael@0 | 1725 | MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams); |
michael@0 | 1726 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1727 | |
michael@0 | 1728 | const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
michael@0 | 1729 | |
michael@0 | 1730 | nsRefPtr<IDBKeyRange> keyRange; |
michael@0 | 1731 | |
michael@0 | 1732 | switch (keyRangeUnion.type()) { |
michael@0 | 1733 | case ipc::OptionalKeyRange::TKeyRange: |
michael@0 | 1734 | keyRange = |
michael@0 | 1735 | IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
michael@0 | 1736 | break; |
michael@0 | 1737 | |
michael@0 | 1738 | case ipc::OptionalKeyRange::Tvoid_t: |
michael@0 | 1739 | break; |
michael@0 | 1740 | |
michael@0 | 1741 | default: |
michael@0 | 1742 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 1743 | } |
michael@0 | 1744 | |
michael@0 | 1745 | nsRefPtr<IDBRequest> request; |
michael@0 | 1746 | |
michael@0 | 1747 | { |
michael@0 | 1748 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1749 | |
michael@0 | 1750 | ErrorResult rv; |
michael@0 | 1751 | request = mObjectStore->CountInternal(keyRange, rv); |
michael@0 | 1752 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1753 | } |
michael@0 | 1754 | |
michael@0 | 1755 | request->SetActor(this); |
michael@0 | 1756 | mRequest.swap(request); |
michael@0 | 1757 | return true; |
michael@0 | 1758 | } |
michael@0 | 1759 | |
michael@0 | 1760 | bool |
michael@0 | 1761 | IndexedDBObjectStoreRequestParent::OpenCursor(const OpenCursorParams& aParams) |
michael@0 | 1762 | { |
michael@0 | 1763 | MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams); |
michael@0 | 1764 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1765 | |
michael@0 | 1766 | const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
michael@0 | 1767 | |
michael@0 | 1768 | nsRefPtr<IDBKeyRange> keyRange; |
michael@0 | 1769 | |
michael@0 | 1770 | switch (keyRangeUnion.type()) { |
michael@0 | 1771 | case ipc::OptionalKeyRange::TKeyRange: |
michael@0 | 1772 | keyRange = |
michael@0 | 1773 | IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
michael@0 | 1774 | break; |
michael@0 | 1775 | |
michael@0 | 1776 | case ipc::OptionalKeyRange::Tvoid_t: |
michael@0 | 1777 | break; |
michael@0 | 1778 | |
michael@0 | 1779 | default: |
michael@0 | 1780 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 1781 | } |
michael@0 | 1782 | |
michael@0 | 1783 | size_t direction = static_cast<size_t>(aParams.direction()); |
michael@0 | 1784 | |
michael@0 | 1785 | nsRefPtr<IDBRequest> request; |
michael@0 | 1786 | |
michael@0 | 1787 | { |
michael@0 | 1788 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1789 | |
michael@0 | 1790 | ErrorResult rv; |
michael@0 | 1791 | request = mObjectStore->OpenCursorInternal(keyRange, direction, rv); |
michael@0 | 1792 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1793 | } |
michael@0 | 1794 | |
michael@0 | 1795 | request->SetActor(this); |
michael@0 | 1796 | mRequest.swap(request); |
michael@0 | 1797 | return true; |
michael@0 | 1798 | } |
michael@0 | 1799 | |
michael@0 | 1800 | bool |
michael@0 | 1801 | IndexedDBObjectStoreRequestParent::OpenKeyCursor( |
michael@0 | 1802 | const OpenKeyCursorParams& aParams) |
michael@0 | 1803 | { |
michael@0 | 1804 | MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenKeyCursorParams); |
michael@0 | 1805 | MOZ_ASSERT(mObjectStore); |
michael@0 | 1806 | |
michael@0 | 1807 | const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
michael@0 | 1808 | |
michael@0 | 1809 | nsRefPtr<IDBKeyRange> keyRange; |
michael@0 | 1810 | |
michael@0 | 1811 | switch (keyRangeUnion.type()) { |
michael@0 | 1812 | case ipc::OptionalKeyRange::TKeyRange: |
michael@0 | 1813 | keyRange = |
michael@0 | 1814 | IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
michael@0 | 1815 | break; |
michael@0 | 1816 | |
michael@0 | 1817 | case ipc::OptionalKeyRange::Tvoid_t: |
michael@0 | 1818 | break; |
michael@0 | 1819 | |
michael@0 | 1820 | default: |
michael@0 | 1821 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 1822 | } |
michael@0 | 1823 | |
michael@0 | 1824 | size_t direction = static_cast<size_t>(aParams.direction()); |
michael@0 | 1825 | |
michael@0 | 1826 | nsRefPtr<IDBRequest> request; |
michael@0 | 1827 | |
michael@0 | 1828 | { |
michael@0 | 1829 | AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
michael@0 | 1830 | |
michael@0 | 1831 | ErrorResult rv; |
michael@0 | 1832 | request = mObjectStore->OpenKeyCursorInternal(keyRange, direction, rv); |
michael@0 | 1833 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1834 | } |
michael@0 | 1835 | |
michael@0 | 1836 | request->SetActor(this); |
michael@0 | 1837 | mRequest.swap(request); |
michael@0 | 1838 | return true; |
michael@0 | 1839 | } |
michael@0 | 1840 | |
michael@0 | 1841 | /******************************************************************************* |
michael@0 | 1842 | * IndexedDBIndexRequestParent |
michael@0 | 1843 | ******************************************************************************/ |
michael@0 | 1844 | |
michael@0 | 1845 | IndexedDBIndexRequestParent::IndexedDBIndexRequestParent( |
michael@0 | 1846 | IDBIndex* aIndex, |
michael@0 | 1847 | RequestType aRequestType) |
michael@0 | 1848 | : mIndex(aIndex), mRequestType(aRequestType) |
michael@0 | 1849 | { |
michael@0 | 1850 | MOZ_COUNT_CTOR(IndexedDBIndexRequestParent); |
michael@0 | 1851 | // Sadly can't assert aIndex here... |
michael@0 | 1852 | MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && |
michael@0 | 1853 | aRequestType <= ParamsUnionType::T__Last); |
michael@0 | 1854 | } |
michael@0 | 1855 | |
michael@0 | 1856 | IndexedDBIndexRequestParent::~IndexedDBIndexRequestParent() |
michael@0 | 1857 | { |
michael@0 | 1858 | MOZ_COUNT_DTOR(IndexedDBIndexRequestParent); |
michael@0 | 1859 | } |
michael@0 | 1860 | |
michael@0 | 1861 | bool |
michael@0 | 1862 | IndexedDBIndexRequestParent::IsDisconnected() |
michael@0 | 1863 | { |
michael@0 | 1864 | MOZ_ASSERT(mIndex); |
michael@0 | 1865 | MOZ_ASSERT(mIndex->GetActorParent()); |
michael@0 | 1866 | return mIndex->GetActorParent()->IsDisconnected(); |
michael@0 | 1867 | } |
michael@0 | 1868 | |
michael@0 | 1869 | bool |
michael@0 | 1870 | IndexedDBIndexRequestParent::Get(const GetParams& aParams) |
michael@0 | 1871 | { |
michael@0 | 1872 | MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams); |
michael@0 | 1873 | MOZ_ASSERT(mIndex); |
michael@0 | 1874 | |
michael@0 | 1875 | nsRefPtr<IDBRequest> request; |
michael@0 | 1876 | |
michael@0 | 1877 | nsRefPtr<IDBKeyRange> keyRange = |
michael@0 | 1878 | IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); |
michael@0 | 1879 | MOZ_ASSERT(keyRange); |
michael@0 | 1880 | |
michael@0 | 1881 | { |
michael@0 | 1882 | AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
michael@0 | 1883 | |
michael@0 | 1884 | ErrorResult rv; |
michael@0 | 1885 | request = mIndex->GetInternal(keyRange, rv); |
michael@0 | 1886 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1887 | } |
michael@0 | 1888 | |
michael@0 | 1889 | request->SetActor(this); |
michael@0 | 1890 | mRequest.swap(request); |
michael@0 | 1891 | return true; |
michael@0 | 1892 | } |
michael@0 | 1893 | |
michael@0 | 1894 | bool |
michael@0 | 1895 | IndexedDBIndexRequestParent::GetKey(const GetKeyParams& aParams) |
michael@0 | 1896 | { |
michael@0 | 1897 | MOZ_ASSERT(mRequestType == ParamsUnionType::TGetKeyParams); |
michael@0 | 1898 | MOZ_ASSERT(mIndex); |
michael@0 | 1899 | |
michael@0 | 1900 | nsRefPtr<IDBRequest> request; |
michael@0 | 1901 | |
michael@0 | 1902 | nsRefPtr<IDBKeyRange> keyRange = |
michael@0 | 1903 | IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); |
michael@0 | 1904 | MOZ_ASSERT(keyRange); |
michael@0 | 1905 | |
michael@0 | 1906 | { |
michael@0 | 1907 | AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
michael@0 | 1908 | |
michael@0 | 1909 | ErrorResult rv; |
michael@0 | 1910 | request = mIndex->GetKeyInternal(keyRange, rv); |
michael@0 | 1911 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1912 | } |
michael@0 | 1913 | |
michael@0 | 1914 | request->SetActor(this); |
michael@0 | 1915 | mRequest.swap(request); |
michael@0 | 1916 | return true; |
michael@0 | 1917 | } |
michael@0 | 1918 | |
michael@0 | 1919 | bool |
michael@0 | 1920 | IndexedDBIndexRequestParent::GetAll(const GetAllParams& aParams) |
michael@0 | 1921 | { |
michael@0 | 1922 | MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams); |
michael@0 | 1923 | MOZ_ASSERT(mIndex); |
michael@0 | 1924 | |
michael@0 | 1925 | nsRefPtr<IDBRequest> request; |
michael@0 | 1926 | |
michael@0 | 1927 | const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
michael@0 | 1928 | |
michael@0 | 1929 | nsRefPtr<IDBKeyRange> keyRange; |
michael@0 | 1930 | |
michael@0 | 1931 | switch (keyRangeUnion.type()) { |
michael@0 | 1932 | case ipc::OptionalKeyRange::TKeyRange: |
michael@0 | 1933 | keyRange = |
michael@0 | 1934 | IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
michael@0 | 1935 | break; |
michael@0 | 1936 | |
michael@0 | 1937 | case ipc::OptionalKeyRange::Tvoid_t: |
michael@0 | 1938 | break; |
michael@0 | 1939 | |
michael@0 | 1940 | default: |
michael@0 | 1941 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 1942 | } |
michael@0 | 1943 | |
michael@0 | 1944 | { |
michael@0 | 1945 | AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
michael@0 | 1946 | |
michael@0 | 1947 | ErrorResult rv; |
michael@0 | 1948 | request = mIndex->GetAllInternal(keyRange, aParams.limit(), rv); |
michael@0 | 1949 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1950 | } |
michael@0 | 1951 | |
michael@0 | 1952 | request->SetActor(this); |
michael@0 | 1953 | mRequest.swap(request); |
michael@0 | 1954 | return true; |
michael@0 | 1955 | } |
michael@0 | 1956 | |
michael@0 | 1957 | bool |
michael@0 | 1958 | IndexedDBIndexRequestParent::GetAllKeys(const GetAllKeysParams& aParams) |
michael@0 | 1959 | { |
michael@0 | 1960 | MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams); |
michael@0 | 1961 | MOZ_ASSERT(mIndex); |
michael@0 | 1962 | |
michael@0 | 1963 | nsRefPtr<IDBRequest> request; |
michael@0 | 1964 | |
michael@0 | 1965 | const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
michael@0 | 1966 | |
michael@0 | 1967 | nsRefPtr<IDBKeyRange> keyRange; |
michael@0 | 1968 | |
michael@0 | 1969 | switch (keyRangeUnion.type()) { |
michael@0 | 1970 | case ipc::OptionalKeyRange::TKeyRange: |
michael@0 | 1971 | keyRange = |
michael@0 | 1972 | IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
michael@0 | 1973 | break; |
michael@0 | 1974 | |
michael@0 | 1975 | case ipc::OptionalKeyRange::Tvoid_t: |
michael@0 | 1976 | break; |
michael@0 | 1977 | |
michael@0 | 1978 | default: |
michael@0 | 1979 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 1980 | } |
michael@0 | 1981 | |
michael@0 | 1982 | { |
michael@0 | 1983 | AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
michael@0 | 1984 | |
michael@0 | 1985 | ErrorResult rv; |
michael@0 | 1986 | request = mIndex->GetAllKeysInternal(keyRange, aParams.limit(), rv); |
michael@0 | 1987 | ENSURE_SUCCESS(rv, false); |
michael@0 | 1988 | } |
michael@0 | 1989 | |
michael@0 | 1990 | request->SetActor(this); |
michael@0 | 1991 | mRequest.swap(request); |
michael@0 | 1992 | return true; |
michael@0 | 1993 | } |
michael@0 | 1994 | |
michael@0 | 1995 | bool |
michael@0 | 1996 | IndexedDBIndexRequestParent::Count(const CountParams& aParams) |
michael@0 | 1997 | { |
michael@0 | 1998 | MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams); |
michael@0 | 1999 | MOZ_ASSERT(mIndex); |
michael@0 | 2000 | |
michael@0 | 2001 | const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
michael@0 | 2002 | |
michael@0 | 2003 | nsRefPtr<IDBKeyRange> keyRange; |
michael@0 | 2004 | |
michael@0 | 2005 | switch (keyRangeUnion.type()) { |
michael@0 | 2006 | case ipc::OptionalKeyRange::TKeyRange: |
michael@0 | 2007 | keyRange = |
michael@0 | 2008 | IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
michael@0 | 2009 | break; |
michael@0 | 2010 | |
michael@0 | 2011 | case ipc::OptionalKeyRange::Tvoid_t: |
michael@0 | 2012 | break; |
michael@0 | 2013 | |
michael@0 | 2014 | default: |
michael@0 | 2015 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 2016 | } |
michael@0 | 2017 | |
michael@0 | 2018 | nsRefPtr<IDBRequest> request; |
michael@0 | 2019 | |
michael@0 | 2020 | { |
michael@0 | 2021 | AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
michael@0 | 2022 | |
michael@0 | 2023 | ErrorResult rv; |
michael@0 | 2024 | request = mIndex->CountInternal(keyRange, rv); |
michael@0 | 2025 | ENSURE_SUCCESS(rv, false); |
michael@0 | 2026 | } |
michael@0 | 2027 | |
michael@0 | 2028 | request->SetActor(this); |
michael@0 | 2029 | mRequest.swap(request); |
michael@0 | 2030 | return true; |
michael@0 | 2031 | } |
michael@0 | 2032 | |
michael@0 | 2033 | bool |
michael@0 | 2034 | IndexedDBIndexRequestParent::OpenCursor(const OpenCursorParams& aParams) |
michael@0 | 2035 | { |
michael@0 | 2036 | MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams); |
michael@0 | 2037 | MOZ_ASSERT(mIndex); |
michael@0 | 2038 | |
michael@0 | 2039 | const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
michael@0 | 2040 | |
michael@0 | 2041 | nsRefPtr<IDBKeyRange> keyRange; |
michael@0 | 2042 | |
michael@0 | 2043 | switch (keyRangeUnion.type()) { |
michael@0 | 2044 | case ipc::OptionalKeyRange::TKeyRange: |
michael@0 | 2045 | keyRange = |
michael@0 | 2046 | IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
michael@0 | 2047 | break; |
michael@0 | 2048 | |
michael@0 | 2049 | case ipc::OptionalKeyRange::Tvoid_t: |
michael@0 | 2050 | break; |
michael@0 | 2051 | |
michael@0 | 2052 | default: |
michael@0 | 2053 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 2054 | } |
michael@0 | 2055 | |
michael@0 | 2056 | size_t direction = static_cast<size_t>(aParams.direction()); |
michael@0 | 2057 | |
michael@0 | 2058 | nsRefPtr<IDBRequest> request; |
michael@0 | 2059 | |
michael@0 | 2060 | { |
michael@0 | 2061 | AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
michael@0 | 2062 | |
michael@0 | 2063 | nsresult rv = |
michael@0 | 2064 | mIndex->OpenCursorInternal(keyRange, direction, getter_AddRefs(request)); |
michael@0 | 2065 | NS_ENSURE_SUCCESS(rv, false); |
michael@0 | 2066 | } |
michael@0 | 2067 | |
michael@0 | 2068 | request->SetActor(this); |
michael@0 | 2069 | mRequest.swap(request); |
michael@0 | 2070 | return true; |
michael@0 | 2071 | } |
michael@0 | 2072 | |
michael@0 | 2073 | bool |
michael@0 | 2074 | IndexedDBIndexRequestParent::OpenKeyCursor(const OpenKeyCursorParams& aParams) |
michael@0 | 2075 | { |
michael@0 | 2076 | MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenKeyCursorParams); |
michael@0 | 2077 | MOZ_ASSERT(mIndex); |
michael@0 | 2078 | |
michael@0 | 2079 | const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
michael@0 | 2080 | |
michael@0 | 2081 | nsRefPtr<IDBKeyRange> keyRange; |
michael@0 | 2082 | |
michael@0 | 2083 | switch (keyRangeUnion.type()) { |
michael@0 | 2084 | case ipc::OptionalKeyRange::TKeyRange: |
michael@0 | 2085 | keyRange = |
michael@0 | 2086 | IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
michael@0 | 2087 | break; |
michael@0 | 2088 | |
michael@0 | 2089 | case ipc::OptionalKeyRange::Tvoid_t: |
michael@0 | 2090 | break; |
michael@0 | 2091 | |
michael@0 | 2092 | default: |
michael@0 | 2093 | MOZ_CRASH("Unknown param type!"); |
michael@0 | 2094 | } |
michael@0 | 2095 | |
michael@0 | 2096 | size_t direction = static_cast<size_t>(aParams.direction()); |
michael@0 | 2097 | |
michael@0 | 2098 | nsRefPtr<IDBRequest> request; |
michael@0 | 2099 | |
michael@0 | 2100 | { |
michael@0 | 2101 | AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
michael@0 | 2102 | |
michael@0 | 2103 | ErrorResult rv; |
michael@0 | 2104 | request = mIndex->OpenKeyCursorInternal(keyRange, direction, rv); |
michael@0 | 2105 | ENSURE_SUCCESS(rv, false); |
michael@0 | 2106 | } |
michael@0 | 2107 | |
michael@0 | 2108 | request->SetActor(this); |
michael@0 | 2109 | mRequest.swap(request); |
michael@0 | 2110 | return true; |
michael@0 | 2111 | } |
michael@0 | 2112 | |
michael@0 | 2113 | /******************************************************************************* |
michael@0 | 2114 | * IndexedDBCursorRequestParent |
michael@0 | 2115 | ******************************************************************************/ |
michael@0 | 2116 | |
michael@0 | 2117 | IndexedDBCursorRequestParent::IndexedDBCursorRequestParent( |
michael@0 | 2118 | IDBCursor* aCursor, |
michael@0 | 2119 | RequestType aRequestType) |
michael@0 | 2120 | : mCursor(aCursor), mRequestType(aRequestType) |
michael@0 | 2121 | { |
michael@0 | 2122 | MOZ_COUNT_CTOR(IndexedDBCursorRequestParent); |
michael@0 | 2123 | MOZ_ASSERT(aCursor); |
michael@0 | 2124 | MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && |
michael@0 | 2125 | aRequestType <= ParamsUnionType::T__Last); |
michael@0 | 2126 | } |
michael@0 | 2127 | |
michael@0 | 2128 | IndexedDBCursorRequestParent::~IndexedDBCursorRequestParent() |
michael@0 | 2129 | { |
michael@0 | 2130 | MOZ_COUNT_DTOR(IndexedDBCursorRequestParent); |
michael@0 | 2131 | } |
michael@0 | 2132 | |
michael@0 | 2133 | bool |
michael@0 | 2134 | IndexedDBCursorRequestParent::IsDisconnected() |
michael@0 | 2135 | { |
michael@0 | 2136 | MOZ_ASSERT(mCursor); |
michael@0 | 2137 | MOZ_ASSERT(mCursor->GetActorParent()); |
michael@0 | 2138 | return mCursor->GetActorParent()->IsDisconnected(); |
michael@0 | 2139 | } |
michael@0 | 2140 | |
michael@0 | 2141 | bool |
michael@0 | 2142 | IndexedDBCursorRequestParent::Continue(const ContinueParams& aParams) |
michael@0 | 2143 | { |
michael@0 | 2144 | MOZ_ASSERT(mCursor); |
michael@0 | 2145 | MOZ_ASSERT(mRequestType == ParamsUnionType::TContinueParams); |
michael@0 | 2146 | |
michael@0 | 2147 | { |
michael@0 | 2148 | AutoSetCurrentTransaction asct(mCursor->Transaction()); |
michael@0 | 2149 | |
michael@0 | 2150 | ErrorResult rv; |
michael@0 | 2151 | mCursor->ContinueInternal(aParams.key(), aParams.count(), rv); |
michael@0 | 2152 | ENSURE_SUCCESS(rv, false); |
michael@0 | 2153 | } |
michael@0 | 2154 | |
michael@0 | 2155 | mRequest = mCursor->Request(); |
michael@0 | 2156 | MOZ_ASSERT(mRequest); |
michael@0 | 2157 | |
michael@0 | 2158 | mRequest->SetActor(this); |
michael@0 | 2159 | return true; |
michael@0 | 2160 | } |
michael@0 | 2161 | |
michael@0 | 2162 | /******************************************************************************* |
michael@0 | 2163 | * IndexedDBDeleteDatabaseRequestParent |
michael@0 | 2164 | ******************************************************************************/ |
michael@0 | 2165 | |
michael@0 | 2166 | IndexedDBDeleteDatabaseRequestParent::IndexedDBDeleteDatabaseRequestParent( |
michael@0 | 2167 | IDBFactory* aFactory) |
michael@0 | 2168 | : mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()), mFactory(aFactory) |
michael@0 | 2169 | { |
michael@0 | 2170 | MOZ_COUNT_CTOR(IndexedDBDeleteDatabaseRequestParent); |
michael@0 | 2171 | MOZ_ASSERT(aFactory); |
michael@0 | 2172 | } |
michael@0 | 2173 | |
michael@0 | 2174 | IndexedDBDeleteDatabaseRequestParent::~IndexedDBDeleteDatabaseRequestParent() |
michael@0 | 2175 | { |
michael@0 | 2176 | MOZ_COUNT_DTOR(IndexedDBDeleteDatabaseRequestParent); |
michael@0 | 2177 | } |
michael@0 | 2178 | |
michael@0 | 2179 | nsresult |
michael@0 | 2180 | IndexedDBDeleteDatabaseRequestParent::HandleEvent(nsIDOMEvent* aEvent) |
michael@0 | 2181 | { |
michael@0 | 2182 | MOZ_ASSERT(aEvent); |
michael@0 | 2183 | |
michael@0 | 2184 | if (IsDisconnected()) { |
michael@0 | 2185 | // We're shutting down, ignore this event. |
michael@0 | 2186 | return NS_OK; |
michael@0 | 2187 | } |
michael@0 | 2188 | |
michael@0 | 2189 | nsString type; |
michael@0 | 2190 | nsresult rv = aEvent->GetType(type); |
michael@0 | 2191 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 2192 | |
michael@0 | 2193 | if (type.EqualsASCII(BLOCKED_EVT_STR)) { |
michael@0 | 2194 | nsCOMPtr<IDBVersionChangeEvent> event = do_QueryInterface(aEvent); |
michael@0 | 2195 | MOZ_ASSERT(event); |
michael@0 | 2196 | |
michael@0 | 2197 | uint64_t currentVersion = event->OldVersion(); |
michael@0 | 2198 | |
michael@0 | 2199 | if (!SendBlocked(currentVersion)) { |
michael@0 | 2200 | return NS_ERROR_FAILURE; |
michael@0 | 2201 | } |
michael@0 | 2202 | |
michael@0 | 2203 | return NS_OK; |
michael@0 | 2204 | } |
michael@0 | 2205 | |
michael@0 | 2206 | #ifdef DEBUG |
michael@0 | 2207 | if (type.EqualsASCII(SUCCESS_EVT_STR)) { |
michael@0 | 2208 | MOZ_ASSERT(NS_SUCCEEDED(mOpenRequest->GetErrorCode())); |
michael@0 | 2209 | } |
michael@0 | 2210 | else { |
michael@0 | 2211 | MOZ_ASSERT(type.EqualsASCII(ERROR_EVT_STR)); |
michael@0 | 2212 | MOZ_ASSERT(NS_FAILED(mOpenRequest->GetErrorCode())); |
michael@0 | 2213 | } |
michael@0 | 2214 | #endif |
michael@0 | 2215 | |
michael@0 | 2216 | if (!Send__delete__(this, mOpenRequest->GetErrorCode())) { |
michael@0 | 2217 | return NS_ERROR_FAILURE; |
michael@0 | 2218 | } |
michael@0 | 2219 | |
michael@0 | 2220 | return NS_OK; |
michael@0 | 2221 | } |
michael@0 | 2222 | |
michael@0 | 2223 | nsresult |
michael@0 | 2224 | IndexedDBDeleteDatabaseRequestParent::SetOpenRequest( |
michael@0 | 2225 | IDBOpenDBRequest* aOpenRequest) |
michael@0 | 2226 | { |
michael@0 | 2227 | MOZ_ASSERT(aOpenRequest); |
michael@0 | 2228 | MOZ_ASSERT(!mOpenRequest); |
michael@0 | 2229 | |
michael@0 | 2230 | EventTarget* target = static_cast<EventTarget*>(aOpenRequest); |
michael@0 | 2231 | |
michael@0 | 2232 | nsresult rv = target->AddEventListener(NS_LITERAL_STRING(SUCCESS_EVT_STR), |
michael@0 | 2233 | mEventListener, false); |
michael@0 | 2234 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 2235 | |
michael@0 | 2236 | rv = target->AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR), |
michael@0 | 2237 | mEventListener, false); |
michael@0 | 2238 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 2239 | |
michael@0 | 2240 | rv = target->AddEventListener(NS_LITERAL_STRING(BLOCKED_EVT_STR), |
michael@0 | 2241 | mEventListener, false); |
michael@0 | 2242 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 2243 | |
michael@0 | 2244 | mOpenRequest = aOpenRequest; |
michael@0 | 2245 | return NS_OK; |
michael@0 | 2246 | } |
michael@0 | 2247 | |
michael@0 | 2248 | /******************************************************************************* |
michael@0 | 2249 | * WeakEventListener |
michael@0 | 2250 | ******************************************************************************/ |
michael@0 | 2251 | |
michael@0 | 2252 | NS_IMPL_ISUPPORTS(WeakEventListenerBase, nsIDOMEventListener) |
michael@0 | 2253 | |
michael@0 | 2254 | NS_IMETHODIMP |
michael@0 | 2255 | WeakEventListenerBase::HandleEvent(nsIDOMEvent* aEvent) |
michael@0 | 2256 | { |
michael@0 | 2257 | MOZ_CRASH("This must be overridden!"); |
michael@0 | 2258 | } |