Bug 630474 - Show a toaster alert when instaling or uninstalling a restartless add-on [r=mbrubeck]
authorMark Finkle <mfinkle@mozilla.com>
Wed, 09 Feb 2011 23:55:20 -0500
changeset 67366 3907517f944c6ffb7ae2bb3e6256df1879a9143b
parent 67365 14695e8f77ef0c5a0f48abb0292b2c198a4665b6
child 67367 78d0e414ff2c8e814d141d77b914616b6037307c
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs630474
Bug 630474 - Show a toaster alert when instaling or uninstalling a restartless add-on [r=mbrubeck]
mobile/chrome/content/extensions.js
--- a/mobile/chrome/content/extensions.js
+++ b/mobile/chrome/content/extensions.js
@@ -803,39 +803,50 @@ var ExtensionsView = {
 
         // Tag the add-on so the AddonInstallListener knows it's an update
         if (updateable)
           element.setAttribute("updating", "true");
         break;
     }
   },
 
-  showAlert: function ev_showAlert(aMessage) {
-    if (this.visible)
-      return;
-
+  showAlert: function ev_showAlert(aMessage, aForceDisplay) {
     let strings = Strings.browser;
 
     let observer = {
       observe: function (aSubject, aTopic, aData) {
         if (aTopic == "alertclickcallback")
           BrowserUI.showPanel("addons-container");
       }
     };
 
-    let alerts = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
-    alerts.showAlertNotification(URI_GENERIC_ICON_XPINSTALL, strings.GetStringFromName("alertAddons"),
-                                 aMessage, true, "", observer, ADDONS_NOTIFICATION_NAME);
+    if (aForceDisplay) {
+      // Show a toaster alert for restartless add-ons all the time
+      let toaster = Cc["@mozilla.org/toaster-alerts-service;1"].getService(Ci.nsIAlertsService);
+      if (this.visible)
+        toaster.showAlertNotification(URI_GENERIC_ICON_XPINSTALL, strings.GetStringFromName("alertAddons"),
+                                      aMessage, false, "", null);
+      else
+        toaster.showAlertNotification(URI_GENERIC_ICON_XPINSTALL, strings.GetStringFromName("alertAddons"),
+                                      aMessage, true, "", observer);
+    } else {
+      // Only show an alert for a normal add-on if the manager is not visible
+      if (!this.visible) {
+        let alerts = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
+        alerts.showAlertNotification(URI_GENERIC_ICON_XPINSTALL, strings.GetStringFromName("alertAddons"),
+                                     aMessage, true, "", observer, ADDONS_NOTIFICATION_NAME);
+      }
+    }
   },
 
   hideAlerts: function ev_hideAlerts() {
 #ifdef ANDROID
     let alertsService = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
     let progressListener = alertsService.QueryInterface(Ci.nsIAlertsProgressListener);
-    progressListener.onCancel("addons");
+    progressListener.onCancel(ADDONS_NOTIFICATION_NAME);
 #endif
   },
 };
 
 
 function searchFailed() {
   ExtensionsView.clearSection("repo");
 
@@ -976,17 +987,17 @@ AddonInstallListener.prototype = {
   },
 
   onDownloadProgress: function xpidm_onDownloadProgress(aInstall) {
     let element = ExtensionsView.getElementForAddon(aInstall.sourceURI.spec);
 
 #ifdef ANDROID
     let alertsService = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
     let progressListener = alertsService.QueryInterface(Ci.nsIAlertsProgressListener);
-    progressListener.onProgress("addons", aInstall.progress, aInstall.maxProgress);
+    progressListener.onProgress(ADDONS_NOTIFICATION_NAME, aInstall.progress, aInstall.maxProgress);
 #endif
     if (!element)
       return;
 
     let opType = element.getAttribute("opType");
     if (!opType)
       element.setAttribute("opType", "needs-install");
 
@@ -1031,11 +1042,12 @@ AddonInstallListener.prototype = {
   _showInstallCompleteAlert: function xpidm_showAlert(aSucceeded, aNeedsRestart) {
     let strings = Strings.browser;
     let stringName = "alertAddonsFail";
     if (aSucceeded) {
       stringName = "alertAddonsInstalled";
       if (!aNeedsRestart)
         stringName += "NoRestart";
     }
-    ExtensionsView.showAlert(strings.GetStringFromName(stringName));
+
+    ExtensionsView.showAlert(strings.GetStringFromName(stringName), !aNeedsRestart);
   },
 };