Bug 1246787 - [webext] Add schema storage.json (r=kmag)
authorBill McCloskey <billm@mozilla.com>
Thu, 26 Nov 2015 10:21:15 -0800
changeset 284030 2b79c6ed27fa1df72d9c9009d1471b1173c821b4
parent 284029 ec234b78ab0a2ea6b6f681405efc925ff0f30efd
child 284031 b2b9363f3edccd028f45e0db2860b2cc07cad913
push id29995
push usercbook@mozilla.com
push dateFri, 12 Feb 2016 14:16:12 +0000
treeherdermozilla-central@218d16a9ddcc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1246787
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1246787 - [webext] Add schema storage.json (r=kmag)
testing/specialpowers/content/SpecialPowersObserverAPI.js
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/Schemas.jsm
toolkit/components/extensions/ext-storage.js
toolkit/components/extensions/schemas/jar.mn
toolkit/components/extensions/schemas/storage.json
toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
--- a/testing/specialpowers/content/SpecialPowersObserverAPI.js
+++ b/testing/specialpowers/content/SpecialPowersObserverAPI.js
@@ -565,16 +565,17 @@ SpecialPowersObserverAPI.prototype = {
         }).then(() => {
           if (extensionData.errors.length) {
             return Promise.reject("Extension contains packaging errors");
           }
           return extension.startup();
         }).then(() => {
           this._sendReply(aMessage, "SPExtensionMessage", {id, type: "extensionStarted", args: []});
         }).catch(e => {
+          dump(`Extension startup failed: ${e}\n${e.stack}`);
           this._sendReply(aMessage, "SPExtensionMessage", {id, type: "extensionFailed", args: []});
         });
         return undefined;
       }
 
       case "SPExtensionMessage": {
         let id = aMessage.data.id;
         let extension = this._extensions.get(id);
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -77,16 +77,17 @@ const BASE_SCHEMA = "chrome://extensions
 
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/cookies.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/downloads.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/extension.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/extension_types.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/i18n.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/idle.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/runtime.json");
+ExtensionManagement.registerSchema("chrome://extensions/content/schemas/storage.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/test.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/web_navigation.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/web_request.json");
 
 Cu.import("resource://gre/modules/ExtensionUtils.jsm");
 var {
   BaseContext,
   LocaleData,
@@ -378,64 +379,71 @@ GlobalManager = {
       // does not.
       let injectObject = (name, defaultCallback) => {
         let browserObj = Cu.createObjectIn(contentWindow, {defineAs: name});
 
         let api = Management.generateAPIs(extension, context, Management.apis);
         injectAPI(api, browserObj);
 
         let schemaApi = Management.generateAPIs(extension, context, Management.schemaApis);
+        function findPath(path) {
+          let obj = schemaApi;
+          for (let elt of path) {
+            obj = obj[elt];
+          }
+          return obj;
+        };
         let schemaWrapper = {
           get cloneScope() {
             return context.cloneScope;
           },
 
-          callFunction(ns, name, args) {
-            return schemaApi[ns][name](...args);
+          callFunction(path, name, args) {
+            return findPath(path)[name](...args);
           },
 
-          callAsyncFunction(ns, name, args, callback) {
+          callAsyncFunction(path, name, args, callback) {
             // We pass an empty stub function as a default callback for
             // the `chrome` API, so promise objects are not returned,
             // and lastError values are reported immediately.
             if (callback === null) {
               callback = defaultCallback;
             }
 
             let promise;
             try {
-              promise = schemaApi[ns][name](...args);
+              promise = findPath(path)[name](...args);
             } catch (e) {
               if (e instanceof context.cloneScope.Error) {
                 promise = Promise.reject(e);
               } else {
                 Cu.reportError(e);
                 promise = Promise.reject({ message: "An unexpected error occurred" });
               }
             }
 
             return context.wrapPromise(promise || Promise.resolve(), callback);
           },
 
-          getProperty(ns, name) {
-            return schemaApi[ns][name];
+          getProperty(path, name) {
+            return findPath(path)[name];
           },
 
-          setProperty(ns, name, value) {
-            schemaApi[ns][name] = value;
+          setProperty(path, name, value) {
+            findPath(path)[name] = value;
           },
 
-          addListener(ns, name, listener, args) {
-            return schemaApi[ns][name].addListener.call(null, listener, ...args);
+          addListener(path, name, listener, args) {
+            return findPath(path)[name].addListener.call(null, listener, ...args);
           },
-          removeListener(ns, name, listener) {
-            return schemaApi[ns][name].removeListener.call(null, listener);
+          removeListener(path, name, listener) {
+            return findPath(path)[name].removeListener.call(null, listener);
           },
-          hasListener(ns, name, listener) {
-            return schemaApi[ns][name].hasListener.call(null, listener);
+          hasListener(path, name, listener) {
+            return findPath(path)[name].hasListener.call(null, listener);
           },
         };
         Schemas.inject(browserObj, schemaWrapper);
       };
 
       injectObject("browser", null);
       injectObject("chrome", () => {});
     };
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -300,17 +300,17 @@ class Entry {
     }
   }
 
   // Injects JS values for the entry into the extension API
   // namespace. The default implementation is to do
   // nothing. |context| is used to call the actual implementation
   // of a given function or event. It's an object with properties
   // callFunction, addListener, removeListener, and hasListener.
-  inject(name, dest, context) {
+  inject(path, name, dest, context) {
   }
 }
 
 // Corresponds either to a type declared in the "types" section of the
 // schema or else to any type object used throughout the schema.
 class Type extends Entry {
   // Takes a value, checks that it has the correct type, and returns a
   // "normalized" version of the value. The normalized version will
@@ -463,17 +463,17 @@ class StringType extends Type {
 
     return r;
   }
 
   checkBaseType(baseType) {
     return baseType == "string";
   }
 
-  inject(name, dest, context) {
+  inject(path, name, dest, context) {
     if (this.enumeration) {
       let obj = Cu.createObjectIn(dest, {defineAs: name});
       for (let e of this.enumeration) {
         let key = e.toUpperCase();
         obj[key] = e;
       }
     }
   }
@@ -618,16 +618,25 @@ class ObjectType extends Type {
     } else if (remainingProps.size) {
       return context.error(`Unexpected properties: ${[...remainingProps]}`);
     }
 
     return {value: result};
   }
 }
 
+// This type is just a placeholder to be referred to by
+// SubModuleProperty. No value is ever expected to have this type.
+class SubModuleType extends Type {
+  constructor(functions) {
+    super();
+    this.functions = functions;
+  }
+};
+
 class NumberType extends Type {
   normalize(value, context) {
     let r = this.normalizeBase("number", value, context);
     if (r.error) {
       return r;
     }
 
     if (isNaN(value) || !Number.isFinite(value)) {
@@ -744,17 +753,17 @@ class FunctionType extends Type {
 // particular value. Essentially this is a constant.
 class ValueProperty extends Entry {
   constructor(schema, name, value) {
     super(schema);
     this.name = name;
     this.value = value;
   }
 
-  inject(name, dest, context) {
+  inject(path, name, dest, context) {
     dest[name] = this.value;
   }
 }
 
 // Represents a "property" defined in a schema namespace that is not a
 // constant.
 class TypeProperty extends Entry {
   constructor(schema, namespaceName, name, type, writable) {
@@ -764,24 +773,24 @@ class TypeProperty extends Entry {
     this.type = type;
     this.writable = writable;
   }
 
   throwError(context, msg) {
     throw context.makeError(`${msg} for ${this.namespaceName}.${this.name}.`);
   }
 
-  inject(name, dest, context) {
+  inject(path, name, dest, context) {
     if (this.unsupported) {
       return;
     }
 
     let getStub = () => {
       this.checkDeprecated(context);
-      return context.getProperty(this.namespaceName, name);
+      return context.getProperty(path, name);
     };
 
     let desc = {
       configurable: false,
       enumerable: true,
 
       get: Cu.exportFunction(getStub, dest),
     };
@@ -798,30 +807,67 @@ class TypeProperty extends Entry {
 
       desc.set = Cu.exportFunction(setStub, dest);
     }
 
     Object.defineProperty(dest, name, desc);
   }
 }
 
+class SubModuleProperty extends Entry {
+  // A SubModuleProperty represents a tree of objects and properties
+  // to expose to an extension. Currently we support only a limited
+  // form of sub-module properties, where "$ref" points to a
+  // SubModuleType containing a list of functions and "properties" is
+  // a list of additional simple properties.
+  //
+  // name: Name of the property stuff is being added to.
+  // namespaceName: Namespace in which the property lives.
+  // reference: Name of the type defining the functions to add to the property.
+  // properties: Additional properties to add to the module (unsupported).
+  constructor(name, namespaceName, reference, properties) {
+    super();
+    this.name = name;
+    this.namespaceName = namespaceName;
+    this.reference = reference;
+    this.properties = properties;
+  }
+
+  inject(path, name, dest, wrapperFuncs) {
+    let obj = Cu.createObjectIn(dest, {defineAs: name});
+
+    let ns = Schemas.namespaces.get(this.namespaceName);
+    let type = ns.get(this.reference);
+    if (!type || !(type instanceof SubModuleType)) {
+      throw new Error(`Internal error: ${this.namespaceName}.${this.reference} is not a sub-module`);
+    }
+
+    let functions = type.functions;
+    for (let fun of functions) {
+      fun.inject(path.concat(name), fun.name, obj, wrapperFuncs);
+    }
+
+    // TODO: Inject this.properties.
+  }
+};
+
 // This class is a base class for FunctionEntrys and Events. It takes
 // care of validating parameter lists (i.e., handling of optional
 // parameters and parameter type checking).
 class CallEntry extends Entry {
-  constructor(schema, namespaceName, name, parameters, allowAmbiguousOptionalArguments) {
+  constructor(schema, path, name, parameters, allowAmbiguousOptionalArguments) {
     super(schema);
-    this.namespaceName = namespaceName;
+    this.path = path;
     this.name = name;
     this.parameters = parameters;
     this.allowAmbiguousOptionalArguments = allowAmbiguousOptionalArguments;
   }
 
   throwError(context, msg) {
-    throw context.makeError(`${msg} for ${this.namespaceName}.${this.name}.`);
+    throw context.makeError(`${msg} for ${this.path.join('.')}.${this.name}.`);
   }
 
   checkParameters(args, context) {
     let fixedArgs = [];
 
     // First we create a new array, fixedArgs, that is the same as
     // |args| but with null values in place of omitted optional
     // parameters.
@@ -886,83 +932,83 @@ class CallEntry extends Entry {
     });
 
     return fixedArgs;
   }
 }
 
 // Represents a "function" defined in a schema namespace.
 class FunctionEntry extends CallEntry {
-  constructor(schema, namespaceName, name, type, unsupported, allowAmbiguousOptionalArguments, returns) {
-    super(schema, namespaceName, name, type.parameters, allowAmbiguousOptionalArguments);
+  constructor(schema, path, name, type, unsupported, allowAmbiguousOptionalArguments, returns) {
+    super(schema, path, name, type.parameters, allowAmbiguousOptionalArguments);
     this.unsupported = unsupported;
     this.returns = returns;
 
     this.isAsync = type.isAsync;
   }
 
-  inject(name, dest, context) {
+  inject(path, name, dest, context) {
     if (this.unsupported) {
       return;
     }
 
     let stub;
     if (this.isAsync) {
       stub = (...args) => {
         this.checkDeprecated(context);
         let actuals = this.checkParameters(args, context);
         let callback = actuals.pop();
-        return context.callAsyncFunction(this.namespaceName, name, actuals, callback);
+        return context.callAsyncFunction(path, name, actuals, callback);
       };
     } else {
       stub = (...args) => {
         this.checkDeprecated(context);
         let actuals = this.checkParameters(args, context);
-        return context.callFunction(this.namespaceName, name, actuals);
+        return context.callFunction(path, name, actuals);
       };
     }
     Cu.exportFunction(stub, dest, {defineAs: name});
   }
 }
 
 // Represents an "event" defined in a schema namespace.
 class Event extends CallEntry {
-  constructor(schema, namespaceName, name, type, extraParameters, unsupported) {
-    super(schema, namespaceName, name, extraParameters);
+  constructor(schema, path, name, type, extraParameters, unsupported) {
+    super(schema, path, name, extraParameters);
     this.type = type;
     this.unsupported = unsupported;
   }
 
   checkListener(listener, context) {
     let r = this.type.normalize(listener, context);
     if (r.error) {
       this.throwError(context, "Invalid listener");
     }
     return r.value;
   }
 
-  inject(name, dest, context) {
+  inject(path, name, dest, context) {
     if (this.unsupported) {
       return;
     }
 
     let addStub = (listener, ...args) => {
       listener = this.checkListener(listener, context);
       let actuals = this.checkParameters(args, context);
-      return context.addListener(this.namespaceName, name, listener, actuals);
+      return context.addListener(this.path, name, listener, actuals);
     };
 
     let removeStub = (listener) => {
       listener = this.checkListener(listener, context);
-      return context.removeListener(this.namespaceName, name, listener);
+      return context.removeListener(this.path, name, listener);
     };
 
     let hasStub = (listener) => {
       listener = this.checkListener(listener, context);
-      return context.hasListener(this.namespaceName, name, listener);
+      return context.hasListener(this.path, name, listener);
     };
 
     let obj = Cu.createObjectIn(dest, {defineAs: name});
     Cu.exportFunction(addStub, obj, {defineAs: "addListener"});
     Cu.exportFunction(removeStub, obj, {defineAs: "removeListener"});
     Cu.exportFunction(hasStub, obj, {defineAs: "hasListener"});
   }
 }
@@ -976,38 +1022,38 @@ this.Schemas = {
     let ns = this.namespaces.get(namespaceName);
     if (!ns) {
       ns = new Map();
       this.namespaces.set(namespaceName, ns);
     }
     ns.set(symbol, value);
   },
 
-  parseType(namespaceName, type, extraProperties = []) {
+  parseType(path, type, extraProperties = []) {
     let allowedProperties = new Set(extraProperties);
 
     // Do some simple validation of our own schemas.
     function checkTypeProperties(...extra) {
       let allowedSet = new Set([...allowedProperties, ...extra, "description", "deprecated"]);
       for (let prop of Object.keys(type)) {
         if (!allowedSet.has(prop)) {
-          throw new Error(`Internal error: Namespace ${namespaceName} has invalid type property "${prop}" in type "${type.id || JSON.stringify(type)}"`);
+          throw new Error(`Internal error: Namespace ${path.join('.')} has invalid type property "${prop}" in type "${type.id || JSON.stringify(type)}"`);
         }
       }
     }
 
     if ("choices" in type) {
       checkTypeProperties("choices");
 
-      let choices = type.choices.map(t => this.parseType(namespaceName, t));
+      let choices = type.choices.map(t => this.parseType(path, t));
       return new ChoiceType(type, choices);
     } else if ("$ref" in type) {
       checkTypeProperties("$ref");
       let ref = type.$ref;
-      let ns = namespaceName;
+      let ns = path[0];
       if (ref.includes(".")) {
         [ns, ref] = ref.split(".");
       }
       return new RefType(type, ns, ref);
     }
 
     if (!("type" in type)) {
       throw new Error(`Unexpected value for type: ${JSON.stringify(type)}`);
@@ -1049,20 +1095,27 @@ this.Schemas = {
         }
         format = FORMATS[type.format];
       }
       return new StringType(type, enumeration,
                             type.minLength || 0,
                             type.maxLength || Infinity,
                             pattern,
                             format);
+    } else if (type.type == "object" && "functions" in type) {
+      checkTypeProperties("functions");
+
+      // The path we pass in here is only used for error messages.
+      let functions = type.functions.map(fun => this.parseFunction(path.concat(type.id), fun));
+
+      return new SubModuleType(functions);
     } else if (type.type == "object") {
       let parseProperty = (type, extraProps = []) => {
         return {
-          type: this.parseType(namespaceName, type,
+          type: this.parseType(path, type,
                                ["unsupported", ...extraProps]),
           optional: type.optional || false,
           unsupported: type.unsupported || false,
         };
       };
 
       let properties = Object.create(null);
       for (let propName of Object.keys(type.properties || {})) {
@@ -1081,29 +1134,29 @@ this.Schemas = {
         patternProperties.push({
           pattern,
           type: parseProperty(type.patternProperties[propName]),
         });
       }
 
       let additionalProperties = null;
       if (type.additionalProperties) {
-        additionalProperties = this.parseType(namespaceName, type.additionalProperties);
+        additionalProperties = this.parseType(path, type.additionalProperties);
       }
 
       if ("$extend" in type) {
         // Only allow extending "properties" and "patternProperties".
         checkTypeProperties("properties", "patternProperties");
       } else {
         checkTypeProperties("properties", "additionalProperties", "patternProperties", "isInstanceOf");
       }
       return new ObjectType(type, properties, additionalProperties, patternProperties, type.isInstanceOf || null);
     } else if (type.type == "array") {
       checkTypeProperties("items", "minItems", "maxItems");
-      return new ArrayType(type, this.parseType(namespaceName, type.items),
+      return new ArrayType(type, this.parseType(path, type.items),
                            type.minItems || 0, type.maxItems || Infinity);
     } else if (type.type == "number") {
       checkTypeProperties();
       return new NumberType(type);
     } else if (type.type == "integer") {
       checkTypeProperties("minimum", "maximum");
       return new IntegerType(type, type.minimum || 0, type.maximum || Infinity);
     } else if (type.type == "boolean") {
@@ -1116,17 +1169,17 @@ this.Schemas = {
       if ("parameters" in type) {
         parameters = [];
         for (let param of type.parameters) {
           // Callbacks default to optional for now, because of promise
           // handling.
           let isCallback = isAsync && param.name == type.async;
 
           parameters.push({
-            type: this.parseType(namespaceName, param, ["name", "optional"]),
+            type: this.parseType(path, param, ["name", "optional"]),
             name: param.name,
             optional: param.optional == null ? isCallback : param.optional,
           });
         }
       }
 
       if (isAsync) {
         if (!parameters || !parameters.length || parameters[parameters.length - 1].name != type.async) {
@@ -1143,88 +1196,98 @@ this.Schemas = {
       // Need to see what minimum and maximum are supposed to do here.
       checkTypeProperties("minimum", "maximum");
       return new AnyType(type);
     } else {
       throw new Error(`Unexpected type ${type.type}`);
     }
   },
 
+  parseFunction(path, fun) {
+    let f = new FunctionEntry(fun, path, fun.name,
+                              this.parseType(path, fun,
+                                             ["name", "unsupported", "returns",
+                                              "allowAmbiguousOptionalArguments"]),
+                              fun.unsupported || false,
+                              fun.allowAmbiguousOptionalArguments || false,
+                              fun.returns || null);
+    return f;
+  },
+
   loadType(namespaceName, type) {
     if ("$extend" in type) {
       this.extendType(namespaceName, type);
     } else {
-      this.register(namespaceName, type.id, this.parseType(namespaceName, type, ["id"]));
+      this.register(namespaceName, type.id, this.parseType([namespaceName], type, ["id"]));
     }
   },
 
   extendType(namespaceName, type) {
     let ns = Schemas.namespaces.get(namespaceName);
     let targetType = ns && ns.get(type.$extend);
 
     // Only allow extending object and choices types for now.
     if (targetType instanceof ObjectType) {
       type.type = "object";
     } else if (!targetType) {
       throw new Error(`Internal error: Attempt to extend a nonexistant type ${type.$extend}`);
     } else if (!(targetType instanceof ChoiceType)) {
       throw new Error(`Internal error: Attempt to extend a non-extensible type ${type.$extend}`);
     }
 
-    let parsed = this.parseType(namespaceName, type, ["$extend"]);
+    let parsed = this.parseType([namespaceName], type, ["$extend"]);
     if (parsed.constructor !== targetType.constructor) {
       throw new Error(`Internal error: Bad attempt to extend ${type.$extend}`);
     }
 
     targetType.extend(parsed);
   },
 
   loadProperty(namespaceName, name, prop) {
-    if ("value" in prop) {
+    if ("$ref" in prop) {
+      if (!prop.unsupported) {
+        this.register(namespaceName, name, new SubModuleProperty(name, namespaceName, prop["$ref"],
+                                                                 prop.properties || {}));
+      }
+    } else if ("value" in prop) {
       this.register(namespaceName, name, new ValueProperty(prop, name, prop.value));
     } else {
       // We ignore the "optional" attribute on properties since we
       // don't inject anything here anyway.
-      let type = this.parseType(namespaceName, prop, ["optional", "writable"]);
+      let type = this.parseType([namespaceName], prop, ["optional", "writable"]);
       this.register(namespaceName, name, new TypeProperty(prop, namespaceName, name, type, prop.writable || false));
     }
   },
 
   loadFunction(namespaceName, fun) {
-    let f = new FunctionEntry(fun, namespaceName, fun.name,
-                              this.parseType(namespaceName, fun,
-                                             ["name", "unsupported", "returns",
-                                              "allowAmbiguousOptionalArguments"]),
-                              fun.unsupported || false,
-                              fun.allowAmbiguousOptionalArguments || false,
-                              fun.returns || null);
+    let f = this.parseFunction([namespaceName], fun);
     this.register(namespaceName, fun.name, f);
   },
 
   loadEvent(namespaceName, event) {
     let extras = event.extraParameters || [];
     extras = extras.map(param => {
       return {
-        type: this.parseType(namespaceName, param, ["name", "optional"]),
+        type: this.parseType([namespaceName], param, ["name", "optional"]),
         name: param.name,
         optional: param.optional || false,
       };
     });
 
     // We ignore these properties for now.
     /* eslint-disable no-unused-vars */
     let returns = event.returns;
     let filters = event.filters;
     /* eslint-enable no-unused-vars */
 
-    let type = this.parseType(namespaceName, event,
+    let type = this.parseType([namespaceName], event,
                               ["name", "unsupported",
                                "extraParameters", "returns", "filters"]);
 
-    let e = new Event(event, namespaceName, event.name, type, extras,
+    let e = new Event(event, [namespaceName], event.name, type, extras,
                       event.unsupported || false);
     this.register(namespaceName, event.name, e);
   },
 
   load(uri) {
     return readJSON(uri).then(json => {
       for (let namespace of json) {
         let name = namespace.namespace;
@@ -1251,17 +1314,17 @@ this.Schemas = {
       }
     });
   },
 
   inject(dest, wrapperFuncs) {
     for (let [namespace, ns] of this.namespaces) {
       let obj = Cu.createObjectIn(dest, {defineAs: namespace});
       for (let [name, entry] of ns) {
-        entry.inject(name, obj, new Context(wrapperFuncs));
+        entry.inject([namespace], name, obj, new Context(wrapperFuncs));
       }
 
       if (!Object.keys(obj).length) {
         delete dest[namespace];
       }
     }
   },
 
--- a/toolkit/components/extensions/ext-storage.js
+++ b/toolkit/components/extensions/ext-storage.js
@@ -5,17 +5,17 @@ var { classes: Cc, interfaces: Ci, utils
 XPCOMUtils.defineLazyModuleGetter(this, "ExtensionStorage",
                                   "resource://gre/modules/ExtensionStorage.jsm");
 
 Cu.import("resource://gre/modules/ExtensionUtils.jsm");
 var {
   EventManager,
 } = ExtensionUtils;
 
-extensions.registerPrivilegedAPI("storage", (extension, context) => {
+extensions.registerSchemaAPI("storage", "storage", (extension, context) => {
   return {
     storage: {
       local: {
         get: function(keys, callback) {
           return context.wrapPromise(
             ExtensionStorage.get(extension.id, keys), callback);
         },
         set: function(items, callback) {
--- a/toolkit/components/extensions/schemas/jar.mn
+++ b/toolkit/components/extensions/schemas/jar.mn
@@ -7,11 +7,12 @@ toolkit.jar:
     content/extensions/schemas/cookies.json
     content/extensions/schemas/downloads.json
     content/extensions/schemas/extension.json
     content/extensions/schemas/extension_types.json
     content/extensions/schemas/i18n.json
     content/extensions/schemas/idle.json
     content/extensions/schemas/manifest.json
     content/extensions/schemas/runtime.json
+    content/extensions/schemas/storage.json
     content/extensions/schemas/test.json
     content/extensions/schemas/web_navigation.json
     content/extensions/schemas/web_request.json
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/schemas/storage.json
@@ -0,0 +1,222 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+[
+  {
+    "namespace": "storage",
+    "description": "Use the <code>browser.storage</code> API to store, retrieve, and track changes to user data.",
+    "types": [
+      {
+        "id": "StorageChange",
+        "type": "object",
+        "properties": {
+          "oldValue": {
+            "type": "any",
+            "description": "The old value of the item, if there was an old value.",
+            "optional": true
+          },
+          "newValue": {
+            "type": "any",
+            "description": "The new value of the item, if there is a new value.",
+            "optional": true
+          }
+        }
+      },
+      {
+        "id": "StorageArea",
+        "type": "object",
+        "functions": [
+          {
+            "name": "get",
+            "type": "function",
+            "description": "Gets one or more items from storage.",
+            "parameters": [
+              {
+                "name": "keys",
+                "choices": [
+                  { "type": "string" },
+                  { "type": "array", "items": { "type": "string" } },
+                  {
+                    "type": "object",
+                    "description": "Storage items to return in the callback, where the values are replaced with those from storage if they exist.",
+                    "additionalProperties": { "type": "any" }
+                  }
+                ],
+                "description": "A single key to get, list of keys to get, or a dictionary specifying default values (see description of the object).  An empty list or object will return an empty result object.  Pass in <code>null</code> to get the entire contents of storage.",
+                "optional": true
+              },
+              {
+                "name": "callback",
+                "type": "function",
+                "description": "Callback with storage items, or on failure (in which case $(ref:runtime.lastError) will be set).",
+                "parameters": [
+                  {
+                    "name": "items",
+                    "type": "object",
+                    "additionalProperties": { "type": "any" },
+                    "description": "Object with items in their key-value mappings."
+                  }
+                ]
+              }
+            ]
+          },
+          {
+            "name": "getBytesInUse",
+            "unsupported": true,
+            "type": "function",
+            "description": "Gets the amount of space (in bytes) being used by one or more items.",
+            "parameters": [
+              {
+                "name": "keys",
+                "choices": [
+                  { "type": "string" },
+                  { "type": "array", "items": { "type": "string" } }
+                ],
+                "description": "A single key or list of keys to get the total usage for. An empty list will return 0. Pass in <code>null</code> to get the total usage of all of storage.",
+                "optional": true
+              },
+              {
+                "name": "callback",
+                "type": "function",
+                "description": "Callback with the amount of space being used by storage, or on failure (in which case $(ref:runtime.lastError) will be set).",
+                "parameters": [
+                  {
+                    "name": "bytesInUse",
+                    "type": "integer",
+                    "description": "Amount of space being used in storage, in bytes."
+                  }
+                ]
+              }
+            ]
+          },
+          {
+            "name": "set",
+            "type": "function",
+            "description": "Sets multiple items.",
+            "parameters": [
+              {
+                "name": "items",
+                "type": "object",
+                "additionalProperties": { "type": "any" },
+                "description": "<p>An object which gives each key/value pair to update storage with. Any other key/value pairs in storage will not be affected.</p><p>Primitive values such as numbers will serialize as expected. Values with a <code>typeof</code> <code>\"object\"</code> and <code>\"function\"</code> will typically serialize to <code>{}</code>, with the exception of <code>Array</code> (serializes as expected), <code>Date</code>, and <code>Regex</code> (serialize using their <code>String</code> representation).</p>"
+              },
+              {
+                "name": "callback",
+                "type": "function",
+                "description": "Callback on success, or on failure (in which case $(ref:runtime.lastError) will be set).",
+                "parameters": [],
+                "optional": true
+              }
+            ]
+          },
+          {
+            "name": "remove",
+            "type": "function",
+            "description": "Removes one or more items from storage.",
+            "parameters": [
+              {
+                "name": "keys",
+                "choices": [
+                  {"type": "string"},
+                  {"type": "array", "items": {"type": "string"}}
+                ],
+                "description": "A single key or a list of keys for items to remove."
+              },
+              {
+                "name": "callback",
+                "type": "function",
+                "description": "Callback on success, or on failure (in which case $(ref:runtime.lastError) will be set).",
+                "parameters": [],
+                "optional": true
+              }
+            ]
+          },
+          {
+            "name": "clear",
+            "type": "function",
+            "description": "Removes all items from storage.",
+            "parameters": [
+              {
+                "name": "callback",
+                "type": "function",
+                "description": "Callback on success, or on failure (in which case $(ref:runtime.lastError) will be set).",
+                "parameters": [],
+                "optional": true
+              }
+            ]
+          }
+        ]
+      }
+    ],
+    "events": [
+      {
+        "name": "onChanged",
+        "type": "function",
+        "description": "Fired when one or more items change.",
+        "parameters": [
+          {
+            "name": "changes",
+            "type": "object",
+            "additionalProperties": { "$ref": "StorageChange" },
+            "description": "Object mapping each key that changed to its corresponding $(ref:storage.StorageChange) for that item."
+          },
+          {
+            "name": "areaName",
+            "type": "string",
+            "description": "The name of the storage area (<code>\"sync\"</code>, <code>\"local\"</code> or <code>\"managed\"</code>) the changes are for."
+          }
+        ]
+      }
+    ],
+    "properties": {
+      "sync": {
+        "unsupported": true,
+        "$ref": "StorageArea",
+        "description": "Items in the <code>sync</code> storage area are synced by the browser.",
+        "properties": {
+          "QUOTA_BYTES": {
+            "value": 102400,
+            "description": "The maximum total amount (in bytes) of data that can be stored in sync storage, as measured by the JSON stringification of every value plus every key's length. Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError)."
+          },
+          "QUOTA_BYTES_PER_ITEM": {
+            "value": 8192,
+            "description": "The maximum size (in bytes) of each individual item in sync storage, as measured by the JSON stringification of its value plus its key length. Updates containing items larger than this limit will fail immediately and set $(ref:runtime.lastError)."
+          },
+          "MAX_ITEMS": {
+            "value": 512,
+            "description": "The maximum number of items that can be stored in sync storage. Updates that would cause this limit to be exceeded will fail immediately and set $(ref:runtime.lastError)."
+          },
+          "MAX_WRITE_OPERATIONS_PER_HOUR": {
+            "value": 1800,
+            "description": "<p>The maximum number of <code>set</code>, <code>remove</code>, or <code>clear</code> operations that can be performed each hour. This is 1 every 2 seconds, a lower ceiling than the short term higher writes-per-minute limit.</p><p>Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError).</p>"
+          },
+          "MAX_WRITE_OPERATIONS_PER_MINUTE": {
+            "value": 120,
+            "description": "<p>The maximum number of <code>set</code>, <code>remove</code>, or <code>clear</code> operations that can be performed each minute. This is 2 per second, providing higher throughput than writes-per-hour over a shorter period of time.</p><p>Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError).</p>"
+          },
+          "MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE": {
+            "value": 1000000,
+            "deprecated": "The storage.sync API no longer has a sustained write operation quota.",
+            "description": ""
+          }
+        }
+      },
+      "local": {
+        "$ref": "StorageArea",
+        "description": "Items in the <code>local</code> storage area are local to each machine.",
+        "properties": {
+          "QUOTA_BYTES": {
+            "value": 5242880,
+            "description": "The maximum amount (in bytes) of data that can be stored in local storage, as measured by the JSON stringification of every value plus every key's length. This value will be ignored if the extension has the <code>unlimitedStorage</code> permission. Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError)."
+          }
+        }
+      },
+      "managed": {
+        "unsupported": true,
+        "$ref": "StorageArea",
+        "description": "Items in the <code>managed</code> storage area are set by the domain administrator, and are read-only for the extension; trying to modify this namespace results in an error."
+      }
+    }
+  }
+]
--- a/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_schemas.js
@@ -4,16 +4,23 @@ Components.utils.import("resource://gre/
 Components.utils.import("resource://gre/modules/BrowserUtils.jsm");
 
 let json = [
   {namespace: "testing",
 
    properties: {
      PROP1: {value: 20},
      prop2: {type: "string"},
+     prop3: {
+       $ref: "submodule",
+     },
+     prop4: {
+       $ref: "submodule",
+       unsupported: true,
+     },
    },
 
    types: [
      {
        id: "type1",
        type: "string",
        "enum": ["value1", "value2", "value3"],
      },
@@ -50,16 +57,28 @@ let json = [
      },
 
      {
        $extend: "basetype2",
        choices: [
          {type: "string"},
        ],
      },
+
+     {
+       id: "submodule",
+       type: "object",
+       functions: [
+         {
+           name: "sub_foo",
+           type: "function",
+           parameters: []
+         },
+       ],
+     },
    ],
 
    functions: [
      {
        name: "foo",
        type: "function",
        parameters: [
          {name: "arg1", type: "integer", optional: true},
@@ -293,35 +312,41 @@ let wrapper = {
   checkLoadURL(url) {
     return !url.startsWith("chrome:");
   },
 
   logError(message) {
     talliedErrors.push(message);
   },
 
-  callFunction(ns, name, args) {
+  callFunction(path, name, args) {
+    let ns = path.join(".");
     tally("call", ns, name, args);
   },
 
-  getProperty(ns, name) {
+  getProperty(path, name) {
+    let ns = path.join(".");
     tally("get", ns, name);
   },
 
-  setProperty(ns, name, value) {
+  setProperty(path, name, value) {
+    let ns = path.join(".");
     tally("set", ns, name, value);
   },
 
-  addListener(ns, name, listener, args) {
+  addListener(path, name, listener, args) {
+    let ns = path.join(".");
     tally("addListener", ns, name, [listener, args]);
   },
-  removeListener(ns, name, listener) {
+  removeListener(path, name, listener) {
+    let ns = path.join(".");
     tally("removeListener", ns, name, [listener]);
   },
-  hasListener(ns, name, listener) {
+  hasListener(path, name, listener) {
+    let ns = path.join(".");
     tally("hasListener", ns, name, [listener]);
   },
 };
 
 add_task(function* () {
   let url = "data:," + JSON.stringify(json);
   let uri = BrowserUtils.makeURI(url);
   yield Schemas.load(uri);
@@ -583,16 +608,24 @@ add_task(function* () {
 
   root.testing.extended2(12);
   verify("call", "testing", "extended2", [12]);
   tallied = null;
 
   Assert.throws(() => root.testing.extended2(true),
                 /Incorrect argument types/,
                 "should throw for wrong argument type");
+
+  root.testing.prop3.sub_foo();
+  verify("call", "testing.prop3", "sub_foo", []);
+  tallied = null;
+
+  Assert.throws(() => root.testing.prop4.sub_foo(),
+                /root.testing.prop4 is undefined/,
+                "should throw for unsupported submodule");
 });
 
 let deprecatedJson = [
   {namespace: "deprecated",
 
    properties: {
      accessor: {
        type: "string",