Bug 1298989 Don't show notification on theme install from discovery pane r=jaws
authorAndrew Swan <aswan@mozilla.com>
Tue, 06 Sep 2016 22:32:31 -0700
changeset 319315 ea865d0587762a8b2dd02ea95661745ae00d9c47
parent 319314 7bd25d3fff7426578e5ac4c2d1e499f53b54bc8f
child 319316 7bc2c36d07d4aaac8cbc5384f50b3beb4f27c66e
push id30869
push userphilringnalda@gmail.com
push dateWed, 26 Oct 2016 04:57:48 +0000
treeherdermozilla-central@9471b3c49b2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1298989
milestone52.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 1298989 Don't show notification on theme install from discovery pane r=jaws MozReview-Commit-ID: 5G8PNFKfJkc
browser/base/content/browser-addons.js
--- a/browser/base/content/browser-addons.js
+++ b/browser/base/content/browser-addons.js
@@ -491,47 +491,66 @@ var LightWeightThemeWebInstaller = {
 
   _installRequest: function (dataString, baseURI) {
     let data = this._manager.parseTheme(dataString, baseURI);
 
     if (!data) {
       return;
     }
 
+    let uri = makeURI(baseURI);
+
+    // A notification bar with the option to undo is normally shown after a
+    // theme is installed.  But the discovery pane served from the url(s)
+    // below has its own toggle switch for quick undos, so don't show the
+    // notification in that case.
+    let notify = uri.prePath != "https://discovery.addons.mozilla.org";
+    if (notify) {
+      try {
+        if (Services.prefs.getBoolPref("extensions.webapi.testing")
+            && (uri.prePath == "https://discovery.addons.allizom.org"
+                || uri.prePath == "https://discovery.addons-dev.allizom.org")) {
+          notify = false;
+        }
+      } catch (e) {
+        // getBoolPref() throws if the testing pref isn't set.  ignore it.
+      }
+    }
+
     if (this._isAllowed(baseURI)) {
-      this._install(data);
+      this._install(data, notify);
       return;
     }
 
     let allowButtonText =
       gNavigatorBundle.getString("lwthemeInstallRequest.allowButton");
     let allowButtonAccesskey =
       gNavigatorBundle.getString("lwthemeInstallRequest.allowButton.accesskey");
     let message =
       gNavigatorBundle.getFormattedString("lwthemeInstallRequest.message",
-                                          [makeURI(baseURI).host]);
+                                          [uri.host]);
     let buttons = [{
       label: allowButtonText,
       accessKey: allowButtonAccesskey,
       callback: function () {
-        LightWeightThemeWebInstaller._install(data);
+        LightWeightThemeWebInstaller._install(data, notify);
       }
     }];
 
     this._removePreviousNotifications();
 
     let notificationBox = gBrowser.getNotificationBox();
     let notificationBar =
       notificationBox.appendNotification(message, "lwtheme-install-request", "",
                                          notificationBox.PRIORITY_INFO_MEDIUM,
                                          buttons);
     notificationBar.persistence = 1;
   },
 
-  _install: function (newLWTheme) {
+  _install: function (newLWTheme, notify) {
     let previousLWTheme = this._manager.currentTheme;
 
     let listener = {
       onEnabling: function(aAddon, aRequiresRestart) {
         if (!aRequiresRestart) {
           return;
         }
 
@@ -551,17 +570,19 @@ var LightWeightThemeWebInstaller = {
         };
 
         PopupNotifications.show(gBrowser.selectedBrowser, "addon-theme-change",
                                 messageString, "addons-notification-icon",
                                 action, null, options);
       },
 
       onEnabled: function(aAddon) {
-        LightWeightThemeWebInstaller._postInstallNotification(newLWTheme, previousLWTheme);
+        if (notify) {
+          LightWeightThemeWebInstaller._postInstallNotification(newLWTheme, previousLWTheme);
+        }
       }
     };
 
     AddonManager.addAddonListener(listener);
     this._manager.currentTheme = newLWTheme;
     AddonManager.removeAddonListener(listener);
   },