From 1a7e5aae666e1f5abb53704f02bc6cfade81e3e5 Mon Sep 17 00:00:00 2001 From: Tomislav Jovanovic Date: Tue, 5 Jun 2018 20:26:24 +0200 Subject: [PATCH] Bug 1466349 part 1 - Enable passing addonData flags to embedded WE, r=aswan also fix permission matcher creation in child process MozReview-Commit-ID: Ht9rEKwaUsp --HG-- extra : rebase_source : 196f52ca686ddf9e8eb83ad2e20f4dd5ebb8d544 --- toolkit/components/extensions/LegacyExtensionsUtils.jsm | 9 ++++++++- .../components/extensions/extension-process-script.js | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/toolkit/components/extensions/LegacyExtensionsUtils.jsm b/toolkit/components/extensions/LegacyExtensionsUtils.jsm index 9ec89df38fdb..2dffdf633ad7 100644 --- a/toolkit/components/extensions/LegacyExtensionsUtils.jsm +++ b/toolkit/components/extensions/LegacyExtensionsUtils.jsm @@ -127,11 +127,13 @@ class EmbeddedExtension { * * @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} 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")); } @@ -140,8 +142,13 @@ class EmbeddedExtension { 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, diff --git a/toolkit/components/extensions/extension-process-script.js b/toolkit/components/extensions/extension-process-script.js index 0dd952465bc2..8fc3309f9873 100644 --- a/toolkit/components/extensions/extension-process-script.js +++ b/toolkit/components/extensions/extension-process-script.js @@ -321,6 +321,8 @@ ExtensionManager = { 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); @@ -329,12 +331,10 @@ ExtensionManager = { } 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,