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

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

Issue 14494013: Allow API functions and events to have entries in _api_features.json (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix browser_tests, Stubs now inspects _api_features.json Created 7 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
Index: chrome/renderer/resources/extensions/binding.js
diff --git a/chrome/renderer/resources/extensions/binding.js b/chrome/renderer/resources/extensions/binding.js
index c7b299a825742573594eb137f2b6892c50a0f07f..14292e489ce582b602a75b9212148b30aedd80ae 100644
--- a/chrome/renderer/resources/extensions/binding.js
+++ b/chrome/renderer/resources/extensions/binding.js
@@ -202,6 +202,7 @@ Binding.prototype = {
// bindings that might be present.
generate: function() {
var schema = this.schema_;
+ var checkUnprivileged = schema['check_unprivileged'];
not at google - send to devlin 2013/05/03 04:58:14 to answer your question in IRC - yeah let's fix th
// TODO(kalman/cduvall): Make GetAvailability handle this, then delete the
// supporting code.
@@ -211,14 +212,6 @@ Binding.prototype = {
return undefined;
}
- var availability = GetAvailability(schema.namespace);
- if (!availability.is_available) {
- console.error('chrome.' + schema.namespace + ' is not available: ' +
- availability.message);
- return undefined;
- }
-
- // See comment on internalAPIs at the top.
var mod = {};
var namespaces = schema.namespace.split('.');
@@ -238,6 +231,7 @@ Binding.prototype = {
}, this);
}
+ // TODO(cduvall): Take out when all APIs have been converted to features.
// Returns whether access to the content of a schema should be denied,
// based on the presence of "unprivileged" and whether this is an
// extension process (versus e.g. a content script).
@@ -247,16 +241,6 @@ Binding.prototype = {
itemSchema.unprivileged;
};
- // Adds a getter that throws an access denied error to object |mod|
- // for property |name|.
- function addUnprivilegedAccessGetter(mod, name) {
- mod.__defineGetter__(name, function() {
- throw new Error(
- '"' + name + '" can only be used in extension processes. See ' +
- 'the content scripts documentation for more details.');
- });
- }
-
// Setup Functions.
if (schema.functions) {
forEach(schema.functions, function(i, functionDef) {
@@ -269,16 +253,17 @@ Binding.prototype = {
this.apiFunctions_.registerUnavailable(functionDef.name);
return;
}
- if (!isSchemaAccessAllowed(functionDef)) {
- this.apiFunctions_.registerUnavailable(functionDef.name);
- addUnprivilegedAccessGetter(mod, functionDef.name);
- return;
- }
var apiFunction = {};
apiFunction.definition = functionDef;
apiFunction.name = schema.namespace + '.' + functionDef.name;
+ if (!GetAvailability(apiFunction.name).is_available ||
+ (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) {
+ this.apiFunctions_.registerUnavailable(functionDef.name);
+ return;
+ }
+
// TODO(aa): It would be best to run this in a unit test, but in order
// to do that we would need to better factor this code so that it
// doesn't depend on so much v8::Extension machinery.
@@ -336,14 +321,14 @@ Binding.prototype = {
}
if (!isSchemaNodeSupported(eventDef, platform, manifestVersion))
return;
- if (!isSchemaAccessAllowed(eventDef)) {
- addUnprivilegedAccessGetter(mod, eventDef.name);
+
+ var eventName = schema.namespace + "." + eventDef.name;
+ if (!GetAvailability(eventName).is_available ||
+ (checkUnprivileged && !isSchemaAccessAllowed(eventDef))) {
return;
}
- var eventName = schema.namespace + "." + eventDef.name;
var options = eventDef.options || {};
-
if (eventDef.filters && eventDef.filters.length > 0)
options.supportsFilters = true;
@@ -370,8 +355,9 @@ Binding.prototype = {
return; // TODO(kalman): be strict like functions/events somehow.
if (!isSchemaNodeSupported(propertyDef, platform, manifestVersion))
return;
- if (!isSchemaAccessAllowed(propertyDef)) {
- addUnprivilegedAccessGetter(m, propertyName);
+ if (!GetAvailability(schema.namespace + "." +
+ propertyName).is_available ||
+ (checkUnprivileged && !isSchemaAccessAllowed(propertyDef))) {
return;
}
@@ -413,6 +399,14 @@ Binding.prototype = {
};
addProperties(mod, schema);
+
+ var availability = GetAvailability(schema.namespace);
+ if (!availability.is_available && Object.keys(mod).length == 0) {
+ console.error('chrome.' + schema.namespace + ' is not available: ' +
+ availability.message);
+ return;
+ }
+
this.runHooks_(mod);
return mod;
}

Powered by Google App Engine
This is Rietveld 408576698