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 var GetAvailability = requireNative('v8_context').GetAvailability; | 7 var GetAvailability = requireNative('v8_context').GetAvailability; |
8 var exceptionHandler = require('uncaught_exception_handler'); | 8 var exceptionHandler = require('uncaught_exception_handler'); |
9 var lastError = require('lastError'); | 9 var lastError = require('lastError'); |
10 var logActivity = requireNative('activityLogger'); | 10 var logActivity = requireNative('activityLogger'); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 268 } |
269 | 269 |
270 var mod = {}; | 270 var mod = {}; |
271 | 271 |
272 var namespaces = $String.split(schema.namespace, '.'); | 272 var namespaces = $String.split(schema.namespace, '.'); |
273 for (var index = 0, name; name = namespaces[index]; index++) { | 273 for (var index = 0, name; name = namespaces[index]; index++) { |
274 mod[name] = mod[name] || {}; | 274 mod[name] = mod[name] || {}; |
275 mod = mod[name]; | 275 mod = mod[name]; |
276 } | 276 } |
277 | 277 |
278 // Add types to global schemaValidator, the types we depend on from other | |
279 // namespaces will be added as needed. | |
280 if (schema.types) { | 278 if (schema.types) { |
281 $Array.forEach(schema.types, function(t) { | 279 $Array.forEach(schema.types, function(t) { |
282 if (!isSchemaNodeSupported(t, platform, manifestVersion)) | 280 if (!isSchemaNodeSupported(t, platform, manifestVersion)) |
283 return; | 281 return; |
| 282 |
| 283 // Add types to global schemaValidator; the types we depend on from |
| 284 // other namespaces will be added as needed. |
284 schemaUtils.schemaValidator.addTypes(t); | 285 schemaUtils.schemaValidator.addTypes(t); |
| 286 |
| 287 // Generate symbols for enums. |
| 288 var enumValues = t['enum']; |
| 289 if (enumValues) { |
| 290 // Type IDs are qualified with the namespace during compilation, |
| 291 // unfortunately, so remove it here. |
| 292 logging.DCHECK( |
| 293 t.id.substr(0, schema.namespace.length) == schema.namespace); |
| 294 // Note: + 1 because it ends in a '.', e.g., 'fooApi.Type'. |
| 295 var id = t.id.substr(schema.namespace.length + 1); |
| 296 mod[id] = {}; |
| 297 $Array.forEach(enumValues, function(enumValue) { |
| 298 // Note: enums can be declared either as a list of strings |
| 299 // ['foo', 'bar'] or as a list of objects |
| 300 // [{'name': 'foo'}, {'name': 'bar'}]. |
| 301 enumValue = |
| 302 enumValue.hasOwnProperty('name') ? enumValue.name : enumValue; |
| 303 if (enumValue) // Avoid setting any empty enums. |
| 304 mod[id][enumValue] = enumValue; |
| 305 }); |
| 306 } |
285 }, this); | 307 }, this); |
286 } | 308 } |
287 | 309 |
288 // TODO(cduvall): Take out when all APIs have been converted to features. | 310 // TODO(cduvall): Take out when all APIs have been converted to features. |
289 // Returns whether access to the content of a schema should be denied, | 311 // Returns whether access to the content of a schema should be denied, |
290 // based on the presence of "unprivileged" and whether this is an | 312 // based on the presence of "unprivileged" and whether this is an |
291 // extension process (versus e.g. a content script). | 313 // extension process (versus e.g. a content script). |
292 function isSchemaAccessAllowed(itemSchema) { | 314 function isSchemaAccessAllowed(itemSchema) { |
293 return (contextType == 'BLESSED_EXTENSION') || | 315 return (contextType == 'BLESSED_EXTENSION') || |
294 schema.unprivileged || | 316 schema.unprivileged || |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 availability.message); | 505 availability.message); |
484 return; | 506 return; |
485 } | 507 } |
486 | 508 |
487 this.runHooks_(mod); | 509 this.runHooks_(mod); |
488 return mod; | 510 return mod; |
489 } | 511 } |
490 }; | 512 }; |
491 | 513 |
492 exports.Binding = Binding; | 514 exports.Binding = Binding; |
OLD | NEW |