| OLD | NEW |
| 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 "platform/inspector_protocol/{{class_name}}.h" | 7 #include "platform/inspector_protocol/{{class_name}}.h" |
| 8 | 8 |
| 9 #include "platform/inspector_protocol/Collections.h" | 9 #include "platform/inspector_protocol/Collections.h" |
| 10 #include "platform/inspector_protocol/FrontendChannel.h" | 10 #include "platform/inspector_protocol/FrontendChannel.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 return weak; | 70 return weak; |
| 71 } | 71 } |
| 72 | 72 |
| 73 virtual void dispatch(int sessionId, const String16& message); | 73 virtual void dispatch(int sessionId, const String16& message); |
| 74 virtual void reportProtocolError(int sessionId, int callId, CommonErrorCode,
const String16& errorMessage, ErrorSupport* errors) const; | 74 virtual void reportProtocolError(int sessionId, int callId, CommonErrorCode,
const String16& errorMessage, ErrorSupport* errors) const; |
| 75 using Dispatcher::reportProtocolError; | 75 using Dispatcher::reportProtocolError; |
| 76 | 76 |
| 77 void sendResponse(int sessionId, int callId, const ErrorString& invocationEr
ror, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result); | 77 void sendResponse(int sessionId, int callId, const ErrorString& invocationEr
ror, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result); |
| 78 | 78 |
| 79 {% for domain in api.domains %} | 79 {% for domain in api.domains %} |
| 80 virtual void registerAgent(blink::protocol::Backend::{{domain.domain}}* agen
t) { ASSERT(!m_{{domain.domain | lower}}Agent); m_{{domain.domain | lower}}Agent
= agent; } | 80 virtual void registerAgent(blink::protocol::Backend::{{domain.domain}}* agen
t) { DCHECK(!m_{{domain.domain | lower}}Agent); m_{{domain.domain | lower}}Agent
= agent; } |
| 81 {% endfor %} | 81 {% endfor %} |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 friend class DispatcherCallbackBase; | 84 friend class DispatcherCallbackBase; |
| 85 friend class DispatcherImplWeakPtr; | 85 friend class DispatcherImplWeakPtr; |
| 86 using CallHandler = void (DispatcherImpl::*)(int sessionId, int callId, Pass
OwnPtr<DictionaryValue> messageObject, ErrorSupport* errors); | 86 using CallHandler = void (DispatcherImpl::*)(int sessionId, int callId, Pass
OwnPtr<DictionaryValue> messageObject, ErrorSupport* errors); |
| 87 using DispatchMap = protocol::HashMap<String16, CallHandler>; | 87 using DispatchMap = protocol::HashMap<String16, CallHandler>; |
| 88 | 88 |
| 89 {% for domain in api.domains %} | 89 {% for domain in api.domains %} |
| 90 {% for command in domain.commands %} | 90 {% for command in domain.commands %} |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 resultObject->setValue("{{parameter.name}}", toValue({{parameter.nam
e}}.fromJust())); | 176 resultObject->setValue("{{parameter.name}}", toValue({{parameter.nam
e}}.fromJust())); |
| 177 {% else %} | 177 {% else %} |
| 178 resultObject->setValue("{{parameter.name}}", toValue({{resolve_type(para
meter).to_raw_type % parameter.name}})); | 178 resultObject->setValue("{{parameter.name}}", toValue({{resolve_type(para
meter).to_raw_type % parameter.name}})); |
| 179 {% endif %} | 179 {% endif %} |
| 180 {% endfor %} | 180 {% endfor %} |
| 181 sendIfActive(std::move(resultObject), ErrorString()); | 181 sendIfActive(std::move(resultObject), ErrorString()); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void sendFailure(const ErrorString& error) override | 184 void sendFailure(const ErrorString& error) override |
| 185 { | 185 { |
| 186 ASSERT(error.length()); | 186 DCHECK(error.length()); |
| 187 sendIfActive(nullptr, error); | 187 sendIfActive(nullptr, error); |
| 188 } | 188 } |
| 189 }; | 189 }; |
| 190 {% endif %} | 190 {% endif %} |
| 191 | 191 |
| 192 void DispatcherImpl::{{domain.domain}}_{{command.name}}(int sessionId, int callI
d, PassOwnPtr<DictionaryValue> requestMessageObject, ErrorSupport* errors) | 192 void DispatcherImpl::{{domain.domain}}_{{command.name}}(int sessionId, int callI
d, PassOwnPtr<DictionaryValue> requestMessageObject, ErrorSupport* errors) |
| 193 { | 193 { |
| 194 if (!m_{{domain.domain | lower}}Agent) | 194 if (!m_{{domain.domain | lower}}Agent) |
| 195 errors->addError("{{domain.domain}} handler is not available."); | 195 errors->addError("{{domain.domain}} handler is not available."); |
| 196 | 196 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 277 |
| 278 PassOwnPtr<Dispatcher> Dispatcher::create(FrontendChannel* frontendChannel) | 278 PassOwnPtr<Dispatcher> Dispatcher::create(FrontendChannel* frontendChannel) |
| 279 { | 279 { |
| 280 return adoptPtr(new DispatcherImpl(frontendChannel)); | 280 return adoptPtr(new DispatcherImpl(frontendChannel)); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void DispatcherImpl::dispatch(int sessionId, const String16& message) | 283 void DispatcherImpl::dispatch(int sessionId, const String16& message) |
| 284 { | 284 { |
| 285 int callId = 0; | 285 int callId = 0; |
| 286 OwnPtr<protocol::Value> parsedMessage = parseJSON(message); | 286 OwnPtr<protocol::Value> parsedMessage = parseJSON(message); |
| 287 ASSERT(parsedMessage); | 287 DCHECK(parsedMessage); |
| 288 OwnPtr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(std:
:move(parsedMessage)); | 288 OwnPtr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(std:
:move(parsedMessage)); |
| 289 ASSERT(messageObject); | 289 DCHECK(messageObject); |
| 290 | 290 |
| 291 protocol::Value* callIdValue = messageObject->get("id"); | 291 protocol::Value* callIdValue = messageObject->get("id"); |
| 292 bool success = callIdValue->asNumber(&callId); | 292 bool success = callIdValue->asNumber(&callId); |
| 293 ASSERT_UNUSED(success, success); | 293 DCHECK(success); |
| 294 | 294 |
| 295 protocol::Value* methodValue = messageObject->get("method"); | 295 protocol::Value* methodValue = messageObject->get("method"); |
| 296 String16 method; | 296 String16 method; |
| 297 success = methodValue && methodValue->asString(&method); | 297 success = methodValue && methodValue->asString(&method); |
| 298 ASSERT_UNUSED(success, success); | 298 DCHECK(success); |
| 299 | 299 |
| 300 protocol::HashMap<String16, CallHandler>::iterator it = m_dispatchMap.find(m
ethod); | 300 protocol::HashMap<String16, CallHandler>::iterator it = m_dispatchMap.find(m
ethod); |
| 301 if (it == m_dispatchMap.end()) { | 301 if (it == m_dispatchMap.end()) { |
| 302 reportProtocolError(sessionId, callId, MethodNotFound, "'" + method + "'
wasn't found"); | 302 reportProtocolError(sessionId, callId, MethodNotFound, "'" + method + "'
wasn't found"); |
| 303 return; | 303 return; |
| 304 } | 304 } |
| 305 | 305 |
| 306 protocol::ErrorSupport errors; | 306 protocol::ErrorSupport errors; |
| 307 ((*this).*(*it->second))(sessionId, callId, std::move(messageObject), &error
s); | 307 ((*this).*(*it->second))(sessionId, callId, std::move(messageObject), &error
s); |
| 308 } | 308 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 322 } | 322 } |
| 323 | 323 |
| 324 void Dispatcher::reportProtocolError(int sessionId, int callId, CommonErrorCode
code, const String16& errorMessage) const | 324 void Dispatcher::reportProtocolError(int sessionId, int callId, CommonErrorCode
code, const String16& errorMessage) const |
| 325 { | 325 { |
| 326 ErrorSupport errors; | 326 ErrorSupport errors; |
| 327 reportProtocolError(sessionId, callId, code, errorMessage, &errors); | 327 reportProtocolError(sessionId, callId, code, errorMessage, &errors); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void DispatcherImpl::reportProtocolError(int sessionId, int callId, CommonErrorC
ode code, const String16& errorMessage, ErrorSupport* errors) const | 330 void DispatcherImpl::reportProtocolError(int sessionId, int callId, CommonErrorC
ode code, const String16& errorMessage, ErrorSupport* errors) const |
| 331 { | 331 { |
| 332 ASSERT(code >=0); | 332 DCHECK(code >=0); |
| 333 ASSERT((unsigned)code < m_commonErrors.size()); | 333 DCHECK((unsigned)code < m_commonErrors.size()); |
| 334 ASSERT(m_commonErrors[code]); | 334 DCHECK(m_commonErrors[code]); |
| 335 OwnPtr<protocol::DictionaryValue> error = DictionaryValue::create(); | 335 OwnPtr<protocol::DictionaryValue> error = DictionaryValue::create(); |
| 336 error->setNumber("code", m_commonErrors[code]); | 336 error->setNumber("code", m_commonErrors[code]); |
| 337 error->setString("message", errorMessage); | 337 error->setString("message", errorMessage); |
| 338 ASSERT(error); | 338 DCHECK(error); |
| 339 if (errors && errors->hasErrors()) | 339 if (errors && errors->hasErrors()) |
| 340 error->setString("data", errors->errors()); | 340 error->setString("data", errors->errors()); |
| 341 OwnPtr<protocol::DictionaryValue> message = DictionaryValue::create(); | 341 OwnPtr<protocol::DictionaryValue> message = DictionaryValue::create(); |
| 342 message->setObject("error", std::move(error)); | 342 message->setObject("error", std::move(error)); |
| 343 message->setNumber("id", callId); | 343 message->setNumber("id", callId); |
| 344 if (m_frontendChannel) | 344 if (m_frontendChannel) |
| 345 m_frontendChannel->sendProtocolResponse(sessionId, callId, std::move(mes
sage)); | 345 m_frontendChannel->sendProtocolResponse(sessionId, callId, std::move(mes
sage)); |
| 346 } | 346 } |
| 347 | 347 |
| 348 bool Dispatcher::getCommandName(const String16& message, String16* result) | 348 bool Dispatcher::getCommandName(const String16& message, String16* result) |
| 349 { | 349 { |
| 350 OwnPtr<protocol::Value> value = parseJSON(message); | 350 OwnPtr<protocol::Value> value = parseJSON(message); |
| 351 if (!value) | 351 if (!value) |
| 352 return false; | 352 return false; |
| 353 | 353 |
| 354 protocol::DictionaryValue* object = DictionaryValue::cast(value.get()); | 354 protocol::DictionaryValue* object = DictionaryValue::cast(value.get()); |
| 355 if (!object) | 355 if (!object) |
| 356 return false; | 356 return false; |
| 357 | 357 |
| 358 if (!object->getString("method", result)) | 358 if (!object->getString("method", result)) |
| 359 return false; | 359 return false; |
| 360 | 360 |
| 361 return true; | 361 return true; |
| 362 } | 362 } |
| 363 | 363 |
| 364 } // namespace protocol | 364 } // namespace protocol |
| 365 } // namespace blink | 365 } // namespace blink |
| OLD | NEW |