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

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

Issue 1930033003: [Extensions] Make Binding.generate() load the schema directly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/resources/binding.js
diff --git a/extensions/renderer/resources/binding.js b/extensions/renderer/resources/binding.js
index 16f09d26b79f3d6f8b5d5d7dcc6725f7c70c4663..9c9aad92d1203a2f681dd4647df3771d9941eda1 100644
--- a/extensions/renderer/resources/binding.js
+++ b/extensions/renderer/resources/binding.js
@@ -189,15 +189,15 @@ function createCustomType(type) {
var platform = getPlatform();
-function Binding(schema) {
- this.schema_ = schema;
- this.apiFunctions_ = new APIFunctions(schema.namespace);
+function Binding(apiName) {
+ this.apiName_ = apiName;
+ this.apiFunctions_ = new APIFunctions(apiName);
this.customEvent_ = null;
this.customHooks_ = [];
};
Binding.create = function(apiName) {
- return new Binding(schemaRegistry.GetSchema(apiName));
+ return new Binding(apiName);
};
Binding.prototype = {
@@ -224,9 +224,9 @@ Binding.prototype = {
},
// TODO(kalman/cduvall): Refactor this so |runHooks_| is not needed.
- runHooks_: function(api) {
+ runHooks_: function(api, schema) {
$Array.forEach(this.customHooks_, function(hook) {
- if (!isSchemaNodeSupported(this.schema_, platform, manifestVersion))
+ if (!isSchemaNodeSupported(schema, platform, manifestVersion))
return;
if (!hook)
@@ -234,16 +234,23 @@ Binding.prototype = {
hook({
apiFunctions: this.apiFunctions_,
- schema: this.schema_,
+ schema: schema,
compiledApi: api
}, extensionId, contextType);
}, this);
},
- // Generates the bindings from |this.schema_| and integrates any custom
- // bindings that might be present.
+ // Generates the bindings from the schema for |this.apiName_| and integrates
+ // any custom bindings that might be present.
generate: function() {
- var schema = this.schema_;
+ // NB: It's important to load the schema during generation rather than
+ // setting it beforehand so that we're more confident the schema we're
+ // loading is real, and not one that was injected by a page intercepting
+ // Binding.generate.
+ // Additionally, since the schema is an object returned from a native
+ // handler, its properties don't have the custom getters/setters that a page
+ // may have put on Object.prototype.
+ var schema = schemaRegistry.GetSchema(this.apiName_);
function shouldCheckUnprivileged() {
var shouldCheck = 'unprivileged' in schema;
@@ -546,7 +553,7 @@ Binding.prototype = {
return;
}
- this.runHooks_(mod);
+ this.runHooks_(mod, schema);
return mod;
}
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698