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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/TypeBuilder_h.template

Issue 2012753003: DevTools: consolidate protocol generators for front-end, backend and type builder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 // This file is generated 1 // This file is generated
2 2
3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 3 // Copyright (c) 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 #ifndef {{class_name}}_h 7 #ifndef {{class_name}}_h
8 #define {{class_name}}_h 8 #define {{class_name}}_h
9 9
10 #include "platform/PlatformExport.h" 10 #include "platform/PlatformExport.h"
11 #include "platform/inspector_protocol/Array.h" 11 #include "platform/inspector_protocol/Array.h"
12 #include "platform/inspector_protocol/BackendCallback.h"
12 #include "platform/inspector_protocol/ErrorSupport.h" 13 #include "platform/inspector_protocol/ErrorSupport.h"
14 #include "platform/inspector_protocol/FrontendChannel.h"
13 #include "platform/inspector_protocol/Maybe.h" 15 #include "platform/inspector_protocol/Maybe.h"
14 #include "platform/inspector_protocol/Object.h" 16 #include "platform/inspector_protocol/Object.h"
15 #include "platform/inspector_protocol/String16.h" 17 #include "platform/inspector_protocol/String16.h"
16 #include "platform/inspector_protocol/Values.h" 18 #include "platform/inspector_protocol/Values.h"
17 #include "platform/inspector_protocol/ValueConversions.h" 19 #include "platform/inspector_protocol/ValueConversions.h"
18 #include "wtf/Assertions.h" 20 #include "wtf/Assertions.h"
19 #include "wtf/PtrUtil.h" 21 #include "wtf/PtrUtil.h"
20 22
21 namespace blink { 23 namespace blink {
22 namespace protocol { 24 namespace protocol {
23 25
26 class PLATFORM_EXPORT Frontend;
27
24 {% for domain in api.domains %} 28 {% for domain in api.domains %}
25 29
26 // ------------- Forward declarations and typedefs. 30 namespace {{domain.domain}} {
27 31
28 namespace {{domain.domain}} { 32 // ------------- Forward and enum declarations.
29 {% for type in domain.types %} 33 {% for type in domain.types %}
30 {% if type.type == "object" %} 34 {% if type.type == "object" %}
31 {% if "properties" in type %} 35 {% if "properties" in type %}
32 // {{type.description}} 36 // {{type.description}}
33 class {{type.id}}; 37 class {{type.id}};
34 {% else %} 38 {% else %}
35 // {{type.description}} 39 // {{type.description}}
36 using {{type.id}} = Object; 40 using {{type.id}} = Object;
37 {% endif %} 41 {% endif %}
38 {% elif type.type != "array" %} 42 {% elif type.type != "array" %}
39 // {{type.description}} 43 // {{type.description}}
40 using {{type.id}} = {{resolve_type(type).type}}; 44 using {{type.id}} = {{resolve_type(type).type}};
41 {% endif %} 45 {% endif %}
42 {% endfor %} 46 {% endfor %}
43 } // {{domain.domain}}
44 {% endfor %}
45
46 // ------------- Enum values from types.
47 {% for domain in api.domains %}
48 {% for type in domain.types %} 47 {% for type in domain.types %}
49 {% if "enum" in type %} 48 {% if "enum" in type %}
50 49
51 namespace {{domain.domain}} {
52 namespace {{type.id}}Enum { 50 namespace {{type.id}}Enum {
53 {% for literal in type.enum %} 51 {% for literal in type.enum %}
54 PLATFORM_EXPORT extern const char* {{ literal | dash_to_camelcase}}; 52 PLATFORM_EXPORT extern const char* {{ literal | dash_to_camelcase}};
55 {% endfor %} 53 {% endfor %}
56 } // {{type.id}}Enum 54 } // {{type.id}}Enum
57 } // {{domain.domain}}
58 {% endif %} 55 {% endif %}
59 {% endfor %} 56 {% endfor %}
60 {% endfor %}
61
62 // ------------- Enum values from params.
63 {% for domain in api.domains %}
64 {% for command in join_arrays(domain, ["commands", "events"]) %} 57 {% for command in join_arrays(domain, ["commands", "events"]) %}
65 {% for param in join_arrays(command, ["parameters", "returns"]) %} 58 {% for param in join_arrays(command, ["parameters", "returns"]) %}
66 {% if "enum" in param %} 59 {% if "enum" in param %}
67 60
68 namespace {{domain.domain}} {
69 namespace {{command.name | to_title_case}} { 61 namespace {{command.name | to_title_case}} {
70 namespace {{param.name | to_title_case}}Enum { 62 namespace {{param.name | to_title_case}}Enum {
71 {% for literal in param.enum %} 63 {% for literal in param.enum %}
72 PLATFORM_EXPORT extern const char* {{ literal | dash_to_camelcase}}; 64 PLATFORM_EXPORT extern const char* {{ literal | dash_to_camelcase}};
73 {% endfor %} 65 {% endfor %}
74 } // {{param.name | to_title_case}}Enum 66 } // {{param.name | to_title_case}}Enum
75 } // {{command.name | to_title_case }} 67 } // {{command.name | to_title_case }}
76 } // {{domain.domain}}
77 {% endif %} 68 {% endif %}
78 {% endfor %} 69 {% endfor %}
79 {% endfor %} 70 {% endfor %}
80 {% endfor %}
81 71
82 // ------------- Type and builder declarations. 72 // ------------- Type and builder declarations.
83 {% for domain in api.domains %}
84
85 namespace {{domain.domain}} {
86 {% for type in domain.types %} 73 {% for type in domain.types %}
87 {% if not (type.type == "object") or not ("properties" in type) %}{% continu e %}{% endif %} 74 {% if not (type.type == "object") or not ("properties" in type) %}{% continu e %}{% endif %}
88 {% set type_def = type_definition(domain.domain + "." + type.id)%} 75 {% set type_def = type_definition(domain.domain + "." + type.id)%}
89 76
90 // {{type.description}} 77 // {{type.description}}
91 class PLATFORM_EXPORT {{type.id}} { 78 class PLATFORM_EXPORT {{type.id}} {
92 public: 79 public:
93 static std::unique_ptr<{{type.id}}> parse(protocol::Value* value, ErrorSuppo rt* errors); 80 static std::unique_ptr<{{type.id}}> parse(protocol::Value* value, ErrorSuppo rt* errors);
94 81
95 ~{{type.id}}() { } 82 ~{{type.id}}() { }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 {% if property.optional %} 167 {% if property.optional %}
181 Maybe<{{resolve_type(property).raw_type}}> m_{{property.name}}; 168 Maybe<{{resolve_type(property).raw_type}}> m_{{property.name}};
182 {% else %} 169 {% else %}
183 {{resolve_type(property).type}} m_{{property.name}}; 170 {{resolve_type(property).type}} m_{{property.name}};
184 {% endif %} 171 {% endif %}
185 {% endfor %} 172 {% endfor %}
186 }; 173 };
187 174
188 {% endfor %} 175 {% endfor %}
189 176
190 } // {{domain.domain}} 177 // ------------- Backend interface.
178
179 class PLATFORM_EXPORT Backend {
180 public:
181 {% for command in domain.commands %}
182 {% if "redirect" in command %}{% continue %}{% endif %}
183 {% if ("handlers" in command) and not ("renderer" in command["handlers"]) %} {% continue %}{% endif %}
184 {% if "async" in command %}
185 class PLATFORM_EXPORT {{command.name | to_title_case}}Callback : public Back endCallback {
186 public:
187 virtual void sendSuccess(
188 {%- for parameter in command.returns -%}
189 {%- if "optional" in parameter -%}
190 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name} }
191 {%- else -%}
192 {{resolve_type(parameter).pass_type}} {{parameter.name}}
193 {%- endif -%}
194 {%- if not loop.last -%}, {% endif -%}
195 {%- endfor -%}
196 ) = 0;
197 };
198 {% endif %}
199 virtual void {{command.name}}(ErrorString*
200 {%- for parameter in command.parameters -%}
201 {%- if "optional" in parameter -%}
202 , const Maybe<{{resolve_type(parameter).raw_type}}>& in_{{parameter.name }}
203 {%- else -%}
204 , {{resolve_type(parameter).pass_type}} in_{{parameter.name}}
205 {%- endif -%}
206 {%- endfor -%}
207 {%- if "async" in command -%}
208 , std::unique_ptr<{{command.name | to_title_case}}Callback> callback
209 {%- else -%}
210 {%- for parameter in command.returns -%}
211 {%- if "optional" in parameter -%}
212 , Maybe<{{resolve_type(parameter).raw_type}}>* out_{{parameter.name}}
213 {%- else -%}
214 , {{resolve_type(parameter).type}}* out_{{parameter.name}}
215 {%- endif -%}
216 {%- endfor -%}
217 {%- endif -%}
218 ) = 0;
219 {% endfor %}
220
221 protected:
222 virtual ~Backend() { }
223 };
224
225 // ------------- Frontend interface.
226
227 class PLATFORM_EXPORT Frontend {
228 public:
229 static Frontend* from(protocol::Frontend* frontend);
230 Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChann el) { }
dgozman 2016/05/26 20:55:30 explicit
231 {% for event in domain.events %}
232 {% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% con tinue %}{% endif %}
233 void {{event.name}}(
234 {%- for parameter in event.parameters -%}
235 {%- if "optional" in parameter -%}
236 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} = Maybe<{{resolve_type(parameter).raw_type}}>()
237 {%- else -%}
238 {{resolve_type(parameter).pass_type}} {{parameter.name}}
239 {%- endif -%}{%- if not loop.last -%}, {% endif -%}
240 {%- endfor -%}
241 );
242 {% endfor %}
243
244 void flush() { m_frontendChannel->flushProtocolNotifications(); }
245 private:
246 FrontendChannel* m_frontendChannel;
247 };
248
249 } // namespace {{domain.domain}}
191 {% endfor %} 250 {% endfor %}
192 251
193 } // namespace protocol 252 } // namespace protocol
194 } // namespace blink 253 } // namespace blink
195 254
196 using blink::protocol::ErrorString; 255 using blink::protocol::ErrorString;
197 256
198 #endif // !defined({{class_name}}_h) 257 #endif // !defined({{class_name}}_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698