2013-03-08 23:21:55 -08:00
|
|
|
/* -*- 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 "MmsMessage.h"
|
|
|
|
#include "nsIDOMClassInfo.h"
|
|
|
|
#include "jsapi.h" // For OBJECT_TO_JSVAL and JS_NewDateObjectMsec
|
|
|
|
#include "jsfriendapi.h" // For js_DateGetMsecSinceEpoch
|
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIDOMFile.h"
|
|
|
|
#include "nsTArrayHelpers.h"
|
2013-04-10 05:18:41 -07:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2013-09-11 20:17:24 -07:00
|
|
|
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
|
2013-04-10 05:18:41 -07:00
|
|
|
#include "mozilla/dom/mobilemessage/SmsTypes.h"
|
2013-05-27 21:24:11 -07:00
|
|
|
#include "nsDOMFile.h"
|
2013-11-05 18:30:25 -08:00
|
|
|
#include "nsCxPusher.h"
|
2013-11-26 20:46:24 -08:00
|
|
|
#include "MessageUtils.h"
|
2013-03-08 23:21:55 -08:00
|
|
|
|
|
|
|
using namespace mozilla::idl;
|
|
|
|
using namespace mozilla::dom::mobilemessage;
|
|
|
|
|
|
|
|
DOMCI_DATA(MozMmsMessage, mozilla::dom::MmsMessage)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(MmsMessage)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozMmsMessage)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozMmsMessage)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(MmsMessage)
|
|
|
|
NS_IMPL_RELEASE(MmsMessage)
|
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
MmsMessage::MmsMessage(int32_t aId,
|
2013-11-02 03:17:16 -07:00
|
|
|
uint64_t aThreadId,
|
|
|
|
const nsAString& aIccId,
|
2013-10-22 01:57:25 -07:00
|
|
|
DeliveryState aDelivery,
|
|
|
|
const nsTArray<MmsDeliveryInfo>& aDeliveryInfo,
|
|
|
|
const nsAString& aSender,
|
|
|
|
const nsTArray<nsString>& aReceivers,
|
|
|
|
uint64_t aTimestamp,
|
2013-09-22 19:31:32 -07:00
|
|
|
uint64_t aSentTimestamp,
|
2013-10-22 01:57:25 -07:00
|
|
|
bool aRead,
|
|
|
|
const nsAString& aSubject,
|
|
|
|
const nsAString& aSmil,
|
|
|
|
const nsTArray<MmsAttachment>& aAttachments,
|
2013-11-03 19:36:00 -08:00
|
|
|
uint64_t aExpiryDate,
|
2013-11-21 23:12:07 -08:00
|
|
|
bool aReadReportRequested)
|
2013-03-08 23:21:55 -08:00
|
|
|
: mId(aId),
|
2013-04-05 05:15:52 -07:00
|
|
|
mThreadId(aThreadId),
|
2013-11-02 03:17:16 -07:00
|
|
|
mIccId(aIccId),
|
2013-03-20 03:24:48 -07:00
|
|
|
mDelivery(aDelivery),
|
2013-10-22 01:57:25 -07:00
|
|
|
mDeliveryInfo(aDeliveryInfo),
|
2013-03-08 23:21:55 -08:00
|
|
|
mSender(aSender),
|
|
|
|
mReceivers(aReceivers),
|
|
|
|
mTimestamp(aTimestamp),
|
2013-09-22 19:31:32 -07:00
|
|
|
mSentTimestamp(aSentTimestamp),
|
2013-03-08 23:21:55 -08:00
|
|
|
mRead(aRead),
|
|
|
|
mSubject(aSubject),
|
|
|
|
mSmil(aSmil),
|
2013-05-01 09:22:52 -07:00
|
|
|
mAttachments(aAttachments),
|
2013-11-03 19:36:00 -08:00
|
|
|
mExpiryDate(aExpiryDate),
|
2013-11-21 23:12:07 -08:00
|
|
|
mReadReportRequested(aReadReportRequested)
|
2013-03-08 23:21:55 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-10 05:18:41 -07:00
|
|
|
MmsMessage::MmsMessage(const mobilemessage::MmsMessageData& aData)
|
|
|
|
: mId(aData.id())
|
2013-05-14 21:42:27 -07:00
|
|
|
, mThreadId(aData.threadId())
|
2013-11-02 03:17:16 -07:00
|
|
|
, mIccId(aData.iccId())
|
2013-04-10 05:18:41 -07:00
|
|
|
, mDelivery(aData.delivery())
|
|
|
|
, mSender(aData.sender())
|
|
|
|
, mReceivers(aData.receivers())
|
|
|
|
, mTimestamp(aData.timestamp())
|
2013-09-22 19:31:32 -07:00
|
|
|
, mSentTimestamp(aData.sentTimestamp())
|
2013-04-10 05:18:41 -07:00
|
|
|
, mRead(aData.read())
|
|
|
|
, mSubject(aData.subject())
|
|
|
|
, mSmil(aData.smil())
|
2013-05-01 09:22:52 -07:00
|
|
|
, mExpiryDate(aData.expiryDate())
|
2013-11-21 23:12:07 -08:00
|
|
|
, mReadReportRequested(aData.readReportRequested())
|
2013-04-10 05:18:41 -07:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
if (element.contentParent()) {
|
|
|
|
att.content = static_cast<BlobParent*>(element.contentParent())->GetBlob();
|
|
|
|
} else if (element.contentChild()) {
|
|
|
|
att.content = static_cast<BlobChild*>(element.contentChild())->GetBlob();
|
|
|
|
} else {
|
|
|
|
NS_WARNING("MmsMessage: Unable to get attachment content.");
|
|
|
|
}
|
|
|
|
mAttachments.AppendElement(att);
|
|
|
|
}
|
2013-10-22 01:57:25 -07:00
|
|
|
|
|
|
|
len = aData.deliveryInfo().Length();
|
|
|
|
mDeliveryInfo.SetCapacity(len);
|
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
|
|
|
MmsDeliveryInfo info;
|
|
|
|
const MmsDeliveryInfoData &infoData = aData.deliveryInfo()[i];
|
2013-11-05 18:30:25 -08:00
|
|
|
|
|
|
|
// Prepare |info.receiver|.
|
2013-10-22 01:57:25 -07:00
|
|
|
info.receiver = infoData.receiver();
|
|
|
|
|
2013-11-05 18:30:25 -08:00
|
|
|
// Prepare |info.deliveryStatus|.
|
2013-10-22 01:57:25 -07:00
|
|
|
nsString statusStr;
|
|
|
|
switch (infoData.deliveryStatus()) {
|
|
|
|
case eDeliveryStatus_NotApplicable:
|
|
|
|
statusStr = DELIVERY_STATUS_NOT_APPLICABLE;
|
|
|
|
break;
|
|
|
|
case eDeliveryStatus_Success:
|
|
|
|
statusStr = DELIVERY_STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
case eDeliveryStatus_Pending:
|
|
|
|
statusStr = DELIVERY_STATUS_PENDING;
|
|
|
|
break;
|
|
|
|
case eDeliveryStatus_Error:
|
|
|
|
statusStr = DELIVERY_STATUS_ERROR;
|
|
|
|
break;
|
|
|
|
case eDeliveryStatus_Reject:
|
|
|
|
statusStr = DELIVERY_STATUS_REJECTED;
|
|
|
|
break;
|
|
|
|
case eDeliveryStatus_Manual:
|
|
|
|
statusStr = DELIVERY_STATUS_MANUAL;
|
|
|
|
break;
|
|
|
|
case eDeliveryStatus_EndGuard:
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("We shouldn't get any other delivery status!");
|
|
|
|
}
|
|
|
|
info.deliveryStatus = statusStr;
|
2013-11-05 18:30:25 -08:00
|
|
|
|
|
|
|
// Prepare |info.deliveryTimestamp|.
|
2013-11-30 03:14:41 -08:00
|
|
|
info.deliveryTimestamp = infoData.deliveryTimestamp();
|
2013-11-05 18:30:25 -08:00
|
|
|
|
2013-11-25 02:54:59 -08:00
|
|
|
// Prepare |info.readStatus|.
|
|
|
|
nsString statusReadString;
|
|
|
|
switch(infoData.readStatus()) {
|
|
|
|
case eReadStatus_NotApplicable:
|
|
|
|
statusReadString = READ_STATUS_NOT_APPLICABLE;
|
|
|
|
break;
|
|
|
|
case eReadStatus_Success:
|
|
|
|
statusReadString = READ_STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
case eReadStatus_Pending:
|
|
|
|
statusReadString = READ_STATUS_PENDING;
|
|
|
|
break;
|
|
|
|
case eReadStatus_Error:
|
|
|
|
statusReadString = READ_STATUS_ERROR;
|
|
|
|
break;
|
|
|
|
case eReadStatus_EndGuard:
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("We shouldn't get any other read status!");
|
|
|
|
}
|
|
|
|
info.readStatus = statusReadString;
|
|
|
|
|
|
|
|
// Prepare |info.readTimestamp|.
|
2013-11-30 03:14:41 -08:00
|
|
|
info.readTimestamp = infoData.readTimestamp();
|
2013-11-25 02:54:59 -08:00
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
mDeliveryInfo.AppendElement(info);
|
|
|
|
}
|
2013-04-10 05:18:41 -07:00
|
|
|
}
|
|
|
|
|
2013-03-08 23:21:55 -08:00
|
|
|
/* static */ nsresult
|
|
|
|
MmsMessage::Create(int32_t aId,
|
2013-11-02 03:17:16 -07:00
|
|
|
uint64_t aThreadId,
|
|
|
|
const nsAString& aIccId,
|
2013-03-20 03:24:48 -07:00
|
|
|
const nsAString& aDelivery,
|
2013-10-22 01:57:25 -07:00
|
|
|
const JS::Value& aDeliveryInfo,
|
2013-03-08 23:21:55 -08:00
|
|
|
const nsAString& aSender,
|
|
|
|
const JS::Value& aReceivers,
|
|
|
|
const JS::Value& aTimestamp,
|
2013-09-22 19:31:32 -07:00
|
|
|
const JS::Value& aSentTimestamp,
|
2013-03-08 23:21:55 -08:00
|
|
|
bool aRead,
|
|
|
|
const nsAString& aSubject,
|
|
|
|
const nsAString& aSmil,
|
|
|
|
const JS::Value& aAttachments,
|
2013-05-01 09:22:52 -07:00
|
|
|
const JS::Value& aExpiryDate,
|
2013-11-03 19:36:00 -08:00
|
|
|
bool aIsReadReportRequested,
|
2013-03-08 23:21:55 -08:00
|
|
|
JSContext* aCx,
|
|
|
|
nsIDOMMozMmsMessage** aMessage)
|
|
|
|
{
|
|
|
|
*aMessage = nullptr;
|
|
|
|
|
2013-03-20 03:24:48 -07:00
|
|
|
// Set |delivery|.
|
|
|
|
DeliveryState delivery;
|
|
|
|
if (aDelivery.Equals(DELIVERY_SENT)) {
|
|
|
|
delivery = eDeliveryState_Sent;
|
|
|
|
} else if (aDelivery.Equals(DELIVERY_RECEIVED)) {
|
|
|
|
delivery = eDeliveryState_Received;
|
|
|
|
} else if (aDelivery.Equals(DELIVERY_SENDING)) {
|
|
|
|
delivery = eDeliveryState_Sending;
|
|
|
|
} else if (aDelivery.Equals(DELIVERY_NOT_DOWNLOADED)) {
|
|
|
|
delivery = eDeliveryState_NotDownloaded;
|
|
|
|
} else if (aDelivery.Equals(DELIVERY_ERROR)) {
|
|
|
|
delivery = eDeliveryState_Error;
|
2013-03-08 23:21:55 -08:00
|
|
|
} else {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
// Set |deliveryInfo|.
|
|
|
|
if (!aDeliveryInfo.isObject()) {
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2013-10-22 01:57:25 -07:00
|
|
|
JS::Rooted<JSObject*> deliveryInfoObj(aCx, &aDeliveryInfo.toObject());
|
|
|
|
if (!JS_IsArrayObject(aCx, deliveryInfoObj)) {
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t length;
|
2013-10-22 01:57:25 -07:00
|
|
|
JS_ALWAYS_TRUE(JS_GetArrayLength(aCx, deliveryInfoObj, &length));
|
2013-03-08 23:21:55 -08:00
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
nsTArray<MmsDeliveryInfo> deliveryInfo;
|
|
|
|
JS::Rooted<JS::Value> infoJsVal(aCx);
|
2013-03-08 23:21:55 -08:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2013-10-22 01:57:25 -07:00
|
|
|
if (!JS_GetElement(aCx, deliveryInfoObj, i, &infoJsVal) ||
|
|
|
|
!infoJsVal.isObject()) {
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
MmsDeliveryInfo info;
|
|
|
|
nsresult rv = info.Init(aCx, infoJsVal.address());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-03-08 23:21:55 -08:00
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
deliveryInfo.AppendElement(info);
|
2013-03-08 23:21:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set |receivers|.
|
|
|
|
if (!aReceivers.isObject()) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2013-05-10 11:22:21 -07:00
|
|
|
JS::Rooted<JSObject*> receiversObj(aCx, &aReceivers.toObject());
|
2013-03-08 23:21:55 -08:00
|
|
|
if (!JS_IsArrayObject(aCx, receiversObj)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_TRUE(JS_GetArrayLength(aCx, receiversObj, &length));
|
|
|
|
|
|
|
|
nsTArray<nsString> receivers;
|
2013-05-10 11:22:21 -07:00
|
|
|
JS::Rooted<JS::Value> receiverJsVal(aCx);
|
2013-03-08 23:21:55 -08:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2013-08-05 06:02:47 -07:00
|
|
|
if (!JS_GetElement(aCx, receiversObj, i, &receiverJsVal) ||
|
2013-03-08 23:21:55 -08:00
|
|
|
!receiverJsVal.isString()) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentJSString receiverStr;
|
|
|
|
receiverStr.init(aCx, receiverJsVal.toString());
|
|
|
|
receivers.AppendElement(receiverStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set |timestamp|.
|
|
|
|
uint64_t timestamp;
|
2013-05-08 03:41:00 -07:00
|
|
|
nsresult rv = convertTimeToInt(aCx, aTimestamp, timestamp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-03-08 23:21:55 -08:00
|
|
|
|
2013-09-22 19:31:32 -07:00
|
|
|
// Set |sentTimestamp|.
|
|
|
|
uint64_t sentTimestamp;
|
|
|
|
rv = convertTimeToInt(aCx, aSentTimestamp, sentTimestamp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-03-08 23:21:55 -08:00
|
|
|
// Set |attachments|.
|
|
|
|
if (!aAttachments.isObject()) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2013-05-10 11:22:21 -07:00
|
|
|
JS::Rooted<JSObject*> attachmentsObj(aCx, &aAttachments.toObject());
|
2013-03-08 23:21:55 -08:00
|
|
|
if (!JS_IsArrayObject(aCx, attachmentsObj)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<MmsAttachment> attachments;
|
|
|
|
JS_ALWAYS_TRUE(JS_GetArrayLength(aCx, attachmentsObj, &length));
|
|
|
|
|
2013-05-10 11:22:21 -07:00
|
|
|
JS::Rooted<JS::Value> attachmentJsVal(aCx);
|
2013-03-08 23:21:55 -08:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2013-08-05 06:02:47 -07:00
|
|
|
if (!JS_GetElement(aCx, attachmentsObj, i, &attachmentJsVal)) {
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
MmsAttachment attachment;
|
2013-05-10 11:22:21 -07:00
|
|
|
rv = attachment.Init(aCx, attachmentJsVal.address());
|
2013-03-08 23:21:55 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
attachments.AppendElement(attachment);
|
|
|
|
}
|
|
|
|
|
2013-05-01 09:22:52 -07:00
|
|
|
// Set |expiryDate|.
|
|
|
|
uint64_t expiryDate;
|
2013-05-08 03:41:00 -07:00
|
|
|
rv = convertTimeToInt(aCx, aExpiryDate, expiryDate);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-05-01 09:22:52 -07:00
|
|
|
|
2013-03-08 23:21:55 -08:00
|
|
|
nsCOMPtr<nsIDOMMozMmsMessage> message = new MmsMessage(aId,
|
2013-04-05 05:15:52 -07:00
|
|
|
aThreadId,
|
2013-11-02 03:17:16 -07:00
|
|
|
aIccId,
|
2013-03-20 03:24:48 -07:00
|
|
|
delivery,
|
2013-10-22 01:57:25 -07:00
|
|
|
deliveryInfo,
|
2013-03-08 23:21:55 -08:00
|
|
|
aSender,
|
|
|
|
receivers,
|
|
|
|
timestamp,
|
2013-09-22 19:31:32 -07:00
|
|
|
sentTimestamp,
|
2013-03-08 23:21:55 -08:00
|
|
|
aRead,
|
|
|
|
aSubject,
|
|
|
|
aSmil,
|
2013-05-01 09:22:52 -07:00
|
|
|
attachments,
|
2013-11-03 19:36:00 -08:00
|
|
|
expiryDate,
|
|
|
|
aIsReadReportRequested);
|
2013-03-08 23:21:55 -08:00
|
|
|
message.forget(aMessage);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-10 05:18:41 -07:00
|
|
|
bool
|
|
|
|
MmsMessage::GetData(ContentParent* aParent,
|
|
|
|
mobilemessage::MmsMessageData& aData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aParent, "aParent is null");
|
|
|
|
|
|
|
|
aData.id() = mId;
|
2013-05-14 21:42:27 -07:00
|
|
|
aData.threadId() = mThreadId;
|
2013-11-02 03:17:16 -07:00
|
|
|
aData.iccId() = mIccId;
|
2013-04-10 05:18:41 -07:00
|
|
|
aData.delivery() = mDelivery;
|
|
|
|
aData.sender().Assign(mSender);
|
|
|
|
aData.receivers() = mReceivers;
|
|
|
|
aData.timestamp() = mTimestamp;
|
2013-09-22 19:31:32 -07:00
|
|
|
aData.sentTimestamp() = mSentTimestamp;
|
2013-04-10 05:18:41 -07:00
|
|
|
aData.read() = mRead;
|
|
|
|
aData.subject() = mSubject;
|
|
|
|
aData.smil() = mSmil;
|
2013-05-01 09:22:52 -07:00
|
|
|
aData.expiryDate() = mExpiryDate;
|
2013-11-21 23:12:07 -08:00
|
|
|
aData.readReportRequested() = mReadReportRequested;
|
2013-04-10 05:18:41 -07:00
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
aData.deliveryInfo().SetCapacity(mDeliveryInfo.Length());
|
|
|
|
for (uint32_t i = 0; i < mDeliveryInfo.Length(); i++) {
|
|
|
|
MmsDeliveryInfoData infoData;
|
|
|
|
const MmsDeliveryInfo &info = mDeliveryInfo[i];
|
2013-11-05 18:30:25 -08:00
|
|
|
|
|
|
|
// Prepare |infoData.receiver|.
|
2013-10-22 01:57:25 -07:00
|
|
|
infoData.receiver().Assign(info.receiver);
|
|
|
|
|
2013-11-05 18:30:25 -08:00
|
|
|
// Prepare |infoData.deliveryStatus|.
|
2013-10-22 01:57:25 -07:00
|
|
|
DeliveryStatus status;
|
|
|
|
if (info.deliveryStatus.Equals(DELIVERY_STATUS_NOT_APPLICABLE)) {
|
|
|
|
status = eDeliveryStatus_NotApplicable;
|
|
|
|
} else if (info.deliveryStatus.Equals(DELIVERY_STATUS_SUCCESS)) {
|
|
|
|
status = eDeliveryStatus_Success;
|
|
|
|
} else if (info.deliveryStatus.Equals(DELIVERY_STATUS_PENDING)) {
|
|
|
|
status = eDeliveryStatus_Pending;
|
|
|
|
} else if (info.deliveryStatus.Equals(DELIVERY_STATUS_ERROR)) {
|
|
|
|
status = eDeliveryStatus_Error;
|
|
|
|
} else if (info.deliveryStatus.Equals(DELIVERY_STATUS_REJECTED)) {
|
|
|
|
status = eDeliveryStatus_Reject;
|
|
|
|
} else if (info.deliveryStatus.Equals(DELIVERY_STATUS_MANUAL)) {
|
|
|
|
status = eDeliveryStatus_Manual;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
infoData.deliveryStatus() = status;
|
2013-11-05 18:30:25 -08:00
|
|
|
|
|
|
|
// Prepare |infoData.deliveryTimestamp|.
|
2013-11-30 03:14:41 -08:00
|
|
|
infoData.deliveryTimestamp() = info.deliveryTimestamp;
|
2013-11-05 18:30:25 -08:00
|
|
|
|
2013-11-25 02:54:59 -08:00
|
|
|
// Prepare |infoData.readStatus|.
|
|
|
|
ReadStatus readStatus;
|
|
|
|
if (info.readStatus.Equals(READ_STATUS_NOT_APPLICABLE)) {
|
|
|
|
readStatus = eReadStatus_NotApplicable;
|
|
|
|
} else if (info.readStatus.Equals(READ_STATUS_SUCCESS)) {
|
|
|
|
readStatus = eReadStatus_Success;
|
|
|
|
} else if (info.readStatus.Equals(READ_STATUS_PENDING)) {
|
|
|
|
readStatus = eReadStatus_Pending;
|
|
|
|
} else if (info.readStatus.Equals(READ_STATUS_ERROR)) {
|
|
|
|
readStatus = eReadStatus_Error;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
infoData.readStatus() = readStatus;
|
|
|
|
|
|
|
|
// Prepare |infoData.readTimestamp|.
|
2013-11-30 03:14:41 -08:00
|
|
|
infoData.readTimestamp() = info.readTimestamp;
|
2013-11-25 02:54:59 -08:00
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
aData.deliveryInfo().AppendElement(infoData);
|
|
|
|
}
|
|
|
|
|
2013-04-10 05:18:41 -07:00
|
|
|
aData.attachments().SetCapacity(mAttachments.Length());
|
|
|
|
for (uint32_t i = 0; i < mAttachments.Length(); i++) {
|
|
|
|
MmsAttachmentData mma;
|
|
|
|
const MmsAttachment &element = mAttachments[i];
|
|
|
|
mma.id().Assign(element.id);
|
|
|
|
mma.location().Assign(element.location);
|
2013-05-27 21:24:11 -07:00
|
|
|
|
|
|
|
// This is a workaround. Sometimes the blob we get from the database
|
|
|
|
// doesn't have a valid last modified date, making the ContentParent
|
|
|
|
// send a "Mystery Blob" to the ContentChild. Attempting to get the
|
|
|
|
// last modified date of blob can force that value to be initialized.
|
|
|
|
nsDOMFileBase* file = static_cast<nsDOMFileBase*>(element.content.get());
|
|
|
|
if (file->IsDateUnknown()) {
|
|
|
|
uint64_t date;
|
|
|
|
if (NS_FAILED(file->GetMozLastModifiedDate(&date))) {
|
|
|
|
NS_WARNING("Failed to get last modified date!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 05:18:41 -07:00
|
|
|
mma.contentParent() = aParent->GetOrCreateActorForBlob(element.content);
|
|
|
|
if (!mma.contentParent()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aData.attachments().AppendElement(mma);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-07 19:46:16 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MmsMessage::GetType(nsAString& aType)
|
|
|
|
{
|
|
|
|
aType = NS_LITERAL_STRING("mms");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-08 23:21:55 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MmsMessage::GetId(int32_t* aId)
|
|
|
|
{
|
|
|
|
*aId = mId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-05 05:15:52 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MmsMessage::GetThreadId(uint64_t* aThreadId)
|
|
|
|
{
|
|
|
|
*aThreadId = mThreadId;
|
|
|
|
return NS_OK;
|
2013-11-02 03:16:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MmsMessage::GetIccId(nsAString& aIccId)
|
|
|
|
{
|
2013-11-02 03:17:16 -07:00
|
|
|
aIccId = mIccId;
|
2013-11-02 03:16:59 -07:00
|
|
|
return NS_OK;
|
2013-04-05 05:15:52 -07:00
|
|
|
}
|
|
|
|
|
2013-03-08 23:21:55 -08:00
|
|
|
NS_IMETHODIMP
|
2013-03-20 03:24:48 -07:00
|
|
|
MmsMessage::GetDelivery(nsAString& aDelivery)
|
2013-03-08 23:21:55 -08:00
|
|
|
{
|
2013-03-20 03:24:48 -07:00
|
|
|
switch (mDelivery) {
|
2013-03-08 23:21:55 -08:00
|
|
|
case eDeliveryState_Received:
|
2013-03-20 03:24:48 -07:00
|
|
|
aDelivery = DELIVERY_RECEIVED;
|
2013-03-08 23:21:55 -08:00
|
|
|
break;
|
|
|
|
case eDeliveryState_Sending:
|
2013-03-20 03:24:48 -07:00
|
|
|
aDelivery = DELIVERY_SENDING;
|
2013-03-08 23:21:55 -08:00
|
|
|
break;
|
|
|
|
case eDeliveryState_Sent:
|
2013-03-20 03:24:48 -07:00
|
|
|
aDelivery = DELIVERY_SENT;
|
2013-03-08 23:21:55 -08:00
|
|
|
break;
|
|
|
|
case eDeliveryState_Error:
|
2013-03-20 03:24:48 -07:00
|
|
|
aDelivery = DELIVERY_ERROR;
|
2013-03-08 23:21:55 -08:00
|
|
|
break;
|
|
|
|
case eDeliveryState_NotDownloaded:
|
2013-03-20 03:24:48 -07:00
|
|
|
aDelivery = DELIVERY_NOT_DOWNLOADED;
|
2013-03-08 23:21:55 -08:00
|
|
|
break;
|
|
|
|
case eDeliveryState_Unknown:
|
|
|
|
case eDeliveryState_EndGuard:
|
|
|
|
default:
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("We shouldn't get any other delivery state!");
|
2013-03-08 23:21:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
MmsMessage::GetDeliveryInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aDeliveryInfo)
|
2013-03-08 23:21:55 -08:00
|
|
|
{
|
2013-03-20 03:24:48 -07:00
|
|
|
// TODO Bug 850525 It'd be better to depend on the delivery of MmsMessage
|
|
|
|
// to return a more correct value. Ex, if .delivery = 'received', we should
|
2013-10-22 01:57:25 -07:00
|
|
|
// also make .deliveryInfo = null, since the .deliveryInfo is useless.
|
|
|
|
uint32_t length = mDeliveryInfo.Length();
|
2013-03-08 23:21:55 -08:00
|
|
|
if (length == 0) {
|
2014-01-09 09:39:36 -08:00
|
|
|
aDeliveryInfo.setNull();
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
JS::Rooted<JSObject*> deliveryInfo(
|
|
|
|
aCx, JS_NewArrayObject(aCx, length, nullptr));
|
|
|
|
NS_ENSURE_TRUE(deliveryInfo, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2013-03-08 23:21:55 -08:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2013-10-22 01:57:25 -07:00
|
|
|
const MmsDeliveryInfo &info = mDeliveryInfo[i];
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> infoJsObj(
|
2014-01-16 09:48:58 -08:00
|
|
|
aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2013-10-22 01:57:25 -07:00
|
|
|
NS_ENSURE_TRUE(infoJsObj, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> tmpJsVal(aCx);
|
|
|
|
JSString* tmpJsStr;
|
|
|
|
|
|
|
|
// Get |info.receiver|.
|
|
|
|
tmpJsStr = JS_NewUCStringCopyN(aCx,
|
|
|
|
info.receiver.get(),
|
|
|
|
info.receiver.Length());
|
|
|
|
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
tmpJsVal.setString(tmpJsStr);
|
|
|
|
if (!JS_DefineProperty(aCx, infoJsObj, "receiver", tmpJsVal,
|
2013-11-11 11:17:14 -08:00
|
|
|
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
2013-10-22 01:57:25 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2013-03-08 23:21:55 -08:00
|
|
|
}
|
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
// Get |info.deliveryStatus|.
|
|
|
|
tmpJsStr = JS_NewUCStringCopyN(aCx,
|
|
|
|
info.deliveryStatus.get(),
|
|
|
|
info.deliveryStatus.Length());
|
|
|
|
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
tmpJsVal.setString(tmpJsStr);
|
|
|
|
if (!JS_DefineProperty(aCx, infoJsObj, "deliveryStatus", tmpJsVal,
|
2013-11-11 11:17:14 -08:00
|
|
|
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
2013-10-22 01:57:25 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:30:25 -08:00
|
|
|
// Get |info.deliveryTimestamp|.
|
2013-11-30 03:14:41 -08:00
|
|
|
tmpJsVal.setNumber(static_cast<double>(info.deliveryTimestamp));
|
|
|
|
if (!JS_DefineProperty(aCx, infoJsObj, "deliveryTimestamp", tmpJsVal,
|
2013-11-11 11:17:14 -08:00
|
|
|
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
2013-11-05 18:30:25 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-11-25 02:54:59 -08:00
|
|
|
// Get |info.readStatus|.
|
|
|
|
tmpJsStr = JS_NewUCStringCopyN(aCx,
|
|
|
|
info.readStatus.get(),
|
|
|
|
info.readStatus.Length());
|
|
|
|
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
tmpJsVal.setString(tmpJsStr);
|
|
|
|
if (!JS_DefineProperty(aCx, infoJsObj, "readStatus", tmpJsVal,
|
2013-11-30 03:14:41 -08:00
|
|
|
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
2013-11-25 02:54:59 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get |info.readTimestamp|.
|
2013-11-30 03:14:41 -08:00
|
|
|
tmpJsVal.setNumber(static_cast<double>(info.readTimestamp));
|
|
|
|
if (!JS_DefineProperty(aCx, infoJsObj, "readTimestamp", tmpJsVal,
|
|
|
|
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
2013-11-25 02:54:59 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
tmpJsVal = OBJECT_TO_JSVAL(infoJsObj);
|
|
|
|
if (!JS_SetElement(aCx, deliveryInfo, i, &tmpJsVal)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2013-03-08 23:21:55 -08:00
|
|
|
|
2014-01-09 09:39:36 -08:00
|
|
|
aDeliveryInfo.setObject(*deliveryInfo);
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MmsMessage::GetSender(nsAString& aSender)
|
|
|
|
{
|
|
|
|
aSender = mSender;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
MmsMessage::GetReceivers(JSContext* aCx, JS::MutableHandle<JS::Value> aReceivers)
|
2013-03-08 23:21:55 -08:00
|
|
|
{
|
2013-05-10 11:22:21 -07:00
|
|
|
JS::Rooted<JSObject*> reveiversObj(aCx);
|
|
|
|
nsresult rv = nsTArrayToJSArray(aCx, mReceivers, reveiversObj.address());
|
2013-03-08 23:21:55 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-01-09 09:39:36 -08:00
|
|
|
aReceivers.setObject(*reveiversObj);
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-11-30 03:14:41 -08:00
|
|
|
MmsMessage::GetTimestamp(DOMTimeStamp* aTimestamp)
|
2013-03-08 23:21:55 -08:00
|
|
|
{
|
2013-11-30 03:14:41 -08:00
|
|
|
*aTimestamp = mTimestamp;
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-22 19:31:12 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MmsMessage::GetSentTimestamp(DOMTimeStamp* aSentTimestamp)
|
|
|
|
{
|
2013-09-22 19:31:32 -07:00
|
|
|
*aSentTimestamp = mSentTimestamp;
|
|
|
|
return NS_OK;
|
2013-09-22 19:31:12 -07:00
|
|
|
}
|
|
|
|
|
2013-03-08 23:21:55 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MmsMessage::GetRead(bool* aRead)
|
|
|
|
{
|
|
|
|
*aRead = mRead;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MmsMessage::GetSubject(nsAString& aSubject)
|
|
|
|
{
|
|
|
|
aSubject = mSubject;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MmsMessage::GetSmil(nsAString& aSmil)
|
|
|
|
{
|
|
|
|
aSmil = mSmil;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
MmsMessage::GetAttachments(JSContext* aCx, JS::MutableHandle<JS::Value> aAttachments)
|
2013-03-08 23:21:55 -08:00
|
|
|
{
|
|
|
|
uint32_t length = mAttachments.Length();
|
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
JS::Rooted<JSObject*> attachments(
|
|
|
|
aCx, JS_NewArrayObject(aCx, length, nullptr));
|
2013-03-08 23:21:55 -08:00
|
|
|
NS_ENSURE_TRUE(attachments, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
const MmsAttachment &attachment = mAttachments[i];
|
|
|
|
|
2013-10-22 01:57:25 -07:00
|
|
|
JS::Rooted<JSObject*> attachmentObj(
|
2014-01-16 09:48:58 -08:00
|
|
|
aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2013-03-08 23:21:55 -08:00
|
|
|
NS_ENSURE_TRUE(attachmentObj, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2013-05-10 11:22:21 -07:00
|
|
|
JS::Rooted<JS::Value> tmpJsVal(aCx);
|
2013-03-08 23:21:55 -08:00
|
|
|
JSString* tmpJsStr;
|
|
|
|
|
|
|
|
// Get |attachment.mId|.
|
|
|
|
tmpJsStr = JS_NewUCStringCopyN(aCx,
|
|
|
|
attachment.id.get(),
|
|
|
|
attachment.id.Length());
|
|
|
|
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
tmpJsVal.setString(tmpJsStr);
|
|
|
|
if (!JS_DefineProperty(aCx, attachmentObj, "id", tmpJsVal,
|
2013-10-28 07:04:47 -07:00
|
|
|
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get |attachment.mLocation|.
|
|
|
|
tmpJsStr = JS_NewUCStringCopyN(aCx,
|
|
|
|
attachment.location.get(),
|
|
|
|
attachment.location.Length());
|
|
|
|
NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
tmpJsVal.setString(tmpJsStr);
|
|
|
|
if (!JS_DefineProperty(aCx, attachmentObj, "location", tmpJsVal,
|
2013-10-28 07:04:47 -07:00
|
|
|
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get |attachment.mContent|.
|
2013-07-29 16:45:27 -07:00
|
|
|
JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
|
2013-03-08 23:21:55 -08:00
|
|
|
nsresult rv = nsContentUtils::WrapNative(aCx,
|
2013-05-02 02:12:46 -07:00
|
|
|
global,
|
2013-03-08 23:21:55 -08:00
|
|
|
attachment.content,
|
|
|
|
&NS_GET_IID(nsIDOMBlob),
|
2013-10-11 22:02:39 -07:00
|
|
|
&tmpJsVal);
|
2013-03-08 23:21:55 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!JS_DefineProperty(aCx, attachmentObj, "content", tmpJsVal,
|
2013-10-28 07:04:47 -07:00
|
|
|
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpJsVal = OBJECT_TO_JSVAL(attachmentObj);
|
2013-08-05 06:02:47 -07:00
|
|
|
if (!JS_SetElement(aCx, attachments, i, &tmpJsVal)) {
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 09:39:36 -08:00
|
|
|
aAttachments.setObject(*attachments);
|
2013-03-08 23:21:55 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-01 09:22:52 -07:00
|
|
|
NS_IMETHODIMP
|
2013-11-30 03:14:41 -08:00
|
|
|
MmsMessage::GetExpiryDate(DOMTimeStamp* aExpiryDate)
|
2013-05-01 09:22:52 -07:00
|
|
|
{
|
2013-11-30 03:14:41 -08:00
|
|
|
*aExpiryDate = mExpiryDate;
|
2013-05-01 09:22:52 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-03 19:36:00 -08:00
|
|
|
NS_IMETHODIMP
|
2013-11-21 23:12:07 -08:00
|
|
|
MmsMessage::GetReadReportRequested(bool* aReadReportRequested)
|
2013-11-03 19:36:00 -08:00
|
|
|
{
|
2013-11-21 23:12:07 -08:00
|
|
|
*aReadReportRequested = mReadReportRequested;
|
2013-11-03 19:36:00 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 23:21:55 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|