Bug 1554127 - Invalidate the start-up cache on legacy extension installation. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 04 Jun 2019 19:51:03 +1200
changeset 35791 72ff6b1ef248bc2cd44edcc3afbfc060e2cb1778
parent 35790 739e1e886d5204f70de3d4272ecd6bc1ad2d69c8
child 35792 20fc951885d9772e559459f83261e25f48bd77a0
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersmkmelin
bugs1554127
Bug 1554127 - Invalidate the start-up cache on legacy extension installation. r=mkmelin
mail/components/extensions/parent/ext-legacy.js
--- a/mail/components/extensions/parent/ext-legacy.js
+++ b/mail/components/extensions/parent/ext-legacy.js
@@ -52,22 +52,27 @@ this.legacy = class extends ExtensionAPI
     let state = {
       id: this.extension.id,
       pendingOperation: null,
       version: this.extension.version,
     };
     if (ExtensionSupport.loadedLegacyExtensions.has(this.extension.id)) {
       state = ExtensionSupport.loadedLegacyExtensions.get(this.extension.id);
       let versionComparison = Services.vc.compare(this.extension.version, state.version);
-      if (versionComparison > 0) {
-        state.pendingOperation = "upgrade";
-        ExtensionSupport.loadedLegacyExtensions.notifyObservers(state);
-      } else if (versionComparison < 0) {
-        state.pendingOperation = "downgrade";
-        ExtensionSupport.loadedLegacyExtensions.notifyObservers(state);
+      if (versionComparison != 0) {
+        if (versionComparison > 0) {
+          state.pendingOperation = "upgrade";
+          ExtensionSupport.loadedLegacyExtensions.notifyObservers(state);
+        } else if (versionComparison < 0) {
+          state.pendingOperation = "downgrade";
+          ExtensionSupport.loadedLegacyExtensions.notifyObservers(state);
+        }
+
+        // Forget any cached files we might've had from another version of this extension.
+        Services.obs.notifyObservers(null, "startupcache-invalidate");
       }
       console.log(`Legacy WebExtension ${this.extension.id} has already been loaded in this run, refusing to do so again. Please restart.`);
       return;
     }
 
     ExtensionSupport.loadedLegacyExtensions.set(this.extension.id, state);
     if (this.extension.startupReason == "ADDON_INSTALL") {
       // Usually, sideloaded extensions are disabled when they first appear,
@@ -80,16 +85,19 @@ this.legacy = class extends ExtensionAPI
       let isDistroAddon = Services.prefs.getBoolPref(
         "extensions.installedDistroAddon." + this.extension.id, false
       );
 
       if (!isDistroAddon && (scope & autoDisableScopes)) {
         state.pendingOperation = "install";
         console.log(`Legacy WebExtension ${this.extension.id} loading for other reason than startup (${this.extension.startupReason}), refusing to load immediately.`);
         ExtensionSupport.loadedLegacyExtensions.notifyObservers(state);
+
+        // Forget any cached files we might've had if this extension was previously installed.
+        Services.obs.notifyObservers(null, "startupcache-invalidate");
         return;
       }
     }
     if (this.extension.startupReason == "ADDON_ENABLE") {
       state.pendingOperation = "enable";
       console.log(`Legacy WebExtension ${this.extension.id} loading for other reason than startup (${this.extension.startupReason}), refusing to load immediately.`);
       ExtensionSupport.loadedLegacyExtensions.notifyObservers(state);
       return;