1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/mobilemessage/src/MmsMessage.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,606 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "MmsMessage.h" 1.10 +#include "nsIDOMClassInfo.h" 1.11 +#include "jsapi.h" // For OBJECT_TO_JSVAL and JS_NewDateObjectMsec 1.12 +#include "jsfriendapi.h" // For js_DateGetMsecSinceEpoch 1.13 +#include "nsJSUtils.h" 1.14 +#include "nsContentUtils.h" 1.15 +#include "nsIDOMFile.h" 1.16 +#include "nsTArrayHelpers.h" 1.17 +#include "mozilla/dom/ContentParent.h" 1.18 +#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType 1.19 +#include "mozilla/dom/mobilemessage/SmsTypes.h" 1.20 +#include "mozilla/dom/ToJSValue.h" 1.21 +#include "nsDOMFile.h" 1.22 +#include "nsCxPusher.h" 1.23 + 1.24 +using namespace mozilla::dom::mobilemessage; 1.25 + 1.26 +DOMCI_DATA(MozMmsMessage, mozilla::dom::MmsMessage) 1.27 + 1.28 +namespace mozilla { 1.29 +namespace dom { 1.30 + 1.31 +NS_INTERFACE_MAP_BEGIN(MmsMessage) 1.32 + NS_INTERFACE_MAP_ENTRY(nsIDOMMozMmsMessage) 1.33 + NS_INTERFACE_MAP_ENTRY(nsISupports) 1.34 + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozMmsMessage) 1.35 +NS_INTERFACE_MAP_END 1.36 + 1.37 +NS_IMPL_ADDREF(MmsMessage) 1.38 +NS_IMPL_RELEASE(MmsMessage) 1.39 + 1.40 +MmsMessage::MmsMessage(int32_t aId, 1.41 + uint64_t aThreadId, 1.42 + const nsAString& aIccId, 1.43 + DeliveryState aDelivery, 1.44 + const nsTArray<MmsDeliveryInfo>& aDeliveryInfo, 1.45 + const nsAString& aSender, 1.46 + const nsTArray<nsString>& aReceivers, 1.47 + uint64_t aTimestamp, 1.48 + uint64_t aSentTimestamp, 1.49 + bool aRead, 1.50 + const nsAString& aSubject, 1.51 + const nsAString& aSmil, 1.52 + const nsTArray<Attachment>& aAttachments, 1.53 + uint64_t aExpiryDate, 1.54 + bool aReadReportRequested) 1.55 + : mId(aId), 1.56 + mThreadId(aThreadId), 1.57 + mIccId(aIccId), 1.58 + mDelivery(aDelivery), 1.59 + mDeliveryInfo(aDeliveryInfo), 1.60 + mSender(aSender), 1.61 + mReceivers(aReceivers), 1.62 + mTimestamp(aTimestamp), 1.63 + mSentTimestamp(aSentTimestamp), 1.64 + mRead(aRead), 1.65 + mSubject(aSubject), 1.66 + mSmil(aSmil), 1.67 + mAttachments(aAttachments), 1.68 + mExpiryDate(aExpiryDate), 1.69 + mReadReportRequested(aReadReportRequested) 1.70 +{ 1.71 +} 1.72 + 1.73 +MmsMessage::MmsMessage(const mobilemessage::MmsMessageData& aData) 1.74 + : mId(aData.id()) 1.75 + , mThreadId(aData.threadId()) 1.76 + , mIccId(aData.iccId()) 1.77 + , mDelivery(aData.delivery()) 1.78 + , mSender(aData.sender()) 1.79 + , mReceivers(aData.receivers()) 1.80 + , mTimestamp(aData.timestamp()) 1.81 + , mSentTimestamp(aData.sentTimestamp()) 1.82 + , mRead(aData.read()) 1.83 + , mSubject(aData.subject()) 1.84 + , mSmil(aData.smil()) 1.85 + , mExpiryDate(aData.expiryDate()) 1.86 + , mReadReportRequested(aData.readReportRequested()) 1.87 +{ 1.88 + uint32_t len = aData.attachments().Length(); 1.89 + mAttachments.SetCapacity(len); 1.90 + for (uint32_t i = 0; i < len; i++) { 1.91 + MmsAttachment att; 1.92 + const MmsAttachmentData &element = aData.attachments()[i]; 1.93 + att.mId = element.id(); 1.94 + att.mLocation = element.location(); 1.95 + if (element.contentParent()) { 1.96 + att.mContent = static_cast<BlobParent*>(element.contentParent())->GetBlob(); 1.97 + } else if (element.contentChild()) { 1.98 + att.mContent = static_cast<BlobChild*>(element.contentChild())->GetBlob(); 1.99 + } else { 1.100 + NS_WARNING("MmsMessage: Unable to get attachment content."); 1.101 + } 1.102 + mAttachments.AppendElement(att); 1.103 + } 1.104 + 1.105 + len = aData.deliveryInfo().Length(); 1.106 + mDeliveryInfo.SetCapacity(len); 1.107 + for (uint32_t i = 0; i < len; i++) { 1.108 + MmsDeliveryInfo info; 1.109 + const MmsDeliveryInfoData &infoData = aData.deliveryInfo()[i]; 1.110 + 1.111 + // Prepare |info.mReceiver|. 1.112 + info.mReceiver = infoData.receiver(); 1.113 + 1.114 + // Prepare |info.mDeliveryStatus|. 1.115 + nsString statusStr; 1.116 + switch (infoData.deliveryStatus()) { 1.117 + case eDeliveryStatus_NotApplicable: 1.118 + statusStr = DELIVERY_STATUS_NOT_APPLICABLE; 1.119 + break; 1.120 + case eDeliveryStatus_Success: 1.121 + statusStr = DELIVERY_STATUS_SUCCESS; 1.122 + break; 1.123 + case eDeliveryStatus_Pending: 1.124 + statusStr = DELIVERY_STATUS_PENDING; 1.125 + break; 1.126 + case eDeliveryStatus_Error: 1.127 + statusStr = DELIVERY_STATUS_ERROR; 1.128 + break; 1.129 + case eDeliveryStatus_Reject: 1.130 + statusStr = DELIVERY_STATUS_REJECTED; 1.131 + break; 1.132 + case eDeliveryStatus_Manual: 1.133 + statusStr = DELIVERY_STATUS_MANUAL; 1.134 + break; 1.135 + case eDeliveryStatus_EndGuard: 1.136 + default: 1.137 + MOZ_CRASH("We shouldn't get any other delivery status!"); 1.138 + } 1.139 + info.mDeliveryStatus = statusStr; 1.140 + 1.141 + // Prepare |info.mDeliveryTimestamp|. 1.142 + info.mDeliveryTimestamp = infoData.deliveryTimestamp(); 1.143 + 1.144 + // Prepare |info.mReadStatus|. 1.145 + nsString statusReadString; 1.146 + switch(infoData.readStatus()) { 1.147 + case eReadStatus_NotApplicable: 1.148 + statusReadString = READ_STATUS_NOT_APPLICABLE; 1.149 + break; 1.150 + case eReadStatus_Success: 1.151 + statusReadString = READ_STATUS_SUCCESS; 1.152 + break; 1.153 + case eReadStatus_Pending: 1.154 + statusReadString = READ_STATUS_PENDING; 1.155 + break; 1.156 + case eReadStatus_Error: 1.157 + statusReadString = READ_STATUS_ERROR; 1.158 + break; 1.159 + case eReadStatus_EndGuard: 1.160 + default: 1.161 + MOZ_CRASH("We shouldn't get any other read status!"); 1.162 + } 1.163 + info.mReadStatus = statusReadString; 1.164 + 1.165 + // Prepare |info.mReadTimestamp|. 1.166 + info.mReadTimestamp = infoData.readTimestamp(); 1.167 + 1.168 + mDeliveryInfo.AppendElement(info); 1.169 + } 1.170 +} 1.171 + 1.172 +/* static */ nsresult 1.173 +MmsMessage::Create(int32_t aId, 1.174 + uint64_t aThreadId, 1.175 + const nsAString& aIccId, 1.176 + const nsAString& aDelivery, 1.177 + const JS::Value& aDeliveryInfo, 1.178 + const nsAString& aSender, 1.179 + const JS::Value& aReceivers, 1.180 + uint64_t aTimestamp, 1.181 + uint64_t aSentTimestamp, 1.182 + bool aRead, 1.183 + const nsAString& aSubject, 1.184 + const nsAString& aSmil, 1.185 + const JS::Value& aAttachments, 1.186 + uint64_t aExpiryDate, 1.187 + bool aIsReadReportRequested, 1.188 + JSContext* aCx, 1.189 + nsIDOMMozMmsMessage** aMessage) 1.190 +{ 1.191 + *aMessage = nullptr; 1.192 + 1.193 + // Set |delivery|. 1.194 + DeliveryState delivery; 1.195 + if (aDelivery.Equals(DELIVERY_SENT)) { 1.196 + delivery = eDeliveryState_Sent; 1.197 + } else if (aDelivery.Equals(DELIVERY_RECEIVED)) { 1.198 + delivery = eDeliveryState_Received; 1.199 + } else if (aDelivery.Equals(DELIVERY_SENDING)) { 1.200 + delivery = eDeliveryState_Sending; 1.201 + } else if (aDelivery.Equals(DELIVERY_NOT_DOWNLOADED)) { 1.202 + delivery = eDeliveryState_NotDownloaded; 1.203 + } else if (aDelivery.Equals(DELIVERY_ERROR)) { 1.204 + delivery = eDeliveryState_Error; 1.205 + } else { 1.206 + return NS_ERROR_INVALID_ARG; 1.207 + } 1.208 + 1.209 + // Set |deliveryInfo|. 1.210 + if (!aDeliveryInfo.isObject()) { 1.211 + return NS_ERROR_INVALID_ARG; 1.212 + } 1.213 + JS::Rooted<JSObject*> deliveryInfoObj(aCx, &aDeliveryInfo.toObject()); 1.214 + if (!JS_IsArrayObject(aCx, deliveryInfoObj)) { 1.215 + return NS_ERROR_INVALID_ARG; 1.216 + } 1.217 + 1.218 + uint32_t length; 1.219 + MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, deliveryInfoObj, &length)); 1.220 + 1.221 + nsTArray<MmsDeliveryInfo> deliveryInfo; 1.222 + JS::Rooted<JS::Value> infoJsVal(aCx); 1.223 + for (uint32_t i = 0; i < length; ++i) { 1.224 + if (!JS_GetElement(aCx, deliveryInfoObj, i, &infoJsVal) || 1.225 + !infoJsVal.isObject()) { 1.226 + return NS_ERROR_INVALID_ARG; 1.227 + } 1.228 + 1.229 + MmsDeliveryInfo info; 1.230 + if (!info.Init(aCx, infoJsVal)) { 1.231 + return NS_ERROR_TYPE_ERR; 1.232 + } 1.233 + 1.234 + deliveryInfo.AppendElement(info); 1.235 + } 1.236 + 1.237 + // Set |receivers|. 1.238 + if (!aReceivers.isObject()) { 1.239 + return NS_ERROR_INVALID_ARG; 1.240 + } 1.241 + JS::Rooted<JSObject*> receiversObj(aCx, &aReceivers.toObject()); 1.242 + if (!JS_IsArrayObject(aCx, receiversObj)) { 1.243 + return NS_ERROR_INVALID_ARG; 1.244 + } 1.245 + 1.246 + MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, receiversObj, &length)); 1.247 + 1.248 + nsTArray<nsString> receivers; 1.249 + JS::Rooted<JS::Value> receiverJsVal(aCx); 1.250 + for (uint32_t i = 0; i < length; ++i) { 1.251 + if (!JS_GetElement(aCx, receiversObj, i, &receiverJsVal) || 1.252 + !receiverJsVal.isString()) { 1.253 + return NS_ERROR_INVALID_ARG; 1.254 + } 1.255 + 1.256 + nsDependentJSString receiverStr; 1.257 + receiverStr.init(aCx, receiverJsVal.toString()); 1.258 + receivers.AppendElement(receiverStr); 1.259 + } 1.260 + 1.261 + // Set |attachments|. 1.262 + if (!aAttachments.isObject()) { 1.263 + return NS_ERROR_INVALID_ARG; 1.264 + } 1.265 + JS::Rooted<JSObject*> attachmentsObj(aCx, &aAttachments.toObject()); 1.266 + if (!JS_IsArrayObject(aCx, attachmentsObj)) { 1.267 + return NS_ERROR_INVALID_ARG; 1.268 + } 1.269 + 1.270 + nsTArray<Attachment> attachments; 1.271 + MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, attachmentsObj, &length)); 1.272 + 1.273 + JS::Rooted<JS::Value> attachmentJsVal(aCx); 1.274 + for (uint32_t i = 0; i < length; ++i) { 1.275 + if (!JS_GetElement(aCx, attachmentsObj, i, &attachmentJsVal)) { 1.276 + return NS_ERROR_INVALID_ARG; 1.277 + } 1.278 + 1.279 + MmsAttachment attachment; 1.280 + if (!attachment.Init(aCx, attachmentJsVal)) { 1.281 + return NS_ERROR_TYPE_ERR; 1.282 + } 1.283 + 1.284 + attachments.AppendElement(attachment); 1.285 + } 1.286 + 1.287 + nsCOMPtr<nsIDOMMozMmsMessage> message = new MmsMessage(aId, 1.288 + aThreadId, 1.289 + aIccId, 1.290 + delivery, 1.291 + deliveryInfo, 1.292 + aSender, 1.293 + receivers, 1.294 + aTimestamp, 1.295 + aSentTimestamp, 1.296 + aRead, 1.297 + aSubject, 1.298 + aSmil, 1.299 + attachments, 1.300 + aExpiryDate, 1.301 + aIsReadReportRequested); 1.302 + message.forget(aMessage); 1.303 + return NS_OK; 1.304 +} 1.305 + 1.306 +bool 1.307 +MmsMessage::GetData(ContentParent* aParent, 1.308 + mobilemessage::MmsMessageData& aData) 1.309 +{ 1.310 + NS_ASSERTION(aParent, "aParent is null"); 1.311 + 1.312 + aData.id() = mId; 1.313 + aData.threadId() = mThreadId; 1.314 + aData.iccId() = mIccId; 1.315 + aData.delivery() = mDelivery; 1.316 + aData.sender().Assign(mSender); 1.317 + aData.receivers() = mReceivers; 1.318 + aData.timestamp() = mTimestamp; 1.319 + aData.sentTimestamp() = mSentTimestamp; 1.320 + aData.read() = mRead; 1.321 + aData.subject() = mSubject; 1.322 + aData.smil() = mSmil; 1.323 + aData.expiryDate() = mExpiryDate; 1.324 + aData.readReportRequested() = mReadReportRequested; 1.325 + 1.326 + aData.deliveryInfo().SetCapacity(mDeliveryInfo.Length()); 1.327 + for (uint32_t i = 0; i < mDeliveryInfo.Length(); i++) { 1.328 + MmsDeliveryInfoData infoData; 1.329 + const MmsDeliveryInfo &info = mDeliveryInfo[i]; 1.330 + 1.331 + // Prepare |infoData.mReceiver|. 1.332 + infoData.receiver().Assign(info.mReceiver); 1.333 + 1.334 + // Prepare |infoData.mDeliveryStatus|. 1.335 + DeliveryStatus status; 1.336 + if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_NOT_APPLICABLE)) { 1.337 + status = eDeliveryStatus_NotApplicable; 1.338 + } else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_SUCCESS)) { 1.339 + status = eDeliveryStatus_Success; 1.340 + } else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_PENDING)) { 1.341 + status = eDeliveryStatus_Pending; 1.342 + } else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_ERROR)) { 1.343 + status = eDeliveryStatus_Error; 1.344 + } else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_REJECTED)) { 1.345 + status = eDeliveryStatus_Reject; 1.346 + } else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_MANUAL)) { 1.347 + status = eDeliveryStatus_Manual; 1.348 + } else { 1.349 + return false; 1.350 + } 1.351 + infoData.deliveryStatus() = status; 1.352 + 1.353 + // Prepare |infoData.mDeliveryTimestamp|. 1.354 + infoData.deliveryTimestamp() = info.mDeliveryTimestamp; 1.355 + 1.356 + // Prepare |infoData.mReadStatus|. 1.357 + ReadStatus readStatus; 1.358 + if (info.mReadStatus.Equals(READ_STATUS_NOT_APPLICABLE)) { 1.359 + readStatus = eReadStatus_NotApplicable; 1.360 + } else if (info.mReadStatus.Equals(READ_STATUS_SUCCESS)) { 1.361 + readStatus = eReadStatus_Success; 1.362 + } else if (info.mReadStatus.Equals(READ_STATUS_PENDING)) { 1.363 + readStatus = eReadStatus_Pending; 1.364 + } else if (info.mReadStatus.Equals(READ_STATUS_ERROR)) { 1.365 + readStatus = eReadStatus_Error; 1.366 + } else { 1.367 + return false; 1.368 + } 1.369 + infoData.readStatus() = readStatus; 1.370 + 1.371 + // Prepare |infoData.mReadTimestamp|. 1.372 + infoData.readTimestamp() = info.mReadTimestamp; 1.373 + 1.374 + aData.deliveryInfo().AppendElement(infoData); 1.375 + } 1.376 + 1.377 + aData.attachments().SetCapacity(mAttachments.Length()); 1.378 + for (uint32_t i = 0; i < mAttachments.Length(); i++) { 1.379 + MmsAttachmentData mma; 1.380 + const Attachment &element = mAttachments[i]; 1.381 + mma.id().Assign(element.id); 1.382 + mma.location().Assign(element.location); 1.383 + 1.384 + // This is a workaround. Sometimes the blob we get from the database 1.385 + // doesn't have a valid last modified date, making the ContentParent 1.386 + // send a "Mystery Blob" to the ContentChild. Attempting to get the 1.387 + // last modified date of blob can force that value to be initialized. 1.388 + nsDOMFileBase* file = static_cast<nsDOMFileBase*>(element.content.get()); 1.389 + if (file->IsDateUnknown()) { 1.390 + uint64_t date; 1.391 + if (NS_FAILED(file->GetMozLastModifiedDate(&date))) { 1.392 + NS_WARNING("Failed to get last modified date!"); 1.393 + } 1.394 + } 1.395 + 1.396 + mma.contentParent() = aParent->GetOrCreateActorForBlob(element.content); 1.397 + if (!mma.contentParent()) { 1.398 + return false; 1.399 + } 1.400 + aData.attachments().AppendElement(mma); 1.401 + } 1.402 + 1.403 + return true; 1.404 +} 1.405 + 1.406 +NS_IMETHODIMP 1.407 +MmsMessage::GetType(nsAString& aType) 1.408 +{ 1.409 + aType = NS_LITERAL_STRING("mms"); 1.410 + return NS_OK; 1.411 +} 1.412 + 1.413 +NS_IMETHODIMP 1.414 +MmsMessage::GetId(int32_t* aId) 1.415 +{ 1.416 + *aId = mId; 1.417 + return NS_OK; 1.418 +} 1.419 + 1.420 +NS_IMETHODIMP 1.421 +MmsMessage::GetThreadId(uint64_t* aThreadId) 1.422 +{ 1.423 + *aThreadId = mThreadId; 1.424 + return NS_OK; 1.425 +} 1.426 + 1.427 +NS_IMETHODIMP 1.428 +MmsMessage::GetIccId(nsAString& aIccId) 1.429 +{ 1.430 + aIccId = mIccId; 1.431 + return NS_OK; 1.432 +} 1.433 + 1.434 +NS_IMETHODIMP 1.435 +MmsMessage::GetDelivery(nsAString& aDelivery) 1.436 +{ 1.437 + switch (mDelivery) { 1.438 + case eDeliveryState_Received: 1.439 + aDelivery = DELIVERY_RECEIVED; 1.440 + break; 1.441 + case eDeliveryState_Sending: 1.442 + aDelivery = DELIVERY_SENDING; 1.443 + break; 1.444 + case eDeliveryState_Sent: 1.445 + aDelivery = DELIVERY_SENT; 1.446 + break; 1.447 + case eDeliveryState_Error: 1.448 + aDelivery = DELIVERY_ERROR; 1.449 + break; 1.450 + case eDeliveryState_NotDownloaded: 1.451 + aDelivery = DELIVERY_NOT_DOWNLOADED; 1.452 + break; 1.453 + case eDeliveryState_Unknown: 1.454 + case eDeliveryState_EndGuard: 1.455 + default: 1.456 + MOZ_CRASH("We shouldn't get any other delivery state!"); 1.457 + } 1.458 + 1.459 + return NS_OK; 1.460 +} 1.461 + 1.462 +NS_IMETHODIMP 1.463 +MmsMessage::GetDeliveryInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aDeliveryInfo) 1.464 +{ 1.465 + // TODO Bug 850525 It'd be better to depend on the delivery of MmsMessage 1.466 + // to return a more correct value. Ex, if .delivery = 'received', we should 1.467 + // also make .deliveryInfo = null, since the .deliveryInfo is useless. 1.468 + uint32_t length = mDeliveryInfo.Length(); 1.469 + if (length == 0) { 1.470 + aDeliveryInfo.setNull(); 1.471 + return NS_OK; 1.472 + } 1.473 + 1.474 + if (!ToJSValue(aCx, mDeliveryInfo, aDeliveryInfo)) { 1.475 + return NS_ERROR_OUT_OF_MEMORY; 1.476 + } 1.477 + 1.478 + return NS_OK; 1.479 +} 1.480 + 1.481 +NS_IMETHODIMP 1.482 +MmsMessage::GetSender(nsAString& aSender) 1.483 +{ 1.484 + aSender = mSender; 1.485 + return NS_OK; 1.486 +} 1.487 + 1.488 +NS_IMETHODIMP 1.489 +MmsMessage::GetReceivers(JSContext* aCx, JS::MutableHandle<JS::Value> aReceivers) 1.490 +{ 1.491 + JS::Rooted<JSObject*> reveiversObj(aCx); 1.492 + nsresult rv = nsTArrayToJSArray(aCx, mReceivers, reveiversObj.address()); 1.493 + NS_ENSURE_SUCCESS(rv, rv); 1.494 + 1.495 + aReceivers.setObject(*reveiversObj); 1.496 + return NS_OK; 1.497 +} 1.498 + 1.499 +NS_IMETHODIMP 1.500 +MmsMessage::GetTimestamp(DOMTimeStamp* aTimestamp) 1.501 +{ 1.502 + *aTimestamp = mTimestamp; 1.503 + return NS_OK; 1.504 +} 1.505 + 1.506 +NS_IMETHODIMP 1.507 +MmsMessage::GetSentTimestamp(DOMTimeStamp* aSentTimestamp) 1.508 +{ 1.509 + *aSentTimestamp = mSentTimestamp; 1.510 + return NS_OK; 1.511 +} 1.512 + 1.513 +NS_IMETHODIMP 1.514 +MmsMessage::GetRead(bool* aRead) 1.515 +{ 1.516 + *aRead = mRead; 1.517 + return NS_OK; 1.518 +} 1.519 + 1.520 +NS_IMETHODIMP 1.521 +MmsMessage::GetSubject(nsAString& aSubject) 1.522 +{ 1.523 + aSubject = mSubject; 1.524 + return NS_OK; 1.525 +} 1.526 + 1.527 +NS_IMETHODIMP 1.528 +MmsMessage::GetSmil(nsAString& aSmil) 1.529 +{ 1.530 + aSmil = mSmil; 1.531 + return NS_OK; 1.532 +} 1.533 + 1.534 +NS_IMETHODIMP 1.535 +MmsMessage::GetAttachments(JSContext* aCx, JS::MutableHandle<JS::Value> aAttachments) 1.536 +{ 1.537 + uint32_t length = mAttachments.Length(); 1.538 + 1.539 + JS::Rooted<JSObject*> attachments( 1.540 + aCx, JS_NewArrayObject(aCx, length)); 1.541 + NS_ENSURE_TRUE(attachments, NS_ERROR_OUT_OF_MEMORY); 1.542 + 1.543 + for (uint32_t i = 0; i < length; ++i) { 1.544 + const Attachment &attachment = mAttachments[i]; 1.545 + 1.546 + JS::Rooted<JSObject*> attachmentObj( 1.547 + aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr())); 1.548 + NS_ENSURE_TRUE(attachmentObj, NS_ERROR_OUT_OF_MEMORY); 1.549 + 1.550 + JS::Rooted<JSString*> tmpJsStr(aCx); 1.551 + 1.552 + // Get |attachment.mId|. 1.553 + tmpJsStr = JS_NewUCStringCopyN(aCx, 1.554 + attachment.id.get(), 1.555 + attachment.id.Length()); 1.556 + NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY); 1.557 + 1.558 + if (!JS_DefineProperty(aCx, attachmentObj, "id", tmpJsStr, JSPROP_ENUMERATE)) { 1.559 + return NS_ERROR_FAILURE; 1.560 + } 1.561 + 1.562 + // Get |attachment.mLocation|. 1.563 + tmpJsStr = JS_NewUCStringCopyN(aCx, 1.564 + attachment.location.get(), 1.565 + attachment.location.Length()); 1.566 + NS_ENSURE_TRUE(tmpJsStr, NS_ERROR_OUT_OF_MEMORY); 1.567 + 1.568 + if (!JS_DefineProperty(aCx, attachmentObj, "location", tmpJsStr, JSPROP_ENUMERATE)) { 1.569 + return NS_ERROR_FAILURE; 1.570 + } 1.571 + 1.572 + // Get |attachment.mContent|. 1.573 + JS::Rooted<JS::Value> tmpJsVal(aCx); 1.574 + nsresult rv = nsContentUtils::WrapNative(aCx, 1.575 + attachment.content, 1.576 + &NS_GET_IID(nsIDOMBlob), 1.577 + &tmpJsVal); 1.578 + NS_ENSURE_SUCCESS(rv, rv); 1.579 + 1.580 + if (!JS_DefineProperty(aCx, attachmentObj, "content", tmpJsVal, JSPROP_ENUMERATE)) { 1.581 + return NS_ERROR_FAILURE; 1.582 + } 1.583 + 1.584 + if (!JS_SetElement(aCx, attachments, i, attachmentObj)) { 1.585 + return NS_ERROR_FAILURE; 1.586 + } 1.587 + } 1.588 + 1.589 + aAttachments.setObject(*attachments); 1.590 + return NS_OK; 1.591 +} 1.592 + 1.593 +NS_IMETHODIMP 1.594 +MmsMessage::GetExpiryDate(DOMTimeStamp* aExpiryDate) 1.595 +{ 1.596 + *aExpiryDate = mExpiryDate; 1.597 + return NS_OK; 1.598 +} 1.599 + 1.600 +NS_IMETHODIMP 1.601 +MmsMessage::GetReadReportRequested(bool* aReadReportRequested) 1.602 +{ 1.603 + *aReadReportRequested = mReadReportRequested; 1.604 + return NS_OK; 1.605 +} 1.606 + 1.607 + 1.608 +} // namespace dom 1.609 +} // namespace mozilla