From fe908f18f96f50224e94d6829bccbedb70af3f42 Mon Sep 17 00:00:00 2001 From: Chia-hung Tai Date: Mon, 18 Mar 2013 18:47:41 +0800 Subject: [PATCH] Bug 849741 - B2G MMS: provide nsIDOMMobileMessageManager.onreceived event. r=vyang a=leo+ --- dom/mms/src/ril/MmsService.js | 17 +++++++++++++---- dom/mms/src/ril/WspPduHelper.jsm | 10 ++-------- dom/mobilemessage/src/Constants.cpp | 1 + dom/mobilemessage/src/Constants.h | 1 + dom/mobilemessage/src/MobileMessageManager.cpp | 13 +++++++++++++ .../src/ril/MobileMessageDatabaseService.js | 15 +++++++++------ 6 files changed, 39 insertions(+), 18 deletions(-) diff --git a/dom/mms/src/ril/MmsService.js b/dom/mms/src/ril/MmsService.js index ac6123ea570e..70e7ea81a4df 100644 --- a/dom/mms/src/ril/MmsService.js +++ b/dom/mms/src/ril/MmsService.js @@ -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)); diff --git a/dom/mms/src/ril/WspPduHelper.jsm b/dom/mms/src/ril/WspPduHelper.jsm index 51c32b9e3272..d64588b35408 100644 --- a/dom/mms/src/ril/WspPduHelper.jsm +++ b/dom/mms/src/ril/WspPduHelper.jsm @@ -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] = { diff --git a/dom/mobilemessage/src/Constants.cpp b/dom/mobilemessage/src/Constants.cpp index 5cb6c8862655..5a7c80514d98 100644 --- a/dom/mobilemessage/src/Constants.cpp +++ b/dom/mobilemessage/src/Constants.cpp @@ -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 diff --git a/dom/mobilemessage/src/Constants.h b/dom/mobilemessage/src/Constants.h index 50ce55f864c3..b675dd4242ff 100644 --- a/dom/mobilemessage/src/Constants.h +++ b/dom/mobilemessage/src/Constants.h @@ -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") diff --git a/dom/mobilemessage/src/MobileMessageManager.cpp b/dom/mobilemessage/src/MobileMessageManager.cpp index d17c57cfb151..930941b93789 100644 --- a/dom/mobilemessage/src/MobileMessageManager.cpp +++ b/dom/mobilemessage/src/MobileMessageManager.cpp @@ -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 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; } diff --git a/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js b/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js index cd98dfa4ff56..588be24e49b3 100644 --- a/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js +++ b/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js @@ -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);