Wed, 31 Dec 2014 06:09:35 +0100
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 "SmsMessage.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 "mozilla/dom/mobilemessage/Constants.h" // For MessageType |
michael@0 | 11 | |
michael@0 | 12 | using namespace mozilla::dom::mobilemessage; |
michael@0 | 13 | |
michael@0 | 14 | DOMCI_DATA(MozSmsMessage, mozilla::dom::SmsMessage) |
michael@0 | 15 | |
michael@0 | 16 | namespace mozilla { |
michael@0 | 17 | namespace dom { |
michael@0 | 18 | |
michael@0 | 19 | NS_INTERFACE_MAP_BEGIN(SmsMessage) |
michael@0 | 20 | NS_INTERFACE_MAP_ENTRY(nsIDOMMozSmsMessage) |
michael@0 | 21 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
michael@0 | 22 | NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozSmsMessage) |
michael@0 | 23 | NS_INTERFACE_MAP_END |
michael@0 | 24 | |
michael@0 | 25 | NS_IMPL_ADDREF(SmsMessage) |
michael@0 | 26 | NS_IMPL_RELEASE(SmsMessage) |
michael@0 | 27 | |
michael@0 | 28 | SmsMessage::SmsMessage(int32_t aId, |
michael@0 | 29 | uint64_t aThreadId, |
michael@0 | 30 | const nsString& aIccId, |
michael@0 | 31 | DeliveryState aDelivery, |
michael@0 | 32 | DeliveryStatus aDeliveryStatus, |
michael@0 | 33 | const nsString& aSender, |
michael@0 | 34 | const nsString& aReceiver, |
michael@0 | 35 | const nsString& aBody, |
michael@0 | 36 | MessageClass aMessageClass, |
michael@0 | 37 | uint64_t aTimestamp, |
michael@0 | 38 | uint64_t aSentTimestamp, |
michael@0 | 39 | uint64_t aDeliveryTimestamp, |
michael@0 | 40 | bool aRead) |
michael@0 | 41 | : mData(aId, aThreadId, aIccId, aDelivery, aDeliveryStatus, |
michael@0 | 42 | aSender, aReceiver, aBody, aMessageClass, aTimestamp, aSentTimestamp, |
michael@0 | 43 | aDeliveryTimestamp, aRead) |
michael@0 | 44 | { |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | SmsMessage::SmsMessage(const SmsMessageData& aData) |
michael@0 | 48 | : mData(aData) |
michael@0 | 49 | { |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | /* static */ nsresult |
michael@0 | 53 | SmsMessage::Create(int32_t aId, |
michael@0 | 54 | uint64_t aThreadId, |
michael@0 | 55 | const nsAString& aIccId, |
michael@0 | 56 | const nsAString& aDelivery, |
michael@0 | 57 | const nsAString& aDeliveryStatus, |
michael@0 | 58 | const nsAString& aSender, |
michael@0 | 59 | const nsAString& aReceiver, |
michael@0 | 60 | const nsAString& aBody, |
michael@0 | 61 | const nsAString& aMessageClass, |
michael@0 | 62 | uint64_t aTimestamp, |
michael@0 | 63 | uint64_t aSentTimestamp, |
michael@0 | 64 | uint64_t aDeliveryTimestamp, |
michael@0 | 65 | bool aRead, |
michael@0 | 66 | JSContext* aCx, |
michael@0 | 67 | nsIDOMMozSmsMessage** aMessage) |
michael@0 | 68 | { |
michael@0 | 69 | *aMessage = nullptr; |
michael@0 | 70 | |
michael@0 | 71 | // SmsMessageData exposes these as references, so we can simply assign |
michael@0 | 72 | // to them. |
michael@0 | 73 | SmsMessageData data; |
michael@0 | 74 | data.id() = aId; |
michael@0 | 75 | data.threadId() = aThreadId; |
michael@0 | 76 | data.iccId() = nsString(aIccId); |
michael@0 | 77 | data.sender() = nsString(aSender); |
michael@0 | 78 | data.receiver() = nsString(aReceiver); |
michael@0 | 79 | data.body() = nsString(aBody); |
michael@0 | 80 | data.read() = aRead; |
michael@0 | 81 | |
michael@0 | 82 | if (aDelivery.Equals(DELIVERY_RECEIVED)) { |
michael@0 | 83 | data.delivery() = eDeliveryState_Received; |
michael@0 | 84 | } else if (aDelivery.Equals(DELIVERY_SENDING)) { |
michael@0 | 85 | data.delivery() = eDeliveryState_Sending; |
michael@0 | 86 | } else if (aDelivery.Equals(DELIVERY_SENT)) { |
michael@0 | 87 | data.delivery() = eDeliveryState_Sent; |
michael@0 | 88 | } else if (aDelivery.Equals(DELIVERY_ERROR)) { |
michael@0 | 89 | data.delivery() = eDeliveryState_Error; |
michael@0 | 90 | } else { |
michael@0 | 91 | return NS_ERROR_INVALID_ARG; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | if (aDeliveryStatus.Equals(DELIVERY_STATUS_NOT_APPLICABLE)) { |
michael@0 | 95 | data.deliveryStatus() = eDeliveryStatus_NotApplicable; |
michael@0 | 96 | } else if (aDeliveryStatus.Equals(DELIVERY_STATUS_SUCCESS)) { |
michael@0 | 97 | data.deliveryStatus() = eDeliveryStatus_Success; |
michael@0 | 98 | } else if (aDeliveryStatus.Equals(DELIVERY_STATUS_PENDING)) { |
michael@0 | 99 | data.deliveryStatus() = eDeliveryStatus_Pending; |
michael@0 | 100 | } else if (aDeliveryStatus.Equals(DELIVERY_STATUS_ERROR)) { |
michael@0 | 101 | data.deliveryStatus() = eDeliveryStatus_Error; |
michael@0 | 102 | } else { |
michael@0 | 103 | return NS_ERROR_INVALID_ARG; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | if (aMessageClass.Equals(MESSAGE_CLASS_NORMAL)) { |
michael@0 | 107 | data.messageClass() = eMessageClass_Normal; |
michael@0 | 108 | } else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_0)) { |
michael@0 | 109 | data.messageClass() = eMessageClass_Class0; |
michael@0 | 110 | } else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_1)) { |
michael@0 | 111 | data.messageClass() = eMessageClass_Class1; |
michael@0 | 112 | } else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_2)) { |
michael@0 | 113 | data.messageClass() = eMessageClass_Class2; |
michael@0 | 114 | } else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_3)) { |
michael@0 | 115 | data.messageClass() = eMessageClass_Class3; |
michael@0 | 116 | } else { |
michael@0 | 117 | return NS_ERROR_INVALID_ARG; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | // Set |timestamp|. |
michael@0 | 121 | data.timestamp() = aTimestamp; |
michael@0 | 122 | |
michael@0 | 123 | // Set |sentTimestamp|. |
michael@0 | 124 | data.sentTimestamp() = aSentTimestamp; |
michael@0 | 125 | |
michael@0 | 126 | // Set |deliveryTimestamp|. |
michael@0 | 127 | data.deliveryTimestamp() = aDeliveryTimestamp; |
michael@0 | 128 | |
michael@0 | 129 | nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(data); |
michael@0 | 130 | message.swap(*aMessage); |
michael@0 | 131 | return NS_OK; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | const SmsMessageData& |
michael@0 | 135 | SmsMessage::GetData() const |
michael@0 | 136 | { |
michael@0 | 137 | return mData; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | NS_IMETHODIMP |
michael@0 | 141 | SmsMessage::GetType(nsAString& aType) |
michael@0 | 142 | { |
michael@0 | 143 | aType = NS_LITERAL_STRING("sms"); |
michael@0 | 144 | return NS_OK; |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | NS_IMETHODIMP |
michael@0 | 148 | SmsMessage::GetId(int32_t* aId) |
michael@0 | 149 | { |
michael@0 | 150 | *aId = mData.id(); |
michael@0 | 151 | return NS_OK; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | NS_IMETHODIMP |
michael@0 | 155 | SmsMessage::GetThreadId(uint64_t* aThreadId) |
michael@0 | 156 | { |
michael@0 | 157 | *aThreadId = mData.threadId(); |
michael@0 | 158 | return NS_OK; |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | NS_IMETHODIMP |
michael@0 | 162 | SmsMessage::GetIccId(nsAString& aIccId) |
michael@0 | 163 | { |
michael@0 | 164 | aIccId = mData.iccId(); |
michael@0 | 165 | return NS_OK; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | NS_IMETHODIMP |
michael@0 | 169 | SmsMessage::GetDelivery(nsAString& aDelivery) |
michael@0 | 170 | { |
michael@0 | 171 | switch (mData.delivery()) { |
michael@0 | 172 | case eDeliveryState_Received: |
michael@0 | 173 | aDelivery = DELIVERY_RECEIVED; |
michael@0 | 174 | break; |
michael@0 | 175 | case eDeliveryState_Sending: |
michael@0 | 176 | aDelivery = DELIVERY_SENDING; |
michael@0 | 177 | break; |
michael@0 | 178 | case eDeliveryState_Sent: |
michael@0 | 179 | aDelivery = DELIVERY_SENT; |
michael@0 | 180 | break; |
michael@0 | 181 | case eDeliveryState_Error: |
michael@0 | 182 | aDelivery = DELIVERY_ERROR; |
michael@0 | 183 | break; |
michael@0 | 184 | case eDeliveryState_Unknown: |
michael@0 | 185 | case eDeliveryState_EndGuard: |
michael@0 | 186 | default: |
michael@0 | 187 | MOZ_CRASH("We shouldn't get any other delivery state!"); |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | return NS_OK; |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | NS_IMETHODIMP |
michael@0 | 194 | SmsMessage::GetDeliveryStatus(nsAString& aDeliveryStatus) |
michael@0 | 195 | { |
michael@0 | 196 | switch (mData.deliveryStatus()) { |
michael@0 | 197 | case eDeliveryStatus_NotApplicable: |
michael@0 | 198 | aDeliveryStatus = DELIVERY_STATUS_NOT_APPLICABLE; |
michael@0 | 199 | break; |
michael@0 | 200 | case eDeliveryStatus_Success: |
michael@0 | 201 | aDeliveryStatus = DELIVERY_STATUS_SUCCESS; |
michael@0 | 202 | break; |
michael@0 | 203 | case eDeliveryStatus_Pending: |
michael@0 | 204 | aDeliveryStatus = DELIVERY_STATUS_PENDING; |
michael@0 | 205 | break; |
michael@0 | 206 | case eDeliveryStatus_Error: |
michael@0 | 207 | aDeliveryStatus = DELIVERY_STATUS_ERROR; |
michael@0 | 208 | break; |
michael@0 | 209 | case eDeliveryStatus_EndGuard: |
michael@0 | 210 | default: |
michael@0 | 211 | MOZ_CRASH("We shouldn't get any other delivery status!"); |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | return NS_OK; |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | NS_IMETHODIMP |
michael@0 | 218 | SmsMessage::GetSender(nsAString& aSender) |
michael@0 | 219 | { |
michael@0 | 220 | aSender = mData.sender(); |
michael@0 | 221 | return NS_OK; |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | NS_IMETHODIMP |
michael@0 | 225 | SmsMessage::GetReceiver(nsAString& aReceiver) |
michael@0 | 226 | { |
michael@0 | 227 | aReceiver = mData.receiver(); |
michael@0 | 228 | return NS_OK; |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | NS_IMETHODIMP |
michael@0 | 232 | SmsMessage::GetBody(nsAString& aBody) |
michael@0 | 233 | { |
michael@0 | 234 | aBody = mData.body(); |
michael@0 | 235 | return NS_OK; |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | NS_IMETHODIMP |
michael@0 | 239 | SmsMessage::GetMessageClass(nsAString& aMessageClass) |
michael@0 | 240 | { |
michael@0 | 241 | switch (mData.messageClass()) { |
michael@0 | 242 | case eMessageClass_Normal: |
michael@0 | 243 | aMessageClass = MESSAGE_CLASS_NORMAL; |
michael@0 | 244 | break; |
michael@0 | 245 | case eMessageClass_Class0: |
michael@0 | 246 | aMessageClass = MESSAGE_CLASS_CLASS_0; |
michael@0 | 247 | break; |
michael@0 | 248 | case eMessageClass_Class1: |
michael@0 | 249 | aMessageClass = MESSAGE_CLASS_CLASS_1; |
michael@0 | 250 | break; |
michael@0 | 251 | case eMessageClass_Class2: |
michael@0 | 252 | aMessageClass = MESSAGE_CLASS_CLASS_2; |
michael@0 | 253 | break; |
michael@0 | 254 | case eMessageClass_Class3: |
michael@0 | 255 | aMessageClass = MESSAGE_CLASS_CLASS_3; |
michael@0 | 256 | break; |
michael@0 | 257 | default: |
michael@0 | 258 | MOZ_CRASH("We shouldn't get any other message class!"); |
michael@0 | 259 | } |
michael@0 | 260 | |
michael@0 | 261 | return NS_OK; |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | NS_IMETHODIMP |
michael@0 | 265 | SmsMessage::GetTimestamp(DOMTimeStamp* aTimestamp) |
michael@0 | 266 | { |
michael@0 | 267 | *aTimestamp = mData.timestamp(); |
michael@0 | 268 | return NS_OK; |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | NS_IMETHODIMP |
michael@0 | 272 | SmsMessage::GetSentTimestamp(DOMTimeStamp* aSentTimestamp) |
michael@0 | 273 | { |
michael@0 | 274 | *aSentTimestamp = mData.sentTimestamp(); |
michael@0 | 275 | return NS_OK; |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | NS_IMETHODIMP |
michael@0 | 279 | SmsMessage::GetDeliveryTimestamp(DOMTimeStamp* aDate) |
michael@0 | 280 | { |
michael@0 | 281 | *aDate = mData.deliveryTimestamp(); |
michael@0 | 282 | return NS_OK; |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | NS_IMETHODIMP |
michael@0 | 286 | SmsMessage::GetRead(bool* aRead) |
michael@0 | 287 | { |
michael@0 | 288 | *aRead = mData.read(); |
michael@0 | 289 | return NS_OK; |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | } // namespace dom |
michael@0 | 293 | } // namespace mozilla |