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", "@mozilla.org/mobilemessage/mobilemessageservice;1",
"nsIMobileMessageService"); "nsIMobileMessageService");
XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
"@mozilla.org/system-message-internal;1",
"nsISystemMessagesInternal");
XPCOMUtils.defineLazyGetter(this, "MMS", function () { XPCOMUtils.defineLazyGetter(this, "MMS", function () {
let MMS = {}; let MMS = {};
Cu.import("resource://gre/modules/MmsPduHelper.jsm", MMS); Cu.import("resource://gre/modules/MmsPduHelper.jsm", MMS);
@ -1001,6 +1005,36 @@ MmsService.prototype = {
transaction.run(callback); 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. * Handle incoming M-Notification.ind PDU.
* *
@ -1033,6 +1067,9 @@ MmsService.prototype = {
return; return;
} }
// Broadcasting an 'sms-received' system message to open apps.
this.broadcastMmsSystemMessage("sms-received", domMessage);
// Notifying observers a new notification indication is coming. // Notifying observers a new notification indication is coming.
Services.obs.notifyObservers(domMessage, kMmsReceivedObserverTopic, null); Services.obs.notifyObservers(domMessage, kMmsReceivedObserverTopic, null);
@ -1104,6 +1141,9 @@ MmsService.prototype = {
return; return;
} }
// Broadcasting an 'sms-received' system message to open apps.
this.broadcastMmsSystemMessage("sms-received", domMessage);
// Notifying observers an MMS message is received. // Notifying observers an MMS message is received.
Services.obs.notifyObservers(domMessage, kMmsReceivedObserverTopic, null); Services.obs.notifyObservers(domMessage, kMmsReceivedObserverTopic, null);
}).bind(this) }).bind(this)
@ -1250,6 +1290,8 @@ MmsService.prototype = {
Services.obs.notifyObservers(aDomMessage, kMmsFailedObserverTopic, null); Services.obs.notifyObservers(aDomMessage, kMmsFailedObserverTopic, null);
return; return;
} }
self.broadcastMmsSystemMessage("sms-sent", aDomMessage);
aRequest.notifyMessageSent(aDomMessage); aRequest.notifyMessageSent(aDomMessage);
Services.obs.notifyObservers(aDomMessage, kMmsSentObserverTopic, null); Services.obs.notifyObservers(aDomMessage, kMmsSentObserverTopic, null);
}); });

View File

@ -1487,6 +1487,35 @@ RadioInterfaceLayer.prototype = {
0, options); 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, portAddressedSmsApps: null,
handleSmsReceived: function handleSmsReceived(message) { handleSmsReceived: function handleSmsReceived(message) {
debug("handleSmsReceived: " + JSON.stringify(message)); debug("handleSmsReceived: " + JSON.stringify(message));
@ -1547,18 +1576,7 @@ RadioInterfaceLayer.prototype = {
return; return;
} }
gSystemMessenger.broadcastMessage("sms-received", { this.broadcastSmsSystemMessage("sms-received", domMessage);
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
});
Services.obs.notifyObservers(domMessage, kSmsReceivedObserverTopic, null); Services.obs.notifyObservers(domMessage, kSmsReceivedObserverTopic, null);
}.bind(this); }.bind(this);
@ -1618,17 +1636,7 @@ RadioInterfaceLayer.prototype = {
options.sms.deliveryStatus, options.sms.deliveryStatus,
function notifyResult(rv, domMessage) { function notifyResult(rv, domMessage) {
// TODO bug 832140 handle !Components.isSuccessCode(rv) // TODO bug 832140 handle !Components.isSuccessCode(rv)
gSystemMessenger.broadcastMessage("sms-sent", { this.broadcastSmsSystemMessage("sms-sent", domMessage);
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
});
if (!options.requestStatusReport) { if (!options.requestStatusReport) {
// No more used if STATUS-REPORT not requested. // No more used if STATUS-REPORT not requested.