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