Bug 771818 - Using WeakMap to store popup notification object. r=MattN

--HG--
extra : rebase_source : 8d798389f01f12a538c99b33d3c45ff50ae55894
This commit is contained in:
OHZEKI Tetsuharu 2012-08-09 13:51:41 -07:00
parent 20d20e28c7
commit 3b66089d27

View File

@ -15,6 +15,8 @@ const NOTIFICATION_EVENT_SHOWN = "shown";
const ICON_SELECTOR = ".notification-anchor-icon";
const ICON_ATTRIBUTE_SHOWING = "showing";
let popupNotificationsMap = new WeakMap();
/**
* Notification object describes a single popup notification.
*
@ -351,7 +353,7 @@ PopupNotifications.prototype = {
return this._getNotificationsForBrowser(this.tabbrowser.selectedBrowser);
},
set _currentNotifications(a) {
return this.tabbrowser.selectedBrowser.popupNotifications = a;
return this._setNotificationsForBrowser(this.tabbrowser.selectedBrowser, a);
},
_remove: function PopupNotifications_removeHelper(notification) {
@ -431,7 +433,7 @@ PopupNotifications.prototype = {
popupnotification.appendChild(item);
}, this);
if (n.secondaryActions.length) {
let closeItemSeparator = doc.createElementNS(XUL_NS, "menuseparator");
popupnotification.appendChild(closeItemSeparator);
@ -539,11 +541,21 @@ PopupNotifications.prototype = {
}
},
/**
* Gets and sets notifications for the browser.
*/
_getNotificationsForBrowser: function PopupNotifications_getNotifications(browser) {
if (browser.popupNotifications)
return browser.popupNotifications;
return browser.popupNotifications = [];
let notifications = popupNotificationsMap.get(browser);
if (!notifications) {
// Initialize the WeakMap for the browser so callers can reference/manipulate the array.
notifications = [];
popupNotificationsMap.set(browser, notifications);
}
return notifications;
},
_setNotificationsForBrowser: function PopupNotifications_setNotifications(browser, notifications) {
popupNotificationsMap.set(browser, notifications);
return notifications;
},
_onIconBoxCommand: function PopupNotifications_onIconBoxCommand(event) {