dom/mobilemessage/src/MmsMessage.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "MmsMessage.h"
michael@0 7 #include "nsIDOMClassInfo.h"
michael@0 8 #include "jsapi.h" // For OBJECT_TO_JSVAL and JS_NewDateObjectMsec
michael@0 9 #include "jsfriendapi.h" // For js_DateGetMsecSinceEpoch
michael@0 10 #include "nsJSUtils.h"
michael@0 11 #include "nsContentUtils.h"
michael@0 12 #include "nsIDOMFile.h"
michael@0 13 #include "nsTArrayHelpers.h"
michael@0 14 #include "mozilla/dom/ContentParent.h"
michael@0 15 #include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
michael@0 16 #include "mozilla/dom/mobilemessage/SmsTypes.h"
michael@0 17 #include "mozilla/dom/ToJSValue.h"
michael@0 18 #include "nsDOMFile.h"
michael@0 19 #include "nsCxPusher.h"
michael@0 20
michael@0 21 using namespace mozilla::dom::mobilemessage;
michael@0 22
michael@0 23 DOMCI_DATA(MozMmsMessage, mozilla::dom::MmsMessage)
michael@0 24
michael@0 25 namespace mozilla {
michael@0 26 namespace dom {
michael@0 27
michael@0 28 NS_INTERFACE_MAP_BEGIN(MmsMessage)
michael@0 29 NS_INTERFACE_MAP_ENTRY(nsIDOMMozMmsMessage)
michael@0 30 NS_INTERFACE_MAP_ENTRY(nsISupports)
michael@0 31 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozMmsMessage)
michael@0 32 NS_INTERFACE_MAP_END
michael@0 33
michael@0 34 NS_IMPL_ADDREF(MmsMessage)
michael@0 35 NS_IMPL_RELEASE(MmsMessage)
michael@0 36
michael@0 37 MmsMessage::MmsMessage(int32_t aId,
michael@0 38 uint64_t aThreadId,
michael@0 39 const nsAString& aIccId,
michael@0 40 DeliveryState aDelivery,
michael@0 41 const nsTArray<MmsDeliveryInfo>& aDeliveryInfo,
michael@0 42 const nsAString& aSender,
michael@0 43 const nsTArray<nsString>& aReceivers,
michael@0 44 uint64_t aTimestamp,
michael@0 45 uint64_t aSentTimestamp,
michael@0 46 bool aRead,
michael@0 47 const nsAString& aSubject,
michael@0 48 const nsAString& aSmil,
michael@0 49 const nsTArray<Attachment>& aAttachments,
michael@0 50 uint64_t aExpiryDate,
michael@0 51 bool aReadReportRequested)
michael@0 52 : mId(aId),
michael@0 53 mThreadId(aThreadId),
michael@0 54 mIccId(aIccId),
michael@0 55 mDelivery(aDelivery),
michael@0 56 mDeliveryInfo(aDeliveryInfo),
michael@0 57 mSender(aSender),
michael@0 58 mReceivers(aReceivers),
michael@0 59 mTimestamp(aTimestamp),
michael@0 60 mSentTimestamp(aSentTimestamp),
michael@0 61 mRead(aRead),
michael@0 62 mSubject(aSubject),
michael@0 63 mSmil(aSmil),
michael@0 64 mAttachments(aAttachments),
michael@0 65 mExpiryDate(aExpiryDate),
michael@0 66 mReadReportRequested(aReadReportRequested)
michael@0 67 {
michael@0 68 }
michael@0 69
michael@0 70 MmsMessage::MmsMessage(const mobilemessage::MmsMessageData& aData)
michael@0 71 : mId(aData.id())
michael@0 72 , mThreadId(aData.threadId())
michael@0 73 , mIccId(aData.iccId())
michael@0 74 , mDelivery(aData.delivery())
michael@0 75 , mSender(aData.sender())
michael@0 76 , mReceivers(aData.receivers())
michael@0 77 , mTimestamp(aData.timestamp())
michael@0 78 , mSentTimestamp(aData.sentTimestamp())
michael@0 79 , mRead(aData.read())
michael@0 80 , mSubject(aData.subject())
michael@0 81 , mSmil(aData.smil())
michael@0 82 , mExpiryDate(aData.expiryDate())
michael@0 83 , mReadReportRequested(aData.readReportRequested())
michael@0 84 {
michael@0 85 uint32_t len = aData.attachments().Length();
michael@0 86 mAttachments.SetCapacity(len);
michael@0 87 for (uint32_t i = 0; i < len; i++) {
michael@0 88 MmsAttachment att;
michael@0 89 const MmsAttachmentData &element = aData.attachments()[i];
michael@0 90 att.mId = element.id();
michael@0 91 att.mLocation = element.location();
michael@0 92 if (element.contentParent()) {
michael@0 93 att.mContent = static_cast<BlobParent*>(element.contentParent())->GetBlob();
michael@0 94 } else if (element.contentChild()) {
michael@0 95 att.mContent = static_cast<BlobChild*>(element.contentChild())->GetBlob();
michael@0 96 } else {
michael@0 97 NS_WARNING("MmsMessage: Unable to get attachment content.");
michael@0 98 }
michael@0 99 mAttachments.AppendElement(att);
michael@0 100 }
michael@0 101
michael@0 102 len = aData.deliveryInfo().Length();
michael@0 103 mDeliveryInfo.SetCapacity(len);
michael@0 104 for (uint32_t i = 0; i < len; i++) {
michael@0 105 MmsDeliveryInfo info;
michael@0 106 const MmsDeliveryInfoData &infoData = aData.deliveryInfo()[i];
michael@0 107
michael@0 108 // Prepare |info.mReceiver|.
michael@0 109 info.mReceiver = infoData.receiver();
michael@0 110
michael@0 111 // Prepare |info.mDeliveryStatus|.
michael@0 112 nsString statusStr;
michael@0 113 switch (infoData.deliveryStatus()) {
michael@0 114 case eDeliveryStatus_NotApplicable:
michael@0 115 statusStr = DELIVERY_STATUS_NOT_APPLICABLE;
michael@0 116 break;
michael@0 117 case eDeliveryStatus_Success:
michael@0 118 statusStr = DELIVERY_STATUS_SUCCESS;
michael@0 119 break;
michael@0 120 case eDeliveryStatus_Pending:
michael@0 121 statusStr = DELIVERY_STATUS_PENDING;
michael@0 122 break;
michael@0 123 case eDeliveryStatus_Error:
michael@0 124 statusStr = DELIVERY_STATUS_ERROR;
michael@0 125 break;
michael@0 126 case eDeliveryStatus_Reject:
michael@0 127 statusStr = DELIVERY_STATUS_REJECTED;
michael@0 128 break;
michael@0 129 case eDeliveryStatus_Manual:
michael@0 130 statusStr = DELIVERY_STATUS_MANUAL;
michael@0 131 break;
michael@0 132 case eDeliveryStatus_EndGuard:
michael@0 133 default:
michael@0 134 MOZ_CRASH("We shouldn't get any other delivery status!");
michael@0 135 }
michael@0 136 info.mDeliveryStatus = statusStr;
michael@0 137
michael@0 138 // Prepare |info.mDeliveryTimestamp|.
michael@0 139 info.mDeliveryTimestamp = infoData.deliveryTimestamp();
michael@0 140
michael@0 141 // Prepare |info.mReadStatus|.
michael@0 142 nsString statusReadString;
michael@0 143 switch(infoData.readStatus()) {
michael@0 144 case eReadStatus_NotApplicable:
michael@0 145 statusReadString = READ_STATUS_NOT_APPLICABLE;
michael@0 146 break;
michael@0 147 case eReadStatus_Success:
michael@0 148 statusReadString = READ_STATUS_SUCCESS;
michael@0 149 break;
michael@0 150 case eReadStatus_Pending:
michael@0 151 statusReadString = READ_STATUS_PENDING;
michael@0 152 break;
michael@0 153 case eReadStatus_Error:
michael@0 154 statusReadString = READ_STATUS_ERROR;
michael@0 155 break;
michael@0 156 case eReadStatus_EndGuard:
michael@0 157 default:
michael@0 158 MOZ_CRASH("We shouldn't get any other read status!");
michael@0 159 }
michael@0 160 info.mReadStatus = statusReadString;
michael@0 161
michael@0 162 // Prepare |info.mReadTimestamp|.
michael@0 163 info.mReadTimestamp = infoData.readTimestamp();
michael@0 164
michael@0 165 mDeliveryInfo.AppendElement(info);
michael@0 166 }
michael@0 167 }
michael@0 168
michael@0 169 /* static */ nsresult
michael@0 170 MmsMessage::Create(int32_t aId,
michael@0 171 uint64_t aThreadId,
michael@0 172 const nsAString& aIccId,
michael@0 173 const nsAString& aDelivery,
michael@0 174 const JS::Value& aDeliveryInfo,
michael@0 175 const nsAString& aSender,
michael@0 176 const JS::Value& aReceivers,
michael@0 177 uint64_t aTimestamp,
michael@0 178 uint64_t aSentTimestamp,
michael@0 179 bool aRead,
michael@0 180 const nsAString& aSubject,
michael@0 181 const nsAString& aSmil,
michael@0 182 const JS::Value& aAttachments,
michael@0 183 uint64_t aExpiryDate,
michael@0 184 bool aIsReadReportRequested,
michael@0 185 JSContext* aCx,
michael@0 186 nsIDOMMozMmsMessage** aMessage)
michael@0 187 {
michael@0 188 *aMessage = nullptr;
michael@0 189
michael@0 190 // Set |delivery|.
michael@0 191 DeliveryState delivery;
michael@0 192 if (aDelivery.Equals(DELIVERY_SENT)) {
michael@0 193 delivery = eDeliveryState_Sent;
michael@0 194 } else if (aDelivery.Equals(DELIVERY_RECEIVED)) {
michael@0 195 delivery = eDeliveryState_Received;
michael@0 196 } else if (aDelivery.Equals(DELIVERY_SENDING)) {
michael@0 197 delivery = eDeliveryState_Sending;
michael@0 198 } else if (aDelivery.Equals(DELIVERY_NOT_DOWNLOADED)) {
michael@0 199 delivery = eDeliveryState_NotDownloaded;
michael@0 200 } else if (aDelivery.Equals(DELIVERY_ERROR)) {
michael@0 201 delivery = eDeliveryState_Error;
michael@0 202 } else {
michael@0 203 return NS_ERROR_INVALID_ARG;
michael@0 204 }
michael@0 205
michael@0 206 // Set |deliveryInfo|.
michael@0 207 if (!aDeliveryInfo.isObject()) {
michael@0 208 return NS_ERROR_INVALID_ARG;
michael@0 209 }
michael@0 210 JS::Rooted<JSObject*> deliveryInfoObj(aCx, &aDeliveryInfo.toObject());
michael@0 211 if (!JS_IsArrayObject(aCx, deliveryInfoObj)) {
michael@0 212 return NS_ERROR_INVALID_ARG;
michael@0 213 }
michael@0 214
michael@0 215 uint32_t length;
michael@0 216 MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, deliveryInfoObj, &length));
michael@0 217
michael@0 218 nsTArray<MmsDeliveryInfo> deliveryInfo;
michael@0 219 JS::Rooted<JS::Value> infoJsVal(aCx);
michael@0 220 for (uint32_t i = 0; i < length; ++i) {
michael@0 221 if (!JS_GetElement(aCx, deliveryInfoObj, i, &infoJsVal) ||
michael@0 222 !infoJsVal.isObject()) {
michael@0 223 return NS_ERROR_INVALID_ARG;
michael@0 224 }
michael@0 225
michael@0 226 MmsDeliveryInfo info;
michael@0 227 if (!info.Init(aCx, infoJsVal)) {
michael@0 228 return NS_ERROR_TYPE_ERR;
michael@0 229 }
michael@0 230
michael@0 231 deliveryInfo.AppendElement(info);
michael@0 232 }
michael@0 233
michael@0 234 // Set |receivers|.
michael@0 235 if (!aReceivers.isObject()) {
michael@0 236 return NS_ERROR_INVALID_ARG;
michael@0 237 }
michael@0 238 JS::Rooted<JSObject*> receiversObj(aCx, &aReceivers.toObject());
michael@0 239 if (!JS_IsArrayObject(aCx, receiversObj)) {
michael@0 240 return NS_ERROR_INVALID_ARG;
michael@0 241 }
michael@0 242
michael@0 243 MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, receiversObj, &length));
michael@0 244
michael@0 245 nsTArray<nsString> receivers;
michael@0 246 JS::Rooted<JS::Value> receiverJsVal(aCx);
michael@0 247 for (uint32_t i = 0; i < length; ++i) {
michael@0 248 if (!JS_GetElement(aCx, receiversObj, i, &receiverJsVal) ||
michael@0 249 !receiverJsVal.isString()) {
michael@0 250 return NS_ERROR_INVALID_ARG;
michael@0 251 }
michael@0 252
michael@0 253 nsDependentJSString receiverStr;
michael@0 254 receiverStr.init(aCx, receiverJsVal.toString());
michael@0 255 receivers.AppendElement(receiverStr);
michael@0 256 }
michael@0 257
michael@0 258 // Set |attachments|.
michael@0 259 if (!aAttachments.isObject()) {
michael@0 260 return NS_ERROR_INVALID_ARG;
michael@0 261 }
michael@0 262 JS::Rooted<JSObject*> attachmentsObj(aCx, &aAttachments.toObject());
michael@0 263 if (!JS_IsArrayObject(aCx, attachmentsObj)) {
michael@0 264 return NS_ERROR_INVALID_ARG;
michael@0 265 }
michael@0 266
michael@0 267 nsTArray<Attachment> attachments;
michael@0 268 MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, attachmentsObj, &length));
michael@0 269
michael@0 270 JS::Rooted<JS::Value> attachmentJsVal(aCx);
michael@0 271 for (uint32_t i = 0; i < length; ++i) {
michael@0 272 if (!JS_GetElement(aCx, attachmentsObj, i, &attachmentJsVal)) {
michael@0 273 return NS_ERROR_INVALID_ARG;
michael@0 274 }
michael@0 275
michael@0 276 MmsAttachment attachment;
michael@0 277 if (!attachment.Init(aCx, attachmentJsVal)) {
michael@0 278 return NS_ERROR_TYPE_ERR;
michael@0 279 }
michael@0 280
michael@0 281 attachments.AppendElement(attachment);
michael@0 282 }
michael@0 283
michael@0 284 nsCOMPtr<nsIDOMMozMmsMessage> message = new MmsMessage(aId,
michael@0 285 aThreadId,
michael@0 286 aIccId,
michael@0 287 delivery,
michael@0 288 deliveryInfo,
michael@0 289 aSender,
michael@0 290 receivers,
michael@0 291 aTimestamp,
michael@0 292 aSentTimestamp,
michael@0 293 aRead,
michael@0 294 aSubject,
michael@0 295 aSmil,
michael@0 296 attachments,
michael@0 297 aExpiryDate,
michael@0 298 aIsReadReportRequested);
michael@0 299 message.forget(aMessage);
michael@0 300 return NS_OK;
michael@0 301 }
michael@0 302
michael@0 303 bool
michael@0 304 MmsMessage::GetData(ContentParent* aParent,
michael@0 305 mobilemessage::MmsMessageData& aData)
michael@0 306 {
michael@0 307 NS_ASSERTION(aParent, "aParent is null");
michael@0 308
michael@0 309 aData.id() = mId;
michael@0 310 aData.threadId() = mThreadId;
michael@0 311 aData.iccId() = mIccId;
michael@0 312 aData.delivery() = mDelivery;
michael@0 313 aData.sender().Assign(mSender);
michael@0 314 aData.receivers() = mReceivers;
michael@0 315 aData.timestamp() = mTimestamp;
michael@0 316 aData.sentTimestamp() = mSentTimestamp;
michael@0 317 aData.read() = mRead;
michael@0 318 aData.subject() = mSubject;
michael@0 319 aData.smil() = mSmil;
michael@0 320 aData.expiryDate() = mExpiryDate;
michael@0 321 aData.readReportRequested() = mReadReportRequested;
michael@0 322
michael@0 323 aData.deliveryInfo().SetCapacity(mDeliveryInfo.Length());
michael@0 324 for (uint32_t i = 0; i < mDeliveryInfo.Length(); i++) {
michael@0 325 MmsDeliveryInfoData infoData;
michael@0 326 const MmsDeliveryInfo &info = mDeliveryInfo[i];
michael@0 327
michael@0 328 // Prepare |infoData.mReceiver|.
michael@0 329 infoData.receiver().Assign(info.mReceiver);
michael@0 330
michael@0 331 // Prepare |infoData.mDeliveryStatus|.
michael@0 332 DeliveryStatus status;
michael@0 333 if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_NOT_APPLICABLE)) {
michael@0 334 status = eDeliveryStatus_NotApplicable;
michael@0 335 } else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_SUCCESS)) {
michael@0 336 status = eDeliveryStatus_Success;
michael@0 337 } else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_PENDING)) {
michael@0 338 status = eDeliveryStatus_Pending;
michael@0 339 } else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_ERROR)) {
michael@0 340 status = eDeliveryStatus_Error;
michael@0 341 } else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_REJECTED)) {
michael@0 342 status = eDeliveryStatus_Reject;
michael@0 343 } else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_MANUAL)) {
michael@0 344 status = eDeliveryStatus_Manual;
michael@0 345 } else {
michael@0 346 return false;
michael@0 347 }
michael@0 348 infoData.deliveryStatus() = status;
michael@0 349
michael@0 350 // Prepare |infoData.mDeliveryTimestamp|.
michael@0 351 infoData.deliveryTimestamp() = info.mDeliveryTimestamp;
michael@0 352
michael@0 353 // Prepare |infoData.mReadStatus|.
michael@0 354 ReadStatus readStatus;
michael@0 355 if (info.mReadStatus.Equals(READ_STATUS_NOT_APPLICABLE)) {
michael@0 356 readStatus = eReadStatus_NotApplicable;
michael@0 357 } else if (info.mReadStatus.Equals(READ_STATUS_SUCCESS)) {
michael@0 358 readStatus = eReadStatus_Success;
michael@0 359 } else if (info.mReadStatus.Equals(READ_STATUS_PENDING)) {
michael@0 360 readStatus = eReadStatus_Pending;
michael@0 361 } else if (info.mReadStatus.Equals(READ_STATUS_ERROR)) {
michael@0 362 readStatus = eReadStatus_Error;
michael@0 363 } else {
michael@0 364 return false;
michael@0 365 }
michael@0 366 infoData.readStatus() = readStatus;
michael@0 367
michael@0 368 // Prepare |infoData.mReadTimestamp|.
michael@0 369 infoData.readTimestamp() = info.mReadTimestamp;
michael@0 370
michael@0 371 aData.deliveryInfo().AppendElement(infoData);
michael@0 372 }
michael@0 373
michael@0 374 aData.attachments().SetCapacity(mAttachments.Length());
michael@0 375 for (uint32_t i = 0; i < mAttachments.Length(); i++) {
michael@0 376 MmsAttachmentData mma;
michael@0 377 const Attachment &element = mAttachments[i];
michael@0 378 mma.id().Assign(element.id);
michael@0 379 mma.location().Assign(element.location);
michael@0 380
michael@0 381 // This is a workaround. Sometimes the blob we get from the database
michael@0 382 // doesn't have a valid last modified date, making the ContentParent
michael@0 383 // send a "Mystery Blob" to the ContentChild. Attempting to get the
michael@0 384 // last modified date of blob can force that value to be initialized.
michael@0 385 nsDOMFileBase* file = static_cast<nsDOMFileBase*>(element.content.get());
michael@0 386 if (file->IsDateUnknown()) {
michael@0 387 uint64_t date;
michael@0 388 if (NS_FAILED(file->GetMozLastModifiedDate(&date))) {
michael@0 389 NS_WARNING("Failed to get last modified date!");
michael@0 390 }
michael@0 391 }
michael@0 392
michael@0 393 mma.contentParent() = aParent->GetOrCreateActorForBlob(element.content);
michael@0 394 if (!mma.contentParent()) {
michael@0 395 return false;
michael@0 396 }
michael@0 397 aData.attachments().AppendElement(mma);
michael@0 398 }
michael@0 399
michael@0 400 return true;
michael@0 401 }
michael@0 402
michael@0 403 NS_IMETHODIMP
michael@0 404 MmsMessage::GetType(nsAString& aType)
michael@0 405 {
michael@0 406 aType = NS_LITERAL_STRING("mms");
michael@0 407 return NS_OK;
michael@0 408 }
michael@0 409
michael@0 410 NS_IMETHODIMP
michael@0 411 MmsMessage::GetId(int32_t* aId)
michael@0 412 {
michael@0 413 *aId = mId;
michael@0 414 return NS_OK;
michael@0 415 }
michael@0 416
michael@0 417 NS_IMETHODIMP
michael@0 418 MmsMessage::GetThreadId(uint64_t* aThreadId)
michael@0 419 {
michael@0 420 *aThreadId = mThreadId;
michael@0 421 return NS_OK;
michael@0 422 }
michael@0 423
michael@0 424 NS_IMETHODIMP
michael@0 425 MmsMessage::GetIccId(nsAString& aIccId)
michael@0 426 {
michael@0 427 aIccId = mIccId;
michael@0 428 return NS_OK;
michael@0 429 }
michael@0 430
michael@0 431 NS_IMETHODIMP
michael@0 432 MmsMessage::GetDelivery(nsAString& aDelivery)
michael@0 433 {
michael@0 434 switch (mDelivery) {
michael@0 435 case eDeliveryState_Received:
michael@0 436 aDelivery = DELIVERY_RECEIVED;
michael@0 437 break;
michael@0 438 case eDeliveryState_Sending:
michael@0 439 aDelivery = DELIVERY_SENDING;
michael@0 440 break;
michael@0 441 case eDeliveryState_Sent:
michael@0 442 aDelivery = DELIVERY_SENT;
michael@0 443 break;
michael@0 444 case eDeliveryState_Error:
michael@0 445 aDelivery = DELIVERY_ERROR;
michael@0 446 break;
michael@0 447 case eDeliveryState_NotDownloaded:
michael@0 448 aDelivery = DELIVERY_NOT_DOWNLOADED;
michael@0 449 break;
michael@0 450 case eDeliveryState_Unknown:
michael@0 451 case eDeliveryState_EndGuard:
michael@0 452 default:
michael@0 453 MOZ_CRASH("We shouldn't get any other delivery state!");
michael@0 454 }
michael@0 455
michael@0 456 return NS_OK;
michael@0 457 }
michael@0 458
michael@0 459 NS_IMETHODIMP
michael@0 460 MmsMessage::GetDeliveryInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aDeliveryInfo)
michael@0 461 {
michael@0 462 // TODO Bug 850525 It'd be better to depend on the delivery of MmsMessage
michael@0 463 // to return a more correct value. Ex, if .delivery = 'received', we should
michael@0 464 // also make .deliveryInfo = null, since the .deliveryInfo is useless.
michael@0 465 uint32_t length = mDeliveryInfo.Length();
michael@0 466 if (length == 0) {
michael@0 467 aDeliveryInfo.setNull();
michael@0 468 return NS_OK;
michael@0 469 }
michael@0 470
michael@0 471 if (!ToJSValue(aCx, mDeliveryInfo, aDeliveryInfo)) {
michael@0 472 return NS_ERROR_OUT_OF_MEMORY;
michael@0 473 }
michael@0 474
michael@0 475 return NS_OK;
michael@0 476 }
michael@0 477
michael@0 478 NS_IMETHODIMP
michael@0 479 MmsMessage::GetSender(nsAString& aSender)
michael@0 480 {
michael@0 481 aSender = mSender;
michael@0 482 return NS_OK;
michael@0 483 }
michael@0 484
michael@0 485 NS_IMETHODIMP
michael@0 486 MmsMessage::GetReceivers(JSContext* aCx, JS::MutableHandle<JS::Value> aReceivers)
michael@0 487 {
michael@0 488 JS::Rooted<JSObject*> reveiversObj(aCx);
michael@0 489 nsresult rv = nsTArrayToJSArray(aCx, mReceivers, reveiversObj.address());
michael@0 490 NS_ENSURE_SUCCESS(rv, rv);
michael@0 491
michael@0 492 aReceivers.setObject(*reveiversObj);
michael@0 493 return NS_OK;
michael@0 494 }
michael@0 495
michael@0 496 NS_IMETHODIMP
michael@0 497 MmsMessage::GetTimestamp(DOMTimeStamp* aTimestamp)
michael@0 498 {
michael@0 499 *aTimestamp = mTimestamp;
michael@0 500 return NS_OK;
michael@0 501 }
michael@0 502
michael@0 503 NS_IMETHODIMP
michael@0 504 MmsMessage::GetSentTimestamp(DOMTimeStamp* aSentTimestamp)
michael@0 505 {
michael@0 506 *aSentTimestamp = mSentTimestamp;
michael@0 507 return NS_OK;
michael@0 508 }
michael@0 509
michael@0 510 NS_IMETHODIMP
michael@0 511 MmsMessage::GetRead(bool* aRead)
michael@0 512 {
michael@0 513 *aRead = mRead;
michael@0 514 return NS_OK;
michael@0 515 }
michael@0 516
michael@0 517 NS_IMETHODIMP
michael@0 518 MmsMessage::GetSubject(nsAString& aSubject)
michael@0 519 {
michael@0 520 aSubject = mSubject;
michael@0 521 return NS_OK;
michael@0 522 }
michael@0 523
michael@0 524 NS_IMETHODIMP
michael@0 525 MmsMessage::GetSmil(nsAString& aSmil)
michael@0 526 {
michael@0 527 aSmil = mSmil;
michael@0 528 return NS_OK;
michael@0 529 }
michael@0 530
michael@0 531 NS_IMETHODIMP
michael@0 532 MmsMessage::GetAttachments(JSContext* aCx, JS::MutableHandle<JS::Value> aAttachments)
michael@0 533 {
michael@0 534 uint32_t length = mAttachments.Length();
michael@0 535
michael@0 536 JS::Rooted<JSObject*> attachments(
michael@0 537 aCx, JS_NewArrayObject(aCx, length));
michael@0 538 NS_ENSURE_TRUE(attachments, NS_ERROR_OUT_OF_MEMORY);
michael@0 539
michael@0 540 for (uint32_t i = 0; i < length; ++i) {
michael@0 541 const Attachment &attachment = mAttachments[i];
michael@0 542
michael@0 543 JS::Rooted<JSObject*> attachmentObj(
michael@0 544 aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr()));
michael@0 545 NS_ENSURE_TRUE(attachmentObj, NS_ERROR_OUT_OF_MEMORY);
michael@0 546
michael@0 547 JS::Rooted<JSString*> tmpJsStr(aCx);
michael@0 548
michael@0 549 // Get |attachment.mId|.
michael@0 550 tmpJsStr = JS_NewUCStringCopyN(aCx,
michael@0 551 attachment.id.get(),
michael@0 552 attachment.id.Length());
michael@0 553 NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
michael@0 554
michael@0 555 if (!JS_DefineProperty(aCx, attachmentObj, "id", tmpJsStr, JSPROP_ENUMERATE)) {
michael@0 556 return NS_ERROR_FAILURE;
michael@0 557 }
michael@0 558
michael@0 559 // Get |attachment.mLocation|.
michael@0 560 tmpJsStr = JS_NewUCStringCopyN(aCx,
michael@0 561 attachment.location.get(),
michael@0 562 attachment.location.Length());
michael@0 563 NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY);
michael@0 564
michael@0 565 if (!JS_DefineProperty(aCx, attachmentObj, "location", tmpJsStr, JSPROP_ENUMERATE)) {
michael@0 566 return NS_ERROR_FAILURE;
michael@0 567 }
michael@0 568
michael@0 569 // Get |attachment.mContent|.
michael@0 570 JS::Rooted<JS::Value> tmpJsVal(aCx);
michael@0 571 nsresult rv = nsContentUtils::WrapNative(aCx,
michael@0 572 attachment.content,
michael@0 573 &NS_GET_IID(nsIDOMBlob),
michael@0 574 &tmpJsVal);
michael@0 575 NS_ENSURE_SUCCESS(rv, rv);
michael@0 576
michael@0 577 if (!JS_DefineProperty(aCx, attachmentObj, "content", tmpJsVal, JSPROP_ENUMERATE)) {
michael@0 578 return NS_ERROR_FAILURE;
michael@0 579 }
michael@0 580
michael@0 581 if (!JS_SetElement(aCx, attachments, i, attachmentObj)) {
michael@0 582 return NS_ERROR_FAILURE;
michael@0 583 }
michael@0 584 }
michael@0 585
michael@0 586 aAttachments.setObject(*attachments);
michael@0 587 return NS_OK;
michael@0 588 }
michael@0 589
michael@0 590 NS_IMETHODIMP
michael@0 591 MmsMessage::GetExpiryDate(DOMTimeStamp* aExpiryDate)
michael@0 592 {
michael@0 593 *aExpiryDate = mExpiryDate;
michael@0 594 return NS_OK;
michael@0 595 }
michael@0 596
michael@0 597 NS_IMETHODIMP
michael@0 598 MmsMessage::GetReadReportRequested(bool* aReadReportRequested)
michael@0 599 {
michael@0 600 *aReadReportRequested = mReadReportRequested;
michael@0 601 return NS_OK;
michael@0 602 }
michael@0 603
michael@0 604
michael@0 605 } // namespace dom
michael@0 606 } // namespace mozilla

mercurial