diff --git a/dom/mobilemessage/src/MobileMessageCallback.cpp b/dom/mobilemessage/src/MobileMessageCallback.cpp index 117929df953..cbadff7be0d 100644 --- a/dom/mobilemessage/src/MobileMessageCallback.cpp +++ b/dom/mobilemessage/src/MobileMessageCallback.cpp @@ -16,11 +16,57 @@ #include "xpcpublic.h" #include "nsServiceManagerUtils.h" #include "nsTArrayHelpers.h" +#include "DOMMobileMessageError.h" namespace mozilla { namespace dom { namespace mobilemessage { +static nsAutoString +ConvertErrorCodeToErrorString(int32_t aError) +{ + 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"); + break; + case nsIMobileMessageCallback::UNKNOWN_ERROR: + errorStr = NS_LITERAL_STRING("UnknownError"); + break; + case nsIMobileMessageCallback::INTERNAL_ERROR: + errorStr = NS_LITERAL_STRING("InternalError"); + break; + case nsIMobileMessageCallback::NO_SIM_CARD_ERROR: + errorStr = NS_LITERAL_STRING("NoSimCardError"); + break; + case nsIMobileMessageCallback::RADIO_DISABLED_ERROR: + errorStr = NS_LITERAL_STRING("RadioDisabledError"); + break; + case nsIMobileMessageCallback::INVALID_ADDRESS_ERROR: + errorStr = NS_LITERAL_STRING("InvalidAddressError"); + break; + case nsIMobileMessageCallback::FDN_CHECK_ERROR: + errorStr = NS_LITERAL_STRING("FdnCheckError"); + break; + case nsIMobileMessageCallback::NON_ACTIVE_SIM_CARD_ERROR: + errorStr = NS_LITERAL_STRING("NonActiveSimCardError"); + break; + case nsIMobileMessageCallback::STORAGE_FULL_ERROR: + errorStr = NS_LITERAL_STRING("StorageFullError"); + 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!"); + } + + return errorStr; +} + NS_IMPL_ADDREF(MobileMessageCallback) NS_IMPL_RELEASE(MobileMessageCallback) @@ -78,56 +124,26 @@ MobileMessageCallback::NotifySuccess(nsISupports *aMessage, bool aAsync) } nsresult -MobileMessageCallback::NotifyError(int32_t aError, bool aAsync) +MobileMessageCallback::NotifyError(int32_t aError, DOMError *aDetailedError, 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"); - break; - case nsIMobileMessageCallback::UNKNOWN_ERROR: - errorStr = NS_LITERAL_STRING("UnknownError"); - break; - case nsIMobileMessageCallback::INTERNAL_ERROR: - errorStr = NS_LITERAL_STRING("InternalError"); - break; - case nsIMobileMessageCallback::NO_SIM_CARD_ERROR: - errorStr = NS_LITERAL_STRING("NoSimCardError"); - break; - case nsIMobileMessageCallback::RADIO_DISABLED_ERROR: - errorStr = NS_LITERAL_STRING("RadioDisabledError"); - break; - case nsIMobileMessageCallback::INVALID_ADDRESS_ERROR: - errorStr = NS_LITERAL_STRING("InvalidAddressError"); - break; - case nsIMobileMessageCallback::FDN_CHECK_ERROR: - errorStr = NS_LITERAL_STRING("FdnCheckError"); - break; - case nsIMobileMessageCallback::NON_ACTIVE_SIM_CARD_ERROR: - errorStr = NS_LITERAL_STRING("NonActiveSimCardError"); - break; - case nsIMobileMessageCallback::STORAGE_FULL_ERROR: - errorStr = NS_LITERAL_STRING("StorageFullError"); - 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 (aAsync) { + NS_ASSERTION(!aDetailedError, + "No Support to FireDetailedErrorAsync() in nsIDOMRequestService!"); + nsCOMPtr rs = do_GetService(DOMREQUEST_SERVICE_CONTRACTID); NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE); - return rs->FireErrorAsync(mDOMRequest, errorStr); + return rs->FireErrorAsync(mDOMRequest, + ConvertErrorCodeToErrorString(aError)); + } + + if (aDetailedError) { + mDOMRequest->FireDetailedError(aDetailedError); + } else { + mDOMRequest->FireError(ConvertErrorCodeToErrorString(aError)); } - mDOMRequest->FireError(errorStr); return NS_OK; } @@ -140,7 +156,23 @@ MobileMessageCallback::NotifyMessageSent(nsISupports *aMessage) NS_IMETHODIMP MobileMessageCallback::NotifySendMessageFailed(int32_t aError, nsISupports *aMessage) { - return NotifyError(aError); + nsRefPtr domMobileMessageError; + if (aMessage) { + nsAutoString errorStr = ConvertErrorCodeToErrorString(aError); + nsCOMPtr smsMsg = do_QueryInterface(aMessage); + if (smsMsg) { + domMobileMessageError = + new DOMMobileMessageError(mDOMRequest->GetOwner(), errorStr, smsMsg); + } + else { + nsCOMPtr mmsMsg = do_QueryInterface(aMessage); + domMobileMessageError = + new DOMMobileMessageError(mDOMRequest->GetOwner(), errorStr, mmsMsg); + } + NS_ASSERTION(domMobileMessageError, "Invalid DOMMobileMessageError!"); + } + + return NotifyError(aError, domMobileMessageError); } NS_IMETHODIMP @@ -211,7 +243,7 @@ MobileMessageCallback::NotifySegmentInfoForTextGot(nsIDOMMozSmsSegmentInfo *aInf NS_IMETHODIMP MobileMessageCallback::NotifyGetSegmentInfoForTextFailed(int32_t aError) { - return NotifyError(aError, true); + return NotifyError(aError, nullptr, true); } NS_IMETHODIMP diff --git a/dom/mobilemessage/src/MobileMessageCallback.h b/dom/mobilemessage/src/MobileMessageCallback.h index b793df70edf..d599a1be65c 100644 --- a/dom/mobilemessage/src/MobileMessageCallback.h +++ b/dom/mobilemessage/src/MobileMessageCallback.h @@ -31,7 +31,7 @@ private: nsresult NotifySuccess(JS::Handle aResult, bool aAsync = false); nsresult NotifySuccess(nsISupports *aMessage, bool aAsync = false); - nsresult NotifyError(int32_t aError, bool aAsync = false); + nsresult NotifyError(int32_t aError, DOMError *aDetailedError = nullptr, bool aAsync = false); }; } // namespace mobilemessage