Bug 1317697: Lazily initialize Schemas.jsm. r?mixedpuppy
MozReview-Commit-ID: 83pKM6lLsra
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -1088,17 +1088,16 @@ defineLazyGetter(BrowserExtensionContent
return new CSSCache(Ci.nsIStyleSheetService.AUTHOR_SHEET);
});
ExtensionManager = {
// Map[extensionId, BrowserExtensionContent]
extensions: new Map(),
init() {
- Schemas.init();
ExtensionChild.initOnce();
Services.cpmm.addMessageListener("Extension:Startup", this);
Services.cpmm.addMessageListener("Extension:Shutdown", this);
Services.cpmm.addMessageListener("Extension:FlushJarCache", this);
if (Services.cpmm.initialProcessData && "Extension:Extensions" in Services.cpmm.initialProcessData) {
let extensions = Services.cpmm.initialProcessData["Extension:Extensions"];
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -2619,16 +2619,20 @@ this.Schemas = {
* Wrapper functions for the given context.
* @param {function} wrapperFuncs.hasPermission
* A function which, when given a string argument, returns true
* if the context has the given permission.
* @returns {boolean}
* True if the context has permission for the given namespace.
*/
checkPermissions(namespace, wrapperFuncs) {
+ if (!this.initialized) {
+ this.init();
+ }
+
let ns = this.getNamespace(namespace);
if (ns && ns.permissions) {
return ns.permissions.some(perm => wrapperFuncs.hasPermission(perm));
}
return true;
},
exportLazyGetter,
@@ -2637,30 +2641,38 @@ this.Schemas = {
* Inject registered extension APIs into `dest`.
*
* @param {object} dest The root namespace for the APIs.
* This object is usually exposed to extensions as "chrome" or "browser".
* @param {object} wrapperFuncs An implementation of the InjectionContext
* interface, which runs the actual functionality of the generated API.
*/
inject(dest, wrapperFuncs) {
+ if (!this.initialized) {
+ this.init();
+ }
+
let context = new InjectionContext(wrapperFuncs);
this.rootNamespace.injectInto(dest, context);
},
/**
* Normalize `obj` according to the loaded schema for `typeName`.
*
* @param {object} obj The object to normalize against the schema.
* @param {string} typeName The name in the format namespace.propertyname
* @param {object} context An implementation of Context. Any validation errors
* are reported to the given context.
* @returns {object} The normalized object.
*/
normalize(obj, typeName, context) {
+ if (!this.initialized) {
+ this.init();
+ }
+
let [namespaceName, prop] = typeName.split(".");
let ns = this.getNamespace(namespaceName);
let type = ns.get(prop);
return type.normalize(obj, new Context(context));
},
};