Bug 782211 - Part 6: Updated the B2G notifications to implement the Notification API. r=etienne

This commit is contained in:
William Chen 2012-07-12 11:45:38 -04:00
parent aef5b50861
commit c6b39fedf9
2 changed files with 45 additions and 13 deletions

View File

@ -636,6 +636,7 @@ var CustomEventManager = {
dump('XXX FIXME : Got a mozContentEvent: ' + detail.type + "\n"); dump('XXX FIXME : Got a mozContentEvent: ' + detail.type + "\n");
switch(detail.type) { switch(detail.type) {
case 'desktop-notification-show':
case 'desktop-notification-click': case 'desktop-notification-click':
case 'desktop-notification-close': case 'desktop-notification-close':
AlertsHelper.handleEvent(detail); AlertsHelper.handleEvent(detail);
@ -673,8 +674,16 @@ var AlertsHelper = {
if (!listener) if (!listener)
return; return;
let topic = detail.type == "desktop-notification-click" ? "alertclickcallback" let topic;
/* desktop-notification-close */ : "alertfinished"; if (detail.type == "desktop-notification-click") {
topic = "alertclickcallback";
} else if (detail.type == "desktop-notification-show") {
topic = "alertshow";
} else {
/* desktop-notification-close */
topic = "alertfinished";
}
if (uid.startsWith("app-notif")) { if (uid.startsWith("app-notif")) {
try { try {
listener.mm.sendAsyncMessage("app-notification-return", { listener.mm.sendAsyncMessage("app-notification-return", {
@ -707,10 +716,8 @@ var AlertsHelper = {
} }
}, },
registerListener: function alert_registerListener(cookie, alertListener) { registerListener: function alert_registerListener(alertId, cookie, alertListener) {
let uid = "alert" + this._count++; this._listeners[alertId] = { observer: alertListener, cookie: cookie };
this._listeners[uid] = { observer: alertListener, cookie: cookie };
return uid;
}, },
registerAppListener: function alert_registerAppListener(uid, listener) { registerAppListener: function alert_registerAppListener(uid, listener) {
@ -745,7 +752,8 @@ var AlertsHelper = {
textClickable, textClickable,
cookie, cookie,
uid, uid,
name, bidi,
lang,
manifestUrl) { manifestUrl) {
function send(appName, appIcon) { function send(appName, appIcon) {
shell.sendChromeEvent({ shell.sendChromeEvent({
@ -754,6 +762,8 @@ var AlertsHelper = {
icon: imageUrl, icon: imageUrl,
title: title, title: title,
text: text, text: text,
bidi: bidi,
lang: lang,
appName: appName, appName: appName,
appIcon: appIcon, appIcon: appIcon,
manifestURL: manifestUrl manifestURL: manifestUrl
@ -779,10 +789,24 @@ var AlertsHelper = {
textClickable, textClickable,
cookie, cookie,
alertListener, alertListener,
name) { name,
let uid = this.registerListener(null, alertListener); bidi,
lang) {
let currentListener = this._listeners[name];
if (currentListener) {
currentListener.observer.observe(null, "alertfinished", currentListener.cookie);
}
this.registerListener(name, cookie, alertListener);
this.showNotification(imageUrl, title, text, textClickable, cookie, this.showNotification(imageUrl, title, text, textClickable, cookie,
uid, name, null); name, bidi, lang, null);
},
closeAlert: function alert_closeAlert(name) {
shell.sendChromeEvent({
type: "desktop-notification-close",
id: name
});
}, },
receiveMessage: function alert_receiveMessage(aMessage) { receiveMessage: function alert_receiveMessage(aMessage) {
@ -804,7 +828,7 @@ var AlertsHelper = {
this.showNotification(data.imageURL, data.title, data.text, this.showNotification(data.imageURL, data.title, data.text,
data.textClickable, null, data.textClickable, null,
data.uid, null, data.manifestURL); data.uid, null, null, data.manifestURL);
}, },
} }

View File

@ -46,11 +46,19 @@ AlertsService.prototype = {
aTextClickable, aTextClickable,
aCookie, aCookie,
aAlertListener, aAlertListener,
aName) { aName,
aBidi,
aLang) {
let browser = Services.wm.getMostRecentWindow("navigator:browser"); let browser = Services.wm.getMostRecentWindow("navigator:browser");
browser.AlertsHelper.showAlertNotification(aImageUrl, aTitle, aText, browser.AlertsHelper.showAlertNotification(aImageUrl, aTitle, aText,
aTextClickable, aCookie, aTextClickable, aCookie,
aAlertListener, aName); aAlertListener, aName, aBidi,
aLang);
},
closeAlert: function(aName) {
let browser = Services.wm.getMostRecentWindow("navigator:browser");
browser.AlertsHelper.closeAlert(aName);
}, },
// nsIAppNotificationService // nsIAppNotificationService