Bug 1374457 - Key cached manifest and locale data by add-on version. r=rhelmer, a=jcristau
authorKris Maglione <maglione.k@gmail.com>
Mon, 19 Jun 2017 15:14:08 -0700
changeset 414051 bd2df31d88f07e468c460beee82397ba0d0256cb
parent 414050 eddd208645656c9846c503d4ce2417ae45a1073f
child 414052 b54b431ba47cea6c7cdde680b410fbe3e2215983
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhelmer, jcristau
bugs1374457
milestone55.0
Bug 1374457 - Key cached manifest and locale data by add-on version. r=rhelmer, a=jcristau MozReview-Commit-ID: 7NdS0Etmhot
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/LegacyExtensionsUtils.jsm
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -743,16 +743,17 @@ this.Extension = class extends Extension
       Cu.reportError(new Error("Remote extensions should not be enabled without also setting " +
                                "the layers.popups.compositing.enabled preference to true"));
     }
 
     // This is filled in the first time an extension child is created.
     this.parentMessageManager = null;
 
     this.id = addonData.id;
+    this.version = addonData.version;
     this.baseURI = NetUtil.newURI(this.getURL("")).QueryInterface(Ci.nsIURL);
     this.principal = this.createPrincipal();
 
     this.onStartup = null;
 
     this.hasShutdown = false;
     this.onShutdown = new Set();
 
@@ -850,25 +851,25 @@ this.Extension = class extends Extension
   isExtensionURL(url) {
     let uri = Services.io.newURI(url);
 
     let common = this.baseURI.getCommonBaseSpec(uri);
     return common == this.baseURI.spec;
   }
 
   readLocaleFile(locale) {
-    return StartupCache.locales.get([this.id, locale],
+    return StartupCache.locales.get([this.id, this.version, locale],
                                     () => super.readLocaleFile(locale))
       .then(result => {
         this.localeData.messages.set(locale, result);
       });
   }
 
   parseManifest() {
-    return StartupCache.manifests.get([this.id, Locale.getLocale()],
+    return StartupCache.manifests.get([this.id, this.version, Locale.getLocale()],
                                       () => super.parseManifest());
   }
 
   loadManifest() {
     return super.loadManifest().then(manifest => {
       if (this.errors.length) {
         return Promise.reject({errors: this.errors});
       }
--- a/toolkit/components/extensions/LegacyExtensionsUtils.jsm
+++ b/toolkit/components/extensions/LegacyExtensionsUtils.jsm
@@ -104,22 +104,25 @@ class EmbeddedExtension {
    * Create a new EmbeddedExtension given the add-on id and the base resource URI of the
    * container add-on (the webextension resources will be loaded from the "webextension/"
    * subdir of the base resource URI for the legacy extension add-on).
    *
    * @param {Object} containerAddonParams
    *   An object with the following properties:
    * @param {string} containerAddonParams.id
    *   The Add-on id of the Legacy Extension which will contain the embedded webextension.
+   * @param {string} containerAddonParams.version
+   *   The add-on version.
    * @param {nsIURI} containerAddonParams.resourceURI
    *   The nsIURI of the Legacy Extension container add-on.
    */
-  constructor({id, resourceURI}) {
+  constructor({id, resourceURI, version}) {
     this.addonId = id;
     this.resourceURI = resourceURI;
+    this.version = version;
 
     // Setup status flag.
     this.started = false;
   }
 
   /**
    * Start the embedded webextension.
    *
@@ -134,16 +137,17 @@ class EmbeddedExtension {
     // Setup the startup promise.
     this.startupPromise = new Promise((resolve, reject) => {
       let embeddedExtensionURI = Services.io.newURI("webextension/", null, this.resourceURI);
 
       // This is the instance of the WebExtension embedded in the hybrid add-on.
       this.extension = new Extension({
         id: this.addonId,
         resourceURI: embeddedExtensionURI,
+        version: this.version,
       });
 
       // This callback is register to the "startup" event, emitted by the Extension instance
       // after the extension manifest.json has been loaded without any errors, but before
       // starting any of the defined contexts (which give the legacy part a chance to subscribe
       // runtime.onMessage/onConnect listener before the background page has been loaded).
       const onBeforeStarted = () => {
         this.extension.off("startup", onBeforeStarted);
@@ -222,21 +226,21 @@ EmbeddedExtensionManager = {
   untrackEmbeddedExtension(embeddedExtensionInstance) {
     // Remove this instance from the tracked embedded extensions
     let id = embeddedExtensionInstance.addonId;
     if (this.embeddedExtensionsByAddonId.get(id) == embeddedExtensionInstance) {
       this.embeddedExtensionsByAddonId.delete(id);
     }
   },
 
-  getEmbeddedExtensionFor({id, resourceURI}) {
+  getEmbeddedExtensionFor({id, resourceURI, version}) {
     let embeddedExtension = this.embeddedExtensionsByAddonId.get(id);
 
     if (!embeddedExtension) {
-      embeddedExtension = new EmbeddedExtension({id, resourceURI});
+      embeddedExtension = new EmbeddedExtension({id, resourceURI, version});
       // Keep track of the embedded extension instance.
       this.embeddedExtensionsByAddonId.set(id, embeddedExtension);
     }
 
     return embeddedExtension;
   },
 };