Bug 867227 - Part 2: Add expiry date into nsIDOMMozMmsMessage. r=vyang, a=leo+
authorChia-hung Tai <ctai@mozilla.com>
Mon, 06 May 2013 18:34:15 +0800
changeset 119262 57c0cda90f179d900a674dca87f388c6abf83881
parent 119261 19435cc447c9a99238ee782a2effc6280b61bfd1
child 119263 77f3d0607412379dbf0efcac4afe4001793b9db7
push id759
push uservyang@mozilla.com
push dateMon, 06 May 2013 10:34:51 +0000
reviewersvyang, leo
bugs867227
milestone18.0
Bug 867227 - Part 2: Add expiry date into nsIDOMMozMmsMessage. r=vyang, a=leo+
dom/mobilemessage/src/MmsMessage.cpp
dom/mobilemessage/src/MmsMessage.h
dom/mobilemessage/src/MobileMessageService.cpp
dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
--- a/dom/mobilemessage/src/MmsMessage.cpp
+++ b/dom/mobilemessage/src/MmsMessage.cpp
@@ -36,41 +36,44 @@ MmsMessage::MmsMessage(int32_t          
                        DeliveryState                   aDelivery,
                        const nsTArray<DeliveryStatus>& aDeliveryStatus,
                        const nsAString&                aSender,
                        const nsTArray<nsString>&       aReceivers,
                        uint64_t                        aTimestamp,
                        bool                            aRead,
                        const nsAString&                aSubject,
                        const nsAString&                aSmil,
-                       const nsTArray<MmsAttachment>&  aAttachments)
+                       const nsTArray<MmsAttachment>&  aAttachments,
+                       uint64_t                        aExpiryDate)
   : mId(aId),
     mThreadId(aThreadId),
     mDelivery(aDelivery),
     mDeliveryStatus(aDeliveryStatus),
     mSender(aSender),
     mReceivers(aReceivers),
     mTimestamp(aTimestamp),
     mRead(aRead),
     mSubject(aSubject),
     mSmil(aSmil),
-    mAttachments(aAttachments)
+    mAttachments(aAttachments),
+    mExpiryDate(aExpiryDate)
 {
 }
 
 MmsMessage::MmsMessage(const mobilemessage::MmsMessageData& aData)
   : mId(aData.id())
   , mDelivery(aData.delivery())
   , mDeliveryStatus(aData.deliveryStatus())
   , mSender(aData.sender())
   , mReceivers(aData.receivers())
   , mTimestamp(aData.timestamp())
   , mRead(aData.read())
   , mSubject(aData.subject())
   , mSmil(aData.smil())
+  , mExpiryDate(aData.expiryDate())
 {
   uint32_t len = aData.attachments().Length();
   mAttachments.SetCapacity(len);
   for (uint32_t i = 0; i < len; i++) {
     MmsAttachment att;
     const MmsAttachmentData &element = aData.attachments()[i];
     att.id = element.id();
     att.location = element.location();
@@ -92,16 +95,17 @@ MmsMessage::Create(int32_t              
                    const JS::Value&      aDeliveryStatus,
                    const nsAString&      aSender,
                    const JS::Value&      aReceivers,
                    const JS::Value&      aTimestamp,
                    bool                  aRead,
                    const nsAString&      aSubject,
                    const nsAString&      aSmil,
                    const JS::Value&      aAttachments,
+                   const JS::Value&      aExpiryDate,
                    JSContext*            aCx,
                    nsIDOMMozMmsMessage** aMessage)
 {
   *aMessage = nullptr;
 
   // Set |delivery|.
   DeliveryState delivery;
   if (aDelivery.Equals(DELIVERY_SENT)) {
@@ -220,27 +224,47 @@ MmsMessage::Create(int32_t              
 
     MmsAttachment attachment;
     nsresult rv = attachment.Init(aCx, &attachmentJsVal);
     NS_ENSURE_SUCCESS(rv, rv);
 
     attachments.AppendElement(attachment);
   }
 
+  // Set |expiryDate|.
+  uint64_t expiryDate;
+  if (aExpiryDate.isObject()) {
+    JSObject* expiryDateObj = &aExpiryDate.toObject();
+    if (!JS_ObjectIsDate(aCx, expiryDateObj)) {
+      return NS_ERROR_INVALID_ARG;
+    }
+    expiryDate = js_DateGetMsecSinceEpoch(expiryDateObj);
+  } else {
+    if (!aExpiryDate.isNumber()) {
+      return NS_ERROR_INVALID_ARG;
+    }
+    double number = aExpiryDate.toNumber();
+    if (static_cast<uint64_t>(number) != number) {
+      return NS_ERROR_INVALID_ARG;
+    }
+    expiryDate = static_cast<uint64_t>(number);
+  }
+
   nsCOMPtr<nsIDOMMozMmsMessage> message = new MmsMessage(aId,
                                                          aThreadId,
                                                          delivery,
                                                          deliveryStatus,
                                                          aSender,
                                                          receivers,
                                                          timestamp,
                                                          aRead,
                                                          aSubject,
                                                          aSmil,
-                                                         attachments);
+                                                         attachments,
+                                                         expiryDate);
   message.forget(aMessage);
   return NS_OK;
 }
 
 bool
 MmsMessage::GetData(ContentParent* aParent,
                     mobilemessage::MmsMessageData& aData)
 {
@@ -248,16 +272,17 @@ MmsMessage::GetData(ContentParent* aPare
 
   aData.id() = mId;
   aData.delivery() = mDelivery;
   aData.sender().Assign(mSender);
   aData.timestamp() = mTimestamp;
   aData.read() = mRead;
   aData.subject() = mSubject;
   aData.smil() = mSmil;
+  aData.expiryDate() = mExpiryDate;
 
   // Bug 819791 is not uplifted in b2g18 branch.
   aData.deliveryStatus().SetCapacity(mDeliveryStatus.Length());
   for (uint32_t i = 0; i < mDeliveryStatus.Length(); i++) {
     aData.deliveryStatus().AppendElement(mDeliveryStatus[i]);
   }
 
   // Bug 819791 is not uplifted in b2g18 branch.
@@ -490,10 +515,20 @@ MmsMessage::GetAttachments(JSContext* aC
       return NS_ERROR_FAILURE;
     }
   }
 
   aAttachments->setObject(*attachments);
   return NS_OK;
 }
 
+NS_IMETHODIMP
+MmsMessage::GetExpiryDate(JSContext* cx, JS::Value* aDate)
+{
+  JSObject *obj = JS_NewDateObjectMsec(cx, mExpiryDate);
+  NS_ENSURE_TRUE(obj, NS_ERROR_FAILURE);
+
+  *aDate = OBJECT_TO_JSVAL(obj);
+  return NS_OK;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/mobilemessage/src/MmsMessage.h
+++ b/dom/mobilemessage/src/MmsMessage.h
@@ -33,31 +33,33 @@ public:
              mobilemessage::DeliveryState                   aDelivery,
              const nsTArray<mobilemessage::DeliveryStatus>& aDeliveryStatus,
              const nsAString&                               aSender,
              const nsTArray<nsString>&                      aReceivers,
              uint64_t                                       aTimestamp,
              bool                                           aRead,
              const nsAString&                               aSubject,
              const nsAString&                               aSmil,
-             const nsTArray<MmsAttachment>&                 aAttachments);
+             const nsTArray<MmsAttachment>&                 aAttachments,
+             uint64_t                                       aExpiryDate);
 
   MmsMessage(const mobilemessage::MmsMessageData& aData);
 
   static nsresult Create(int32_t               aId,
                          const uint64_t        aThreadId,
                          const nsAString&      aDelivery,
                          const JS::Value&      aDeliveryStatus,
                          const nsAString&      aSender,
                          const JS::Value&      aReceivers,
                          const JS::Value&      aTimestamp,
                          bool                  aRead,
                          const nsAString&      aSubject,
                          const nsAString&      aSmil,
                          const JS::Value&      aAttachments,
+                         const JS::Value&      aExpiryDate,
                          JSContext*            aCx,
                          nsIDOMMozMmsMessage** aMessage);
 
   bool GetData(ContentParent* aParent,
                mobilemessage::MmsMessageData& aData);
 
 private:
 
@@ -67,14 +69,15 @@ private:
   nsTArray<mobilemessage::DeliveryStatus> mDeliveryStatus;
   nsString                                mSender;
   nsTArray<nsString>                      mReceivers;
   uint64_t                                mTimestamp;
   bool                                    mRead;
   nsString                                mSubject;
   nsString                                mSmil;
   nsTArray<MmsAttachment>                 mAttachments;
+  uint64_t                                mExpiryDate;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_mobilemessage_MmsMessage_h
--- a/dom/mobilemessage/src/MobileMessageService.cpp
+++ b/dom/mobilemessage/src/MobileMessageService.cpp
@@ -64,30 +64,32 @@ MobileMessageService::CreateMmsMessage(i
                                        const JS::Value&      aDeliveryStatus,
                                        const nsAString&      aSender,
                                        const JS::Value&      aReceivers,
                                        const JS::Value&      aTimestamp,
                                        bool                  aRead,
                                        const nsAString&      aSubject,
                                        const nsAString&      aSmil,
                                        const JS::Value&      aAttachments,
+                                       const JS::Value&      aExpiryDate,
                                        JSContext*            aCx,
                                        nsIDOMMozMmsMessage** aMessage)
 {
   return MmsMessage::Create(aId,
                             aThreadId,
                             aDelivery,
                             aDeliveryStatus,
                             aSender,
                             aReceivers,
                             aTimestamp,
                             aRead,
                             aSubject,
                             aSmil,
                             aAttachments,
+                            aExpiryDate,
                             aCx,
                             aMessage);
 }
 
 NS_IMETHODIMP
 MobileMessageService::CreateSmsSegmentInfo(int32_t aSegments,
                                            int32_t aCharsPerSegment,
                                            int32_t aCharsAvailableInLastSegment,
--- a/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
+++ b/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
@@ -664,27 +664,29 @@ MobileMessageDatabaseService.prototype =
           }
           attachments.push({
             "id": partHeaders["content-id"],
             "location": partHeaders["content-location"],
             "content": partContent
           });
         }
       }
+      let expiryDate = aMessageRecord.timestamp + headers["x-mms-expiry"] * 1000;
       return gMobileMessageService.createMmsMessage(aMessageRecord.id,
                                                     aMessageRecord.threadId,
                                                     aMessageRecord.delivery,
                                                     aMessageRecord.deliveryStatus,
                                                     aMessageRecord.sender,
                                                     aMessageRecord.receivers,
                                                     aMessageRecord.timestamp,
                                                     aMessageRecord.read,
                                                     subject,
                                                     smil,
-                                                    attachments);
+                                                    attachments,
+                                                    expiryDate);
     }
   },
 
   findParticipantRecordByAddress: function findParticipantRecordByAddress(
       aParticipantStore, aAddress, aCreate, aCallback) {
     if (DEBUG) {
       debug("findParticipantRecordByAddress("
             + JSON.stringify(aAddress) + ", " + aCreate + ")");