summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py')
-rwxr-xr-xchromium/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py81
1 files changed, 53 insertions, 28 deletions
diff --git a/chromium/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py b/chromium/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py
index 02dec7b9d9d..c175403925f 100755
--- a/chromium/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py
+++ b/chromium/third_party/WebKit/Source/devtools/scripts/generate_protocol_externs.py
@@ -92,6 +92,8 @@ def generate_protocol_externs(output_path, input_path):
output_file.write(
"""
+var InspectorBackend = {}
+
var Protocol = {};
/** @typedef {string}*/
Protocol.Error;
@@ -106,32 +108,9 @@ Protocol.Error;
for domain in json_api:
domain_name = domain["domain"]
- output_file.write("\n\n\nvar %sAgent = {};\n" % domain_name)
- if "types" in domain:
- for type in domain["types"]:
- if type["type"] == "object":
- typedef_args = []
- if "properties" in type:
- for property in type["properties"]:
- suffix = ""
- if ("optional" in property):
- suffix = "|undefined"
- if "enum" in property:
- enum_name = "%sAgent.%s%s" % (domain_name, type["id"], to_title_case(property["name"]))
- output_file.write(generate_enum(enum_name, property))
- typedef_args.append("%s:(%s%s)" % (property["name"], enum_name, suffix))
- else:
- typedef_args.append("%s:(%s%s)" % (property["name"], param_type(domain_name, property), suffix))
- if (typedef_args):
- output_file.write("\n/** @typedef {!{%s}} */\n%sAgent.%s;\n" % (", ".join(typedef_args), domain_name, type["id"]))
- else:
- output_file.write("\n/** @typedef {!Object} */\n%sAgent.%s;\n" % (domain_name, type["id"]))
- elif type["type"] == "string" and "enum" in type:
- output_file.write(generate_enum("%sAgent.%s" % (domain_name, type["id"]), type))
- elif type["type"] == "array":
- output_file.write("\n/** @typedef {!Array.<!%s>} */\n%sAgent.%s;\n" % (param_type(domain_name, type["items"]), domain_name, type["id"]))
- else:
- output_file.write("\n/** @typedef {%s} */\n%sAgent.%s;\n" % (type_traits[type["type"]], domain_name, type["id"]))
+
+ output_file.write("\n\n/**\n * @constructor\n*/\n")
+ output_file.write("Protocol.%sAgent = function(){};\n" % domain_name)
if "commands" in domain:
for command in domain["commands"]:
@@ -157,9 +136,37 @@ Protocol.Error;
output_file.write(" * @param {function(%s):void=} opt_callback\n" % ", ".join(returns))
output_file.write(" */\n")
params.append("opt_callback")
- output_file.write("%sAgent.%s = function(%s) {}\n" % (domain_name, command["name"], ", ".join(params)))
+ output_file.write("Protocol.%sAgent.prototype.%s = function(%s) {}\n" % (domain_name, command["name"], ", ".join(params)))
output_file.write("/** @param {function(%s):void=} opt_callback */\n" % ", ".join(returns))
- output_file.write("%sAgent.%s.invoke = function(obj, opt_callback) {}\n" % (domain_name, command["name"]))
+ output_file.write("Protocol.%sAgent.prototype.invoke_%s = function(obj, opt_callback) {}\n" % (domain_name, command["name"]))
+
+ output_file.write("\n\n\nvar %sAgent = new Protocol.%sAgent();\n" % (domain_name, domain_name))
+
+ if "types" in domain:
+ for type in domain["types"]:
+ if type["type"] == "object":
+ typedef_args = []
+ if "properties" in type:
+ for property in type["properties"]:
+ suffix = ""
+ if ("optional" in property):
+ suffix = "|undefined"
+ if "enum" in property:
+ enum_name = "%sAgent.%s%s" % (domain_name, type["id"], to_title_case(property["name"]))
+ output_file.write(generate_enum(enum_name, property))
+ typedef_args.append("%s:(%s%s)" % (property["name"], enum_name, suffix))
+ else:
+ typedef_args.append("%s:(%s%s)" % (property["name"], param_type(domain_name, property), suffix))
+ if (typedef_args):
+ output_file.write("\n/** @typedef {!{%s}} */\n%sAgent.%s;\n" % (", ".join(typedef_args), domain_name, type["id"]))
+ else:
+ output_file.write("\n/** @typedef {!Object} */\n%sAgent.%s;\n" % (domain_name, type["id"]))
+ elif type["type"] == "string" and "enum" in type:
+ output_file.write(generate_enum("%sAgent.%s" % (domain_name, type["id"]), type))
+ elif type["type"] == "array":
+ output_file.write("\n/** @typedef {!Array.<!%s>} */\n%sAgent.%s;\n" % (param_type(domain_name, type["items"]), domain_name, type["id"]))
+ else:
+ output_file.write("\n/** @typedef {%s} */\n%sAgent.%s;\n" % (type_traits[type["type"]], domain_name, type["id"]))
output_file.write("/** @interface */\n")
output_file.write("%sAgent.Dispatcher = function() {};\n" % domain_name)
@@ -179,6 +186,24 @@ Protocol.Error;
output_file.write("%sAgent.Dispatcher.prototype.%s = function(%s) {};\n" % (domain_name, event["name"], ", ".join(params)))
output_file.write("/**\n * @param {%sAgent.Dispatcher} dispatcher\n */\n" % domain_name)
output_file.write("InspectorBackend.register%sDispatcher = function(dispatcher) {}\n" % domain_name)
+
+ output_file.write("\n/** @constructor\n * @param {!Object.<string, !Object>} agentsMap\n */\n")
+ output_file.write("Protocol.Agents = function(agentsMap){this._agentsMap;};\n")
+ output_file.write("/**\n * @param {string} domain\n * @param {!Object} dispatcher\n */\n")
+ output_file.write("Protocol.Agents.prototype.registerDispatcher = function(domain, dispatcher){};\n")
+ for domain in json_api:
+ domain_name = domain["domain"]
+ uppercase_length = 0
+ while uppercase_length < len(domain_name) and domain_name[uppercase_length].isupper():
+ uppercase_length += 1
+
+ output_file.write("/** @return {!Protocol.%sAgent}*/\n" % domain_name)
+ output_file.write("Protocol.Agents.prototype.%s = function(){};\n" % (domain_name[:uppercase_length].lower() + domain_name[uppercase_length:] + "Agent"))
+
+ output_file.write("/**\n * @param {!%sAgent.Dispatcher} dispatcher\n */\n" % domain_name)
+ output_file.write("Protocol.Agents.prototype.register%sDispatcher = function(dispatcher) {}\n" % domain_name)
+
+
output_file.close()
if __name__ == "__main__":