Bug 1359733 - (pt. 3) Pull out browser-addons.js badges draft
authorDoug Thayer <dothayer@mozilla.com>
Mon, 15 May 2017 10:38:33 -0700
changeset 583048 66fd989a62c7f15315b7d4816ac3b09010fdd270
parent 583047 1438ba81708d072e1850d22f4b80304429c226de
child 583049 cf1d5078a43bbc2259601858d712ee73e83c13b2
push id60284
push userbmo:dothayer@mozilla.com
push dateTue, 23 May 2017 17:20:55 +0000
bugs1359733
milestone55.0a1
Bug 1359733 - (pt. 3) Pull out browser-addons.js badges We are moving app menu doorhangers and badges out from window- specific code into a jsm, in order to simplify the work that the new app udpate UI has to do. Since browser-addons.js also consumes the badge system, this ensures that it also uses the jsm store. MozReview-Commit-ID: Fb5Fsja0RcA
browser/base/content/browser-addons.js
browser/modules/ExtensionsUI.jsm
--- a/browser/base/content/browser-addons.js
+++ b/browser/base/content/browser-addons.js
@@ -510,21 +510,16 @@ const gExtensionsNotifications = {
 
     button.addEventListener("click", callback);
     PanelUI.addonNotificationContainer.appendChild(button);
   },
 
   updateAlerts() {
     let sideloaded = ExtensionsUI.sideloaded;
     let updates = ExtensionsUI.updates;
-    if (sideloaded.size + updates.size == 0) {
-      PanelUI.removeNotification("addon-alert");
-    } else {
-      PanelUI.showBadgeOnlyNotification("addon-alert");
-    }
 
     let container = PanelUI.addonNotificationContainer;
 
     while (container.firstChild) {
       container.firstChild.remove();
     }
 
     let items = 0;
--- a/browser/modules/ExtensionsUI.jsm
+++ b/browser/modules/ExtensionsUI.jsm
@@ -9,16 +9,18 @@ this.EXPORTED_SYMBOLS = ["ExtensionsUI"]
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/EventEmitter.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
                                   "resource://gre/modules/AddonManager.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManagerPrivate",
                                   "resource://gre/modules/AddonManager.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "AppMenuNotifications",
+                                  "resource://gre/modules/AppMenuNotifications.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
                                   "resource://gre/modules/PluralForm.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
                                   "resource:///modules/RecentWindow.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
                                   "resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "WEBEXT_PERMISSION_PROMPTS",
@@ -66,55 +68,64 @@ this.ExtensionsUI = {
       if (!this.sideloadListener) {
         this.sideloadListener = {
           onEnabled: addon => {
             if (!this.sideloaded.has(addon)) {
               return;
             }
 
             this.sideloaded.delete(addon);
-            this.emit("change");
+              this._updateNotifications();
 
             if (this.sideloaded.size == 0) {
               AddonManager.removeAddonListener(this.sideloadListener);
               this.sideloadListener = null;
             }
           },
         };
         AddonManager.addAddonListener(this.sideloadListener);
       }
 
       for (let addon of sideloaded) {
         this.sideloaded.add(addon);
       }
-      this.emit("change");
+        this._updateNotifications();
     } else {
       // This and all the accompanying about:newaddon code can eventually
       // be removed.  See bug 1331521.
       let win = RecentWindow.getMostRecentBrowserWindow();
       for (let addon of sideloaded) {
         win.openUILinkIn(`about:newaddon?id=${addon.id}`, "tab");
       }
     }
   },
 
+  _updateNotifications() {
+    if (this.sideloaded.size + this.updates.size == 0) {
+      AppMenuNotifications.removeNotification("addon-alert");
+    } else {
+      AppMenuNotifications.showBadgeOnlyNotification("addon-alert");
+    }
+    this.emit("change");
+  },
+
   showAddonsManager(browser, strings, icon, histkey) {
     let global = browser.selectedBrowser.ownerGlobal;
     return global.BrowserOpenAddonsMgr("addons://list/extension").then(aomWin => {
       let aomBrowser = aomWin.QueryInterface(Ci.nsIInterfaceRequestor)
                              .getInterface(Ci.nsIDocShell)
                              .chromeEventHandler;
       return this.showPermissionsPrompt(aomBrowser, strings, icon, histkey);
     });
   },
 
   showSideloaded(browser, addon) {
     addon.markAsSeen();
     this.sideloaded.delete(addon);
-    this.emit("change");
+    this._updateNotifications();
 
     let strings = this._buildStrings({
       addon,
       permissions: addon.userPermissions,
       type: "sideload",
     });
     this.showAddonsManager(browser, strings, addon.iconURL, "sideload")
         .then(answer => {
@@ -128,17 +139,17 @@ this.ExtensionsUI = {
           if (answer) {
             info.resolve();
           } else {
             info.reject();
           }
           // At the moment, this prompt will re-appear next time we do an update
           // check.  See bug 1332360 for proposal to avoid this.
           this.updates.delete(info);
-          this.emit("change");
+          this._updateNotifications();
         });
   },
 
   observe(subject, topic, data) {
     if (topic == "webextension-permission-prompt") {
       let {target, info} = subject.wrappedJSObject;
 
       // Dismiss the progress notification.  Note that this is bad if
@@ -200,17 +211,17 @@ this.ExtensionsUI = {
       let update = {
         strings,
         addon: info.addon,
         resolve: info.resolve,
         reject: info.reject,
       };
 
       this.updates.add(update);
-      this.emit("change");
+      this._updateNotifications();
     } else if (topic == "webextension-install-notify") {
       let {target, addon, callback} = subject.wrappedJSObject;
       this.showInstallNotification(target, addon).then(() => {
         if (callback) {
           callback();
         }
       });
     } else if (topic == "webextension-optional-permission-prompt") {