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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 | 231 |
230 // Generates the bindings from the schema for |this.apiName_| and integrates | 232 // Generates the bindings from the schema for |this.apiName_| and integrates |
231 // any custom bindings that might be present. | 233 // any custom bindings that might be present. |
232 generate: function() { | 234 generate: function() { |
233 // NB: It's important to load the schema during generation rather than | 235 // NB: It's important to load the schema during generation rather than |
234 // setting it beforehand so that we're more confident the schema we're | 236 // setting it beforehand so that we're more confident the schema we're |
235 // loading is real, and not one that was injected by a page intercepting | 237 // loading is real, and not one that was injected by a page intercepting |
236 // Binding.generate. | 238 // Binding.generate. |
237 // Additionally, since the schema is an object returned from a native | 239 // Additionally, since the schema is an object returned from a native |
238 // handler, its properties don't have the custom getters/setters that a page | 240 // handler, its properties don't have the custom getters/setters that a page |
239 // may have put on Object.prototype. | 241 // may have put on Object.prototype, and the object is frozen by v8. |
240 var schema = schemaRegistry.GetSchema(this.apiName_); | 242 var schema = schemaRegistry.GetSchema(this.apiName_); |
241 | 243 |
242 function shouldCheckUnprivileged() { | 244 function shouldCheckUnprivileged() { |
243 var shouldCheck = 'unprivileged' in schema; | 245 var shouldCheck = 'unprivileged' in schema; |
244 if (shouldCheck) | 246 if (shouldCheck) |
245 return shouldCheck; | 247 return shouldCheck; |
246 | 248 |
247 $Array.forEach(['functions', 'events'], function(type) { | 249 $Array.forEach(['functions', 'events'], function(type) { |
248 if ($Object.hasOwnProperty(schema, type)) { | 250 if ($Object.hasOwnProperty(schema, type)) { |
249 $Array.forEach(schema[type], function(node) { | 251 $Array.forEach(schema[type], function(node) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 ' already defined in ' + schema.namespace); | 361 ' already defined in ' + schema.namespace); |
360 } | 362 } |
361 | 363 |
362 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) { | 364 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) { |
363 this.apiFunctions_.registerUnavailable(functionDef.name); | 365 this.apiFunctions_.registerUnavailable(functionDef.name); |
364 return; | 366 return; |
365 } | 367 } |
366 | 368 |
367 var apiFunction = {}; | 369 var apiFunction = {}; |
368 apiFunction.definition = functionDef; | 370 apiFunction.definition = functionDef; |
369 apiFunction.name = schema.namespace + '.' + functionDef.name; | 371 var apiFunctionName = schema.namespace + '.' + functionDef.name; |
372 apiFunction.name = apiFunctionName; | |
robwu
2016/04/20 10:49:17
If you're concerned about being affected by protot
Devlin
2016/04/20 13:44:38
This is what https://codereview.chromium.org/19020
robwu
2016/04/20 15:06:35
|apiFunction| is an internal object, so it shouldn
| |
370 | 373 |
371 if (!GetAvailability(apiFunction.name).is_available || | 374 if (!GetAvailability(apiFunctionName).is_available || |
asargent_no_longer_on_chrome
2016/04/19 23:06:48
ugh, javascript
I fear we will this mistake again
Devlin
2016/04/19 23:18:22
Quite :/ I've been talking with Adam Klein and go
| |
372 (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) { | 375 (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) { |
373 this.apiFunctions_.registerUnavailable(functionDef.name); | 376 this.apiFunctions_.registerUnavailable(functionDef.name); |
374 return; | 377 return; |
375 } | 378 } |
376 | 379 |
377 // TODO(aa): It would be best to run this in a unit test, but in order | 380 // TODO(aa): It would be best to run this in a unit test, but in order |
378 // to do that we would need to better factor this code so that it | 381 // to do that we would need to better factor this code so that it |
379 // doesn't depend on so much v8::Extension machinery. | 382 // doesn't depend on so much v8::Extension machinery. |
380 if (logging.DCHECK_IS_ON() && | 383 if (logging.DCHECK_IS_ON() && |
381 schemaUtils.isFunctionSignatureAmbiguous(apiFunction.definition)) { | 384 schemaUtils.isFunctionSignatureAmbiguous(apiFunction.definition)) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 availability.message); | 542 availability.message); |
540 return; | 543 return; |
541 } | 544 } |
542 | 545 |
543 this.runHooks_(mod, schema); | 546 this.runHooks_(mod, schema); |
544 return mod; | 547 return mod; |
545 } | 548 } |
546 }; | 549 }; |
547 | 550 |
548 exports.$set('Binding', Binding); | 551 exports.$set('Binding', Binding); |
OLD | NEW |