OLD | NEW |
1 // This file is generated | 1 // This file is generated |
2 | 2 |
3 // Copyright 2016 The Chromium Authors. All rights reserved. | 3 // Copyright 2016 The Chromium Authors. All rights reserved. |
4 // Use of this source code is governed by a BSD-style license that can be | 4 // Use of this source code is governed by a BSD-style license that can be |
5 // found in the LICENSE file. | 5 // found in the LICENSE file. |
6 | 6 |
7 #include "headless/public/devtools/domains/{{domain.domain | camelcase_to_hacker
_style}}.h" | 7 #include "headless/public/devtools/domains/{{domain.domain | camelcase_to_hacker
_style}}.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 base::Unretained(this))); | 38 base::Unretained(this))); |
39 {% endfor %} | 39 {% endfor %} |
40 } | 40 } |
41 {% endif %} | 41 {% endif %} |
42 | 42 |
43 {% for command in domain.commands %} | 43 {% for command in domain.commands %} |
44 {# Skip redirected commands. #} | 44 {# Skip redirected commands. #} |
45 {% if "redirect" in command %}{% continue %}{% endif %} | 45 {% if "redirect" in command %}{% continue %}{% endif %} |
46 | 46 |
47 {% set class_name = 'ExperimentalDomain' if command.experimental else 'Domai
n' %} | 47 {% set class_name = 'ExperimentalDomain' if command.experimental else 'Domai
n' %} |
48 {% set method_name = command.name | to_title_case %} | 48 {% set method_name = command.name | sanitize_literal | to_title_case %} |
49 void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> para
ms, base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) { | 49 void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> para
ms, base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) { |
50 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), base::Bind(&Domain::Handle{{method_name}}Response, callback)); | 50 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), base::Bind(&Domain::Handle{{method_name}}Response, callback)); |
51 } | 51 } |
52 {# Generate convenience methods that take the required parameters directly.
#} | 52 {# Generate convenience methods that take the required parameters directly.
#} |
53 {% if not "parameters" in command %}{% continue %}{% endif %} | 53 {% if not "parameters" in command %}{% continue %}{% endif %} |
54 {# Don't generate these for experimental commands. #} | 54 {# Don't generate these for experimental commands. #} |
55 {% if command.experimental %}{% continue %}{% endif %} | 55 {% if command.experimental %}{% continue %}{% endif %} |
56 | 56 |
57 void {{class_name}}::{{method_name}}({##} | 57 void {{class_name}}::{{method_name}}({##} |
58 {% for parameter in command.parameters -%} | 58 {% for parameter in command.parameters -%} |
(...skipping 30 matching lines...) Expand all Loading... |
89 {% if not command.get("returns", []) %} | 89 {% if not command.get("returns", []) %} |
90 void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> para
ms, base::Callback<void()> callback) { | 90 void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> para
ms, base::Callback<void()> callback) { |
91 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), std::move(callback)); | 91 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), std::move(callback)); |
92 } | 92 } |
93 {% endif %} | 93 {% endif %} |
94 {% endfor %} | 94 {% endfor %} |
95 | 95 |
96 {# Generate response handlers for commands that need them. #} | 96 {# Generate response handlers for commands that need them. #} |
97 {% for command in domain.commands %} | 97 {% for command in domain.commands %} |
98 {% if not "returns" in command %}{% continue %}{% endif %} | 98 {% if not "returns" in command %}{% continue %}{% endif %} |
99 {% set method_name = command.name | to_title_case %} | 99 {% set method_name = command.name | sanitize_literal | to_title_case %} |
100 | 100 |
101 // static | 101 // static |
102 void Domain::Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{
{method_name}}Result>)> callback, const base::Value& response) { | 102 void Domain::Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{
{method_name}}Result>)> callback, const base::Value& response) { |
103 if (callback.is_null()) | 103 if (callback.is_null()) |
104 return; | 104 return; |
105 // This is an error response. | 105 // This is an error response. |
106 if (response.IsType(base::Value::Type::NONE)) { | 106 if (response.IsType(base::Value::Type::NONE)) { |
107 callback.Run(nullptr); | 107 callback.Run(nullptr); |
108 return; | 108 return; |
109 } | 109 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 146 } |
147 | 147 |
148 void ExperimentalDomain::RemoveObserver(ExperimentalObserver* observer) { | 148 void ExperimentalDomain::RemoveObserver(ExperimentalObserver* observer) { |
149 observers_.RemoveObserver(observer); | 149 observers_.RemoveObserver(observer); |
150 } | 150 } |
151 {% endif %} | 151 {% endif %} |
152 | 152 |
153 } // namespace {{domain.domain | camelcase_to_hacker_style}} | 153 } // namespace {{domain.domain | camelcase_to_hacker_style}} |
154 | 154 |
155 } // namespace headless | 155 } // namespace headless |
OLD | NEW |