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

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: 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..916001c4c0b5799ea57f09bed37af3622062b9a8 100644
--- a/chrome/renderer/resources/extensions/binding.js
+++ b/chrome/renderer/resources/extensions/binding.js
@@ -117,13 +117,19 @@ function isSchemaNodeSupported(schemaNode, platform, manifestVersion) {
isManifestVersionSupported(schemaNode, manifestVersion);
}
+function createCustomType(t) {
+ var customType = require(t['js_module'])[t['js_module']];
not at google - send to devlin 2013/03/21 00:01:13 * t -> type * save reference to t['js_module;] (al
cduvall 2013/03/21 00:59:51 Done.
+ customType.prototype = new CustomBindingsObject();
+ customType.prototype.setSchema(t);
+ return customType;
+}
+
var platform = getPlatform();
function Binding(schema) {
this.schema_ = schema;
this.apiFunctions_ = new APIFunctions();
this.customEvent_ = null;
- this.customTypes_ = {};
this.customHooks_ = [];
};
@@ -139,15 +145,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 +181,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.
@@ -217,10 +213,9 @@ Binding.prototype = {
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];
+ if (t.type == 'object' && 'js_module' in t) {
not at google - send to devlin 2013/03/21 00:01:13 i think this type == 'object' thing isn't necessar
cduvall 2013/03/21 00:59:51 Done, took it all out.
+ var parts = t.id.split('.');
+ mod[parts[parts.length - 1]] = createCustomType(t);
not at google - send to devlin 2013/03/21 00:01:13 looks like this splitting shenanigans also unneces
cduvall 2013/03/21 00:59:51 Done.
}
}, 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;
not at google - send to devlin 2013/03/21 00:01:13 not initializing things makes me slightly uncomfor
cduvall 2013/03/21 00:59:51 Done.
+ var type = utils.loadRefType(propertyDef['$ref'], schema);
+ if (type)
+ var constructor = createCustomType(type);
not at google - send to devlin 2013/03/21 00:01:13 var here doesn't make sense
cduvall 2013/03/21 00:59:51 Done.
if (!constructor)
throw new Error('No custom binding for ' + propertyDef['$ref']);
var args = value;

Powered by Google App Engine
This is Rietveld 408576698