| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 var Event = require('event_bindings').Event; | 5 var Event = require('event_bindings').Event; |
| 6 var forEach = require('utils').forEach; | 6 var forEach = require('utils').forEach; |
| 7 // Note: Beware sneaky getters/setters when using GetAvailbility(). Use safe/raw | |
| 8 // variables as arguments. | |
| 9 var GetAvailability = requireNative('v8_context').GetAvailability; | 7 var GetAvailability = requireNative('v8_context').GetAvailability; |
| 10 var exceptionHandler = require('uncaught_exception_handler'); | 8 var exceptionHandler = require('uncaught_exception_handler'); |
| 11 var lastError = require('lastError'); | 9 var lastError = require('lastError'); |
| 12 var logActivity = requireNative('activityLogger'); | 10 var logActivity = requireNative('activityLogger'); |
| 13 var logging = requireNative('logging'); | 11 var logging = requireNative('logging'); |
| 14 var process = requireNative('process'); | 12 var process = requireNative('process'); |
| 15 var schemaRegistry = requireNative('schema_registry'); | 13 var schemaRegistry = requireNative('schema_registry'); |
| 16 var schemaUtils = require('schemaUtils'); | 14 var schemaUtils = require('schemaUtils'); |
| 17 var utils = require('utils'); | 15 var utils = require('utils'); |
| 18 var sendRequestHandler = require('sendRequest'); | 16 var sendRequestHandler = require('sendRequest'); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 242 |
| 245 // Generates the bindings from the schema for |this.apiName_| and integrates | 243 // Generates the bindings from the schema for |this.apiName_| and integrates |
| 246 // any custom bindings that might be present. | 244 // any custom bindings that might be present. |
| 247 generate: function() { | 245 generate: function() { |
| 248 // NB: It's important to load the schema during generation rather than | 246 // NB: It's important to load the schema during generation rather than |
| 249 // setting it beforehand so that we're more confident the schema we're | 247 // setting it beforehand so that we're more confident the schema we're |
| 250 // loading is real, and not one that was injected by a page intercepting | 248 // loading is real, and not one that was injected by a page intercepting |
| 251 // Binding.generate. | 249 // Binding.generate. |
| 252 // Additionally, since the schema is an object returned from a native | 250 // Additionally, since the schema is an object returned from a native |
| 253 // handler, its properties don't have the custom getters/setters that a page | 251 // handler, its properties don't have the custom getters/setters that a page |
| 254 // may have put on Object.prototype, and the object is frozen by v8. | 252 // may have put on Object.prototype. |
| 255 var schema = schemaRegistry.GetSchema(this.apiName_); | 253 var schema = schemaRegistry.GetSchema(this.apiName_); |
| 256 | 254 |
| 257 function shouldCheckUnprivileged() { | 255 function shouldCheckUnprivileged() { |
| 258 var shouldCheck = 'unprivileged' in schema; | 256 var shouldCheck = 'unprivileged' in schema; |
| 259 if (shouldCheck) | 257 if (shouldCheck) |
| 260 return shouldCheck; | 258 return shouldCheck; |
| 261 | 259 |
| 262 $Array.forEach(['functions', 'events'], function(type) { | 260 $Array.forEach(['functions', 'events'], function(type) { |
| 263 if ($Object.hasOwnProperty(schema, type)) { | 261 if ($Object.hasOwnProperty(schema, type)) { |
| 264 $Array.forEach(schema[type], function(node) { | 262 $Array.forEach(schema[type], function(node) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 ' already defined in ' + schema.namespace); | 372 ' already defined in ' + schema.namespace); |
| 375 } | 373 } |
| 376 | 374 |
| 377 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) { | 375 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) { |
| 378 this.apiFunctions_.registerUnavailable(functionDef.name); | 376 this.apiFunctions_.registerUnavailable(functionDef.name); |
| 379 return; | 377 return; |
| 380 } | 378 } |
| 381 | 379 |
| 382 var apiFunction = {}; | 380 var apiFunction = {}; |
| 383 apiFunction.definition = functionDef; | 381 apiFunction.definition = functionDef; |
| 384 var apiFunctionName = schema.namespace + '.' + functionDef.name; | 382 apiFunction.name = schema.namespace + '.' + functionDef.name; |
| 385 apiFunction.name = apiFunctionName; | |
| 386 | 383 |
| 387 if (!GetAvailability(apiFunctionName).is_available || | 384 if (!GetAvailability(apiFunction.name).is_available || |
| 388 (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) { | 385 (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) { |
| 389 this.apiFunctions_.registerUnavailable(functionDef.name); | 386 this.apiFunctions_.registerUnavailable(functionDef.name); |
| 390 return; | 387 return; |
| 391 } | 388 } |
| 392 | 389 |
| 393 // TODO(aa): It would be best to run this in a unit test, but in order | 390 // TODO(aa): It would be best to run this in a unit test, but in order |
| 394 // to do that we would need to better factor this code so that it | 391 // to do that we would need to better factor this code so that it |
| 395 // doesn't depend on so much v8::Extension machinery. | 392 // doesn't depend on so much v8::Extension machinery. |
| 396 if (logging.DCHECK_IS_ON() && | 393 if (logging.DCHECK_IS_ON() && |
| 397 schemaUtils.isFunctionSignatureAmbiguous(apiFunction.definition)) { | 394 schemaUtils.isFunctionSignatureAmbiguous(apiFunction.definition)) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 availability.message); | 552 availability.message); |
| 556 return; | 553 return; |
| 557 } | 554 } |
| 558 | 555 |
| 559 this.runHooks_(mod, schema); | 556 this.runHooks_(mod, schema); |
| 560 return mod; | 557 return mod; |
| 561 } | 558 } |
| 562 }; | 559 }; |
| 563 | 560 |
| 564 exports.$set('Binding', Binding); | 561 exports.$set('Binding', Binding); |
| OLD | NEW |