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/JSONParser.h" | 9 #include "platform/JSONParser.h" |
10 #include "platform/inspector_protocol/FrontendChannel.h" | 10 #include "platform/inspector_protocol/FrontendChannel.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 {% endfor %} | 64 {% endfor %} |
65 {% endfor %} | 65 {% endfor %} |
66 | 66 |
67 FrontendChannel* m_frontendChannel; | 67 FrontendChannel* m_frontendChannel; |
68 | 68 |
69 {% for domain in api.domains %} | 69 {% for domain in api.domains %} |
70 {{domain.domain}}CommandHandler* m_{{domain.domain | lower}}Agent; | 70 {{domain.domain}}CommandHandler* m_{{domain.domain | lower}}Agent; |
71 {% endfor %} | 71 {% endfor %} |
72 | 72 |
73 template<typename R, typename V, typename V0> | 73 template<typename R, typename V, typename V0> |
74 static R getPropertyValueImpl(JSONObject* object, const char* name, bool* va
lueFound, JSONArray* protocolErrors, V0 initial_value, bool (*as_method)(PassRef
Ptr<JSONValue>, V*), const char* type_name); | 74 static R getPropertyValueImpl(JSONObject* object, const char* name, bool* va
lueFound, JSONArray* protocolErrors, V0 initial_value, bool (*as_method)(JSONVal
ue*, V*), const char* type_name); |
75 | 75 |
76 static OptionalValue<int> getInteger(JSONObject* object, const char* name, b
ool isOptional, JSONArray* protocolErrors); | 76 static OptionalValue<int> getInteger(JSONObject* object, const char* name, b
ool isOptional, JSONArray* protocolErrors); |
77 static OptionalValue<double> getNumber(JSONObject* object, const char* name,
bool isOptional, JSONArray* protocolErrors); | 77 static OptionalValue<double> getNumber(JSONObject* object, const char* name,
bool isOptional, JSONArray* protocolErrors); |
78 static OptionalValue<String> getString(JSONObject* object, const char* name,
bool isOptional, JSONArray* protocolErrors); | 78 static OptionalValue<String> getString(JSONObject* object, const char* name,
bool isOptional, JSONArray* protocolErrors); |
79 static OptionalValue<bool> getBoolean(JSONObject* object, const char* name,
bool isOptional, JSONArray* protocolErrors); | 79 static OptionalValue<bool> getBoolean(JSONObject* object, const char* name,
bool isOptional, JSONArray* protocolErrors); |
80 static PassRefPtr<JSONObject> getObject(JSONObject* object, const char* name
, bool isOptional, JSONArray* protocolErrors); | 80 static PassRefPtr<JSONObject> getObject(JSONObject* object, const char* name
, bool isOptional, JSONArray* protocolErrors); |
81 static PassRefPtr<JSONArray> getArray(JSONObject* object, const char* name,
bool isOptional, JSONArray* protocolErrors); | 81 static PassRefPtr<JSONArray> getArray(JSONObject* object, const char* name,
bool isOptional, JSONArray* protocolErrors); |
82 | 82 |
83 void sendResponse(int sessionId, int callId, ErrorString invocationError, Pa
ssRefPtr<JSONObject> result) | 83 void sendResponse(int sessionId, int callId, ErrorString invocationError, Pa
ssRefPtr<JSONObject> result) |
84 { | 84 { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 { | 206 { |
207 return adoptRef(new DispatcherImpl(frontendChannel)); | 207 return adoptRef(new DispatcherImpl(frontendChannel)); |
208 } | 208 } |
209 | 209 |
210 void DispatcherImpl::dispatch(int sessionId, const String& message) | 210 void DispatcherImpl::dispatch(int sessionId, const String& message) |
211 { | 211 { |
212 RefPtr<Dispatcher> protect(this); | 212 RefPtr<Dispatcher> protect(this); |
213 int callId = 0; | 213 int callId = 0; |
214 RefPtr<JSONValue> parsedMessage = parseJSON(message); | 214 RefPtr<JSONValue> parsedMessage = parseJSON(message); |
215 ASSERT(parsedMessage); | 215 ASSERT(parsedMessage); |
216 RefPtr<JSONObject> messageObject = JSONObject::cast(parsedMessage.release())
; | 216 RefPtr<JSONObject> messageObject = parsedMessage->asObject(); |
217 ASSERT(messageObject); | 217 ASSERT(messageObject); |
218 | 218 |
219 RefPtr<JSONValue> callIdValue = messageObject->get("id"); | 219 RefPtr<JSONValue> callIdValue = messageObject->get("id"); |
220 bool success = callIdValue->asNumber(&callId); | 220 bool success = callIdValue->asNumber(&callId); |
221 ASSERT_UNUSED(success, success); | 221 ASSERT_UNUSED(success, success); |
222 | 222 |
223 RefPtr<JSONValue> methodValue = messageObject->get("method"); | 223 RefPtr<JSONValue> methodValue = messageObject->get("method"); |
224 String method; | 224 String method; |
225 success = methodValue && methodValue->asString(&method); | 225 success = methodValue && methodValue->asString(&method); |
226 ASSERT_UNUSED(success, success); | 226 ASSERT_UNUSED(success, success); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 if (data) | 266 if (data) |
267 error->setValue("data", data); | 267 error->setValue("data", data); |
268 RefPtr<JSONObject> message = JSONObject::create(); | 268 RefPtr<JSONObject> message = JSONObject::create(); |
269 message->setObject("error", error); | 269 message->setObject("error", error); |
270 message->setNumber("id", callId); | 270 message->setNumber("id", callId); |
271 if (m_frontendChannel) | 271 if (m_frontendChannel) |
272 m_frontendChannel->sendProtocolResponse(sessionId, callId, message.relea
se()); | 272 m_frontendChannel->sendProtocolResponse(sessionId, callId, message.relea
se()); |
273 } | 273 } |
274 | 274 |
275 template<typename R, typename V, typename V0> | 275 template<typename R, typename V, typename V0> |
276 R DispatcherImpl::getPropertyValueImpl(JSONObject* object, const char* name, boo
l* valueFound, JSONArray* protocolErrors, V0 initial_value, bool (*as_method)(Pa
ssRefPtr<JSONValue>, V*), const char* type_name) | 276 R DispatcherImpl::getPropertyValueImpl(JSONObject* object, const char* name, boo
l* valueFound, JSONArray* protocolErrors, V0 initial_value, bool (*as_method)(JS
ONValue*, V*), const char* type_name) |
277 { | 277 { |
278 ASSERT(protocolErrors); | 278 ASSERT(protocolErrors); |
279 | 279 |
280 if (valueFound) | 280 if (valueFound) |
281 *valueFound = false; | 281 *valueFound = false; |
282 | 282 |
283 V value = initial_value; | 283 V value = initial_value; |
284 | 284 |
285 if (!object) { | 285 if (!object) { |
286 if (!valueFound) { | 286 if (!valueFound) { |
(...skipping 14 matching lines...) Expand all Loading... |
301 | 301 |
302 if (!as_method(valueIterator->value.get(), &value)) | 302 if (!as_method(valueIterator->value.get(), &value)) |
303 protocolErrors->pushString(String::format("Parameter '%s' has wrong type
. It must be '%s'.", name, type_name)); | 303 protocolErrors->pushString(String::format("Parameter '%s' has wrong type
. It must be '%s'.", name, type_name)); |
304 else | 304 else |
305 if (valueFound) | 305 if (valueFound) |
306 *valueFound = true; | 306 *valueFound = true; |
307 return value; | 307 return value; |
308 } | 308 } |
309 | 309 |
310 struct AsMethodBridges { | 310 struct AsMethodBridges { |
311 static bool asInteger(PassRefPtr<JSONValue> value, int* output) { return val
ue->asNumber(output); } | 311 static bool asInteger(JSONValue* value, int* output) { return value->asNumbe
r(output); } |
312 static bool asNumber(PassRefPtr<JSONValue> value, double* output) { return v
alue->asNumber(output); } | 312 static bool asNumber(JSONValue* value, double* output) { return value->asNum
ber(output); } |
313 static bool asString(PassRefPtr<JSONValue> value, String* output) { return v
alue->asString(output); } | 313 static bool asString(JSONValue* value, String* output) { return value->asStr
ing(output); } |
314 static bool asBoolean(PassRefPtr<JSONValue> value, bool* output) { return va
lue->asBoolean(output); } | 314 static bool asBoolean(JSONValue* value, bool* output) { return value->asBool
ean(output); } |
315 static bool asObject(PassRefPtr<JSONValue> value, RefPtr<JSONObject>* output
) { *output = JSONObject::cast(value); return *output; } | 315 static bool asObject(JSONValue* value, RefPtr<JSONObject>* output) { return
value->asObject(output); } |
316 static bool asArray(PassRefPtr<JSONValue> value, RefPtr<JSONArray>* output)
{ *output = JSONArray::cast(value); return *output; } | 316 static bool asArray(JSONValue* value, RefPtr<JSONArray>* output) { return va
lue->asArray(output); } |
317 }; | 317 }; |
318 | 318 |
319 OptionalValue<int> DispatcherImpl::getInteger(JSONObject* object, const char* na
me, bool isOptional, JSONArray* protocolErrors) | 319 OptionalValue<int> DispatcherImpl::getInteger(JSONObject* object, const char* na
me, bool isOptional, JSONArray* protocolErrors) |
320 { | 320 { |
321 bool valueFound = false; | 321 bool valueFound = false; |
322 int result = getPropertyValueImpl<int, int, int>(object, name, isOptional ?
&valueFound : 0, protocolErrors, 0, AsMethodBridges::asInteger, "Number"); | 322 int result = getPropertyValueImpl<int, int, int>(object, name, isOptional ?
&valueFound : 0, protocolErrors, 0, AsMethodBridges::asInteger, "Number"); |
323 return valueFound || !isOptional ? OptionalValue<int>(result) : OptionalValu
e<int>(); | 323 return valueFound || !isOptional ? OptionalValue<int>(result) : OptionalValu
e<int>(); |
324 } | 324 } |
325 | 325 |
326 OptionalValue<double> DispatcherImpl::getNumber(JSONObject* object, const char*
name, bool isOptional, JSONArray* protocolErrors) | 326 OptionalValue<double> DispatcherImpl::getNumber(JSONObject* object, const char*
name, bool isOptional, JSONArray* protocolErrors) |
(...skipping 28 matching lines...) Expand all Loading... |
355 bool valueFound = false; | 355 bool valueFound = false; |
356 return getPropertyValueImpl<PassRefPtr<JSONArray>, RefPtr<JSONArray>, JSONAr
ray*>(object, name, isOptional ? &valueFound : 0, protocolErrors, 0, AsMethodBri
dges::asArray, "Array"); | 356 return getPropertyValueImpl<PassRefPtr<JSONArray>, RefPtr<JSONArray>, JSONAr
ray*>(object, name, isOptional ? &valueFound : 0, protocolErrors, 0, AsMethodBri
dges::asArray, "Array"); |
357 } | 357 } |
358 | 358 |
359 bool Dispatcher::getCommandName(const String& message, String* result) | 359 bool Dispatcher::getCommandName(const String& message, String* result) |
360 { | 360 { |
361 RefPtr<JSONValue> value = parseJSON(message); | 361 RefPtr<JSONValue> value = parseJSON(message); |
362 if (!value) | 362 if (!value) |
363 return false; | 363 return false; |
364 | 364 |
365 RefPtr<JSONObject> object = JSONObject::cast(value.release()); | 365 RefPtr<JSONObject> object = value->asObject(); |
366 if (!object) | 366 if (!object) |
367 return false; | 367 return false; |
368 | 368 |
369 if (!object->getString("method", result)) | 369 if (!object->getString("method", result)) |
370 return false; | 370 return false; |
371 | 371 |
372 return true; | 372 return true; |
373 } | 373 } |
374 | 374 |
375 Dispatcher::CallbackBase::CallbackBase(PassRefPtr<DispatcherImpl> backendImpl, i
nt sessionId, int id) | 375 Dispatcher::CallbackBase::CallbackBase(PassRefPtr<DispatcherImpl> backendImpl, i
nt sessionId, int id) |
(...skipping 15 matching lines...) Expand all Loading... |
391 void Dispatcher::CallbackBase::sendIfActive(PassRefPtr<JSONObject> partialMessag
e, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData) | 391 void Dispatcher::CallbackBase::sendIfActive(PassRefPtr<JSONObject> partialMessag
e, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData) |
392 { | 392 { |
393 if (m_alreadySent) | 393 if (m_alreadySent) |
394 return; | 394 return; |
395 m_backendImpl->sendResponse(m_sessionId, m_id, invocationError, errorData, p
artialMessage); | 395 m_backendImpl->sendResponse(m_sessionId, m_id, invocationError, errorData, p
artialMessage); |
396 m_alreadySent = true; | 396 m_alreadySent = true; |
397 } | 397 } |
398 | 398 |
399 } // namespace protocol | 399 } // namespace protocol |
400 } // namespace blink | 400 } // namespace blink |
OLD | NEW |