Chromium Code Reviews| 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..f3e0df98b9d6f47054933ef7e0fcb2e175c95a45 100644 |
| --- a/chrome/renderer/resources/extensions/binding.js |
| +++ b/chrome/renderer/resources/extensions/binding.js |
| @@ -211,14 +211,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,15 +230,6 @@ Binding.prototype = { |
| }, this); |
| } |
| - // 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). |
| - function isSchemaAccessAllowed(itemSchema) { |
| - return (contextType == 'BLESSED_EXTENSION') || |
| - schema.unprivileged || |
| - itemSchema.unprivileged; |
| - }; |
| - |
| // Adds a getter that throws an access denied error to object |mod| |
| // for property |name|. |
| function addUnprivilegedAccessGetter(mod, name) { |
| @@ -269,16 +252,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) { |
| + this.apiFunctions_.registerUnavailable(functionDef.name); |
| + addUnprivilegedAccessGetter(mod, functionDef.name); |
|
not at google - send to devlin
2013/05/01 20:47:04
Just leave it blank. No need for the unprivileged
cduvall
2013/05/01 23:47:10
Done.
|
| + 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,13 +320,13 @@ Binding.prototype = { |
| } |
| if (!isSchemaNodeSupported(eventDef, platform, manifestVersion)) |
| return; |
| - if (!isSchemaAccessAllowed(eventDef)) { |
| - addUnprivilegedAccessGetter(mod, eventDef.name); |
| - return; |
| - } |
| var eventName = schema.namespace + "." + eventDef.name; |
| var options = eventDef.options || {}; |
|
not at google - send to devlin
2013/05/01 20:47:04
might as well define options after this block.
cduvall
2013/05/01 23:47:10
Done.
|
| + if (!GetAvailability(eventName).is_available) { |
| + addUnprivilegedAccessGetter(mod, eventDef.name); |
|
not at google - send to devlin
2013/05/01 20:47:04
ditto - no unprivileged access getter, just leave
cduvall
2013/05/01 23:47:10
Done.
|
| + return; |
| + } |
| if (eventDef.filters && eventDef.filters.length > 0) |
| options.supportsFilters = true; |
| @@ -370,8 +354,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) { |
| + addUnprivilegedAccessGetter(mod, propertyName); |
|
not at google - send to devlin
2013/05/01 20:47:04
ditto
cduvall
2013/05/01 23:47:10
Done.
|
| return; |
| } |
| @@ -414,6 +399,22 @@ Binding.prototype = { |
| addProperties(mod, schema); |
| this.runHooks_(mod); |
| + |
| + var availability = GetAvailability(schema.namespace); |
| + |
| + function hasItemOfType(typeArray) { |
| + return typeArray.length && !typeArray.filter(function (def) { |
| + return mod.hasOwnProperty(def.name); |
| + }).length; |
| + } |
| + |
| + if (!availability.is_available && |
| + (hasItemOfType(schema.events) || hasItemOfType(schema.functions))) { |
|
not at google - send to devlin
2013/05/01 20:47:04
a simpler test may be to just check whether the mo
cduvall
2013/05/01 23:47:10
Done.
|
| + console.error('chrome.' + schema.namespace + ' is not available: ' + |
| + availability.message); |
| + return; |
| + } |
| + |
| return mod; |
| } |
| }; |