Bug 749086 - 2/3: DOM & IPC changes. r=bent
authorVicamo Yang <vyang@mozilla.com>
Tue, 09 Apr 2013 10:22:19 +0800
changeset 139048 f1584e7c0992fe0fd95f997f0d7dee55b31bf0c5
parent 139047 b3c8b7cc36ce34fbf7a3cbf824b9c219338ad792
child 139049 bc8c31010d962c14842eb3bba55992a5a5a21bd6
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs749086
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 749086 - 2/3: DOM & IPC changes. r=bent
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/mobilemessage/interfaces/moz.build
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
@@ -327,17 +327,16 @@ using mozilla::dom::workers::ResolveWork
 
 #include "BatteryManager.h"
 #include "nsIDOMPowerManager.h"
 #include "nsIDOMWakeLock.h"
 #include "nsIDOMSmsManager.h"
 #include "nsIDOMMobileMessageManager.h"
 #include "nsIDOMMozSmsMessage.h"
 #include "nsIDOMMozMmsMessage.h"
-#include "nsIDOMSmsRequest.h"
 #include "nsIDOMSmsFilter.h"
 #include "nsIDOMSmsSegmentInfo.h"
 #include "nsIDOMMozMobileMessageThread.h"
 #include "nsIDOMConnection.h"
 #include "mozilla/dom/network/Utils.h"
 
 #ifdef MOZ_B2G_RIL
 #include "Telephony.h"
@@ -907,19 +906,16 @@ static nsDOMClassInfoData sClassInfoData
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(MozSmsMessage, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(MozMmsMessage, 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)
@@ -2353,21 +2349,16 @@ nsDOMClassInfo::Init()
   DOM_CLASSINFO_MAP_BEGIN(MozSmsMessage, nsIDOMMozSmsMessage)
      DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsMessage)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(MozMmsMessage, nsIDOMMozMmsMessage)
      DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozMmsMessage)
   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
@@ -185,17 +185,16 @@ DOMCI_CLASS(GeoPositionError)
 
 DOMCI_CLASS(MozPowerManager)
 DOMCI_CLASS(MozWakeLock)
 
 DOMCI_CLASS(MozSmsManager)
 DOMCI_CLASS(MozMobileMessageManager)
 DOMCI_CLASS(MozSmsMessage)
 DOMCI_CLASS(MozMmsMessage)
-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/moz.build
+++ b/dom/mobilemessage/interfaces/moz.build
@@ -10,17 +10,16 @@ XPIDL_SOURCES += [
     'nsIDOMMozMmsMessage.idl',
     'nsIDOMMozMobileMessageThread.idl',
     'nsIDOMMozSmsEvent.idl',
     'nsIDOMMozSmsMessage.idl',
     'nsIDOMNavigatorMobileMessage.idl',
     'nsIDOMNavigatorSms.idl',
     'nsIDOMSmsFilter.idl',
     'nsIDOMSmsManager.idl',
-    'nsIDOMSmsRequest.idl',
     'nsIDOMSmsSegmentInfo.idl',
     'nsIMobileMessageCallback.idl',
     'nsIMobileMessageCursorCallback.idl',
     'nsIMobileMessageDatabaseService.idl',
     'nsIMobileMessageService.idl',
     'nsISmsService.idl',
 ]
 
--- a/dom/mobilemessage/src/Makefile.in
+++ b/dom/mobilemessage/src/Makefile.in
@@ -32,17 +32,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 \
@@ -61,17 +60,16 @@ CPPSRCS = \
   MobileMessageService.cpp \
   SmsIPCService.cpp \
   SmsServicesFactory.cpp \
   SmsParent.cpp \
   SmsMessage.cpp \
   MmsMessage.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 "nsIDOMMozSmsEvent.h"
 #include "nsIDOMMozMmsEvent.h"
 #include "nsIDOMMozSmsMessage.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"
@@ -115,31 +114,31 @@ MobileMessageManager::GetSegmentInfoForT
   return smsService->GetSegmentInfoForText(aText, aResult);
 }
 
 nsresult
 MobileMessageManager::Send(JSContext* aCx, JSObject* aGlobal, JSString* aNumber,
                            const nsAString& aMessage, JS::Value* 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,23 +8,23 @@
 #include "nsIDOMClassInfo.h"
 #include "nsISmsService.h"
 #include "nsIObserverService.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "Constants.h"
 #include "nsIDOMMozSmsEvent.h"
 #include "nsIDOMMozSmsMessage.h"
-#include "SmsRequest.h"
 #include "nsJSUtils.h"
 #include "nsContentUtils.h"
 #include "nsIMobileMessageDatabaseService.h"
 #include "nsIXPConnect.h"
 #include "nsIPermissionManager.h"
 #include "GeneratedEvents.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")
@@ -140,31 +140,31 @@ SmsManager::GetSegmentInfoForText(const 
   return smsService->GetSegmentInfoForText(aText, aResult);
 }
 
 nsresult
 SmsManager::Send(JSContext* aCx, JSObject* aGlobal, JSString* aNumber,
                  const nsAString& aMessage, JS::Value* 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;
 }
 
@@ -212,46 +212,53 @@ SmsManager::Send(const JS::Value& aNumbe
 
   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 JS::Value& aParam, nsIDOMMozSmsRequest** aRequest)
+SmsManager::Delete(const JS::Value& aParam, nsIDOMDOMRequest** aRequest)
 {
   if (aParam.isInt32()) {
     return Delete(aParam.toInt32(), aRequest);
   }
 
   if (!aParam.isObject()) {
     return NS_ERROR_INVALID_ARG;
   }
@@ -295,26 +302,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
@@ -37,17 +37,17 @@ private:
    * Internal Send() method used to send one message.
    */
   nsresult Send(JSContext* aCx, JSObject* aGlobal, JSString* aNumber,
                 const nsAString& aMessage, JS::Value* 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,391 +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 "nsIDOMMozSmsMessage.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_TRAVERSE_BEGIN_INHERITED(SmsRequest,
-                                                  nsDOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(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(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_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::Reset()
-{
-  NS_ASSERTION(mDone, "mDone should be true if we try to reset!");
-  NS_ASSERTION(mResult != JSVAL_VOID, "mResult should be set if we try to reset!");
-  NS_ASSERTION(!mError, "There should be no error if we try to reset!");
-
-  mResult = JSVAL_VOID;
-  mDone = false;
-}
-
-void
-SmsRequest::SetSuccess(nsIDOMMozSmsMessage* aMessage)
-{
-  SetSuccessInternal(aMessage);
-}
-
-void
-SmsRequest::SetSuccess(bool aResult)
-{
-  SetSuccess(aResult ? JSVAL_TRUE : JSVAL_FALSE);
-}
-
-void
-SmsRequest::SetSuccess(const JS::Value& 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;
-  }
-
-  AutoPushJSContext 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(JS::Value* 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)
-{
-  nsCOMPtr<nsIDOMEvent> event;
-  NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr);
-  nsresult rv = event->InitEvent(aEventName, false, false);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  event->SetTrusted(true);
-
-  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 JS::Value.
-   */
-  void SetSuccess(const JS::Value& 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);
-
-  JS::Value 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 "nsIDOMMozSmsMessage.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
@@ -1796,20 +1796,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;
     }