Bug 1331918 - Make addon install failure messages non-persistent. r=past draft
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 19 Jan 2017 10:15:05 +0100
changeset 463596 b20327867e8cf87051d07e0d5a39d189899f06c5
parent 463342 96cb95af530477edb66ae48d98c18533476e57bb
child 464082 4c83d23ccc9fdba98ad701fdadb0fe9c6a047626
push id42129
push userbmo:jhofmann@mozilla.com
push dateThu, 19 Jan 2017 13:37:08 +0000
reviewerspast
bugs1331918
milestone53.0a1
Bug 1331918 - Make addon install failure messages non-persistent. r=past MozReview-Commit-ID: BO00gCCzT7f
browser/base/content/browser-addons.js
toolkit/modules/PopupNotifications.jsm
--- a/browser/base/content/browser-addons.js
+++ b/browser/base/content/browser-addons.js
@@ -233,39 +233,49 @@ const gXPInstallObserver = {
       persistent: true,
       hideClose: true,
       timeout: Date.now() + 30000,
     };
 
     switch (aTopic) {
     case "addon-install-disabled": {
       notificationID = "xpinstall-disabled";
+      let secondaryActions = null;
 
       if (gPrefService.prefIsLocked("xpinstall.enabled")) {
         messageString = gNavigatorBundle.getString("xpinstallDisabledMessageLocked");
         buttons = [];
       } else {
         messageString = gNavigatorBundle.getString("xpinstallDisabledMessage");
 
         action = {
           label: gNavigatorBundle.getString("xpinstallDisabledButton"),
           accessKey: gNavigatorBundle.getString("xpinstallDisabledButton.accesskey"),
           callback: function editPrefs() {
             gPrefService.setBoolPref("xpinstall.enabled", true);
           }
         };
+
+        secondaryActions = [{
+          label: gNavigatorBundle.getString("addonInstall.cancelButton.label"),
+          accessKey: gNavigatorBundle.getString("addonInstall.cancelButton.accesskey"),
+          callback: () => {},
+        }];
       }
 
       PopupNotifications.show(browser, notificationID, messageString, anchorID,
-                              action, null, options);
+                              action, secondaryActions, options);
       break; }
     case "addon-install-origin-blocked": {
       messageString = gNavigatorBundle.getFormattedString("xpinstallPromptMessage",
                         [brandShortName]);
 
+      options.removeOnDismissal = true;
+      options.persistent = false;
+
       let secHistogram = Components.classes["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry).getHistogramById("SECURITY_UI");
       secHistogram.add(Ci.nsISecurityUITelemetry.WARNING_ADDON_ASKING_PREVENTED);
       let popup = PopupNotifications.show(browser, notificationID,
                                           messageString, anchorID,
                                           null, null, options);
       removeNotificationOnEnd(popup, installInfo.installs);
       break; }
     case "addon-install-blocked": {
@@ -345,16 +355,19 @@ const gXPInstallObserver = {
       };
       let notification = PopupNotifications.show(browser, notificationID, messageString,
                                                  anchorID, action,
                                                  [secondaryAction], options);
       notification._startTime = Date.now();
 
       break; }
     case "addon-install-failed": {
+      options.removeOnDismissal = true;
+      options.persistent = false;
+
       // TODO This isn't terribly ideal for the multiple failure case
       for (let install of installInfo.installs) {
         let host;
         try {
           host  = options.displayURI.host;
         } catch (e) {
           // displayURI might be missing or 'host' might throw for non-nsStandardURL nsIURIs.
         }
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -886,16 +886,24 @@ PopupNotifications.prototype = {
         anchorElement = this.tabbrowser.selectedTab;
       }
     }
 
     if (this.isPanelOpen && this._currentAnchorElement == anchorElement) {
       notificationsToShow.forEach(function(n) {
         this._fireCallback(n, NOTIFICATION_EVENT_SHOWN);
       }, this);
+
+      // Make sure we update the noautohide attribute on the panel, in case it changed.
+      if (notificationsToShow.some(n => n.options.persistent)) {
+        this.panel.setAttribute("noautohide", "true");
+      } else {
+        this.panel.removeAttribute("noautohide");
+      }
+
       // Let tests know that the panel was updated and what notifications it was
       // updated with so that tests can wait for the correct notifications to be
       // added.
       let event = new this.window.CustomEvent("PanelUpdated",
                                               {"detail": notificationIds});
       this.panel.dispatchEvent(event);
       return;
     }