From 64cb92d2d2f758f7dbd3d9c9abfd6a9dc5962833 Mon Sep 17 00:00:00 2001 From: Samael Wang Date: Wed, 29 Apr 2015 10:41:05 +0800 Subject: [PATCH] Bug 1044721 - Part 1: Add setSmscAddress API in MozMobileMessageManager Web IDL interface, and corresponding implementation in MobileMessageManager class. r=hsinyi --- dom/mobilemessage/MobileMessageManager.cpp | 67 ++++++++++++++++++++++ dom/mobilemessage/MobileMessageManager.h | 7 +++ dom/webidl/MozMobileMessageManager.webidl | 55 ++++++++++++++++++ 3 files changed, 129 insertions(+) diff --git a/dom/mobilemessage/MobileMessageManager.cpp b/dom/mobilemessage/MobileMessageManager.cpp index 8000b5a0f45..6e7b871d5b9 100644 --- a/dom/mobilemessage/MobileMessageManager.cpp +++ b/dom/mobilemessage/MobileMessageManager.cpp @@ -15,6 +15,7 @@ #include "mozilla/dom/MozMmsEvent.h" #include "mozilla/dom/MozMobileMessageManagerBinding.h" #include "mozilla/dom/MozSmsEvent.h" +#include "mozilla/dom/Promise.h" #include "mozilla/dom/ToJSValue.h" #include "mozilla/Preferences.h" #include "mozilla/Services.h" @@ -697,6 +698,72 @@ MobileMessageManager::GetSmscAddress(const Optional& aServiceId, return request.forget(); } +already_AddRefed +MobileMessageManager::SetSmscAddress(const SmscAddress& aSmscAddress, + const Optional& aServiceId, + ErrorResult& aRv) +{ + nsCOMPtr smsService = do_GetService(SMS_SERVICE_CONTRACTID); + if (!smsService) { + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } + + // Use the default one unless |serviceId| is available. + uint32_t serviceId; + nsresult rv; + if (aServiceId.WasPassed()) { + serviceId = aServiceId.Value(); + } else { + rv = smsService->GetSmsDefaultServiceId(&serviceId); + if (NS_FAILED(rv)) { + aRv.Throw(rv); + return nullptr; + } + } + + nsCOMPtr global = do_QueryInterface(GetOwner()); + if (!global) { + aRv.Throw(NS_ERROR_UNEXPECTED); + return nullptr; + } + + nsRefPtr promise = Promise::Create(global, aRv); + if (aRv.Failed()) { + return nullptr; + } + + if (!aSmscAddress.mAddress.WasPassed()) { + NS_WARNING("SmscAddress.address is a mandatory field and can not be omitted."); + promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR); + return promise.forget(); + } + + nsString address = aSmscAddress.mAddress.Value(); + TypeOfNumber ton = aSmscAddress.mTypeOfAddress.mTypeOfNumber; + NumberPlanIdentification npi = + aSmscAddress.mTypeOfAddress.mNumberPlanIdentification; + + // If the address begins with +, set TON to international no matter what has + // passed in. + if (!address.IsEmpty() && address[0] == '+') { + ton = TypeOfNumber::International; + } + + nsCOMPtr msgCallback = + new MobileMessageCallback(promise); + + rv = smsService->SetSmscAddress(serviceId, address, + static_cast(ton), static_cast(npi), msgCallback); + if (NS_FAILED(rv)) { + promise->MaybeReject(rv); + return promise.forget(); + } + + return promise.forget(); +} + + } // namespace dom } // namespace mozilla diff --git a/dom/mobilemessage/MobileMessageManager.h b/dom/mobilemessage/MobileMessageManager.h index 5e3da5d55b0..e4565b76a20 100644 --- a/dom/mobilemessage/MobileMessageManager.h +++ b/dom/mobilemessage/MobileMessageManager.h @@ -13,6 +13,7 @@ class nsISmsService; class nsIDOMMozSmsMessage; class nsIDOMMozMmsMessage; +class Promise; namespace mozilla { namespace dom { @@ -24,6 +25,7 @@ struct MmsSendParameters; struct MobileMessageFilter; class OwningLongOrMozSmsMessageOrMozMmsMessage; struct SmsSendParameters; +struct SmscAddress; class MobileMessageManager final : public DOMEventTargetHelper , public nsIObserver @@ -115,6 +117,11 @@ public: GetSmscAddress(const Optional& aServiceId, ErrorResult& aRv); + already_AddRefed + SetSmscAddress(const SmscAddress& aSmscAddress, + const Optional& aServiceId, + ErrorResult& aRv); + IMPL_EVENT_HANDLER(received) IMPL_EVENT_HANDLER(retrieving) IMPL_EVENT_HANDLER(sending) diff --git a/dom/webidl/MozMobileMessageManager.webidl b/dom/webidl/MozMobileMessageManager.webidl index 32fe5323355..7329a9f639b 100644 --- a/dom/webidl/MozMobileMessageManager.webidl +++ b/dom/webidl/MozMobileMessageManager.webidl @@ -75,6 +75,45 @@ dictionary MobileMessageFilter [EnforceRange] unsigned long long? threadId = 0; }; +/** + * TON defined in |Table 10.5.118: Called party BCD number| of 3GPP TS 24.008. + * It's used in SM-RL originator / destination address element as defined in + * |8.2.5.2 Destination address element| of 3GPP TS 24.011. + */ +enum TypeOfNumber { "unknown", "international", "national", "network-specific", + "dedicated-access-short-code" }; + +/** + * NPI defined in |Table 10.5.118: Called party BCD number| of 3GPP TS 24.008. + * It's used in SM-RL originator / destination address element as defined in + * |8.2.5.2 Destination address element| of 3GPP TS 24.011. + */ +enum NumberPlanIdentification { "unknown", "isdn", "data", "telex", "national", + "private" }; + +/** + * Type of address used in SmscAddress. + * + * As described in |3.1 Parameters Definitions| of 3GPP TS 27.005, the default + * value of should be 129 (typeOfNumber=unknown, + * numberPlanIdentification=isdn) if the number does not begin with '+'. + * + * |setSmscAddress| updates typeOfNumber to international automatically if the + * given number begins with '+'. + */ +dictionary TypeOfAddress { + TypeOfNumber typeOfNumber = "unknown"; + NumberPlanIdentification numberPlanIdentification = "isdn"; +}; + +/** + * SMSC address. + */ +dictionary SmscAddress { + DOMString address; + TypeOfAddress typeOfAddress; +}; + [Pref="dom.sms.enabled", CheckPermissions="sms", AvailableIn="CertifiedApps"] @@ -157,6 +196,22 @@ interface MozMobileMessageManager : EventTarget [Throws] DOMRequest getSmscAddress(optional unsigned long serviceId); + /** + * Set the SMSC address. + * + * @param smscAddress + * SMSC address to use. + * Reject if smscAddress.address does not present. + * @param serviceId (optional) + * The ID of the RIL service which needs to be specified under + * the multi-sim scenario. + * @return a Promise + * Resolve if success. Otherwise, reject with error cause. + */ + [NewObject] + Promise setSmscAddress(optional SmscAddress smscAddress, + optional unsigned long serviceId); + attribute EventHandler onreceived; attribute EventHandler onretrieving; attribute EventHandler onsending;