Bug 921918 - 2/4: DOM implementation. r=khuey

This commit is contained in:
Chia-hung Tai 2013-11-25 18:54:59 +08:00
parent 9b86257458
commit fd767635b0
12 changed files with 180 additions and 0 deletions

View File

@ -771,6 +771,8 @@ GK_ATOM(onpopuphiding, "onpopuphiding")
GK_ATOM(onpopupshowing, "onpopupshowing")
GK_ATOM(onpopupshown, "onpopupshown")
GK_ATOM(onradiostatechange, "onradiostatechange")
GK_ATOM(onreaderror, "onreaderror")
GK_ATOM(onreadsuccess, "onreadsuccess")
GK_ATOM(onreadystatechange, "onreadystatechange")
GK_ATOM(onreceived, "onreceived")
GK_ATOM(onremoteheld, "onremoteheld")

View File

@ -74,6 +74,9 @@ this.SystemMessagePermissionsTable = {
"sms-delivery-success": {
"sms": []
},
"sms-read-success": {
"sms": []
},
"sms-received": {
"sms": []
},

View File

@ -15,6 +15,8 @@ const char* kSmsFailedObserverTopic = "sms-failed";
const char* kSmsDeliverySuccessObserverTopic = "sms-delivery-success";
const char* kSmsDeliveryErrorObserverTopic = "sms-delivery-error";
const char* kSilentSmsReceivedObserverTopic = "silent-sms-received";
const char* kSmsReadSuccessObserverTopic = "sms-read-success";
const char* kSmsReadErrorObserverTopic = "sms-read-error";
} // namespace mobilemessage
} // namespace dom

View File

@ -19,6 +19,8 @@ extern const char* kSmsFailedObserverTopic;
extern const char* kSmsDeliverySuccessObserverTopic;
extern const char* kSmsDeliveryErrorObserverTopic;
extern const char* kSilentSmsReceivedObserverTopic;
extern const char* kSmsReadSuccessObserverTopic;
extern const char* kSmsReadErrorObserverTopic;
#define DELIVERY_RECEIVED NS_LITERAL_STRING("received")
#define DELIVERY_SENDING NS_LITERAL_STRING("sending")
@ -33,6 +35,11 @@ extern const char* kSilentSmsReceivedObserverTopic;
#define DELIVERY_STATUS_REJECTED NS_LITERAL_STRING("rejected")
#define DELIVERY_STATUS_MANUAL NS_LITERAL_STRING("manual")
#define READ_STATUS_NOT_APPLICABLE NS_LITERAL_STRING("not-applicable")
#define READ_STATUS_SUCCESS NS_LITERAL_STRING("success")
#define READ_STATUS_PENDING NS_LITERAL_STRING("pending")
#define READ_STATUS_ERROR NS_LITERAL_STRING("error")
#define MESSAGE_CLASS_NORMAL NS_LITERAL_STRING("normal")
#define MESSAGE_CLASS_CLASS_0 NS_LITERAL_STRING("class-0")
#define MESSAGE_CLASS_CLASS_1 NS_LITERAL_STRING("class-1")

View File

@ -145,6 +145,40 @@ MmsMessage::MmsMessage(const mobilemessage::MmsMessageData& aData)
}
}
// 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|.
info.readTimestamp = JSVAL_NULL;
if (infoData.readTimestamp() != 0) {
AutoJSContext cx;
JS::Rooted<JSObject*>
dateObj(cx, JS_NewDateObjectMsec(cx, infoData.readTimestamp()));
if (!dateObj) {
NS_WARNING("MmsMessage: Unable to create Data for readTimestamp.");
} else {
info.readTimestamp = OBJECT_TO_JSVAL(dateObj);
}
}
mDeliveryInfo.AppendElement(info);
}
}
@ -376,6 +410,29 @@ MmsMessage::GetData(ContentParent* aParent,
convertTimeToInt(cx, info.deliveryTimestamp, infoData.deliveryTimestamp());
}
// 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|.
if (info.readTimestamp == JSVAL_NULL) {
infoData.readTimestamp() = 0;
} else {
AutoJSContext cx;
convertTimeToInt(cx, info.readTimestamp, infoData.readTimestamp());
}
aData.deliveryInfo().AppendElement(infoData);
}
@ -521,6 +578,24 @@ MmsMessage::GetDeliveryInfo(JSContext* aCx, JS::Value* aDeliveryInfo)
return NS_ERROR_FAILURE;
}
// 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,
NULL, NULL, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
// Get |info.readTimestamp|.
if (!JS_DefineProperty(aCx, infoJsObj, "readTimestamp", info.readTimestamp,
NULL, NULL, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
tmpJsVal = OBJECT_TO_JSVAL(infoJsObj);
if (!JS_SetElement(aCx, deliveryInfo, i, &tmpJsVal)) {
return NS_ERROR_FAILURE;

View File

@ -38,6 +38,8 @@
#define FAILED_EVENT_NAME NS_LITERAL_STRING("failed")
#define DELIVERY_SUCCESS_EVENT_NAME NS_LITERAL_STRING("deliverysuccess")
#define DELIVERY_ERROR_EVENT_NAME NS_LITERAL_STRING("deliveryerror")
#define READ_SUCCESS_EVENT_NAME NS_LITERAL_STRING("readsuccess")
#define READ_ERROR_EVENT_NAME NS_LITERAL_STRING("readerror")
using namespace mozilla::dom::mobilemessage;
@ -62,6 +64,8 @@ NS_IMPL_EVENT_HANDLER(MobileMessageManager, sent)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, failed)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, deliverysuccess)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, deliveryerror)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, readsuccess)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, readerror)
void
MobileMessageManager::Init(nsPIDOMWindow *aWindow)
@ -81,6 +85,8 @@ MobileMessageManager::Init(nsPIDOMWindow *aWindow)
obs->AddObserver(this, kSmsFailedObserverTopic, false);
obs->AddObserver(this, kSmsDeliverySuccessObserverTopic, false);
obs->AddObserver(this, kSmsDeliveryErrorObserverTopic, false);
obs->AddObserver(this, kSmsReadSuccessObserverTopic, false);
obs->AddObserver(this, kSmsReadErrorObserverTopic, false);
}
void
@ -99,6 +105,8 @@ MobileMessageManager::Shutdown()
obs->RemoveObserver(this, kSmsFailedObserverTopic);
obs->RemoveObserver(this, kSmsDeliverySuccessObserverTopic);
obs->RemoveObserver(this, kSmsDeliveryErrorObserverTopic);
obs->RemoveObserver(this, kSmsReadSuccessObserverTopic);
obs->RemoveObserver(this, kSmsReadErrorObserverTopic);
}
NS_IMETHODIMP
@ -536,6 +544,14 @@ MobileMessageManager::Observe(nsISupports* aSubject, const char* aTopic,
return DispatchTrustedSmsEventToSelf(aTopic, DELIVERY_ERROR_EVENT_NAME, aSubject);
}
if (!strcmp(aTopic, kSmsReadSuccessObserverTopic)) {
return DispatchTrustedSmsEventToSelf(aTopic, READ_SUCCESS_EVENT_NAME, aSubject);
}
if (!strcmp(aTopic, kSmsReadErrorObserverTopic)) {
return DispatchTrustedSmsEventToSelf(aTopic, READ_ERROR_EVENT_NAME, aSubject);
}
return NS_OK;
}

View File

@ -38,6 +38,16 @@ enum DeliveryStatus {
eDeliveryStatus_EndGuard
};
// For MmsMessageData.readStatus.
enum ReadStatus {
eReadStatus_NotApplicable = 0,
eReadStatus_Success,
eReadStatus_Pending,
eReadStatus_Error,
// This state should stay at the end.
eReadStatus_EndGuard
};
// For {Mms,Sms}FilterData.read.
enum ReadState {
eReadState_Unknown = -1,
@ -92,6 +102,16 @@ struct ParamTraits<mozilla::dom::mobilemessage::DeliveryStatus>
mozilla::dom::mobilemessage::eDeliveryStatus_EndGuard>
{};
/**
* Read status serializer.
*/
template <>
struct ParamTraits<mozilla::dom::mobilemessage::ReadStatus>
: public EnumSerializer<mozilla::dom::mobilemessage::ReadStatus,
mozilla::dom::mobilemessage::eReadStatus_NotApplicable,
mozilla::dom::mobilemessage::eReadStatus_EndGuard>
{};
/**
* Read state serializer.
*/

View File

@ -118,6 +118,10 @@ child:
NotifyReceivedSilentMessage(MobileMessageData aMessageData);
NotifyReadSuccessMessage(MobileMessageData aMessageData);
NotifyReadErrorMessage(MobileMessageData aMessageData);
parent:
/**
* Sent when the child no longer needs to use sms.

View File

@ -118,6 +118,20 @@ SmsChild::RecvNotifyReceivedSilentMessage(const MobileMessageData& aData)
return true;
}
bool
SmsChild::RecvNotifyReadSuccessMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsReadSuccessObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifyReadErrorMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsReadErrorObserverTopic, aData);
return true;
}
PSmsRequestChild*
SmsChild::AllocPSmsRequestChild(const IPCSmsRequest& aRequest)
{

View File

@ -58,6 +58,12 @@ protected:
virtual bool
RecvNotifyReceivedSilentMessage(const MobileMessageData& aMessage) MOZ_OVERRIDE;
virtual bool
RecvNotifyReadSuccessMessage(const MobileMessageData& aMessage) MOZ_OVERRIDE;
virtual bool
RecvNotifyReadErrorMessage(const MobileMessageData& aMessage) MOZ_OVERRIDE;
virtual PSmsRequestChild*
AllocPSmsRequestChild(const IPCSmsRequest& aRequest) MOZ_OVERRIDE;

View File

@ -153,6 +153,8 @@ SmsParent::SmsParent()
obs->AddObserver(this, kSmsDeliverySuccessObserverTopic, false);
obs->AddObserver(this, kSmsDeliveryErrorObserverTopic, false);
obs->AddObserver(this, kSilentSmsReceivedObserverTopic, false);
obs->AddObserver(this, kSmsReadSuccessObserverTopic, false);
obs->AddObserver(this, kSmsReadErrorObserverTopic, false);
}
void
@ -171,6 +173,8 @@ SmsParent::ActorDestroy(ActorDestroyReason why)
obs->RemoveObserver(this, kSmsDeliverySuccessObserverTopic);
obs->RemoveObserver(this, kSmsDeliveryErrorObserverTopic);
obs->RemoveObserver(this, kSilentSmsReceivedObserverTopic);
obs->RemoveObserver(this, kSmsReadSuccessObserverTopic);
obs->RemoveObserver(this, kSmsReadErrorObserverTopic);
}
NS_IMETHODIMP
@ -272,6 +276,30 @@ SmsParent::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
if (!strcmp(aTopic, kSmsReadSuccessObserverTopic)) {
MobileMessageData msgData;
if (!GetMobileMessageDataFromMessage(aSubject, msgData)) {
NS_ERROR("Got a 'sms-read-success' topic without a valid message!");
return NS_OK;
}
unused << SendNotifyReadSuccessMessage(msgData);
return NS_OK;
}
if (!strcmp(aTopic, kSmsReadErrorObserverTopic)) {
MobileMessageData msgData;
if (!GetMobileMessageDataFromMessage(aSubject, msgData)) {
NS_ERROR("Got a 'sms-read-error' topic without a valid message!");
return NS_OK;
}
unused << SendNotifyReadErrorMessage(msgData);
return NS_OK;
}
return NS_OK;
}

View File

@ -9,6 +9,7 @@ include protocol PBlob;
using DeliveryState from "mozilla/dom/mobilemessage/Types.h";
using DeliveryStatus from "mozilla/dom/mobilemessage/Types.h";
using MessageClass from "mozilla/dom/mobilemessage/Types.h";
using ReadStatus from "mozilla/dom/mobilemessage/Types.h";
using ReadState from "mozilla/dom/mobilemessage/Types.h";
using MessageType from "mozilla/dom/mobilemessage/Types.h";
@ -51,6 +52,8 @@ struct MmsDeliveryInfoData
nsString receiver;
DeliveryStatus deliveryStatus;
uint64_t deliveryTimestamp;
ReadStatus readStatus;
uint64_t readTimestamp;
};
struct MmsMessageData