| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/inspector_protocol/DispatcherBase.h" | 5 #include "platform/inspector_protocol/DispatcherBase.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/FrontendChannel.h" | 7 #include "platform/inspector_protocol/FrontendChannel.h" |
| 8 #include "platform/inspector_protocol/Parser.h" | 8 #include "platform/inspector_protocol/Parser.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError
, ErrorSupport* errors, std::unique_ptr<protocol::DictionaryValue> result) | 68 void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError
, ErrorSupport* errors, std::unique_ptr<protocol::DictionaryValue> result) |
| 69 { | 69 { |
| 70 if (invocationError.length() || (errors && errors->hasErrors())) { | 70 if (invocationError.length() || (errors && errors->hasErrors())) { |
| 71 reportProtocolError(callId, ServerError, invocationError, errors); | 71 reportProtocolError(callId, ServerError, invocationError, errors); |
| 72 return; | 72 return; |
| 73 } | 73 } |
| 74 | 74 |
| 75 std::unique_ptr<protocol::DictionaryValue> responseMessage = DictionaryValue
::create(); | 75 std::unique_ptr<protocol::DictionaryValue> responseMessage = DictionaryValue
::create(); |
| 76 responseMessage->setNumber("id", callId); | 76 responseMessage->setInteger("id", callId); |
| 77 responseMessage->setObject("result", std::move(result)); | 77 responseMessage->setObject("result", std::move(result)); |
| 78 if (m_frontendChannel) | 78 if (m_frontendChannel) |
| 79 m_frontendChannel->sendProtocolResponse(callId, responseMessage->toJSONS
tring()); | 79 m_frontendChannel->sendProtocolResponse(callId, responseMessage->toJSONS
tring()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError
, std::unique_ptr<protocol::DictionaryValue> result) | 82 void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError
, std::unique_ptr<protocol::DictionaryValue> result) |
| 83 { | 83 { |
| 84 sendResponse(callId, invocationError, nullptr, std::move(result)); | 84 sendResponse(callId, invocationError, nullptr, std::move(result)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError
) | 87 void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError
) |
| 88 { | 88 { |
| 89 sendResponse(callId, invocationError, nullptr, DictionaryValue::create()); | 89 sendResponse(callId, invocationError, nullptr, DictionaryValue::create()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 static void reportProtocolError(FrontendChannel* frontendChannel, int callId, Di
spatcherBase::CommonErrorCode code, const String16& errorMessage, ErrorSupport*
errors) | 92 static void reportProtocolError(FrontendChannel* frontendChannel, int callId, Di
spatcherBase::CommonErrorCode code, const String16& errorMessage, ErrorSupport*
errors) |
| 93 { | 93 { |
| 94 std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create()
; | 94 std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create()
; |
| 95 error->setNumber("code", code); | 95 error->setInteger("code", code); |
| 96 error->setString("message", errorMessage); | 96 error->setString("message", errorMessage); |
| 97 DCHECK(error); | 97 DCHECK(error); |
| 98 if (errors && errors->hasErrors()) | 98 if (errors && errors->hasErrors()) |
| 99 error->setString("data", errors->errors()); | 99 error->setString("data", errors->errors()); |
| 100 std::unique_ptr<protocol::DictionaryValue> message = DictionaryValue::create
(); | 100 std::unique_ptr<protocol::DictionaryValue> message = DictionaryValue::create
(); |
| 101 message->setObject("error", std::move(error)); | 101 message->setObject("error", std::move(error)); |
| 102 message->setNumber("id", callId); | 102 message->setInteger("id", callId); |
| 103 frontendChannel->sendProtocolResponse(callId, message->toJSONString()); | 103 frontendChannel->sendProtocolResponse(callId, message->toJSONString()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void DispatcherBase::reportProtocolError(int callId, CommonErrorCode code, const
String16& errorMessage, ErrorSupport* errors) | 106 void DispatcherBase::reportProtocolError(int callId, CommonErrorCode code, const
String16& errorMessage, ErrorSupport* errors) |
| 107 { | 107 { |
| 108 if (m_frontendChannel) | 108 if (m_frontendChannel) |
| 109 ::blink::protocol::reportProtocolError(m_frontendChannel, callId, code,
errorMessage, errors); | 109 ::blink::protocol::reportProtocolError(m_frontendChannel, callId, code,
errorMessage, errors); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void DispatcherBase::clearFrontend() | 112 void DispatcherBase::clearFrontend() |
| (...skipping 23 matching lines...) Expand all Loading... |
| 136 { | 136 { |
| 137 std::unique_ptr<protocol::Value> parsedMessage = parseJSON(message); | 137 std::unique_ptr<protocol::Value> parsedMessage = parseJSON(message); |
| 138 if (!parsedMessage) | 138 if (!parsedMessage) |
| 139 return; | 139 return; |
| 140 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue::
cast(std::move(parsedMessage)); | 140 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue::
cast(std::move(parsedMessage)); |
| 141 if (!messageObject) | 141 if (!messageObject) |
| 142 return; | 142 return; |
| 143 | 143 |
| 144 int callId = 0; | 144 int callId = 0; |
| 145 protocol::Value* callIdValue = messageObject->get("id"); | 145 protocol::Value* callIdValue = messageObject->get("id"); |
| 146 bool success = callIdValue->asNumber(&callId); | 146 bool success = callIdValue->asInteger(&callId); |
| 147 if (!success) | 147 if (!success) |
| 148 return; | 148 return; |
| 149 | 149 |
| 150 protocol::Value* methodValue = messageObject->get("method"); | 150 protocol::Value* methodValue = messageObject->get("method"); |
| 151 String16 method; | 151 String16 method; |
| 152 success = methodValue && methodValue->asString(&method); | 152 success = methodValue && methodValue->asString(&method); |
| 153 if (!success) | 153 if (!success) |
| 154 return; | 154 return; |
| 155 | 155 |
| 156 size_t dotIndex = method.find("."); | 156 size_t dotIndex = method.find("."); |
| 157 if (dotIndex == kNotFound) { | 157 if (dotIndex == kNotFound) { |
| 158 reportProtocolError(m_frontendChannel, callId, DispatcherBase::MethodNot
Found, "'" + method + "' wasn't found", nullptr); | 158 reportProtocolError(m_frontendChannel, callId, DispatcherBase::MethodNot
Found, "'" + method + "' wasn't found", nullptr); |
| 159 return; | 159 return; |
| 160 } | 160 } |
| 161 String16 domain = method.substring(0, dotIndex); | 161 String16 domain = method.substring(0, dotIndex); |
| 162 auto it = m_dispatchers.find(domain); | 162 auto it = m_dispatchers.find(domain); |
| 163 if (it == m_dispatchers.end()) { | 163 if (it == m_dispatchers.end()) { |
| 164 reportProtocolError(m_frontendChannel, callId, DispatcherBase::MethodNot
Found, "'" + method + "' wasn't found", nullptr); | 164 reportProtocolError(m_frontendChannel, callId, DispatcherBase::MethodNot
Found, "'" + method + "' wasn't found", nullptr); |
| 165 return; | 165 return; |
| 166 } | 166 } |
| 167 it->second->dispatch(callId, method, std::move(messageObject)); | 167 it->second->dispatch(callId, method, std::move(messageObject)); |
| 168 } | 168 } |
| 169 | 169 |
| 170 UberDispatcher::~UberDispatcher() = default; | 170 UberDispatcher::~UberDispatcher() = default; |
| 171 | 171 |
| 172 } // namespace protocol | 172 } // namespace protocol |
| 173 } // namespace blink | 173 } // namespace blink |
| OLD | NEW |