Skip to content

Commit

Permalink
Bug 921918 - 2/4: DOM implementation. r=khuey
Browse files Browse the repository at this point in the history
  • Loading branch information
Chia-hung Tai committed Nov 25, 2013
1 parent 5e37b32 commit 787a113
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 0 deletions.
2 changes: 2 additions & 0 deletions content/base/src/nsGkAtomList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions dom/messages/SystemMessagePermissionsChecker.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ this.SystemMessagePermissionsTable = {
"sms-delivery-success": {
"sms": []
},
"sms-read-success": {
"sms": []
},
"sms-received": {
"sms": []
},
Expand Down
2 changes: 2 additions & 0 deletions dom/mobilemessage/src/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions dom/mobilemessage/src/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
75 changes: 75 additions & 0 deletions dom/mobilemessage/src/MmsMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions dom/mobilemessage/src/MobileMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
20 changes: 20 additions & 0 deletions dom/mobilemessage/src/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*/
Expand Down
4 changes: 4 additions & 0 deletions dom/mobilemessage/src/ipc/PSms.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions dom/mobilemessage/src/ipc/SmsChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions dom/mobilemessage/src/ipc/SmsChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class SmsChild : public PSmsChild
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;

Expand Down
28 changes: 28 additions & 0 deletions dom/mobilemessage/src/ipc/SmsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions dom/mobilemessage/src/ipc/SmsTypes.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -51,6 +52,8 @@ struct MmsDeliveryInfoData
nsString receiver;
DeliveryStatus deliveryStatus;
uint64_t deliveryTimestamp;
ReadStatus readStatus;
uint64_t readTimestamp;
};

struct MmsMessageData
Expand Down

0 comments on commit 787a113

Please sign in to comment.