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

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

Issue 12647017: Lazily require types when validating Extensions API calls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/binding.js
diff --git a/chrome/renderer/resources/extensions/binding.js b/chrome/renderer/resources/extensions/binding.js
index 59c9917984a99f13ae3339b5d1117cd551e62f11..7719757e1ae6d9212b524ac6dcfda6f58e7e946f 100644
--- a/chrome/renderer/resources/extensions/binding.js
+++ b/chrome/renderer/resources/extensions/binding.js
@@ -17,6 +17,7 @@ var schemaRegistry = requireNative('schema_registry');
var schemaUtils = require('schemaUtils');
var sendRequest = require('sendRequest').sendRequest;
var utils = require('utils');
+var CHECK = requireNative('logging').CHECK;
// Stores the name and definition of each API function, with methods to
// modify their behaviour (such as a custom way to handle requests to the
@@ -117,13 +118,21 @@ function isSchemaNodeSupported(schemaNode, platform, manifestVersion) {
isManifestVersionSupported(schemaNode, manifestVersion);
}
+function createCustomType(type) {
+ var jsModule = type.js_module;
+ CHECK(jsModule, 'Custom type has no "js_module" property.');
not at google - send to devlin 2013/03/21 01:36:55 'custom type ' + type.id + ' must have a...'
cduvall 2013/03/21 17:16:07 Done.
+ var customType = require(jsModule)[jsModule];
not at google - send to devlin 2013/03/21 01:36:55 i don't really know how paranoid we should be here
cduvall 2013/03/21 17:16:07 Done.
+ customType.prototype = new CustomBindingsObject();
+ customType.prototype.setSchema(type);
+ return customType;
+}
+
var platform = getPlatform();
function Binding(schema) {
this.schema_ = schema;
this.apiFunctions_ = new APIFunctions();
this.customEvent_ = null;
- this.customTypes_ = {};
this.customHooks_ = [];
};
@@ -139,15 +148,6 @@ Binding.prototype = {
// order to do the schema generation (registerCustomEvent and
// registerCustomType), and those which can only run after the bindings have
// been generated (registerCustomHook).
- //
-
- // Registers a custom type referenced via "$ref" fields in the API schema
- // JSON.
- registerCustomType: function(typeName, customTypeFactory) {
- var customType = customTypeFactory();
- customType.prototype = new CustomBindingsObject();
- this.customTypes_[typeName] = customType;
- },
// Registers a custom event type for the API identified by |namespace|.
// |event| is the event's constructor.
@@ -184,7 +184,6 @@ Binding.prototype = {
// bindings that might be present.
generate: function() {
var schema = this.schema_;
- var customTypes = this.customTypes_;
// TODO(kalman/cduvall): Make GetAvailability handle this, then delete the
// supporting code.
@@ -210,18 +209,14 @@ Binding.prototype = {
mod = mod[name];
}
- // Add types to global schemaValidator
+ // Add types to global schemaValidator, the ones for the types we depend on
+ // will be added as needed.
if (schema.types) {
forEach(schema.types, function(i, t) {
if (!isSchemaNodeSupported(t, platform, manifestVersion))
return;
schemaUtils.schemaValidator.addTypes(t);
- if (t.type == 'object' && this.customTypes_[t.id]) {
- var parts = t.id.split(".");
- this.customTypes_[t.id].prototype.setSchema(t);
- mod[parts[parts.length - 1]] = this.customTypes_[t.id];
- }
}, this);
}
@@ -371,14 +366,10 @@ Binding.prototype = {
} else if (type === 'boolean') {
value = value === 'true';
} else if (propertyDef['$ref']) {
- if (propertyDef['$ref'] in customTypes) {
- var constructor = customTypes[propertyDef['$ref']];
- } else {
- var refParts = propertyDef['$ref'].split('.');
- // This should never try to load a $ref in the current namespace.
- var constructor = utils.loadRefDependency(
- propertyDef['$ref'])[refParts[refParts.length - 1]];
- }
+ var constructor = null;
+ var type = utils.loadTypeSchema(propertyDef['$ref'], schema);
+ if (type)
+ constructor = createCustomType(type);
not at google - send to devlin 2013/03/21 01:36:55 looks like it's actually impossible for createCust
cduvall 2013/03/21 17:16:07 Done.
if (!constructor)
throw new Error('No custom binding for ' + propertyDef['$ref']);
var args = value;

Powered by Google App Engine
This is Rietveld 408576698