| 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 API bindings. |
| 8 | 8 |
| 9 The Blink Web Module bindings provide a stable, IDL-generated interface for the | 9 The Blink API bindings provide a stable, IDL-generated interface for the |
| 10 Web Modules. | 10 Web Agents. |
| 11 | 11 |
| 12 The Web Modules are the high-level services like Autofill, | 12 The Web Agents 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 Agents |
| 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 Agents 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, render_template | 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 BLINK_API_IDL_ATTRIBUTE = 'BlinkAPI' |
| 32 STRING_INCLUDE_PATH = 'wtf/text/WTFString.h' | 32 STRING_INCLUDE_PATH = 'wtf/text/WTFString.h' |
| 33 | 33 |
| 34 |
| 34 def interface_context(idl_interface): | 35 def interface_context(idl_interface): |
| 35 builder = InterfaceContextBuilder(MODULE_PYNAME, TypeResolver()) | 36 builder = InterfaceContextBuilder(MODULE_PYNAME, TypeResolver()) |
| 36 builder.set_class_name(idl_interface.name) | 37 builder.set_class_name(idl_interface.name) |
| 37 builder.set_inheritance(idl_interface.parent) | 38 builder.set_inheritance(idl_interface.parent) |
| 38 | 39 |
| 39 for idl_attribute in idl_interface.attributes: | 40 for idl_attribute in idl_interface.attributes: |
| 40 builder.add_attribute(idl_attribute) | 41 builder.add_attribute(idl_attribute) |
| 41 | 42 |
| 42 for idl_operation in idl_interface.operations: | 43 for idl_operation in idl_interface.operations: |
| 43 builder.add_operation(idl_operation) | 44 builder.add_operation(idl_operation) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 return_type = self.type_resolver.type_from_definition(idl_attribute) | 124 return_type = self.type_resolver.type_from_definition(idl_attribute) |
| 124 return { | 125 return { |
| 125 'name': name, | 126 'name': name, |
| 126 'return_type': return_type | 127 'return_type': return_type |
| 127 } | 128 } |
| 128 | 129 |
| 129 def build(self): | 130 def build(self): |
| 130 return self.result | 131 return self.result |
| 131 | 132 |
| 132 | 133 |
| 133 class CodeGeneratorWebModule(CodeGeneratorBase): | 134 class CodeGeneratorBlinkAPI(CodeGeneratorBase): |
| 134 def __init__(self, info_provider, cache_dir, output_dir): | 135 def __init__(self, info_provider, cache_dir, output_dir): |
| 135 CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, | 136 CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, |
| 136 cache_dir, output_dir) | 137 cache_dir, output_dir) |
| 137 self.typedef_resolver = TypedefResolver(info_provider) | 138 self.typedef_resolver = TypedefResolver(info_provider) |
| 138 | 139 |
| 139 def get_template(self, file_extension): | 140 def get_template(self, file_extension): |
| 140 template_filename = 'web_module_interface.%s.tmpl' % file_extension | 141 template_filename = 'blink_api_interface.%s.tmpl' % file_extension |
| 141 return self.jinja_env.get_template(template_filename) | 142 return self.jinja_env.get_template(template_filename) |
| 142 | 143 |
| 143 # TODO(dglazkov): Move to CodeGeneratorBase. | 144 # TODO(dglazkov): Move to CodeGeneratorBase. |
| 144 def output_paths(self, definition_name): | 145 def output_paths(self, definition_name): |
| 145 header_path = posixpath.join(self.output_dir, | 146 header_path = posixpath.join(self.output_dir, |
| 146 'Web%s.h' % definition_name) | 147 'Web%s.h' % definition_name) |
| 147 cpp_path = posixpath.join(self.output_dir, | 148 cpp_path = posixpath.join(self.output_dir, |
| 148 'Web%s.cpp' % definition_name) | 149 'Web%s.cpp' % definition_name) |
| 149 return header_path, cpp_path | 150 return header_path, cpp_path |
| 150 | 151 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 162 header_text = render_template(header_template, template_context) | 163 header_text = render_template(header_template, template_context) |
| 163 header_path, cpp_path = self.output_paths(interface.name) | 164 header_path, cpp_path = self.output_paths(interface.name) |
| 164 | 165 |
| 165 return ( | 166 return ( |
| 166 (header_path, header_text), | 167 (header_path, header_text), |
| 167 (cpp_path, cpp_text) | 168 (cpp_path, cpp_text) |
| 168 ) | 169 ) |
| 169 | 170 |
| 170 def generate_code(self, definitions, definition_name): | 171 def generate_code(self, definitions, definition_name): |
| 171 self.typedef_resolver.resolve(definitions, definition_name) | 172 self.typedef_resolver.resolve(definitions, definition_name) |
| 172 header_path, cpp_path = self.output_paths(definition_name) | |
| 173 | 173 |
| 174 template_context = {} | |
| 175 # TODO(dglazkov): Implement dictionaries | 174 # TODO(dglazkov): Implement dictionaries |
| 176 if definition_name not in definitions.interfaces: | 175 if definition_name not in definitions.interfaces: |
| 177 return None | 176 return None |
| 178 | 177 |
| 179 interface = definitions.interfaces[definition_name] | 178 interface = definitions.interfaces[definition_name] |
| 180 if WEB_MODULE_IDL_ATTRIBUTE not in interface.extended_attributes: | 179 if BLINK_API_IDL_ATTRIBUTE not in interface.extended_attributes: |
| 181 return None | 180 return None |
| 182 | 181 |
| 183 return self.generate_interface_code(interface) | 182 return self.generate_interface_code(interface) |
| OLD | NEW |