Bug 824717 - Part 5: Fire DOMMobileMessageError when NotifySendMessageFailed(). r=vyang
☠☠ backed out by f99dce77b837 ☠ ☠
authorBevis Tseng <btseng@mozilla.com>
Mon, 28 Apr 2014 13:20:02 +0800 (2014-04-28)
changeset 184051 fd9e72e50518272259317cbdbdaccb9e11974d82
parent 184050 d66a089882723e4bf9884dcef5283e28224f3490
child 184052 4c4b8b15da373959940e631b2b41c34307d35e7c
push id7197
push userryanvm@gmail.com
push dateWed, 21 May 2014 12:17:54 +0000 (2014-05-21)
treeherderb2g-inbound@04193066a20c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvyang
bugs824717
milestone32.0a1
Bug 824717 - Part 5: Fire DOMMobileMessageError when NotifySendMessageFailed(). r=vyang
dom/mobilemessage/src/MobileMessageCallback.cpp
dom/mobilemessage/src/MobileMessageCallback.h
--- a/dom/mobilemessage/src/MobileMessageCallback.cpp
+++ b/dom/mobilemessage/src/MobileMessageCallback.cpp
@@ -11,16 +11,17 @@
 #include "nsIDOMSmsSegmentInfo.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsPIDOMWindow.h"
 #include "MmsMessage.h"
 #include "jsapi.h"
 #include "xpcpublic.h"
 #include "nsServiceManagerUtils.h"
 #include "nsTArrayHelpers.h"
+#include "DOMMobileMessageError.h"
 
 namespace mozilla {
 namespace dom {
 namespace mobilemessage {
 
 NS_IMPL_ADDREF(MobileMessageCallback)
 NS_IMPL_RELEASE(MobileMessageCallback)
 
@@ -73,17 +74,17 @@ MobileMessageCallback::NotifySuccess(nsI
   JS::Rooted<JS::Value> wrappedMessage(cx);
   rv = nsContentUtils::WrapNative(cx, aMessage, &wrappedMessage);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NotifySuccess(wrappedMessage, aAsync);
 }
 
 nsresult
-MobileMessageCallback::NotifyError(int32_t aError, bool aAsync)
+MobileMessageCallback::NotifyError(int32_t aError, nsISupports *aData, bool aAsync)
 {
   nsAutoString errorStr;
   switch (aError) {
     case nsIMobileMessageCallback::NO_SIGNAL_ERROR:
       errorStr = NS_LITERAL_STRING("NoSignalError");
       break;
     case nsIMobileMessageCallback::NOT_FOUND_ERROR:
       errorStr = NS_LITERAL_STRING("NotFoundError");
@@ -114,38 +115,59 @@ MobileMessageCallback::NotifyError(int32
       break;
     case nsIMobileMessageCallback::SIM_NOT_MATCHED_ERROR:
       errorStr = NS_LITERAL_STRING("SimNotMatchedError");
       break;
     default: // SUCCESS_NO_ERROR is handled above.
       MOZ_CRASH("Should never get here!");
   }
 
+  if (aData && aAsync) {
+    MOZ_CRASH("No Support to FireDetailedErrorAsync() in nsIDOMRequestService!");
+  }
+
   if (aAsync) {
     nsCOMPtr<nsIDOMRequestService> rs =
       do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
     NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
 
     return rs->FireErrorAsync(mDOMRequest, errorStr);
   }
 
+  if (aData) {
+    nsCOMPtr<nsISupports> domMobileMessageError;
+    nsCOMPtr<nsIDOMMozSmsMessage> smsMsg = do_QueryInterface(aData);
+    if (smsMsg) {
+      domMobileMessageError =
+        new DOMMobileMessageError(mDOMRequest->GetOwner(), errorStr, smsMsg);
+    }
+    else {
+      nsCOMPtr<nsIDOMMozMmsMessage> mmsMsg = do_QueryInterface(aData);
+      domMobileMessageError =
+        new DOMMobileMessageError(mDOMRequest->GetOwner(), errorStr, mmsMsg);
+    }
+    NS_ASSERTION(domMobileMessageError, "Invalid DOMMobileMessageError!");
+    mDOMRequest->FireDetailedError(domMobileMessageError);
+    return NS_OK;
+  }
+
   mDOMRequest->FireError(errorStr);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 MobileMessageCallback::NotifyMessageSent(nsISupports *aMessage)
 {
   return NotifySuccess(aMessage);
 }
 
 NS_IMETHODIMP
 MobileMessageCallback::NotifySendMessageFailed(int32_t aError, nsISupports *aMessage)
 {
-  return NotifyError(aError);
+  return NotifyError(aError, aMessage);
 }
 
 NS_IMETHODIMP
 MobileMessageCallback::NotifyMessageGot(nsISupports *aMessage)
 {
   return NotifySuccess(aMessage);
 }
 
@@ -206,17 +228,17 @@ NS_IMETHODIMP
 MobileMessageCallback::NotifySegmentInfoForTextGot(nsIDOMMozSmsSegmentInfo *aInfo)
 {
   return NotifySuccess(aInfo, true);
 }
 
 NS_IMETHODIMP
 MobileMessageCallback::NotifyGetSegmentInfoForTextFailed(int32_t aError)
 {
-  return NotifyError(aError, true);
+  return NotifyError(aError, nullptr, true);
 }
 
 NS_IMETHODIMP
 MobileMessageCallback::NotifyGetSmscAddress(const nsAString& aSmscAddress)
 {
   AutoJSContext cx;
   JSString* smsc = JS_NewUCStringCopyN(cx,
                                        static_cast<const jschar *>(aSmscAddress.BeginReading()),
--- a/dom/mobilemessage/src/MobileMessageCallback.h
+++ b/dom/mobilemessage/src/MobileMessageCallback.h
@@ -26,16 +26,16 @@ public:
 
 private:
   ~MobileMessageCallback();
 
   nsRefPtr<DOMRequest> mDOMRequest;
 
   nsresult NotifySuccess(JS::Handle<JS::Value> aResult, bool aAsync = false);
   nsresult NotifySuccess(nsISupports *aMessage, bool aAsync = false);
-  nsresult NotifyError(int32_t aError, bool aAsync = false);
+  nsresult NotifyError(int32_t aError, nsISupports *aData = nullptr, bool aAsync = false);
 };
 
 } // namespace mobilemessage
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_mobilemessage_MobileMessageCallback_h