Bug 1466349 - Part 1: Enable passing addonData flags to embedded WE. r=aswan, a=RyanVM
authorTomislav Jovanovic <tomica@gmail.com>
Tue, 05 Jun 2018 20:26:24 +0200
changeset 473618 68167e946240b461513fbbc3e53b9fbf6f354ba4
parent 473617 2d9d187e5b04774262ead862935055387f9d4fa1
child 473619 4a309778103f3906f6963704db8b244b25bf7665
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, RyanVM
bugs1466349
milestone61.0
Bug 1466349 - Part 1: Enable passing addonData flags to embedded WE. r=aswan, a=RyanVM 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,