Bug 1402066: Fix ordering of base schema data in extension child processes. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 22 Sep 2017 15:49:44 -0700
changeset 669351 5613613bfb211ce814d76b0c730f6c33600ae619
parent 669204 5d42f8d147c677923fb04ed83a7e41e9a27d4c91
child 669352 f9ab74ad8833f5287df8873637be8eb9539e67da
push id81306
push usermaglione.k@gmail.com
push dateFri, 22 Sep 2017 22:51:05 +0000
reviewersaswan
bugs1402066
milestone58.0a1
Bug 1402066: Fix ordering of base schema data in extension child processes. r?aswan MozReview-Commit-ID: FtLHJq5H5oD
toolkit/components/extensions/Schemas.jsm
toolkit/components/extensions/extension-process-script.js
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -2713,26 +2713,34 @@ this.Schemas = {
 
       Services.cpmm.addMessageListener("Schema:Add", this);
     }
 
     this.flushSchemas();
   },
 
   receiveMessage(msg) {
+    let {data} = msg;
     switch (msg.name) {
       case "Schema:Add":
-        for (let [url, schema] of msg.data) {
+        // If we're given a Map, the ordering of the initial items
+        // matters, so swap with our current data to make sure its
+        // entries appear first.
+        if (typeof data.get === "function") {
+          [this.schemaJSON, data] = [new Map(data), this.schemaJSON];
+        }
+
+        for (let [url, schema] of data) {
           this.schemaJSON.set(url, schema);
         }
         this.flushSchemas();
         break;
 
       case "Schema:Delete":
-        this.schemaJSON.delete(msg.data.url);
+        this.schemaJSON.delete(data.url);
         this.flushSchemas();
         break;
     }
   },
 
   _needFlush: true,
   flushSchemas() {
     if (this._needFlush) {
--- a/toolkit/components/extensions/extension-process-script.js
+++ b/toolkit/components/extensions/extension-process-script.js
@@ -375,16 +375,26 @@ ExtensionManager = {
 
       case "Extension:FlushJarCache": {
         ExtensionUtils.flushJarCache(data.path);
         Services.cpmm.sendAsyncMessage("Extension:FlushJarCacheComplete");
         break;
       }
 
       case "Schema:Add": {
+        // If we're given a Map, the ordering of the initial items
+        // matters, so swap with our current data to make sure its
+        // entries appear first.
+        if (typeof data.get === "function") {
+          [this.schemaJSON, data] = [data, this.schemaJSON];
+
+          Services.cpmm.initialProcessData["Extension:Schemas"] =
+            this.schemaJSON;
+        }
+
         for (let [url, schema] of data) {
           this.schemaJSON.set(url, schema);
         }
         break;
       }
     }
   },
 };