Bug 1252215 - Integrate changes to LegacyExtensionUtils.jsm into the patch rebased for aurora. r=kmag, r=aswan, a=ritu
authorLuca Greco <lgreco@mozilla.com>
Fri, 09 Sep 2016 15:14:22 +0200
changeset 350258 352666cdee72996c02990b0b19bd5d1d77ba54d0
parent 350257 bfd7e6f5db590e2b0b65fb0cb2b465cb761fb3df
child 350259 c3bd6ceb6fc2338ff649dd0e8ca5505671090fe4
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag, aswan, ritu
bugs1252215, 1298979
milestone50.0a2
Bug 1252215 - Integrate changes to LegacyExtensionUtils.jsm into the patch rebased for aurora. r=kmag, r=aswan, a=ritu - This patch introduces, on top of the Bug 1252215 patches rebased to aurora, part of the changes introduced in Bug 1298979. MozReview-Commit-ID: ENU5T7mN1GT
toolkit/components/extensions/LegacyExtensionsUtils.jsm
toolkit/components/extensions/test/xpcshell/test_ext_legacy_extension_context.js
--- a/toolkit/components/extensions/LegacyExtensionsUtils.jsm
+++ b/toolkit/components/extensions/LegacyExtensionsUtils.jsm
@@ -35,28 +35,20 @@ var LegacyExtensionContext = class exten
   /**
    * Create a new LegacyExtensionContext given a target Extension instance and an optional
    * url (which can be used to recognize the messages of container context).
    *
    * @param {Extension} targetExtension
    *   The webextension instance associated with this context. This will be the
    *   instance of the newly created embedded webextension when this class is
    *   used through the EmbeddedWebExtensionsUtils.
-   * @param {Object} [optionalParams]
-   *   An object with the following properties:
-   * @param {string}  [optionalParams.url]
-   *   An URL to mark the messages sent from this context
-   *   (e.g. EmbeddedWebExtension sets it to the base url of the container addon).
    */
-  constructor(targetExtension, optionalParams = {}) {
-    let {url} = optionalParams;
-
+  constructor(targetExtension) {
     super(targetExtension, {
       contentWindow: null,
-      uri: NetUtil.newURI(url || "about:blank"),
       type: "legacy_extension",
     });
 
     // Legacy Extensions (xul overlays, bootstrap restartless and Addon SDK)
     // runs with a systemPrincipal.
     let addonPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
     Object.defineProperty(
       this, "principal",
@@ -162,19 +154,17 @@ class EmbeddedExtension {
         this.startupPromise = null;
 
         // Create the legacy extension context, the legacy container addon
         // needs to use it before the embedded webextension startup,
         // because it is supposed to be used during the legacy container startup
         // to subscribe its message listeners (which are supposed to be able to
         // receive any message that the embedded part can try to send to it
         // during its startup).
-        this.context = new LegacyExtensionContext(this.extension, {
-          url: this.resourceURI.resolve("/"),
-        });
+        this.context = new LegacyExtensionContext(this.extension);
 
         // Destroy the LegacyExtensionContext cloneScope when
         // the embedded webextensions is unloaded.
         this.extension.callOnClose({
           close: () => {
             this.context.unload();
           },
         });
--- a/toolkit/components/extensions/test/xpcshell/test_ext_legacy_extension_context.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_legacy_extension_context.js
@@ -24,31 +24,35 @@ add_task(function* test_legacy_extension
     let extensionInfo = {
       bgURL,
       // Extract the assigned uuid from the background page url.
       uuid: window.location.hostname,
     };
 
     browser.test.sendMessage("webextension-ready", extensionInfo);
 
+    let port;
+
     browser.test.onMessage.addListener(msg => {
       if (msg == "do-send-message") {
         browser.runtime.sendMessage("webextension -> legacy_extension message").then(reply => {
           browser.test.assertEq("legacy_extension -> webextension reply", reply,
                                 "Got the expected message from the LegacyExtensionContext");
           browser.test.sendMessage("got-reply-message");
         });
       } else if (msg == "do-connect") {
-        let port = browser.runtime.connect();
+        port = browser.runtime.connect();
 
         port.onMessage.addListener(msg => {
           browser.test.assertEq("legacy_extension -> webextension port message", msg,
                                 "Got the expected message from the LegacyExtensionContext");
           port.postMessage("webextension -> legacy_extension port message");
         });
+      } else if (msg == "do-disconnect") {
+        port.disconnect();
       }
     });
   }
 
   let extensionData = {
     background: "new " + backgroundScript,
   };
 
@@ -60,24 +64,32 @@ add_task(function* test_legacy_extension
         reject(new Error(`Got an unexpected test-message: ${msg}`));
       } else {
         extension.off("test-message", testMessageListener);
         resolve(args[0]);
       }
     });
   });
 
+  // Connect to the target extension as an external context
+  // using the given custom sender info.
+  let legacyContext;
+
+  extension.on("startup", function onStartup() {
+    extension.off("startup", onStartup);
+    legacyContext = new LegacyExtensionContext(extension);
+    extension.callOnClose({
+      close: () => legacyContext.unload(),
+    });
+  });
+
   yield extension.startup();
 
   let extensionInfo = yield waitForExtensionInfo;
 
-  // Connect to the target extension.id as an external context
-  // using the given custom sender info.
-  let legacyContext = new LegacyExtensionContext(extension);
-
   equal(legacyContext.type, "legacy_extension",
      "LegacyExtensionContext instance has the expected type");
 
   ok(legacyContext.api, "Got the expected API object");
   ok(legacyContext.api.browser, "Got the expected browser property");
 
   let waitMessage = new Promise(resolve => {
     const {browser} = legacyContext.api;
@@ -141,16 +153,16 @@ add_task(function* test_legacy_extension
 
   equal(msg, "webextension -> legacy_extension port message",
      "LegacyExtensionContext received the expected message from the webextension");
 
   let waitForDisconnect = new Promise(resolve => {
     port.onDisconnect.addListener(resolve);
   });
 
-  extension.shutdown();
+  extension.testMessage("do-disconnect");
 
   yield waitForDisconnect;
 
   do_print("Got the disconnect event on unload");
 
-  legacyContext.shutdown();
+  yield extension.shutdown();
 });