From c6b39fedf96fd7ba6e5059c48a4735c9f70ec0fc Mon Sep 17 00:00:00 2001 From: William Chen Date: Thu, 12 Jul 2012 11:45:38 -0400 Subject: [PATCH] Bug 782211 - Part 6: Updated the B2G notifications to implement the Notification API. r=etienne --- b2g/chrome/content/shell.js | 46 +++++++++++++++++++++++++-------- b2g/components/AlertsService.js | 12 +++++++-- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index 5a99d828f2d5..3f324dbc9f28 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -636,6 +636,7 @@ var CustomEventManager = { dump('XXX FIXME : Got a mozContentEvent: ' + detail.type + "\n"); switch(detail.type) { + case 'desktop-notification-show': case 'desktop-notification-click': case 'desktop-notification-close': AlertsHelper.handleEvent(detail); @@ -673,8 +674,16 @@ var AlertsHelper = { if (!listener) return; - let topic = detail.type == "desktop-notification-click" ? "alertclickcallback" - /* desktop-notification-close */ : "alertfinished"; + let topic; + 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")) { try { listener.mm.sendAsyncMessage("app-notification-return", { @@ -707,10 +716,8 @@ var AlertsHelper = { } }, - registerListener: function alert_registerListener(cookie, alertListener) { - let uid = "alert" + this._count++; - this._listeners[uid] = { observer: alertListener, cookie: cookie }; - return uid; + registerListener: function alert_registerListener(alertId, cookie, alertListener) { + this._listeners[alertId] = { observer: alertListener, cookie: cookie }; }, registerAppListener: function alert_registerAppListener(uid, listener) { @@ -745,7 +752,8 @@ var AlertsHelper = { textClickable, cookie, uid, - name, + bidi, + lang, manifestUrl) { function send(appName, appIcon) { shell.sendChromeEvent({ @@ -754,6 +762,8 @@ var AlertsHelper = { icon: imageUrl, title: title, text: text, + bidi: bidi, + lang: lang, appName: appName, appIcon: appIcon, manifestURL: manifestUrl @@ -779,10 +789,24 @@ var AlertsHelper = { textClickable, cookie, alertListener, - name) { - let uid = this.registerListener(null, alertListener); + name, + 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, - 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) { @@ -804,7 +828,7 @@ var AlertsHelper = { this.showNotification(data.imageURL, data.title, data.text, data.textClickable, null, - data.uid, null, data.manifestURL); + data.uid, null, null, data.manifestURL); }, } diff --git a/b2g/components/AlertsService.js b/b2g/components/AlertsService.js index 0ea74f982880..c7ad120b9132 100644 --- a/b2g/components/AlertsService.js +++ b/b2g/components/AlertsService.js @@ -46,11 +46,19 @@ AlertsService.prototype = { aTextClickable, aCookie, aAlertListener, - aName) { + aName, + aBidi, + aLang) { let browser = Services.wm.getMostRecentWindow("navigator:browser"); browser.AlertsHelper.showAlertNotification(aImageUrl, aTitle, aText, aTextClickable, aCookie, - aAlertListener, aName); + aAlertListener, aName, aBidi, + aLang); + }, + + closeAlert: function(aName) { + let browser = Services.wm.getMostRecentWindow("navigator:browser"); + browser.AlertsHelper.closeAlert(aName); }, // nsIAppNotificationService