Bug 1392653: Remove redundant LegacyExtensionUtils shutdown blocker. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 24 Aug 2017 15:01:55 -0700
changeset 652490 81f1033903be8e2aa241e496167de64b6332119d
parent 652489 6dab9d07dc51be6a2747a523474f996ea6a12389
child 653288 7fee753b2fa729e2cf3970694fc3a318a8d47cbc
push id76072
push usermaglione.k@gmail.com
push dateThu, 24 Aug 2017 22:05:35 +0000
reviewersaswan
bugs1392653
milestone57.0a1
Bug 1392653: Remove redundant LegacyExtensionUtils shutdown blocker. r?aswan The base Extension class now handles adding shutdown blockers and waiting for extension startup before beginning shutdown, so the redundant logic only causes problems. MozReview-Commit-ID: 2gBWlmIs1KQ
toolkit/components/extensions/LegacyExtensionsUtils.jsm
--- a/toolkit/components/extensions/LegacyExtensionsUtils.jsm
+++ b/toolkit/components/extensions/LegacyExtensionsUtils.jsm
@@ -12,18 +12,16 @@ this.EXPORTED_SYMBOLS = ["LegacyExtensio
  * This file exports helpers for Legacy Extensions that want to embed a webextensions
  * and exchange messages with the embedded WebExtension.
  */
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
-XPCOMUtils.defineLazyModuleGetter(this, "AsyncShutdown",
-                                  "resource://gre/modules/AsyncShutdown.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Extension",
                                   "resource://gre/modules/Extension.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ExtensionChild",
                                   "resource://gre/modules/ExtensionChild.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
                                   "resource://gre/modules/Services.jsm");
 
 Cu.import("resource://gre/modules/ExtensionCommon.jsm");
@@ -197,38 +195,26 @@ class EmbeddedExtension {
     return this.startupPromise;
   }
 
   /**
    * Shuts down the embedded webextension.
    *
    * @returns {Promise<void>} a promise that is resolved when the shutdown has been done
    */
-  shutdown() {
+  async shutdown() {
     EmbeddedExtensionManager.untrackEmbeddedExtension(this);
 
-    // If there is a pending startup,  wait to be completed and then shutdown.
-    if (this.startupPromise) {
-      let promise = this.startupPromise.then(() => {
-        return this.extension.shutdown();
-      });
-
-      AsyncShutdown.profileChangeTeardown.addBlocker(
-        `Legacy Extension Shutdown: ${this.addonId}`,
-        promise.catch(() => {}));
+    if (this.extension && !this.extension.hasShutdown) {
+      let {extension} = this;
+      this.extension = null;
 
-      return promise;
+      await extension.shutdown();
     }
-
-    // Run shutdown now if the embedded webextension has been correctly started
-    if (this.extension && this.started && !this.extension.hasShutdown) {
-      this.extension.shutdown();
-    }
-
-    return Promise.resolve();
+    return undefined;
   }
 }
 
 // Keep track on the created EmbeddedExtension instances and destroy
 // them when their container addon is going to be disabled or uninstalled.
 EmbeddedExtensionManager = {
   // Map of the existent EmbeddedExtensions instances by addon id.
   embeddedExtensionsByAddonId: new Map(),