Bug 850680 - B2G MMS: broadcast "sms-received" and "sms-sent" system messages (part 2, broadcast system messages). r=vicamo

This commit is contained in:
Gene Lian 2013-03-22 20:16:43 +08:00
parent 0cb190b727
commit bba20c695d
2 changed files with 73 additions and 23 deletions

View File

@ -80,6 +80,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "gMobileMessageService",
"@mozilla.org/mobilemessage/mobilemessageservice;1",
"nsIMobileMessageService");
XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
"@mozilla.org/system-message-internal;1",
"nsISystemMessagesInternal");
XPCOMUtils.defineLazyGetter(this, "MMS", function () {
let MMS = {};
Cu.import("resource://gre/modules/MmsPduHelper.jsm", MMS);
@ -1001,6 +1005,36 @@ MmsService.prototype = {
transaction.run(callback);
},
/**
* A helper to broadcast the system message to launch registered apps
* like Costcontrol, Notification and Message app... etc.
*
* @param aName
* The system message name.
* @param aDomMessage
* The nsIDOMMozMmsMessage object.
*/
broadcastMmsSystemMessage: function broadcastMmsSystemMessage(aName, aDomMessage) {
debug("Broadcasting the MMS system message: " + aName);
// Sadly we cannot directly broadcast the aDomMessage object
// because the system message mechamism will rewrap the object
// based on the content window, which needs to know the properties.
gSystemMessenger.broadcastMessage(aName, {
type: aDomMessage.type,
id: aDomMessage.id,
delivery: aDomMessage.delivery,
deliveryStatus: aDomMessage.deliveryStatus,
sender: aDomMessage.sender,
receivers: aDomMessage.receivers,
timestamp: aDomMessage.timestamp.getTime(),
read: aDomMessage.read,
subject: aDomMessage.subject,
smil: aDomMessage.smil,
attachments: aDomMessage.attachments
});
},
/**
* Handle incoming M-Notification.ind PDU.
*
@ -1033,6 +1067,9 @@ MmsService.prototype = {
return;
}
// Broadcasting an 'sms-received' system message to open apps.
this.broadcastMmsSystemMessage("sms-received", domMessage);
// Notifying observers a new notification indication is coming.
Services.obs.notifyObservers(domMessage, kMmsReceivedObserverTopic, null);
@ -1104,6 +1141,9 @@ MmsService.prototype = {
return;
}
// Broadcasting an 'sms-received' system message to open apps.
this.broadcastMmsSystemMessage("sms-received", domMessage);
// Notifying observers an MMS message is received.
Services.obs.notifyObservers(domMessage, kMmsReceivedObserverTopic, null);
}).bind(this)
@ -1250,6 +1290,8 @@ MmsService.prototype = {
Services.obs.notifyObservers(aDomMessage, kMmsFailedObserverTopic, null);
return;
}
self.broadcastMmsSystemMessage("sms-sent", aDomMessage);
aRequest.notifyMessageSent(aDomMessage);
Services.obs.notifyObservers(aDomMessage, kMmsSentObserverTopic, null);
});

View File

@ -1487,6 +1487,35 @@ RadioInterfaceLayer.prototype = {
0, options);
},
/**
* A helper to broadcast the system message to launch registered apps
* like Costcontrol, Notification and Message app... etc.
*
* @param aName
* The system message name.
* @param aDomMessage
* The nsIDOMMozSmsMessage object.
*/
broadcastSmsSystemMessage: function broadcastSmsSystemMessage(aName, aDomMessage) {
debug("Broadcasting the SMS system message: " + aName);
// Sadly we cannot directly broadcast the aDomMessage object
// because the system message mechamism will rewrap the object
// based on the content window, which needs to know the properties.
gSystemMessenger.broadcastMessage(aName, {
type: aDomMessage.type,
id: aDomMessage.id,
delivery: aDomMessage.delivery,
deliveryStatus: aDomMessage.deliveryStatus,
sender: aDomMessage.sender,
receiver: aDomMessage.receiver,
body: aDomMessage.body,
messageClass: aDomMessage.messageClass,
timestamp: aDomMessage.timestamp.getTime(),
read: aDomMessage.read
});
},
portAddressedSmsApps: null,
handleSmsReceived: function handleSmsReceived(message) {
debug("handleSmsReceived: " + JSON.stringify(message));
@ -1547,18 +1576,7 @@ RadioInterfaceLayer.prototype = {
return;
}
gSystemMessenger.broadcastMessage("sms-received", {
id: message.id,
delivery: DOM_MOBILE_MESSAGE_DELIVERY_RECEIVED,
deliveryStatus: RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS,
sender: message.sender,
receiver: message.receiver,
body: message.fullBody,
messageClass: message.messageClass,
timestamp: message.timestamp,
read: false
});
this.broadcastSmsSystemMessage("sms-received", domMessage);
Services.obs.notifyObservers(domMessage, kSmsReceivedObserverTopic, null);
}.bind(this);
@ -1618,17 +1636,7 @@ RadioInterfaceLayer.prototype = {
options.sms.deliveryStatus,
function notifyResult(rv, domMessage) {
// TODO bug 832140 handle !Components.isSuccessCode(rv)
gSystemMessenger.broadcastMessage("sms-sent", {
id: options.sms.id,
delivery: DOM_MOBILE_MESSAGE_DELIVERY_SENT,
deliveryStatus: options.sms.deliveryStatus,
sender: message.sender || null,
receiver: options.sms.receiver,
body: options.sms.body,
messageClass: options.sms.messageClass,
timestamp: options.sms.timestamp,
read: true
});
this.broadcastSmsSystemMessage("sms-sent", domMessage);
if (!options.requestStatusReport) {
// No more used if STATUS-REPORT not requested.