| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 # pylint: disable=import-error,print-statement,relative-import | 5 # pylint: disable=import-error,print-statement,relative-import |
| 6 | 6 |
| 7 """Generates Blink Web Module bindings. | 7 """Generates Blink Web Module bindings. |
| 8 | 8 |
| 9 The Blink Web Module bindings provide a stable, IDL-generated interface for the | 9 The Blink Web Module bindings provide a stable, IDL-generated interface for the |
| 10 Web Modules. | 10 Web Modules. |
| 11 | 11 |
| 12 The Web Modules are the high-level services like Autofill, | 12 The Web Modules are the high-level services like Autofill, |
| 13 Autocomplete, Translate, Distiller, Phishing Detector, and others. Web Modules | 13 Autocomplete, Translate, Distiller, Phishing Detector, and others. Web Modules |
| 14 typically want to introspec the document and rendering infromation to implement | 14 typically want to introspec the document and rendering infromation to implement |
| 15 browser features. | 15 browser features. |
| 16 | 16 |
| 17 The bindings are meant to be as simple and as ephemeral as possible, mostly just | 17 The bindings are meant to be as simple and as ephemeral as possible, mostly just |
| 18 wrapping existing DOM classes. Their primary goal is to avoid leaking the actual | 18 wrapping existing DOM classes. Their primary goal is to avoid leaking the actual |
| 19 DOM classes to the Web Modules layer. | 19 DOM classes to the Web Modules layer. |
| 20 """ | 20 """ |
| 21 | 21 |
| 22 import os | 22 import os |
| 23 import posixpath | 23 import posixpath |
| 24 | 24 |
| 25 from code_generator import CodeGeneratorBase | 25 from code_generator import CodeGeneratorBase, render_template |
| 26 # TODO(dglazkov): Move TypedefResolver to code_generator.py | 26 # TODO(dglazkov): Move TypedefResolver to code_generator.py |
| 27 from code_generator_v8 import TypedefResolver | 27 from code_generator_v8 import TypedefResolver |
| 28 | 28 |
| 29 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' | 29 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' |
| 30 | 30 |
| 31 WEB_MODULE_IDL_ATTRIBUTE = 'WebModuleAPI' | 31 WEB_MODULE_IDL_ATTRIBUTE = 'WebModuleAPI' |
| 32 | 32 |
| 33 | 33 |
| 34 def includes_for_type(idl_type): | 34 def includes_for_type(idl_type): |
| 35 # TODO(dglazkov): Make this actually work. | 35 # TODO(dglazkov): Make this actually work. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 def generate_interface_code(self, interface): | 117 def generate_interface_code(self, interface): |
| 118 # TODO(dglazkov): Implement callback interfaces. | 118 # TODO(dglazkov): Implement callback interfaces. |
| 119 # TODO(dglazkov): Make sure partial interfaces are handled. | 119 # TODO(dglazkov): Make sure partial interfaces are handled. |
| 120 if interface.is_callback or interface.is_partial: | 120 if interface.is_callback or interface.is_partial: |
| 121 raise ValueError('Partial or callback interfaces are not supported') | 121 raise ValueError('Partial or callback interfaces are not supported') |
| 122 | 122 |
| 123 template_context = interface_context(interface) | 123 template_context = interface_context(interface) |
| 124 | 124 |
| 125 cpp_template = self.get_template('cpp') | 125 cpp_template = self.get_template('cpp') |
| 126 header_template = self.get_template('h') | 126 header_template = self.get_template('h') |
| 127 cpp_text = cpp_template.render(template_context) | 127 cpp_text = render_template(cpp_template, template_context) |
| 128 header_text = header_template.render(template_context) | 128 header_text = render_template(header_template, template_context) |
| 129 header_path, cpp_path = self.output_paths(interface.name) | 129 header_path, cpp_path = self.output_paths(interface.name) |
| 130 | 130 |
| 131 return ( | 131 return ( |
| 132 (header_path, header_text), | 132 (header_path, header_text), |
| 133 (cpp_path, cpp_text) | 133 (cpp_path, cpp_text) |
| 134 ) | 134 ) |
| 135 | 135 |
| 136 def generate_code(self, definitions, definition_name): | 136 def generate_code(self, definitions, definition_name): |
| 137 self.typedef_resolver.resolve(definitions, definition_name) | 137 self.typedef_resolver.resolve(definitions, definition_name) |
| 138 header_path, cpp_path = self.output_paths(definition_name) | 138 header_path, cpp_path = self.output_paths(definition_name) |
| 139 | 139 |
| 140 template_context = {} | 140 template_context = {} |
| 141 # TODO(dglazkov): Implement dictionaries | 141 # TODO(dglazkov): Implement dictionaries |
| 142 if definition_name not in definitions.interfaces: | 142 if definition_name not in definitions.interfaces: |
| 143 return None | 143 return None |
| 144 | 144 |
| 145 interface = definitions.interfaces[definition_name] | 145 interface = definitions.interfaces[definition_name] |
| 146 if WEB_MODULE_IDL_ATTRIBUTE not in interface.extended_attributes: | 146 if WEB_MODULE_IDL_ATTRIBUTE not in interface.extended_attributes: |
| 147 return None | 147 return None |
| 148 | 148 |
| 149 return self.generate_interface_code(interface) | 149 return self.generate_interface_code(interface) |
| OLD | NEW |