Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 # pylint: disable=import-error,print-statement,relative-import | |
| 6 | |
| 7 """Generates Blink Web Module bindings. | |
| 8 | |
| 9 The Blink Web Module bindings provide a stable, IDL-generated interface for the | |
| 10 Web Modules. | |
| 11 | |
| 12 The Web Modules are the high-level services like Autofill, | |
| 13 Autocomplete, Translate, Distiller, Phishing Detector, and others. Web Modules | |
| 14 typically want to introspec the document and rendering infromation to implement | |
| 15 browser features. | |
| 16 | |
| 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 | |
| 19 DOM classes to the Web Modules layer. | |
| 20 """ | |
| 21 | |
| 22 import os | |
| 23 import posixpath | |
| 24 | |
| 25 from code_generator import CodeGeneratorBase | |
| 26 # TODO(dglazkov): Move TypedefResolver to code_generator.py | |
| 27 from code_generator_v8 import TypedefResolver | |
| 28 from v8_interface import interface_context | |
| 29 | |
| 30 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' | |
| 31 | |
| 32 WEB_MODULE_IDL_ATTRIBUTE = 'WebModuleAPI' | |
| 33 | |
| 34 | |
| 35 class CodeGeneratorWebModule(CodeGeneratorBase): | |
| 36 def __init__(self, info_provider, cache_dir, output_dir): | |
| 37 CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, | |
| 38 cache_dir, output_dir) | |
| 39 self.typedef_resolver = TypedefResolver(info_provider) | |
| 40 | |
| 41 def get_template(self): | |
| 42 template_filename = 'web_module_interface.cpp.tmpl' | |
| 43 return self.jinja_env.get_template(template_filename) | |
| 44 | |
| 45 # TODO(dglazkov): Move to CodeGeneratorBase. | |
| 46 def output_paths(self, definition_name): | |
| 47 header_path = posixpath.join(self.output_dir, | |
| 48 'Web%s.h' % definition_name) | |
| 49 cpp_path = posixpath.join(self.output_dir, | |
| 50 'Web%s.cpp' % definition_name) | |
| 51 return header_path, cpp_path | |
| 52 | |
| 53 def generate_code(self, definitions, definition_name): | |
| 54 self.typedef_resolver.resolve(definitions, definition_name) | |
| 55 header_path, cpp_path = self.output_paths(definition_name) | |
| 56 | |
| 57 template_context = {} | |
| 58 # TODO(dglazkov): Implement dictionaries | |
| 59 if definition_name not in definitions.interfaces: | |
| 60 return None | |
| 61 | |
| 62 interface = definitions.interfaces[definition_name] | |
| 63 if WEB_MODULE_IDL_ATTRIBUTE not in interface.extended_attributes: | |
| 64 return None | |
| 65 | |
| 66 # TODO(dglazkov): Implement callback interfaces. | |
| 67 # TODO(dglazkov): Implement partial interfaces. | |
| 68 if interface.is_callback and interface.is_partial: | |
| 69 return None | |
| 70 | |
| 71 template_context = interface_context(interface, | |
|
bashi
2016/11/06 23:58:20
v8_interface.interface_context() creates a jinja2
| |
| 72 definitions.interfaces) | |
| 73 template_context['code_generator'] = MODULE_PYNAME | |
| 74 template_context['class_name'] = definition_name | |
| 75 | |
| 76 cpp_template = self.get_template() | |
| 77 cpp_text = cpp_template.render(template_context) | |
| 78 | |
| 79 header_text = 'header' | |
| 80 return ( | |
| 81 (header_path, header_text), | |
| 82 (cpp_path, cpp_text) | |
| 83 ) | |
| OLD | NEW |