Bug 944890 - B2G SMS & MMS: remove convertTimeToInt(...) which is no longer needed (part 1, implementation). r=vicamo

This commit is contained in:
Gene Lian 2014-03-20 10:45:55 +08:00
parent ae60eb63be
commit 80d8429c19
13 changed files with 149 additions and 225 deletions

View File

@ -14,40 +14,40 @@ interface nsIDOMMozSmsSegmentInfo;
#define MOBILE_MESSAGE_SERVICE_CONTRACTID "@mozilla.org/mobilemessage/mobilemessageservice;1"
%}
[scriptable, builtinclass, uuid(67d038b2-0039-11e3-9fd3-83de190730f7)]
[scriptable, builtinclass, uuid(17fce9e4-af56-11e3-83d9-b71055e95493)]
interface nsIMobileMessageService : nsISupports
{
[implicit_jscontext]
nsIDOMMozSmsMessage createSmsMessage(in long id,
nsIDOMMozSmsMessage createSmsMessage(in long id,
in unsigned long long threadId,
in DOMString iccId,
in DOMString delivery,
in DOMString deliveryStatus,
in DOMString sender,
in DOMString receiver,
in DOMString body,
in DOMString messageClass,
in jsval timestamp,
in jsval sentTimestamp,
in jsval deliveryTimestamp,
in bool read);
in DOMString iccId,
in DOMString delivery,
in DOMString deliveryStatus,
in DOMString sender,
in DOMString receiver,
in DOMString body,
in DOMString messageClass,
in unsigned long long timestamp,
in unsigned long long sentTimestamp,
in unsigned long long deliveryTimestamp,
in bool read);
[implicit_jscontext]
nsIDOMMozMmsMessage createMmsMessage(in long id,
nsIDOMMozMmsMessage createMmsMessage(in long id,
in unsigned long long threadId,
in DOMString iccId,
in DOMString delivery,
in jsval deliveryInfo,
in DOMString sender,
in jsval receivers,
in jsval timestamp,
in jsval sentTimestamp,
in boolean read,
in DOMString subject,
in DOMString smil,
in jsval attachments,
in jsval expiryDate,
in boolean readReportRequested);
in DOMString iccId,
in DOMString delivery,
in jsval deliveryInfo,
in DOMString sender,
in jsval receivers,
in unsigned long long timestamp,
in unsigned long long sentTimestamp,
in boolean read,
in DOMString subject,
in DOMString smil,
in jsval attachments,
in unsigned long long expiryDate,
in boolean readReportRequested);
nsIDOMMozSmsSegmentInfo createSmsSegmentInfo(in long segments,
in long charsPerSegment,
@ -56,7 +56,7 @@ interface nsIMobileMessageService : nsISupports
[implicit_jscontext]
nsIDOMMozMobileMessageThread createThread(in unsigned long long id,
in jsval participants,
in jsval timestamp,
in unsigned long long timestamp,
in DOMString lastMessageSubject,
in DOMString body,
in unsigned long long unreadCount,

View File

@ -1,42 +0,0 @@
/* -*- 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/. */
#ifndef MessageUtils_h
#define MessageUtils_h
/**
* A helper function to convert the JS value to an integer value for time.
*
* @params aCx
* The JS context.
* @params aTime
* Can be an object or a number.
* @params aReturn
* The integer value to return.
* @return NS_OK if the convertion succeeds.
*/
static nsresult
convertTimeToInt(JSContext* aCx, const JS::Value& aTime, uint64_t& aReturn)
{
if (aTime.isObject()) {
JS::Rooted<JSObject*> timestampObj(aCx, &aTime.toObject());
if (!JS_ObjectIsDate(aCx, timestampObj)) {
return NS_ERROR_INVALID_ARG;
}
aReturn = js_DateGetMsecSinceEpoch(timestampObj);
} else {
if (!aTime.isNumber()) {
return NS_ERROR_INVALID_ARG;
}
double number = aTime.toNumber();
if (static_cast<uint64_t>(number) != number) {
return NS_ERROR_INVALID_ARG;
}
aReturn = static_cast<uint64_t>(number);
}
return NS_OK;
}
#endif

View File

@ -16,7 +16,6 @@
#include "mozilla/dom/mobilemessage/SmsTypes.h"
#include "nsDOMFile.h"
#include "nsCxPusher.h"
#include "MessageUtils.h"
using namespace mozilla::dom::mobilemessage;
@ -167,22 +166,22 @@ MmsMessage::MmsMessage(const mobilemessage::MmsMessageData& aData)
}
/* static */ nsresult
MmsMessage::Create(int32_t aId,
uint64_t aThreadId,
const nsAString& aIccId,
const nsAString& aDelivery,
const JS::Value& aDeliveryInfo,
const nsAString& aSender,
const JS::Value& aReceivers,
const JS::Value& aTimestamp,
const JS::Value& aSentTimestamp,
bool aRead,
const nsAString& aSubject,
const nsAString& aSmil,
const JS::Value& aAttachments,
const JS::Value& aExpiryDate,
bool aIsReadReportRequested,
JSContext* aCx,
MmsMessage::Create(int32_t aId,
uint64_t aThreadId,
const nsAString& aIccId,
const nsAString& aDelivery,
const JS::Value& aDeliveryInfo,
const nsAString& aSender,
const JS::Value& aReceivers,
uint64_t aTimestamp,
uint64_t aSentTimestamp,
bool aRead,
const nsAString& aSubject,
const nsAString& aSmil,
const JS::Value& aAttachments,
uint64_t aExpiryDate,
bool aIsReadReportRequested,
JSContext* aCx,
nsIDOMMozMmsMessage** aMessage)
{
*aMessage = nullptr;
@ -255,16 +254,6 @@ MmsMessage::Create(int32_t aId,
receivers.AppendElement(receiverStr);
}
// Set |timestamp|.
uint64_t timestamp;
nsresult rv = convertTimeToInt(aCx, aTimestamp, timestamp);
NS_ENSURE_SUCCESS(rv, rv);
// Set |sentTimestamp|.
uint64_t sentTimestamp;
rv = convertTimeToInt(aCx, aSentTimestamp, sentTimestamp);
NS_ENSURE_SUCCESS(rv, rv);
// Set |attachments|.
if (!aAttachments.isObject()) {
return NS_ERROR_INVALID_ARG;
@ -291,11 +280,6 @@ MmsMessage::Create(int32_t aId,
attachments.AppendElement(attachment);
}
// Set |expiryDate|.
uint64_t expiryDate;
rv = convertTimeToInt(aCx, aExpiryDate, expiryDate);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMMozMmsMessage> message = new MmsMessage(aId,
aThreadId,
aIccId,
@ -303,13 +287,13 @@ MmsMessage::Create(int32_t aId,
deliveryInfo,
aSender,
receivers,
timestamp,
sentTimestamp,
aTimestamp,
aSentTimestamp,
aRead,
aSubject,
aSmil,
attachments,
expiryDate,
aExpiryDate,
aIsReadReportRequested);
message.forget(aMessage);
return NS_OK;

View File

@ -41,40 +41,40 @@ public:
{}
};
MmsMessage(int32_t aId,
uint64_t aThreadId,
const nsAString& aIccId,
mobilemessage::DeliveryState aDelivery,
const nsTArray<MmsDeliveryInfo>& aDeliveryInfo,
const nsAString& aSender,
const nsTArray<nsString>& aReceivers,
uint64_t aTimestamp,
uint64_t aSentTimestamp,
bool aRead,
const nsAString& aSubject,
const nsAString& aSmil,
const nsTArray<Attachment>& aAttachments,
uint64_t aExpiryDate,
bool aReadReportRequested);
MmsMessage(int32_t aId,
uint64_t aThreadId,
const nsAString& aIccId,
mobilemessage::DeliveryState aDelivery,
const nsTArray<MmsDeliveryInfo>& aDeliveryInfo,
const nsAString& aSender,
const nsTArray<nsString>& aReceivers,
uint64_t aTimestamp,
uint64_t aSentTimestamp,
bool aRead,
const nsAString& aSubject,
const nsAString& aSmil,
const nsTArray<Attachment>& aAttachments,
uint64_t aExpiryDate,
bool aReadReportRequested);
MmsMessage(const mobilemessage::MmsMessageData& aData);
static nsresult Create(int32_t aId,
uint64_t aThreadId,
const nsAString& aIccId,
const nsAString& aDelivery,
const JS::Value& aDeliveryInfo,
const nsAString& aSender,
const JS::Value& aReceivers,
const JS::Value& aTimestamp,
const JS::Value& aSentTimestamp,
bool aRead,
const nsAString& aSubject,
const nsAString& aSmil,
const JS::Value& aAttachments,
const JS::Value& aExpiryDate,
bool aReadReportRequested,
JSContext* aCx,
static nsresult Create(int32_t aId,
uint64_t aThreadId,
const nsAString& aIccId,
const nsAString& aDelivery,
const JS::Value& aDeliveryInfo,
const nsAString& aSender,
const JS::Value& aReceivers,
uint64_t aTimestamp,
uint64_t aSentTimestamp,
bool aRead,
const nsAString& aSubject,
const nsAString& aSmil,
const JS::Value& aAttachments,
uint64_t aExpiryDate,
bool aReadReportRequested,
JSContext* aCx,
nsIDOMMozMmsMessage** aMessage);
bool GetData(ContentParent* aParent,
@ -82,21 +82,21 @@ public:
private:
int32_t mId;
uint64_t mThreadId;
nsString mIccId;
mobilemessage::DeliveryState mDelivery;
nsTArray<MmsDeliveryInfo> mDeliveryInfo;
nsString mSender;
nsTArray<nsString> mReceivers;
uint64_t mTimestamp;
uint64_t mSentTimestamp;
bool mRead;
nsString mSubject;
nsString mSmil;
nsTArray<Attachment> mAttachments;
uint64_t mExpiryDate;
bool mReadReportRequested;
int32_t mId;
uint64_t mThreadId;
nsString mIccId;
mobilemessage::DeliveryState mDelivery;
nsTArray<MmsDeliveryInfo> mDeliveryInfo;
nsString mSender;
nsTArray<nsString> mReceivers;
uint64_t mTimestamp;
uint64_t mSentTimestamp;
bool mRead;
nsString mSubject;
nsString mSmil;
nsTArray<Attachment> mAttachments;
uint64_t mExpiryDate;
bool mReadReportRequested;
};
} // namespace dom

View File

@ -38,10 +38,10 @@ MobileMessageService::CreateSmsMessage(int32_t aId,
const nsAString& aReceiver,
const nsAString& aBody,
const nsAString& aMessageClass,
JS::Handle<JS::Value> aTimestamp,
JS::Handle<JS::Value> aSentTimestamp,
JS::Handle<JS::Value> aDeliveryTimestamp,
const bool aRead,
uint64_t aTimestamp,
uint64_t aSentTimestamp,
uint64_t aDeliveryTimestamp,
bool aRead,
JSContext* aCx,
nsIDOMMozSmsMessage** aMessage)
{
@ -63,22 +63,22 @@ MobileMessageService::CreateSmsMessage(int32_t aId,
}
NS_IMETHODIMP
MobileMessageService::CreateMmsMessage(int32_t aId,
uint64_t aThreadId,
const nsAString& aIccId,
const nsAString& aDelivery,
MobileMessageService::CreateMmsMessage(int32_t aId,
uint64_t aThreadId,
const nsAString& aIccId,
const nsAString& aDelivery,
JS::Handle<JS::Value> aDeliveryInfo,
const nsAString& aSender,
const nsAString& aSender,
JS::Handle<JS::Value> aReceivers,
JS::Handle<JS::Value> aTimestamp,
JS::Handle<JS::Value> aSentTimestamp,
bool aRead,
const nsAString& aSubject,
const nsAString& aSmil,
uint64_t aTimestamp,
uint64_t aSentTimestamp,
bool aRead,
const nsAString& aSubject,
const nsAString& aSmil,
JS::Handle<JS::Value> aAttachments,
JS::Handle<JS::Value> aExpiryDate,
bool aReadReportRequested,
JSContext* aCx,
uint64_t aExpiryDate,
bool aReadReportRequested,
JSContext* aCx,
nsIDOMMozMmsMessage** aMessage)
{
return MmsMessage::Create(aId,
@ -115,7 +115,7 @@ MobileMessageService::CreateSmsSegmentInfo(int32_t aSegments,
NS_IMETHODIMP
MobileMessageService::CreateThread(uint64_t aId,
JS::Handle<JS::Value> aParticipants,
JS::Handle<JS::Value> aTimestamp,
uint64_t aTimestamp,
const nsAString& aLastMessageSubject,
const nsAString& aBody,
uint64_t aUnreadCount,

View File

@ -28,12 +28,12 @@ NS_IMPL_ADDREF(MobileMessageThread)
NS_IMPL_RELEASE(MobileMessageThread)
/* static */ nsresult
MobileMessageThread::Create(const uint64_t aId,
MobileMessageThread::Create(uint64_t aId,
const JS::Value& aParticipants,
const JS::Value& aTimestamp,
uint64_t aTimestamp,
const nsAString& aLastMessageSubject,
const nsAString& aBody,
const uint64_t aUnreadCount,
uint64_t aUnreadCount,
const nsAString& aLastMessageType,
JSContext* aCx,
nsIDOMMozMobileMessageThread** aThread)
@ -76,25 +76,10 @@ MobileMessageThread::Create(const uint64_t aId,
}
}
// We support both a Date object and a millisecond timestamp as a number.
if (aTimestamp.isObject()) {
JS::Rooted<JSObject*> obj(aCx, &aTimestamp.toObject());
if (!JS_ObjectIsDate(aCx, obj)) {
return NS_ERROR_INVALID_ARG;
}
data.timestamp() = js_DateGetMsecSinceEpoch(obj);
} else {
if (!aTimestamp.isNumber()) {
return NS_ERROR_INVALID_ARG;
}
double number = aTimestamp.toNumber();
if (static_cast<uint64_t>(number) != number) {
return NS_ERROR_INVALID_ARG;
}
data.timestamp() = static_cast<uint64_t>(number);
}
// Set |timestamp|;
data.timestamp() = aTimestamp;
// Set |aLastMessageType|.
// Set |lastMessageType|.
{
MessageType lastMessageType;
if (aLastMessageType.Equals(MESSAGE_TYPE_SMS)) {
@ -112,12 +97,12 @@ MobileMessageThread::Create(const uint64_t aId,
return NS_OK;
}
MobileMessageThread::MobileMessageThread(const uint64_t aId,
MobileMessageThread::MobileMessageThread(uint64_t aId,
const nsTArray<nsString>& aParticipants,
const uint64_t aTimestamp,
uint64_t aTimestamp,
const nsString& aLastMessageSubject,
const nsString& aBody,
const uint64_t aUnreadCount,
uint64_t aUnreadCount,
MessageType aLastMessageType)
: mData(aId, aParticipants, aTimestamp, aLastMessageSubject, aBody,
aUnreadCount, aLastMessageType)

View File

@ -23,22 +23,22 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMMOZMOBILEMESSAGETHREAD
MobileMessageThread(const uint64_t aId,
MobileMessageThread(uint64_t aId,
const nsTArray<nsString>& aParticipants,
const uint64_t aTimestamp,
uint64_t aTimestamp,
const nsString& aLastMessageSubject,
const nsString& aBody,
const uint64_t aUnreadCount,
uint64_t aUnreadCount,
mobilemessage::MessageType aLastMessageType);
MobileMessageThread(const ThreadData& aData);
static nsresult Create(const uint64_t aId,
static nsresult Create(uint64_t aId,
const JS::Value& aParticipants,
const JS::Value& aTimestamp,
uint64_t aTimestamp,
const nsAString& aLastMessageSubject,
const nsAString& aBody,
const uint64_t aUnreadCount,
uint64_t aUnreadCount,
const nsAString& aLastMessageType,
JSContext* aCx,
nsIDOMMozMobileMessageThread** aThread);

View File

@ -8,7 +8,6 @@
#include "jsapi.h" // For OBJECT_TO_JSVAL and JS_NewDateObjectMsec
#include "jsfriendapi.h" // For js_DateGetMsecSinceEpoch
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
#include "MessageUtils.h"
using namespace mozilla::dom::mobilemessage;
@ -60,10 +59,10 @@ SmsMessage::Create(int32_t aId,
const nsAString& aReceiver,
const nsAString& aBody,
const nsAString& aMessageClass,
const JS::Value& aTimestamp,
const JS::Value& aSentTimestamp,
const JS::Value& aDeliveryTimestamp,
const bool aRead,
uint64_t aTimestamp,
uint64_t aSentTimestamp,
uint64_t aDeliveryTimestamp,
bool aRead,
JSContext* aCx,
nsIDOMMozSmsMessage** aMessage)
{
@ -119,16 +118,13 @@ SmsMessage::Create(int32_t aId,
}
// Set |timestamp|.
nsresult rv = convertTimeToInt(aCx, aTimestamp, data.timestamp());
NS_ENSURE_SUCCESS(rv, rv);
data.timestamp() = aTimestamp;
// Set |sentTimestamp|.
rv = convertTimeToInt(aCx, aSentTimestamp, data.sentTimestamp());
NS_ENSURE_SUCCESS(rv, rv);
data.sentTimestamp() = aSentTimestamp;
// Set |deliveryTimestamp|.
rv = convertTimeToInt(aCx, aDeliveryTimestamp, data.deliveryTimestamp());
NS_ENSURE_SUCCESS(rv, rv);
data.deliveryTimestamp() = aDeliveryTimestamp;
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(data);
message.swap(*aMessage);

View File

@ -34,6 +34,7 @@ public:
uint64_t aSentTimestamp,
uint64_t aDeliveryTimestamp,
bool aRead);
SmsMessage(const mobilemessage::SmsMessageData& aData);
static nsresult Create(int32_t aId,
@ -45,10 +46,10 @@ public:
const nsAString& aReceiver,
const nsAString& aBody,
const nsAString& aMessageClass,
const JS::Value& aTimestamp,
const JS::Value& aSentTimestamp,
const JS::Value& aDeliveryTimestamp,
const bool aRead,
uint64_t aTimestamp,
uint64_t aSentTimestamp,
uint64_t aDeliveryTimestamp,
bool aRead,
JSContext* aCx,
nsIDOMMozSmsMessage** aMessage);
const mobilemessage::SmsMessageData& GetData() const;

View File

@ -37,10 +37,10 @@ SmsService::GetSegmentInfoForText(const nsAString& aText,
}
NS_IMETHODIMP
SmsService::Send(uint32_t aServiceId,
SmsService::Send(uint32_t aServiceId,
const nsAString& aNumber,
const nsAString& aMessage,
const bool aSilent,
bool aSilent,
nsIMobileMessageCallback* aRequest)
{
if (!AndroidBridge::Bridge()) {

View File

@ -97,10 +97,10 @@ SmsService::GetSegmentInfoForText(const nsAString& aText,
}
NS_IMETHODIMP
SmsService::Send(uint32_t aServiceId,
SmsService::Send(uint32_t aServiceId,
const nsAString& aNumber,
const nsAString& aMessage,
const bool aSilent,
bool aSilent,
nsIMobileMessageCallback* aRequest)
{
nsCOMPtr<nsIRadioInterface> radioInterface;

View File

@ -165,7 +165,7 @@ NS_IMETHODIMP
SmsIPCService::Send(uint32_t aServiceId,
const nsAString& aNumber,
const nsAString& aMessage,
const bool aSilent,
bool aSilent,
nsIMobileMessageCallback* aRequest)
{
return SendRequest(SendMessageRequest(SendSmsMessageRequest(aServiceId,

View File

@ -94,12 +94,12 @@ struct SmsFilterData
struct ThreadData
{
uint64_t id;
nsString[] participants;
uint64_t timestamp;
nsString lastMessageSubject;
nsString body;
uint64_t unreadCount;
uint64_t id;
nsString[] participants;
uint64_t timestamp;
nsString lastMessageSubject;
nsString body;
uint64_t unreadCount;
MessageType lastMessageType;
};