Bug 745524 - Minor code cleanup in PopupNotifications.jsm. r=dolske
authorOHZEKI Tetsuharu <saneyuki.s.snyk@gmail.com>
Sun, 15 Apr 2012 19:11:41 -0400
changeset 95037 b69c5c0bb7274ebf6f722873a6f5e2eb64ed3a7b
parent 95036 3b35598ce292c9cfc0d6b27389198a43ad3d4bfc
child 95038 9a2f5f6016160523630a565df941b0e61173f10a
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs745524
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 745524 - Minor code cleanup in PopupNotifications.jsm. r=dolske
toolkit/content/PopupNotifications.jsm
--- a/toolkit/content/PopupNotifications.jsm
+++ b/toolkit/content/PopupNotifications.jsm
@@ -37,16 +37,20 @@
  * ***** END LICENSE BLOCK ***** */
 
 var EXPORTED_SYMBOLS = ["PopupNotifications"];
 
 var Cc = Components.classes, Ci = Components.interfaces;
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
+const NOTIFICATION_EVENT_DISMISSED = "dismissed";
+const NOTIFICATION_EVENT_REMOVED = "removed";
+const NOTIFICATION_EVENT_SHOWN = "shown";
+
 /**
  * Notification object describes a single popup notification.
  *
  * @see PopupNotifications.show()
  */
 function Notification(id, message, anchorID, mainAction, secondaryActions,
                       browser, owner, options) {
   this.id = id;
@@ -55,16 +59,26 @@ function Notification(id, message, ancho
   this.mainAction = mainAction;
   this.secondaryActions = secondaryActions || [];
   this.browser = browser;
   this.owner = owner;
   this.options = options || {};
 }
 
 Notification.prototype = {
+
+  id: null,
+  message: null,
+  anchorID: null,
+  mainAction: null,
+  secondaryActions: null,
+  browser: null,
+  owner: null,
+  options: null,
+
   /**
    * Removes the notification and updates the popup accordingly if needed.
    */
   remove: function Notification_remove() {
     this.owner.remove(this);
   },
 
   get anchorElement() {
@@ -124,16 +138,22 @@ function PopupNotifications(tabbrowser, 
       self._update();
     }, 0);
   }
   this.window.addEventListener("activate", updateFromListeners, true);
   this.tabbrowser.tabContainer.addEventListener("TabSelect", updateFromListeners, true);
 }
 
 PopupNotifications.prototype = {
+
+  window: null,
+  panel: null,
+  tabbrowser: null,
+
+  _iconBox: null,
   set iconBox(iconBox) {
     // Remove the listeners on the old iconBox, if needed
     if (this._iconBox) {
       this._iconBox.removeEventListener("click", this._onIconBoxCommand, false);
       this._iconBox.removeEventListener("keypress", this._onIconBoxCommand, false);
     }
     this._iconBox = iconBox;
     if (iconBox) {
@@ -154,17 +174,17 @@ PopupNotifications.prototype = {
    *        currently selected browser's notifications will be searched.
    *
    * @returns the corresponding Notification object, or null if no such
    *          notification exists.
    */
   getNotification: function PopupNotifications_getNotification(id, browser) {
     let n = null;
     let notifications = this._getNotificationsForBrowser(browser || this.tabbrowser.selectedBrowser);
-    notifications.some(function(x) x.id == id && (n = x))
+    notifications.some(function(x) x.id == id && (n = x));
     return n;
   },
 
   /**
    * Adds a new popup notification.
    * @param browser
    *        The <xul:browser> element associated with the notification. Must not
    *        be null.
@@ -293,32 +313,32 @@ PopupNotifications.prototype = {
       // across location changes
       if (notification.options.persistWhileVisible &&
           this.isPanelOpen) {
         if ("persistence" in notification.options &&
           notification.options.persistence)
           notification.options.persistence--;
         return true;
       }
-      
+
       // The persistence option allows a notification to persist across multiple
       // page loads
       if ("persistence" in notification.options &&
           notification.options.persistence) {
         notification.options.persistence--;
         return true;
       }
 
       // The timeout option allows a notification to persist until a certain time
       if ("timeout" in notification.options &&
           Date.now() <= notification.options.timeout) {
         return true;
       }
 
-      this._fireCallback(notification, "removed");
+      this._fireCallback(notification, NOTIFICATION_EVENT_REMOVED);
       return false;
     }, this);
 
     this._update();
   },
 
   /**
    * Removes a Notification.
@@ -333,16 +353,19 @@ PopupNotifications.prototype = {
     if (isCurrent)
       this._update();
   },
 
 ////////////////////////////////////////////////////////////////////////////////
 // Utility methods
 ////////////////////////////////////////////////////////////////////////////////
 
+  _ignoreDismissal: null,
+  _currentAnchorElement: null,
+
   /**
    * Gets and sets notifications for the currently selected browser.
    */
   get _currentNotifications() {
     return this._getNotificationsForBrowser(this.tabbrowser.selectedBrowser);
   },
   set _currentNotifications(a) {
     return this.tabbrowser.selectedBrowser.popupNotifications = a;
@@ -356,19 +379,19 @@ PopupNotifications.prototype = {
       return;
 
     var index = notifications.indexOf(notification);
     if (index == -1)
       return;
 
     // remove the notification
     notifications.splice(index, 1);
-    this._fireCallback(notification, "removed");
+    this._fireCallback(notification, NOTIFICATION_EVENT_REMOVED);
   },
-  
+
   /**
    * Dismisses the notification without removing it.
    */
   _dismiss: function PopupNotifications_dismiss() {
     this.panel.hidePopup();
   },
 
   /**
@@ -454,17 +477,17 @@ PopupNotifications.prototype = {
     } else {
       anchorElement = selectedTab; // null
     }
 
     this._currentAnchorElement = anchorElement;
 
     this.panel.openPopup(anchorElement, "bottomcenter topleft");
     notificationsToShow.forEach(function (n) {
-      this._fireCallback(n, "shown");
+      this._fireCallback(n, NOTIFICATION_EVENT_SHOWN);
     }, this);
   },
 
   /**
    * Updates the notification state in response to window activation or tab
    * selection changes.
    */
   _update: function PopupNotifications_update(anchor) {
@@ -558,23 +581,23 @@ PopupNotifications.prototype = {
     let notifications = this._getNotificationsForBrowser(browser);
     // Mark notifications as dismissed and call dismissal callbacks
     Array.forEach(this.panel.childNodes, function (nEl) {
       let notificationObj = nEl.notification;
       // Never call a dismissal handler on a notification that's been removed.
       if (notifications.indexOf(notificationObj) == -1)
         return;
 
-      // Do not mark the notification as dismissed or fire "dismissed" if the
-      // notification is removed. 
+      // Do not mark the notification as dismissed or fire NOTIFICATION_EVENT_DISMISSED
+      // if the notification is removed.
       if (notificationObj.options.removeOnDismissal)
         this._remove(notificationObj);
       else {
         notificationObj.dismissed = true;
-        this._fireCallback(notificationObj, "dismissed");
+        this._fireCallback(notificationObj, NOTIFICATION_EVENT_DISMISSED);
       }
     }, this);
 
     this._update();
   },
 
   _onButtonCommand: function PopupNotifications_onButtonCommand(event) {
     // Need to find the associated notification object, which is a bit tricky
@@ -609,10 +632,10 @@ PopupNotifications.prototype = {
     target.action.callback.call();
 
     this._remove(target.notification);
     this._update();
   },
 
   _notify: function PopupNotifications_notify(topic) {
     Services.obs.notifyObservers(null, "PopupNotifications-" + topic, "");
-  }
-}
+  },
+};