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

Side by Side Diff: content/browser/devtools/protocol/devtools_protocol_handler_generator.py

Issue 1018983002: [DevTools] Support redirects in protocol handler generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reuse tmpl_register Created 5 years, 9 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import sys 6 import sys
7 import string 7 import string
8 import json 8 import json
9 9
10 blink_protocol_path = sys.argv[1] 10 blink_protocol_path = sys.argv[1]
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 devtools::${domain}::${Domain}Handler* ${domain}_handler) { 304 devtools::${domain}::${Domain}Handler* ${domain}_handler) {
305 DCHECK(!${domain}_handler_); 305 DCHECK(!${domain}_handler_);
306 ${domain}_handler_ = ${domain}_handler; 306 ${domain}_handler_ = ${domain}_handler;
307 ${initializations}\ 307 ${initializations}\
308 } 308 }
309 """) 309 """)
310 310
311 tmpl_register = string.Template("""\ 311 tmpl_register = string.Template("""\
312 command_handlers_["${Domain}.${command}"] = 312 command_handlers_["${Domain}.${command}"] =
313 base::Bind( 313 base::Bind(
314 &DevToolsProtocolDispatcher::On${Domain}${Command}, 314 &DevToolsProtocolDispatcher::On${TargetDomain}${Command},
315 base::Unretained(this)); 315 base::Unretained(this));
316 """) 316 """)
317 317
318 tmpl_init_client = string.Template("""\ 318 tmpl_init_client = string.Template("""\
319 ${domain}_handler_->SetClient(make_scoped_ptr( 319 ${domain}_handler_->SetClient(make_scoped_ptr(
320 new devtools::${domain}::Client(notifier_))); 320 new devtools::${domain}::Client(notifier_)));
321 """) 321 """)
322 322
323 tmpl_callback_impl = string.Template("""\ 323 tmpl_callback_impl = string.Template("""\
324 bool DevToolsProtocolDispatcher::On${Domain}${Command}( 324 bool DevToolsProtocolDispatcher::On${Domain}${Command}(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 result += c 443 result += c
444 return result 444 return result
445 445
446 types = {} 446 types = {}
447 blink_protocol = json.loads(open(blink_protocol_path, "r").read()) 447 blink_protocol = json.loads(open(blink_protocol_path, "r").read())
448 browser_protocol = json.loads(open(browser_protocol_path, "r").read()) 448 browser_protocol = json.loads(open(browser_protocol_path, "r").read())
449 type_decls = [] 449 type_decls = []
450 type_impls = [] 450 type_impls = []
451 handler_methods = [] 451 handler_methods = []
452 handler_method_impls = [] 452 handler_method_impls = []
453 domain_maps = []
454 redirects = {}
453 455
454 all_domains = blink_protocol["domains"] + browser_protocol["domains"] 456 all_domains = blink_protocol["domains"] + browser_protocol["domains"]
455 457
456 for json_domain in all_domains: 458 for json_domain in all_domains:
457 if "types" in json_domain: 459 if "types" in json_domain:
458 for json_type in json_domain["types"]: 460 for json_type in json_domain["types"]:
459 types["%s.%s" % (json_domain["domain"], json_type["id"])] = json_type 461 types["%s.%s" % (json_domain["domain"], json_type["id"])] = json_type
460 462
461 def DeclareStruct(json_properties, mapping): 463 def DeclareStruct(json_properties, mapping):
462 methods = [] 464 methods = []
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 for json_command in json_domain["commands"]: 633 for json_command in json_domain["commands"]:
632 if (not ("handlers" in json_command) or 634 if (not ("handlers" in json_command) or
633 not ("browser" in json_command["handlers"])): 635 not ("browser" in json_command["handlers"])):
634 continue 636 continue
635 domain_empty = False 637 domain_empty = False
636 638
637 command_map = domain_map.copy() 639 command_map = domain_map.copy()
638 command_map["command"] = json_command["name"] 640 command_map["command"] = json_command["name"]
639 command_map["Command"] = Capitalize(json_command["name"]) 641 command_map["Command"] = Capitalize(json_command["name"])
640 642
643 if "redirect" in json_command:
644 redirect_domain = json_command["redirect"]
645 if not (redirect_domain in redirects):
646 redirects[redirect_domain] = []
647 command_map["TargetDomain"] = redirect_domain
648 redirects[redirect_domain].append(tmpl_register.substitute(command_map))
649 continue
650
651 command_map["TargetDomain"] = json_domain["domain"]
dgozman 2015/03/18 17:30:11 I'd rather do command_map["TargetDomain"] = comman
vkuzkokov 2015/03/18 17:34:10 Done.
641 prep = [] 652 prep = []
642 args = [] 653 args = []
643 654
644 if "parameters" in json_command: 655 if "parameters" in json_command:
645 for json_param in json_command["parameters"]: 656 for json_param in json_command["parameters"]:
646 param_map = command_map.copy() 657 param_map = command_map.copy()
647 param_map["proto_param"] = json_param["name"] 658 param_map["proto_param"] = json_param["name"]
648 param_map["param"] = Uncamelcase(json_param["name"]) 659 param_map["param"] = Uncamelcase(json_param["name"])
649 ResolveType(json_param, param_map) 660 ResolveType(json_param, param_map)
650 if json_param.get("optional"): 661 if json_param.get("optional"):
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 setters.append(tmpl_setter.substitute(domain_map)) 739 setters.append(tmpl_setter.substitute(domain_map))
729 fields.append(tmpl_field.substitute(domain_map)) 740 fields.append(tmpl_field.substitute(domain_map))
730 includes.append(tmpl_include.substitute(domain_map)) 741 includes.append(tmpl_include.substitute(domain_map))
731 fields_init.append(tmpl_field_init.substitute(domain_map)) 742 fields_init.append(tmpl_field_init.substitute(domain_map))
732 if domain_needs_client: 743 if domain_needs_client:
733 type_decls.append(tmpl_client.substitute(domain_map, 744 type_decls.append(tmpl_client.substitute(domain_map,
734 methods = "".join(client_methods))) 745 methods = "".join(client_methods)))
735 initializations.append(tmpl_init_client.substitute(domain_map)) 746 initializations.append(tmpl_init_client.substitute(domain_map))
736 type_impls.append(tmpl_client_impl.substitute(domain_map, 747 type_impls.append(tmpl_client_impl.substitute(domain_map,
737 methods = "\n".join(client_method_impls))) 748 methods = "\n".join(client_method_impls)))
738 handler_method_impls.append(tmpl_setter_impl.substitute(domain_map, 749 domain_map["initializations"] = "".join(initializations)
739 initializations = "".join(initializations))) 750 domain_maps.append(domain_map)
740 751
752 for domain_map in domain_maps:
753 domain = domain_map["Domain"]
754 if domain in redirects:
755 domain_map["initializations"] += "".join(redirects[domain])
756 handler_method_impls.append(tmpl_setter_impl.substitute(domain_map))
741 757
742 output_h_file = open(output_h_path, "w") 758 output_h_file = open(output_h_path, "w")
743 output_cc_file = open(output_cc_path, "w") 759 output_cc_file = open(output_cc_path, "w")
744 760
745 output_h_file.write(template_h.substitute({}, 761 output_h_file.write(template_h.substitute({},
746 types = "\n".join(type_decls), 762 types = "\n".join(type_decls),
747 setters = "".join(setters), 763 setters = "".join(setters),
748 methods = "".join(handler_methods), 764 methods = "".join(handler_methods),
749 fields = "".join(fields))) 765 fields = "".join(fields)))
750 output_h_file.close() 766 output_h_file.close()
751 767
752 output_cc_file.write(template_cc.substitute({}, 768 output_cc_file.write(template_cc.substitute({},
753 major = blink_protocol["version"]["major"], 769 major = blink_protocol["version"]["major"],
754 minor = blink_protocol["version"]["minor"], 770 minor = blink_protocol["version"]["minor"],
755 includes = "".join(sorted(includes)), 771 includes = "".join(sorted(includes)),
756 fields_init = ",\n ".join(fields_init), 772 fields_init = ",\n ".join(fields_init),
757 methods = "\n".join(handler_method_impls), 773 methods = "\n".join(handler_method_impls),
758 types = "\n".join(type_impls))) 774 types = "\n".join(type_impls)))
759 output_cc_file.close() 775 output_cc_file.close()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698