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

Side by Side Diff: headless/lib/browser/client_api_generator.py

Issue 1904073002: headless: Move hidden commands and events to experimental domains (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also require parameters for hidden commands where the entire domain isn't hidden Created 4 years, 8 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
« no previous file with comments | « no previous file | headless/lib/browser/client_api_generator_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import argparse 5 import argparse
6 import os.path 6 import os.path
7 import sys 7 import sys
8 import re 8 import re
9 try: 9 try:
10 import json 10 import json
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 event_type = { 346 event_type = {
347 'id': ToTitleCase(event['name']) + 'Params', 347 'id': ToTitleCase(event['name']) + 'Params',
348 'type': 'object', 348 'type': 'object',
349 'description': 'Parameters for the %s event.' % ToTitleCase( 349 'description': 'Parameters for the %s event.' % ToTitleCase(
350 event['name']), 350 event['name']),
351 'properties': event.get('parameters', []) 351 'properties': event.get('parameters', [])
352 } 352 }
353 domain['types'].append(event_type) 353 domain['types'].append(event_type)
354 354
355 355
356 def PatchHiddenCommandsAndEvents(json_api):
357 """
358 Mark all commands and events in hidden domains as hidden and make sure hidden
359 commands have at least empty parameters and return values.
360 """
361 for domain in json_api['domains']:
362 if domain.get('hidden', False):
363 for command in domain.get('commands', []):
364 command['hidden'] = True
365 for event in domain.get('events', []):
366 event['hidden'] = True
367 for command in domain.get('commands', []):
368 if not command.get('hidden', False):
369 continue
370 if not 'parameters' in command:
371 command['parameters'] = []
372 if not 'returns' in command:
373 command['returns'] = []
374 for event in domain.get('events', []):
375 if not event.get('hidden', False):
376 continue
377 if not 'parameters' in event:
378 event['parameters'] = []
379
380
356 def Generate(jinja_env, output_dirname, json_api, class_name, file_types): 381 def Generate(jinja_env, output_dirname, json_api, class_name, file_types):
357 template_context = { 382 template_context = {
358 'api': json_api, 383 'api': json_api,
359 'join_arrays': JoinArrays, 384 'join_arrays': JoinArrays,
360 'resolve_type': ResolveType, 385 'resolve_type': ResolveType,
361 'type_definition': TypeDefinition, 386 'type_definition': TypeDefinition,
362 } 387 }
363 for file_type in file_types: 388 for file_type in file_types:
364 template = jinja_env.get_template('/%s_%s.template' % ( 389 template = jinja_env.get_template('/%s_%s.template' % (
365 class_name, file_type)) 390 class_name, file_type))
(...skipping 14 matching lines...) Expand all
380 } 405 }
381 domain_name = CamelCaseToHackerStyle(domain['domain']) 406 domain_name = CamelCaseToHackerStyle(domain['domain'])
382 output_file = '%s/%s.%s' % (output_dirname, domain_name, file_type) 407 output_file = '%s/%s.%s' % (output_dirname, domain_name, file_type)
383 with open(output_file, 'w') as f: 408 with open(output_file, 'w') as f:
384 f.write(template.render(template_context)) 409 f.write(template.render(template_context))
385 410
386 411
387 if __name__ == '__main__': 412 if __name__ == '__main__':
388 json_api, output_dirname = ParseArguments(sys.argv[1:]) 413 json_api, output_dirname = ParseArguments(sys.argv[1:])
389 jinja_env = InitializeJinjaEnv(output_dirname) 414 jinja_env = InitializeJinjaEnv(output_dirname)
415 PatchHiddenCommandsAndEvents(json_api)
390 SynthesizeCommandTypes(json_api) 416 SynthesizeCommandTypes(json_api)
391 SynthesizeEventTypes(json_api) 417 SynthesizeEventTypes(json_api)
392 PatchFullQualifiedRefs(json_api) 418 PatchFullQualifiedRefs(json_api)
393 CreateTypeDefinitions(json_api) 419 CreateTypeDefinitions(json_api)
394 Generate(jinja_env, output_dirname, json_api, 'types', ['cc', 'h']) 420 Generate(jinja_env, output_dirname, json_api, 'types', ['cc', 'h'])
395 Generate(jinja_env, output_dirname, json_api, 'type_conversions', ['h']) 421 Generate(jinja_env, output_dirname, json_api, 'type_conversions', ['h'])
396 GenerateDomains(jinja_env, output_dirname, json_api, 'domain', ['cc', 'h']) 422 GenerateDomains(jinja_env, output_dirname, json_api, 'domain', ['cc', 'h'])
OLDNEW
« no previous file with comments | « no previous file | headless/lib/browser/client_api_generator_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698