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

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

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

@ -21,6 +21,7 @@ const DEBUG = false;
const kMmsSendingObserverTopic = "mms-sending"; const kMmsSendingObserverTopic = "mms-sending";
const kMmsSentObserverTopic = "mms-sent"; const kMmsSentObserverTopic = "mms-sent";
const kMmsFailedObserverTopic = "mms-failed"; const kMmsFailedObserverTopic = "mms-failed";
const kMmsReceivedObserverTopic = "mms-received";
const kNetworkInterfaceStateChangedTopic = "network-interface-state-changed"; const kNetworkInterfaceStateChangedTopic = "network-interface-state-changed";
const kXpcomShutdownObserverTopic = "xpcom-shutdown"; const kXpcomShutdownObserverTopic = "xpcom-shutdown";
@ -51,6 +52,10 @@ const DELIVERY_SENDING = "sending";
const DELIVERY_SENT = "sent"; const DELIVERY_SENT = "sent";
const DELIVERY_ERROR = "error"; 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 MAX_RETRY_COUNT = Services.prefs.getIntPref("dom.mms.retrievalRetryCount");
const DELAY_TIME_TO_RETRY = Services.prefs.getIntPref("dom.mms.retrievalRetryInterval"); const DELAY_TIME_TO_RETRY = Services.prefs.getIntPref("dom.mms.retrievalRetryInterval");
@ -922,6 +927,7 @@ MmsService.prototype = {
convertIntermediateToSavable: function convertIntermediateToSavable(intermediate) { convertIntermediateToSavable: function convertIntermediateToSavable(intermediate) {
intermediate.type = "mms"; intermediate.type = "mms";
intermediate.delivery = DELIVERY_NOT_DOWNLOADED; intermediate.delivery = DELIVERY_NOT_DOWNLOADED;
intermediate.deliveryStatus = [DELIVERY_STATUS_PENDING];
intermediate.timestamp = Date.now(); intermediate.timestamp = Date.now();
intermediate.sender = null; intermediate.sender = null;
if (intermediate.headers.from) { if (intermediate.headers.from) {
@ -967,6 +973,7 @@ MmsService.prototype = {
} }
savable.delivery = DELIVERY_RECEIVED; savable.delivery = DELIVERY_RECEIVED;
savable.deliveryStatus = [DELIVERY_STATUS_SUCCESS];
for (let field in intermediate.headers) { for (let field in intermediate.headers) {
savable.headers[field] = intermediate.headers[field]; savable.headers[field] = intermediate.headers[field];
} }
@ -1017,8 +1024,6 @@ MmsService.prototype = {
gMobileMessageDatabaseService.saveReceivedMessage(savableMessage, gMobileMessageDatabaseService.saveReceivedMessage(savableMessage,
(function (rv, domMessage) { (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); let success = Components.isSuccessCode(rv);
if (!success) { if (!success) {
// At this point we could send a message to content to notify the // At this point we could send a message to content to notify the
@ -1032,6 +1037,9 @@ MmsService.prototype = {
return; return;
} }
// Notifing new comming notification indication through notifyObservers.
Services.obs.notifyObservers(domMessage, kMmsReceivedObserverTopic, null);
let retrievalMode = RETRIEVAL_MODE_MANUAL; let retrievalMode = RETRIEVAL_MODE_MANUAL;
try { try {
retrievalMode = Services.prefs.getCharPref(PREF_RETRIEVAL_MODE); retrievalMode = Services.prefs.getCharPref(PREF_RETRIEVAL_MODE);
@ -1081,8 +1089,6 @@ MmsService.prototype = {
gMobileMessageDatabaseService.saveReceivedMessage(savableMessage, gMobileMessageDatabaseService.saveReceivedMessage(savableMessage,
(function (rv, domMessage) { (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); let success = Components.isSuccessCode(rv);
if (!success) { if (!success) {
// At this point we could send a message to content to // At this point we could send a message to content to
@ -1098,6 +1104,9 @@ MmsService.prototype = {
transaction.run(); transaction.run();
return; return;
} }
// Notifing new retrieved MMS message through notifyObservers.
Services.obs.notifyObservers(domMessage, kMmsReceivedObserverTopic, null);
}).bind(this) }).bind(this)
); );
}).bind(this)); }).bind(this));

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

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

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

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

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

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

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

@ -78,6 +78,7 @@ MobileMessageManager::Init(nsPIDOMWindow *aWindow)
obs->AddObserver(this, kMmsSendingObserverTopic, false); obs->AddObserver(this, kMmsSendingObserverTopic, false);
obs->AddObserver(this, kMmsSentObserverTopic, false); obs->AddObserver(this, kMmsSentObserverTopic, false);
obs->AddObserver(this, kMmsFailedObserverTopic, false); obs->AddObserver(this, kMmsFailedObserverTopic, false);
obs->AddObserver(this, kMmsReceivedObserverTopic, false);
} }
void void
@ -99,6 +100,7 @@ MobileMessageManager::Shutdown()
obs->RemoveObserver(this, kMmsSendingObserverTopic); obs->RemoveObserver(this, kMmsSendingObserverTopic);
obs->RemoveObserver(this, kMmsSentObserverTopic); obs->RemoveObserver(this, kMmsSentObserverTopic);
obs->RemoveObserver(this, kMmsFailedObserverTopic); obs->RemoveObserver(this, kMmsFailedObserverTopic);
obs->RemoveObserver(this, kMmsReceivedObserverTopic);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -453,6 +455,17 @@ MobileMessageManager::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK; 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; return NS_OK;
} }

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

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