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

Side by Side Diff: third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py

Issue 2450973002: [DevTools] Inherit WI.Target from Protocol.Target. (Closed)
Patch Set: Created 4 years, 1 month 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 | « third_party/WebKit/Source/devtools/scripts/compile_frontend.py ('k') | 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 (c) 2011 Google Inc. All rights reserved. 2 # Copyright (c) 2011 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 "array": "!Array.<*>", 43 "array": "!Array.<*>",
44 "object": "!Object", 44 "object": "!Object",
45 } 45 }
46 46
47 promisified_domains = { 47 promisified_domains = {
48 "Accessibility", 48 "Accessibility",
49 "Animation", 49 "Animation",
50 "Browser", 50 "Browser",
51 "CSS", 51 "CSS",
52 "Emulation", 52 "Emulation",
53 "HeapProfiler",
53 "Profiler", 54 "Profiler",
54 "LayerTree" 55 "LayerTree"
55 } 56 }
56 57
57 ref_types = {} 58 ref_types = {}
58 59
59 def full_qualified_type_id(domain_name, type_id): 60 def full_qualified_type_id(domain_name, type_id):
60 if type_id.find(".") == -1: 61 if type_id.find(".") == -1:
61 return "%s.%s" % (domain_name, type_id) 62 return "%s.%s" % (domain_name, type_id)
62 return type_id 63 return type_id
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 parsed_json = json.loads(json_string) 106 parsed_json = json.loads(json_string)
106 domains.extend(parsed_json["domains"]) 107 domains.extend(parsed_json["domains"])
107 108
108 109
109 def generate_protocol_externs(output_path, file1, file2): 110 def generate_protocol_externs(output_path, file1, file2):
110 domains = [] 111 domains = []
111 load_schema(file1, domains) 112 load_schema(file1, domains)
112 load_schema(file2, domains) 113 load_schema(file2, domains)
113 output_file = open(output_path, "w") 114 output_file = open(output_path, "w")
114 115
115 output_file.write(
116 """
117 var InspectorBackend = {}
118
119 var Protocol = {};
120 /** @typedef {string}*/
121 Protocol.Error;
122 """)
123
124 for domain in domains: 116 for domain in domains:
125 domain_name = domain["domain"] 117 domain_name = domain["domain"]
126 if "types" in domain: 118 if "types" in domain:
127 for type in domain["types"]: 119 for type in domain["types"]:
128 type_id = full_qualified_type_id(domain_name, type["id"]) 120 type_id = full_qualified_type_id(domain_name, type["id"])
129 ref_types[type_id] = "%sAgent.%s" % (domain_name, type["id"]) 121 ref_types[type_id] = "%sAgent.%s" % (domain_name, type["id"])
130 122
131 for domain in domains: 123 for domain in domains:
132 domain_name = domain["domain"] 124 domain_name = domain["domain"]
133 promisified = domain_name in promisified_domains 125 promisified = domain_name in promisified_domains
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 for param in event["parameters"]: 211 for param in event["parameters"]:
220 if ("optional" in param): 212 if ("optional" in param):
221 params.append("opt_%s" % param["name"]) 213 params.append("opt_%s" % param["name"])
222 output_file.write(" * @param {%s=} opt_%s\n" % (para m_type(domain_name, param), param["name"])) 214 output_file.write(" * @param {%s=} opt_%s\n" % (para m_type(domain_name, param), param["name"]))
223 else: 215 else:
224 params.append(param["name"]) 216 params.append(param["name"])
225 output_file.write(" * @param {%s} %s\n" % (param_typ e(domain_name, param), param["name"])) 217 output_file.write(" * @param {%s} %s\n" % (param_typ e(domain_name, param), param["name"]))
226 output_file.write(" */\n") 218 output_file.write(" */\n")
227 output_file.write("%sAgent.Dispatcher.prototype.%s = function(%s ) {};\n" % (domain_name, event["name"], ", ".join(params))) 219 output_file.write("%sAgent.Dispatcher.prototype.%s = function(%s ) {};\n" % (domain_name, event["name"], ", ".join(params)))
228 220
229 output_file.write("\n/** @constructor\n * @param {!Object.<string, !Object>} agentsMap\n */\n")
230 output_file.write("Protocol.Agents = function(agentsMap){this._agentsMap;};\ n")
231 output_file.write("/**\n * @param {string} domain\n * @param {!Object} dispa tcher\n */\n")
232 output_file.write("Protocol.Agents.prototype.registerDispatcher = function(d omain, dispatcher){};\n")
233 for domain in domains: 221 for domain in domains:
234 domain_name = domain["domain"] 222 domain_name = domain["domain"]
235 uppercase_length = 0 223 uppercase_length = 0
236 while uppercase_length < len(domain_name) and domain_name[uppercase_leng th].isupper(): 224 while uppercase_length < len(domain_name) and domain_name[uppercase_leng th].isupper():
237 uppercase_length += 1 225 uppercase_length += 1
238 226
239 output_file.write("/** @return {!Protocol.%sAgent}*/\n" % domain_name) 227 output_file.write("/** @return {!Protocol.%sAgent}*/\n" % domain_name)
240 output_file.write("Protocol.Agents.prototype.%s = function(){};\n" % (do main_name[:uppercase_length].lower() + domain_name[uppercase_length:] + "Agent") ) 228 output_file.write("Protocol.Target.prototype.%s = function(){};\n" % (do main_name[:uppercase_length].lower() + domain_name[uppercase_length:] + "Agent") )
241 229
242 output_file.write("/**\n * @param {!%sAgent.Dispatcher} dispatcher\n */\ n" % domain_name) 230 output_file.write("/**\n * @param {!%sAgent.Dispatcher} dispatcher\n */\ n" % domain_name)
243 output_file.write("Protocol.Agents.prototype.register%sDispatcher = func tion(dispatcher) {}\n" % domain_name) 231 output_file.write("Protocol.Target.prototype.register%sDispatcher = func tion(dispatcher) {}\n" % domain_name)
244 232
245 233
246 output_file.close() 234 output_file.close()
247 235
248 if __name__ == "__main__": 236 if __name__ == "__main__":
249 import sys 237 import sys
250 import os.path 238 import os.path
251 program_name = os.path.basename(__file__) 239 program_name = os.path.basename(__file__)
252 if len(sys.argv) < 5 or sys.argv[1] != "-o": 240 if len(sys.argv) < 5 or sys.argv[1] != "-o":
253 sys.stderr.write("Usage: %s -o OUTPUT_FILE INPUT_FILE_1 INPUT_FILE_2\n" % program_name) 241 sys.stderr.write("Usage: %s -o OUTPUT_FILE INPUT_FILE_1 INPUT_FILE_2\n" % program_name)
254 exit(1) 242 exit(1)
255 output_path = sys.argv[2] 243 output_path = sys.argv[2]
256 input_path_1 = sys.argv[3] 244 input_path_1 = sys.argv[3]
257 input_path_2 = sys.argv[4] 245 input_path_2 = sys.argv[4]
258 generate_protocol_externs(output_path, input_path_1, input_path_2) 246 generate_protocol_externs(output_path, input_path_1, input_path_2)
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/scripts/compile_frontend.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698