Bug 864484 - Part 7: Narrow down the DOMString values to predefined constants in .idl. r=vyang, r=smaug

--HG--
extra : rebase_source : 0038e0d9ba6a45f19ea7552202d9db9d165c6c88
extra : amend_source : 7ac906a928fe14fbcac03cd470da78f433a9f192
This commit is contained in:
Bevis Tseng 2014-09-23 18:27:03 +08:00
parent 18a889dbd5
commit 4b147318a8
13 changed files with 165 additions and 74 deletions

View File

@ -111,16 +111,16 @@ CellBroadcast::WrapObject(JSContext* aCx)
NS_IMETHODIMP
CellBroadcast::NotifyMessageReceived(uint32_t aServiceId,
const nsAString& aGsmGeographicalScope,
uint32_t aGsmGeographicalScope,
uint16_t aMessageCode,
uint16_t aMessageId,
const nsAString& aLanguage,
const nsAString& aBody,
const nsAString& aMessageClass,
uint32_t aMessageClass,
DOMTimeStamp aTimestamp,
uint32_t aCdmaServiceCategory,
bool aHasEtwsInfo,
const nsAString& aEtwsWarningType,
uint32_t aEtwsWarningType,
bool aEtwsEmergencyUserAlert,
bool aEtwsPopup) {
MozCellBroadcastEventInit init;

View File

@ -6,24 +6,42 @@
#include "CellBroadcastMessage.h"
#include "mozilla/dom/MozCellBroadcastMessageBinding.h"
#include "nsPIDOMWindow.h"
#define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum) \
{ \
_enum.SetNull(); \
\
uint32_t i = 0; \
for (const EnumEntry* entry = _enumType##Values::strings; \
entry->value; \
++entry, ++i) { \
if (_string.EqualsASCII(entry->value)) { \
_enum.SetValue(static_cast<_enumType>(i)); \
} \
} \
}
#include "nsICellBroadcastService.h"
namespace mozilla {
namespace dom {
/**
* Converter for XPIDL Constants to WebIDL Enumerations
*/
template<class T> struct EnumConverter {};
template<class T>
struct StaticEnumConverter
{
typedef T WebidlEnumType;
typedef uint32_t XpidlEnumType;
static MOZ_CONSTEXPR WebidlEnumType
x2w(XpidlEnumType aXpidlEnum) { return static_cast<WebidlEnumType>(aXpidlEnum); }
};
template<class T>
MOZ_CONSTEXPR T
ToWebidlEnum(uint32_t aXpidlEnum) { return EnumConverter<T>::x2w(aXpidlEnum); }
// Declare converters here:
template <>
struct EnumConverter<CellBroadcastGsmGeographicalScope> :
public StaticEnumConverter<CellBroadcastGsmGeographicalScope> {};
template <>
struct EnumConverter<CellBroadcastMessageClass> :
public StaticEnumConverter<CellBroadcastMessageClass> {};
template <>
struct EnumConverter<CellBroadcastEtwsWarningType> :
public StaticEnumConverter<CellBroadcastEtwsWarningType> {};
/**
* CellBroadcastMessage Implementation.
*/
@ -40,16 +58,16 @@ NS_INTERFACE_MAP_END
CellBroadcastMessage::CellBroadcastMessage(nsPIDOMWindow* aWindow,
uint32_t aServiceId,
const nsAString& aGsmGeographicalScope,
uint32_t aGsmGeographicalScope,
uint16_t aMessageCode,
uint16_t aMessageId,
const nsAString& aLanguage,
const nsAString& aBody,
const nsAString& aMessageClass,
uint32_t aMessageClass,
uint64_t aTimestamp,
uint32_t aCdmaServiceCategory,
bool aHasEtwsInfo,
const nsAString& aEtwsWarningType,
uint32_t aEtwsWarningType,
bool aEtwsEmergencyUserAlert,
bool aEtwsPopup)
: mWindow(aWindow)
@ -65,18 +83,18 @@ CellBroadcastMessage::CellBroadcastMessage(nsPIDOMWindow* aWindow,
aEtwsPopup)
: nullptr)
{
CONVERT_STRING_TO_NULLABLE_ENUM(aGsmGeographicalScope,
CellBroadcastGsmGeographicalScope,
mGsmGeographicalScope)
if (aGsmGeographicalScope < nsICellBroadcastService::GSM_GEOGRAPHICAL_SCOPE_INVALID) {
mGsmGeographicalScope.SetValue(
ToWebidlEnum<CellBroadcastGsmGeographicalScope>(aGsmGeographicalScope));
}
CONVERT_STRING_TO_NULLABLE_ENUM(aMessageClass,
CellBroadcastMessageClass,
mMessageClass)
if (aMessageClass < nsICellBroadcastService::GSM_MESSAGE_CLASS_INVALID) {
mMessageClass.SetValue(
ToWebidlEnum<CellBroadcastMessageClass>(aMessageClass));
}
// CdmaServiceCategory represents a 16bit unsigned value.
if (aCdmaServiceCategory > 0xFFFFU) {
mCdmaServiceCategory.SetNull();
} else {
if (aCdmaServiceCategory <= 0xFFFFU) {
mCdmaServiceCategory.SetValue(static_cast<uint16_t>(aCdmaServiceCategory));
}
@ -111,16 +129,17 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CellBroadcastEtwsInfo)
NS_INTERFACE_MAP_END
CellBroadcastEtwsInfo::CellBroadcastEtwsInfo(nsPIDOMWindow* aWindow,
const nsAString& aWarningType,
uint32_t aWarningType,
bool aEmergencyUserAlert,
bool aPopup)
: mWindow(aWindow)
, mEmergencyUserAlert(aEmergencyUserAlert)
, mPopup(aPopup)
{
CONVERT_STRING_TO_NULLABLE_ENUM(aWarningType,
CellBroadcastEtwsWarningType,
mWarningType)
if (aWarningType < nsICellBroadcastService::GSM_ETWS_WARNING_INVALID) {
mWarningType.SetValue(
ToWebidlEnum<CellBroadcastEtwsWarningType>(aWarningType));
}
SetIsDOMBinding();
}

View File

@ -28,16 +28,16 @@ public:
CellBroadcastMessage(nsPIDOMWindow* aWindow,
uint32_t aServiceId,
const nsAString& aGsmGeographicalScope,
uint32_t aGsmGeographicalScope,
uint16_t aMessageCode,
uint16_t aMessageId,
const nsAString& aLanguage,
const nsAString& aBody,
const nsAString& aMessageClass,
uint32_t aMessageClass,
uint64_t aTimestamp,
uint32_t aCdmaServiceCategory,
bool aHasEtwsInfo,
const nsAString& aEtwsWarningType,
uint32_t aEtwsWarningType,
bool aEtwsEmergencyUserAlert,
bool aEtwsPopup);
@ -99,7 +99,7 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CellBroadcastEtwsInfo)
CellBroadcastEtwsInfo(nsPIDOMWindow* aWindow,
const nsAString& aWarningType,
uint32_t aWarningType,
bool aEmergencyUserAlert,
bool aPopup);

View File

@ -67,6 +67,24 @@ CellBroadcastService.prototype = {
} catch (e) {}
},
_convertCbGsmGeographicalScope: function(aGeographicalScope) {
return (aGeographicalScope >= Ci.nsICellBroadcastService.GSM_GEOGRAPHICAL_SCOPE_INVALID)
? null
: RIL.CB_GSM_GEOGRAPHICAL_SCOPE_NAMES[aGeographicalScope];
},
_convertCbMessageClass: function(aMessageClass) {
return (aMessageClass >= Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS)
? null
: RIL.GECKO_SMS_MESSAGE_CLASSES[aMessageClass];
},
_convertCbEtwsWarningType: function(aWarningType) {
return (aWarningType >= Ci.nsICellBroadcastService.GSM_ETWS_WARNING_INVALID)
? null
: RIL.CB_ETWS_WARNING_TYPE_NAMES[aWarningType];
},
/**
* nsICellBroadcastService interface
*/
@ -108,12 +126,12 @@ CellBroadcastService.prototype = {
// Align the same layout to MozCellBroadcastMessage
let systemMessage = {
serviceId: aServiceId,
gsmGeographicalScope: aGsmGeographicalScope,
gsmGeographicalScope: this._convertCbGsmGeographicalScope(aGsmGeographicalScope),
messageCode: aMessageCode,
messageId: aMessageId,
language: aLanguage,
body: aBody,
messageClass: aMessageClass,
messageClass: this._convertCbMessageClass(aMessageClass),
timestamp: aTimestamp,
cdmaServiceCategory: null,
etws: null
@ -121,7 +139,7 @@ CellBroadcastService.prototype = {
if (aHasEtwsInfo) {
systemMessage.etws = {
warningType: aEtwsWarningType,
warningType: this._convertCbEtwsWarningType(aEtwsWarningType),
emergencyUserAlert: aEtwsEmergencyUserAlert,
popup: aEtwsPopup
};

View File

@ -5,23 +5,23 @@
#include "domstubs.idl"
#include "nsISupports.idl"
[scriptable, uuid(fd1f9efa-3d6c-11e4-a7be-e3b99e7f903b)]
[scriptable, uuid(56f66190-44a0-11e4-aa32-636783cc014a)]
interface nsICellBroadcastListener : nsISupports
{
/**
* Called when a Cell Broadcast message has been received by the network.
*/
void notifyMessageReceived(in unsigned long aServiceId,
in DOMString aGsmGeographicalScope,
in unsigned long aGsmGeographicalScope,
in unsigned short aMessageCode,
in unsigned short aMessageId,
in DOMString aLanguage,
in DOMString aBody,
in DOMString aMessageClass,
in unsigned long aMessageClass,
in DOMTimeStamp aTimestamp,
in unsigned long aCdmaServiceCategory,
in boolean aHasEtwsInfo,
in DOMString aEtwsWarningType,
in unsigned long aEtwsWarningType,
in boolean aEtwsEmergencyUserAlert,
in boolean aEtwsPopup);
};
@ -36,9 +36,43 @@ interface nsICellBroadcastListener : nsISupports
/**
* XPCOM component that provides the cell broadcast information.
*/
[scriptable, uuid(05099b34-21f7-11e4-b3b9-1b1b03487cab)]
[scriptable, uuid(eed283f6-44a8-11e4-b364-afb894b7a283)]
interface nsICellBroadcastService : nsISupports
{
/**
* Constant definitions of predefined GSM Geographic Scope
* See 3GPP TS 23.041 clause 9.4.1.2.1 Serial Number
*/
const unsigned short GSM_GEOGRAPHICAL_SCOPE_CELL_IMMEDIATE = 0;
const unsigned short GSM_GEOGRAPHICAL_SCOPE_PLMN = 1;
const unsigned short GSM_GEOGRAPHICAL_SCOPE_LOCATION_AREA = 2;
const unsigned short GSM_GEOGRAPHICAL_SCOPE_CELL = 3;
const unsigned short GSM_GEOGRAPHICAL_SCOPE_INVALID = 4;
/**
* Constant definitions of predefined GSM Message Class
* See 3GPP TS 23.038 clause 5 CBS Data Coding Scheme
*/
const unsigned short GSM_MESSAGE_CLASS_0 = 0;
const unsigned short GSM_MESSAGE_CLASS_1 = 1;
const unsigned short GSM_MESSAGE_CLASS_2 = 2;
const unsigned short GSM_MESSAGE_CLASS_3 = 3;
const unsigned short GSM_MESSAGE_CLASS_USER_1 = 4;
const unsigned short GSM_MESSAGE_CLASS_USER_2 = 5;
const unsigned short GSM_MESSAGE_CLASS_NORMAL = 6;
const unsigned short GSM_MESSAGE_CLASS_INVALID = 7;
/**
* Constant definitions of predefined GSM ETWS Warning Types
* see 3GPP TS 23.041 clause 9.3.24 Warning-Type
*/
const unsigned short GSM_ETWS_WARNING_EARTHQUAKE = 0;
const unsigned short GSM_ETWS_WARNING_TSUNAMI = 1;
const unsigned short GSM_ETWS_WARNING_EARTHQUAKE_TSUNAMI = 2;
const unsigned short GSM_ETWS_WARNING_TEST = 3;
const unsigned short GSM_ETWS_WARNING_OTHER = 4;
const unsigned short GSM_ETWS_WARNING_INVALID = 5;
/**
* Attribute CdmaServiceCategory is only valid in CDMA network.
* Set to CDMA_SERVICE_CATEGORY_INVALID if received from GSM/UMTS network.

View File

@ -9,23 +9,23 @@
"@mozilla.org/cellbroadcast/gonkservice;1"
%}
[scriptable, uuid(f72ced60-21f9-11e4-8896-6fdff2f5c909)]
[scriptable, uuid(7cac92aa-42f8-11e4-96f3-7f490e355277)]
interface nsIGonkCellBroadcastService : nsICellBroadcastService
{
/**
* Called when a cellbroadcast message has been received by the network.
*/
void notifyMessageReceived(in unsigned long aServiceId,
in DOMString aGsmGeographicalScope,
in unsigned long aGsmGeographicalScope,
in unsigned short aMessageCode,
in unsigned short aMessageId,
in DOMString aLanguage,
in DOMString aBody,
in DOMString aMessageClass,
in unsigned long aMessageClass,
in DOMTimeStamp aTimestamp,
in unsigned long aCdmaServiceCategory,
in boolean aHasEtwsInfo,
in DOMString aEtwsWarningType,
in unsigned long aEtwsWarningType,
in boolean aEtwsEmergencyUserAlert,
in boolean aEtwsPopup);
};

View File

@ -63,16 +63,16 @@ CellBroadcastIPCService::UnregisterListener(nsICellBroadcastListener* aListener)
bool
CellBroadcastIPCService::RecvNotifyReceivedMessage(const uint32_t& aServiceId,
const nsString& aGsmGeographicalScope,
const uint32_t& aGsmGeographicalScope,
const uint16_t& aMessageCode,
const uint16_t& aMessageId,
const nsString& aLanguage,
const nsString& aBody,
const nsString& aMessageClass,
const uint32_t& aMessageClass,
const uint64_t& aTimestamp,
const uint32_t& aCdmaServiceCategory,
const bool& aHasEtwsInfo,
const nsString& aEtwsWarningType,
const uint32_t& aEtwsWarningType,
const bool& aEtwsEmergencyUserAlert,
const bool& aEtwsPopup)
{

View File

@ -28,16 +28,16 @@ public:
// PCellBroadcastChild interface
virtual bool
RecvNotifyReceivedMessage(const uint32_t& aServiceId,
const nsString& aGsmGeographicalScope,
const uint32_t& aGsmGeographicalScope,
const uint16_t& aMessageCode,
const uint16_t& aMessageId,
const nsString& aLanguage,
const nsString& aBody,
const nsString& aMessageClass,
const uint32_t& aMessageClass,
const uint64_t& aTimestamp,
const uint32_t& aCdmaServiceCategory,
const bool& aHasEtwsInfo,
const nsString& aEtwsWarningType,
const uint32_t& aEtwsWarningType,
const bool& aEtwsEmergencyUserAlert,
const bool& aEtwsPopup) MOZ_OVERRIDE;

View File

@ -41,30 +41,30 @@ CellBroadcastParent::ActorDestroy(ActorDestroyReason aWhy)
*/
NS_IMETHODIMP
CellBroadcastParent::NotifyMessageReceived(uint32_t aServiceId,
const nsAString& aGsmGeographicalScope,
uint32_t aGsmGeographicalScope,
uint16_t aMessageCode,
uint16_t aMessageId,
const nsAString& aLanguage,
const nsAString& aBody,
const nsAString& aMessageClass,
uint32_t aMessageClass,
DOMTimeStamp aTimestamp,
uint32_t aCdmaServiceCategory,
bool aHasEtwsInfo,
const nsAString& aEtwsWarningType,
uint32_t aEtwsWarningType,
bool aEtwsEmergencyUserAlert,
bool aEtwsPopup)
{
return SendNotifyReceivedMessage(aServiceId,
nsString(aGsmGeographicalScope),
aGsmGeographicalScope,
aMessageCode,
aMessageId,
nsString(aLanguage),
nsString(aBody),
nsString(aMessageClass),
aMessageClass,
aTimestamp,
aCdmaServiceCategory,
aHasEtwsInfo,
nsString(aEtwsWarningType),
aEtwsWarningType,
aEtwsEmergencyUserAlert,
aEtwsPopup) ? NS_OK : NS_ERROR_FAILURE;
}

View File

@ -15,16 +15,16 @@ sync protocol PCellBroadcast {
child:
NotifyReceivedMessage(uint32_t aServiceId,
nsString aGsmGeographicalScope,
uint32_t aGsmGeographicalScope,
uint16_t aMessageCode,
uint16_t aMessageId,
nsString aLanguage,
nsString aBody,
nsString aMessageClass,
uint32_t aMessageClass,
uint64_t aTimestamp,
uint32_t aCdmaServiceCategory,
bool aHasEtwsInfo,
nsString aEtwsWarningType,
uint32_t aEtwsWarningType,
bool aEtwsEmergencyUserAlert,
bool aEtwsPopup);

View File

@ -2943,6 +2943,25 @@ RadioInterface.prototype = {
gMessageManager.sendIccMessage("RIL:StkCommand", this.clientId, message);
},
_convertCbGsmGeographicalScope: function(aGeographicalScope) {
return (aGeographicalScope != null)
? aGeographicalScope
: Ci.nsICellBroadcastService.GSM_GEOGRAPHICAL_SCOPE_INVALID;
},
_convertCbMessageClass: function(aMessageClass) {
let index = RIL.GECKO_SMS_MESSAGE_CLASSES.indexOf(aMessageClass);
return (index != -1)
? index
: Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS_INVALID;
},
_convertCbEtwsWarningType: function(aWarningType) {
return (aWarningType != null)
? aWarningType
: Ci.nsICellBroadcastService.GSM_ETWS_WARNING_INVALID;
},
handleCellbroadcastMessageReceived: function(aMessage) {
let etwsInfo = aMessage.etws;
let hasEtwsInfo = etwsInfo != null;
@ -2952,18 +2971,18 @@ RadioInterface.prototype = {
gCellBroadcastService
.notifyMessageReceived(this.clientId,
RIL.CB_GSM_GEOGRAPHICAL_SCOPE_NAMES[aMessage.geographicalScope],
this._convertCbGsmGeographicalScope(aMessage.geographicalScope),
aMessage.messageCode,
aMessage.messageId,
aMessage.language,
aMessage.fullBody,
aMessage.messageClass,
this._convertCbMessageClass(aMessage.messageClass),
Date.now(),
serviceCategory,
hasEtwsInfo,
(hasEtwsInfo && etwsInfo.warningType != null)
? RIL.CB_ETWS_WARNING_TYPE_NAMES[etwsInfo.warningType]
: null,
(hasEtwsInfo)
? this._convertCbEtwsWarningType(etwsInfo.warningType)
: Ci.nsICellBroadcastService.GSM_ETWS_WARNING_INVALID,
hasEtwsInfo ? etwsInfo.emergencyUserAlert : false,
hasEtwsInfo ? etwsInfo.popup : false);
},

View File

@ -1571,13 +1571,13 @@ this.PDU_PID_USIM_DATA_DOWNLOAD = 0x7F;
this.PDU_DCS_MSG_CODING_7BITS_ALPHABET = 0x00;
this.PDU_DCS_MSG_CODING_8BITS_ALPHABET = 0x04;
this.PDU_DCS_MSG_CODING_16BITS_ALPHABET = 0x08;
this.PDU_DCS_MSG_CLASS_NORMAL = 0xFF;
this.PDU_DCS_MSG_CLASS_0 = 0x00;
this.PDU_DCS_MSG_CLASS_1 = 0x01;
this.PDU_DCS_MSG_CLASS_2 = 0x02;
this.PDU_DCS_MSG_CLASS_3 = 0x03;
this.PDU_DCS_MSG_CLASS_USER_1 = 0x04;
this.PDU_DCS_MSG_CLASS_USER_2 = 0x05;
this.PDU_DCS_MSG_CLASS_NORMAL = 0x06;
this.PDU_DCS_CODING_GROUP_BITS = 0xF0;
this.PDU_DCS_MSG_CLASS_BITS = 0x03;
this.PDU_DCS_MWI_ACTIVE_BITS = 0x08;
@ -1588,14 +1588,15 @@ this.PDU_DCS_MWI_TYPE_FAX = 0x01;
this.PDU_DCS_MWI_TYPE_EMAIL = 0x02;
this.PDU_DCS_MWI_TYPE_OTHER = 0x03;
this.GECKO_SMS_MESSAGE_CLASSES = {};
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL] = "normal";
// Set as Array instead of Object for reversed-mapping with Array.indexOf().
this.GECKO_SMS_MESSAGE_CLASSES = [];
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_0] = "class-0";
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_1] = "class-1";
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_2] = "class-2";
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_3] = "class-3";
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_USER_1] = "user-1";
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_USER_2] = "user-2";
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL] = "normal";
// Because service center timestamp omit the century. Yay.
this.PDU_TIMESTAMP_YEAR_OFFSET = 2000;

View File

@ -6,8 +6,8 @@
enum CellBroadcastGsmGeographicalScope {"cell-immediate", "plmn",
"location-area", "cell"};
enum CellBroadcastMessageClass {"normal", "class-0", "class-1", "class-2",
"class-3", "user-1", "user-2"};
enum CellBroadcastMessageClass {"class-0", "class-1", "class-2",
"class-3", "user-1", "user-2", "normal"};
enum CellBroadcastEtwsWarningType {"earthquake", "tsunami",
"earthquake-tsunami", "test", "other"};