Bug 864484 - Part 7: Narrow down the DOMString values to predefined constants in .idl. r=vyang, r=smaug
authorBevis Tseng <btseng@mozilla.com>
Tue, 23 Sep 2014 18:27:03 +0800
changeset 232299 c91b29906f9cd09415ded6c0c8f5e5166e45eb2a
parent 232298 028249514d59b49007fa75fc4424dd5cec3c26b5
child 232300 e380780c6728c12b3eef6871bf6a9499c51909c4
push id611
push userraliiev@mozilla.com
push dateMon, 05 Jan 2015 23:23:16 +0000
treeherdermozilla-release@345cd3b9c445 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvyang, smaug
bugs864484
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 864484 - Part 7: Narrow down the DOMString values to predefined constants in .idl. r=vyang, r=smaug
dom/cellbroadcast/CellBroadcast.cpp
dom/cellbroadcast/CellBroadcastMessage.cpp
dom/cellbroadcast/CellBroadcastMessage.h
dom/cellbroadcast/gonk/CellBroadcastService.js
dom/cellbroadcast/interfaces/nsICellBroadcastService.idl
dom/cellbroadcast/interfaces/nsIGonkCellBroadcastService.idl
dom/cellbroadcast/ipc/CellBroadcastIPCService.cpp
dom/cellbroadcast/ipc/CellBroadcastIPCService.h
dom/cellbroadcast/ipc/CellBroadcastParent.cpp
dom/cellbroadcast/ipc/PCellBroadcast.ipdl
dom/system/gonk/RadioInterfaceLayer.js
dom/system/gonk/ril_consts.js
dom/webidl/MozCellBroadcastMessage.webidl
--- a/dom/cellbroadcast/CellBroadcast.cpp
+++ b/dom/cellbroadcast/CellBroadcast.cpp
@@ -106,26 +106,26 @@ CellBroadcast::WrapObject(JSContext* aCx
 {
   return MozCellBroadcastBinding::Wrap(aCx, this);
 }
 
 // Forwarded nsICellBroadcastListener methods
 
 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;
   init.mBubbles = true;
   init.mCancelable = false;
   init.mMessage = new CellBroadcastMessage(GetOwner(),
                                            aServiceId,
                                            aGsmGeographicalScope,
--- a/dom/cellbroadcast/CellBroadcastMessage.cpp
+++ b/dom/cellbroadcast/CellBroadcastMessage.cpp
@@ -1,87 +1,105 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #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.
  */
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CellBroadcastMessage, mWindow, mEtwsInfo)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(CellBroadcastMessage)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(CellBroadcastMessage)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CellBroadcastMessage)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 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)
   , mServiceId(aServiceId)
   , mMessageCode(aMessageCode)
   , mMessageId(aMessageId)
   , mLanguage(aLanguage)
   , mBody(aBody)
   , mTimestamp(aTimestamp)
   , mEtwsInfo(aHasEtwsInfo ? new CellBroadcastEtwsInfo(aWindow,
                                                        aEtwsWarningType,
                                                        aEtwsEmergencyUserAlert,
                                                        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));
   }
 
   SetIsDOMBinding();
 }
 
 JSObject*
 CellBroadcastMessage::WrapObject(JSContext* aCx)
@@ -106,26 +124,27 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(CellBroa
 NS_IMPL_CYCLE_COLLECTING_RELEASE(CellBroadcastEtwsInfo)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CellBroadcastEtwsInfo)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 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();
 }
 
 JSObject*
 CellBroadcastEtwsInfo::WrapObject(JSContext* aCx)
 {
   return MozCellBroadcastEtwsInfoBinding::Wrap(aCx, this);
--- a/dom/cellbroadcast/CellBroadcastMessage.h
+++ b/dom/cellbroadcast/CellBroadcastMessage.h
@@ -23,26 +23,26 @@ class CellBroadcastMessage MOZ_FINAL : p
                                      , public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(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);
 
   nsPIDOMWindow*
   GetParentObject() const { return mWindow; }
 
   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
 
@@ -94,17 +94,17 @@ private:
 class CellBroadcastEtwsInfo MOZ_FINAL : public nsISupports
                                       , public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CellBroadcastEtwsInfo)
 
   CellBroadcastEtwsInfo(nsPIDOMWindow* aWindow,
-                        const nsAString& aWarningType,
+                        uint32_t aWarningType,
                         bool aEmergencyUserAlert,
                         bool aPopup);
 
   nsPIDOMWindow*
   GetParentObject() const { return mWindow; }
 
   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
 
--- a/dom/cellbroadcast/gonk/CellBroadcastService.js
+++ b/dom/cellbroadcast/gonk/CellBroadcastService.js
@@ -62,16 +62,34 @@ CellBroadcastService.prototype = {
 
   _updateDebugFlag: function() {
     try {
       DEBUG = RIL.DEBUG_RIL ||
               Services.prefs.getBoolPref(kPrefRilDebuggingEnabled);
     } 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
    */
   registerListener: function(aListener) {
     if (this._listeners.indexOf(aListener) >= 0) {
       throw Cr.NS_ERROR_UNEXPECTED;
     }
 
@@ -103,30 +121,30 @@ CellBroadcastService.prototype = {
                                   aHasEtwsInfo,
                                   aEtwsWarningType,
                                   aEtwsEmergencyUserAlert,
                                   aEtwsPopup) {
     // Broadcast CBS System message
     // 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
     };
 
     if (aHasEtwsInfo) {
       systemMessage.etws = {
-        warningType: aEtwsWarningType,
+        warningType: this._convertCbEtwsWarningType(aEtwsWarningType),
         emergencyUserAlert: aEtwsEmergencyUserAlert,
         popup: aEtwsPopup
       };
     }
 
     if (aCdmaServiceCategory !=
         Ci.nsICellBroadcastService.CDMA_SERVICE_CATEGORY_INVALID) {
       systemMessage.cdmaServiceCategory = aCdmaServiceCategory;
--- a/dom/cellbroadcast/interfaces/nsICellBroadcastService.idl
+++ b/dom/cellbroadcast/interfaces/nsICellBroadcastService.idl
@@ -1,50 +1,84 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #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);
 };
 
 %{C++
 #define CELLBROADCAST_SERVICE_CID \
   { 0xc870bdca, 0x277c, 0x11e4, { 0xac, 0xa3, 0x33, 0x73, 0xa1, 0xef, 0x48, 0xf8 } }
 #define CELLBROADCAST_SERVICE_CONTRACTID \
   "@mozilla.org/cellbroadcast/cellbroadcastservice;1"
 %}
 
 /**
  * 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.
    */
   const unsigned long CDMA_SERVICE_CATEGORY_INVALID = 0xFFFFFFFF;
 
   /**
    * Called to register receiving cellbroadcast messages.
    *
--- a/dom/cellbroadcast/interfaces/nsIGonkCellBroadcastService.idl
+++ b/dom/cellbroadcast/interfaces/nsIGonkCellBroadcastService.idl
@@ -4,28 +4,28 @@
 
 #include "nsICellBroadcastService.idl"
 
 %{C++
 #define GONK_CELLBROADCAST_SERVICE_CONTRACTID \
         "@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);
 };
--- a/dom/cellbroadcast/ipc/CellBroadcastIPCService.cpp
+++ b/dom/cellbroadcast/ipc/CellBroadcastIPCService.cpp
@@ -58,26 +58,26 @@ CellBroadcastIPCService::UnregisterListe
 }
 
 /*
  * Implementation of PCellBroadcastChild.
  */
 
 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)
 {
   // UnregisterListener() could be triggered in
   // nsICellBroadcastListener::NotifyMessageReceived().
   // Make a immutable copy for notifying the event.
   nsTArray<nsCOMPtr<nsICellBroadcastListener>> immutableListeners(mListeners);
   for (uint32_t i = 0; i < immutableListeners.Length(); i++) {
--- a/dom/cellbroadcast/ipc/CellBroadcastIPCService.h
+++ b/dom/cellbroadcast/ipc/CellBroadcastIPCService.h
@@ -23,26 +23,26 @@ public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSICELLBROADCASTSERVICE
 
   CellBroadcastIPCService();
 
   // 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;
 
   virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
 
 private:
   // MOZ_FINAL suppresses -Werror,-Wdelete-non-virtual-dtor
   ~CellBroadcastIPCService();
--- a/dom/cellbroadcast/ipc/CellBroadcastParent.cpp
+++ b/dom/cellbroadcast/ipc/CellBroadcastParent.cpp
@@ -36,39 +36,39 @@ CellBroadcastParent::ActorDestroy(ActorD
   }
 }
 
 /*
  * nsICellBroadcastListener
  */
 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;
 }
 
 } // namespace cellbroadcast
 } // namespace dom
 } // namespace mozilla
\ No newline at end of file
--- a/dom/cellbroadcast/ipc/PCellBroadcast.ipdl
+++ b/dom/cellbroadcast/ipc/PCellBroadcast.ipdl
@@ -10,26 +10,26 @@ namespace mozilla {
 namespace dom {
 namespace cellbroadcast {
 
 sync protocol PCellBroadcast {
   manager PContent;
 
 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);
 
 parent:
   /**
    * Sent when the child no longer needs to use cellbroadcast.
    */
   __delete__();
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -2938,37 +2938,56 @@ RadioInterface.prototype = {
     if (iccId) {
       gSystemMessenger.broadcastMessage("icc-stkcommand",
                                         {iccId: iccId,
                                          command: message});
     }
     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;
     let serviceCategory = (aMessage.serviceCategory)
       ? aMessage.serviceCategory
       : Ci.nsICellBroadcastService.CDMA_SERVICE_CATEGORY_INVALID;
 
     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);
   },
 
   // nsIObserver
 
   observe: function(subject, topic, data) {
     switch (topic) {
--- a/dom/system/gonk/ril_consts.js
+++ b/dom/system/gonk/ril_consts.js
@@ -1566,41 +1566,42 @@ this.PDU_PID_ANSI_136_R_DATA            
 this.PDU_PID_ME_DATA_DOWNLOAD             = 0x7D;
 this.PDU_PID_ME_DEPERSONALIZATION         = 0x7E;
 this.PDU_PID_USIM_DATA_DOWNLOAD           = 0x7F;
 
 // DCS - Data Coding Scheme
 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;
 this.PDU_DCS_MWI_ACTIVE_VALUE           = 0x08;
 this.PDU_DCS_MWI_TYPE_BITS              = 0x03;
 this.PDU_DCS_MWI_TYPE_VOICEMAIL         = 0x00;
 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;
 
 // See 9.2.3.24 TP‑User Data (TP‑UD)
 this.PDU_IEI_CONCATENATED_SHORT_MESSAGES_8BIT         = 0x00;
 this.PDU_IEI_SPECIAL_SMS_MESSAGE_INDICATION           = 0x01;
 this.PDU_IEI_APPLICATION_PORT_ADDRESSING_SCHEME_8BIT  = 0x04;
--- a/dom/webidl/MozCellBroadcastMessage.webidl
+++ b/dom/webidl/MozCellBroadcastMessage.webidl
@@ -1,18 +1,18 @@
 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
 /* vim: set ts=2 et sw=2 tw=40: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 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"};
 
 [Pref="dom.cellbroadcast.enabled"]
 interface MozCellBroadcastMessage
 {
   /**
    * The Service Id in the device where the message is received from.