| 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 browser_domains_list = ["Inspector", "Memory", "Page", "Emulation", "Security", |
| 647 "IO", "Target", "ServiceWorker", "Input", "Tracing", "Storage", |
| 648 "SystemInfo", "Tethering", "Schema"] |
| 649 browser_commands_list = [ |
| 650 "DOM.setFileInputFiles", |
| 651 "Network.enable", |
| 652 "Network.disable", |
| 653 "Network.clearBrowserCache", |
| 654 "Network.clearBrowserCookies", |
| 655 "Network.getCookies", |
| 656 "Network.deleteCookie", |
| 657 "Network.setCookie", |
| 658 "Network.canEmulateNetworkConditions", |
| 659 "Network.emulateNetworkConditions"] |
| 660 |
| 643 for json_domain in all_domains: | 661 for json_domain in all_domains: |
| 644 domain_map = {} | 662 domain_map = {} |
| 645 domain_map["Domain"] = json_domain["domain"] | 663 domain_map["Domain"] = json_domain["domain"] |
| 646 domain_map["domain"] = Uncamelcase(json_domain["domain"]) | 664 domain_map["domain"] = Uncamelcase(json_domain["domain"]) |
| 647 | 665 |
| 648 initializations = [] | 666 initializations = [] |
| 649 client_methods = [] | 667 client_methods = [] |
| 650 client_method_impls = [] | 668 client_method_impls = [] |
| 651 domain_empty = True | 669 domain_empty = True |
| 652 domain_needs_client = False | 670 domain_needs_client = False |
| 653 | 671 |
| 654 if "commands" in json_domain: | 672 if "commands" in json_domain: |
| 655 for json_command in json_domain["commands"]: | 673 for json_command in json_domain["commands"]: |
| 656 if (not ("handlers" in json_command) or | 674 full_command_name = json_domain["domain"] + "." + json_command["name"] |
| 657 not ("browser" in json_command["handlers"])): | 675 if (json_domain["domain"] not in browser_domains_list and |
| 676 full_command_name not in browser_commands_list): |
| 658 continue | 677 continue |
| 659 domain_empty = False | 678 domain_empty = False |
| 660 | 679 |
| 661 command_map = domain_map.copy() | 680 command_map = domain_map.copy() |
| 662 command_map["command"] = json_command["name"] | 681 command_map["command"] = json_command["name"] |
| 663 command_map["Command"] = Capitalize(json_command["name"]) | 682 command_map["Command"] = Capitalize(json_command["name"]) |
| 664 | 683 |
| 665 if "redirect" in json_command: | 684 if "redirect" in json_command: |
| 666 redirect_domain = json_command["redirect"] | 685 redirect_domain = json_command["redirect"] |
| 667 if not (redirect_domain in redirects): | 686 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))) | 736 args = "\n " + ",\n ".join(args))) |
| 718 client_methods.append(tmpl_response.substitute(command_map)) | 737 client_methods.append(tmpl_response.substitute(command_map)) |
| 719 client_method_impls.append(tmpl_response_impl.substitute(command_map)) | 738 client_method_impls.append(tmpl_response_impl.substitute(command_map)) |
| 720 else: | 739 else: |
| 721 wrap = [] | 740 wrap = [] |
| 722 if "returns" in json_command: | 741 if "returns" in json_command: |
| 723 for json_param in json_command["returns"]: | 742 for json_param in json_command["returns"]: |
| 724 param_map = command_map.copy() | 743 param_map = command_map.copy() |
| 725 param_map["proto_param"] = json_param["name"] | 744 param_map["proto_param"] = json_param["name"] |
| 726 param_map["param"] = Uncamelcase(json_param["name"]) | 745 param_map["param"] = Uncamelcase(json_param["name"]) |
| 727 if json_param.get("optional"): | 746 is_string = "type" in json_param and json_param["type"] == "string" |
| 747 if json_param.get("optional") and not is_string: |
| 728 # TODO(vkuzkokov) Implement Optional<T> for value types. | 748 # TODO(vkuzkokov) Implement Optional<T> for value types. |
| 729 raise Exception("Optional return values are not implemented") | 749 raise Exception( |
| 750 "Optional return values are not implemented (%s.%s.%s)" % |
| 751 (param_map["Domain"], param_map["command"], |
| 752 param_map["proto_param"])) |
| 730 ResolveType(json_param, param_map) | 753 ResolveType(json_param, param_map) |
| 731 prep.append(tmpl_prep_output.substitute(param_map)) | 754 prep.append(tmpl_prep_output.substitute(param_map)) |
| 732 args.append(param_map["arg_out"]) | 755 args.append(param_map["arg_out"]) |
| 733 wrap.append(tmpl_wrap.substitute(param_map)) | 756 wrap.append(tmpl_wrap.substitute(param_map)) |
| 734 args_str = "" | 757 args_str = "" |
| 735 if len(args) > 0: | 758 if len(args) > 0: |
| 736 args_str = "\n " + ",\n ".join(args) | 759 args_str = "\n " + ",\n ".join(args) |
| 737 handler_method_impls.append(tmpl_callback_impl.substitute(command_map, | 760 handler_method_impls.append(tmpl_callback_impl.substitute(command_map, |
| 738 prep = "".join(prep), | 761 prep = "".join(prep), |
| 739 args = args_str, | 762 args = args_str, |
| 740 wrap = "".join(wrap))) | 763 wrap = "".join(wrap))) |
| 741 | 764 |
| 742 initializations.append(tmpl_register.substitute(command_map)) | 765 initializations.append(tmpl_register.substitute(command_map)) |
| 743 handler_methods.append(tmpl_callback.substitute(command_map)) | 766 handler_methods.append(tmpl_callback.substitute(command_map)) |
| 744 | 767 |
| 745 if "events" in json_domain: | 768 if "events" in json_domain: |
| 746 for json_event in json_domain["events"]: | 769 for json_event in json_domain["events"]: |
| 747 if (not ("handlers" in json_event) or | 770 if json_domain["domain"] not in browser_domains_list: |
| 748 not ("browser" in json_event["handlers"])): | |
| 749 continue | 771 continue |
| 750 domain_empty = False | 772 domain_empty = False |
| 751 domain_needs_client = True | 773 domain_needs_client = True |
| 752 | 774 |
| 753 event_map = domain_map.copy() | 775 event_map = domain_map.copy() |
| 754 event_map["command"] = json_event["name"] | 776 event_map["command"] = json_event["name"] |
| 755 event_map["Command"] = Capitalize(json_event["name"]) | 777 event_map["Command"] = Capitalize(json_event["name"]) |
| 756 | 778 |
| 757 json_parameters = [] | 779 json_parameters = [] |
| 758 if "parameters" in json_event: | 780 if "parameters" in json_event: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 output_h_file.close() | 818 output_h_file.close() |
| 797 | 819 |
| 798 output_cc_file.write(template_cc.substitute({}, | 820 output_cc_file.write(template_cc.substitute({}, |
| 799 major = blink_protocol["version"]["major"], | 821 major = blink_protocol["version"]["major"], |
| 800 minor = blink_protocol["version"]["minor"], | 822 minor = blink_protocol["version"]["minor"], |
| 801 includes = "".join(sorted(includes)), | 823 includes = "".join(sorted(includes)), |
| 802 fields_init = ",\n ".join(fields_init), | 824 fields_init = ",\n ".join(fields_init), |
| 803 methods = "\n".join(handler_method_impls), | 825 methods = "\n".join(handler_method_impls), |
| 804 types = "\n".join(type_impls))) | 826 types = "\n".join(type_impls))) |
| 805 output_cc_file.close() | 827 output_cc_file.close() |
| OLD | NEW |