Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1059)

Unified Diff: chrome/renderer/resources/extensions/json_schema.js

Issue 12647017: Lazily require types when validating Extensions API calls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/json_schema.js
diff --git a/chrome/renderer/resources/extensions/json_schema.js b/chrome/renderer/resources/extensions/json_schema.js
index 7770185283aa6bf0e6c0dd9cc28595467b959313..6640f483996103ea794a17d43865bb99344d85e4 100644
--- a/chrome/renderer/resources/extensions/json_schema.js
+++ b/chrome/renderer/resources/extensions/json_schema.js
@@ -40,7 +40,8 @@
// TODO(cduvall): Make this file not depend on chromeHidden.
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
-var loadRefDependency = require('utils').loadRefDependency;
+var loadTypeSchema = require('utils').loadTypeSchema;
+var CHECK = requireNative('logging').CHECK;
function isInstanceOfClass(instance, className) {
if (!instance)
@@ -176,13 +177,21 @@ chromeHidden.JSONSchemaValidator.prototype.getAllTypesForSchema =
schemaTypes = schemaTypes.concat(choiceTypes);
}
}
- if (schema['$ref']) {
- var refTypes = this.getAllTypesForSchema(this.types[schema['$ref']]);
- schemaTypes = schemaTypes.concat(refTypes);
+ var ref = schema['$ref'];
+ if (ref) {
+ var type = this.getOrAddType(ref);
+ CHECK(type, 'Could not find type ' + ref);
+ schemaTypes = schemaTypes.concat(this.getAllTypesForSchema(type));
}
return schemaTypes;
};
+chromeHidden.JSONSchemaValidator.prototype.getOrAddType = function(typeName) {
+ if (!this.types[typeName])
+ this.types[typeName] = loadTypeSchema(typeName);
+ return this.types[typeName];
+};
+
/**
* Returns true if |schema| would accept an argument of type |type|.
*/
@@ -243,12 +252,12 @@ chromeHidden.JSONSchemaValidator.prototype.validate =
// If the schema has a $ref property, the instance must validate against
// that schema too. It must be present in this.types to be referenced.
- if (schema["$ref"]) {
- loadRefDependency(schema["$ref"]);
- if (!this.types[schema["$ref"]])
- this.addError(path, "unknownSchemaReference", [ schema["$ref"] ]);
+ var ref = schema["$ref"];
+ if (ref) {
+ if (!this.getOrAddType(ref))
+ this.addError(path, "unknownSchemaReference", [ ref ]);
else
- this.validate(instance, this.types[schema["$ref"]], path)
+ this.validate(instance, this.getOrAddType(ref), path)
}
// If the schema has a choices property, the instance must validate against at

Powered by Google App Engine
This is Rietveld 408576698