| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module provides shared functionality for the system to generate | 6 """This module provides shared functionality for the system to generate |
| 7 dart:html APIs from the IDL database.""" | 7 dart:html APIs from the IDL database.""" |
| 8 | 8 |
| 9 from generator import AnalyzeOperation, ConstantOutputOrder, \ | 9 from generator import AnalyzeOperation, ConstantOutputOrder, \ |
| 10 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ | 10 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ |
| 11 IsPureInterface, TypeOrNothing | 11 IsPureInterface, TypeOrNothing |
| 12 | 12 |
| 13 # Types that are accessible cross-frame in a limited fashion. | 13 # Types that are accessible cross-frame in a limited fashion. |
| 14 # In these cases, the base type (e.g., Window) provides restricted access | 14 # In these cases, the base type (e.g., WindowBase) provides restricted access |
| 15 # while the subtype (e.g., LocalWindow) provides full access to the | 15 # while the subtype (e.g., Window) provides full access to the |
| 16 # corresponding objects if there are from the same frame. | 16 # corresponding objects if there are from the same frame. |
| 17 _secure_base_types = { | 17 _secure_base_types = { |
| 18 'LocalWindow': 'Window', | 18 'Window': 'WindowBase', |
| 19 'LocalLocation': 'Location', | 19 'Location': 'LocationBase', |
| 20 'LocalHistory': 'History', | 20 'History': 'HistoryBase', |
| 21 } | 21 } |
| 22 | 22 |
| 23 class HtmlDartGenerator(object): | 23 class HtmlDartGenerator(object): |
| 24 def __init__(self, interface, options): | 24 def __init__(self, interface, options): |
| 25 self._database = options.database | 25 self._database = options.database |
| 26 self._interface = interface | 26 self._interface = interface |
| 27 self._type_registry = options.type_registry | 27 self._type_registry = options.type_registry |
| 28 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) | 28 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) |
| 29 self._renamer = options.renamer | 29 self._renamer = options.renamer |
| 30 | 30 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 296 |
| 297 def SecureOutputType(self, type_name, is_dart_type=False): | 297 def SecureOutputType(self, type_name, is_dart_type=False): |
| 298 """ Converts the type name to the secure type name for return types. | 298 """ Converts the type name to the secure type name for return types. |
| 299 """ | 299 """ |
| 300 if is_dart_type: | 300 if is_dart_type: |
| 301 dart_name = type_name | 301 dart_name = type_name |
| 302 else: | 302 else: |
| 303 dart_name = self._DartType(type_name) | 303 dart_name = self._DartType(type_name) |
| 304 # We only need to secure Window. Only local History and Location are | 304 # We only need to secure Window. Only local History and Location are |
| 305 # returned in generated code. | 305 # returned in generated code. |
| 306 assert(dart_name != 'History' and dart_name != 'Location') | 306 assert(dart_name != 'HistoryBase' and dart_name != 'LocationBase') |
| 307 if dart_name == 'LocalWindow': | 307 if dart_name == 'Window': |
| 308 return _secure_base_types[dart_name] | 308 return _secure_base_types[dart_name] |
| 309 return dart_name | 309 return dart_name |
| 310 | 310 |
| 311 def SecureBaseName(self, type_name): | 311 def SecureBaseName(self, type_name): |
| 312 if type_name in _secure_base_types: | 312 if type_name in _secure_base_types: |
| 313 return _secure_base_types[type_name] | 313 return _secure_base_types[type_name] |
| 314 | 314 |
| 315 def _TransitiveSecondaryParents(self, interface): | 315 def _TransitiveSecondaryParents(self, interface): |
| 316 """Returns a list of all non-primary parents. | 316 """Returns a list of all non-primary parents. |
| 317 | 317 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 340 walk(interface.parents) | 340 walk(interface.parents) |
| 341 else: | 341 else: |
| 342 walk(interface.parents[1:]) | 342 walk(interface.parents[1:]) |
| 343 return result | 343 return result |
| 344 | 344 |
| 345 def _DartType(self, type_name): | 345 def _DartType(self, type_name): |
| 346 return self._type_registry.DartType(type_name) | 346 return self._type_registry.DartType(type_name) |
| 347 | 347 |
| 348 def _IsPrivate(self, name): | 348 def _IsPrivate(self, name): |
| 349 return name.startswith('_') | 349 return name.startswith('_') |
| OLD | NEW |