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

Side by Side Diff: templates/TypeBuilder_cpp.template

Issue 2566343002: [inspector_protocol] Support redirects and types whitelisting. (Closed)
Patch Set: Created 4 years 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 #include {{format_include(config.protocol.package, domain.domain)}} 7 #include {{format_include(config.protocol.package, domain.domain)}}
8 8
9 #include {{format_include(config.protocol.package, "Protocol")}} 9 #include {{format_include(config.protocol.package, "Protocol")}}
10 10
11 {% for namespace in config.protocol.namespace %} 11 {% for namespace in config.protocol.namespace %}
12 namespace {{namespace}} { 12 namespace {{namespace}} {
13 {% endfor %} 13 {% endfor %}
14 namespace {{domain.domain}} { 14 namespace {{domain.domain}} {
15 15
16 // ------------- Enum values from types. 16 // ------------- Enum values from types.
17 17
18 const char Metainfo::domainName[] = "{{domain.domain}}"; 18 const char Metainfo::domainName[] = "{{domain.domain}}";
19 const char Metainfo::commandPrefix[] = "{{domain.domain}}."; 19 const char Metainfo::commandPrefix[] = "{{domain.domain}}.";
20 const char Metainfo::version[] = "{{domain.version}}"; 20 const char Metainfo::version[] = "{{domain.version}}";
21 {% for type in domain.types %} 21 {% for type in domain.types %}
22 {% if not protocol.generate_type(domain.domain, type.id) %}{% continue %} {% endif %}
22 {% if "enum" in type %} 23 {% if "enum" in type %}
23 24
24 namespace {{type.id}}Enum { 25 namespace {{type.id}}Enum {
25 {% for literal in type.enum %} 26 {% for literal in type.enum %}
26 const char* {{ literal | dash_to_camelcase}} = "{{literal}}"; 27 const char* {{ literal | dash_to_camelcase}} = "{{literal}}";
27 {% endfor %} 28 {% endfor %}
28 } // namespace {{type.id}}Enum 29 } // namespace {{type.id}}Enum
29 {% if protocol.is_exported(domain.domain, type.id) %} 30 {% if protocol.is_exported(domain.domain, type.id) %}
30 31
31 namespace API { 32 namespace API {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 194
194 // --------------------- Dispatcher. 195 // --------------------- Dispatcher.
195 196
196 class DispatcherImpl : public protocol::DispatcherBase { 197 class DispatcherImpl : public protocol::DispatcherBase {
197 public: 198 public:
198 DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fall ThroughForNotFound) 199 DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fall ThroughForNotFound)
199 : DispatcherBase(frontendChannel) 200 : DispatcherBase(frontendChannel)
200 , m_backend(backend) 201 , m_backend(backend)
201 , m_fallThroughForNotFound(fallThroughForNotFound) { 202 , m_fallThroughForNotFound(fallThroughForNotFound) {
202 {% for command in domain.commands %} 203 {% for command in domain.commands %}
203 {% if "redirect" in command %}{% continue %}{% endif %} 204 {% if "redirect" in command %}
205 m_redirects["{{domain.domain}}.{{command.name}}"] = "{{command.redirect}}. {{command.name}}";
206 {% continue %}
207 {% endif %}
204 {% if not protocol.generate_command(domain.domain, command.name) %}{% contin ue %}{% endif %} 208 {% if not protocol.generate_command(domain.domain, command.name) %}{% contin ue %}{% endif %}
205 m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{ {command.name}}; 209 m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{ {command.name}};
206 {% endfor %} 210 {% endfor %}
207 } 211 }
208 ~DispatcherImpl() override { } 212 ~DispatcherImpl() override { }
209 DispatchResponse::Status dispatch(int callId, const String& method, std::uni que_ptr<protocol::DictionaryValue> messageObject) override; 213 DispatchResponse::Status dispatch(int callId, const String& method, std::uni que_ptr<protocol::DictionaryValue> messageObject) override;
214 HashMap<String, String>& redirects() { return m_redirects; }
210 215
211 protected: 216 protected:
212 using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors); 217 using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
213 using DispatchMap = protocol::HashMap<String, CallHandler>; 218 using DispatchMap = protocol::HashMap<String, CallHandler>;
214 DispatchMap m_dispatchMap; 219 DispatchMap m_dispatchMap;
220 HashMap<String, String> m_redirects;
215 221
216 {% for command in domain.commands %} 222 {% for command in domain.commands %}
217 {% if "redirect" in command %}{% continue %}{% endif %} 223 {% if "redirect" in command %}{% continue %}{% endif %}
218 {% if not protocol.generate_command(domain.domain, command.name) %}{% contin ue %}{% endif %} 224 {% if not protocol.generate_command(domain.domain, command.name) %}{% contin ue %}{% endif %}
219 DispatchResponse::Status {{command.name}}(int callId, std::unique_ptr<Dictio naryValue> requestMessageObject, ErrorSupport*); 225 DispatchResponse::Status {{command.name}}(int callId, std::unique_ptr<Dictio naryValue> requestMessageObject, ErrorSupport*);
220 {% endfor %} 226 {% endfor %}
221 227
222 Backend* m_backend; 228 Backend* m_backend;
223 bool m_fallThroughForNotFound; 229 bool m_fallThroughForNotFound;
224 }; 230 };
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 {%- else -%} 336 {%- else -%}
331 {{protocol.resolve_type(parameter).to_pass_type % ("in_" + parameter.nam e)}} 337 {{protocol.resolve_type(parameter).to_pass_type % ("in_" + parameter.nam e)}}
332 {%- endif -%} 338 {%- endif -%}
333 {%- endfor %} 339 {%- endfor %}
334 {%- if "returns" in command %} 340 {%- if "returns" in command %}
335 {%- for parameter in command.returns -%} 341 {%- for parameter in command.returns -%}
336 {%- if not loop.first or command.parameters -%}, {% endif -%} 342 {%- if not loop.first or command.parameters -%}, {% endif -%}
337 &out_{{parameter.name}} 343 &out_{{parameter.name}}
338 {%- endfor %} 344 {%- endfor %}
339 {% endif %}); 345 {% endif %});
340 {% if "returns" in command %}
341 if (response.status() == DispatchResponse::kFallThrough) 346 if (response.status() == DispatchResponse::kFallThrough)
342 return response.status(); 347 return response.status();
348 {% if "returns" in command %}
343 std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create( ); 349 std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create( );
344 if (response.status() == DispatchResponse::kSuccess) { 350 if (response.status() == DispatchResponse::kSuccess) {
345 {% for parameter in command.returns %} 351 {% for parameter in command.returns %}
346 {% if "optional" in parameter %} 352 {% if "optional" in parameter %}
347 if (out_{{parameter.name}}.isJust()) 353 if (out_{{parameter.name}}.isJust())
348 result->setValue("{{parameter.name}}", ValueConversions<{{protocol.r esolve_type(parameter).raw_type}}>::toValue(out_{{parameter.name}}.fromJust())); 354 result->setValue("{{parameter.name}}", ValueConversions<{{protocol.r esolve_type(parameter).raw_type}}>::toValue(out_{{parameter.name}}.fromJust()));
349 {% else %} 355 {% else %}
350 result->setValue("{{parameter.name}}", ValueConversions<{{protocol.resol ve_type(parameter).raw_type}}>::toValue({{protocol.resolve_type(parameter).to_ra w_type % ("out_" + parameter.name)}})); 356 result->setValue("{{parameter.name}}", ValueConversions<{{protocol.resol ve_type(parameter).raw_type}}>::toValue({{protocol.resolve_type(parameter).to_ra w_type % ("out_" + parameter.name)}}));
351 {% endif %} 357 {% endif %}
352 {% endfor %} 358 {% endfor %}
(...skipping 18 matching lines...) Expand all
371 {%- endif -%} 377 {%- endif -%}
372 {%- endfor -%} 378 {%- endfor -%}
373 {%- if command.parameters -%}, {% endif -%} 379 {%- if command.parameters -%}, {% endif -%}
374 std::move(callback)); 380 std::move(callback));
375 return (weak->get() && weak->get()->lastCallbackFallThrough()) ? DispatchRes ponse::kFallThrough : DispatchResponse::kAsync; 381 return (weak->get() && weak->get()->lastCallbackFallThrough()) ? DispatchRes ponse::kFallThrough : DispatchResponse::kAsync;
376 {% endif %} 382 {% endif %}
377 } 383 }
378 {% endfor %} 384 {% endfor %}
379 385
380 // static 386 // static
381 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) 387 void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
382 { 388 {
383 dispatcher->registerBackend("{{domain.domain}}", std::unique_ptr<protocol::D ispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend, dispatcher->fa llThroughForNotFound()))); 389 std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel( ), backend, uber->fallThroughForNotFound()));
390 uber->setupRedirects(dispatcher->redirects());
391 uber->registerBackend("{{domain.domain}}", std::move(dispatcher));
384 } 392 }
385 393
386 } // {{domain.domain}} 394 } // {{domain.domain}}
387 {% for namespace in config.protocol.namespace %} 395 {% for namespace in config.protocol.namespace %}
388 } // namespace {{namespace}} 396 } // namespace {{namespace}}
389 {% endfor %} 397 {% endfor %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698