Bug 1450926 - Detection of side-loaded add-ons: Offer user to enable new side-loaded add-ons. r=philipp a=jorgk
authorChris <chris@birdiesync.com>
Wed, 02 May 2018 13:14:58 +0200
changeset 31442 c1de436bc575c5f901f64dfe83c142951611df8f
parent 31441 b2d63636dca84397d55784504b141e450b6c8e2a
child 31443 ce49187468a02223fc7dfed5fda6796061ba9895
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersphilipp, jorgk
bugs1450926
Bug 1450926 - Detection of side-loaded add-ons: Offer user to enable new side-loaded add-ons. r=philipp a=jorgk
mail/components/mailGlue.js
--- a/mail/components/mailGlue.js
+++ b/mail/components/mailGlue.js
@@ -130,41 +130,51 @@ MailGlue.prototype = {
       accentcolor: "black",
       popup: "#4a4a4f",
       popup_text: "rgb(249, 249, 250)",
       popup_border: "#27272b",
       author: vendorShortName,
     });
   },
 
+ _offertToEnableAddons(aAddons) {
+    let win = Services.wm.getMostRecentWindow("mail:3pane");
+    let tabmail = win.document.getElementById("tabmail");
+
+    aAddons.forEach(function(aAddon) {
+    // If the add-on isn't user disabled or can't be enabled, then skip it.
+    if (!aAddon.userDisabled || !(aAddon.permissions & AddonManager.PERM_CAN_ENABLE))
+      return;
+
+    tabmail.openTab("contentTab",
+                    { contentPage: "about:newaddon?id=" + aAddon.id,
+                      clickHandler: null });
+    });
+  },
+
+  _detectNewSideloadedAddons: async function () {
+    let newSideloadedAddons = await AddonManagerPrivate.getNewSideloads();
+    this._offertToEnableAddons(newSideloadedAddons);
+  },
+
   _onMailStartupDone: function MailGlue__onMailStartupDone() {
     // On Windows 7 and above, initialize the jump list module.
     const WINTASKBAR_CONTRACTID = "@mozilla.org/windows-taskbar;1";
     if (WINTASKBAR_CONTRACTID in Cc &&
         Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar).available) {
       ChromeUtils.import("resource:///modules/windowsJumpLists.js");
       WinTaskbarJumpList.startup();
     }
 
     // For any add-ons that were installed disabled and can be enabled, offer
     // them to the user.
-    var win = Services.wm.getMostRecentWindow("mail:3pane");
-    var tabmail = win.document.getElementById("tabmail");
     var changedIDs = AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_INSTALLED);
-    AddonManager.getAddonsByIDs(changedIDs, function (aAddons) {
-      aAddons.forEach(function(aAddon) {
-        // If the add-on isn't user disabled or can't be enabled then skip it.
-        if (!aAddon.userDisabled || !(aAddon.permissions & AddonManager.PERM_CAN_ENABLE))
-          return;
+    AddonManager.getAddonsByIDs(changedIDs, this._offertToEnableAddons.bind(this));
 
-        tabmail.openTab("contentTab",
-                        { contentPage: "about:newaddon?id=" + aAddon.id,
-                          clickHandler: null });
-      });
-    });
+    this._detectNewSideloadedAddons();
   },
 
   _handleLink: function MailGlue__handleLink(aSubject, aData) {
     let linkHandled = aSubject.QueryInterface(Ci.nsISupportsPRBool);
     if (!linkHandled.data) {
       let win = Services.wm.getMostRecentWindow("mail:3pane");
       aData = JSON.parse(aData);
       let tabParams = { contentPage: aData.href, clickHandler: null };