Bug 849741 - B2G MMS: provide nsIDOMMobileMessageManager.onreceived event. r=vyang a=leo+

This commit is contained in:
Chia-hung Tai 2013-03-18 18:47:41 +08:00
Родитель 14864f622c
Коммит fe908f18f9
6 изменённых файлов: 39 добавлений и 18 удалений

Просмотреть файл

@ -21,6 +21,7 @@ const DEBUG = false;
const kMmsSendingObserverTopic = "mms-sending";
const kMmsSentObserverTopic = "mms-sent";
const kMmsFailedObserverTopic = "mms-failed";
const kMmsReceivedObserverTopic = "mms-received";
const kNetworkInterfaceStateChangedTopic = "network-interface-state-changed";
const kXpcomShutdownObserverTopic = "xpcom-shutdown";
@ -50,6 +51,10 @@ const DELIVERY_SENDING = "sending";
const DELIVERY_SENT = "sent";
const DELIVERY_ERROR = "error";
const DELIVERY_STATUS_SUCCESS = "success";
const DELIVERY_STATUS_PENDING = "pending";
const MAX_RETRY_COUNT = Services.prefs.getIntPref("dom.mms.retrievalRetryCount");
const DELAY_TIME_TO_RETRY = Services.prefs.getIntPref("dom.mms.retrievalRetryInterval");
@ -923,6 +928,7 @@ MmsService.prototype = {
convertIntermediateToSavable: function convertIntermediateToSavable(intermediate) {
intermediate.type = "mms";
intermediate.delivery = DELIVERY_NOT_DOWNLOADED;
intermediate.deliveryStatus = [DELIVERY_STATUS_PENDING];
intermediate.timestamp = Date.now();
intermediate.sender = null;
if (intermediate.headers.from) {
@ -968,6 +974,7 @@ MmsService.prototype = {
}
savable.delivery = DELIVERY_RECEIVED;
savable.deliveryStatus = [DELIVERY_STATUS_SUCCESS];
for (let field in intermediate.headers) {
savable.headers[field] = intermediate.headers[field];
}
@ -1018,8 +1025,6 @@ MmsService.prototype = {
gMobileMessageDatabaseService.saveReceivedMessage(savableMessage,
(function (rv, domMessage) {
// TODO: Bug 760065 - B2G MMS: Implement MMS DOM API
// Connect to DOM API for notifing new comming MMS to Gaia.
let success = Components.isSuccessCode(rv);
if (!success) {
// At this point we could send a message to content to notify the
@ -1033,6 +1038,9 @@ MmsService.prototype = {
return;
}
// Notifing new comming notification indication through notifyObservers.
Services.obs.notifyObservers(domMessage, kMmsReceivedObserverTopic, null);
let retrievalMode = RETRIEVAL_MODE_MANUAL;
try {
retrievalMode = Services.prefs.getCharPref(PREF_RETRIEVAL_MODE);
@ -1082,8 +1090,6 @@ MmsService.prototype = {
gMobileMessageDatabaseService.saveReceivedMessage(savableMessage,
(function (rv, domMessage) {
// TODO: Bug 760065 - B2G MMS: Implement MMS DOM API
// Connect to DOM API for notifing new comming MMS to Gaia.
let success = Components.isSuccessCode(rv);
if (!success) {
// At this point we could send a message to content to
@ -1099,6 +1105,9 @@ MmsService.prototype = {
transaction.run();
return;
}
// Notifing new retrieved MMS message through notifyObservers.
Services.obs.notifyObservers(domMessage, kMmsReceivedObserverTopic, null);
}).bind(this)
);
}).bind(this));

Просмотреть файл

@ -2292,14 +2292,8 @@ this.PduHelper = {
let octetArray = Octet.decodeMultiple(data, contentEnd);
let content = null;
if (octetArray) {
if (headers["content-type"].media.indexOf("text/") === 0) {
content = this.decodeStringContent(octetArray,
headers["content-type"].params.charset["charset"]);
}
if (!content) {
content = new Blob([octetArray],
{"type" : headers["content-type"].media});
}
content = new Blob([octetArray],
{type : headers["content-type"].media});
}
parts[i] = {

Просмотреть файл

@ -17,6 +17,7 @@ const char* kSmsDeliveryErrorObserverTopic = "sms-delivery-error";
const char* kMmsSendingObserverTopic = "mms-sending";
const char* kMmsSentObserverTopic = "mms-sent";
const char* kMmsFailedObserverTopic = "mms-failed";
const char* kMmsReceivedObserverTopic = "mms-received";
} // namespace mobilemessage
} // namespace dom

Просмотреть файл

@ -21,6 +21,7 @@ extern const char* kSmsDeliveryErrorObserverTopic;
extern const char* kMmsSendingObserverTopic;
extern const char* kMmsSentObserverTopic;
extern const char* kMmsFailedObserverTopic;
extern const char* kMmsReceivedObserverTopic;
#define DELIVERY_RECEIVED NS_LITERAL_STRING("received")
#define DELIVERY_SENDING NS_LITERAL_STRING("sending")

Просмотреть файл

@ -89,6 +89,7 @@ MobileMessageManager::Init(nsPIDOMWindow *aWindow)
obs->AddObserver(this, kMmsSendingObserverTopic, false);
obs->AddObserver(this, kMmsSentObserverTopic, false);
obs->AddObserver(this, kMmsFailedObserverTopic, false);
obs->AddObserver(this, kMmsReceivedObserverTopic, false);
}
void
@ -110,6 +111,7 @@ MobileMessageManager::Shutdown()
obs->RemoveObserver(this, kMmsSendingObserverTopic);
obs->RemoveObserver(this, kMmsSentObserverTopic);
obs->RemoveObserver(this, kMmsFailedObserverTopic);
obs->RemoveObserver(this, kMmsReceivedObserverTopic);
}
NS_IMETHODIMP
@ -462,6 +464,17 @@ MobileMessageManager::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
if (!strcmp(aTopic, kMmsReceivedObserverTopic)) {
nsCOMPtr<nsIDOMMozMmsMessage> message = do_QueryInterface(aSubject);
if (!message) {
NS_ERROR("Got a 'mms-received' topic without a valid message!");
return NS_OK;
}
DispatchTrustedMmsEventToSelf(RECEIVED_EVENT_NAME, message);
return NS_OK;
}
return NS_OK;
}

Просмотреть файл

@ -1131,11 +1131,12 @@ MobileMessageDatabaseService.prototype = {
*/
saveReceivedMessage: function saveReceivedMessage(aMessage, aCallback) {
if (aMessage.type === undefined ||
aMessage.sender === undefined ||
(aMessage.type == "sms" && aMessage.messageClass === undefined) ||
(aMessage.type == "mms" && aMessage.delivery === undefined) ||
aMessage.timestamp === undefined) {
if (aMessage.type == undefined ||
aMessage.sender == undefined ||
(aMessage.type == "sms" && aMessage.messageClass == undefined) ||
(aMessage.type == "mms" && aMessage.delivery == undefined) ||
(aMessage.type == "mms" && aMessage.deliveryStatus == undefined) ||
aMessage.timestamp == undefined) {
if (aCallback) {
aCallback.notify(Cr.NS_ERROR_FAILURE, null);
}
@ -1166,10 +1167,12 @@ MobileMessageDatabaseService.prototype = {
// threadIdIndex & participantIdsIndex are filled in saveRecord().
aMessage.deliveryIndex = [DELIVERY_RECEIVED, timestamp];
aMessage.readIndex = [FILTER_READ_UNREAD, timestamp];
if (aMessage.type == "sms") {
aMessage.deliveryStatus = DELIVERY_STATUS_SUCCESS;
aMessage.delivery = DELIVERY_RECEIVED;
}
aMessage.deliveryStatus = DELIVERY_STATUS_SUCCESS;
aMessage.read = FILTER_READ_UNREAD;
return this.saveRecord(aMessage, threadParticipants, aCallback);