Bug 1381687: Store and transfer schema JSON in structured clone blobs. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Mon, 17 Jul 2017 15:33:54 -0700
changeset 610191 8b6d04278377e24e188b787a3dacb9a63d8964ae
parent 610190 2cdc242fae8beaae3a7499b8e6c0ffd4125e7356
child 637776 01c878541912828c920da37b8a09faf85b3628c5
push id68798
push usermaglione.k@gmail.com
push dateMon, 17 Jul 2017 23:45:15 +0000
reviewersaswan
bugs1381687
milestone56.0a1
Bug 1381687: Store and transfer schema JSON in structured clone blobs. r?aswan MozReview-Commit-ID: FMSbSB1hC3F
toolkit/components/extensions/Schemas.jsm
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -62,16 +62,22 @@ function readJSON(url) {
         resolve(JSON.parse(text));
       } catch (e) {
         reject(e);
       }
     });
   });
 }
 
+async function readJSONAndBlobbify(url) {
+  let json = await readJSON(url);
+
+  return new StructuredCloneHolder(json);
+}
+
 /**
  * Defines a lazy getter for the given property on the given object. Any
  * security wrappers are waived on the object before the property is
  * defined, and the getter and setter methods are wrapped for the target
  * scope.
  *
  * The given getter function is guaranteed to be called only once, even
  * if the target scope retrieves the wrapped getter from the property
@@ -2625,19 +2631,19 @@ this.Schemas = {
     this._needFlush = true;
 
     Object.defineProperty(this, "rootNamespace", {
       enumerable: true,
       configurable: true,
       value: new Namespace("", []),
     });
 
-    for (let json of this.schemaJSON.values()) {
+    for (let blob of this.schemaJSON.values()) {
       try {
-        this.loadSchema(json);
+        this.loadSchema(blob.deserialize(global));
       } catch (e) {
         Cu.reportError(e);
       }
     }
 
     return this.rootNamespace;
   },
 
@@ -2654,39 +2660,39 @@ this.Schemas = {
       this._loadCachedSchemasPromise = StartupCache.schemas.getAll().then(results => {
         return results;
       });
     }
 
     return this._loadCachedSchemasPromise;
   },
 
-  addSchema(url, json) {
-    this.schemaJSON.set(url, json);
+  addSchema(url, schema) {
+    this.schemaJSON.set(url, schema);
 
     let data = Services.ppmm.initialProcessData;
     data["Extension:Schemas"] = this.schemaJSON;
 
-    Services.ppmm.broadcastAsyncMessage("Schema:Add", {url, schema: json});
+    Services.ppmm.broadcastAsyncMessage("Schema:Add", {url, schema});
 
     this.flushSchemas();
   },
 
   async load(url) {
     if (!isParentProcess) {
       return;
     }
 
     let schemaCache = await this.loadCachedSchemas();
 
-    let json = (schemaCache.get(url) ||
-                await StartupCache.schemas.get(url, readJSON));
+    let blob = (schemaCache.get(url) ||
+                await StartupCache.schemas.get(url, readJSONAndBlobbify));
 
     if (!this.schemaJSON.has(url)) {
-      this.addSchema(url, json);
+      this.addSchema(url, blob);
     }
   },
 
   unload(url) {
     this.schemaJSON.delete(url);
 
     let data = Services.ppmm.initialProcessData;
     data["Extension:Schemas"] = this.schemaJSON;