dom/indexedDB/ipc/IndexedDBParent.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "IndexedDBParent.h"
     8 #include "nsIDOMEvent.h"
     9 #include "nsIDOMFile.h"
    10 #include "nsIXPConnect.h"
    12 #include "mozilla/AppProcessChecker.h"
    13 #include "mozilla/Assertions.h"
    14 #include "mozilla/Attributes.h"
    15 #include "mozilla/dom/ContentParent.h"
    16 #include "mozilla/dom/IDBDatabaseBinding.h"
    17 #include "mozilla/dom/ipc/Blob.h"
    18 #include "mozilla/dom/TabParent.h"
    19 #include "mozilla/unused.h"
    20 #include "nsCxPusher.h"
    22 #include "AsyncConnectionHelper.h"
    23 #include "DatabaseInfo.h"
    24 #include "IDBDatabase.h"
    25 #include "IDBEvents.h"
    26 #include "IDBFactory.h"
    27 #include "IDBIndex.h"
    28 #include "IDBKeyRange.h"
    29 #include "IDBObjectStore.h"
    30 #include "IDBTransaction.h"
    32 #define CHROME_ORIGIN "chrome"
    33 #define PERMISSION_PREFIX "indexedDB-chrome-"
    34 #define PERMISSION_SUFFIX_READ "-read"
    35 #define PERMISSION_SUFFIX_WRITE "-write"
    37 USING_INDEXEDDB_NAMESPACE
    39 using namespace mozilla;
    40 using namespace mozilla::dom;
    42 /*******************************************************************************
    43  * AutoSetCurrentTransaction
    44  ******************************************************************************/
    46 AutoSetCurrentTransaction::AutoSetCurrentTransaction(
    47                                                    IDBTransaction* aTransaction)
    48 {
    49   MOZ_ASSERT(aTransaction);
    50   AsyncConnectionHelper::SetCurrentTransaction(aTransaction);
    51 }
    53 AutoSetCurrentTransaction::~AutoSetCurrentTransaction()
    54 {
    55   AsyncConnectionHelper::SetCurrentTransaction(nullptr);
    56 }
    58 /*******************************************************************************
    59  * IndexedDBParent
    60  ******************************************************************************/
    62 IndexedDBParent::IndexedDBParent(ContentParent* aContentParent)
    63 : mManagerContent(aContentParent), mManagerTab(nullptr), mDisconnected(false)
    64 {
    65   MOZ_COUNT_CTOR(IndexedDBParent);
    66   MOZ_ASSERT(aContentParent);
    67 }
    69 IndexedDBParent::IndexedDBParent(TabParent* aTabParent)
    70 : mManagerContent(nullptr), mManagerTab(aTabParent), mDisconnected(false)
    71 {
    72   MOZ_COUNT_CTOR(IndexedDBParent);
    73   MOZ_ASSERT(aTabParent);
    74 }
    76 IndexedDBParent::~IndexedDBParent()
    77 {
    78   MOZ_COUNT_DTOR(IndexedDBParent);
    79 }
    81 void
    82 IndexedDBParent::Disconnect()
    83 {
    84   if (mDisconnected) {
    85     return;
    86   }
    88   mDisconnected = true;
    90   const InfallibleTArray<PIndexedDBDatabaseParent*>& databases =
    91     ManagedPIndexedDBDatabaseParent();
    92   for (uint32_t i = 0; i < databases.Length(); ++i) {
    93     static_cast<IndexedDBDatabaseParent*>(databases[i])->Disconnect();
    94   }
    95 }
    97 bool
    98 IndexedDBParent::CheckReadPermission(const nsAString& aDatabaseName)
    99 {
   100   NS_NAMED_LITERAL_CSTRING(permission, PERMISSION_SUFFIX_READ);
   101   return CheckPermissionInternal(aDatabaseName, permission);
   102 }
   104 bool
   105 IndexedDBParent::CheckWritePermission(const nsAString& aDatabaseName)
   106 {
   107   // Write permission assumes read permission is granted as well.
   108   MOZ_ASSERT(CheckReadPermission(aDatabaseName));
   110   NS_NAMED_LITERAL_CSTRING(permission, PERMISSION_SUFFIX_WRITE);
   111   return CheckPermissionInternal(aDatabaseName, permission);
   112 }
   114 mozilla::ipc::IProtocol*
   115 IndexedDBParent::CloneProtocol(Channel* aChannel,
   116                                mozilla::ipc::ProtocolCloneContext* aCtx)
   117 {
   118   MOZ_ASSERT(mManagerContent != nullptr);
   119   MOZ_ASSERT(mManagerTab == nullptr);
   120   MOZ_ASSERT(!mDisconnected);
   121   MOZ_ASSERT(IndexedDatabaseManager::Get());
   122   MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess());
   124   ContentParent* contentParent = aCtx->GetContentParent();
   125   nsAutoPtr<PIndexedDBParent> actor(contentParent->AllocPIndexedDBParent());
   126   if (!actor || !contentParent->RecvPIndexedDBConstructor(actor)) {
   127     return nullptr;
   128   }
   129   return actor.forget();
   130 }
   132 bool
   133 IndexedDBParent::CheckPermissionInternal(const nsAString& aDatabaseName,
   134                                          const nsACString& aPermission)
   135 {
   136   MOZ_ASSERT(!mASCIIOrigin.IsEmpty());
   137   MOZ_ASSERT(mManagerContent || mManagerTab);
   139   if (mASCIIOrigin.EqualsLiteral(CHROME_ORIGIN)) {
   140     nsAutoCString fullPermission =
   141       NS_LITERAL_CSTRING(PERMISSION_PREFIX) +
   142       NS_ConvertUTF16toUTF8(aDatabaseName) +
   143       aPermission;
   145     if ((mManagerContent &&
   146          !AssertAppProcessPermission(mManagerContent, fullPermission.get())) ||
   147         (mManagerTab &&
   148          !AssertAppProcessPermission(mManagerTab, fullPermission.get()))) {
   149       return false;
   150     }
   151   }
   153   return true;
   154 }
   156 void
   157 IndexedDBParent::ActorDestroy(ActorDestroyReason aWhy)
   158 {
   159   // Nothing really needs to be done here...
   160 }
   162 bool
   163 IndexedDBParent::RecvPIndexedDBDatabaseConstructor(
   164                                         PIndexedDBDatabaseParent* aActor,
   165                                         const nsString& aName,
   166                                         const uint64_t& aVersion,
   167                                         const PersistenceType& aPersistenceType)
   168 {
   169   if (!CheckReadPermission(aName)) {
   170     return false;
   171   }
   173   if (IsDisconnected()) {
   174     // We're shutting down, ignore this request.
   175     return true;
   176   }
   178   if (!mFactory) {
   179     return true;
   180   }
   182   nsRefPtr<IDBOpenDBRequest> request;
   183   nsresult rv = mFactory->OpenInternal(aName, aVersion, aPersistenceType, false,
   184                                        getter_AddRefs(request));
   185   NS_ENSURE_SUCCESS(rv, false);
   187   IndexedDBDatabaseParent* actor =
   188     static_cast<IndexedDBDatabaseParent*>(aActor);
   190   rv = actor->SetOpenRequest(request);
   191   NS_ENSURE_SUCCESS(rv, false);
   193   return true;
   194 }
   196 bool
   197 IndexedDBParent::RecvPIndexedDBDeleteDatabaseRequestConstructor(
   198                                   PIndexedDBDeleteDatabaseRequestParent* aActor,
   199                                   const nsString& aName,
   200                                   const PersistenceType& aPersistenceType)
   201 {
   202   if (!CheckWritePermission(aName)) {
   203     return false;
   204   }
   206   if (IsDisconnected()) {
   207     // We're shutting down, ignore this request.
   208     return true;
   209   }
   211   if (!mFactory) {
   212     return true;
   213   }
   215   IndexedDBDeleteDatabaseRequestParent* actor =
   216     static_cast<IndexedDBDeleteDatabaseRequestParent*>(aActor);
   218   nsRefPtr<IDBOpenDBRequest> request;
   220   nsresult rv = mFactory->OpenInternal(aName, 0, aPersistenceType, true,
   221                                        getter_AddRefs(request));
   222   NS_ENSURE_SUCCESS(rv, false);
   224   rv = actor->SetOpenRequest(request);
   225   NS_ENSURE_SUCCESS(rv, false);
   227   return true;
   228 }
   230 PIndexedDBDatabaseParent*
   231 IndexedDBParent::AllocPIndexedDBDatabaseParent(
   232                                         const nsString& aName,
   233                                         const uint64_t& aVersion,
   234                                         const PersistenceType& aPersistenceType)
   235 {
   236   return new IndexedDBDatabaseParent();
   237 }
   239 bool
   240 IndexedDBParent::DeallocPIndexedDBDatabaseParent(PIndexedDBDatabaseParent* aActor)
   241 {
   242   delete aActor;
   243   return true;
   244 }
   246 PIndexedDBDeleteDatabaseRequestParent*
   247 IndexedDBParent::AllocPIndexedDBDeleteDatabaseRequestParent(
   248                                         const nsString& aName,
   249                                         const PersistenceType& aPersistenceType)
   250 {
   251   return new IndexedDBDeleteDatabaseRequestParent(mFactory);
   252 }
   254 bool
   255 IndexedDBParent::DeallocPIndexedDBDeleteDatabaseRequestParent(
   256                                   PIndexedDBDeleteDatabaseRequestParent* aActor)
   257 {
   258   delete aActor;
   259   return true;
   260 }
   262 /*******************************************************************************
   263  * IndexedDBDatabaseParent
   264  ******************************************************************************/
   266 IndexedDBDatabaseParent::IndexedDBDatabaseParent()
   267 : mEventListener(MOZ_THIS_IN_INITIALIZER_LIST())
   268 {
   269   MOZ_COUNT_CTOR(IndexedDBDatabaseParent);
   270 }
   272 IndexedDBDatabaseParent::~IndexedDBDatabaseParent()
   273 {
   274   MOZ_COUNT_DTOR(IndexedDBDatabaseParent);
   275 }
   277 nsresult
   278 IndexedDBDatabaseParent::SetOpenRequest(IDBOpenDBRequest* aRequest)
   279 {
   280   MOZ_ASSERT(aRequest);
   281   MOZ_ASSERT(!mOpenRequest);
   283   nsresult rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(SUCCESS_EVT_STR),
   284                                                         mEventListener, false);
   285   NS_ENSURE_SUCCESS(rv, rv);
   287   rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR),
   288                                                mEventListener, false);
   289   NS_ENSURE_SUCCESS(rv, rv);
   291   rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(BLOCKED_EVT_STR),
   292                                                mEventListener, false);
   293   NS_ENSURE_SUCCESS(rv, rv);
   295   rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(UPGRADENEEDED_EVT_STR),
   296                                                mEventListener, false);
   297   NS_ENSURE_SUCCESS(rv, rv);
   299   mOpenRequest = aRequest;
   300   return NS_OK;
   301 }
   303 nsresult
   304 IndexedDBDatabaseParent::HandleEvent(nsIDOMEvent* aEvent)
   305 {
   306   MOZ_ASSERT(aEvent);
   308   if (IsDisconnected()) {
   309     // We're shutting down, ignore this event.
   310     return NS_OK;
   311   }
   313   nsString type;
   314   nsresult rv = aEvent->GetType(type);
   315   NS_ENSURE_SUCCESS(rv, rv);
   317   nsCOMPtr<EventTarget> target = aEvent->InternalDOMEvent()->GetTarget();
   319   if (mDatabase &&
   320       SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*,
   321                                                 mDatabase))) {
   322     rv = HandleDatabaseEvent(aEvent, type);
   323     NS_ENSURE_SUCCESS(rv, rv);
   325     return NS_OK;
   326   }
   328   if (mOpenRequest &&
   329       SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*,
   330                                                 mOpenRequest))) {
   331     rv = HandleRequestEvent(aEvent, type);
   332     NS_ENSURE_SUCCESS(rv, rv);
   334     return NS_OK;
   335   }
   337   MOZ_CRASH("Unexpected message!");
   338 }
   340 void
   341 IndexedDBDatabaseParent::Disconnect()
   342 {
   343   if (mDatabase) {
   344     mDatabase->DisconnectFromActorParent();
   345   }
   346 }
   348 bool
   349 IndexedDBDatabaseParent::CheckWritePermission(const nsAString& aDatabaseName)
   350 {
   351   IndexedDBParent* manager = static_cast<IndexedDBParent*>(Manager());
   352   MOZ_ASSERT(manager);
   354   return manager->CheckWritePermission(aDatabaseName);
   355 }
   357 void
   358 IndexedDBDatabaseParent::Invalidate()
   359 {
   360   MOZ_ASSERT(mDatabase);
   362   if (!IsDisconnected()) {
   363     mozilla::unused << SendInvalidate();
   364   }
   365 }
   367 nsresult
   368 IndexedDBDatabaseParent::HandleRequestEvent(nsIDOMEvent* aEvent,
   369                                             const nsAString& aType)
   370 {
   371   MOZ_ASSERT(mOpenRequest);
   372   MOZ_ASSERT(!IsDisconnected());
   374   nsresult rv;
   376   if (aType.EqualsLiteral(ERROR_EVT_STR)) {
   377     nsRefPtr<IDBOpenDBRequest> request;
   378     mOpenRequest.swap(request);
   380     rv = request->GetErrorCode();
   381     MOZ_ASSERT(NS_FAILED(rv));
   383     if (!SendError(rv)) {
   384       return NS_ERROR_FAILURE;
   385     }
   387     rv = aEvent->PreventDefault();
   388     NS_ENSURE_SUCCESS(rv, rv);
   390     return NS_OK;
   391   }
   393   if (aType.EqualsLiteral(BLOCKED_EVT_STR)) {
   394     MOZ_ASSERT(!mDatabase);
   396     nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent);
   397     NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE);
   399     uint64_t oldVersion = changeEvent->OldVersion();
   401     if (!SendBlocked(oldVersion)) {
   402       return NS_ERROR_FAILURE;
   403     }
   405     return NS_OK;
   406   }
   408   AutoSafeJSContext cx;
   410   ErrorResult error;
   411   JS::Rooted<JS::Value> result(cx);
   412   mOpenRequest->GetResult(cx, &result, error);
   413   ENSURE_SUCCESS(error, error.ErrorCode());
   415   MOZ_ASSERT(!JSVAL_IS_PRIMITIVE(result));
   417   IDBDatabase *database;
   418   rv = UNWRAP_OBJECT(IDBDatabase, &result.toObject(), database);
   419   if (NS_FAILED(rv)) {
   420     NS_WARNING("Didn't get the object we expected!");
   421     return rv;
   422   }
   424   DatabaseInfo* dbInfo = database->Info();
   425   MOZ_ASSERT(dbInfo);
   427   nsAutoTArray<nsString, 20> objectStoreNames;
   428   if (!dbInfo->GetObjectStoreNames(objectStoreNames)) {
   429     MOZ_CRASH("This should never fail!");
   430   }
   432   InfallibleTArray<ObjectStoreInfoGuts> objectStoreInfos;
   433   if (!objectStoreNames.IsEmpty()) {
   434     uint32_t length = objectStoreNames.Length();
   436     objectStoreInfos.SetCapacity(length);
   438     for (uint32_t i = 0; i < length; i++) {
   439       ObjectStoreInfo* osInfo = dbInfo->GetObjectStore(objectStoreNames[i]);
   440       MOZ_ASSERT(osInfo);
   442       objectStoreInfos.AppendElement(*osInfo);
   443     }
   444   }
   446   if (aType.EqualsLiteral(SUCCESS_EVT_STR)) {
   447     nsRefPtr<IDBOpenDBRequest> request;
   448     mOpenRequest.swap(request);
   450     EventTarget* target = static_cast<EventTarget*>(database);
   452 #ifdef DEBUG
   453     {
   454       nsresult rvDEBUG =
   455         target->AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR),
   456                                  mEventListener, false);
   457       NS_WARN_IF_FALSE(NS_SUCCEEDED(rvDEBUG), "Failed to add error listener!");
   458     }
   459 #endif
   461     NS_NAMED_LITERAL_STRING(versionChange, VERSIONCHANGE_EVT_STR);
   462     rv = target->AddEventListener(versionChange, mEventListener, false);
   463     NS_ENSURE_SUCCESS(rv, rv);
   465     if (!SendSuccess(*dbInfo, objectStoreInfos)) {
   466       return NS_ERROR_FAILURE;
   467     }
   469     MOZ_ASSERT(!mDatabase || mDatabase == database);
   471     if (!mDatabase) {
   472       database->SetActor(this);
   473       mDatabase = database;
   474     }
   476     return NS_OK;
   477   }
   479   if (aType.EqualsLiteral(UPGRADENEEDED_EVT_STR)) {
   480     MOZ_ASSERT(!mDatabase);
   482     IDBTransaction* transaction =
   483       AsyncConnectionHelper::GetCurrentTransaction();
   484     MOZ_ASSERT(transaction);
   486     if (!CheckWritePermission(database->Name())) {
   487       // If we get here then the child process is either dead or in the process
   488       // of being killed. Abort the transaction now to prevent any changes to
   489       // the database.
   490       ErrorResult rv;
   491       transaction->Abort(rv);
   492       if (rv.Failed()) {
   493         NS_WARNING("Failed to abort transaction!");
   494       }
   495       return NS_ERROR_FAILURE;
   496     }
   498     nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent);
   499     NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE);
   501     uint64_t oldVersion = changeEvent->OldVersion();
   503     nsAutoPtr<IndexedDBVersionChangeTransactionParent> actor(
   504       new IndexedDBVersionChangeTransactionParent());
   506     rv = actor->SetTransaction(transaction);
   507     NS_ENSURE_SUCCESS(rv, rv);
   509     VersionChangeTransactionParams versionChangeParams;
   510     versionChangeParams.dbInfo() = *dbInfo;
   511     versionChangeParams.osInfo() = objectStoreInfos;
   512     versionChangeParams.oldVersion() = oldVersion;
   514     if (!SendPIndexedDBTransactionConstructor(actor.forget(),
   515                                               versionChangeParams)) {
   516       return NS_ERROR_FAILURE;
   517     }
   519     database->SetActor(this);
   520     mDatabase = database;
   522     return NS_OK;
   523   }
   525   MOZ_CRASH("Unexpected message type!");
   526 }
   528 nsresult
   529 IndexedDBDatabaseParent::HandleDatabaseEvent(nsIDOMEvent* aEvent,
   530                                              const nsAString& aType)
   531 {
   532   MOZ_ASSERT(mDatabase);
   533   MOZ_ASSERT(!aType.EqualsLiteral(ERROR_EVT_STR),
   534              "Should never get error events in the parent process!");
   535   MOZ_ASSERT(!IsDisconnected());
   537   if (aType.EqualsLiteral(VERSIONCHANGE_EVT_STR)) {
   538     AutoSafeJSContext cx;
   539     NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
   541     nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent);
   542     NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE);
   544     uint64_t oldVersion = changeEvent->OldVersion();
   546     Nullable<uint64_t> newVersionVal = changeEvent->GetNewVersion();
   548     uint64_t newVersion;
   549     if (newVersionVal.IsNull()) {
   550       newVersion = 0;
   551     }
   552     else {
   553       newVersion = newVersionVal.Value();
   554     }
   556     if (!SendVersionChange(oldVersion, newVersion)) {
   557       return NS_ERROR_FAILURE;
   558     }
   560     return NS_OK;
   561   }
   563   MOZ_CRASH("Unexpected message type!");
   564 }
   566 void
   567 IndexedDBDatabaseParent::ActorDestroy(ActorDestroyReason aWhy)
   568 {
   569   if (mDatabase) {
   570     mDatabase->SetActor(static_cast<IndexedDBDatabaseParent*>(nullptr));
   571     mDatabase->InvalidateInternal(/* aIsDead */ true);
   572   }
   573 }
   575 bool
   576 IndexedDBDatabaseParent::RecvClose(const bool& aUnlinked)
   577 {
   578   MOZ_ASSERT(mDatabase);
   580   if (IsDisconnected()) {
   581     // We're shutting down, ignore this request.
   582     return true;
   583   }
   585   mDatabase->CloseInternal(aUnlinked);
   586   return true;
   587 }
   589 bool
   590 IndexedDBDatabaseParent::RecvPIndexedDBTransactionConstructor(
   591                                             PIndexedDBTransactionParent* aActor,
   592                                             const TransactionParams& aParams)
   593 {
   594   MOZ_ASSERT(aParams.type() ==
   595              TransactionParams::TNormalTransactionParams);
   596   MOZ_ASSERT(!mOpenRequest);
   598   if (IsDisconnected()) {
   599     // We're shutting down, ignore this request.
   600     return true;
   601   }
   603   if (!mDatabase) {
   604     return true;
   605   }
   607   IndexedDBTransactionParent* actor =
   608     static_cast<IndexedDBTransactionParent*>(aActor);
   610   const NormalTransactionParams& params = aParams.get_NormalTransactionParams();
   612   if (params.mode() != IDBTransaction::READ_ONLY &&
   613       !CheckWritePermission(mDatabase->Name())) {
   614     return false;
   615   }
   617   if (mDatabase->IsClosed()) {
   618     // If the window was navigated then we won't be able to do anything here.
   619     return true;
   620   }
   622   Sequence<nsString> storesToOpen;
   623   storesToOpen.AppendElements(params.names());
   625   nsRefPtr<IDBTransaction> transaction =
   626     IDBTransaction::Create(mDatabase, storesToOpen, params.mode(), false);
   627   NS_ENSURE_TRUE(transaction, false);
   629   nsresult rv = actor->SetTransaction(transaction);
   630   NS_ENSURE_SUCCESS(rv, false);
   632   return true;
   633 }
   635 PIndexedDBTransactionParent*
   636 IndexedDBDatabaseParent::AllocPIndexedDBTransactionParent(
   637                                                const TransactionParams& aParams)
   638 {
   639   MOZ_ASSERT(aParams.type() ==
   640              TransactionParams::TNormalTransactionParams);
   641   return new IndexedDBTransactionParent();
   642 }
   644 bool
   645 IndexedDBDatabaseParent::DeallocPIndexedDBTransactionParent(
   646                                             PIndexedDBTransactionParent* aActor)
   647 {
   648   delete aActor;
   649   return true;
   650 }
   652 /*******************************************************************************
   653  * IndexedDBTransactionParent
   654  ******************************************************************************/
   656 IndexedDBTransactionParent::IndexedDBTransactionParent()
   657 : mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()),
   658   mArtificialRequestCount(false)
   659 {
   660   MOZ_COUNT_CTOR(IndexedDBTransactionParent);
   661 }
   663 IndexedDBTransactionParent::~IndexedDBTransactionParent()
   664 {
   665   MOZ_COUNT_DTOR(IndexedDBTransactionParent);
   666 }
   668 nsresult
   669 IndexedDBTransactionParent::SetTransaction(IDBTransaction* aTransaction)
   670 {
   671   MOZ_ASSERT(aTransaction);
   672   MOZ_ASSERT(!mTransaction);
   674   EventTarget* target = static_cast<EventTarget*>(aTransaction);
   676   NS_NAMED_LITERAL_STRING(complete, COMPLETE_EVT_STR);
   677   nsresult rv = target->AddEventListener(complete, mEventListener, false);
   678   NS_ENSURE_SUCCESS(rv, rv);
   680   rv = target->AddEventListener(NS_LITERAL_STRING(ABORT_EVT_STR),
   681                                 mEventListener, false);
   682   NS_ENSURE_SUCCESS(rv, rv);
   684   aTransaction->OnNewRequest();
   685   mArtificialRequestCount = true;
   687   aTransaction->SetActor(this);
   689   mTransaction = aTransaction;
   690   return NS_OK;
   691 }
   693 nsresult
   694 IndexedDBTransactionParent::HandleEvent(nsIDOMEvent* aEvent)
   695 {
   696   MOZ_ASSERT(aEvent);
   698   if (IsDisconnected()) {
   699     // We're shutting down, ignore this event.
   700     return NS_OK;
   701   }
   703   nsString type;
   704   nsresult rv = aEvent->GetType(type);
   705   NS_ENSURE_SUCCESS(rv, rv);
   707   CompleteParams params;
   709   if (type.EqualsLiteral(COMPLETE_EVT_STR)) {
   710     params = CompleteResult();
   711   }
   712   else if (type.EqualsLiteral(ABORT_EVT_STR)) {
   713 #ifdef DEBUG
   714     {
   715       nsCOMPtr<EventTarget> target = aEvent->InternalDOMEvent()->GetTarget();
   716       MOZ_ASSERT(SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*,
   717                                                            mTransaction)));
   718     }
   719 #endif
   720     params = AbortResult(mTransaction->GetAbortCode());
   721   }
   722   else {
   723     NS_WARNING("Unknown message type!");
   724     return NS_ERROR_UNEXPECTED;
   725   }
   727   if (!SendComplete(params)) {
   728     return NS_ERROR_FAILURE;
   729   }
   731   return NS_OK;
   732 }
   734 void
   735 IndexedDBTransactionParent::ActorDestroy(ActorDestroyReason aWhy)
   736 {
   737   if (mTransaction) {
   738     if (mArtificialRequestCount) {
   739       // The transaction never completed and now the child side is dead. Abort
   740       // here to be safe.
   741       ErrorResult rv;
   742       mTransaction->Abort(rv);
   744       mTransaction->OnRequestFinished();
   745 #ifdef DEBUG
   746       mArtificialRequestCount = false;
   747 #endif
   748     }
   749     mTransaction->SetActor(static_cast<IndexedDBTransactionParent*>(nullptr));
   750   }
   751 }
   753 bool
   754 IndexedDBTransactionParent::RecvAbort(const nsresult& aAbortCode)
   755 {
   756   MOZ_ASSERT(mTransaction);
   758   if (IsDisconnected()) {
   759     // We're shutting down, ignore this request.
   760     return true;
   761   }
   763   mTransaction->Abort(aAbortCode);
   764   return true;
   765 }
   767 bool
   768 IndexedDBTransactionParent::RecvAllRequestsFinished()
   769 {
   770   MOZ_ASSERT(mTransaction);
   771   MOZ_ASSERT(mArtificialRequestCount);
   773   if (IsDisconnected()) {
   774     // We're shutting down, ignore this request.
   775     return true;
   776   }
   778   mTransaction->OnRequestFinished();
   779   mArtificialRequestCount = false;
   781   return true;
   782 }
   784 bool
   785 IndexedDBTransactionParent::RecvDeleteObjectStore(const nsString& aName)
   786 {
   787   MOZ_CRASH("Should be overridden, don't call me!");
   788 }
   790 bool
   791 IndexedDBTransactionParent::RecvPIndexedDBObjectStoreConstructor(
   792                                     PIndexedDBObjectStoreParent* aActor,
   793                                     const ObjectStoreConstructorParams& aParams)
   794 {
   795   if (IsDisconnected()) {
   796     // We're shutting down, ignore this request.
   797     return true;
   798   }
   800   if (!mTransaction) {
   801     return true;
   802   }
   804   IndexedDBObjectStoreParent* actor =
   805     static_cast<IndexedDBObjectStoreParent*>(aActor);
   807   if (aParams.type() ==
   808       ObjectStoreConstructorParams::TGetObjectStoreParams) {
   809     const GetObjectStoreParams& params = aParams.get_GetObjectStoreParams();
   810     const nsString& name = params.name();
   812     nsRefPtr<IDBObjectStore> objectStore;
   814     {
   815       AutoSetCurrentTransaction asct(mTransaction);
   817       ErrorResult rv;
   818       objectStore = mTransaction->ObjectStore(name, rv);
   819       ENSURE_SUCCESS(rv, false);
   821       actor->SetObjectStore(objectStore);
   822     }
   824     objectStore->SetActor(actor);
   825     return true;
   826   }
   828   if (aParams.type() ==
   829       ObjectStoreConstructorParams::TCreateObjectStoreParams) {
   830     MOZ_CRASH("Should be overridden, don't call me!");
   831   }
   833   MOZ_CRASH("Unknown param type!");
   834 }
   836 PIndexedDBObjectStoreParent*
   837 IndexedDBTransactionParent::AllocPIndexedDBObjectStoreParent(
   838                                     const ObjectStoreConstructorParams& aParams)
   839 {
   840   return new IndexedDBObjectStoreParent();
   841 }
   843 bool
   844 IndexedDBTransactionParent::DeallocPIndexedDBObjectStoreParent(
   845                                             PIndexedDBObjectStoreParent* aActor)
   846 {
   847   delete aActor;
   848   return true;
   849 }
   851 /*******************************************************************************
   852  * IndexedDBVersionChangeTransactionParent
   853  ******************************************************************************/
   855 IndexedDBVersionChangeTransactionParent::
   856   IndexedDBVersionChangeTransactionParent()
   857 {
   858   MOZ_COUNT_CTOR(IndexedDBVersionChangeTransactionParent);
   859 }
   861 IndexedDBVersionChangeTransactionParent::
   862   ~IndexedDBVersionChangeTransactionParent()
   863 {
   864   MOZ_COUNT_DTOR(IndexedDBVersionChangeTransactionParent);
   865 }
   867 bool
   868 IndexedDBVersionChangeTransactionParent::RecvDeleteObjectStore(
   869                                                           const nsString& aName)
   870 {
   871   MOZ_ASSERT(!mTransaction ||
   872              mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE);
   874   if (IsDisconnected()) {
   875     // We're shutting down, ignore this request.
   876     return true;
   877   }
   879   if (!mTransaction) {
   880     return true;
   881   }
   883   if (mTransaction->Database()->IsInvalidated()) {
   884     // If we've invalidated this database in the parent then we should bail out
   885     // now to avoid logic problems that could force-kill the child.
   886     return true;
   887   }
   889   IDBDatabase* db = mTransaction->Database();
   890   MOZ_ASSERT(db);
   892   ErrorResult rv;
   894   {
   895     AutoSetCurrentTransaction asct(mTransaction);
   896     db->DeleteObjectStore(aName, rv);
   897   }
   899   ENSURE_SUCCESS(rv, false);
   900   return true;
   901 }
   903 bool
   904 IndexedDBVersionChangeTransactionParent::RecvPIndexedDBObjectStoreConstructor(
   905                                     PIndexedDBObjectStoreParent* aActor,
   906                                     const ObjectStoreConstructorParams& aParams)
   907 {
   908   if (IsDisconnected()) {
   909     // We're shutting down, ignore this request.
   910     return true;
   911   }
   913   if (!mTransaction) {
   914     return true;
   915   }
   917   if (mTransaction->Database()->IsInvalidated()) {
   918     // If we've invalidated this database in the parent then we should bail out
   919     // now to avoid logic problems that could force-kill the child.
   920     return true;
   921   }
   923   IndexedDBObjectStoreParent* actor =
   924     static_cast<IndexedDBObjectStoreParent*>(aActor);
   926   if (aParams.type() ==
   927       ObjectStoreConstructorParams::TCreateObjectStoreParams) {
   928     MOZ_ASSERT(mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE);
   930     const CreateObjectStoreParams& params =
   931       aParams.get_CreateObjectStoreParams();
   933     const ObjectStoreInfoGuts& info = params.info();
   935     IDBDatabase* db = mTransaction->Database();
   936     MOZ_ASSERT(db);
   938     nsRefPtr<IDBObjectStore> objectStore;
   940     ErrorResult rv;
   942     {
   943       AutoSetCurrentTransaction asct(mTransaction);
   945       objectStore = db->CreateObjectStoreInternal(mTransaction, info, rv);
   946     }
   948     ENSURE_SUCCESS(rv, false);
   950     actor->SetObjectStore(objectStore);
   951     objectStore->SetActor(actor);
   952     return true;
   953   }
   955   return
   956     IndexedDBTransactionParent::RecvPIndexedDBObjectStoreConstructor(aActor,
   957                                                                      aParams);
   958 }
   960 PIndexedDBObjectStoreParent*
   961 IndexedDBVersionChangeTransactionParent::AllocPIndexedDBObjectStoreParent(
   962                                     const ObjectStoreConstructorParams& aParams)
   963 {
   964   if (aParams.type() ==
   965       ObjectStoreConstructorParams::TCreateObjectStoreParams ||
   966       mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE) {
   967     return new IndexedDBVersionChangeObjectStoreParent();
   968   }
   970   return IndexedDBTransactionParent::AllocPIndexedDBObjectStoreParent(aParams);
   971 }
   973 /*******************************************************************************
   974  * IndexedDBCursorParent
   975  ******************************************************************************/
   977 IndexedDBCursorParent::IndexedDBCursorParent(IDBCursor* aCursor)
   978 : mCursor(aCursor)
   979 {
   980   MOZ_COUNT_CTOR(IndexedDBCursorParent);
   981   MOZ_ASSERT(aCursor);
   982   aCursor->SetActor(this);
   983 }
   985 IndexedDBCursorParent::~IndexedDBCursorParent()
   986 {
   987   MOZ_COUNT_DTOR(IndexedDBCursorParent);
   988 }
   990 bool
   991 IndexedDBCursorParent::IsDisconnected() const
   992 {
   993   MOZ_ASSERT(mCursor);
   994   return mCursor->Transaction()->GetActorParent()->IsDisconnected();
   995 }
   997 void
   998 IndexedDBCursorParent::ActorDestroy(ActorDestroyReason aWhy)
   999 {
  1000   MOZ_ASSERT(mCursor);
  1001   mCursor->SetActor(static_cast<IndexedDBCursorParent*>(nullptr));
  1004 bool
  1005 IndexedDBCursorParent::RecvPIndexedDBRequestConstructor(
  1006                                              PIndexedDBRequestParent* aActor,
  1007                                              const CursorRequestParams& aParams)
  1009   MOZ_ASSERT(mCursor);
  1011   if (IsDisconnected()) {
  1012     // We're shutting down, ignore this request.
  1013     return true;
  1016   IndexedDBCursorRequestParent* actor =
  1017     static_cast<IndexedDBCursorRequestParent*>(aActor);
  1019   if (mCursor->Transaction()->Database()->IsInvalidated()) {
  1020     // If we've invalidated this database in the parent then we should bail out
  1021     // now to avoid logic problems that could force-kill the child.
  1022     return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
  1025   switch (aParams.type()) {
  1026     case CursorRequestParams::TContinueParams:
  1027       return actor->Continue(aParams.get_ContinueParams());
  1029     default:
  1030       MOZ_CRASH("Unknown type!");
  1033   MOZ_CRASH("Should never get here!");
  1036 PIndexedDBRequestParent*
  1037 IndexedDBCursorParent::AllocPIndexedDBRequestParent(
  1038                                              const CursorRequestParams& aParams)
  1040   MOZ_ASSERT(mCursor);
  1041   return new IndexedDBCursorRequestParent(mCursor, aParams.type());
  1044 bool
  1045 IndexedDBCursorParent::DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor)
  1047   delete aActor;
  1048   return true;
  1051 /*******************************************************************************
  1052  * IndexedDBObjectStoreParent
  1053  ******************************************************************************/
  1055 IndexedDBObjectStoreParent::IndexedDBObjectStoreParent()
  1057   MOZ_COUNT_CTOR(IndexedDBObjectStoreParent);
  1060 IndexedDBObjectStoreParent::~IndexedDBObjectStoreParent()
  1062   MOZ_COUNT_DTOR(IndexedDBObjectStoreParent);
  1065 void
  1066 IndexedDBObjectStoreParent::SetObjectStore(IDBObjectStore* aObjectStore)
  1068   // Sadly can't assert aObjectStore here...
  1069   MOZ_ASSERT(!mObjectStore);
  1071   mObjectStore = aObjectStore;
  1074 void
  1075 IndexedDBObjectStoreParent::ActorDestroy(ActorDestroyReason aWhy)
  1077   if (mObjectStore) {
  1078     mObjectStore->SetActor(static_cast<IndexedDBObjectStoreParent*>(nullptr));
  1082 bool
  1083 IndexedDBObjectStoreParent::RecvDeleteIndex(const nsString& aName)
  1085   MOZ_CRASH("Should be overridden, don't call me!");
  1088 bool
  1089 IndexedDBObjectStoreParent::RecvPIndexedDBRequestConstructor(
  1090                                         PIndexedDBRequestParent* aActor,
  1091                                         const ObjectStoreRequestParams& aParams)
  1093   if (IsDisconnected()) {
  1094     // We're shutting down, ignore this request.
  1095     return true;
  1098   if (!mObjectStore) {
  1099     return true;
  1102   IndexedDBObjectStoreRequestParent* actor =
  1103     static_cast<IndexedDBObjectStoreRequestParent*>(aActor);
  1105   if (mObjectStore->Transaction()->Database()->IsInvalidated()) {
  1106     // If we've invalidated this database in the parent then we should bail out
  1107     // now to avoid logic problems that could force-kill the child.
  1108     return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
  1111   switch (aParams.type()) {
  1112     case ObjectStoreRequestParams::TGetParams:
  1113       return actor->Get(aParams.get_GetParams());
  1115     case ObjectStoreRequestParams::TGetAllParams:
  1116       return actor->GetAll(aParams.get_GetAllParams());
  1118     case ObjectStoreRequestParams::TGetAllKeysParams:
  1119       return actor->GetAllKeys(aParams.get_GetAllKeysParams());
  1121     case ObjectStoreRequestParams::TAddParams:
  1122       return actor->Add(aParams.get_AddParams());
  1124     case ObjectStoreRequestParams::TPutParams:
  1125       return actor->Put(aParams.get_PutParams());
  1127     case ObjectStoreRequestParams::TDeleteParams:
  1128       return actor->Delete(aParams.get_DeleteParams());
  1130     case ObjectStoreRequestParams::TClearParams:
  1131       return actor->Clear(aParams.get_ClearParams());
  1133     case ObjectStoreRequestParams::TCountParams:
  1134       return actor->Count(aParams.get_CountParams());
  1136     case ObjectStoreRequestParams::TOpenCursorParams:
  1137       return actor->OpenCursor(aParams.get_OpenCursorParams());
  1139     case ObjectStoreRequestParams::TOpenKeyCursorParams:
  1140       return actor->OpenKeyCursor(aParams.get_OpenKeyCursorParams());
  1142     default:
  1143       MOZ_CRASH("Unknown type!");
  1146   MOZ_CRASH("Should never get here!");
  1149 bool
  1150 IndexedDBObjectStoreParent::RecvPIndexedDBIndexConstructor(
  1151                                           PIndexedDBIndexParent* aActor,
  1152                                           const IndexConstructorParams& aParams)
  1154   if (IsDisconnected()) {
  1155     // We're shutting down, ignore this request.
  1156     return true;
  1159   if (!mObjectStore) {
  1160     return true;
  1163   IndexedDBIndexParent* actor = static_cast<IndexedDBIndexParent*>(aActor);
  1165   if (aParams.type() == IndexConstructorParams::TGetIndexParams) {
  1166     const GetIndexParams& params = aParams.get_GetIndexParams();
  1167     const nsString& name = params.name();
  1169     nsRefPtr<IDBIndex> index;
  1172       AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1174       ErrorResult rv;
  1175       index = mObjectStore->Index(name, rv);
  1176       ENSURE_SUCCESS(rv, false);
  1178       actor->SetIndex(index);
  1181     index->SetActor(actor);
  1182     return true;
  1185   if (aParams.type() == IndexConstructorParams::TCreateIndexParams) {
  1186     MOZ_CRASH("Should be overridden, don't call me!");
  1189   MOZ_CRASH("Unknown param type!");
  1192 PIndexedDBRequestParent*
  1193 IndexedDBObjectStoreParent::AllocPIndexedDBRequestParent(
  1194                                         const ObjectStoreRequestParams& aParams)
  1196   return new IndexedDBObjectStoreRequestParent(mObjectStore, aParams.type());
  1199 bool
  1200 IndexedDBObjectStoreParent::DeallocPIndexedDBRequestParent(
  1201                                                 PIndexedDBRequestParent* aActor)
  1203   delete aActor;
  1204   return true;
  1207 PIndexedDBIndexParent*
  1208 IndexedDBObjectStoreParent::AllocPIndexedDBIndexParent(
  1209                                           const IndexConstructorParams& aParams)
  1211   return new IndexedDBIndexParent();
  1214 bool
  1215 IndexedDBObjectStoreParent::DeallocPIndexedDBIndexParent(
  1216                                                   PIndexedDBIndexParent* aActor)
  1218   delete aActor;
  1219   return true;
  1222 PIndexedDBCursorParent*
  1223 IndexedDBObjectStoreParent::AllocPIndexedDBCursorParent(
  1224                               const ObjectStoreCursorConstructorParams& aParams)
  1226   MOZ_CRASH("Caller is supposed to manually construct a cursor!");
  1229 bool
  1230 IndexedDBObjectStoreParent::DeallocPIndexedDBCursorParent(
  1231                                                  PIndexedDBCursorParent* aActor)
  1233   delete aActor;
  1234   return true;
  1237 /*******************************************************************************
  1238  * IndexedDBVersionChangeObjectStoreParent
  1239  ******************************************************************************/
  1241 IndexedDBVersionChangeObjectStoreParent::
  1242   IndexedDBVersionChangeObjectStoreParent()
  1244   MOZ_COUNT_CTOR(IndexedDBVersionChangeObjectStoreParent);
  1247 IndexedDBVersionChangeObjectStoreParent::
  1248   ~IndexedDBVersionChangeObjectStoreParent()
  1250   MOZ_COUNT_DTOR(IndexedDBVersionChangeObjectStoreParent);
  1253 bool
  1254 IndexedDBVersionChangeObjectStoreParent::RecvDeleteIndex(const nsString& aName)
  1256   MOZ_ASSERT(!mObjectStore ||
  1257              mObjectStore->Transaction()->GetMode() ==
  1258              IDBTransaction::VERSION_CHANGE);
  1260   if (IsDisconnected()) {
  1261     // We're shutting down, ignore this request.
  1262     return true;
  1265   if (!mObjectStore) {
  1266     return true;
  1269   if (mObjectStore->Transaction()->Database()->IsInvalidated()) {
  1270     // If we've invalidated this database in the parent then we should bail out
  1271     // now to avoid logic problems that could force-kill the child.
  1272     return true;
  1275   ErrorResult rv;
  1278     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1280     mObjectStore->DeleteIndex(aName, rv);
  1283   ENSURE_SUCCESS(rv, false);
  1284   return true;
  1287 bool
  1288 IndexedDBVersionChangeObjectStoreParent::RecvPIndexedDBIndexConstructor(
  1289                                           PIndexedDBIndexParent* aActor,
  1290                                           const IndexConstructorParams& aParams)
  1292   if (IsDisconnected()) {
  1293     // We're shutting down, ignore this request.
  1294     return true;
  1297   if (!mObjectStore) {
  1298     return true;
  1301   if (mObjectStore->Transaction()->Database()->IsInvalidated()) {
  1302     // If we've invalidated this database in the parent then we should bail out
  1303     // now to avoid logic problems that could force-kill the child.
  1304     return true;
  1307   IndexedDBIndexParent* actor = static_cast<IndexedDBIndexParent*>(aActor);
  1309   if (aParams.type() == IndexConstructorParams::TCreateIndexParams) {
  1310     MOZ_ASSERT(mObjectStore->Transaction()->GetMode() ==
  1311                IDBTransaction::VERSION_CHANGE);
  1313     const CreateIndexParams& params = aParams.get_CreateIndexParams();
  1314     const IndexInfo& info = params.info();
  1316     nsRefPtr<IDBIndex> index;
  1319       AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1321       ErrorResult rv;
  1322       index = mObjectStore->CreateIndexInternal(info, rv);
  1323       ENSURE_SUCCESS(rv, false);
  1326     actor->SetIndex(index);
  1327     index->SetActor(actor);
  1328     return true;
  1331   return IndexedDBObjectStoreParent::RecvPIndexedDBIndexConstructor(aActor,
  1332                                                                     aParams);
  1335 /*******************************************************************************
  1336  * IndexedDBIndexParent
  1337  ******************************************************************************/
  1339 IndexedDBIndexParent::IndexedDBIndexParent()
  1341   MOZ_COUNT_CTOR(IndexedDBIndexParent);
  1344 IndexedDBIndexParent::~IndexedDBIndexParent()
  1346   MOZ_COUNT_DTOR(IndexedDBIndexParent);
  1349 void
  1350 IndexedDBIndexParent::SetIndex(IDBIndex* aIndex)
  1352   MOZ_ASSERT(aIndex);
  1353   MOZ_ASSERT(!mIndex);
  1355   mIndex = aIndex;
  1358 void
  1359 IndexedDBIndexParent::ActorDestroy(ActorDestroyReason aWhy)
  1361   if (mIndex) {
  1362     mIndex->SetActor(static_cast<IndexedDBIndexParent*>(nullptr));
  1366 bool
  1367 IndexedDBIndexParent::RecvPIndexedDBRequestConstructor(
  1368                                               PIndexedDBRequestParent* aActor,
  1369                                               const IndexRequestParams& aParams)
  1371   if (IsDisconnected()) {
  1372     // We're shutting down, ignore this request.
  1373     return true;
  1376   if (!mIndex) {
  1377     return true;
  1380   IndexedDBIndexRequestParent* actor =
  1381     static_cast<IndexedDBIndexRequestParent*>(aActor);
  1383   if (mIndex->ObjectStore()->Transaction()->Database()->IsInvalidated()) {
  1384     // If we've invalidated this database in the parent then we should bail out
  1385     // now to avoid logic problems that could force-kill the child.
  1386     return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
  1389   switch (aParams.type()) {
  1390     case IndexRequestParams::TGetParams:
  1391       return actor->Get(aParams.get_GetParams());
  1393     case IndexRequestParams::TGetKeyParams:
  1394       return actor->GetKey(aParams.get_GetKeyParams());
  1396     case IndexRequestParams::TGetAllParams:
  1397       return actor->GetAll(aParams.get_GetAllParams());
  1399     case IndexRequestParams::TGetAllKeysParams:
  1400       return actor->GetAllKeys(aParams.get_GetAllKeysParams());
  1402     case IndexRequestParams::TCountParams:
  1403       return actor->Count(aParams.get_CountParams());
  1405     case IndexRequestParams::TOpenCursorParams:
  1406       return actor->OpenCursor(aParams.get_OpenCursorParams());
  1408     case IndexRequestParams::TOpenKeyCursorParams:
  1409       return actor->OpenKeyCursor(aParams.get_OpenKeyCursorParams());
  1411     default:
  1412       MOZ_CRASH("Unknown type!");
  1415   MOZ_CRASH("Should never get here!");
  1418 PIndexedDBRequestParent*
  1419 IndexedDBIndexParent::AllocPIndexedDBRequestParent(const IndexRequestParams& aParams)
  1421   return new IndexedDBIndexRequestParent(mIndex, aParams.type());
  1424 bool
  1425 IndexedDBIndexParent::DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor)
  1427   delete aActor;
  1428   return true;
  1431 PIndexedDBCursorParent*
  1432 IndexedDBIndexParent::AllocPIndexedDBCursorParent(
  1433                                     const IndexCursorConstructorParams& aParams)
  1435   MOZ_CRASH("Caller is supposed to manually construct a cursor!");
  1438 bool
  1439 IndexedDBIndexParent::DeallocPIndexedDBCursorParent(PIndexedDBCursorParent* aActor)
  1441   delete aActor;
  1442   return true;
  1445 /*******************************************************************************
  1446  * IndexedDBRequestParentBase
  1447  ******************************************************************************/
  1449 IndexedDBRequestParentBase::IndexedDBRequestParentBase()
  1451   MOZ_COUNT_CTOR(IndexedDBRequestParentBase);
  1454 IndexedDBRequestParentBase::~IndexedDBRequestParentBase()
  1456   MOZ_COUNT_DTOR(IndexedDBRequestParentBase);
  1459 void
  1460 IndexedDBRequestParentBase::ActorDestroy(ActorDestroyReason aWhy)
  1462   if (mRequest) {
  1463     mRequest->SetActor(nullptr);
  1467 /*******************************************************************************
  1468  * IndexedDBObjectStoreRequestParent
  1469  ******************************************************************************/
  1471 IndexedDBObjectStoreRequestParent::IndexedDBObjectStoreRequestParent(
  1472                                                    IDBObjectStore* aObjectStore,
  1473                                                    RequestType aRequestType)
  1474 : mObjectStore(aObjectStore), mRequestType(aRequestType)
  1476   MOZ_COUNT_CTOR(IndexedDBObjectStoreRequestParent);
  1477   // Sadly can't assert aObjectStore here...
  1478   MOZ_ASSERT(aRequestType > ParamsUnionType::T__None &&
  1479              aRequestType <= ParamsUnionType::T__Last);
  1482 IndexedDBObjectStoreRequestParent::~IndexedDBObjectStoreRequestParent()
  1484   MOZ_COUNT_DTOR(IndexedDBObjectStoreRequestParent);
  1487 void
  1488 IndexedDBObjectStoreRequestParent::ConvertBlobActors(
  1489                                   const InfallibleTArray<PBlobParent*>& aActors,
  1490                                   nsTArray<nsCOMPtr<nsIDOMBlob> >& aBlobs)
  1492   MOZ_ASSERT(aBlobs.IsEmpty());
  1493   MOZ_ASSERT(mObjectStore);
  1495   if (!aActors.IsEmpty()) {
  1496     // Walk the chain to get to ContentParent.
  1497     MOZ_ASSERT(mObjectStore->Transaction()->Database()->GetContentParent());
  1499     uint32_t length = aActors.Length();
  1500     aBlobs.SetCapacity(length);
  1502     for (uint32_t index = 0; index < length; index++) {
  1503       BlobParent* actor = static_cast<BlobParent*>(aActors[index]);
  1504       nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob();
  1505       aBlobs.AppendElement(blob);
  1510 bool
  1511 IndexedDBObjectStoreRequestParent::IsDisconnected()
  1513   MOZ_ASSERT(mObjectStore);
  1514   MOZ_ASSERT(mObjectStore->GetActorParent());
  1515   return mObjectStore->GetActorParent()->IsDisconnected();
  1518 bool
  1519 IndexedDBObjectStoreRequestParent::Get(const GetParams& aParams)
  1521   MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams);
  1522   MOZ_ASSERT(mObjectStore);
  1524   nsRefPtr<IDBRequest> request;
  1526   nsRefPtr<IDBKeyRange> keyRange =
  1527     IDBKeyRange::FromSerializedKeyRange(aParams.keyRange());
  1528   MOZ_ASSERT(keyRange);
  1531     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1533     ErrorResult rv;
  1534     request = mObjectStore->GetInternal(keyRange, rv);
  1535     ENSURE_SUCCESS(rv, false);
  1538   request->SetActor(this);
  1539   mRequest.swap(request);
  1541   return true;
  1544 bool
  1545 IndexedDBObjectStoreRequestParent::GetAll(const GetAllParams& aParams)
  1547   MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams);
  1548   MOZ_ASSERT(mObjectStore);
  1550   nsRefPtr<IDBRequest> request;
  1552   const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange();
  1554   nsRefPtr<IDBKeyRange> keyRange;
  1556   switch (keyRangeUnion.type()) {
  1557     case ipc::OptionalKeyRange::TKeyRange:
  1558       keyRange =
  1559         IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange());
  1560       break;
  1562     case ipc::OptionalKeyRange::Tvoid_t:
  1563       break;
  1565     default:
  1566       MOZ_CRASH("Unknown param type!");
  1570     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1572     ErrorResult rv;
  1573     request = mObjectStore->GetAllInternal(keyRange, aParams.limit(), rv);
  1574     ENSURE_SUCCESS(rv, false);
  1577   request->SetActor(this);
  1578   mRequest.swap(request);
  1579   return true;
  1582 bool
  1583 IndexedDBObjectStoreRequestParent::GetAllKeys(const GetAllKeysParams& aParams)
  1585   MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams);
  1586   MOZ_ASSERT(mObjectStore);
  1588   nsRefPtr<IDBRequest> request;
  1590   const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange();
  1592   nsRefPtr<IDBKeyRange> keyRange;
  1594   switch (keyRangeUnion.type()) {
  1595     case ipc::OptionalKeyRange::TKeyRange:
  1596       keyRange =
  1597         IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange());
  1598       break;
  1600     case ipc::OptionalKeyRange::Tvoid_t:
  1601       break;
  1603     default:
  1604       MOZ_CRASH("Unknown param type!");
  1608     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1610     ErrorResult rv;
  1611     request = mObjectStore->GetAllKeysInternal(keyRange, aParams.limit(), rv);
  1612     ENSURE_SUCCESS(rv, false);
  1615   request->SetActor(this);
  1616   mRequest.swap(request);
  1617   return true;
  1620 bool
  1621 IndexedDBObjectStoreRequestParent::Add(const AddParams& aParams)
  1623   MOZ_ASSERT(mRequestType == ParamsUnionType::TAddParams);
  1624   MOZ_ASSERT(mObjectStore);
  1626   ipc::AddPutParams params = aParams.commonParams();
  1628   nsTArray<nsCOMPtr<nsIDOMBlob> > blobs;
  1629   ConvertBlobActors(params.blobsParent(), blobs);
  1631   nsRefPtr<IDBRequest> request;
  1634     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1636     nsresult rv =
  1637       mObjectStore->AddOrPutInternal(params.cloneInfo(), params.key(),
  1638                                      params.indexUpdateInfos(), blobs, false,
  1639                                      getter_AddRefs(request));
  1640     NS_ENSURE_SUCCESS(rv, false);
  1643   request->SetActor(this);
  1644   mRequest.swap(request);
  1645   return true;
  1648 bool
  1649 IndexedDBObjectStoreRequestParent::Put(const PutParams& aParams)
  1651   MOZ_ASSERT(mRequestType == ParamsUnionType::TPutParams);
  1652   MOZ_ASSERT(mObjectStore);
  1654   ipc::AddPutParams params = aParams.commonParams();
  1656   nsTArray<nsCOMPtr<nsIDOMBlob> > blobs;
  1657   ConvertBlobActors(params.blobsParent(), blobs);
  1659   nsRefPtr<IDBRequest> request;
  1662     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1664     nsresult rv =
  1665       mObjectStore->AddOrPutInternal(params.cloneInfo(), params.key(),
  1666                                      params.indexUpdateInfos(), blobs, true,
  1667                                      getter_AddRefs(request));
  1668     NS_ENSURE_SUCCESS(rv, false);
  1671   request->SetActor(this);
  1672   mRequest.swap(request);
  1673   return true;
  1676 bool
  1677 IndexedDBObjectStoreRequestParent::Delete(const DeleteParams& aParams)
  1679   MOZ_ASSERT(mRequestType == ParamsUnionType::TDeleteParams);
  1680   MOZ_ASSERT(mObjectStore);
  1682   nsRefPtr<IDBRequest> request;
  1684   nsRefPtr<IDBKeyRange> keyRange =
  1685     IDBKeyRange::FromSerializedKeyRange(aParams.keyRange());
  1686   MOZ_ASSERT(keyRange);
  1689     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1691     ErrorResult rv;
  1692     request = mObjectStore->DeleteInternal(keyRange, rv);
  1693     ENSURE_SUCCESS(rv, false);
  1696   request->SetActor(this);
  1697   mRequest.swap(request);
  1698   return true;
  1701 bool
  1702 IndexedDBObjectStoreRequestParent::Clear(const ClearParams& aParams)
  1704   MOZ_ASSERT(mRequestType == ParamsUnionType::TClearParams);
  1705   MOZ_ASSERT(mObjectStore);
  1707   nsRefPtr<IDBRequest> request;
  1710     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1712     ErrorResult rv;
  1713     request = mObjectStore->Clear(rv);
  1714     ENSURE_SUCCESS(rv, false);
  1717   request->SetActor(this);
  1718   mRequest.swap(request);
  1719   return true;
  1722 bool
  1723 IndexedDBObjectStoreRequestParent::Count(const CountParams& aParams)
  1725   MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams);
  1726   MOZ_ASSERT(mObjectStore);
  1728   const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange();
  1730   nsRefPtr<IDBKeyRange> keyRange;
  1732   switch (keyRangeUnion.type()) {
  1733     case ipc::OptionalKeyRange::TKeyRange:
  1734       keyRange =
  1735         IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange());
  1736       break;
  1738     case ipc::OptionalKeyRange::Tvoid_t:
  1739       break;
  1741     default:
  1742       MOZ_CRASH("Unknown param type!");
  1745   nsRefPtr<IDBRequest> request;
  1748     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1750     ErrorResult rv;
  1751     request = mObjectStore->CountInternal(keyRange, rv);
  1752     ENSURE_SUCCESS(rv, false);
  1755   request->SetActor(this);
  1756   mRequest.swap(request);
  1757   return true;
  1760 bool
  1761 IndexedDBObjectStoreRequestParent::OpenCursor(const OpenCursorParams& aParams)
  1763   MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams);
  1764   MOZ_ASSERT(mObjectStore);
  1766   const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange();
  1768   nsRefPtr<IDBKeyRange> keyRange;
  1770   switch (keyRangeUnion.type()) {
  1771     case ipc::OptionalKeyRange::TKeyRange:
  1772       keyRange =
  1773         IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange());
  1774       break;
  1776     case ipc::OptionalKeyRange::Tvoid_t:
  1777       break;
  1779     default:
  1780       MOZ_CRASH("Unknown param type!");
  1783   size_t direction = static_cast<size_t>(aParams.direction());
  1785   nsRefPtr<IDBRequest> request;
  1788     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1790     ErrorResult rv;
  1791     request = mObjectStore->OpenCursorInternal(keyRange, direction, rv);
  1792     ENSURE_SUCCESS(rv, false);
  1795   request->SetActor(this);
  1796   mRequest.swap(request);
  1797   return true;
  1800 bool
  1801 IndexedDBObjectStoreRequestParent::OpenKeyCursor(
  1802                                              const OpenKeyCursorParams& aParams)
  1804   MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenKeyCursorParams);
  1805   MOZ_ASSERT(mObjectStore);
  1807   const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange();
  1809   nsRefPtr<IDBKeyRange> keyRange;
  1811   switch (keyRangeUnion.type()) {
  1812     case ipc::OptionalKeyRange::TKeyRange:
  1813       keyRange =
  1814         IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange());
  1815       break;
  1817     case ipc::OptionalKeyRange::Tvoid_t:
  1818       break;
  1820     default:
  1821       MOZ_CRASH("Unknown param type!");
  1824   size_t direction = static_cast<size_t>(aParams.direction());
  1826   nsRefPtr<IDBRequest> request;
  1829     AutoSetCurrentTransaction asct(mObjectStore->Transaction());
  1831     ErrorResult rv;
  1832     request = mObjectStore->OpenKeyCursorInternal(keyRange, direction, rv);
  1833     ENSURE_SUCCESS(rv, false);
  1836   request->SetActor(this);
  1837   mRequest.swap(request);
  1838   return true;
  1841 /*******************************************************************************
  1842  * IndexedDBIndexRequestParent
  1843  ******************************************************************************/
  1845 IndexedDBIndexRequestParent::IndexedDBIndexRequestParent(
  1846                                                        IDBIndex* aIndex,
  1847                                                        RequestType aRequestType)
  1848 : mIndex(aIndex), mRequestType(aRequestType)
  1850   MOZ_COUNT_CTOR(IndexedDBIndexRequestParent);
  1851   // Sadly can't assert aIndex here...
  1852   MOZ_ASSERT(aRequestType > ParamsUnionType::T__None &&
  1853              aRequestType <= ParamsUnionType::T__Last);
  1856 IndexedDBIndexRequestParent::~IndexedDBIndexRequestParent()
  1858   MOZ_COUNT_DTOR(IndexedDBIndexRequestParent);
  1861 bool
  1862 IndexedDBIndexRequestParent::IsDisconnected()
  1864   MOZ_ASSERT(mIndex);
  1865   MOZ_ASSERT(mIndex->GetActorParent());
  1866   return mIndex->GetActorParent()->IsDisconnected();
  1869 bool
  1870 IndexedDBIndexRequestParent::Get(const GetParams& aParams)
  1872   MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams);
  1873   MOZ_ASSERT(mIndex);
  1875   nsRefPtr<IDBRequest> request;
  1877   nsRefPtr<IDBKeyRange> keyRange =
  1878     IDBKeyRange::FromSerializedKeyRange(aParams.keyRange());
  1879   MOZ_ASSERT(keyRange);
  1882     AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction());
  1884     ErrorResult rv;
  1885     request = mIndex->GetInternal(keyRange, rv);
  1886     ENSURE_SUCCESS(rv, false);
  1889   request->SetActor(this);
  1890   mRequest.swap(request);
  1891   return true;
  1894 bool
  1895 IndexedDBIndexRequestParent::GetKey(const GetKeyParams& aParams)
  1897   MOZ_ASSERT(mRequestType == ParamsUnionType::TGetKeyParams);
  1898   MOZ_ASSERT(mIndex);
  1900   nsRefPtr<IDBRequest> request;
  1902   nsRefPtr<IDBKeyRange> keyRange =
  1903     IDBKeyRange::FromSerializedKeyRange(aParams.keyRange());
  1904   MOZ_ASSERT(keyRange);
  1907     AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction());
  1909     ErrorResult rv;
  1910     request = mIndex->GetKeyInternal(keyRange, rv);
  1911     ENSURE_SUCCESS(rv, false);
  1914   request->SetActor(this);
  1915   mRequest.swap(request);
  1916   return true;
  1919 bool
  1920 IndexedDBIndexRequestParent::GetAll(const GetAllParams& aParams)
  1922   MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams);
  1923   MOZ_ASSERT(mIndex);
  1925   nsRefPtr<IDBRequest> request;
  1927   const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange();
  1929   nsRefPtr<IDBKeyRange> keyRange;
  1931   switch (keyRangeUnion.type()) {
  1932     case ipc::OptionalKeyRange::TKeyRange:
  1933       keyRange =
  1934         IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange());
  1935       break;
  1937     case ipc::OptionalKeyRange::Tvoid_t:
  1938       break;
  1940     default:
  1941       MOZ_CRASH("Unknown param type!");
  1945     AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction());
  1947     ErrorResult rv;
  1948     request = mIndex->GetAllInternal(keyRange, aParams.limit(), rv);
  1949     ENSURE_SUCCESS(rv, false);
  1952   request->SetActor(this);
  1953   mRequest.swap(request);
  1954   return true;
  1957 bool
  1958 IndexedDBIndexRequestParent::GetAllKeys(const GetAllKeysParams& aParams)
  1960   MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams);
  1961   MOZ_ASSERT(mIndex);
  1963   nsRefPtr<IDBRequest> request;
  1965   const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange();
  1967   nsRefPtr<IDBKeyRange> keyRange;
  1969   switch (keyRangeUnion.type()) {
  1970     case ipc::OptionalKeyRange::TKeyRange:
  1971       keyRange =
  1972         IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange());
  1973       break;
  1975     case ipc::OptionalKeyRange::Tvoid_t:
  1976       break;
  1978     default:
  1979       MOZ_CRASH("Unknown param type!");
  1983     AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction());
  1985     ErrorResult rv;
  1986     request = mIndex->GetAllKeysInternal(keyRange, aParams.limit(), rv);
  1987     ENSURE_SUCCESS(rv, false);
  1990   request->SetActor(this);
  1991   mRequest.swap(request);
  1992   return true;
  1995 bool
  1996 IndexedDBIndexRequestParent::Count(const CountParams& aParams)
  1998   MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams);
  1999   MOZ_ASSERT(mIndex);
  2001   const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange();
  2003   nsRefPtr<IDBKeyRange> keyRange;
  2005   switch (keyRangeUnion.type()) {
  2006     case ipc::OptionalKeyRange::TKeyRange:
  2007       keyRange =
  2008         IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange());
  2009       break;
  2011     case ipc::OptionalKeyRange::Tvoid_t:
  2012       break;
  2014     default:
  2015       MOZ_CRASH("Unknown param type!");
  2018   nsRefPtr<IDBRequest> request;
  2021     AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction());
  2023     ErrorResult rv;
  2024     request = mIndex->CountInternal(keyRange, rv);
  2025     ENSURE_SUCCESS(rv, false);
  2028   request->SetActor(this);
  2029   mRequest.swap(request);
  2030   return true;
  2033 bool
  2034 IndexedDBIndexRequestParent::OpenCursor(const OpenCursorParams& aParams)
  2036   MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams);
  2037   MOZ_ASSERT(mIndex);
  2039   const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange();
  2041   nsRefPtr<IDBKeyRange> keyRange;
  2043   switch (keyRangeUnion.type()) {
  2044     case ipc::OptionalKeyRange::TKeyRange:
  2045       keyRange =
  2046         IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange());
  2047       break;
  2049     case ipc::OptionalKeyRange::Tvoid_t:
  2050       break;
  2052     default:
  2053       MOZ_CRASH("Unknown param type!");
  2056   size_t direction = static_cast<size_t>(aParams.direction());
  2058   nsRefPtr<IDBRequest> request;
  2061     AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction());
  2063     nsresult rv =
  2064       mIndex->OpenCursorInternal(keyRange, direction, getter_AddRefs(request));
  2065     NS_ENSURE_SUCCESS(rv, false);
  2068   request->SetActor(this);
  2069   mRequest.swap(request);
  2070   return true;
  2073 bool
  2074 IndexedDBIndexRequestParent::OpenKeyCursor(const OpenKeyCursorParams& aParams)
  2076   MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenKeyCursorParams);
  2077   MOZ_ASSERT(mIndex);
  2079   const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange();
  2081   nsRefPtr<IDBKeyRange> keyRange;
  2083   switch (keyRangeUnion.type()) {
  2084     case ipc::OptionalKeyRange::TKeyRange:
  2085       keyRange =
  2086         IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange());
  2087       break;
  2089     case ipc::OptionalKeyRange::Tvoid_t:
  2090       break;
  2092     default:
  2093       MOZ_CRASH("Unknown param type!");
  2096   size_t direction = static_cast<size_t>(aParams.direction());
  2098   nsRefPtr<IDBRequest> request;
  2101     AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction());
  2103     ErrorResult rv;
  2104     request = mIndex->OpenKeyCursorInternal(keyRange, direction, rv);
  2105     ENSURE_SUCCESS(rv, false);
  2108   request->SetActor(this);
  2109   mRequest.swap(request);
  2110   return true;
  2113 /*******************************************************************************
  2114  * IndexedDBCursorRequestParent
  2115  ******************************************************************************/
  2117 IndexedDBCursorRequestParent::IndexedDBCursorRequestParent(
  2118                                                        IDBCursor* aCursor,
  2119                                                        RequestType aRequestType)
  2120 : mCursor(aCursor), mRequestType(aRequestType)
  2122   MOZ_COUNT_CTOR(IndexedDBCursorRequestParent);
  2123   MOZ_ASSERT(aCursor);
  2124   MOZ_ASSERT(aRequestType > ParamsUnionType::T__None &&
  2125              aRequestType <= ParamsUnionType::T__Last);
  2128 IndexedDBCursorRequestParent::~IndexedDBCursorRequestParent()
  2130   MOZ_COUNT_DTOR(IndexedDBCursorRequestParent);
  2133 bool
  2134 IndexedDBCursorRequestParent::IsDisconnected()
  2136   MOZ_ASSERT(mCursor);
  2137   MOZ_ASSERT(mCursor->GetActorParent());
  2138   return mCursor->GetActorParent()->IsDisconnected();
  2141 bool
  2142 IndexedDBCursorRequestParent::Continue(const ContinueParams& aParams)
  2144   MOZ_ASSERT(mCursor);
  2145   MOZ_ASSERT(mRequestType == ParamsUnionType::TContinueParams);
  2148     AutoSetCurrentTransaction asct(mCursor->Transaction());
  2150     ErrorResult rv;
  2151     mCursor->ContinueInternal(aParams.key(), aParams.count(), rv);
  2152     ENSURE_SUCCESS(rv, false);
  2155   mRequest = mCursor->Request();
  2156   MOZ_ASSERT(mRequest);
  2158   mRequest->SetActor(this);
  2159   return true;
  2162 /*******************************************************************************
  2163  * IndexedDBDeleteDatabaseRequestParent
  2164  ******************************************************************************/
  2166 IndexedDBDeleteDatabaseRequestParent::IndexedDBDeleteDatabaseRequestParent(
  2167                                                            IDBFactory* aFactory)
  2168 : mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()), mFactory(aFactory)
  2170   MOZ_COUNT_CTOR(IndexedDBDeleteDatabaseRequestParent);
  2171   MOZ_ASSERT(aFactory);
  2174 IndexedDBDeleteDatabaseRequestParent::~IndexedDBDeleteDatabaseRequestParent()
  2176   MOZ_COUNT_DTOR(IndexedDBDeleteDatabaseRequestParent);
  2179 nsresult
  2180 IndexedDBDeleteDatabaseRequestParent::HandleEvent(nsIDOMEvent* aEvent)
  2182   MOZ_ASSERT(aEvent);
  2184   if (IsDisconnected()) {
  2185     // We're shutting down, ignore this event.
  2186     return NS_OK;
  2189   nsString type;
  2190   nsresult rv = aEvent->GetType(type);
  2191   NS_ENSURE_SUCCESS(rv, rv);
  2193   if (type.EqualsASCII(BLOCKED_EVT_STR)) {
  2194     nsCOMPtr<IDBVersionChangeEvent> event = do_QueryInterface(aEvent);
  2195     MOZ_ASSERT(event);
  2197     uint64_t currentVersion = event->OldVersion();
  2199     if (!SendBlocked(currentVersion)) {
  2200       return NS_ERROR_FAILURE;
  2203     return NS_OK;
  2206 #ifdef DEBUG
  2207   if (type.EqualsASCII(SUCCESS_EVT_STR)) {
  2208     MOZ_ASSERT(NS_SUCCEEDED(mOpenRequest->GetErrorCode()));
  2210   else {
  2211     MOZ_ASSERT(type.EqualsASCII(ERROR_EVT_STR));
  2212     MOZ_ASSERT(NS_FAILED(mOpenRequest->GetErrorCode()));
  2214 #endif
  2216   if (!Send__delete__(this, mOpenRequest->GetErrorCode())) {
  2217     return NS_ERROR_FAILURE;
  2220   return NS_OK;
  2223 nsresult
  2224 IndexedDBDeleteDatabaseRequestParent::SetOpenRequest(
  2225                                                  IDBOpenDBRequest* aOpenRequest)
  2227   MOZ_ASSERT(aOpenRequest);
  2228   MOZ_ASSERT(!mOpenRequest);
  2230   EventTarget* target = static_cast<EventTarget*>(aOpenRequest);
  2232   nsresult rv = target->AddEventListener(NS_LITERAL_STRING(SUCCESS_EVT_STR),
  2233                                          mEventListener, false);
  2234   NS_ENSURE_SUCCESS(rv, rv);
  2236   rv = target->AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR),
  2237                                 mEventListener, false);
  2238   NS_ENSURE_SUCCESS(rv, rv);
  2240   rv = target->AddEventListener(NS_LITERAL_STRING(BLOCKED_EVT_STR),
  2241                                 mEventListener, false);
  2242   NS_ENSURE_SUCCESS(rv, rv);
  2244   mOpenRequest = aOpenRequest;
  2245   return NS_OK;
  2248 /*******************************************************************************
  2249  * WeakEventListener
  2250  ******************************************************************************/
  2252  NS_IMPL_ISUPPORTS(WeakEventListenerBase, nsIDOMEventListener)
  2254  NS_IMETHODIMP
  2255  WeakEventListenerBase::HandleEvent(nsIDOMEvent* aEvent)
  2257   MOZ_CRASH("This must be overridden!");

mercurial