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