OLD | NEW |
---|---|
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 input_json_path = sys.argv[1] | 10 blink_protocol_path = sys.argv[1] |
11 output_cc_path = sys.argv[2] | 11 browser_protocol_path = sys.argv[2] |
12 output_h_path = sys.argv[3] | 12 output_cc_path = sys.argv[3] |
13 output_h_path = sys.argv[4] | |
13 | 14 |
14 header = """\ | 15 header = """\ |
15 // Copyright 2014 The Chromium Authors. All rights reserved. | 16 // Copyright 2014 The Chromium Authors. All rights reserved. |
16 // Use of this source code is governed by a BSD-style license that can be | 17 // Use of this source code is governed by a BSD-style license that can be |
17 // found in the LICENSE file. | 18 // found in the LICENSE file. |
18 | 19 |
19 // THIS FILE IS AUTOGENERATED. DO NOT EDIT. | 20 // THIS FILE IS AUTOGENERATED. DO NOT EDIT. |
20 // Generated by | 21 // Generated by |
21 // content/public/browser/devtools_protocol_handler_generator.py from | 22 // content/public/browser/devtools_protocol_handler_generator.py from |
22 // third_party/WebKit/Source/devtools/protocol.json | 23 // third_party/WebKit/Source/devtools/protocol.json |
dgozman
2014/11/11 10:38:46
nit: list browser protocol here.
vkuzkokov
2014/11/11 11:06:00
Done.
| |
23 """ | 24 """ |
24 | 25 |
25 template_h = string.Template(header + """\ | 26 template_h = string.Template(header + """\ |
26 | 27 |
27 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_HANDLER_IMPL_H_ | 28 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_HANDLER_IMPL_H_ |
28 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_HANDLER_IMPL_H_ | 29 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_HANDLER_IMPL_H_ |
29 | 30 |
30 #include "content/browser/devtools/devtools_protocol.h" | 31 #include "content/browser/devtools/devtools_protocol.h" |
31 #include "content/browser/devtools/protocol/devtools_protocol_client.h" | 32 #include "content/browser/devtools/protocol/devtools_protocol_client.h" |
32 | 33 |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 for i, c in enumerate(s): | 421 for i, c in enumerate(s): |
421 if c.isupper(): | 422 if c.isupper(): |
422 if (i > 0) and ((i < len(s)-1) and s[i+1].islower() or s[i-1].islower()): | 423 if (i > 0) and ((i < len(s)-1) and s[i+1].islower() or s[i-1].islower()): |
423 result += "_" | 424 result += "_" |
424 result += c.lower() | 425 result += c.lower() |
425 else: | 426 else: |
426 result += c | 427 result += c |
427 return result | 428 return result |
428 | 429 |
429 types = {} | 430 types = {} |
430 json_api = json.loads(open(input_json_path, "r").read()) | 431 blink_protocol = json.loads(open(blink_protocol_path, "r").read()) |
432 browser_protocol = json.loads(open(browser_protocol_path, "r").read()) | |
431 type_decls = [] | 433 type_decls = [] |
432 type_impls = [] | 434 type_impls = [] |
433 handler_methods = [] | 435 handler_methods = [] |
434 handler_method_impls = [] | 436 handler_method_impls = [] |
435 | 437 |
436 for json_domain in json_api["domains"]: | 438 all_domains = blink_protocol["domains"] + browser_protocol["domains"] |
439 | |
440 for json_domain in all_domains: | |
437 if "types" in json_domain: | 441 if "types" in json_domain: |
438 for json_type in json_domain["types"]: | 442 for json_type in json_domain["types"]: |
439 types["%s.%s" % (json_domain["domain"], json_type["id"])] = json_type | 443 types["%s.%s" % (json_domain["domain"], json_type["id"])] = json_type |
440 | 444 |
441 def DeclareStruct(json_properties, mapping): | 445 def DeclareStruct(json_properties, mapping): |
442 methods = [] | 446 methods = [] |
443 fields_enum = [] | 447 fields_enum = [] |
444 enum_items = [] | 448 enum_items = [] |
445 req_fields_num = 0 | 449 req_fields_num = 0 |
446 for json_prop in json_properties: | 450 for json_prop in json_properties: |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 else: | 586 else: |
583 raise Exception("Unknown type at %s.%s %s" % | 587 raise Exception("Unknown type at %s.%s %s" % |
584 (mapping["Domain"], mapping["command"], mapping["proto_param"])) | 588 (mapping["Domain"], mapping["command"], mapping["proto_param"])) |
585 | 589 |
586 setters = [] | 590 setters = [] |
587 fields = [] | 591 fields = [] |
588 | 592 |
589 includes = [] | 593 includes = [] |
590 fields_init = [] | 594 fields_init = [] |
591 | 595 |
592 for json_domain in json_api["domains"]: | 596 for json_domain in all_domains: |
593 domain_map = {} | 597 domain_map = {} |
594 domain_map["Domain"] = json_domain["domain"] | 598 domain_map["Domain"] = json_domain["domain"] |
595 domain_map["domain"] = Uncamelcase(json_domain["domain"]) | 599 domain_map["domain"] = Uncamelcase(json_domain["domain"]) |
596 | 600 |
597 initializations = [] | 601 initializations = [] |
598 client_methods = [] | 602 client_methods = [] |
599 client_method_impls = [] | 603 client_method_impls = [] |
600 domain_empty = True | 604 domain_empty = True |
601 domain_needs_client = False | 605 domain_needs_client = False |
602 | 606 |
603 if "commands" in json_domain: | 607 if "commands" in json_domain: |
604 for json_command in json_domain["commands"]: | 608 for json_command in json_domain["commands"]: |
605 if (not ("handlers" in json_command) or | 609 if (not ("handlers" in json_command) or |
606 not ("browser" in json_command["handlers"])): | 610 not ("browser" in json_command["handlers"])): |
607 continue | 611 continue |
608 domain_empty = False | 612 domain_empty = False |
609 | 613 |
610 command_map = domain_map.copy() | 614 command_map = domain_map.copy() |
611 command_map["command"] = json_command["name"] | 615 command_map["command"] = json_command["name"] |
612 command_map["Command"] = Capitalize(json_command["name"]) | 616 command_map["Command"] = Capitalize(json_command["name"]) |
613 | 617 |
614 prep = [] | 618 prep = [] |
615 args = [] | 619 args = [] |
616 | 620 |
617 if "parameters" in json_command: | 621 if "parameters" in json_command: |
618 for json_param in json_command["parameters"]: | 622 for json_param in json_command["parameters"]: |
619 param_map = command_map.copy() | 623 param_map = command_map.copy() |
620 param_map["proto_param"] = json_param["name"] | 624 param_map["proto_param"] = json_param["name"] |
621 param_map["param"] = Uncamelcase(json_param["name"]) | 625 param_map["param"] = Uncamelcase(json_param["name"]) |
622 | |
623 ResolveType(json_param, param_map) | 626 ResolveType(json_param, param_map) |
624 if len(prep) == 0: | 627 if len(prep) == 0: |
625 prep.append(params_prep) | 628 prep.append(params_prep) |
626 if json_param.get("optional"): | 629 if json_param.get("optional"): |
627 if param_map["Type"] in ["List", "Dictionary"]: | 630 if param_map["Type"] in ["List", "Dictionary"]: |
628 # TODO(vkuzkokov) Implement transformation of base::ListValue | 631 # TODO(vkuzkokov) Implement transformation of base::ListValue |
629 # to std::vector and base::DictonaryValue to struct. | 632 # to std::vector and base::DictonaryValue to struct. |
630 raise Exception( | 633 raise Exception( |
631 "Optional array and object parameters are not implemented") | 634 "Optional array and object parameters are not implemented") |
632 prep.append(tmpl_prep_opt.substitute(param_map)) | 635 prep.append(tmpl_prep_opt.substitute(param_map)) |
(...skipping 19 matching lines...) Expand all Loading... | |
652 args = "\n " + ",\n ".join(args))) | 655 args = "\n " + ",\n ".join(args))) |
653 client_methods.append(tmpl_response.substitute(command_map)) | 656 client_methods.append(tmpl_response.substitute(command_map)) |
654 client_method_impls.append(tmpl_response_impl.substitute(command_map)) | 657 client_method_impls.append(tmpl_response_impl.substitute(command_map)) |
655 else: | 658 else: |
656 wrap = [] | 659 wrap = [] |
657 if "returns" in json_command: | 660 if "returns" in json_command: |
658 for json_param in json_command["returns"]: | 661 for json_param in json_command["returns"]: |
659 param_map = command_map.copy() | 662 param_map = command_map.copy() |
660 param_map["proto_param"] = json_param["name"] | 663 param_map["proto_param"] = json_param["name"] |
661 param_map["param"] = Uncamelcase(json_param["name"]) | 664 param_map["param"] = Uncamelcase(json_param["name"]) |
662 | |
663 if json_param.get("optional"): | 665 if json_param.get("optional"): |
664 # TODO(vkuzkokov) Implement Optional<T> for value types. | 666 # TODO(vkuzkokov) Implement Optional<T> for value types. |
665 raise Exception("Optional return values are not implemented") | 667 raise Exception("Optional return values are not implemented") |
666 ResolveType(json_param, param_map) | 668 ResolveType(json_param, param_map) |
667 prep.append(tmpl_prep_output.substitute(param_map)) | 669 prep.append(tmpl_prep_output.substitute(param_map)) |
668 args.append(param_map["arg_out"]) | 670 args.append(param_map["arg_out"]) |
669 wrap.append(tmpl_wrap.substitute(param_map)) | 671 wrap.append(tmpl_wrap.substitute(param_map)) |
670 | |
671 args_str = "" | 672 args_str = "" |
672 if len(args) > 0: | 673 if len(args) > 0: |
673 args_str = "\n " + ",\n ".join(args) | 674 args_str = "\n " + ",\n ".join(args) |
674 handler_method_impls.append(tmpl_callback_impl.substitute(command_map, | 675 handler_method_impls.append(tmpl_callback_impl.substitute(command_map, |
675 prep = "".join(prep), | 676 prep = "".join(prep), |
676 args = args_str, | 677 args = args_str, |
677 wrap = "".join(wrap))) | 678 wrap = "".join(wrap))) |
678 | 679 |
679 initializations.append(tmpl_register.substitute(command_map)) | 680 initializations.append(tmpl_register.substitute(command_map)) |
680 handler_methods.append(tmpl_callback.substitute(command_map)) | 681 handler_methods.append(tmpl_callback.substitute(command_map)) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 methods = "".join(handler_methods), | 727 methods = "".join(handler_methods), |
727 fields = "".join(fields))) | 728 fields = "".join(fields))) |
728 output_h_file.close() | 729 output_h_file.close() |
729 | 730 |
730 output_cc_file.write(template_cc.substitute({}, | 731 output_cc_file.write(template_cc.substitute({}, |
731 includes = "".join(sorted(includes)), | 732 includes = "".join(sorted(includes)), |
732 fields_init = ",\n ".join(fields_init), | 733 fields_init = ",\n ".join(fields_init), |
733 methods = "\n".join(handler_method_impls), | 734 methods = "\n".join(handler_method_impls), |
734 types = "\n".join(type_impls))) | 735 types = "\n".join(type_impls))) |
735 output_cc_file.close() | 736 output_cc_file.close() |
OLD | NEW |