Bug 1574183 - At start-up, check for newer versions of extensions disabled by application update. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 29 Jan 2020 12:54:03 +0200
changeset 37153 71a037b9e9cd27ad72740b45d5bf1f4d8c6e6d8d
parent 37152 cbfeac2dfd57d092d8e1498ad806e63dad213661
child 37154 66070529eac2ec0d93e3855674a3a6f87b132106
push id2552
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:24:16 +0000
treeherdercomm-beta@f95a6f4408a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1574183
Bug 1574183 - At start-up, check for newer versions of extensions disabled by application update. r=mkmelin
mail/components/MailGlue.jsm
--- a/mail/components/MailGlue.jsm
+++ b/mail/components/MailGlue.jsm
@@ -133,16 +133,25 @@ MailGlue.prototype = {
       "Thunderbird-internal-BrowserConsole"
     );
   },
 
   // nsIObserver implementation
   observe(aSubject, aTopic, aData) {
     let fs;
     switch (aTopic) {
+      case "app-startup":
+        // Record the previously started version. This is used to check for
+        // extensions that were disabled by an application update. We need to
+        // read this pref before the Add-Ons Manager changes it.
+        this.previousVersion = Services.prefs.getCharPref(
+          "extensions.lastAppVersion",
+          "0"
+        );
+        break;
       case "xpcom-shutdown":
         this._dispose();
         break;
       case "intl:app-locales-changed":
         fs = Cc["@mozilla.org/msgFolder/msgFolderService;1"].getService(
           Ci.nsIMsgFolderService
         );
         fs.initializeFolderStrings();
@@ -251,16 +260,54 @@ MailGlue.prototype = {
       WinTaskbarJumpList.startup();
     }
 
     const { ExtensionsUI } = ChromeUtils.import(
       "resource:///modules/ExtensionsUI.jsm"
     );
     ExtensionsUI.checkForSideloadedExtensions();
 
+    // If the application has been updated, look for any extensions that may
+    // have been disabled by the update, and check for newer versions of those
+    // extensions.
+    let currentVersion = Services.appinfo.version;
+    if (this.previousVersion != "0" && this.previousVersion != currentVersion) {
+      let { AddonManager } = ChromeUtils.import(
+        "resource://gre/modules/AddonManager.jsm"
+      );
+      let startupChanges = AddonManager.getStartupChanges(
+        AddonManager.STARTUP_CHANGE_DISABLED
+      );
+      if (startupChanges.length > 0) {
+        let { XPIDatabase } = ChromeUtils.import(
+          "resource://gre/modules/addons/XPIDatabase.jsm"
+        );
+        let addons = XPIDatabase.getAddons();
+        for (let addon of addons) {
+          if (
+            startupChanges.includes(addon.id) &&
+            addon.permissions() & AddonManager.PERM_CAN_UPGRADE &&
+            !addon.isCompatible
+          ) {
+            AddonManager.getAddonByID(addon.id).then(addon => {
+              addon.findUpdates(
+                {
+                  onUpdateFinished() {},
+                  onUpdateAvailable(addon, install) {
+                    install.install();
+                  },
+                },
+                AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED
+              );
+            });
+          }
+        }
+      }
+    }
+
     // Certificates revocation list, etc.
     Services.tm.idleDispatchToMainThread(() => {
       RemoteSecuritySettings.init();
     });
   },
 
   _handleLink(aSubject, aData) {
     let linkHandled = aSubject.QueryInterface(Ci.nsISupportsPRBool);