Bug 1496632 - Add prompt for sideloaded extensions to notification UI; r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 19 Oct 2018 21:59:41 +1300
changeset 33419 7d6de3006fc3475ffb21d6982adc60a32c48c7cc
parent 33418 e16ec20c7395cf961894b9d67936208ad906ab31
child 33420 1c197e89daef90e15018adc1544312658207bf49
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersmkmelin
bugs1496632
Bug 1496632 - Add prompt for sideloaded extensions to notification UI; r=mkmelin
mail/base/modules/ExtensionsUI.jsm
mail/components/mailGlue.js
--- a/mail/base/modules/ExtensionsUI.jsm
+++ b/mail/base/modules/ExtensionsUI.jsm
@@ -1,23 +1,24 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-this.EXPORTED_SYMBOLS = [];
+this.EXPORTED_SYMBOLS = ["ExtensionsUI"];
 
 const ADDONS_PROPERTIES = "chrome://messenger/locale/addons.properties";
 const BRAND_PROPERTIES = "chrome://branding/locale/brand.properties";
 const DEFAULT_EXTENSION_ICON = "chrome://mozapps/skin/extensions/extensionGeneric.svg";
 const HTML_NS = "http://www.w3.org/1999/xhtml";
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 XPCOMUtils.defineLazyModuleGetters(this, {
   AddonManager: "resource://gre/modules/AddonManager.jsm",
+  AddonManagerPrivate: "resource://gre/modules/AddonManager.jsm",
   ExtensionData: "resource://gre/modules/Extension.jsm",
   PluralForm: "resource://gre/modules/PluralForm.jsm",
   Services: "resource://gre/modules/Services.jsm",
   setTimeout: "resource://gre/modules/Timer.jsm",
   StringBundle: "resource:///modules/StringBundle.js",
 });
 
 XPCOMUtils.defineLazyGetter(this, "addonsBundle", function() {
@@ -612,21 +613,44 @@ var gXPInstallObserver = {
   },
 
   _removeProgressNotification(browser) {
     let notification = getNotification("addon-progress", browser);
     if (notification) {
       notification.remove();
     }
   },
+
+  async _checkForSideloaded(browser) {
+    let sideloaded = await AddonManagerPrivate.getNewSideloads();
+    for (let addon of sideloaded) {
+      let strings = this._buildStrings({
+        addon,
+        permissions: addon.userPermissions,
+        type: "sideload",
+      });
+      let answer = await this.showPermissionsPrompt(browser, strings, addon.iconURL);
+      if (answer) {
+        await addon.enable();
+      }
+    }
+  },
 };
 
 Services.obs.addObserver(gXPInstallObserver, "addon-install-disabled");
 Services.obs.addObserver(gXPInstallObserver, "addon-install-origin-blocked");
 Services.obs.addObserver(gXPInstallObserver, "addon-install-blocked");
 Services.obs.addObserver(gXPInstallObserver, "addon-install-started");
 Services.obs.addObserver(gXPInstallObserver, "addon-install-failed");
 Services.obs.addObserver(gXPInstallObserver, "addon-install-confirmation");
 Services.obs.addObserver(gXPInstallObserver, "addon-install-complete");
 Services.obs.addObserver(gXPInstallObserver, "webextension-permission-prompt");
 Services.obs.addObserver(gXPInstallObserver, "webextension-update-permissions");
 Services.obs.addObserver(gXPInstallObserver, "webextension-install-notify");
 Services.obs.addObserver(gXPInstallObserver, "webextension-optional-permission-prompt");
+
+var ExtensionsUI = {
+  checkForSideloadedExtensions() {
+    let win = Services.wm.getMostRecentWindow("mail:3pane");
+    let tabmail = win.document.getElementById("tabmail");
+    gXPInstallObserver._checkForSideloaded(tabmail.selectedBrowser);
+  },
+};
--- a/mail/components/mailGlue.js
+++ b/mail/components/mailGlue.js
@@ -193,51 +193,27 @@ MailGlue.prototype = {
       sidebar_text: "rgb(249, 249, 250)",
       sidebar_border: "rgba(255, 255, 255, 0.2)",
       author: vendorShortName,
     }, {
       useInDarkMode: true,
     });
   },
 
- _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 });
-    });
-  },
-
-  async _detectNewSideloadedAddons() {
-    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) {
       const { WinTaskbarJumpList } = ChromeUtils.import("resource:///modules/windowsJumpLists.js", null);
       WinTaskbarJumpList.startup();
     }
 
-    // For any add-ons that were installed disabled and can be enabled, offer
-    // them to the user.
-    var changedIDs = AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_INSTALLED);
-    AddonManager.getAddonsByIDs(changedIDs, this._offertToEnableAddons.bind(this));
-
-    this._detectNewSideloadedAddons();
+    ChromeUtils.import("resource:///modules/ExtensionsUI.jsm");
+    ExtensionsUI.checkForSideloadedExtensions();
   },
 
   _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 };