Bug 797277 - Part 2/5: dom implementation, r=mounir
authorVicamo Yang <vyang@mozilla.com>
Wed, 31 Oct 2012 17:10:44 +0800
changeset 112012 e57c5417fb2c4c920333787a44bd24ca0d85291e
parent 112011 e2cb5f94ead63d0e8c07b86a08bfa561767cb371
child 112013 c02178f03fa4769f3f2a1f54af170b1f3280dc04
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmounir
bugs797277
milestone19.0a1
Bug 797277 - Part 2/5: dom implementation, r=mounir
dom/sms/interfaces/nsISmsDatabaseService.idl
dom/sms/interfaces/nsISmsService.idl
dom/sms/src/Constants.h
dom/sms/src/SmsMessage.cpp
dom/sms/src/SmsMessage.h
dom/sms/src/Types.h
dom/sms/src/fallback/SmsDatabaseService.cpp
dom/sms/src/fallback/SmsService.cpp
dom/sms/src/ipc/PSms.ipdl
dom/sms/src/ipc/SmsIPCService.cpp
dom/sms/src/ipc/SmsParent.cpp
dom/sms/src/ipc/SmsParent.h
dom/sms/src/ril/SmsService.cpp
--- a/dom/sms/interfaces/nsISmsDatabaseService.idl
+++ b/dom/sms/interfaces/nsISmsDatabaseService.idl
@@ -8,21 +8,21 @@
 #define SMS_DATABASE_SERVICE_CID \
 { 0x2454c2a1, 0xefdd, 0x4d96,    \
 { 0x83, 0xbd, 0x51, 0xa2, 0x9a, 0x21, 0xf5, 0xab } }
 #define SMS_DATABASE_SERVICE_CONTRACTID "@mozilla.org/sms/smsdatabaseservice;1"
 %}
 
 interface nsIDOMMozSmsFilter;
 
-[scriptable, uuid(d6318c22-1ebd-4262-b991-432f61a96237)]
+[scriptable, uuid(6fdb6007-51d0-456c-8b2e-dc0aea456298)]
 interface nsISmsDatabaseService : nsISupports
 {
   // Takes some information required to save the message and returns its id.
-  long saveReceivedMessage(in DOMString aSender, in DOMString aBody, in unsigned long long aDate);
+  long saveReceivedMessage(in DOMString aSender, in DOMString aBody, in DOMString aMessageClass, in unsigned long long aDate);
   // Takes some information required to save the message and returns its id.
   long saveSentMessage(in DOMString aReceiver, in DOMString aBody, in unsigned long long aDate);
   void setMessageDeliveryStatus(in long aMessageId, in DOMString aDeliveryStatus);
 
   [binaryname(GetMessageMoz)] void getMessage(in long messageId, in long requestId, [optional] in unsigned long long processId);
   void deleteMessage(in long messageId, in long requestId, [optional] in unsigned long long processId);
 
   void createMessageList(in nsIDOMMozSmsFilter filter, in boolean reverse, in long requestId, [optional] in unsigned long long processId);
--- a/dom/sms/interfaces/nsISmsService.idl
+++ b/dom/sms/interfaces/nsISmsService.idl
@@ -6,26 +6,27 @@
 
 interface nsIDOMMozSmsMessage;
 
 %{C++
 #define SMS_SERVICE_CID { 0xbada3cb8, 0xa568, 0x4dff, { 0xb5, 0x43, 0x52, 0xbb, 0xb3, 0x14, 0x31, 0x21 } }
 #define SMS_SERVICE_CONTRACTID "@mozilla.org/sms/smsservice;1"
 %}
 
-[scriptable, builtinclass, uuid(a1367149-c09f-4e8c-a890-5812406bed61)]
+[scriptable, builtinclass, uuid(9808dc00-33c6-45cc-a761-d1151cb192d6)]
 interface nsISmsService : nsISupports
 {
   boolean        hasSupport();
   unsigned short getNumberOfMessagesForText(in DOMString text);
             void send(in DOMString number, in DOMString message,
                       in long requestId, [optional] in unsigned long long processId);
 
   [implicit_jscontext]
   nsIDOMMozSmsMessage createSmsMessage(in long      id,
                                        in DOMString delivery,
                                        in DOMString deliveryStatus,
                                        in DOMString sender,
                                        in DOMString receiver,
                                        in DOMString body,
+                                       in DOMString messageClass,
                                        in jsval     timestamp,
                                        in bool      read);
 };
--- a/dom/sms/src/Constants.h
+++ b/dom/sms/src/Constants.h
@@ -18,13 +18,19 @@ extern const char* kSmsDeliveryErrorObse
 #define DELIVERY_RECEIVED NS_LITERAL_STRING("received")
 #define DELIVERY_SENT     NS_LITERAL_STRING("sent")
 
 #define DELIVERY_STATUS_NOT_APPLICABLE NS_LITERAL_STRING("not-applicable")
 #define DELIVERY_STATUS_SUCCESS        NS_LITERAL_STRING("success")
 #define DELIVERY_STATUS_PENDING        NS_LITERAL_STRING("pending")
 #define DELIVERY_STATUS_ERROR          NS_LITERAL_STRING("error")
 
+#define MESSAGE_CLASS_NORMAL  NS_LITERAL_STRING("normal")
+#define MESSAGE_CLASS_CLASS_0 NS_LITERAL_STRING("class-0")
+#define MESSAGE_CLASS_CLASS_1 NS_LITERAL_STRING("class-1")
+#define MESSAGE_CLASS_CLASS_2 NS_LITERAL_STRING("class-2")
+#define MESSAGE_CLASS_CLASS_3 NS_LITERAL_STRING("class-3")
+
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_sms_Constants_h
--- a/dom/sms/src/SmsMessage.cpp
+++ b/dom/sms/src/SmsMessage.cpp
@@ -25,35 +25,37 @@ NS_IMPL_ADDREF(SmsMessage)
 NS_IMPL_RELEASE(SmsMessage)
 
 SmsMessage::SmsMessage(int32_t aId,
                        DeliveryState aDelivery,
                        DeliveryStatus aDeliveryStatus,
                        const nsString& aSender,
                        const nsString& aReceiver,
                        const nsString& aBody,
+                       MessageClass aMessageClass,
                        uint64_t aTimestamp,
                        bool aRead)
   : mData(aId, aDelivery, aDeliveryStatus, aSender, aReceiver, aBody,
-          aTimestamp, aRead)
+          aMessageClass, aTimestamp, aRead)
 {
 }
 
 SmsMessage::SmsMessage(const SmsMessageData& aData)
   : mData(aData)
 {
 }
 
 /* static */ nsresult
 SmsMessage::Create(int32_t aId,
                    const nsAString& aDelivery,
                    const nsAString& aDeliveryStatus,
                    const nsAString& aSender,
                    const nsAString& aReceiver,
                    const nsAString& aBody,
+                   const nsAString& aMessageClass,
                    const jsval& aTimestamp,
                    const bool aRead,
                    JSContext* aCx,
                    nsIDOMMozSmsMessage** aMessage)
 {
   *aMessage = nullptr;
 
   // SmsMessageData exposes these as references, so we can simply assign
@@ -80,16 +82,30 @@ SmsMessage::Create(int32_t aId,
   } else if (aDeliveryStatus.Equals(DELIVERY_STATUS_PENDING)) {
     data.deliveryStatus() = eDeliveryStatus_Pending;
   } else if (aDeliveryStatus.Equals(DELIVERY_STATUS_ERROR)) {
     data.deliveryStatus() = eDeliveryStatus_Error;
   } else {
     return NS_ERROR_INVALID_ARG;
   }
 
+  if (aMessageClass.Equals(MESSAGE_CLASS_NORMAL)) {
+    data.messageClass() = eMessageClass_Normal;
+  } else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_0)) {
+    data.messageClass() = eMessageClass_Class0;
+  } else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_1)) {
+    data.messageClass() = eMessageClass_Class1;
+  } else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_2)) {
+    data.messageClass() = eMessageClass_Class2;
+  } else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_3)) {
+    data.messageClass() = eMessageClass_Class3;
+  } else {
+    return NS_ERROR_INVALID_ARG;
+  }
+
   // We support both a Date object and a millisecond timestamp as a number.
   if (aTimestamp.isObject()) {
     JSObject& obj = aTimestamp.toObject();
     if (!JS_ObjectIsDate(aCx, &obj)) {
       return NS_ERROR_INVALID_ARG;
     }
     data.timestamp() = js_DateGetMsecSinceEpoch(&obj);
   } else {
@@ -183,16 +199,43 @@ SmsMessage::GetReceiver(nsAString& aRece
 NS_IMETHODIMP
 SmsMessage::GetBody(nsAString& aBody)
 {
   aBody = mData.body();
   return NS_OK;
 }
 
 NS_IMETHODIMP
+SmsMessage::GetMessageClass(nsAString& aMessageClass)
+{
+  switch (mData.messageClass()) {
+    case eMessageClass_Normal:
+      aMessageClass = MESSAGE_CLASS_NORMAL;
+      break;
+    case eMessageClass_Class0:
+      aMessageClass = MESSAGE_CLASS_CLASS_0;
+      break;
+    case eMessageClass_Class1:
+      aMessageClass = MESSAGE_CLASS_CLASS_1;
+      break;
+    case eMessageClass_Class2:
+      aMessageClass = MESSAGE_CLASS_CLASS_2;
+      break;
+    case eMessageClass_Class3:
+      aMessageClass = MESSAGE_CLASS_CLASS_3;
+      break;
+    default:
+      MOZ_NOT_REACHED("We shouldn't get any other message class!");
+      return NS_ERROR_UNEXPECTED;
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 SmsMessage::GetTimestamp(JSContext* cx, jsval* aDate)
 {
   *aDate = OBJECT_TO_JSVAL(JS_NewDateObjectMsec(cx, mData.timestamp()));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SmsMessage::GetRead(bool* aRead)
--- a/dom/sms/src/SmsMessage.h
+++ b/dom/sms/src/SmsMessage.h
@@ -24,26 +24,28 @@ public:
   NS_DECL_NSIDOMMOZSMSMESSAGE
 
   SmsMessage(int32_t aId,
              DeliveryState aDelivery,
              DeliveryStatus aDeliveryStatus,
              const nsString& aSender,
              const nsString& aReceiver,
              const nsString& aBody,
+             MessageClass aMessageClass,
              uint64_t aTimestamp,
              bool aRead);
   SmsMessage(const SmsMessageData& aData);
 
   static nsresult Create(int32_t aId,
                          const nsAString& aDelivery,
                          const nsAString& aDeliveryStatus,
                          const nsAString& aSender,
                          const nsAString& aReceiver,
                          const nsAString& aBody,
+                         const nsAString& aMessageClass,
                          const JS::Value& aTimestamp,
                          const bool aRead,
                          JSContext* aCx,
                          nsIDOMMozSmsMessage** aMessage);
   const SmsMessageData& GetData() const;
 
 private:
   // Don't try to use the default constructor.
--- a/dom/sms/src/Types.h
+++ b/dom/sms/src/Types.h
@@ -37,16 +37,27 @@ enum DeliveryStatus {
 enum ReadState {
   eReadState_Unknown = -1,
   eReadState_Unread,
   eReadState_Read,
   // This state should stay at the end.
   eReadState_EndGuard
 };
 
+// For SmsFilterData.messageClass
+enum MessageClass {
+  eMessageClass_Normal = 0,
+  eMessageClass_Class0,
+  eMessageClass_Class1,
+  eMessageClass_Class2,
+  eMessageClass_Class3,
+  // This state should stay at the end.
+  eMessageClass_EndGuard
+};
+
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
 
 namespace IPC {
 
 /**
  * Delivery state serializer.
@@ -73,11 +84,21 @@ struct ParamTraits<mozilla::dom::sms::De
  */
 template <>
 struct ParamTraits<mozilla::dom::sms::ReadState>
   : public EnumSerializer<mozilla::dom::sms::ReadState,
                           mozilla::dom::sms::eReadState_Unknown,
                           mozilla::dom::sms::eReadState_EndGuard>
 {};
 
+/**
+ * Message class serializer.
+ */
+template <>
+struct ParamTraits<mozilla::dom::sms::MessageClass>
+  : public EnumSerializer<mozilla::dom::sms::MessageClass,
+                          mozilla::dom::sms::eMessageClass_Normal,
+                          mozilla::dom::sms::eMessageClass_EndGuard>
+{};
+
 } // namespace IPC
 
 #endif // mozilla_dom_sms_Types_h
--- a/dom/sms/src/fallback/SmsDatabaseService.cpp
+++ b/dom/sms/src/fallback/SmsDatabaseService.cpp
@@ -9,17 +9,19 @@ namespace mozilla {
 namespace dom {
 namespace sms {
 
 NS_IMPL_ISUPPORTS1(SmsDatabaseService, nsISmsDatabaseService)
 
 NS_IMETHODIMP
 SmsDatabaseService::SaveReceivedMessage(const nsAString& aSender,
                                         const nsAString& aBody,
-                                        uint64_t aDate, int32_t* aId)
+                                        const nsAString& aMessageClass,
+                                        uint64_t aDate,
+                                        int32_t* aId)
 {
   *aId = -1;
   NS_ERROR("We should not be here!");
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SmsDatabaseService::SaveSentMessage(const nsAString& aReceiver,
--- a/dom/sms/src/fallback/SmsService.cpp
+++ b/dom/sms/src/fallback/SmsService.cpp
@@ -38,22 +38,23 @@ SmsService::Send(const nsAString& aNumbe
 
 NS_IMETHODIMP
 SmsService::CreateSmsMessage(int32_t aId,
                              const nsAString& aDelivery,
                              const nsAString& aDeliveryStatus,
                              const nsAString& aSender,
                              const nsAString& aReceiver,
                              const nsAString& aBody,
+                             const nsAString& aMessageClass,
                              const jsval& aTimestamp,
                              const bool aRead,
                              JSContext* aCx,
                              nsIDOMMozSmsMessage** aMessage)
 {
   return SmsMessage::Create(aId, aDelivery, aDeliveryStatus,
                             aSender, aReceiver,
-                            aBody, aTimestamp, aRead,
+                            aBody, aMessageClass, aTimestamp, aRead,
                             aCx, aMessage);
 }
 
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
--- a/dom/sms/src/ipc/PSms.ipdl
+++ b/dom/sms/src/ipc/PSms.ipdl
@@ -4,29 +4,31 @@
  * 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 protocol PContent;
 include "mozilla/dom/sms/Types.h";
 
 using DeliveryState;
 using DeliveryStatus;
+using MessageClass;
 using ReadState;
 
 namespace mozilla {
 namespace dom {
 namespace sms {
 
 struct SmsMessageData {
   int32_t        id;
   DeliveryState  delivery;
   DeliveryStatus deliveryStatus;
   nsString       sender;
   nsString       receiver;
   nsString       body;
+  MessageClass   messageClass;
   uint64_t       timestamp; // ms since epoch.
   bool           read;
 };
 
 struct SmsFilterData {
   uint64_t      startDate;
   uint64_t      endDate;
   nsString[]    numbers;
@@ -82,17 +84,17 @@ parent:
         returns (bool aHasSupport);
 
     sync GetNumberOfMessagesForText(nsString aText)
         returns (uint16_t aNumber);
 
     SendMessage(nsString aNumber, nsString aMessage, int32_t aRequestId,
                 uint64_t aProcessId);
 
-    sync SaveReceivedMessage(nsString aSender, nsString aBody, uint64_t aDate)
+    sync SaveReceivedMessage(nsString aSender, nsString aBody, nsString aMessageClass, uint64_t aDate)
         returns (int32_t aId);
 
     sync SaveSentMessage(nsString aReceiver, nsString aBody, uint64_t aDate)
         returns (int32_t aId);
 
     SetMessageDeliveryStatus(int32_t aMessageId, nsString aDeliveryStatus);
 
     GetMessage(int32_t aMessageId, int32_t aRequestId, uint64_t aProcessId);
--- a/dom/sms/src/ipc/SmsIPCService.cpp
+++ b/dom/sms/src/ipc/SmsIPCService.cpp
@@ -60,37 +60,40 @@ SmsIPCService::Send(const nsAString& aNu
 
 NS_IMETHODIMP
 SmsIPCService::CreateSmsMessage(int32_t aId,
                                 const nsAString& aDelivery,
                                 const nsAString& aDeliveryStatus,
                                 const nsAString& aSender,
                                 const nsAString& aReceiver,
                                 const nsAString& aBody,
+                                const nsAString& aMessageClass,
                                 const jsval& aTimestamp,
                                 const bool aRead,
                                 JSContext* aCx,
                                 nsIDOMMozSmsMessage** aMessage)
 {
   return SmsMessage::Create(aId, aDelivery, aDeliveryStatus,
                             aSender, aReceiver,
-                            aBody, aTimestamp, aRead,
+                            aBody, aMessageClass, aTimestamp, aRead,
                             aCx, aMessage);
 }
 
 /*
  * Implementation of nsISmsDatabaseService.
  */
 NS_IMETHODIMP
 SmsIPCService::SaveReceivedMessage(const nsAString& aSender,
                                    const nsAString& aBody,
-                                   uint64_t aDate, int32_t* aId)
+                                   const nsAString& aMessageClass,
+                                   uint64_t aDate,
+                                   int32_t* aId)
 {
   GetSmsChild()->SendSaveReceivedMessage(nsString(aSender), nsString(aBody),
-                                         aDate, aId);
+                                         nsString(aMessageClass), aDate, aId);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SmsIPCService::SaveSentMessage(const nsAString& aReceiver,
                                const nsAString& aBody,
                                uint64_t aDate, int32_t* aId)
--- a/dom/sms/src/ipc/SmsParent.cpp
+++ b/dom/sms/src/ipc/SmsParent.cpp
@@ -157,25 +157,27 @@ SmsParent::RecvSendMessage(const nsStrin
 
   smsService->Send(aNumber, aMessage, aRequestId, aProcessId);
   return true;
 }
 
 bool
 SmsParent::RecvSaveReceivedMessage(const nsString& aSender,
                                    const nsString& aBody,
-                                   const uint64_t& aDate, int32_t* aId)
+                                   const nsString& aMessageClass,
+                                   const uint64_t& aDate,
+                                   int32_t* aId)
 {
   *aId = -1;
 
   nsCOMPtr<nsISmsDatabaseService> smsDBService =
     do_GetService(SMS_DATABASE_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(smsDBService, true);
 
-  smsDBService->SaveReceivedMessage(aSender, aBody, aDate, aId);
+  smsDBService->SaveReceivedMessage(aSender, aBody, aMessageClass, aDate, aId);
   return true;
 }
 
 bool
 SmsParent::RecvSaveSentMessage(const nsString& aRecipient,
                                const nsString& aBody,
                                const uint64_t& aDate, int32_t* aId)
 {
--- a/dom/sms/src/ipc/SmsParent.h
+++ b/dom/sms/src/ipc/SmsParent.h
@@ -22,17 +22,17 @@ public:
 
   static void GetAll(nsTArray<SmsParent*>& aArray);
 
   SmsParent();
 
   virtual bool RecvHasSupport(bool* aHasSupport) MOZ_OVERRIDE;
   virtual bool RecvGetNumberOfMessagesForText(const nsString& aText, uint16_t* aResult) MOZ_OVERRIDE;
   virtual bool RecvSendMessage(const nsString& aNumber, const nsString& aMessage, const int32_t& aRequestId, const uint64_t& aProcessId) MOZ_OVERRIDE;
-  virtual bool RecvSaveReceivedMessage(const nsString& aSender, const nsString& aBody, const uint64_t& aDate, int32_t* aId) MOZ_OVERRIDE;
+  virtual bool RecvSaveReceivedMessage(const nsString& aSender, const nsString& aBody, const nsString& aMessageClass, const uint64_t& aDate, int32_t* aId) MOZ_OVERRIDE;
   virtual bool RecvSaveSentMessage(const nsString& aRecipient, const nsString& aBody, const uint64_t& aDate, int32_t* aId) MOZ_OVERRIDE;
   virtual bool RecvSetMessageDeliveryStatus(const int32_t& aMessageId, const nsString& aDeliveryStatus) MOZ_OVERRIDE;
   virtual bool RecvGetMessage(const int32_t& aMessageId, const int32_t& aRequestId, const uint64_t& aProcessId) MOZ_OVERRIDE;
   virtual bool RecvDeleteMessage(const int32_t& aMessageId, const int32_t& aRequestId, const uint64_t& aProcessId) MOZ_OVERRIDE;
   virtual bool RecvCreateMessageList(const SmsFilterData& aFilter, const bool& aReverse, const int32_t& aRequestId, const uint64_t& aProcessId) MOZ_OVERRIDE;
   virtual bool RecvGetNextMessageInList(const int32_t& aListId, const int32_t& aRequestId, const uint64_t& aProcessId) MOZ_OVERRIDE;
   virtual bool RecvClearMessageList(const int32_t& aListId) MOZ_OVERRIDE;
   virtual bool RecvMarkMessageRead(const int32_t& aMessageId, const bool& aValue, const int32_t& aRequestId, const uint64_t& aProcessId) MOZ_OVERRIDE;
--- a/dom/sms/src/ril/SmsService.cpp
+++ b/dom/sms/src/ril/SmsService.cpp
@@ -63,22 +63,23 @@ SmsService::Send(const nsAString& aNumbe
 
 NS_IMETHODIMP
 SmsService::CreateSmsMessage(int32_t aId,
                              const nsAString& aDelivery,
                              const nsAString& aDeliveryStatus,
                              const nsAString& aSender,
                              const nsAString& aReceiver,
                              const nsAString& aBody,
+                             const nsAString& aMessageClass,
                              const jsval& aTimestamp,
                              const bool aRead,
                              JSContext* aCx,
                              nsIDOMMozSmsMessage** aMessage)
 {
   return SmsMessage::Create(aId, aDelivery, aDeliveryStatus,
                             aSender, aReceiver,
-                            aBody, aTimestamp, aRead,
+                            aBody, aMessageClass, aTimestamp, aRead,
                             aCx, aMessage);
 }
 
 } // namespace sms
 } // namespace dom
 } // namespace mozilla