Chromium Code Reviews| 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 blink_protocol_path = sys.argv[1] | 10 blink_protocol_path = sys.argv[1] |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 req_fields_num = 0 | 474 req_fields_num = 0 |
| 475 for json_prop in json_properties: | 475 for json_prop in json_properties: |
| 476 prop_map = mapping.copy() | 476 prop_map = mapping.copy() |
| 477 prop_map["proto_param"] = json_prop["name"] | 477 prop_map["proto_param"] = json_prop["name"] |
| 478 prop_map["param"] = Uncamelcase(json_prop["name"]) | 478 prop_map["param"] = Uncamelcase(json_prop["name"]) |
| 479 prop_map["Param"] = Capitalize(json_prop["name"]) | 479 prop_map["Param"] = Capitalize(json_prop["name"]) |
| 480 prop_map["subdomain"] = Uncamelcase(prop_map["declared_name"]) | 480 prop_map["subdomain"] = Uncamelcase(prop_map["declared_name"]) |
| 481 del prop_map["declared_name"] | 481 del prop_map["declared_name"] |
| 482 ResolveType(json_prop, prop_map) | 482 ResolveType(json_prop, prop_map) |
| 483 prop_map["declared_name"] = mapping["declared_name"] | 483 prop_map["declared_name"] = mapping["declared_name"] |
| 484 if prop_map["pass_type"].find(mapping["declared_name"]) != -1: | |
| 485 prop_map["pass_type"] = prop_map["pass_type"].replace( | |
| 486 mapping["declared_name"], mapping["declared_name"] + "Builder<0>") | |
| 484 if json_prop.get("optional"): | 487 if json_prop.get("optional"): |
| 485 methods.append(tmpl_builder_setter_opt.substitute(prop_map)) | 488 methods.append(tmpl_builder_setter_opt.substitute(prop_map)) |
| 486 else: | 489 else: |
| 487 methods.append(tmpl_builder_setter_req.substitute(prop_map)) | 490 methods.append(tmpl_builder_setter_req.substitute(prop_map)) |
| 488 enum_items.append("k%s" % prop_map["Param"]); | 491 enum_items.append("k%s" % prop_map["Param"]); |
| 489 fields_enum.append(tmpl_builder_enum.substitute(prop_map, | 492 fields_enum.append(tmpl_builder_enum.substitute(prop_map, |
| 490 ordinal = req_fields_num)) | 493 ordinal = req_fields_num)) |
| 491 req_fields_num += 1 | 494 req_fields_num += 1 |
| 492 | 495 |
| 493 all_fields = "kAllSet" | 496 all_fields = "kAllSet" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 else: | 636 else: |
| 634 raise Exception("Unknown type at %s.%s %s" % | 637 raise Exception("Unknown type at %s.%s %s" % |
| 635 (mapping["Domain"], mapping["command"], mapping["proto_param"])) | 638 (mapping["Domain"], mapping["command"], mapping["proto_param"])) |
| 636 | 639 |
| 637 setters = [] | 640 setters = [] |
| 638 fields = [] | 641 fields = [] |
| 639 | 642 |
| 640 includes = [] | 643 includes = [] |
| 641 fields_init = [] | 644 fields_init = [] |
| 642 | 645 |
| 646 domains_list = ["Inspector", "Memory", "Page", "Emulation", "Security", | |
|
caseq
2016/11/04 01:20:40
browser_domains_list?
dgozman
2016/11/04 01:52:27
Done.
| |
| 647 "IO", "Target", "ServiceWorker", "Input", "Tracing", "Storage", | |
| 648 "SystemInfo", "Tethering", "Schema"] | |
| 649 commands_list = ["DOM.setFileInputFiles", "Network.enable", "Network.disable", | |
| 650 "Network.clearBrowserCache", "Network.clearBrowserCookies", | |
| 651 "Network.getCookies", "Network.deleteCookie", "Network.setCookie", | |
| 652 "Network.canEmulateNetworkConditions", "Network.emulateNetworkConditions"] | |
| 653 | |
| 643 for json_domain in all_domains: | 654 for json_domain in all_domains: |
| 644 domain_map = {} | 655 domain_map = {} |
| 645 domain_map["Domain"] = json_domain["domain"] | 656 domain_map["Domain"] = json_domain["domain"] |
| 646 domain_map["domain"] = Uncamelcase(json_domain["domain"]) | 657 domain_map["domain"] = Uncamelcase(json_domain["domain"]) |
| 647 | 658 |
| 648 initializations = [] | 659 initializations = [] |
| 649 client_methods = [] | 660 client_methods = [] |
| 650 client_method_impls = [] | 661 client_method_impls = [] |
| 651 domain_empty = True | 662 domain_empty = True |
| 652 domain_needs_client = False | 663 domain_needs_client = False |
| 653 | 664 |
| 654 if "commands" in json_domain: | 665 if "commands" in json_domain: |
| 655 for json_command in json_domain["commands"]: | 666 for json_command in json_domain["commands"]: |
| 656 if (not ("handlers" in json_command) or | 667 full_command_name = json_domain["domain"] + "." + json_command["name"] |
| 657 not ("browser" in json_command["handlers"])): | 668 if (json_domain["domain"] not in domains_list and |
| 669 full_command_name not in commands_list): | |
| 658 continue | 670 continue |
| 659 domain_empty = False | 671 domain_empty = False |
| 660 | 672 |
| 661 command_map = domain_map.copy() | 673 command_map = domain_map.copy() |
| 662 command_map["command"] = json_command["name"] | 674 command_map["command"] = json_command["name"] |
| 663 command_map["Command"] = Capitalize(json_command["name"]) | 675 command_map["Command"] = Capitalize(json_command["name"]) |
| 664 | 676 |
| 665 if "redirect" in json_command: | 677 if "redirect" in json_command: |
| 666 redirect_domain = json_command["redirect"] | 678 redirect_domain = json_command["redirect"] |
| 667 if not (redirect_domain in redirects): | 679 if not (redirect_domain in redirects): |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 args = "\n " + ",\n ".join(args))) | 729 args = "\n " + ",\n ".join(args))) |
| 718 client_methods.append(tmpl_response.substitute(command_map)) | 730 client_methods.append(tmpl_response.substitute(command_map)) |
| 719 client_method_impls.append(tmpl_response_impl.substitute(command_map)) | 731 client_method_impls.append(tmpl_response_impl.substitute(command_map)) |
| 720 else: | 732 else: |
| 721 wrap = [] | 733 wrap = [] |
| 722 if "returns" in json_command: | 734 if "returns" in json_command: |
| 723 for json_param in json_command["returns"]: | 735 for json_param in json_command["returns"]: |
| 724 param_map = command_map.copy() | 736 param_map = command_map.copy() |
| 725 param_map["proto_param"] = json_param["name"] | 737 param_map["proto_param"] = json_param["name"] |
| 726 param_map["param"] = Uncamelcase(json_param["name"]) | 738 param_map["param"] = Uncamelcase(json_param["name"]) |
| 727 if json_param.get("optional"): | 739 is_string = "type" in json_param and json_param["type"] == "string" |
| 740 if json_param.get("optional") and not is_string: | |
| 728 # TODO(vkuzkokov) Implement Optional<T> for value types. | 741 # TODO(vkuzkokov) Implement Optional<T> for value types. |
| 729 raise Exception("Optional return values are not implemented") | 742 raise Exception( |
| 743 "Optional return values are not implemented (%s.%s.%s)" % | |
| 744 (param_map["Domain"], param_map["command"], | |
| 745 param_map["proto_param"])) | |
| 730 ResolveType(json_param, param_map) | 746 ResolveType(json_param, param_map) |
| 731 prep.append(tmpl_prep_output.substitute(param_map)) | 747 prep.append(tmpl_prep_output.substitute(param_map)) |
| 732 args.append(param_map["arg_out"]) | 748 args.append(param_map["arg_out"]) |
| 733 wrap.append(tmpl_wrap.substitute(param_map)) | 749 wrap.append(tmpl_wrap.substitute(param_map)) |
| 734 args_str = "" | 750 args_str = "" |
| 735 if len(args) > 0: | 751 if len(args) > 0: |
| 736 args_str = "\n " + ",\n ".join(args) | 752 args_str = "\n " + ",\n ".join(args) |
| 737 handler_method_impls.append(tmpl_callback_impl.substitute(command_map, | 753 handler_method_impls.append(tmpl_callback_impl.substitute(command_map, |
| 738 prep = "".join(prep), | 754 prep = "".join(prep), |
| 739 args = args_str, | 755 args = args_str, |
| 740 wrap = "".join(wrap))) | 756 wrap = "".join(wrap))) |
| 741 | 757 |
| 742 initializations.append(tmpl_register.substitute(command_map)) | 758 initializations.append(tmpl_register.substitute(command_map)) |
| 743 handler_methods.append(tmpl_callback.substitute(command_map)) | 759 handler_methods.append(tmpl_callback.substitute(command_map)) |
| 744 | 760 |
| 745 if "events" in json_domain: | 761 if "events" in json_domain: |
| 746 for json_event in json_domain["events"]: | 762 for json_event in json_domain["events"]: |
| 747 if (not ("handlers" in json_event) or | 763 if json_domain["domain"] not in domains_list: |
| 748 not ("browser" in json_event["handlers"])): | |
| 749 continue | 764 continue |
| 750 domain_empty = False | 765 domain_empty = False |
| 751 domain_needs_client = True | 766 domain_needs_client = True |
| 752 | 767 |
| 753 event_map = domain_map.copy() | 768 event_map = domain_map.copy() |
| 754 event_map["command"] = json_event["name"] | 769 event_map["command"] = json_event["name"] |
| 755 event_map["Command"] = Capitalize(json_event["name"]) | 770 event_map["Command"] = Capitalize(json_event["name"]) |
| 756 | 771 |
| 757 json_parameters = [] | 772 json_parameters = [] |
| 758 if "parameters" in json_event: | 773 if "parameters" in json_event: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 output_h_file.close() | 811 output_h_file.close() |
| 797 | 812 |
| 798 output_cc_file.write(template_cc.substitute({}, | 813 output_cc_file.write(template_cc.substitute({}, |
| 799 major = blink_protocol["version"]["major"], | 814 major = blink_protocol["version"]["major"], |
| 800 minor = blink_protocol["version"]["minor"], | 815 minor = blink_protocol["version"]["minor"], |
| 801 includes = "".join(sorted(includes)), | 816 includes = "".join(sorted(includes)), |
| 802 fields_init = ",\n ".join(fields_init), | 817 fields_init = ",\n ".join(fields_init), |
| 803 methods = "\n".join(handler_method_impls), | 818 methods = "\n".join(handler_method_impls), |
| 804 types = "\n".join(type_impls))) | 819 types = "\n".join(type_impls))) |
| 805 output_cc_file.close() | 820 output_cc_file.close() |
| OLD | NEW |