| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 ~DispatcherImpl() { clearFrontend(); } | 56 ~DispatcherImpl() { clearFrontend(); } |
| 57 | 57 |
| 58 virtual void clearFrontend() | 58 virtual void clearFrontend() |
| 59 { | 59 { |
| 60 m_frontendChannel = nullptr; | 60 m_frontendChannel = nullptr; |
| 61 for (auto& weak : m_weakPtrs) | 61 for (auto& weak : m_weakPtrs) |
| 62 weak.first->dispose(); | 62 weak.first->dispose(); |
| 63 m_weakPtrs.clear(); | 63 m_weakPtrs.clear(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 PassOwnPtr<DispatcherImplWeakPtr> weakPtr() | 66 std::unique_ptr<DispatcherImplWeakPtr> weakPtr() |
| 67 { | 67 { |
| 68 OwnPtr<DispatcherImplWeakPtr> weak = adoptPtr(new DispatcherImplWeakPtr(
this)); | 68 std::unique_ptr<DispatcherImplWeakPtr> weak(new DispatcherImplWeakPtr(th
is)); |
| 69 m_weakPtrs.add(weak.get()); | 69 m_weakPtrs.add(weak.get()); |
| 70 return weak; | 70 return weak; |
| 71 } | 71 } |
| 72 | 72 |
| 73 virtual void dispatch(const String16& message); | 73 virtual void dispatch(const String16& message); |
| 74 virtual void reportProtocolError(int callId, CommonErrorCode, const String16
& errorMessage, ErrorSupport* errors) const; | 74 virtual void reportProtocolError(int callId, CommonErrorCode, const String16
& errorMessage, ErrorSupport* errors) const; |
| 75 using Dispatcher::reportProtocolError; | 75 using Dispatcher::reportProtocolError; |
| 76 | 76 |
| 77 void sendResponse(int callId, const ErrorString& invocationError, ErrorSuppo
rt* errors, PassOwnPtr<protocol::DictionaryValue> result); | 77 void sendResponse(int callId, const ErrorString& invocationError, ErrorSuppo
rt* errors, std::unique_ptr<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) { DCHECK(!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 callId, PassOwnPtr<Dictiona
ryValue> messageObject, ErrorSupport* errors); | 86 using CallHandler = void (DispatcherImpl::*)(int callId, std::unique_ptr<Dic
tionaryValue> 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 %} |
| 91 {% if "redirect" in command %}{% continue %}{% endif %} | 91 {% if "redirect" in command %}{% continue %}{% endif %} |
| 92 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{%
continue %}{% endif %} | 92 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{%
continue %}{% endif %} |
| 93 void {{domain.domain}}_{{command.name}}(int callId, PassOwnPtr<DictionaryVal
ue> requestMessageObject, ErrorSupport*); | 93 void {{domain.domain}}_{{command.name}}(int callId, std::unique_ptr<Dictiona
ryValue> requestMessageObject, ErrorSupport*); |
| 94 {% endfor %} | 94 {% endfor %} |
| 95 {% endfor %} | 95 {% endfor %} |
| 96 | 96 |
| 97 FrontendChannel* m_frontendChannel; | 97 FrontendChannel* m_frontendChannel; |
| 98 | 98 |
| 99 {% for domain in api.domains %} | 99 {% for domain in api.domains %} |
| 100 Backend::{{domain.domain}}* m_{{domain.domain | lower}}Agent; | 100 Backend::{{domain.domain}}* m_{{domain.domain | lower}}Agent; |
| 101 {% endfor %} | 101 {% endfor %} |
| 102 | 102 |
| 103 void sendResponse(int callId, ErrorString invocationError, PassOwnPtr<protoc
ol::DictionaryValue> result) | 103 void sendResponse(int callId, ErrorString invocationError, std::unique_ptr<p
rotocol::DictionaryValue> result) |
| 104 { | 104 { |
| 105 sendResponse(callId, invocationError, nullptr, std::move(result)); | 105 sendResponse(callId, invocationError, nullptr, std::move(result)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void sendResponse(int callId, ErrorString invocationError) | 108 void sendResponse(int callId, ErrorString invocationError) |
| 109 { | 109 { |
| 110 sendResponse(callId, invocationError, nullptr, DictionaryValue::create()
); | 110 sendResponse(callId, invocationError, nullptr, DictionaryValue::create()
); |
| 111 } | 111 } |
| 112 | 112 |
| 113 static const char kInvalidRequest[]; | 113 static const char kInvalidRequest[]; |
| 114 | 114 |
| 115 DispatchMap m_dispatchMap; | 115 DispatchMap m_dispatchMap; |
| 116 protocol::Vector<int> m_commonErrors; | 116 protocol::Vector<int> m_commonErrors; |
| 117 protocol::HashSet<DispatcherImplWeakPtr*> m_weakPtrs; | 117 protocol::HashSet<DispatcherImplWeakPtr*> m_weakPtrs; |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 class PLATFORM_EXPORT DispatcherCallbackBase : public protocol::Backend::Callbac
kBase { | 120 class PLATFORM_EXPORT DispatcherCallbackBase : public protocol::Backend::Callbac
kBase { |
| 121 public: | 121 public: |
| 122 DispatcherCallbackBase(PassOwnPtr<DispatcherImplWeakPtr> backendImpl, int ca
llId) | 122 DispatcherCallbackBase(std::unique_ptr<DispatcherImplWeakPtr> backendImpl, i
nt callId) |
| 123 : m_backendImpl(std::move(backendImpl)), m_callId(callId) { } | 123 : m_backendImpl(std::move(backendImpl)), m_callId(callId) { } |
| 124 virtual ~DispatcherCallbackBase() { } | 124 virtual ~DispatcherCallbackBase() { } |
| 125 void dispose() { m_backendImpl = nullptr; } | 125 void dispose() { m_backendImpl = nullptr; } |
| 126 | 126 |
| 127 protected: | 127 protected: |
| 128 void sendIfActive(PassOwnPtr<protocol::DictionaryValue> partialMessage, cons
t ErrorString& invocationError) | 128 void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage,
const ErrorString& invocationError) |
| 129 { | 129 { |
| 130 if (!m_backendImpl->get()) | 130 if (!m_backendImpl->get()) |
| 131 return; | 131 return; |
| 132 m_backendImpl->get()->sendResponse(m_callId, invocationError, nullptr, s
td::move(partialMessage)); | 132 m_backendImpl->get()->sendResponse(m_callId, invocationError, nullptr, s
td::move(partialMessage)); |
| 133 m_backendImpl = nullptr; | 133 m_backendImpl = nullptr; |
| 134 } | 134 } |
| 135 | 135 |
| 136 private: | 136 private: |
| 137 OwnPtr<DispatcherImplWeakPtr> m_backendImpl; | 137 std::unique_ptr<DispatcherImplWeakPtr> m_backendImpl; |
| 138 int m_callId; | 138 int m_callId; |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 DispatcherImplWeakPtr::~DispatcherImplWeakPtr() | 141 DispatcherImplWeakPtr::~DispatcherImplWeakPtr() |
| 142 { | 142 { |
| 143 if (m_dispatcher) | 143 if (m_dispatcher) |
| 144 m_dispatcher->m_weakPtrs.remove(this); | 144 m_dispatcher->m_weakPtrs.remove(this); |
| 145 } | 145 } |
| 146 | 146 |
| 147 const char DispatcherImpl::kInvalidRequest[] = "Invalid request"; | 147 const char DispatcherImpl::kInvalidRequest[] = "Invalid request"; |
| 148 | 148 |
| 149 {% for domain in api.domains %} | 149 {% for domain in api.domains %} |
| 150 {% for command in domain.commands %} | 150 {% for command in domain.commands %} |
| 151 {% if "redirect" in command %}{% continue %}{% endif %} | 151 {% if "redirect" in command %}{% continue %}{% endif %} |
| 152 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{%
continue %}{% endif %} | 152 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{%
continue %}{% endif %} |
| 153 | 153 |
| 154 {% if "async" in command %} | 154 {% if "async" in command %} |
| 155 | 155 |
| 156 class PLATFORM_EXPORT {{domain.domain}}{{command.name | to_title_case}}Callback
: public Backend::{{domain.domain}}::{{command.name | to_title_case}}Callback, p
ublic DispatcherCallbackBase { | 156 class PLATFORM_EXPORT {{domain.domain}}{{command.name | to_title_case}}Callback
: public Backend::{{domain.domain}}::{{command.name | to_title_case}}Callback, p
ublic DispatcherCallbackBase { |
| 157 public: | 157 public: |
| 158 {{domain.domain}}{{command.name | to_title_case}}Callback(PassOwnPtr<Dispatc
herImplWeakPtr> backendImpl, int callId) | 158 {{domain.domain}}{{command.name | to_title_case}}Callback(std::unique_ptr<Di
spatcherImplWeakPtr> backendImpl, int callId) |
| 159 : DispatcherCallbackBase(std::move(backendImpl), callId) { } | 159 : DispatcherCallbackBase(std::move(backendImpl), callId) { } |
| 160 | 160 |
| 161 void sendSuccess( | 161 void sendSuccess( |
| 162 {%- for parameter in command.returns -%} | 162 {%- for parameter in command.returns -%} |
| 163 {%- if "optional" in parameter -%} | 163 {%- if "optional" in parameter -%} |
| 164 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} | 164 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} |
| 165 {%- else -%} | 165 {%- else -%} |
| 166 {{resolve_type(parameter).pass_type}} {{parameter.name}} | 166 {{resolve_type(parameter).pass_type}} {{parameter.name}} |
| 167 {%- endif -%} | 167 {%- endif -%} |
| 168 {%- if not loop.last -%}, {% endif -%} | 168 {%- if not loop.last -%}, {% endif -%} |
| 169 {%- endfor -%}) override | 169 {%- endfor -%}) override |
| 170 { | 170 { |
| 171 OwnPtr<protocol::DictionaryValue> resultObject = DictionaryValue::create
(); | 171 std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValu
e::create(); |
| 172 {% for parameter in command.returns %} | 172 {% for parameter in command.returns %} |
| 173 {% if "optional" in parameter %} | 173 {% if "optional" in parameter %} |
| 174 if ({{parameter.name}}.isJust()) | 174 if ({{parameter.name}}.isJust()) |
| 175 resultObject->setValue("{{parameter.name}}", toValue({{parameter.nam
e}}.fromJust())); | 175 resultObject->setValue("{{parameter.name}}", toValue({{parameter.nam
e}}.fromJust())); |
| 176 {% else %} | 176 {% else %} |
| 177 resultObject->setValue("{{parameter.name}}", toValue({{resolve_type(para
meter).to_raw_type % parameter.name}})); | 177 resultObject->setValue("{{parameter.name}}", toValue({{resolve_type(para
meter).to_raw_type % parameter.name}})); |
| 178 {% endif %} | 178 {% endif %} |
| 179 {% endfor %} | 179 {% endfor %} |
| 180 sendIfActive(std::move(resultObject), ErrorString()); | 180 sendIfActive(std::move(resultObject), ErrorString()); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void sendFailure(const ErrorString& error) override | 183 void sendFailure(const ErrorString& error) override |
| 184 { | 184 { |
| 185 DCHECK(error.length()); | 185 DCHECK(error.length()); |
| 186 sendIfActive(nullptr, error); | 186 sendIfActive(nullptr, error); |
| 187 } | 187 } |
| 188 }; | 188 }; |
| 189 {% endif %} | 189 {% endif %} |
| 190 | 190 |
| 191 void DispatcherImpl::{{domain.domain}}_{{command.name}}(int callId, PassOwnPtr<D
ictionaryValue> requestMessageObject, ErrorSupport* errors) | 191 void DispatcherImpl::{{domain.domain}}_{{command.name}}(int callId, std::unique_
ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors) |
| 192 { | 192 { |
| 193 if (!m_{{domain.domain | lower}}Agent) | 193 if (!m_{{domain.domain | lower}}Agent) |
| 194 errors->addError("{{domain.domain}} handler is not available."); | 194 errors->addError("{{domain.domain}} handler is not available."); |
| 195 | 195 |
| 196 if (errors->hasErrors()) { | 196 if (errors->hasErrors()) { |
| 197 reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); | 197 reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 {% if "parameters" in command %} | 200 {% if "parameters" in command %} |
| 201 | 201 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 216 {% endif %} | 216 {% endif %} |
| 217 {% endfor %} | 217 {% endfor %} |
| 218 errors->pop(); | 218 errors->pop(); |
| 219 if (errors->hasErrors()) { | 219 if (errors->hasErrors()) { |
| 220 reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); | 220 reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); |
| 221 return; | 221 return; |
| 222 } | 222 } |
| 223 {% endif %} | 223 {% endif %} |
| 224 | 224 |
| 225 {% if "async" in command %} | 225 {% if "async" in command %} |
| 226 OwnPtr<{{domain.domain}}{{command.name | to_title_case}}Callback> callback =
adoptPtr(new {{domain.domain}}{{command.name | to_title_case}}Callback(weakPtr(
), callId)); | 226 std::unique_ptr<{{domain.domain}}{{command.name | to_title_case}}Callback> c
allback(new {{domain.domain}}{{command.name | to_title_case}}Callback(weakPtr(),
callId)); |
| 227 {% elif "returns" in command %} | 227 {% elif "returns" in command %} |
| 228 // Declare output parameters. | 228 // Declare output parameters. |
| 229 OwnPtr<protocol::DictionaryValue> result = DictionaryValue::create(); | 229 std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create(
); |
| 230 {% for property in command.returns %} | 230 {% for property in command.returns %} |
| 231 {% if "optional" in property %} | 231 {% if "optional" in property %} |
| 232 Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}}; | 232 Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}}; |
| 233 {% else %} | 233 {% else %} |
| 234 {{resolve_type(property).type}} out_{{property.name}}; | 234 {{resolve_type(property).type}} out_{{property.name}}; |
| 235 {% endif %} | 235 {% endif %} |
| 236 {% endfor %} | 236 {% endfor %} |
| 237 {% endif %} | 237 {% endif %} |
| 238 | 238 |
| 239 OwnPtr<DispatcherImplWeakPtr> weak = weakPtr(); | 239 std::unique_ptr<DispatcherImplWeakPtr> weak = weakPtr(); |
| 240 ErrorString error; | 240 ErrorString error; |
| 241 m_{{domain.domain | lower}}Agent->{{command.name}}(&error | 241 m_{{domain.domain | lower}}Agent->{{command.name}}(&error |
| 242 {%- for property in command.parameters -%} | 242 {%- for property in command.parameters -%} |
| 243 {%- if "optional" in property -%} | 243 {%- if "optional" in property -%} |
| 244 , in_{{property.name}} | 244 , in_{{property.name}} |
| 245 {%- else -%} | 245 {%- else -%} |
| 246 , {{resolve_type(property).to_pass_type % ("in_" + property.name)}} | 246 , {{resolve_type(property).to_pass_type % ("in_" + property.name)}} |
| 247 {%- endif -%} | 247 {%- endif -%} |
| 248 {%- endfor %} | 248 {%- endfor %} |
| 249 {%- if "async" in command -%} | 249 {%- if "async" in command -%} |
| (...skipping 17 matching lines...) Expand all Loading... |
| 267 if (weak->get()) | 267 if (weak->get()) |
| 268 weak->get()->sendResponse(callId, error, std::move(result)); | 268 weak->get()->sendResponse(callId, error, std::move(result)); |
| 269 {% elif not("async" in command) %} | 269 {% elif not("async" in command) %} |
| 270 if (weak->get()) | 270 if (weak->get()) |
| 271 weak->get()->sendResponse(callId, error); | 271 weak->get()->sendResponse(callId, error); |
| 272 {% endif %} | 272 {% endif %} |
| 273 } | 273 } |
| 274 {% endfor %} | 274 {% endfor %} |
| 275 {% endfor %} | 275 {% endfor %} |
| 276 | 276 |
| 277 PassOwnPtr<Dispatcher> Dispatcher::create(FrontendChannel* frontendChannel) | 277 std::unique_ptr<Dispatcher> Dispatcher::create(FrontendChannel* frontendChannel) |
| 278 { | 278 { |
| 279 return adoptPtr(new DispatcherImpl(frontendChannel)); | 279 return wrapUnique(new DispatcherImpl(frontendChannel)); |
| 280 } | 280 } |
| 281 | 281 |
| 282 void DispatcherImpl::dispatch(const String16& message) | 282 void DispatcherImpl::dispatch(const String16& message) |
| 283 { | 283 { |
| 284 int callId = 0; | 284 int callId = 0; |
| 285 OwnPtr<protocol::Value> parsedMessage = parseJSON(message); | 285 std::unique_ptr<protocol::Value> parsedMessage = parseJSON(message); |
| 286 DCHECK(parsedMessage); | 286 DCHECK(parsedMessage); |
| 287 OwnPtr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(std:
:move(parsedMessage)); | 287 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue::
cast(std::move(parsedMessage)); |
| 288 DCHECK(messageObject); | 288 DCHECK(messageObject); |
| 289 | 289 |
| 290 protocol::Value* callIdValue = messageObject->get("id"); | 290 protocol::Value* callIdValue = messageObject->get("id"); |
| 291 bool success = callIdValue->asNumber(&callId); | 291 bool success = callIdValue->asNumber(&callId); |
| 292 DCHECK(success); | 292 DCHECK(success); |
| 293 | 293 |
| 294 protocol::Value* methodValue = messageObject->get("method"); | 294 protocol::Value* methodValue = messageObject->get("method"); |
| 295 String16 method; | 295 String16 method; |
| 296 success = methodValue && methodValue->asString(&method); | 296 success = methodValue && methodValue->asString(&method); |
| 297 DCHECK(success); | 297 DCHECK(success); |
| 298 | 298 |
| 299 protocol::HashMap<String16, CallHandler>::iterator it = m_dispatchMap.find(m
ethod); | 299 protocol::HashMap<String16, CallHandler>::iterator it = m_dispatchMap.find(m
ethod); |
| 300 if (it == m_dispatchMap.end()) { | 300 if (it == m_dispatchMap.end()) { |
| 301 reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't fou
nd"); | 301 reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't fou
nd"); |
| 302 return; | 302 return; |
| 303 } | 303 } |
| 304 | 304 |
| 305 protocol::ErrorSupport errors; | 305 protocol::ErrorSupport errors; |
| 306 ((*this).*(*it->second))(callId, std::move(messageObject), &errors); | 306 ((*this).*(*it->second))(callId, std::move(messageObject), &errors); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void DispatcherImpl::sendResponse(int callId, const ErrorString& invocationError
, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result) | 309 void DispatcherImpl::sendResponse(int callId, const ErrorString& invocationError
, ErrorSupport* errors, std::unique_ptr<protocol::DictionaryValue> result) |
| 310 { | 310 { |
| 311 if (invocationError.length() || (errors && errors->hasErrors())) { | 311 if (invocationError.length() || (errors && errors->hasErrors())) { |
| 312 reportProtocolError(callId, ServerError, invocationError, errors); | 312 reportProtocolError(callId, ServerError, invocationError, errors); |
| 313 return; | 313 return; |
| 314 } | 314 } |
| 315 | 315 |
| 316 OwnPtr<protocol::DictionaryValue> responseMessage = DictionaryValue::create(
); | 316 std::unique_ptr<protocol::DictionaryValue> responseMessage = DictionaryValue
::create(); |
| 317 responseMessage->setNumber("id", callId); | 317 responseMessage->setNumber("id", callId); |
| 318 responseMessage->setObject("result", std::move(result)); | 318 responseMessage->setObject("result", std::move(result)); |
| 319 if (m_frontendChannel) | 319 if (m_frontendChannel) |
| 320 m_frontendChannel->sendProtocolResponse(callId, responseMessage->toJSONS
tring()); | 320 m_frontendChannel->sendProtocolResponse(callId, responseMessage->toJSONS
tring()); |
| 321 } | 321 } |
| 322 | 322 |
| 323 void Dispatcher::reportProtocolError(int callId, CommonErrorCode code, const Str
ing16& errorMessage) const | 323 void Dispatcher::reportProtocolError(int callId, CommonErrorCode code, const Str
ing16& errorMessage) const |
| 324 { | 324 { |
| 325 ErrorSupport errors; | 325 ErrorSupport errors; |
| 326 reportProtocolError(callId, code, errorMessage, &errors); | 326 reportProtocolError(callId, code, errorMessage, &errors); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void DispatcherImpl::reportProtocolError(int callId, CommonErrorCode code, const
String16& errorMessage, ErrorSupport* errors) const | 329 void DispatcherImpl::reportProtocolError(int callId, CommonErrorCode code, const
String16& errorMessage, ErrorSupport* errors) const |
| 330 { | 330 { |
| 331 DCHECK(code >=0); | 331 DCHECK(code >=0); |
| 332 DCHECK((unsigned)code < m_commonErrors.size()); | 332 DCHECK((unsigned)code < m_commonErrors.size()); |
| 333 DCHECK(m_commonErrors[code]); | 333 DCHECK(m_commonErrors[code]); |
| 334 OwnPtr<protocol::DictionaryValue> error = DictionaryValue::create(); | 334 std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create()
; |
| 335 error->setNumber("code", m_commonErrors[code]); | 335 error->setNumber("code", m_commonErrors[code]); |
| 336 error->setString("message", errorMessage); | 336 error->setString("message", errorMessage); |
| 337 DCHECK(error); | 337 DCHECK(error); |
| 338 if (errors && errors->hasErrors()) | 338 if (errors && errors->hasErrors()) |
| 339 error->setString("data", errors->errors()); | 339 error->setString("data", errors->errors()); |
| 340 OwnPtr<protocol::DictionaryValue> message = DictionaryValue::create(); | 340 std::unique_ptr<protocol::DictionaryValue> message = DictionaryValue::create
(); |
| 341 message->setObject("error", std::move(error)); | 341 message->setObject("error", std::move(error)); |
| 342 message->setNumber("id", callId); | 342 message->setNumber("id", callId); |
| 343 if (m_frontendChannel) | 343 if (m_frontendChannel) |
| 344 m_frontendChannel->sendProtocolResponse(callId, message->toJSONString())
; | 344 m_frontendChannel->sendProtocolResponse(callId, message->toJSONString())
; |
| 345 } | 345 } |
| 346 | 346 |
| 347 bool Dispatcher::getCommandName(const String16& message, String16* result) | 347 bool Dispatcher::getCommandName(const String16& message, String16* result) |
| 348 { | 348 { |
| 349 OwnPtr<protocol::Value> value = parseJSON(message); | 349 std::unique_ptr<protocol::Value> value = parseJSON(message); |
| 350 if (!value) | 350 if (!value) |
| 351 return false; | 351 return false; |
| 352 | 352 |
| 353 protocol::DictionaryValue* object = DictionaryValue::cast(value.get()); | 353 protocol::DictionaryValue* object = DictionaryValue::cast(value.get()); |
| 354 if (!object) | 354 if (!object) |
| 355 return false; | 355 return false; |
| 356 | 356 |
| 357 if (!object->getString("method", result)) | 357 if (!object->getString("method", result)) |
| 358 return false; | 358 return false; |
| 359 | 359 |
| 360 return true; | 360 return true; |
| 361 } | 361 } |
| 362 | 362 |
| 363 } // namespace protocol | 363 } // namespace protocol |
| 364 } // namespace blink | 364 } // namespace blink |
| OLD | NEW |