Bug 1392872 - Fix missing startup/shutdown reason in LegacyExtensionsUtils. draft
authorLuca Greco <lgreco@mozilla.com>
Wed, 23 Aug 2017 15:43:09 +0200
changeset 652093 7f81c454c5529951f1bd9c9d312a228c78bac0cd
parent 651207 b911a4c97fde5d8bdeebfd5d0266ee9f7b9e59b2
child 727975 39d498511fd2dd21be3b222b129e49ce91577ba4
push id75934
push userluca.greco@alcacoop.it
push dateThu, 24 Aug 2017 11:58:37 +0000
bugs1392872
milestone57.0a1
Bug 1392872 - Fix missing startup/shutdown reason in LegacyExtensionsUtils. MozReview-Commit-ID: K8pyxR7Vhpl
toolkit/components/extensions/LegacyExtensionsUtils.jsm
--- a/toolkit/components/extensions/LegacyExtensionsUtils.jsm
+++ b/toolkit/components/extensions/LegacyExtensionsUtils.jsm
@@ -123,20 +123,23 @@ class EmbeddedExtension {
 
     // Setup status flag.
     this.started = false;
   }
 
   /**
    * Start the embedded webextension.
    *
+   * @param {number} reason
+   *   The add-on startup bootstrap reason received from the XPIProvider.
+   *
    * @returns {Promise<LegacyContextAPI>} A promise which resolve to the API exposed to the
    *   legacy context.
    */
-  startup() {
+  startup(reason) {
     if (this.started) {
       return Promise.reject(new Error("This embedded extension has already been started"));
     }
 
     // Setup the startup promise.
     this.startupPromise = new Promise((resolve, reject) => {
       let embeddedExtensionURI = Services.io.newURI("webextension/", null, this.resourceURI);
 
@@ -180,52 +183,55 @@ class EmbeddedExtension {
         // chained to it.
         resolve(this.context.api);
       };
 
       this.extension.on("startup", onBeforeStarted);
 
       // Run ambedded extension startup and catch any error during embedded extension
       // startup.
-      this.extension.startup().catch((err) => {
+      this.extension.startup(reason).catch((err) => {
         this.started = false;
         this.startupPromise = null;
         this.extension.off("startup", onBeforeStarted);
 
         reject(err);
       });
     });
 
     return this.startupPromise;
   }
 
   /**
    * Shuts down the embedded webextension.
    *
+   * @param {number} reason
+   *   The add-on shutdown bootstrap reason received from the XPIProvider.
+   *
    * @returns {Promise<void>} a promise that is resolved when the shutdown has been done
    */
-  shutdown() {
+  shutdown(reason) {
     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();
+        return this.extension.shutdown(reason);
       });
 
       AsyncShutdown.profileChangeTeardown.addBlocker(
         `Legacy Extension Shutdown: ${this.addonId}`,
         promise.catch(() => {}));
 
       return promise;
     }
 
     // Run shutdown now if the embedded webextension has been correctly started
     if (this.extension && this.started && !this.extension.hasShutdown) {
-      this.extension.shutdown();
+      this.extension.shutdown(reason);
     }
 
     return Promise.resolve();
   }
 }
 
 // Keep track on the created EmbeddedExtension instances and destroy
 // them when their container addon is going to be disabled or uninstalled.