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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 m_weakPtrs.clear(); | 63 m_weakPtrs.clear(); |
64 } | 64 } |
65 | 65 |
66 PassOwnPtr<DispatcherImplWeakPtr> weakPtr() | 66 PassOwnPtr<DispatcherImplWeakPtr> weakPtr() |
67 { | 67 { |
68 OwnPtr<DispatcherImplWeakPtr> weak = adoptPtr(new DispatcherImplWeakPtr(
this)); | 68 OwnPtr<DispatcherImplWeakPtr> weak = adoptPtr(new DispatcherImplWeakPtr(
this)); |
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(int sessionId, const String16& message); | 73 virtual void dispatch(const String16& message); |
74 virtual void reportProtocolError(int sessionId, 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 sessionId, int callId, const ErrorString& invocationEr
ror, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result); | 77 void sendResponse(int callId, const ErrorString& invocationError, ErrorSuppo
rt* 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) { 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 sessionId, int callId, Pass
OwnPtr<DictionaryValue> messageObject, ErrorSupport* errors); | 86 using CallHandler = void (DispatcherImpl::*)(int callId, PassOwnPtr<Dictiona
ryValue> 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 sessionId, int callId, PassOwnPt
r<DictionaryValue> requestMessageObject, ErrorSupport*); | 93 void {{domain.domain}}_{{command.name}}(int callId, PassOwnPtr<DictionaryVal
ue> 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 sessionId, int callId, ErrorString invocationError, Pa
ssOwnPtr<protocol::DictionaryValue> result) | 103 void sendResponse(int callId, ErrorString invocationError, PassOwnPtr<protoc
ol::DictionaryValue> result) |
104 { | 104 { |
105 sendResponse(sessionId, callId, invocationError, nullptr, std::move(resu
lt)); | 105 sendResponse(callId, invocationError, nullptr, std::move(result)); |
106 } | 106 } |
107 | 107 |
108 void sendResponse(int sessionId, int callId, ErrorString invocationError) | 108 void sendResponse(int callId, ErrorString invocationError) |
109 { | 109 { |
110 sendResponse(sessionId, callId, invocationError, nullptr, DictionaryValu
e::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 se
ssionId, int id) | 122 DispatcherCallbackBase(PassOwnPtr<DispatcherImplWeakPtr> backendImpl, int ca
llId) |
123 : m_backendImpl(std::move(backendImpl)), m_sessionId(sessionId), m_id(id
) { } | 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(PassOwnPtr<protocol::DictionaryValue> partialMessage, cons
t ErrorString& invocationError) |
129 { | 129 { |
130 if (!m_backendImpl->get()) | 130 if (!m_backendImpl->get()) |
131 return; | 131 return; |
132 m_backendImpl->get()->sendResponse(m_sessionId, m_id, invocationError, n
ullptr, std::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 OwnPtr<DispatcherImplWeakPtr> m_backendImpl; |
138 int m_sessionId; | 138 int m_callId; |
139 int m_id; | |
140 }; | 139 }; |
141 | 140 |
142 DispatcherImplWeakPtr::~DispatcherImplWeakPtr() | 141 DispatcherImplWeakPtr::~DispatcherImplWeakPtr() |
143 { | 142 { |
144 if (m_dispatcher) | 143 if (m_dispatcher) |
145 m_dispatcher->m_weakPtrs.remove(this); | 144 m_dispatcher->m_weakPtrs.remove(this); |
146 } | 145 } |
147 | 146 |
148 const char DispatcherImpl::kInvalidRequest[] = "Invalid request"; | 147 const char DispatcherImpl::kInvalidRequest[] = "Invalid request"; |
149 | 148 |
150 {% for domain in api.domains %} | 149 {% for domain in api.domains %} |
151 {% for command in domain.commands %} | 150 {% for command in domain.commands %} |
152 {% if "redirect" in command %}{% continue %}{% endif %} | 151 {% if "redirect" in command %}{% continue %}{% endif %} |
153 {% 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 %} |
154 | 153 |
155 {% if "async" in command %} | 154 {% if "async" in command %} |
156 | 155 |
157 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 { |
158 public: | 157 public: |
159 {{domain.domain}}{{command.name | to_title_case}}Callback(PassOwnPtr<Dispatc
herImplWeakPtr> backendImpl, int sessionId, int id) | 158 {{domain.domain}}{{command.name | to_title_case}}Callback(PassOwnPtr<Dispatc
herImplWeakPtr> backendImpl, int callId) |
160 : DispatcherCallbackBase(std::move(backendImpl), sessionId, id) { } | 159 : DispatcherCallbackBase(std::move(backendImpl), callId) { } |
161 | 160 |
162 void sendSuccess( | 161 void sendSuccess( |
163 {%- for parameter in command.returns -%} | 162 {%- for parameter in command.returns -%} |
164 {%- if "optional" in parameter -%} | 163 {%- if "optional" in parameter -%} |
165 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} | 164 const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} |
166 {%- else -%} | 165 {%- else -%} |
167 {{resolve_type(parameter).pass_type}} {{parameter.name}} | 166 {{resolve_type(parameter).pass_type}} {{parameter.name}} |
168 {%- endif -%} | 167 {%- endif -%} |
169 {%- if not loop.last -%}, {% endif -%} | 168 {%- if not loop.last -%}, {% endif -%} |
170 {%- endfor -%}) override | 169 {%- endfor -%}) override |
(...skipping 11 matching lines...) Expand all Loading... |
182 } | 181 } |
183 | 182 |
184 void sendFailure(const ErrorString& error) override | 183 void sendFailure(const ErrorString& error) override |
185 { | 184 { |
186 DCHECK(error.length()); | 185 DCHECK(error.length()); |
187 sendIfActive(nullptr, error); | 186 sendIfActive(nullptr, error); |
188 } | 187 } |
189 }; | 188 }; |
190 {% endif %} | 189 {% endif %} |
191 | 190 |
192 void DispatcherImpl::{{domain.domain}}_{{command.name}}(int sessionId, int callI
d, PassOwnPtr<DictionaryValue> requestMessageObject, ErrorSupport* errors) | 191 void DispatcherImpl::{{domain.domain}}_{{command.name}}(int callId, PassOwnPtr<D
ictionaryValue> requestMessageObject, ErrorSupport* errors) |
193 { | 192 { |
194 if (!m_{{domain.domain | lower}}Agent) | 193 if (!m_{{domain.domain | lower}}Agent) |
195 errors->addError("{{domain.domain}} handler is not available."); | 194 errors->addError("{{domain.domain}} handler is not available."); |
196 | 195 |
197 if (errors->hasErrors()) { | 196 if (errors->hasErrors()) { |
198 reportProtocolError(sessionId, callId, InvalidParams, kInvalidRequest, e
rrors); | 197 reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); |
199 return; | 198 return; |
200 } | 199 } |
201 {% if "parameters" in command %} | 200 {% if "parameters" in command %} |
202 | 201 |
203 // Prepare input parameters. | 202 // Prepare input parameters. |
204 protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObje
ct->get("params")); | 203 protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObje
ct->get("params")); |
205 errors->push(); | 204 errors->push(); |
206 {% for property in command.parameters %} | 205 {% for property in command.parameters %} |
207 protocol::Value* {{property.name}}Value = object ? object->get("{{property.n
ame}}") : nullptr; | 206 protocol::Value* {{property.name}}Value = object ? object->get("{{property.n
ame}}") : nullptr; |
208 {% if property.optional %} | 207 {% if property.optional %} |
209 Maybe<{{resolve_type(property).raw_type}}> in_{{property.name}}; | 208 Maybe<{{resolve_type(property).raw_type}}> in_{{property.name}}; |
210 if ({{property.name}}Value) { | 209 if ({{property.name}}Value) { |
211 errors->setName("{{property.name}}"); | 210 errors->setName("{{property.name}}"); |
212 in_{{property.name}} = FromValue<{{resolve_type(property).raw_type}}>::p
arse({{property.name}}Value, errors); | 211 in_{{property.name}} = FromValue<{{resolve_type(property).raw_type}}>::p
arse({{property.name}}Value, errors); |
213 } | 212 } |
214 {% else %} | 213 {% else %} |
215 errors->setName("{{property.name}}"); | 214 errors->setName("{{property.name}}"); |
216 {{resolve_type(property).type}} in_{{property.name}} = FromValue<{{resolve_t
ype(property).raw_type}}>::parse({{property.name}}Value, errors); | 215 {{resolve_type(property).type}} in_{{property.name}} = FromValue<{{resolve_t
ype(property).raw_type}}>::parse({{property.name}}Value, errors); |
217 {% endif %} | 216 {% endif %} |
218 {% endfor %} | 217 {% endfor %} |
219 errors->pop(); | 218 errors->pop(); |
220 if (errors->hasErrors()) { | 219 if (errors->hasErrors()) { |
221 reportProtocolError(sessionId, callId, InvalidParams, kInvalidRequest, e
rrors); | 220 reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); |
222 return; | 221 return; |
223 } | 222 } |
224 {% endif %} | 223 {% endif %} |
225 | 224 |
226 {% if "async" in command %} | 225 {% if "async" in command %} |
227 OwnPtr<{{domain.domain}}{{command.name | to_title_case}}Callback> callback =
adoptPtr(new {{domain.domain}}{{command.name | to_title_case}}Callback(weakPtr(
), sessionId, callId)); | 226 OwnPtr<{{domain.domain}}{{command.name | to_title_case}}Callback> callback =
adoptPtr(new {{domain.domain}}{{command.name | to_title_case}}Callback(weakPtr(
), callId)); |
228 {% elif "returns" in command %} | 227 {% elif "returns" in command %} |
229 // Declare output parameters. | 228 // Declare output parameters. |
230 OwnPtr<protocol::DictionaryValue> result = DictionaryValue::create(); | 229 OwnPtr<protocol::DictionaryValue> result = DictionaryValue::create(); |
231 {% for property in command.returns %} | 230 {% for property in command.returns %} |
232 {% if "optional" in property %} | 231 {% if "optional" in property %} |
233 Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}}; | 232 Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}}; |
234 {% else %} | 233 {% else %} |
235 {{resolve_type(property).type}} out_{{property.name}}; | 234 {{resolve_type(property).type}} out_{{property.name}}; |
236 {% endif %} | 235 {% endif %} |
237 {% endfor %} | 236 {% endfor %} |
(...skipping 21 matching lines...) Expand all Loading... |
259 {% for parameter in command.returns %} | 258 {% for parameter in command.returns %} |
260 {% if "optional" in parameter %} | 259 {% if "optional" in parameter %} |
261 if (out_{{parameter.name}}.isJust()) | 260 if (out_{{parameter.name}}.isJust()) |
262 result->setValue("{{parameter.name}}", toValue(out_{{parameter.name}
}.fromJust())); | 261 result->setValue("{{parameter.name}}", toValue(out_{{parameter.name}
}.fromJust())); |
263 {% else %} | 262 {% else %} |
264 result->setValue("{{parameter.name}}", toValue({{resolve_type(parameter)
.to_raw_type % ("out_" + parameter.name)}})); | 263 result->setValue("{{parameter.name}}", toValue({{resolve_type(parameter)
.to_raw_type % ("out_" + parameter.name)}})); |
265 {% endif %} | 264 {% endif %} |
266 {% endfor %} | 265 {% endfor %} |
267 } | 266 } |
268 if (weak->get()) | 267 if (weak->get()) |
269 weak->get()->sendResponse(sessionId, callId, error, std::move(result)); | 268 weak->get()->sendResponse(callId, error, std::move(result)); |
270 {% elif not("async" in command) %} | 269 {% elif not("async" in command) %} |
271 if (weak->get()) | 270 if (weak->get()) |
272 weak->get()->sendResponse(sessionId, callId, error); | 271 weak->get()->sendResponse(callId, error); |
273 {% endif %} | 272 {% endif %} |
274 } | 273 } |
275 {% endfor %} | 274 {% endfor %} |
276 {% endfor %} | 275 {% endfor %} |
277 | 276 |
278 PassOwnPtr<Dispatcher> Dispatcher::create(FrontendChannel* frontendChannel) | 277 PassOwnPtr<Dispatcher> Dispatcher::create(FrontendChannel* frontendChannel) |
279 { | 278 { |
280 return adoptPtr(new DispatcherImpl(frontendChannel)); | 279 return adoptPtr(new DispatcherImpl(frontendChannel)); |
281 } | 280 } |
282 | 281 |
283 void DispatcherImpl::dispatch(int sessionId, const String16& message) | 282 void DispatcherImpl::dispatch(const String16& message) |
284 { | 283 { |
285 int callId = 0; | 284 int callId = 0; |
286 OwnPtr<protocol::Value> parsedMessage = parseJSON(message); | 285 OwnPtr<protocol::Value> parsedMessage = parseJSON(message); |
287 DCHECK(parsedMessage); | 286 DCHECK(parsedMessage); |
288 OwnPtr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(std:
:move(parsedMessage)); | 287 OwnPtr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(std:
:move(parsedMessage)); |
289 DCHECK(messageObject); | 288 DCHECK(messageObject); |
290 | 289 |
291 protocol::Value* callIdValue = messageObject->get("id"); | 290 protocol::Value* callIdValue = messageObject->get("id"); |
292 bool success = callIdValue->asNumber(&callId); | 291 bool success = callIdValue->asNumber(&callId); |
293 DCHECK(success); | 292 DCHECK(success); |
294 | 293 |
295 protocol::Value* methodValue = messageObject->get("method"); | 294 protocol::Value* methodValue = messageObject->get("method"); |
296 String16 method; | 295 String16 method; |
297 success = methodValue && methodValue->asString(&method); | 296 success = methodValue && methodValue->asString(&method); |
298 DCHECK(success); | 297 DCHECK(success); |
299 | 298 |
300 protocol::HashMap<String16, CallHandler>::iterator it = m_dispatchMap.find(m
ethod); | 299 protocol::HashMap<String16, CallHandler>::iterator it = m_dispatchMap.find(m
ethod); |
301 if (it == m_dispatchMap.end()) { | 300 if (it == m_dispatchMap.end()) { |
302 reportProtocolError(sessionId, callId, MethodNotFound, "'" + method + "'
wasn't found"); | 301 reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't fou
nd"); |
303 return; | 302 return; |
304 } | 303 } |
305 | 304 |
306 protocol::ErrorSupport errors; | 305 protocol::ErrorSupport errors; |
307 ((*this).*(*it->second))(sessionId, callId, std::move(messageObject), &error
s); | 306 ((*this).*(*it->second))(callId, std::move(messageObject), &errors); |
308 } | 307 } |
309 | 308 |
310 void DispatcherImpl::sendResponse(int sessionId, int callId, const ErrorString&
invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> res
ult) | 309 void DispatcherImpl::sendResponse(int callId, const ErrorString& invocationError
, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result) |
311 { | 310 { |
312 if (invocationError.length() || (errors && errors->hasErrors())) { | 311 if (invocationError.length() || (errors && errors->hasErrors())) { |
313 reportProtocolError(sessionId, callId, ServerError, invocationError, err
ors); | 312 reportProtocolError(callId, ServerError, invocationError, errors); |
314 return; | 313 return; |
315 } | 314 } |
316 | 315 |
317 OwnPtr<protocol::DictionaryValue> responseMessage = DictionaryValue::create(
); | 316 OwnPtr<protocol::DictionaryValue> responseMessage = DictionaryValue::create(
); |
318 responseMessage->setNumber("id", callId); | 317 responseMessage->setNumber("id", callId); |
319 responseMessage->setObject("result", std::move(result)); | 318 responseMessage->setObject("result", std::move(result)); |
320 if (m_frontendChannel) | 319 if (m_frontendChannel) |
321 m_frontendChannel->sendProtocolResponse(sessionId, callId, std::move(res
ponseMessage)); | 320 m_frontendChannel->sendProtocolResponse(callId, responseMessage->toJSONS
tring()); |
322 } | 321 } |
323 | 322 |
324 void Dispatcher::reportProtocolError(int sessionId, int callId, CommonErrorCode
code, const String16& errorMessage) const | 323 void Dispatcher::reportProtocolError(int callId, CommonErrorCode code, const Str
ing16& errorMessage) const |
325 { | 324 { |
326 ErrorSupport errors; | 325 ErrorSupport errors; |
327 reportProtocolError(sessionId, callId, code, errorMessage, &errors); | 326 reportProtocolError(callId, code, errorMessage, &errors); |
328 } | 327 } |
329 | 328 |
330 void DispatcherImpl::reportProtocolError(int sessionId, int callId, CommonErrorC
ode code, const String16& errorMessage, ErrorSupport* errors) const | 329 void DispatcherImpl::reportProtocolError(int callId, CommonErrorCode code, const
String16& errorMessage, ErrorSupport* errors) const |
331 { | 330 { |
332 DCHECK(code >=0); | 331 DCHECK(code >=0); |
333 DCHECK((unsigned)code < m_commonErrors.size()); | 332 DCHECK((unsigned)code < m_commonErrors.size()); |
334 DCHECK(m_commonErrors[code]); | 333 DCHECK(m_commonErrors[code]); |
335 OwnPtr<protocol::DictionaryValue> error = DictionaryValue::create(); | 334 OwnPtr<protocol::DictionaryValue> error = DictionaryValue::create(); |
336 error->setNumber("code", m_commonErrors[code]); | 335 error->setNumber("code", m_commonErrors[code]); |
337 error->setString("message", errorMessage); | 336 error->setString("message", errorMessage); |
338 DCHECK(error); | 337 DCHECK(error); |
339 if (errors && errors->hasErrors()) | 338 if (errors && errors->hasErrors()) |
340 error->setString("data", errors->errors()); | 339 error->setString("data", errors->errors()); |
341 OwnPtr<protocol::DictionaryValue> message = DictionaryValue::create(); | 340 OwnPtr<protocol::DictionaryValue> message = DictionaryValue::create(); |
342 message->setObject("error", std::move(error)); | 341 message->setObject("error", std::move(error)); |
343 message->setNumber("id", callId); | 342 message->setNumber("id", callId); |
344 if (m_frontendChannel) | 343 if (m_frontendChannel) |
345 m_frontendChannel->sendProtocolResponse(sessionId, callId, std::move(mes
sage)); | 344 m_frontendChannel->sendProtocolResponse(callId, message->toJSONString())
; |
346 } | 345 } |
347 | 346 |
348 bool Dispatcher::getCommandName(const String16& message, String16* result) | 347 bool Dispatcher::getCommandName(const String16& message, String16* result) |
349 { | 348 { |
350 OwnPtr<protocol::Value> value = parseJSON(message); | 349 OwnPtr<protocol::Value> value = parseJSON(message); |
351 if (!value) | 350 if (!value) |
352 return false; | 351 return false; |
353 | 352 |
354 protocol::DictionaryValue* object = DictionaryValue::cast(value.get()); | 353 protocol::DictionaryValue* object = DictionaryValue::cast(value.get()); |
355 if (!object) | 354 if (!object) |
356 return false; | 355 return false; |
357 | 356 |
358 if (!object->getString("method", result)) | 357 if (!object->getString("method", result)) |
359 return false; | 358 return false; |
360 | 359 |
361 return true; | 360 return true; |
362 } | 361 } |
363 | 362 |
364 } // namespace protocol | 363 } // namespace protocol |
365 } // namespace blink | 364 } // namespace blink |
OLD | NEW |