Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 require('json_schema'); | 5 require('json_schema'); |
| 6 require('event_bindings'); | 6 require('event_bindings'); |
| 7 var chrome = requireNative('chrome').GetChrome(); | 7 var chrome = requireNative('chrome').GetChrome(); |
| 8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 9 var forEach = require('utils').forEach; | 9 var forEach = require('utils').forEach; |
| 10 var GetAvailability = requireNative('v8_context').GetAvailability; | 10 var GetAvailability = requireNative('v8_context').GetAvailability; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 var schema = this.schema_; | 204 var schema = this.schema_; |
| 205 | 205 |
| 206 // TODO(kalman/cduvall): Make GetAvailability handle this, then delete the | 206 // TODO(kalman/cduvall): Make GetAvailability handle this, then delete the |
| 207 // supporting code. | 207 // supporting code. |
| 208 if (!isSchemaNodeSupported(schema, platform, manifestVersion)) { | 208 if (!isSchemaNodeSupported(schema, platform, manifestVersion)) { |
| 209 console.error('chrome.' + schema.namespace + ' is not supported on ' + | 209 console.error('chrome.' + schema.namespace + ' is not supported on ' + |
| 210 'this platform or manifest version'); | 210 'this platform or manifest version'); |
| 211 return undefined; | 211 return undefined; |
| 212 } | 212 } |
| 213 | 213 |
| 214 var availability = GetAvailability(schema.namespace); | |
| 215 if (!availability.is_available) { | |
| 216 console.error('chrome.' + schema.namespace + ' is not available: ' + | |
| 217 availability.message); | |
| 218 return undefined; | |
| 219 } | |
| 220 | |
| 221 // See comment on internalAPIs at the top. | |
| 222 var mod = {}; | 214 var mod = {}; |
| 215 var hasEventOrFunction = false; | |
| 223 | 216 |
| 224 var namespaces = schema.namespace.split('.'); | 217 var namespaces = schema.namespace.split('.'); |
| 225 for (var index = 0, name; name = namespaces[index]; index++) { | 218 for (var index = 0, name; name = namespaces[index]; index++) { |
| 226 mod[name] = mod[name] || {}; | 219 mod[name] = mod[name] || {}; |
| 227 mod = mod[name]; | 220 mod = mod[name]; |
| 228 } | 221 } |
| 229 | 222 |
| 230 // Add types to global schemaValidator, the types we depend on from other | 223 // Add types to global schemaValidator, the types we depend on from other |
| 231 // namespaces will be added as needed. | 224 // namespaces will be added as needed. |
| 232 if (schema.types) { | 225 if (schema.types) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 if (!isSchemaAccessAllowed(functionDef)) { | 265 if (!isSchemaAccessAllowed(functionDef)) { |
| 273 this.apiFunctions_.registerUnavailable(functionDef.name); | 266 this.apiFunctions_.registerUnavailable(functionDef.name); |
| 274 addUnprivilegedAccessGetter(mod, functionDef.name); | 267 addUnprivilegedAccessGetter(mod, functionDef.name); |
| 275 return; | 268 return; |
| 276 } | 269 } |
| 277 | 270 |
| 278 var apiFunction = {}; | 271 var apiFunction = {}; |
| 279 apiFunction.definition = functionDef; | 272 apiFunction.definition = functionDef; |
| 280 apiFunction.name = schema.namespace + '.' + functionDef.name; | 273 apiFunction.name = schema.namespace + '.' + functionDef.name; |
| 281 | 274 |
| 275 if (!GetAvailability(apiFunction.name).is_available) { | |
| 276 this.apiFunctions_.registerUnavailable(functionDef.name); | |
| 277 addUnprivilegedAccessGetter(mod, functionDef.name); | |
| 278 return; | |
| 279 } | |
| 280 | |
| 281 hasEventOrFunction = true; | |
|
not at google - send to devlin
2013/04/27 01:02:43
we may actually want to implement most of this in
cduvall
2013/05/01 02:51:47
All the C++ is just to make sure that the bindings
not at google - send to devlin
2013/05/01 20:47:04
yep - sorry I was misreading this a bit. cool.
| |
| 282 | |
| 282 // TODO(aa): It would be best to run this in a unit test, but in order | 283 // TODO(aa): It would be best to run this in a unit test, but in order |
| 283 // to do that we would need to better factor this code so that it | 284 // to do that we would need to better factor this code so that it |
| 284 // doesn't depend on so much v8::Extension machinery. | 285 // doesn't depend on so much v8::Extension machinery. |
| 285 if (chromeHidden.validateAPI && | 286 if (chromeHidden.validateAPI && |
| 286 schemaUtils.isFunctionSignatureAmbiguous( | 287 schemaUtils.isFunctionSignatureAmbiguous( |
| 287 apiFunction.definition)) { | 288 apiFunction.definition)) { |
| 288 throw new Error( | 289 throw new Error( |
| 289 apiFunction.name + ' has ambiguous optional arguments. ' + | 290 apiFunction.name + ' has ambiguous optional arguments. ' + |
| 290 'To implement custom disambiguation logic, add ' + | 291 'To implement custom disambiguation logic, add ' + |
| 291 '"allowAmbiguousOptionalArguments" to the function\'s schema.'); | 292 '"allowAmbiguousOptionalArguments" to the function\'s schema.'); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 } | 337 } |
| 337 if (!isSchemaNodeSupported(eventDef, platform, manifestVersion)) | 338 if (!isSchemaNodeSupported(eventDef, platform, manifestVersion)) |
| 338 return; | 339 return; |
| 339 if (!isSchemaAccessAllowed(eventDef)) { | 340 if (!isSchemaAccessAllowed(eventDef)) { |
| 340 addUnprivilegedAccessGetter(mod, eventDef.name); | 341 addUnprivilegedAccessGetter(mod, eventDef.name); |
| 341 return; | 342 return; |
| 342 } | 343 } |
| 343 | 344 |
| 344 var eventName = schema.namespace + "." + eventDef.name; | 345 var eventName = schema.namespace + "." + eventDef.name; |
| 345 var options = eventDef.options || {}; | 346 var options = eventDef.options || {}; |
| 347 if (!GetAvailability(eventName).is_available) { | |
| 348 addUnprivilegedAccessGetter(mod, eventDef.name); | |
| 349 return; | |
| 350 } | |
| 351 | |
| 352 hasEventOrFunction = true; | |
| 346 | 353 |
| 347 if (eventDef.filters && eventDef.filters.length > 0) | 354 if (eventDef.filters && eventDef.filters.length > 0) |
| 348 options.supportsFilters = true; | 355 options.supportsFilters = true; |
| 349 | 356 |
| 350 if (this.customEvent_) { | 357 if (this.customEvent_) { |
| 351 mod[eventDef.name] = new this.customEvent_( | 358 mod[eventDef.name] = new this.customEvent_( |
| 352 eventName, eventDef.parameters, eventDef.extraParameters, | 359 eventName, eventDef.parameters, eventDef.extraParameters, |
| 353 options); | 360 options); |
| 354 } else if (eventDef.anonymous) { | 361 } else if (eventDef.anonymous) { |
| 355 mod[eventDef.name] = new chrome.Event(); | 362 mod[eventDef.name] = new chrome.Event(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 throw new Error('NOT IMPLEMENTED (extension_api.json error): ' + | 414 throw new Error('NOT IMPLEMENTED (extension_api.json error): ' + |
| 408 'Cannot parse values for type "' + type + '"'); | 415 'Cannot parse values for type "' + type + '"'); |
| 409 } | 416 } |
| 410 m[propertyName] = value; | 417 m[propertyName] = value; |
| 411 } | 418 } |
| 412 }); | 419 }); |
| 413 }; | 420 }; |
| 414 | 421 |
| 415 addProperties(mod, schema); | 422 addProperties(mod, schema); |
| 416 this.runHooks_(mod); | 423 this.runHooks_(mod); |
| 424 | |
| 425 var availability = GetAvailability(schema.namespace); | |
| 426 if (!availability.is_available && !hasEventOrFunction) { | |
|
not at google - send to devlin
2013/04/27 01:02:43
You should be able to calculate hasEventOrFunction
cduvall
2013/05/01 02:51:47
Done.
| |
| 427 console.error('chrome.' + schema.namespace + ' is not available: ' + | |
| 428 availability.message); | |
| 429 return; | |
| 430 } | |
| 431 | |
| 417 return mod; | 432 return mod; |
| 418 } | 433 } |
| 419 }; | 434 }; |
| 420 | 435 |
| 421 exports.Binding = Binding; | 436 exports.Binding = Binding; |
| OLD | NEW |