Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/code_generator_web_agent_api.py

Issue 2970003002: Add code generation for ConditionalFeatures bindings code (Closed)
Patch Set: Clean up Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 Web Agent API bindings. 7 """Generates Web Agent API bindings.
8 8
9 The Web Agent API 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 Agents. 10 Web Agents.
11 11
12 The Web Agents 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 Agents 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 Agents 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 IDLCodeGeneratorBase, 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 = 'platform/wtf/text/WTFString.h' 32 STRING_INCLUDE_PATH = 'platform/wtf/text/WTFString.h'
33 WEB_AGENT_API_IDL_ATTRIBUTE = 'WebAgentAPI' 33 WEB_AGENT_API_IDL_ATTRIBUTE = 'WebAgentAPI'
34 34
35 35
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return_type = self.type_resolver.type_from_definition(idl_attribute) 227 return_type = self.type_resolver.type_from_definition(idl_attribute)
228 return { 228 return {
229 'name': name, 229 'name': name,
230 'type': return_type 230 'type': return_type
231 } 231 }
232 232
233 def build(self): 233 def build(self):
234 return self.result 234 return self.result
235 235
236 236
237 class CodeGeneratorWebAgentAPI(CodeGeneratorBase): 237 class CodeGeneratorWebAgentAPI(IDLCodeGeneratorBase):
238 def __init__(self, info_provider, cache_dir, output_dir): 238 def __init__(self, info_provider, cache_dir, output_dir):
239 CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, 239 IDLCodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider,
240 cache_dir, output_dir) 240 cache_dir, output_dir)
241 self.type_resolver = TypeResolver(info_provider.interfaces_info) 241 self.type_resolver = TypeResolver(info_provider.interfaces_info)
242 self.typedef_resolver = TypedefResolver(info_provider) 242 self.typedef_resolver = TypedefResolver(info_provider)
243 243
244 def get_template(self, file_extension): 244 def get_template(self, file_extension):
245 template_filename = 'web_agent_api_interface.%s.tmpl' % file_extension 245 template_filename = 'web_agent_api_interface.%s.tmpl' % file_extension
246 return self.jinja_env.get_template(template_filename) 246 return self.jinja_env.get_template(template_filename)
247 247
248 def generate_file(self, template_context, file_extension): 248 def generate_file(self, template_context, file_extension):
249 template = self.get_template(file_extension) 249 template = self.get_template(file_extension)
250 path = posixpath.join( 250 path = posixpath.join(
(...skipping 21 matching lines...) Expand all
272 272
273 # TODO(dglazkov): Implement dictionaries 273 # TODO(dglazkov): Implement dictionaries
274 if definition_name not in definitions.interfaces: 274 if definition_name not in definitions.interfaces:
275 return None 275 return None
276 276
277 interface = definitions.interfaces[definition_name] 277 interface = definitions.interfaces[definition_name]
278 if WEB_AGENT_API_IDL_ATTRIBUTE not in interface.extended_attributes: 278 if WEB_AGENT_API_IDL_ATTRIBUTE not in interface.extended_attributes:
279 return None 279 return None
280 280
281 return self.generate_interface_code(interface) 281 return self.generate_interface_code(interface)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698