Bug 1466349 part 1 - Enable passing addonData flags to embedded WE, draft
authorTomislav Jovanovic <tomica@gmail.com>
Tue, 05 Jun 2018 20:26:24 +0200
changeset 804312 a236ed6854a475a2ff9d8387f6ed9ce62d766bb8
parent 803222 8c926373039374cd1a47d92215e9efb4d5557983
child 804313 fbe7ca62cafe2727c8b2a816555986a8e796e097
push id112338
push userbmo:tomica@gmail.com
push dateTue, 05 Jun 2018 18:32:54 +0000
bugs1466349
milestone62.0a1
Bug 1466349 part 1 - Enable passing addonData flags to embedded WE, also fix permission matcher creation in child process MozReview-Commit-ID: Ht9rEKwaUsp
toolkit/components/extensions/LegacyExtensionsUtils.jsm
toolkit/components/extensions/extension-process-script.js
--- a/toolkit/components/extensions/LegacyExtensionsUtils.jsm
+++ b/toolkit/components/extensions/LegacyExtensionsUtils.jsm
@@ -122,31 +122,38 @@ class EmbeddedExtension {
     this.started = false;
   }
 
   /**
    * Start the embedded webextension.
    *
    * @param {number} reason
    *   The add-on startup bootstrap reason received from the XPIProvider.
+   * @param {object} [addonData]
+   *   Additional data to pass to the Extension constructor.
    *
    * @returns {Promise<LegacyContextAPI>} A promise which resolve to the API exposed to the
    *   legacy context.
    */
-  startup(reason) {
+  startup(reason, addonData = {}) {
     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);
 
+      let {builtIn, signedState, temporarilyInstalled} = addonData;
+
       // This is the instance of the WebExtension embedded in the hybrid add-on.
       this.extension = new Extension({
+        builtIn,
+        signedState,
+        temporarilyInstalled,
         id: this.addonId,
         resourceURI: embeddedExtensionURI,
         version: this.version,
       });
 
       this.extension.isEmbedded = true;
 
       // This callback is register to the "startup" event, emitted by the Extension instance
--- a/toolkit/components/extensions/extension-process-script.js
+++ b/toolkit/components/extensions/extension-process-script.js
@@ -316,30 +316,30 @@ ExtensionManager = {
       Services.cpmm.addMessageListener("Schema:Add", this);
     }
   },
 
   initExtensionPolicy(extension) {
     let policy = WebExtensionPolicy.getByID(extension.id);
     if (!policy) {
       let localizeCallback, allowedOrigins, webAccessibleResources;
+      let restrictSchemes = !extension.permissions.has("mozillaAddons");
+
       if (extension.localize) {
         // We have a real Extension object.
         localizeCallback = extension.localize.bind(extension);
         allowedOrigins = extension.whiteListedHosts;
         webAccessibleResources = extension.webAccessibleResources;
       } else {
         // We have serialized extension data;
         localizeCallback = str => extensions.get(policy).localize(str);
-        allowedOrigins = new MatchPatternSet(extension.whiteListedHosts);
+        allowedOrigins = new MatchPatternSet(extension.whiteListedHosts, {restrictSchemes});
         webAccessibleResources = extension.webAccessibleResources.map(host => new MatchGlob(host));
       }
 
-      let restrictSchemes = !extension.permissions.has("mozillaAddons");
-
       policy = new WebExtensionPolicy({
         id: extension.id,
         mozExtensionHostname: extension.uuid,
         name: extension.name,
         baseURL: extension.resourceURL,
 
         permissions: Array.from(extension.permissions),
         allowedOrigins,