Bug 824717 - Part 5: Fire DOMMobileMessageError when NotifySendMessageFailed(). r=vyang
--- 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