Bug 749086 - 2/3: DOM & IPC changes. r=bent, a=leo+
authorVicamo Yang <vyang@mozilla.com>
Thu, 18 Apr 2013 09:09:45 +0800
changeset 119102 417880a025d11069d9aa7acd9af101feaef27ad3
parent 119101 3a29c841f3b296cfdeae9ed0bdec044b69066916
child 119103 eb102e6d41c0593e96c35f81e54232826f4bcb07
push id680
push uservyang@mozilla.com
push dateThu, 18 Apr 2013 01:11:41 +0000
reviewersbent, leo
bugs749086
milestone18.0
Bug 749086 - 2/3: DOM & IPC changes. r=bent, a=leo+
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/mobilemessage/interfaces/Makefile.in
dom/mobilemessage/src/Makefile.in
dom/mobilemessage/src/MobileMessageManager.cpp
dom/mobilemessage/src/SmsManager.cpp
dom/mobilemessage/src/SmsManager.h
dom/mobilemessage/src/SmsRequest.cpp
dom/mobilemessage/src/SmsRequest.h
dom/mobilemessage/src/ipc/SmsChild.cpp
dom/mobilemessage/src/ipc/SmsIPCService.cpp
dom/mobilemessage/src/ipc/SmsParent.cpp
dom/mobilemessage/src/ipc/SmsParent.h
dom/system/gonk/ril_worker.js
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -494,17 +494,16 @@ using mozilla::dom::indexedDB::IDBWrappe
 #include "BatteryManager.h"
 #include "nsIDOMPowerManager.h"
 #include "nsIDOMWakeLock.h"
 #include "nsIDOMSmsManager.h"
 #include "nsIDOMMobileMessageManager.h"
 #include "nsIDOMSmsMessage.h"
 #include "nsIDOMMozMmsMessage.h"
 #include "nsIDOMSmsEvent.h"
-#include "nsIDOMSmsRequest.h"
 #include "nsIDOMSmsFilter.h"
 #include "nsIDOMSmsSegmentInfo.h"
 #include "nsIDOMMozMobileMessageThread.h"
 #include "nsIDOMConnection.h"
 #ifdef MOZ_B2G_RIL
 #include "nsIDOMMobileConnection.h"
 #endif
 #include "USSDReceivedEvent.h"
@@ -1524,19 +1523,16 @@ static nsDOMClassInfoData sClassInfoData
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(MozMmsMessage, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(MozSmsEvent, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
-  NS_DEFINE_CLASSINFO_DATA(MozSmsRequest, nsDOMGenericSH,
-                           DOM_DEFAULT_SCRIPTABLE_FLAGS)
-
   NS_DEFINE_CLASSINFO_DATA(MozSmsFilter, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(MozSmsSegmentInfo, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(MozMobileMessageThread, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
@@ -4175,21 +4171,16 @@ nsDOMClassInfo::Init()
      DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozMmsMessage)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(MozSmsEvent, nsIDOMMozSmsEvent)
      DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsEvent)
      DOM_CLASSINFO_EVENT_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
 
-  DOM_CLASSINFO_MAP_BEGIN(MozSmsRequest, nsIDOMMozSmsRequest)
-     DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsRequest)
-     DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
-  DOM_CLASSINFO_MAP_END
-
   DOM_CLASSINFO_MAP_BEGIN(MozSmsFilter, nsIDOMMozSmsFilter)
      DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsFilter)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(MozSmsSegmentInfo, nsIDOMMozSmsSegmentInfo)
      DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsSegmentInfo)
   DOM_CLASSINFO_MAP_END
 
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -398,17 +398,16 @@ DOMCI_CLASS(BatteryManager)
 DOMCI_CLASS(MozPowerManager)
 DOMCI_CLASS(MozWakeLock)
 
 DOMCI_CLASS(MozSmsManager)
 DOMCI_CLASS(MozMobileMessageManager)
 DOMCI_CLASS(MozSmsMessage)
 DOMCI_CLASS(MozMmsMessage)
 DOMCI_CLASS(MozSmsEvent)
-DOMCI_CLASS(MozSmsRequest)
 DOMCI_CLASS(MozSmsFilter)
 DOMCI_CLASS(MozSmsSegmentInfo)
 DOMCI_CLASS(MozMobileMessageThread)
 
 DOMCI_CLASS(MozConnection)
 #ifdef MOZ_B2G_RIL
 DOMCI_CLASS(MozMobileConnection)
 DOMCI_CLASS(MozCellBroadcast)
--- a/dom/mobilemessage/interfaces/Makefile.in
+++ b/dom/mobilemessage/interfaces/Makefile.in
@@ -19,17 +19,16 @@ XPIDLSRCS = \
   nsIDOMNavigatorMobileMessage.idl \
   nsIDOMSmsManager.idl \
   nsIDOMMobileMessageManager.idl \
   nsIDOMSmsMessage.idl \
   nsIDOMMozMmsMessage.idl \
   nsIDOMSmsEvent.idl \
   nsIDOMMozMmsEvent.idl \
   nsIDOMMozMobileMessageThread.idl \
-  nsIDOMSmsRequest.idl \
   nsIDOMSmsFilter.idl \
   nsIDOMSmsSegmentInfo.idl \
   nsIMobileMessageCallback.idl \
   nsIMobileMessageCursorCallback.idl \
   nsIMobileMessageService.idl \
   nsISmsService.idl \
   $(NULL)
 
--- a/dom/mobilemessage/src/Makefile.in
+++ b/dom/mobilemessage/src/Makefile.in
@@ -34,17 +34,16 @@ EXPORTS_NAMESPACES = \
   mozilla/dom/mobilemessage \
   $(NULL)
 
 EXPORTS_mozilla/dom = \
   SmsManager.h \
   MobileMessageManager.h \
   SmsMessage.h \
   MmsMessage.h \
-  SmsRequest.h \
   SmsSegmentInfo.h \
   SmsFilter.h \
   $(NULL)
 
 EXPORTS_mozilla/dom/mobilemessage = \
   SmsChild.h \
   SmsParent.h \
   MobileMessageService.h \
@@ -64,17 +63,16 @@ CPPSRCS = \
   SmsIPCService.cpp \
   SmsServicesFactory.cpp \
   SmsParent.cpp \
   SmsMessage.cpp \
   MmsMessage.cpp \
   SmsEvent.cpp \
   Constants.cpp \
   SmsChild.cpp \
-  SmsRequest.cpp \
   MobileMessageCallback.cpp \
   SmsFilter.cpp \
   SmsSegmentInfo.cpp \
   $(NULL)
 
 LOCAL_INCLUDES = \
   -I$(topsrcdir)/content/events/src \
   -I$(topsrcdir)/dom/base \
--- a/dom/mobilemessage/src/MobileMessageManager.cpp
+++ b/dom/mobilemessage/src/MobileMessageManager.cpp
@@ -11,17 +11,16 @@
 #include "nsIObserverService.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "Constants.h"
 #include "SmsEvent.h"
 #include "nsIDOMMozMmsEvent.h"
 #include "nsIDOMSmsMessage.h"
 #include "nsIDOMMozMmsMessage.h"
-#include "SmsRequest.h"
 #include "nsJSUtils.h"
 #include "nsContentUtils.h"
 #include "nsIMobileMessageDatabaseService.h"
 #include "nsIXPConnect.h"
 #include "nsIPermissionManager.h"
 #include "GeneratedEvents.h"
 #include "DOMRequest.h"
 #include "nsIMobileMessageCallback.h"
@@ -126,31 +125,31 @@ MobileMessageManager::GetSegmentInfoForT
   return smsService->GetSegmentInfoForText(aText, aResult);
 }
 
 nsresult
 MobileMessageManager::Send(JSContext* aCx, JSObject* aGlobal, JSString* aNumber,
                            const nsAString& aMessage, jsval* aRequest)
 {
   nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
-  if (!smsService) {
-    NS_ERROR("No SMS Service!");
-    return NS_ERROR_FAILURE;
-  }
+  NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
 
-  nsCOMPtr<nsIDOMMozSmsRequest> request = SmsRequest::Create(this);
   nsDependentJSString number;
   number.init(aCx, aNumber);
 
-  nsCOMPtr<nsIMobileMessageCallback> forwarder =
-    new SmsRequestForwarder(static_cast<SmsRequest*>(request.get()));
+  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
+  nsCOMPtr<nsIMobileMessageCallback> msgCallback =
+    new MobileMessageCallback(request);
 
-  smsService->Send(number, aMessage, forwarder);
+  nsresult rv = smsService->Send(number, aMessage, msgCallback);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  nsresult rv = nsContentUtils::WrapNative(aCx, aGlobal, request, aRequest);
+  rv = nsContentUtils::WrapNative(aCx, aGlobal,
+                                  static_cast<nsIDOMDOMRequest*>(request.get()),
+                                  aRequest);
   if (NS_FAILED(rv)) {
     NS_ERROR("Failed to create the js value!");
     return rv;
   }
 
   return NS_OK;
 }
 
--- a/dom/mobilemessage/src/SmsManager.cpp
+++ b/dom/mobilemessage/src/SmsManager.cpp
@@ -8,22 +8,22 @@
 #include "nsIDOMClassInfo.h"
 #include "nsISmsService.h"
 #include "nsIObserverService.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "Constants.h"
 #include "SmsEvent.h"
 #include "nsIDOMSmsMessage.h"
-#include "SmsRequest.h"
 #include "nsJSUtils.h"
 #include "nsContentUtils.h"
 #include "nsIMobileMessageDatabaseService.h"
 #include "nsIXPConnect.h"
 #include "nsIPermissionManager.h"
+#include "MobileMessageCallback.h"
 #include "MobileMessageCursorCallback.h"
 #include "DOMCursor.h"
 
 #define RECEIVED_EVENT_NAME         NS_LITERAL_STRING("received")
 #define SENDING_EVENT_NAME          NS_LITERAL_STRING("sending")
 #define SENT_EVENT_NAME             NS_LITERAL_STRING("sent")
 #define FAILED_EVENT_NAME           NS_LITERAL_STRING("failed")
 #define DELIVERY_SUCCESS_EVENT_NAME NS_LITERAL_STRING("deliverysuccess")
@@ -150,31 +150,31 @@ SmsManager::GetSegmentInfoForText(const 
   return smsService->GetSegmentInfoForText(aText, aResult);
 }
 
 nsresult
 SmsManager::Send(JSContext* aCx, JSObject* aGlobal, JSString* aNumber,
                  const nsAString& aMessage, jsval* aRequest)
 {
   nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
-  if (!smsService) {
-    NS_ERROR("No SMS Service!");
-    return NS_ERROR_FAILURE;
-  }
+  NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
 
-  nsCOMPtr<nsIDOMMozSmsRequest> request = SmsRequest::Create(this);
   nsDependentJSString number;
   number.init(aCx, aNumber);
 
-  nsCOMPtr<nsIMobileMessageCallback> forwarder =
-    new SmsRequestForwarder(static_cast<SmsRequest*>(request.get()));
+  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
+  nsCOMPtr<nsIMobileMessageCallback> msgCallback =
+    new MobileMessageCallback(request);
 
-  smsService->Send(number, aMessage, forwarder);
+  nsresult rv = smsService->Send(number, aMessage, msgCallback);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  nsresult rv = nsContentUtils::WrapNative(aCx, aGlobal, request, aRequest);
+  rv = nsContentUtils::WrapNative(aCx, aGlobal,
+                                  static_cast<nsIDOMDOMRequest*>(request.get()),
+                                  aRequest);
   if (NS_FAILED(rv)) {
     NS_ERROR("Failed to create the js value!");
     return rv;
   }
 
   return NS_OK;
 }
 
@@ -222,46 +222,53 @@ SmsManager::Send(const jsval& aNumber, c
 
   aReturn->setObjectOrNull(JS_NewArrayObject(cx, size, requests));
   NS_ENSURE_TRUE(aReturn->isObject(), NS_ERROR_FAILURE);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-SmsManager::GetMessageMoz(int32_t aId, nsIDOMMozSmsRequest** aRequest)
+SmsManager::GetMessageMoz(int32_t aId, nsIDOMDOMRequest** aRequest)
 {
-  nsCOMPtr<nsIDOMMozSmsRequest> req = SmsRequest::Create(this);
-  nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
+  nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
     do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
-  nsCOMPtr<nsIMobileMessageCallback> forwarder =
-    new SmsRequestForwarder(static_cast<SmsRequest*>(req.get()));
-  mobileMessageDBService->GetMessageMoz(aId, forwarder);
-  req.forget(aRequest);
+  NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
+
+  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
+  nsCOMPtr<nsIMobileMessageCallback> msgCallback =
+    new MobileMessageCallback(request);
+
+  nsresult rv = dbService->GetMessageMoz(aId, msgCallback);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  request.forget(aRequest);
   return NS_OK;
 }
 
 nsresult
-SmsManager::Delete(int32_t aId, nsIDOMMozSmsRequest** aRequest)
+SmsManager::Delete(int32_t aId, nsIDOMDOMRequest** aRequest)
 {
-  nsCOMPtr<nsIDOMMozSmsRequest> req = SmsRequest::Create(this);
-  nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
+  nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
     do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
 
-  nsCOMPtr<nsIMobileMessageCallback> forwarder =
-    new SmsRequestForwarder(static_cast<SmsRequest*>(req.get()));
-  mobileMessageDBService->DeleteMessage(aId, forwarder);
-  req.forget(aRequest);
+  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
+  nsCOMPtr<nsIMobileMessageCallback> msgCallback =
+    new MobileMessageCallback(request);
+
+  nsresult rv = dbService->DeleteMessage(aId, msgCallback);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  request.forget(aRequest);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-SmsManager::Delete(const jsval& aParam, nsIDOMMozSmsRequest** aRequest)
+SmsManager::Delete(const jsval& aParam, nsIDOMDOMRequest** aRequest)
 {
   if (aParam.isInt32()) {
     return Delete(aParam.toInt32(), aRequest);
   }
 
   if (!aParam.isObject()) {
     return NS_ERROR_INVALID_ARG;
   }
@@ -305,26 +312,30 @@ SmsManager::GetMessages(nsIDOMMozSmsFilt
   cursorCallback->mDOMCursor = new DOMCursor(GetOwner(), continueCallback);
   NS_ADDREF(*aCursor = cursorCallback->mDOMCursor);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SmsManager::MarkMessageRead(int32_t aId, bool aValue,
-                            nsIDOMMozSmsRequest** aRequest)
+                            nsIDOMDOMRequest** aRequest)
 {
-  nsCOMPtr<nsIDOMMozSmsRequest> req = SmsRequest::Create(this);
-  nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
+  nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
     do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
-  nsCOMPtr<nsIMobileMessageCallback> forwarder =
-    new SmsRequestForwarder(static_cast<SmsRequest*>(req.get()));
-  mobileMessageDBService->MarkMessageRead(aId, aValue, forwarder);
-  req.forget(aRequest);
+  NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
+
+  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
+  nsCOMPtr<nsIMobileMessageCallback> msgCallback =
+    new MobileMessageCallback(request);
+
+  nsresult rv = dbService->MarkMessageRead(aId, aValue, msgCallback);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  request.forget(aRequest);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SmsManager::GetThreads(nsIDOMDOMCursor** aCursor)
 {
   nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
     do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
--- a/dom/mobilemessage/src/SmsManager.h
+++ b/dom/mobilemessage/src/SmsManager.h
@@ -40,17 +40,17 @@ private:
    * Internal Send() method used to send one message.
    */
   nsresult Send(JSContext* aCx, JSObject* aGlobal, JSString* aNumber,
                 const nsAString& aMessage, jsval* aRequest);
 
   /**
    * Internal Delete() method used to delete a message.
    */
-  nsresult Delete(int32_t aId, nsIDOMMozSmsRequest** aRequest);
+  nsresult Delete(int32_t aId, nsIDOMDOMRequest** aRequest);
 
   nsresult DispatchTrustedSmsEventToSelf(const nsAString& aEventName,
                                          nsIDOMMozSmsMessage* aMessage);
 };
 
 } // namespace dom
 } // namespace mozilla
 
deleted file mode 100644
--- a/dom/mobilemessage/src/SmsRequest.cpp
+++ /dev/null
@@ -1,383 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "SmsRequest.h"
-#include "nsIDOMClassInfo.h"
-#include "nsDOMEvent.h"
-#include "nsDOMString.h"
-#include "nsContentUtils.h"
-#include "nsIDOMSmsMessage.h"
-#include "nsIScriptGlobalObject.h"
-#include "nsPIDOMWindow.h"
-#include "SmsMessage.h"
-#include "SmsManager.h"
-#include "MobileMessageManager.h"
-#include "mozilla/dom/DOMError.h"
-#include "SmsParent.h"
-#include "jsapi.h"
-#include "DictionaryHelpers.h"
-#include "xpcpublic.h"
-
-#define SUCCESS_EVENT_NAME NS_LITERAL_STRING("success")
-#define ERROR_EVENT_NAME   NS_LITERAL_STRING("error")
-
-using namespace mozilla::dom::mobilemessage;
-
-DOMCI_DATA(MozSmsRequest, mozilla::dom::SmsRequest)
-
-namespace mozilla {
-namespace dom {
-
-NS_IMPL_ISUPPORTS1(SmsRequestForwarder, nsIMobileMessageCallback)
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(SmsRequest)
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SmsRequest,
-                                                  nsDOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mError)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SmsRequest,
-                                                nsDOMEventTargetHelper)
-  tmp->mResult = JSVAL_VOID;
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mError)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(SmsRequest,
-                                               nsDOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mResult)
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SmsRequest)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMMozSmsRequest)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMDOMRequest)
-  NS_INTERFACE_MAP_ENTRY(nsIMobileMessageCallback)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMozSmsRequest)
-  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozSmsRequest)
-NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
-
-NS_IMPL_ADDREF_INHERITED(SmsRequest, nsDOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(SmsRequest, nsDOMEventTargetHelper)
-
-NS_IMPL_EVENT_HANDLER(SmsRequest, success)
-NS_IMPL_EVENT_HANDLER(SmsRequest, error)
-
-already_AddRefed<nsIDOMMozSmsRequest>
-SmsRequest::Create(SmsManager* aManager)
-{
-  nsCOMPtr<nsIDOMMozSmsRequest> request = new SmsRequest(aManager);
-  return request.forget();
-}
-
-already_AddRefed<nsIDOMMozSmsRequest>
-SmsRequest::Create(MobileMessageManager* aManager)
-{
-  nsCOMPtr<nsIDOMMozSmsRequest> request = new SmsRequest(aManager);
-  return request.forget();
-}
-
-already_AddRefed<SmsRequest>
-SmsRequest::Create(SmsRequestParent* aRequestParent)
-{
-  nsRefPtr<SmsRequest> request = new SmsRequest(aRequestParent);
-  return request.forget();
-}
-
-SmsRequest::SmsRequest(SmsManager* aManager)
-  : mResult(JSVAL_VOID)
-  , mDone(false)
-  , mParentAlive(false)
-  , mParent(nullptr)
-{
-  BindToOwner(aManager);
-}
-
-SmsRequest::SmsRequest(MobileMessageManager* aManager)
-  : mResult(JSVAL_VOID)
-  , mDone(false)
-  , mParentAlive(false)
-  , mParent(nullptr)
-{
-  BindToOwner(aManager);
-}
-
-SmsRequest::SmsRequest(SmsRequestParent* aRequestParent)
-  : mResult(JSVAL_VOID)
-  , mDone(false)
-  , mParentAlive(true)
-  , mParent(aRequestParent)
-{
-  MOZ_ASSERT(aRequestParent);
-}
-
-SmsRequest::~SmsRequest()
-{
-  mResult = JSVAL_VOID;
-  NS_DROP_JS_OBJECTS(this, SmsRequest);
-}
-
-void
-SmsRequest::SetSuccess(nsIDOMMozSmsMessage* aMessage)
-{
-  SetSuccessInternal(aMessage);
-}
-
-void
-SmsRequest::SetSuccess(bool aResult)
-{
-  SetSuccess(aResult ? JSVAL_TRUE : JSVAL_FALSE);
-}
-
-void
-SmsRequest::SetSuccess(const jsval& aResult)
-{
-  NS_PRECONDITION(!mDone, "mDone shouldn't have been set to true already!");
-  NS_PRECONDITION(!mError, "mError shouldn't have been set!");
-  NS_PRECONDITION(JSVAL_IS_VOID(mResult), "mResult shouldn't have been set!");
-
-  mResult = aResult;
-  mDone = true;
-}
-
-bool
-SmsRequest::SetSuccessInternal(nsISupports* aObject)
-{
-  NS_PRECONDITION(!mDone, "mDone shouldn't have been set to true already!");
-  NS_PRECONDITION(!mError, "mError shouldn't have been set!");
-  NS_PRECONDITION(mResult == JSVAL_VOID, "mResult shouldn't have been set!");
-
-  nsresult rv;
-  nsIScriptContext* sc = GetContextForEventHandlers(&rv);
-  if (!sc) {
-    SetError(nsIMobileMessageCallback::INTERNAL_ERROR);
-    return false;
-  }
-
-  JSContext* cx = sc->GetNativeContext();    
-  NS_ASSERTION(cx, "Failed to get a context!");
-
-  JSObject* global = sc->GetNativeGlobal();
-  NS_ASSERTION(global, "Failed to get global object!");
-
-  JSAutoRequest ar(cx);
-  JSAutoCompartment ac(cx, global);
-
-  NS_HOLD_JS_OBJECTS(this, SmsRequest);
-
-  if (NS_FAILED(nsContentUtils::WrapNative(cx, global, aObject, &mResult))) {
-    mResult = JSVAL_VOID;
-    SetError(nsIMobileMessageCallback::INTERNAL_ERROR);
-    return false;
-  }
-
-  mDone = true;
-  return true;
-}
-
-void
-SmsRequest::SetError(int32_t aError)
-{
-  NS_PRECONDITION(!mDone, "mDone shouldn't have been set to true already!");
-  NS_PRECONDITION(!mError, "mError shouldn't have been set!");
-  NS_PRECONDITION(mResult == JSVAL_VOID, "mResult shouldn't have been set!");
-  NS_PRECONDITION(aError != nsIMobileMessageCallback::SUCCESS_NO_ERROR,
-                  "Can't call SetError() with SUCCESS_NO_ERROR!");
-
-  mDone = true;
-
-  switch (aError) {
-    case nsIMobileMessageCallback::NO_SIGNAL_ERROR:
-      mError = DOMError::CreateWithName(NS_LITERAL_STRING("NoSignalError"));
-      break;
-    case nsIMobileMessageCallback::NOT_FOUND_ERROR:
-      mError = DOMError::CreateWithName(NS_LITERAL_STRING("NotFoundError"));
-      break;
-    case nsIMobileMessageCallback::UNKNOWN_ERROR:
-      mError = DOMError::CreateWithName(NS_LITERAL_STRING("UnknownError"));
-      break;
-    case nsIMobileMessageCallback::INTERNAL_ERROR:
-      mError = DOMError::CreateWithName(NS_LITERAL_STRING("InternalError"));
-      break;
-    default: // SUCCESS_NO_ERROR is handled above.
-      MOZ_ASSERT(false, "Unknown error value.");
-  }
-}
-
-NS_IMETHODIMP
-SmsRequest::GetReadyState(nsAString& aReadyState)
-{
-  if (mDone) {
-    aReadyState.AssignLiteral("done");
-  } else {
-    aReadyState.AssignLiteral("processing");
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-SmsRequest::GetError(nsIDOMDOMError** aError)
-{
-  NS_ASSERTION(mDone || !mError, "mError should be null when pending");
-  NS_ASSERTION(!mError || mResult == JSVAL_VOID,
-               "mResult should be void when there is an error!");
-
-  NS_IF_ADDREF(*aError = mError);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-SmsRequest::GetResult(jsval* aResult)
-{
-  if (!mDone) {
-    NS_ASSERTION(mResult == JSVAL_VOID,
-                 "When not done, result should be null!");
-
-    *aResult = JSVAL_VOID;
-    return NS_OK;
-  }
-
-  *aResult = mResult;
-  return NS_OK;
-}
-
-nsresult
-SmsRequest::DispatchTrustedEvent(const nsAString& aEventName)
-{
-  nsRefPtr<nsDOMEvent> event = new nsDOMEvent(nullptr, nullptr);
-  nsresult rv = event->InitEvent(aEventName, false, false);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = event->SetTrusted(true);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  bool dummy;
-  return DispatchEvent(event, &dummy);
-}
-
-template <class T>
-nsresult
-SmsRequest::NotifySuccess(T aParam)
-{
-  SetSuccess(aParam);
-  nsresult rv = DispatchTrustedEvent(SUCCESS_EVENT_NAME);
-  return rv;
-}
-
-nsresult
-SmsRequest::NotifyError(int32_t aError)
-{
-  SetError(aError);
-
-  nsresult rv = DispatchTrustedEvent(ERROR_EVENT_NAME);
-  return rv;
-}
-
-nsresult
-SmsRequest::SendMessageReply(const MessageReply& aReply)
-{
-  if (mParentAlive) {
-    mParent->SendReply(aReply);
-    mParent = nullptr;
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-SmsRequest::NotifyMessageSent(nsISupports *aMessage)
-{
-  // We only support nsIDOMMozSmsMessage for SmsRequest.
-  nsCOMPtr<nsIDOMMozSmsMessage> message(do_QueryInterface(aMessage));
-  if (!message) {
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-
-  SmsMessage* smsMessage = static_cast<SmsMessage*>(message.get());
-
-  if (mParent) {
-    SmsMessageData data = SmsMessageData(smsMessage->GetData());
-    return SendMessageReply(MessageReply(ReplyMessageSend(data)));
-  }
-  return NotifySuccess<nsIDOMMozSmsMessage*>(smsMessage);
-}
-
-NS_IMETHODIMP
-SmsRequest::NotifySendMessageFailed(int32_t aError)
-{
-  if (mParent) {
-    return SendMessageReply(MessageReply(ReplyMessageSendFail(aError)));
-  }
-  return NotifyError(aError);
-
-}
-
-NS_IMETHODIMP
-SmsRequest::NotifyMessageGot(nsISupports *aMessage)
-{
-  // We only support nsIDOMMozSmsMessage for SmsRequest.
-  nsCOMPtr<nsIDOMMozSmsMessage> message(do_QueryInterface(aMessage));
-  if (!message) {
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-
-  SmsMessage* smsMessage = static_cast<SmsMessage*>(message.get());
-
-  if (mParent) {
-    SmsMessageData data = SmsMessageData(smsMessage->GetData());
-    return SendMessageReply(MessageReply(ReplyGetMessage(data)));
-  }
-  return NotifySuccess<nsIDOMMozSmsMessage*>(smsMessage);
-
-}
-
-NS_IMETHODIMP
-SmsRequest::NotifyGetMessageFailed(int32_t aError)
-{
-  if (mParent) {
-    return SendMessageReply(MessageReply(ReplyGetMessageFail(aError)));
-  }
-  return NotifyError(aError);
-}
-
-NS_IMETHODIMP
-SmsRequest::NotifyMessageDeleted(bool aDeleted)
-{
-  if (mParent) {
-    return SendMessageReply(MessageReply(ReplyMessageDelete(aDeleted)));
-  }
-  return NotifySuccess<bool>(aDeleted);
-}
-
-NS_IMETHODIMP
-SmsRequest::NotifyDeleteMessageFailed(int32_t aError)
-{
-  if (mParent) {
-    return SendMessageReply(MessageReply(ReplyMessageDeleteFail(aError)));
-  }
-  return NotifyError(aError);
-}
-
-NS_IMETHODIMP
-SmsRequest::NotifyMessageMarkedRead(bool aRead)
-{
-  if (mParent) {
-    return SendMessageReply(MessageReply(ReplyMarkeMessageRead(aRead)));
-  }
-  return NotifySuccess<bool>(aRead);
-}
-
-NS_IMETHODIMP
-SmsRequest::NotifyMarkMessageReadFailed(int32_t aError)
-{
-  if (mParent) {
-    return SendMessageReply(MessageReply(ReplyMarkeMessageReadFail(aError)));
-  }
-  return NotifyError(aError);
-}
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/mobilemessage/src/SmsRequest.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_mobilemessage_SmsRequest_h
-#define mozilla_dom_mobilemessage_SmsRequest_h
-
-#include "nsIDOMSmsRequest.h"
-#include "nsIMobileMessageCallback.h"
-#include "nsDOMEventTargetHelper.h"
-
-class nsIDOMMozSmsMessage;
-
-namespace mozilla {
-namespace dom {
-
-namespace mobilemessage {
-  class SmsRequestChild;
-  class SmsRequestParent;
-  class MessageReply;
-  class ThreadListItem;
-}
-
-// We need this forwarder to avoid a QI to nsIClassInfo.
-// See: https://bugzilla.mozilla.org/show_bug.cgi?id=775997#c51 
-class SmsRequestForwarder : public nsIMobileMessageCallback
-{
-  friend class mobilemessage::SmsRequestChild;
-
-public:
-  NS_DECL_ISUPPORTS
-  NS_FORWARD_NSIMOBILEMESSAGECALLBACK(mRealRequest->)
-
-  SmsRequestForwarder(nsIMobileMessageCallback* aRealRequest) {
-    mRealRequest = aRealRequest;
-  }
-
-private:
-  virtual
-  ~SmsRequestForwarder() {}
-
-  nsIMobileMessageCallback* GetRealRequest() {
-    return mRealRequest;
-  }
-
-  nsCOMPtr<nsIMobileMessageCallback> mRealRequest;
-};
-
-class SmsManager;
-class MobileMessageManager;
-
-class SmsRequest : public nsDOMEventTargetHelper
-                 , public nsIDOMMozSmsRequest
-                 , public nsIMobileMessageCallback
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIDOMDOMREQUEST
-  NS_DECL_NSIMOBILEMESSAGECALLBACK
-  NS_DECL_NSIDOMMOZSMSREQUEST
-
-  NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
-
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(SmsRequest,
-                                                         nsDOMEventTargetHelper)
-
-  static already_AddRefed<nsIDOMMozSmsRequest> Create(SmsManager* aManager);
-  static already_AddRefed<nsIDOMMozSmsRequest> Create(MobileMessageManager* aManager);
-
-  static already_AddRefed<SmsRequest> Create(mobilemessage::SmsRequestParent* requestParent);
-  void SetActorDied() {
-    mParentAlive = false;
-  }
-
-  void
-  NotifyThreadList(const InfallibleTArray<mobilemessage::ThreadListItem>& aItems);
-
-private:
-  SmsRequest() MOZ_DELETE;
-
-  SmsRequest(SmsManager* aManager);
-  SmsRequest(MobileMessageManager* aManager);
-  SmsRequest(mobilemessage::SmsRequestParent* aParent);
-  ~SmsRequest();
-
-  nsresult SendMessageReply(const mobilemessage::MessageReply& aReply);
-
-  /**
-   * Set the object in a success state with the result being aMessage.
-   */
-  void SetSuccess(nsIDOMMozSmsMessage* aMessage);
-
-  /**
-   * Set the object in a success state with the result being a boolean.
-   */
-  void SetSuccess(bool aResult);
-
-  /**
-   * Set the object in a success state with the result being the given jsval.
-   */
-  void SetSuccess(const jsval& aVal);
-
-  /**
-   * Set the object in an error state with the error type being aError.
-   */
-  void SetError(int32_t aError);
-
-  /**
-   * Set the object in a success state with the result being the nsISupports
-   * object in parameter.
-   * @return whether setting the object was a success
-   */
-  bool SetSuccessInternal(nsISupports* aObject);
-
-  nsresult DispatchTrustedEvent(const nsAString& aEventName);
-
-  template <class T>
-  nsresult NotifySuccess(T aParam);
-  nsresult NotifyError(int32_t aError);
-
-  jsval     mResult;
-  bool      mDone;
-  bool      mParentAlive;
-  mobilemessage::SmsRequestParent* mParent;
-  nsCOMPtr<nsIDOMDOMError> mError;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_mobilemessage_SmsRequest_h
--- a/dom/mobilemessage/src/ipc/SmsChild.cpp
+++ b/dom/mobilemessage/src/ipc/SmsChild.cpp
@@ -3,17 +3,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SmsChild.h"
 #include "SmsMessage.h"
 #include "Constants.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "mozilla/dom/ContentChild.h"
-#include "SmsRequest.h"
 #include "MobileMessageThread.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::dom::mobilemessage;
 
 namespace {
 
--- a/dom/mobilemessage/src/ipc/SmsIPCService.cpp
+++ b/dom/mobilemessage/src/ipc/SmsIPCService.cpp
@@ -5,17 +5,16 @@
 
 #include "mozilla/dom/ContentChild.h"
 #include "SmsIPCService.h"
 #include "nsXULAppAPI.h"
 #include "jsapi.h"
 #include "mozilla/dom/mobilemessage/SmsChild.h"
 #include "SmsMessage.h"
 #include "SmsFilter.h"
-#include "SmsRequest.h"
 #include "SmsSegmentInfo.h"
 
 using namespace mozilla::dom;
 using namespace mozilla::dom::mobilemessage;
 
 namespace {
 
 // TODO: Bug 767082 - WebSMS: sSmsChild leaks at shutdown
--- a/dom/mobilemessage/src/ipc/SmsParent.cpp
+++ b/dom/mobilemessage/src/ipc/SmsParent.cpp
@@ -8,17 +8,16 @@
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "Constants.h"
 #include "nsIDOMSmsMessage.h"
 #include "mozilla/unused.h"
 #include "SmsMessage.h"
 #include "nsIMobileMessageDatabaseService.h"
 #include "SmsFilter.h"
-#include "SmsRequest.h"
 #include "SmsSegmentInfo.h"
 #include "MobileMessageThread.h"
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
 NS_IMPL_ISUPPORTS1(SmsParent, nsIObserver)
@@ -190,23 +189,29 @@ SmsParent::RecvPSmsRequestConstructor(PS
   }
 
   return false;
 }
 
 PSmsRequestParent*
 SmsParent::AllocPSmsRequest(const IPCSmsRequest& aRequest)
 {
-  return new SmsRequestParent();
+  SmsRequestParent* actor = new SmsRequestParent();
+  // Add an extra ref for IPDL. Will be released in
+  // SmsParent::DeallocPSmsRequest().
+  actor->AddRef();
+
+  return actor;
 }
 
 bool
 SmsParent::DeallocPSmsRequest(PSmsRequestParent* aActor)
 {
-  delete aActor;
+  // SmsRequestParent is refcounted, must not be freed manually.
+  static_cast<SmsRequestParent*>(aActor)->Release();
   return true;
 }
 
 bool
 SmsParent::RecvPMobileMessageCursorConstructor(PMobileMessageCursorParent* aActor,
                                                const IPCMobileMessageCursor& aRequest)
 {
   MobileMessageCursorParent* actor =
@@ -243,103 +248,159 @@ SmsParent::DeallocPMobileMessageCursor(P
   static_cast<MobileMessageCursorParent*>(aActor)->Release();
   return true;
 }
 
 /*******************************************************************************
  * SmsRequestParent
  ******************************************************************************/
 
-SmsRequestParent::SmsRequestParent()
-{
-  MOZ_COUNT_CTOR(SmsRequestParent);
-}
-
-SmsRequestParent::~SmsRequestParent()
-{
-  MOZ_COUNT_DTOR(SmsRequestParent);
-}
+NS_IMPL_ISUPPORTS1(SmsRequestParent, nsIMobileMessageCallback)
 
 void
 SmsRequestParent::ActorDestroy(ActorDestroyReason aWhy)
 {
-  if (mSmsRequest) {
-    mSmsRequest->SetActorDied();
-    mSmsRequest = nullptr;
-  }
-}
-
-void
-SmsRequestParent::SendReply(const MessageReply& aReply) {
-  nsRefPtr<SmsRequest> request;
-  mSmsRequest.swap(request);
-  if (!Send__delete__(this, aReply)) {
-    NS_WARNING("Failed to send response to child process!");
-  }
+  mActorDestroyed = true;
 }
 
 bool
 SmsRequestParent::DoRequest(const SendMessageRequest& aRequest)
 {
-  nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(smsService, true);
+  nsresult rv = NS_ERROR_FAILURE;
 
-  mSmsRequest = SmsRequest::Create(this);
-  nsCOMPtr<nsIMobileMessageCallback> forwarder = new SmsRequestForwarder(mSmsRequest);
-  nsresult rv = smsService->Send(aRequest.number(), aRequest.message(), forwarder);
-  NS_ENSURE_SUCCESS(rv, false);
+  nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
+  if (smsService) {
+    rv = smsService->Send(aRequest.number(), aRequest.message(), this);
+  }
+
+  if (NS_FAILED(rv)) {
+    return NS_SUCCEEDED(NotifySendMessageFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
+  }
 
   return true;
 }
 
 bool
 SmsRequestParent::DoRequest(const GetMessageRequest& aRequest)
 {
-  nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
-    do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(mobileMessageDBService, true);
+  nsresult rv = NS_ERROR_FAILURE;
 
-  mSmsRequest = SmsRequest::Create(this);
-  nsCOMPtr<nsIMobileMessageCallback> forwarder = new SmsRequestForwarder(mSmsRequest);
-  nsresult rv = mobileMessageDBService->GetMessageMoz(aRequest.messageId(), forwarder);
-  NS_ENSURE_SUCCESS(rv, false);
+  nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
+    do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
+  if (dbService) {
+    rv = dbService->GetMessageMoz(aRequest.messageId(), this);
+  }
+
+  if (NS_FAILED(rv)) {
+    return NS_SUCCEEDED(NotifyGetMessageFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
+  }
 
   return true;
 }
 
 bool
 SmsRequestParent::DoRequest(const DeleteMessageRequest& aRequest)
 {
-  nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
-    do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(mobileMessageDBService, true);
+  nsresult rv = NS_ERROR_FAILURE;
 
-  mSmsRequest = SmsRequest::Create(this);
-  nsCOMPtr<nsIMobileMessageCallback> forwarder = new SmsRequestForwarder(mSmsRequest);
-  nsresult rv = mobileMessageDBService->DeleteMessage(aRequest.messageId(), forwarder);
-  NS_ENSURE_SUCCESS(rv, false);
+  nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
+    do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
+  if (dbService) {
+    rv = dbService->DeleteMessage(aRequest.messageId(), this);
+  }
+
+  if (NS_FAILED(rv)) {
+    return NS_SUCCEEDED(NotifyDeleteMessageFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
+  }
 
   return true;
 }
 
 bool
 SmsRequestParent::DoRequest(const MarkMessageReadRequest& aRequest)
 {
-  nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
-    do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
+  nsresult rv = NS_ERROR_FAILURE;
 
-  NS_ENSURE_TRUE(mobileMessageDBService, true);
-  mSmsRequest = SmsRequest::Create(this);
-  nsCOMPtr<nsIMobileMessageCallback> forwarder = new SmsRequestForwarder(mSmsRequest);
-  nsresult rv = mobileMessageDBService->MarkMessageRead(aRequest.messageId(), aRequest.value(), forwarder);
-  NS_ENSURE_SUCCESS(rv, false);
+  nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
+    do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
+  if (dbService) {
+    rv = dbService->MarkMessageRead(aRequest.messageId(), aRequest.value(),
+                                    this);
+  }
+
+  if (NS_FAILED(rv)) {
+    return NS_SUCCEEDED(NotifyMarkMessageReadFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
+  }
 
   return true;
 }
 
+nsresult
+SmsRequestParent::SendReply(const MessageReply& aReply)
+{
+  // The child process could die before this asynchronous notification, in which
+  // case ActorDestroy() was called and mActorDestroyed is set to true. Return
+  // an error here to avoid sending a message to the dead process.
+  NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
+
+  return Send__delete__(this, aReply) ? NS_OK : NS_ERROR_FAILURE;
+}
+
+// nsIMobileMessageCallback
+
+NS_IMETHODIMP
+SmsRequestParent::NotifyMessageSent(nsISupports *aMessage)
+{
+  SmsMessage* message = static_cast<SmsMessage*>(aMessage);
+  return SendReply(ReplyMessageSend(message->GetData()));
+}
+
+NS_IMETHODIMP
+SmsRequestParent::NotifySendMessageFailed(int32_t aError)
+{
+  return SendReply(ReplyMessageSendFail(aError));
+}
+
+NS_IMETHODIMP
+SmsRequestParent::NotifyMessageGot(nsISupports *aMessage)
+{
+  SmsMessage* message = static_cast<SmsMessage*>(aMessage);
+  return SendReply(ReplyGetMessage(message->GetData()));
+}
+
+NS_IMETHODIMP
+SmsRequestParent::NotifyGetMessageFailed(int32_t aError)
+{
+  return SendReply(ReplyGetMessageFail(aError));
+}
+
+NS_IMETHODIMP
+SmsRequestParent::NotifyMessageDeleted(bool aDeleted)
+{
+  return SendReply(ReplyMessageDelete(aDeleted));
+}
+
+NS_IMETHODIMP
+SmsRequestParent::NotifyDeleteMessageFailed(int32_t aError)
+{
+  return SendReply(ReplyMessageDeleteFail(aError));
+}
+
+NS_IMETHODIMP
+SmsRequestParent::NotifyMessageMarkedRead(bool aRead)
+{
+  return SendReply(ReplyMarkeMessageRead(aRead));
+}
+
+NS_IMETHODIMP
+SmsRequestParent::NotifyMarkMessageReadFailed(int32_t aError)
+{
+  return SendReply(ReplyMarkeMessageReadFail(aError));
+}
+
 /*******************************************************************************
  * MobileMessageCursorParent
  ******************************************************************************/
 
 NS_IMPL_ISUPPORTS1(MobileMessageCursorParent, nsIMobileMessageCursorCallback)
 
 void
 MobileMessageCursorParent::ActorDestroy(ActorDestroyReason aWhy)
--- a/dom/mobilemessage/src/ipc/SmsParent.h
+++ b/dom/mobilemessage/src/ipc/SmsParent.h
@@ -5,24 +5,24 @@
 
 #ifndef mozilla_dom_mobilemessage_SmsParent_h
 #define mozilla_dom_mobilemessage_SmsParent_h
 
 #include "mozilla/dom/mobilemessage/PSmsParent.h"
 #include "mozilla/dom/mobilemessage/PSmsRequestParent.h"
 #include "mozilla/dom/mobilemessage/PMobileMessageCursorParent.h"
 #include "nsIDOMDOMCursor.h"
+#include "nsIMobileMessageCallback.h"
 #include "nsIMobileMessageCursorCallback.h"
 #include "nsIObserver.h"
 
 namespace mozilla {
 namespace dom {
 
 class ContentParent;
-class SmsRequest;
 
 namespace mobilemessage {
 
 class SmsParent : public PSmsParent
                 , public nsIObserver
 {
   friend class mozilla::dom::ContentParent;
 
@@ -63,43 +63,55 @@ protected:
   virtual PMobileMessageCursorParent*
   AllocPMobileMessageCursor(const IPCMobileMessageCursor& aCursor) MOZ_OVERRIDE;
 
   virtual bool
   DeallocPMobileMessageCursor(PMobileMessageCursorParent* aActor) MOZ_OVERRIDE;
 };
 
 class SmsRequestParent : public PSmsRequestParent
+                       , public nsIMobileMessageCallback
 {
   friend class SmsParent;
 
-  nsRefPtr<SmsRequest> mSmsRequest;
+  bool mActorDestroyed;
 
 public:
-  void
-  SendReply(const MessageReply& aReply);
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIMOBILEMESSAGECALLBACK
 
 protected:
-  SmsRequestParent();
-  virtual ~SmsRequestParent();
+  SmsRequestParent()
+    : mActorDestroyed(false)
+  {
+    MOZ_COUNT_CTOR(SmsRequestParent);
+  }
+
+  virtual ~SmsRequestParent()
+  {
+    MOZ_COUNT_DTOR(SmsRequestParent);
+  }
 
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
 
   bool
   DoRequest(const SendMessageRequest& aRequest);
 
   bool
   DoRequest(const GetMessageRequest& aRequest);
 
   bool
   DoRequest(const DeleteMessageRequest& aRequest);
 
   bool
   DoRequest(const MarkMessageReadRequest& aRequest);
+
+  nsresult
+  SendReply(const MessageReply& aReply);
 };
 
 class MobileMessageCursorParent : public PMobileMessageCursorParent
                                 , public nsIMobileMessageCursorCallback
 {
   friend class SmsParent;
 
   nsCOMPtr<nsICursorContinueCallback> mContinueCallback;
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -2777,20 +2777,18 @@ let RIL = {
    * Send an SMS.
    *
    * The `options` parameter object should contain the following attributes:
    *
    * @param number
    *        String containing the recipient number.
    * @param body
    *        String containing the message text.
-   * @param requestId
-   *        String identifying the sms request used by the SmsRequestManager.
-   * @param processId
-   *        String containing the processId for the SmsRequestManager.
+   * @param envelopeId
+   *        Numeric value identifying the sms request.
    */
   sendSMS: function sendSMS(options) {
     options.langIndex = options.langIndex || PDU_NL_IDENTIFIER_DEFAULT;
     options.langShiftIndex = options.langShiftIndex || PDU_NL_IDENTIFIER_DEFAULT;
 
     if (!options.retryCount) {
       options.retryCount = 0;
     }