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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // ----------------------------------------------------------------------------- 5 // -----------------------------------------------------------------------------
6 // NOTE: If you change this file you need to touch renderer_resources.grd to 6 // NOTE: If you change this file you need to touch renderer_resources.grd to
7 // have your change take effect. 7 // have your change take effect.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 9
10 //============================================================================== 10 //==============================================================================
(...skipping 22 matching lines...) Expand all
33 // - null counts as 'unspecified' for optional values 33 // - null counts as 'unspecified' for optional values
34 // - added the 'choices' property, to allow specifying a list of possible types 34 // - added the 'choices' property, to allow specifying a list of possible types
35 // for a value 35 // for a value
36 // - by default an "object" typed schema does not allow additional properties. 36 // - by default an "object" typed schema does not allow additional properties.
37 // if present, "additionalProperties" is to be a schema against which all 37 // if present, "additionalProperties" is to be a schema against which all
38 // additional properties will be validated. 38 // additional properties will be validated.
39 //============================================================================== 39 //==============================================================================
40 40
41 // TODO(cduvall): Make this file not depend on chromeHidden. 41 // TODO(cduvall): Make this file not depend on chromeHidden.
42 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 42 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
43 var loadRefDependency = require('utils').loadRefDependency; 43 var loadRefType = require('utils').loadRefType;
44 44
45 function isInstanceOfClass(instance, className) { 45 function isInstanceOfClass(instance, className) {
46 if (!instance) 46 if (!instance)
47 return false; 47 return false;
48 48
49 if (Object.prototype.toString.call(instance) == "[object " + className + "]") 49 if (Object.prototype.toString.call(instance) == "[object " + className + "]")
50 return true; 50 return true;
51 51
52 return isInstanceOfClass(Object.getPrototypeOf(instance), className); 52 return isInstanceOfClass(Object.getPrototypeOf(instance), className);
53 } 53 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 function(schema) { 169 function(schema) {
170 var schemaTypes = []; 170 var schemaTypes = [];
171 if (schema.type) 171 if (schema.type)
172 schemaTypes.push(schema.type); 172 schemaTypes.push(schema.type);
173 if (schema.choices) { 173 if (schema.choices) {
174 for (var i = 0; i < schema.choices.length; i++) { 174 for (var i = 0; i < schema.choices.length; i++) {
175 var choiceTypes = this.getAllTypesForSchema(schema.choices[i]); 175 var choiceTypes = this.getAllTypesForSchema(schema.choices[i]);
176 schemaTypes = schemaTypes.concat(choiceTypes); 176 schemaTypes = schemaTypes.concat(choiceTypes);
177 } 177 }
178 } 178 }
179 if (schema['$ref']) { 179 if (schema['$ref']) {
not at google - send to devlin 2013/03/21 00:01:13 save a reference to schema['$ref'], it'd make this
cduvall 2013/03/21 00:59:51 Done.
180 var refTypes = this.getAllTypesForSchema(this.types[schema['$ref']]); 180 if (!this.types[schema['$ref']])
181 schemaTypes = schemaTypes.concat(refTypes); 181 this.types[schema['$ref']] = loadRefType(schema['$ref']);
not at google - send to devlin 2013/03/21 00:01:13 CHECK that it found it.
cduvall 2013/03/21 00:59:51 Done.
182 schemaTypes = schemaTypes.concat(
183 this.getAllTypesForSchema(this.types[schema['$ref']]));
182 } 184 }
183 return schemaTypes; 185 return schemaTypes;
184 }; 186 };
185 187
186 /** 188 /**
187 * Returns true if |schema| would accept an argument of type |type|. 189 * Returns true if |schema| would accept an argument of type |type|.
188 */ 190 */
189 chromeHidden.JSONSchemaValidator.prototype.isValidSchemaType = 191 chromeHidden.JSONSchemaValidator.prototype.isValidSchemaType =
190 function(type, schema) { 192 function(type, schema) {
191 if (type == 'any') 193 if (type == 'any')
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 this.types[schema.id] = schema; 239 this.types[schema.id] = schema;
238 240
239 // If the schema has an extends property, the instance must validate against 241 // If the schema has an extends property, the instance must validate against
240 // that schema too. 242 // that schema too.
241 if (schema.extends) 243 if (schema.extends)
242 this.validate(instance, schema.extends, path); 244 this.validate(instance, schema.extends, path);
243 245
244 // If the schema has a $ref property, the instance must validate against 246 // If the schema has a $ref property, the instance must validate against
245 // that schema too. It must be present in this.types to be referenced. 247 // that schema too. It must be present in this.types to be referenced.
246 if (schema["$ref"]) { 248 if (schema["$ref"]) {
247 loadRefDependency(schema["$ref"]); 249 if (!this.types[schema["$ref"]])
250 this.types[schema["$ref"]] = loadRefType(schema["$ref"]);
not at google - send to devlin 2013/03/21 00:01:13 save schema[$ref], CHECK actually this logic is r
cduvall 2013/03/21 00:59:51 I don't think this should CHECK, because it throws
not at google - send to devlin 2013/03/21 01:36:55 ah ok.
248 if (!this.types[schema["$ref"]]) 251 if (!this.types[schema["$ref"]])
249 this.addError(path, "unknownSchemaReference", [ schema["$ref"] ]); 252 this.addError(path, "unknownSchemaReference", [ schema["$ref"] ]);
250 else 253 else
251 this.validate(instance, this.types[schema["$ref"]], path) 254 this.validate(instance, this.types[schema["$ref"]], path)
252 } 255 }
253 256
254 // If the schema has a choices property, the instance must validate against at 257 // If the schema has a choices property, the instance must validate against at
255 // least one of the items in that array. 258 // least one of the items in that array.
256 if (schema.choices) { 259 if (schema.choices) {
257 this.validateChoices(instance, schema, path); 260 this.validateChoices(instance, schema, path);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) 512 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements)
510 }); 513 });
511 }; 514 };
512 515
513 /** 516 /**
514 * Resets errors to an empty list so you can call 'validate' again. 517 * Resets errors to an empty list so you can call 'validate' again.
515 */ 518 */
516 chromeHidden.JSONSchemaValidator.prototype.resetErrors = function() { 519 chromeHidden.JSONSchemaValidator.prototype.resetErrors = function() {
517 this.errors = []; 520 this.errors = [];
518 }; 521 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698