Bug 1044721 - Part 1: Add setSmscAddress API in MozMobileMessageManager Web IDL interface, and corresponding implementation in MobileMessageManager class. r=hsinyi

This commit is contained in:
Samael Wang 2015-04-29 10:41:05 +08:00
parent bbdb05b6ba
commit 64cb92d2d2
3 changed files with 129 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include "mozilla/dom/MozMmsEvent.h" #include "mozilla/dom/MozMmsEvent.h"
#include "mozilla/dom/MozMobileMessageManagerBinding.h" #include "mozilla/dom/MozMobileMessageManagerBinding.h"
#include "mozilla/dom/MozSmsEvent.h" #include "mozilla/dom/MozSmsEvent.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ToJSValue.h" #include "mozilla/dom/ToJSValue.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
@ -697,6 +698,72 @@ MobileMessageManager::GetSmscAddress(const Optional<uint32_t>& aServiceId,
return request.forget(); return request.forget();
} }
already_AddRefed<Promise>
MobileMessageManager::SetSmscAddress(const SmscAddress& aSmscAddress,
const Optional<uint32_t>& aServiceId,
ErrorResult& aRv)
{
nsCOMPtr<nsISmsService> 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<nsIGlobalObject> global = do_QueryInterface(GetOwner());
if (!global) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsRefPtr<Promise> 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<nsIMobileMessageCallback> msgCallback =
new MobileMessageCallback(promise);
rv = smsService->SetSmscAddress(serviceId, address,
static_cast<uint32_t>(ton), static_cast<uint32_t>(npi), msgCallback);
if (NS_FAILED(rv)) {
promise->MaybeReject(rv);
return promise.forget();
}
return promise.forget();
}
} // namespace dom } // namespace dom
} // namespace mozilla } // namespace mozilla

View File

@ -13,6 +13,7 @@
class nsISmsService; class nsISmsService;
class nsIDOMMozSmsMessage; class nsIDOMMozSmsMessage;
class nsIDOMMozMmsMessage; class nsIDOMMozMmsMessage;
class Promise;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -24,6 +25,7 @@ struct MmsSendParameters;
struct MobileMessageFilter; struct MobileMessageFilter;
class OwningLongOrMozSmsMessageOrMozMmsMessage; class OwningLongOrMozSmsMessageOrMozMmsMessage;
struct SmsSendParameters; struct SmsSendParameters;
struct SmscAddress;
class MobileMessageManager final : public DOMEventTargetHelper class MobileMessageManager final : public DOMEventTargetHelper
, public nsIObserver , public nsIObserver
@ -115,6 +117,11 @@ public:
GetSmscAddress(const Optional<uint32_t>& aServiceId, GetSmscAddress(const Optional<uint32_t>& aServiceId,
ErrorResult& aRv); ErrorResult& aRv);
already_AddRefed<Promise>
SetSmscAddress(const SmscAddress& aSmscAddress,
const Optional<uint32_t>& aServiceId,
ErrorResult& aRv);
IMPL_EVENT_HANDLER(received) IMPL_EVENT_HANDLER(received)
IMPL_EVENT_HANDLER(retrieving) IMPL_EVENT_HANDLER(retrieving)
IMPL_EVENT_HANDLER(sending) IMPL_EVENT_HANDLER(sending)

View File

@ -75,6 +75,45 @@ dictionary MobileMessageFilter
[EnforceRange] unsigned long long? threadId = 0; [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 <tosca> 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", [Pref="dom.sms.enabled",
CheckPermissions="sms", CheckPermissions="sms",
AvailableIn="CertifiedApps"] AvailableIn="CertifiedApps"]
@ -157,6 +196,22 @@ interface MozMobileMessageManager : EventTarget
[Throws] [Throws]
DOMRequest getSmscAddress(optional unsigned long serviceId); 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<void> setSmscAddress(optional SmscAddress smscAddress,
optional unsigned long serviceId);
attribute EventHandler onreceived; attribute EventHandler onreceived;
attribute EventHandler onretrieving; attribute EventHandler onretrieving;
attribute EventHandler onsending; attribute EventHandler onsending;