Bug 1381687: Store and transfer schema JSON in structured clone blobs. r?aswan
MozReview-Commit-ID: FMSbSB1hC3F
--- 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;