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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/CodeGenerator.py

Issue 1739613002: DevTools: validate protocol input parameters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined a test. Created 4 years, 9 months 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
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os.path 5 import os.path
6 import sys 6 import sys
7 import string 7 import string
8 import optparse 8 import optparse
9 import re 9 import re
10 try: 10 try:
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 json["$ref"] = domain_name + "." + json["$ref"] 97 json["$ref"] = domain_name + "." + json["$ref"]
98 98
99 for domain in json_api["domains"]: 99 for domain in json_api["domains"]:
100 patch_full_qualified_refs_in_domain(domain, domain["domain"]) 100 patch_full_qualified_refs_in_domain(domain, domain["domain"])
101 101
102 102
103 def create_user_type_definition(domain_name, type): 103 def create_user_type_definition(domain_name, type):
104 return { 104 return {
105 "return_type": "PassOwnPtr<protocol::%s::%s>" % (domain_name, type["id"] ), 105 "return_type": "PassOwnPtr<protocol::%s::%s>" % (domain_name, type["id"] ),
106 "pass_type": "PassOwnPtr<protocol::%s::%s>" % (domain_name, type["id"]), 106 "pass_type": "PassOwnPtr<protocol::%s::%s>" % (domain_name, type["id"]),
107 "to_raw_type": "%s.get()",
107 "to_pass_type": "%s.release()", 108 "to_pass_type": "%s.release()",
108 "type": "OwnPtr<protocol::%s::%s>" % (domain_name, type["id"]), 109 "type": "OwnPtr<protocol::%s::%s>" % (domain_name, type["id"]),
109 "raw_type": "protocol::%s::%s" % (domain_name, type["id"]), 110 "raw_type": "protocol::%s::%s" % (domain_name, type["id"]),
110 "create_type": "adoptPtr(new protocol::%s::%s())" % (domain_name, type[" id"]), 111 "raw_pass_type": "protocol::%s::%s*" % (domain_name, type["id"]),
111 "json_getter": "FromValue<protocol::%s::%s>::convert(getObject(%%s))" % (domain_name, type["id"]), 112 "raw_return_type": "protocol::%s::%s*" % (domain_name, type["id"]),
112 "json_type": "TypeObject",
113 } 113 }
114 114
115 115
116 def create_object_type_definition(): 116 def create_object_type_definition():
117 return { 117 return {
118 "return_type": "PassRefPtr<JSONObject>", 118 "return_type": "PassRefPtr<JSONObject>",
119 "pass_type": "PassRefPtr<JSONObject>", 119 "pass_type": "PassRefPtr<JSONObject>",
120 "to_raw_type": "%s",
120 "to_pass_type": "%s.release()", 121 "to_pass_type": "%s.release()",
121 "type": "RefPtr<JSONObject>", 122 "type": "RefPtr<JSONObject>",
122 "raw_type": "RefPtr<JSONObject>", 123 "raw_type": "RefPtr<JSONObject>",
123 "json_getter": "getObject(%s)", 124 "raw_pass_type": "PassRefPtr<JSONObject>",
124 "json_type": "TypeObject", 125 "raw_return_type": "RefPtr<JSONObject>",
125 } 126 }
126 127
127 128
128 def create_any_type_definition(): 129 def create_any_type_definition():
129 return { 130 return {
130 "return_type": "PassRefPtr<JSONValue>", 131 "return_type": "PassRefPtr<JSONValue>",
131 "pass_type": "PassRefPtr<JSONValue>", 132 "pass_type": "PassRefPtr<JSONValue>",
132 "to_pass_type": "%s.release()", 133 "to_pass_type": "%s.release()",
134 "to_raw_type": "%s",
133 "type": "RefPtr<JSONValue>", 135 "type": "RefPtr<JSONValue>",
134 "raw_type": "RefPtr<JSONValue>", 136 "raw_type": "RefPtr<JSONValue>",
135 "json_getter": "getValue(%s)", 137 "raw_pass_type": "PassRefPtr<JSONValue>",
138 "raw_return_type": "RefPtr<JSONValue>",
136 } 139 }
137 140
138 141
139 def create_primitive_type_definition(type): 142 def create_primitive_type_definition(type):
140 if type == "string": 143 if type == "string":
141 return { 144 return {
142 "return_type": "String", 145 "return_type": "String",
143 "pass_type": "const String&", 146 "pass_type": "const String&",
144 "to_pass_type": "%s", 147 "to_pass_type": "%s",
148 "to_raw_type": "%s",
145 "type": "String", 149 "type": "String",
146 "raw_type": "String", 150 "raw_type": "String",
147 "json_getter": "getString(%s)", 151 "raw_pass_type": "const String&",
148 "json_type": "TypeString", 152 "raw_return_type": "String",
149 } 153 }
150 154
151 typedefs = { 155 typedefs = {
152 "number": "double", 156 "number": "double",
153 "integer": "int", 157 "integer": "int",
154 "boolean": "bool" 158 "boolean": "bool"
155 } 159 }
156 jsontypes = { 160 jsontypes = {
157 "number": "TypeNumber", 161 "number": "TypeNumber",
158 "integer": "TypeNumber", 162 "integer": "TypeNumber",
159 "boolean": "TypeBoolean", 163 "boolean": "TypeBoolean",
160 } 164 }
161 return { 165 return {
162 "return_type": typedefs[type], 166 "return_type": typedefs[type],
163 "pass_type": typedefs[type], 167 "pass_type": typedefs[type],
164 "to_pass_type": "%s", 168 "to_pass_type": "%s",
169 "to_raw_type": "%s",
165 "type": typedefs[type], 170 "type": typedefs[type],
166 "raw_type": typedefs[type], 171 "raw_type": typedefs[type],
167 "json_getter": "get" + to_title_case(type) + "(%s)", 172 "raw_pass_type": typedefs[type],
168 "json_type": jsontypes[type], 173 "raw_return_type": typedefs[type],
169 } 174 }
170 175
171 type_definitions = {} 176 type_definitions = {}
172 type_definitions["string"] = create_primitive_type_definition("string") 177 type_definitions["string"] = create_primitive_type_definition("string")
173 type_definitions["number"] = create_primitive_type_definition("number") 178 type_definitions["number"] = create_primitive_type_definition("number")
174 type_definitions["integer"] = create_primitive_type_definition("integer") 179 type_definitions["integer"] = create_primitive_type_definition("integer")
175 type_definitions["boolean"] = create_primitive_type_definition("boolean") 180 type_definitions["boolean"] = create_primitive_type_definition("boolean")
176 type_definitions["object"] = create_object_type_definition() 181 type_definitions["object"] = create_object_type_definition()
177 type_definitions["any"] = create_any_type_definition() 182 type_definitions["any"] = create_any_type_definition()
178 183
179 184
180 def wrap_array_definition(type): 185 def wrap_array_definition(type):
181 return { 186 return {
182 "return_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"], 187 "return_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"],
183 "pass_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"], 188 "pass_type": "PassOwnPtr<protocol::Array<%s>>" % type["raw_type"],
189 "to_raw_type": "%s.get()",
184 "to_pass_type": "%s.release()", 190 "to_pass_type": "%s.release()",
185 "type": "OwnPtr<protocol::Array<%s>>" % type["raw_type"], 191 "type": "OwnPtr<protocol::Array<%s>>" % type["raw_type"],
186 "raw_type": "protocol::Array<%s>" % type["raw_type"], 192 "raw_type": "protocol::Array<%s>" % type["raw_type"],
193 "raw_pass_type": "protocol::Array<%s>*" % type["raw_type"],
194 "raw_return_type": "protocol::Array<%s>*" % type["raw_type"],
187 "create_type": "adoptPtr(new protocol::Array<%s>())" % type["raw_type"], 195 "create_type": "adoptPtr(new protocol::Array<%s>())" % type["raw_type"],
188 "out_type": "protocol::Array<%s>&" % type["raw_type"], 196 "out_type": "protocol::Array<%s>&" % type["raw_type"],
189 "json_getter": "protocol::Array<%s>::runtimeCast(getArray(%%s))" % type[ "raw_type"],
190 "json_type": "TypeArray",
191 } 197 }
192 198
193 199
194 def create_type_definitions(): 200 def create_type_definitions():
195 for domain in json_api["domains"]: 201 for domain in json_api["domains"]:
196 if not ("types" in domain): 202 if not ("types" in domain):
197 continue 203 continue
198 for type in domain["types"]: 204 for type in domain["types"]:
199 if type["type"] == "object": 205 if type["type"] == "object":
200 type_definitions[domain["domain"] + "." + type["id"]] = create_u ser_type_definition(domain["domain"], type) 206 type_definitions[domain["domain"] + "." + type["id"]] = create_u ser_type_definition(domain["domain"], type)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 h_file.write(h_template.render(template_context)) 249 h_file.write(h_template.render(template_context))
244 cpp_file.write(cpp_template.render(template_context)) 250 cpp_file.write(cpp_template.render(template_context))
245 h_file.close() 251 h_file.close()
246 cpp_file.close() 252 cpp_file.close()
247 253
248 254
249 jinja_env = initialize_jinja_env(output_dirname) 255 jinja_env = initialize_jinja_env(output_dirname)
250 generate("Dispatcher") 256 generate("Dispatcher")
251 generate("Frontend") 257 generate("Frontend")
252 generate("TypeBuilder") 258 generate("TypeBuilder")
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698