| 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 Web Agent API bindings. |
| 8 | 8 |
| 9 The Blink Web Module bindings provide a stable, IDL-generated interface for the | 9 The Web Agent 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 from name_style_converter import NameStyleConverter | 28 from name_style_converter import NameStyleConverter |
| 29 | 29 |
| 30 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' | 30 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' |
| 31 | 31 |
| 32 STRING_INCLUDE_PATH = 'wtf/text/WTFString.h' | 32 STRING_INCLUDE_PATH = 'wtf/text/WTFString.h' |
| 33 WEB_MODULE_IDL_ATTRIBUTE = 'WebModuleAPI' | 33 WEB_AGENT_API_IDL_ATTRIBUTE = 'WebAgentAPI' |
| 34 | 34 |
| 35 | 35 |
| 36 def interface_context(idl_interface, type_resolver): | 36 def interface_context(idl_interface, type_resolver): |
| 37 builder = InterfaceContextBuilder(MODULE_PYNAME, type_resolver) | 37 builder = InterfaceContextBuilder(MODULE_PYNAME, type_resolver) |
| 38 builder.set_class_name(idl_interface.name) | 38 builder.set_class_name(idl_interface.name) |
| 39 builder.set_inheritance(idl_interface.parent) | 39 builder.set_inheritance(idl_interface.parent) |
| 40 | 40 |
| 41 for idl_attribute in idl_interface.attributes: | 41 for idl_attribute in idl_interface.attributes: |
| 42 builder.add_attribute(idl_attribute) | 42 builder.add_attribute(idl_attribute) |
| 43 | 43 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return_type = self.type_resolver.type_from_definition(idl_attribute) | 136 return_type = self.type_resolver.type_from_definition(idl_attribute) |
| 137 return { | 137 return { |
| 138 'name': name, | 138 'name': name, |
| 139 'return_type': return_type | 139 'return_type': return_type |
| 140 } | 140 } |
| 141 | 141 |
| 142 def build(self): | 142 def build(self): |
| 143 return self.result | 143 return self.result |
| 144 | 144 |
| 145 | 145 |
| 146 class CodeGeneratorWebModule(CodeGeneratorBase): | 146 class CodeGeneratorWebAgentAPI(CodeGeneratorBase): |
| 147 def __init__(self, info_provider, cache_dir, output_dir): | 147 def __init__(self, info_provider, cache_dir, output_dir): |
| 148 CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, | 148 CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, |
| 149 cache_dir, output_dir) | 149 cache_dir, output_dir) |
| 150 self.type_resolver = TypeResolver(info_provider.interfaces_info) | 150 self.type_resolver = TypeResolver(info_provider.interfaces_info) |
| 151 self.typedef_resolver = TypedefResolver(info_provider) | 151 self.typedef_resolver = TypedefResolver(info_provider) |
| 152 | 152 |
| 153 def get_template(self, file_extension): | 153 def get_template(self, file_extension): |
| 154 template_filename = 'web_module_interface.%s.tmpl' % file_extension | 154 template_filename = 'web_agent_api_interface.%s.tmpl' % file_extension |
| 155 return self.jinja_env.get_template(template_filename) | 155 return self.jinja_env.get_template(template_filename) |
| 156 | 156 |
| 157 def generate_file(self, template_context, file_extension): | 157 def generate_file(self, template_context, file_extension): |
| 158 template = self.get_template(file_extension) | 158 template = self.get_template(file_extension) |
| 159 path = posixpath.join( | 159 path = posixpath.join( |
| 160 self.output_dir, | 160 self.output_dir, |
| 161 '%s.%s' % (template_context['class_name']['snake_case'], | 161 '%s.%s' % (template_context['class_name']['snake_case'], |
| 162 file_extension)) | 162 file_extension)) |
| 163 text = render_template(template, template_context) | 163 text = render_template(template, template_context) |
| 164 return (path, text) | 164 return (path, text) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 177 ) | 177 ) |
| 178 | 178 |
| 179 def generate_code(self, definitions, definition_name): | 179 def generate_code(self, definitions, definition_name): |
| 180 self.typedef_resolver.resolve(definitions, definition_name) | 180 self.typedef_resolver.resolve(definitions, definition_name) |
| 181 | 181 |
| 182 # TODO(dglazkov): Implement dictionaries | 182 # TODO(dglazkov): Implement dictionaries |
| 183 if definition_name not in definitions.interfaces: | 183 if definition_name not in definitions.interfaces: |
| 184 return None | 184 return None |
| 185 | 185 |
| 186 interface = definitions.interfaces[definition_name] | 186 interface = definitions.interfaces[definition_name] |
| 187 if WEB_MODULE_IDL_ATTRIBUTE not in interface.extended_attributes: | 187 if WEB_AGENT_API_IDL_ATTRIBUTE not in interface.extended_attributes: |
| 188 return None | 188 return None |
| 189 | 189 |
| 190 return self.generate_interface_code(interface) | 190 return self.generate_interface_code(interface) |
| OLD | NEW |