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

Side by Side Diff: content/browser/devtools/protocol/devtools_protocol_handler_generator.py

Issue 1408363004: [DevTools] Filter any messages from previous sessions in DevToolsAgentHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 base::Value* CreateValue(const std::string& param); 69 base::Value* CreateValue(const std::string& param);
70 70
71 ${types}\ 71 ${types}\
72 72
73 } // namespace devtools 73 } // namespace devtools
74 74
75 class DevToolsProtocolDispatcher { 75 class DevToolsProtocolDispatcher {
76 public: 76 public:
77 using Notifier = DevToolsProtocolClient::RawMessageCallback; 77 using Notifier = DevToolsProtocolClient::RawMessageCallback;
78 using CommandHandler = 78 using CommandHandler =
79 base::Callback<bool(int, scoped_ptr<base::DictionaryValue>)>; 79 base::Callback<bool(int, int, scoped_ptr<base::DictionaryValue>)>;
80 80
81 explicit DevToolsProtocolDispatcher(const Notifier& notifier); 81 explicit DevToolsProtocolDispatcher(const Notifier& notifier);
82 ~DevToolsProtocolDispatcher(); 82 ~DevToolsProtocolDispatcher();
83 83
84 CommandHandler FindCommandHandler(const std::string& method); 84 CommandHandler FindCommandHandler(const std::string& method);
85 85
86 ${setters}\ 86 ${setters}\
87 87
88 private: 88 private:
89 using Response = DevToolsProtocolClient::Response; 89 using Response = DevToolsProtocolClient::Response;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } // namespace ${domain} 216 } // namespace ${domain}
217 """) 217 """)
218 218
219 tmpl_event = string.Template("""\ 219 tmpl_event = string.Template("""\
220 void ${Command}( 220 void ${Command}(
221 scoped_refptr<${Command}Params> params); 221 scoped_refptr<${Command}Params> params);
222 """) 222 """)
223 223
224 tmpl_response = string.Template("""\ 224 tmpl_response = string.Template("""\
225 void Send${Command}Response( 225 void Send${Command}Response(
226 int session_id,
226 DevToolsCommandId command_id, 227 DevToolsCommandId command_id,
227 scoped_refptr<${Command}Response> params); 228 scoped_refptr<${Command}Response> params);
228 """) 229 """)
229 230
230 tmpl_setter = string.Template("""\ 231 tmpl_setter = string.Template("""\
231 void Set${Domain}Handler( 232 void Set${Domain}Handler(
232 devtools::${domain}::${Domain}Handler* ${domain}_handler); 233 devtools::${domain}::${Domain}Handler* ${domain}_handler);
233 """) 234 """)
234 235
235 tmpl_callback = string.Template("""\ 236 tmpl_callback = string.Template("""\
236 bool On${Domain}${Command}( 237 bool On${Domain}${Command}(
238 int session_id,
237 DevToolsCommandId command_id, 239 DevToolsCommandId command_id,
238 scoped_ptr<base::DictionaryValue> params); 240 scoped_ptr<base::DictionaryValue> params);
239 """) 241 """)
240 242
241 tmpl_field = string.Template("""\ 243 tmpl_field = string.Template("""\
242 devtools::${domain}::${Domain}Handler* ${domain}_handler_; 244 devtools::${domain}::${Domain}Handler* ${domain}_handler_;
243 """) 245 """)
244 246
245 template_cc = string.Template(header + """\ 247 template_cc = string.Template(header + """\
246 248
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 base::Unretained(this)); 318 base::Unretained(this));
317 """) 319 """)
318 320
319 tmpl_init_client = string.Template("""\ 321 tmpl_init_client = string.Template("""\
320 ${domain}_handler_->SetClient(make_scoped_ptr( 322 ${domain}_handler_->SetClient(make_scoped_ptr(
321 new devtools::${domain}::Client(notifier_))); 323 new devtools::${domain}::Client(notifier_)));
322 """) 324 """)
323 325
324 tmpl_callback_impl = string.Template("""\ 326 tmpl_callback_impl = string.Template("""\
325 bool DevToolsProtocolDispatcher::On${Domain}${Command}( 327 bool DevToolsProtocolDispatcher::On${Domain}${Command}(
326 DevToolsCommandId command_id, 328 int session_id, DevToolsCommandId command_id,
327 scoped_ptr<base::DictionaryValue> params) { 329 scoped_ptr<base::DictionaryValue> params) {
328 ${prep}\ 330 ${prep}\
329 Response response = ${domain}_handler_->${Command}(${args}); 331 Response response = ${domain}_handler_->${Command}(${args});
330 scoped_ptr<base::DictionaryValue> protocol_response; 332 scoped_ptr<base::DictionaryValue> protocol_response;
331 if (client_.SendError(command_id, response)) 333 if (client_.SendError(session_id, command_id, response))
332 return true; 334 return true;
333 if (response.IsFallThrough()) 335 if (response.IsFallThrough())
334 return false; 336 return false;
335 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 337 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
336 ${wrap}\ 338 ${wrap}\
337 client_.SendSuccess(command_id, result.Pass()); 339 client_.SendSuccess(session_id, command_id, result.Pass());
338 return true; 340 return true;
339 } 341 }
340 """) 342 """)
341 343
342 tmpl_wrap = string.Template("""\ 344 tmpl_wrap = string.Template("""\
343 result->Set("${proto_param}", devtools::CreateValue(out_${param})); 345 result->Set("${proto_param}", devtools::CreateValue(out_${param}));
344 """) 346 """)
345 347
346 tmpl_callback_async_impl = string.Template("""\ 348 tmpl_callback_async_impl = string.Template("""\
347 bool DevToolsProtocolDispatcher::On${Domain}${Command}( 349 bool DevToolsProtocolDispatcher::On${Domain}${Command}(
350 int session_id,
348 DevToolsCommandId command_id, 351 DevToolsCommandId command_id,
349 scoped_ptr<base::DictionaryValue> params) { 352 scoped_ptr<base::DictionaryValue> params) {
350 ${prep}\ 353 ${prep}\
351 Response response = ${domain}_handler_->${Command}(${args}); 354 Response response = ${domain}_handler_->${Command}(${args});
352 if (client_.SendError(command_id, response)) 355 if (client_.SendError(session_id, command_id, response))
353 return true; 356 return true;
354 return !response.IsFallThrough(); 357 return !response.IsFallThrough();
355 } 358 }
356 """) 359 """)
357 360
358 tmpl_prep_req = string.Template("""\ 361 tmpl_prep_req = string.Template("""\
359 ${raw_type} in_${param}${init}; 362 ${raw_type} in_${param}${init};
360 if (!params || !params->Get${Type}("${proto_param}", &in_${param})) { 363 if (!params || !params->Get${Type}("${proto_param}", &in_${param})) {
361 client_.SendError(command_id, Response::InvalidParams("${proto_param}")); 364 client_.SendError(session_id, command_id, Response::InvalidParams("${proto_p aram}"));
362 return true; 365 return true;
363 } 366 }
364 """) 367 """)
365 368
366 tmpl_prep_req_list = string.Template("""\ 369 tmpl_prep_req_list = string.Template("""\
367 base::ListValue* list_${param} = nullptr; 370 base::ListValue* list_${param} = nullptr;
368 if (!params || !params->GetList("${proto_param}", &list_${param})) { 371 if (!params || !params->GetList("${proto_param}", &list_${param})) {
369 client_.SendError(command_id, Response::InvalidParams("${proto_param}")); 372 client_.SendError(session_id, command_id, Response::InvalidParams("${proto_p aram}"));
370 return true; 373 return true;
371 } 374 }
372 std::vector<${item_type}> in_${param}; 375 std::vector<${item_type}> in_${param};
373 for (base::ListValue::const_iterator it = 376 for (base::ListValue::const_iterator it =
374 list_${param}->begin(); it != list_${param}->end(); ++it) { 377 list_${param}->begin(); it != list_${param}->end(); ++it) {
375 ${item_raw_type} item; 378 ${item_raw_type} item;
376 if (!(*it)->GetAs${ItemType}(&item)) { 379 if (!(*it)->GetAs${ItemType}(&item)) {
377 client_.SendError(command_id, Response::InvalidParams("${proto_param}")); 380 client_.SendError(session_id, command_id, Response::InvalidParams("${proto _param}"));
378 return true; 381 return true;
379 } 382 }
380 in_${param}.push_back(${item_pass}); 383 in_${param}.push_back(${item_pass});
381 } 384 }
382 """) 385 """)
383 386
384 tmpl_prep_opt = string.Template("""\ 387 tmpl_prep_opt = string.Template("""\
385 ${raw_type} in_${param}${init}; 388 ${raw_type} in_${param}${init};
386 bool ${param}_found = params && params->Get${Type}( 389 bool ${param}_found = params && params->Get${Type}(
387 "${proto_param}", 390 "${proto_param}",
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 tmpl_event_impl = string.Template("""\ 423 tmpl_event_impl = string.Template("""\
421 void Client::${Command}( 424 void Client::${Command}(
422 scoped_refptr<${Command}Params> params) { 425 scoped_refptr<${Command}Params> params) {
423 SendNotification("${Domain}.${command}", 426 SendNotification("${Domain}.${command}",
424 params->ToValue().Pass()); 427 params->ToValue().Pass());
425 } 428 }
426 """) 429 """)
427 430
428 tmpl_response_impl = string.Template("""\ 431 tmpl_response_impl = string.Template("""\
429 void Client::Send${Command}Response( 432 void Client::Send${Command}Response(
433 int session_id,
430 DevToolsCommandId command_id, 434 DevToolsCommandId command_id,
431 scoped_refptr<${Command}Response> params) { 435 scoped_refptr<${Command}Response> params) {
432 SendSuccess(command_id, params->ToValue().Pass()); 436 SendSuccess(session_id, command_id, params->ToValue().Pass());
433 } 437 }
434 """) 438 """)
435 439
436 tmpl_typename = string.Template("devtools::${domain}::${declared_name}") 440 tmpl_typename = string.Template("devtools::${domain}::${declared_name}")
437 441
438 def Capitalize(s): 442 def Capitalize(s):
439 return s[:1].upper() + s[1:] 443 return s[:1].upper() + s[1:]
440 444
441 def Uncamelcase(s): 445 def Uncamelcase(s):
442 result = "" 446 result = ""
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 if json_command.get("async"): 705 if json_command.get("async"):
702 domain_needs_client = True 706 domain_needs_client = True
703 json_returns = [] 707 json_returns = []
704 if "returns" in json_command: 708 if "returns" in json_command:
705 json_returns = json_command["returns"] 709 json_returns = json_command["returns"]
706 command_map["declared_name"] = "%sResponse" % command_map["Command"] 710 command_map["declared_name"] = "%sResponse" % command_map["Command"]
707 DeclareStruct(json_returns, command_map) 711 DeclareStruct(json_returns, command_map)
708 # TODO(vkuzkokov) Pass async callback instance similar to how 712 # TODO(vkuzkokov) Pass async callback instance similar to how
709 # InspectorBackendDispatcher does it. This, however, can work 713 # InspectorBackendDispatcher does it. This, however, can work
710 # only if Blink and Chrome are in the same repo. 714 # only if Blink and Chrome are in the same repo.
711 args.insert(0, "command_id") 715 args.insert(0, "session_id")
716 args.insert(1, "command_id")
712 handler_method_impls.append( 717 handler_method_impls.append(
713 tmpl_callback_async_impl.substitute(command_map, 718 tmpl_callback_async_impl.substitute(command_map,
714 prep = "".join(prep), 719 prep = "".join(prep),
715 args = "\n " + ",\n ".join(args))) 720 args = "\n " + ",\n ".join(args)))
716 client_methods.append(tmpl_response.substitute(command_map)) 721 client_methods.append(tmpl_response.substitute(command_map))
717 client_method_impls.append(tmpl_response_impl.substitute(command_map)) 722 client_method_impls.append(tmpl_response_impl.substitute(command_map))
718 else: 723 else:
719 wrap = [] 724 wrap = []
720 if "returns" in json_command: 725 if "returns" in json_command:
721 for json_param in json_command["returns"]: 726 for json_param in json_command["returns"]:
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 output_h_file.close() 799 output_h_file.close()
795 800
796 output_cc_file.write(template_cc.substitute({}, 801 output_cc_file.write(template_cc.substitute({},
797 major = blink_protocol["version"]["major"], 802 major = blink_protocol["version"]["major"],
798 minor = blink_protocol["version"]["minor"], 803 minor = blink_protocol["version"]["minor"],
799 includes = "".join(sorted(includes)), 804 includes = "".join(sorted(includes)),
800 fields_init = ",\n ".join(fields_init), 805 fields_init = ",\n ".join(fields_init),
801 methods = "\n".join(handler_method_impls), 806 methods = "\n".join(handler_method_impls),
802 types = "\n".join(type_impls))) 807 types = "\n".join(type_impls)))
803 output_cc_file.close() 808 output_cc_file.close()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698