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

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"
13 #include "platform/inspector_protocol/DispatcherBase.h"
12 #include "platform/inspector_protocol/ErrorSupport.h" 14 #include "platform/inspector_protocol/ErrorSupport.h"
15 #include "platform/inspector_protocol/FrontendChannel.h"
13 #include "platform/inspector_protocol/Maybe.h" 16 #include "platform/inspector_protocol/Maybe.h"
14 #include "platform/inspector_protocol/Object.h" 17 #include "platform/inspector_protocol/Object.h"
15 #include "platform/inspector_protocol/String16.h" 18 #include "platform/inspector_protocol/String16.h"
16 #include "platform/inspector_protocol/Values.h" 19 #include "platform/inspector_protocol/Values.h"
17 #include "platform/inspector_protocol/ValueConversions.h" 20 #include "platform/inspector_protocol/ValueConversions.h"
18 #include "wtf/Assertions.h" 21 #include "wtf/Assertions.h"
19 #include "wtf/PtrUtil.h" 22 #include "wtf/PtrUtil.h"
20 23
21 namespace blink { 24 namespace blink {
22 namespace protocol { 25 namespace protocol {
23 26
24 {% for domain in api.domains %} 27 {% for domain in api.domains %}
25 28
26 // ------------- Forward declarations and typedefs. 29 namespace {{domain.domain}} {
27 30
28 namespace {{domain.domain}} { 31 // ------------- Forward and enum declarations.
29 {% for type in domain.types %} 32 {% for type in domain.types %}
30 {% if type.type == "object" %} 33 {% if type.type == "object" %}
31 {% if "properties" in type %} 34 {% if "properties" in type %}
32 // {{type.description}} 35 // {{type.description}}
33 class {{type.id}}; 36 class {{type.id}};
34 {% else %} 37 {% else %}
35 // {{type.description}} 38 // {{type.description}}
36 using {{type.id}} = Object; 39 using {{type.id}} = Object;
37 {% endif %} 40 {% endif %}
38 {% elif type.type != "array" %} 41 {% elif type.type != "array" %}
39 // {{type.description}} 42 // {{type.description}}
40 using {{type.id}} = {{resolve_type(type).type}}; 43 using {{type.id}} = {{resolve_type(type).type}};
41 {% endif %} 44 {% endif %}
42 {% endfor %} 45 {% endfor %}
43 } // {{domain.domain}}
44 {% endfor %}
45
46 // ------------- Enum values from types.
47 {% for domain in api.domains %}
48 {% for type in domain.types %} 46 {% for type in domain.types %}
49 {% if "enum" in type %} 47 {% if "enum" in type %}
50 48
51 namespace {{domain.domain}} {
52 namespace {{type.id}}Enum { 49 namespace {{type.id}}Enum {
53 {% for literal in type.enum %} 50 {% for literal in type.enum %}
54 PLATFORM_EXPORT extern const char* {{ literal | dash_to_camelcase}}; 51 PLATFORM_EXPORT extern const char* {{ literal | dash_to_camelcase}};
55 {% endfor %} 52 {% endfor %}
56 } // {{type.id}}Enum 53 } // {{type.id}}Enum
57 } // {{domain.domain}}
58 {% endif %} 54 {% endif %}
59 {% endfor %} 55 {% endfor %}
60 {% endfor %}
61
62 // ------------- Enum values from params.
63 {% for domain in api.domains %}
64 {% for command in join_arrays(domain, ["commands", "events"]) %} 56 {% for command in join_arrays(domain, ["commands", "events"]) %}
65 {% for param in join_arrays(command, ["parameters", "returns"]) %} 57 {% for param in join_arrays(command, ["parameters", "returns"]) %}
66 {% if "enum" in param %} 58 {% if "enum" in param %}
67 59
68 namespace {{domain.domain}} {
69 namespace {{command.name | to_title_case}} { 60 namespace {{command.name | to_title_case}} {
70 namespace {{param.name | to_title_case}}Enum { 61 namespace {{param.name | to_title_case}}Enum {
71 {% for literal in param.enum %} 62 {% for literal in param.enum %}
72 PLATFORM_EXPORT extern const char* {{ literal | dash_to_camelcase}}; 63 PLATFORM_EXPORT extern const char* {{ literal | dash_to_camelcase}};
73 {% endfor %} 64 {% endfor %}
74 } // {{param.name | to_title_case}}Enum 65 } // {{param.name | to_title_case}}Enum
75 } // {{command.name | to_title_case }} 66 } // {{command.name | to_title_case }}
76 } // {{domain.domain}}
77 {% endif %} 67 {% endif %}
78 {% endfor %} 68 {% endfor %}
79 {% endfor %} 69 {% endfor %}
80 {% endfor %}
81 70
82 // ------------- Type and builder declarations. 71 // ------------- Type and builder declarations.
83 {% for domain in api.domains %}
84
85 namespace {{domain.domain}} {
86 {% for type in domain.types %} 72 {% for type in domain.types %}
87 {% if not (type.type == "object") or not ("properties" in type) %}{% continu e %}{% endif %} 73 {% if not (type.type == "object") or not ("properties" in type) %}{% continu e %}{% endif %}
88 {% set type_def = type_definition(domain.domain + "." + type.id)%} 74 {% set type_def = type_definition(domain.domain + "." + type.id)%}
89 75
90 // {{type.description}} 76 // {{type.description}}
91 class PLATFORM_EXPORT {{type.id}} { 77 class PLATFORM_EXPORT {{type.id}} {
92 public: 78 public:
93 static std::unique_ptr<{{type.id}}> parse(protocol::Value* value, ErrorSuppo rt* errors); 79 static std::unique_ptr<{{type.id}}> parse(protocol::Value* value, ErrorSuppo rt* errors);
94 80
95 ~{{type.id}}() { } 81 ~{{type.id}}() { }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 {% if property.optional %} 166 {% if property.optional %}
181 Maybe<{{resolve_type(property).raw_type}}> m_{{property.name}}; 167 Maybe<{{resolve_type(property).raw_type}}> m_{{property.name}};
182 {% else %} 168 {% else %}
183 {{resolve_type(property).type}} m_{{property.name}}; 169 {{resolve_type(property).type}} m_{{property.name}};
184 {% endif %} 170 {% endif %}
185 {% endfor %} 171 {% endfor %}
186 }; 172 };
187 173
188 {% endfor %} 174 {% endfor %}
189 175
190 } // {{domain.domain}} 176 // ------------- Backend interface.
177
178 class PLATFORM_EXPORT Backend {
179 public:
180 {% for command in domain.commands %}
181 {% if "redirect" in command %}{% continue %}{% endif %}
182 {% if ("handlers" in command) and not ("renderer" in command["handlers"]) %} {% continue %}{% endif %}
183 {% if "async" in command %}
184 class PLATFORM_EXPORT {{command.name | to_title_case}}Callback : public Back endCallback {
185 public:
186 virtual void sendSuccess(
187 {%- for parameter in command.returns -%}
188 {%- if "optional" in parameter -%}
189 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name} }
190 {%- else -%}
191 {{resolve_type(parameter).pass_type}} {{parameter.name}}
192 {%- endif -%}
193 {%- if not loop.last -%}, {% endif -%}
194 {%- endfor -%}
195 ) = 0;
196 };
197 {% endif %}
198 virtual void {{command.name}}(ErrorString*
199 {%- for parameter in command.parameters -%}
200 {%- if "optional" in parameter -%}
201 , const Maybe<{{resolve_type(parameter).raw_type}}>& in_{{parameter.name }}
202 {%- else -%}
203 , {{resolve_type(parameter).pass_type}} in_{{parameter.name}}
204 {%- endif -%}
205 {%- endfor -%}
206 {%- if "async" in command -%}
207 , std::unique_ptr<{{command.name | to_title_case}}Callback> callback
208 {%- else -%}
209 {%- for parameter in command.returns -%}
210 {%- if "optional" in parameter -%}
211 , Maybe<{{resolve_type(parameter).raw_type}}>* out_{{parameter.name}}
212 {%- else -%}
213 , {{resolve_type(parameter).type}}* out_{{parameter.name}}
214 {%- endif -%}
215 {%- endfor -%}
216 {%- endif -%}
217 ) = 0;
218 {% endfor %}
219
220 {% if not has_disable(domain.commands) %}
221 virtual void disable(ErrorString*) { }
222 {% endif %}
223
224 protected:
225 virtual ~Backend() { }
226 };
227
228 // ------------- Frontend interface.
229
230 class PLATFORM_EXPORT Frontend {
231 public:
232 Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChann el) { }
233 {% for event in domain.events %}
234 {% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% con tinue %}{% endif %}
235 void {{event.name}}(
236 {%- for parameter in event.parameters -%}
237 {%- if "optional" in parameter -%}
238 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} = Maybe<{{resolve_type(parameter).raw_type}}>()
239 {%- else -%}
240 {{resolve_type(parameter).pass_type}} {{parameter.name}}
241 {%- endif -%}{%- if not loop.last -%}, {% endif -%}
242 {%- endfor -%}
243 );
244 {% endfor %}
245
246 void flush() { m_frontendChannel->flushProtocolNotifications(); }
247 private:
248 FrontendChannel* m_frontendChannel;
249 };
250
251 // ------------- Dispatcher.
252
253 class PLATFORM_EXPORT Dispatcher {
254 public:
255 static void wire(UberDispatcher*, blink::protocol::{{domain.domain}}::Backen d*);
256
257 private:
258 Dispatcher() { }
259 };
260
261 // ------------- Metainfo.
262
263 class PLATFORM_EXPORT Metainfo {
264 public:
265 using BackendClass = Backend;
266 using FrontendClass = Frontend;
267 using DispatcherClass = Dispatcher;
268 static const char domainName[];
269 };
270
271 } // namespace {{domain.domain}}
191 {% endfor %} 272 {% endfor %}
192 273
193 } // namespace protocol 274 } // namespace protocol
194 } // namespace blink 275 } // namespace blink
195 276
196 using blink::protocol::ErrorString; 277 using blink::protocol::ErrorString;
197 278
198 #endif // !defined({{class_name}}_h) 279 #endif // !defined({{class_name}}_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698