Bug 598923 - add-on bar should be made visible if there are any add-ons installed (r=dao, a=blocking)
authorDietrich Ayala <dietrich@mozilla.com>
Tue, 16 Nov 2010 20:19:50 +0700
changeset 57573 6b25735eebd08801845e958e0f88ee5c1d57f79a
parent 57572 2bcf34fc37a76cb179447839bfb30e30f1f1efb0
child 57574 f9e32506519f880bf8f548cd285f813da12d1d8c
push id16987
push userdietrich@mozilla.com
push dateTue, 16 Nov 2010 13:21:08 +0000
treeherdermozilla-central@6b25735eebd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao, blocking
bugs598923
milestone2.0b8pre
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 598923 - add-on bar should be made visible if there are any add-ons installed (r=dao, a=blocking)
browser/base/content/browser.js
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug598923.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1373,16 +1373,17 @@ function delayedStartup(isLoadingBlank, 
   Services.obs.addObserver(gXPInstallObserver, "addon-install-failed", false);
   Services.obs.addObserver(gXPInstallObserver, "addon-install-complete", false);
   Services.obs.addObserver(gFormSubmitObserver, "invalidformsubmit", false);
 
   BrowserOffline.init();
   OfflineApps.init();
   IndexedDBPromptHelper.init();
   gFormSubmitObserver.init();
+  AddonManager.addAddonListener(AddonsMgrListener);
 
   gBrowser.addEventListener("pageshow", function(evt) { setTimeout(pageShowEventHandlers, 0, evt); }, true);
 
   // Ensure login manager is up and running.
   Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
 
   if (mustLoadSidebar) {
     let sidebar = document.getElementById("sidebar");
@@ -1636,16 +1637,17 @@ function BrowserShutdown()
   } catch (ex) {
     Components.utils.reportError(ex);
   }
 
   BrowserOffline.uninit();
   OfflineApps.uninit();
   gPrivateBrowsingUI.uninit();
   IndexedDBPromptHelper.uninit();
+  AddonManager.removeAddonListener(AddonsMgrListener);
 
   var enumerator = Services.wm.getEnumerator(null);
   enumerator.getNext();
   if (!enumerator.hasMoreElements()) {
     document.persist("sidebar-box", "sidebarcommand");
     document.persist("sidebar-box", "width");
     document.persist("sidebar-box", "src");
     document.persist("sidebar-title", "value");
@@ -8045,8 +8047,38 @@ function duplicateTabIn(aTab, where, his
       loadInBackground = !loadInBackground;
       // fall through
     case "tab":
       if (!loadInBackground)
         gBrowser.selectedTab = newTab;
       break;
   }
 }
+
+/*
+ * When addons are installed/uninstalled, check and see if the number of items
+ * on the add-on bar changed:
+ * - If an add-on was installed, incrementing the count, show the bar.
+ * - If an add-on was uninstalled, and no more items are left, hide the bar.
+ */
+let AddonsMgrListener = {
+  get addonBar() document.getElementById("addon-bar"),
+  get statusBar() document.getElementById("status-bar"),
+  getAddonBarItemCount: function() {
+    // Take into account the contents of the status bar shim for the count.
+    return this.addonBar.childNodes.length - 1 +
+           this.statusBar.childNodes.length;
+  },
+  onInstalling: function(aAddon) {
+    this.lastAddonBarCount = this.getAddonBarItemCount();
+  },
+  onInstalled: function(aAddon) {
+    if (this.getAddonBarItemCount() > this.lastAddonBarCount)
+      setToolbarVisibility(this.addonBar, true);
+  },
+  onUninstalling: function(aAddon) {
+    this.lastAddonBarCount = this.getAddonBarItemCount();
+  },
+  onUninstalled: function(aAddon) {
+    if (this.lastAddonBarCount > 0 && this.getAddonBarItemCount() == 0)
+      setToolbarVisibility(this.addonBar, false);
+  }
+};
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -155,16 +155,17 @@ endif
                  browser_bug581947.js \
                  browser_bug585785.js \
                  browser_bug585830.js \
                  browser_bug592338.js \
                  browser_bug594131.js \
                  browser_bug595507.js \
                  browser_bug596687.js \
                  browser_bug597218.js \
+                 browser_bug598923.js \
                  browser_bug599325.js \
                  browser_bug609700.js \
                  browser_contextSearchTabPosition.js \
                  browser_ctrlTab.js \
                  browser_discovery.js \
                  browser_duplicateIDs.js \
                  browser_gestureSupport.js \
                  browser_getshortcutoruri.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug598923.js
@@ -0,0 +1,32 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// Test:
+// * if add-on is installed to the add-on bar, the bar is made visible.
+// * if add-on is uninstalled from the add-on bar, and no more add-ons there,
+//   the bar is hidden.
+
+function test() {
+  let aml = AddonsMgrListener;
+  ok(aml, "AddonsMgrListener exists");
+  // check is hidden
+  is(aml.addonBar.collapsed, true, "aob is hidden");
+  // aob gets the count
+  AddonsMgrListener.onInstalling();
+  // add an item
+  let element = document.createElement("toolbaritem");
+  aml.addonBar.appendChild(element);
+  // aob checks the count, makes visible
+  AddonsMgrListener.onInstalled();
+  // check is visible
+  is(aml.addonBar.collapsed, false, "aob is visible");
+  // aob gets the count
+  AddonsMgrListener.onUninstalling();
+  // remove an item
+  aml.addonBar.removeChild(element);
+  // aob checks the count, makes hidden
+  AddonsMgrListener.onUninstalled();
+  // check is hidden
+  is(aml.addonBar.collapsed, true, "aob is hidden");
+}