зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1138264 - Part 2: Broadcast System Messages from SmsService/MmsService accordingly. r=echen
This commit is contained in:
Родитель
37699fa7da
Коммит
2fa99c6fda
|
@ -1677,24 +1677,30 @@ MmsService.prototype = {
|
|||
// 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, {
|
||||
iccId: aDomMessage.iccId,
|
||||
type: aDomMessage.type,
|
||||
id: aDomMessage.id,
|
||||
threadId: aDomMessage.threadId,
|
||||
delivery: aDomMessage.delivery,
|
||||
deliveryInfo: aDomMessage.deliveryInfo,
|
||||
sender: aDomMessage.sender,
|
||||
receivers: aDomMessage.receivers,
|
||||
timestamp: aDomMessage.timestamp,
|
||||
sentTimestamp: aDomMessage.sentTimestamp,
|
||||
read: aDomMessage.read,
|
||||
subject: aDomMessage.subject,
|
||||
smil: aDomMessage.smil,
|
||||
attachments: aDomMessage.attachments,
|
||||
expiryDate: aDomMessage.expiryDate,
|
||||
readReportRequested: aDomMessage.readReportRequested
|
||||
});
|
||||
try {
|
||||
gSystemMessenger.broadcastMessage(aName, {
|
||||
iccId: aDomMessage.iccId,
|
||||
type: aDomMessage.type,
|
||||
id: aDomMessage.id,
|
||||
threadId: aDomMessage.threadId,
|
||||
delivery: aDomMessage.delivery,
|
||||
deliveryInfo: aDomMessage.deliveryInfo,
|
||||
sender: aDomMessage.sender,
|
||||
receivers: aDomMessage.receivers,
|
||||
timestamp: aDomMessage.timestamp,
|
||||
sentTimestamp: aDomMessage.sentTimestamp,
|
||||
read: aDomMessage.read,
|
||||
subject: aDomMessage.subject,
|
||||
smil: aDomMessage.smil,
|
||||
attachments: aDomMessage.attachments,
|
||||
expiryDate: aDomMessage.expiryDate,
|
||||
readReportRequested: aDomMessage.readReportRequested
|
||||
});
|
||||
} catch (e) {
|
||||
if (DEBUG) {
|
||||
debug("Failed to _broadcastSmsSystemMessage: " + e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1712,6 +1718,21 @@ MmsService.prototype = {
|
|||
Services.obs.notifyObservers(aDomMessage, kSmsSentObserverTopic, null);
|
||||
},
|
||||
|
||||
/**
|
||||
* A helper function to broadcast system message and notify observers that
|
||||
* an MMS is failed to send.
|
||||
*
|
||||
* @params aDomMessage
|
||||
* The nsIDOMMozMmsMessage object.
|
||||
*/
|
||||
broadcastSentFailureMessageEvent: function(aDomMessage) {
|
||||
// Broadcasting a 'sms-sent' system message to open apps.
|
||||
this.broadcastMmsSystemMessage(kSmsFailedObserverTopic, aDomMessage);
|
||||
|
||||
// Notifying observers an MMS message is sent.
|
||||
Services.obs.notifyObservers(aDomMessage, kSmsFailedObserverTopic, null);
|
||||
},
|
||||
|
||||
/**
|
||||
* A helper function to broadcast system message and notify observers that
|
||||
* an MMS is received.
|
||||
|
@ -1972,11 +1993,12 @@ MmsService.prototype = {
|
|||
let topic;
|
||||
if (mmsStatus === MMS.MMS_PDU_STATUS_RETRIEVED) {
|
||||
topic = kSmsDeliverySuccessObserverTopic;
|
||||
|
||||
// Broadcasting a 'sms-delivery-success' system message to open apps.
|
||||
this.broadcastMmsSystemMessage(topic, aDomMessage);
|
||||
} else if (mmsStatus === MMS.MMS_PDU_STATUS_REJECTED) {
|
||||
topic = kSmsDeliveryErrorObserverTopic;
|
||||
// Broadcasting a 'sms-delivery-error' system message to open apps.
|
||||
this.broadcastMmsSystemMessage(topic, aDomMessage);
|
||||
} else {
|
||||
if (DEBUG) debug("Needn't fire event for this MMS status. Returning.");
|
||||
return;
|
||||
|
@ -2224,11 +2246,7 @@ MmsService.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
let self = this;
|
||||
|
||||
let sendTransactionCb = function sendTransactionCb(aDomMessage,
|
||||
aErrorCode,
|
||||
aEnvelopeId) {
|
||||
let sendTransactionCb = (aDomMessage, aErrorCode, aEnvelopeId) => {
|
||||
if (DEBUG) {
|
||||
debug("The returned status of sending transaction: " +
|
||||
"aErrorCode: " + aErrorCode + " aEnvelopeId: " + aEnvelopeId);
|
||||
|
@ -2238,7 +2256,7 @@ MmsService.prototype = {
|
|||
// cancelled), we don't need to reset the its delievery state/status.
|
||||
if (aErrorCode == Ci.nsIMobileMessageCallback.NOT_FOUND_ERROR) {
|
||||
aRequest.notifySendMessageFailed(aErrorCode, aDomMessage);
|
||||
Services.obs.notifyObservers(aDomMessage, kSmsFailedObserverTopic, null);
|
||||
this.broadcastSentFailureMessageEvent(aDomMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2249,20 +2267,20 @@ MmsService.prototype = {
|
|||
isSentSuccess ? DELIVERY_SENT : DELIVERY_ERROR,
|
||||
isSentSuccess ? null : DELIVERY_STATUS_ERROR,
|
||||
aEnvelopeId,
|
||||
function notifySetDeliveryResult(aRv, aDomMessage) {
|
||||
(aRv, aDomMessage) => {
|
||||
if (DEBUG) debug("Marking the delivery state/staus is done. Notify sent or failed.");
|
||||
// TODO bug 832140 handle !Components.isSuccessCode(aRv)
|
||||
if (!isSentSuccess) {
|
||||
if (DEBUG) debug("Sending MMS failed.");
|
||||
aRequest.notifySendMessageFailed(aErrorCode, aDomMessage);
|
||||
Services.obs.notifyObservers(aDomMessage, kSmsFailedObserverTopic, null);
|
||||
this.broadcastSentFailureMessageEvent(aDomMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) debug("Sending MMS succeeded.");
|
||||
|
||||
// Notifying observers the MMS message is sent.
|
||||
self.broadcastSentMessageEvent(aDomMessage);
|
||||
this.broadcastSentMessageEvent(aDomMessage);
|
||||
|
||||
// Return the request after sending the MMS message successfully.
|
||||
aRequest.notifyMessageSent(aDomMessage);
|
||||
|
@ -2276,13 +2294,13 @@ MmsService.prototype = {
|
|||
savableMessage);
|
||||
gMobileMessageDatabaseService
|
||||
.saveSendingMessage(savableMessage,
|
||||
function notifySendingResult(aRv, aDomMessage) {
|
||||
(aRv, aDomMessage) => {
|
||||
if (!Components.isSuccessCode(aRv)) {
|
||||
if (DEBUG) debug("Error! Fail to save sending message! rv = " + aRv);
|
||||
aRequest.notifySendMessageFailed(
|
||||
gMobileMessageDatabaseService.translateCrErrorToMessageCallbackError(aRv),
|
||||
aDomMessage);
|
||||
Services.obs.notifyObservers(aDomMessage, kSmsFailedObserverTopic, null);
|
||||
this.broadcastSentFailureMessageEvent(aDomMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2308,7 +2326,7 @@ MmsService.prototype = {
|
|||
// To support DSDS, we have to stop users sending MMS when the selected
|
||||
// SIM is not active, thus avoiding the data disconnection of the current
|
||||
// SIM. Users have to manually swith the default SIM before sending.
|
||||
if (mmsConnection.serviceId != self.mmsDefaultServiceId) {
|
||||
if (mmsConnection.serviceId != this.mmsDefaultServiceId) {
|
||||
if (DEBUG) debug("RIL service is not active to send MMS.");
|
||||
sendTransactionCb(aDomMessage,
|
||||
Ci.nsIMobileMessageCallback.NON_ACTIVE_SIM_CARD_ERROR,
|
||||
|
|
|
@ -308,6 +308,8 @@ SmsService.prototype = {
|
|||
null,
|
||||
(aRv, aDomMessage) => {
|
||||
// TODO bug 832140 handle !Components.isSuccessCode(aRv)
|
||||
this._broadcastSmsSystemMessage(
|
||||
Ci.nsISmsMessenger_new.NOTIFICATION_TYPE_SENT_FAILED, aDomMessage);
|
||||
aRequest.notifySendMessageFailed(error, aDomMessage);
|
||||
Services.obs.notifyObservers(aDomMessage, kSmsFailedObserverTopic, null);
|
||||
});
|
||||
|
@ -373,16 +375,16 @@ SmsService.prototype = {
|
|||
(aRv, aDomMessage) => {
|
||||
// TODO bug 832140 handle !Components.isSuccessCode(aRv)
|
||||
|
||||
let topic = (aResponse.deliveryStatus ==
|
||||
RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS)
|
||||
? kSmsDeliverySuccessObserverTopic
|
||||
: kSmsDeliveryErrorObserverTopic;
|
||||
let [topic, notificationType] =
|
||||
(aResponse.deliveryStatus == RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS)
|
||||
? [kSmsDeliverySuccessObserverTopic,
|
||||
Ci.nsISmsMessenger.NOTIFICATION_TYPE_DELIVERY_SUCCESS]
|
||||
: [kSmsDeliveryErrorObserverTopic,
|
||||
Ci.nsISmsMessenger_new.NOTIFICATION_TYPE_DELIVERY_ERROR];
|
||||
|
||||
// Broadcasting a "sms-delivery-success" system message to open apps.
|
||||
if (topic == kSmsDeliverySuccessObserverTopic) {
|
||||
this._broadcastSmsSystemMessage(
|
||||
Ci.nsISmsMessenger.NOTIFICATION_TYPE_DELIVERY_SUCCESS, aDomMessage);
|
||||
}
|
||||
// Broadcasting a "sms-delivery-success/sms-delivery-error" system
|
||||
// message to open apps.
|
||||
this._broadcastSmsSystemMessage(notificationType, aDomMessage);
|
||||
|
||||
// Notifying observers the delivery status is updated.
|
||||
Services.obs.notifyObservers(aDomMessage, topic, null);
|
||||
|
@ -861,6 +863,8 @@ SmsService.prototype = {
|
|||
let saveSendingMessageCallback = (aRv, aSendingMessage) => {
|
||||
if (!Components.isSuccessCode(aRv)) {
|
||||
if (DEBUG) debug("Error! Fail to save sending message! aRv = " + aRv);
|
||||
this._broadcastSmsSystemMessage(
|
||||
Ci.nsISmsMessenger_new.NOTIFICATION_TYPE_SENT_FAILED, aSendingMessage);
|
||||
aRequest.notifySendMessageFailed(
|
||||
gMobileMessageDatabaseService.translateCrErrorToMessageCallbackError(aRv),
|
||||
aSendingMessage);
|
||||
|
@ -904,6 +908,8 @@ SmsService.prototype = {
|
|||
null,
|
||||
(aRv, aDomMessage) => {
|
||||
// TODO bug 832140 handle !Components.isSuccessCode(aRv)
|
||||
this._broadcastSmsSystemMessage(
|
||||
Ci.nsISmsMessenger_new.NOTIFICATION_TYPE_SENT_FAILED, aDomMessage);
|
||||
aRequest.notifySendMessageFailed(errorCode, aDomMessage);
|
||||
Services.obs.notifyObservers(aDomMessage, kSmsFailedObserverTopic, null);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче