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)(JSONVal
ue*, 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)(PassRef
Ptr<JSONValue>, V*), const char* type_name); |
75 | 75 |
76 static Maybe<int> getInteger(JSONObject* object, const char* name, bool isOp
tional, JSONArray* protocolErrors); | 76 static Maybe<int> getInteger(JSONObject* object, const char* name, bool isOp
tional, JSONArray* protocolErrors); |
77 static Maybe<double> getNumber(JSONObject* object, const char* name, bool is
Optional, JSONArray* protocolErrors); | 77 static Maybe<double> getNumber(JSONObject* object, const char* name, bool is
Optional, JSONArray* protocolErrors); |
78 static Maybe<String> getString(JSONObject* object, const char* name, bool is
Optional, JSONArray* protocolErrors); | 78 static Maybe<String> getString(JSONObject* object, const char* name, bool is
Optional, JSONArray* protocolErrors); |
79 static Maybe<bool> getBoolean(JSONObject* object, const char* name, bool isO
ptional, JSONArray* protocolErrors); | 79 static Maybe<bool> getBoolean(JSONObject* object, const char* name, bool isO
ptional, 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 { | 205 { |
206 return adoptRef(new DispatcherImpl(frontendChannel)); | 206 return adoptRef(new DispatcherImpl(frontendChannel)); |
207 } | 207 } |
208 | 208 |
209 void DispatcherImpl::dispatch(int sessionId, const String& message) | 209 void DispatcherImpl::dispatch(int sessionId, const String& message) |
210 { | 210 { |
211 RefPtr<Dispatcher> protect(this); | 211 RefPtr<Dispatcher> protect(this); |
212 int callId = 0; | 212 int callId = 0; |
213 RefPtr<JSONValue> parsedMessage = parseJSON(message); | 213 RefPtr<JSONValue> parsedMessage = parseJSON(message); |
214 ASSERT(parsedMessage); | 214 ASSERT(parsedMessage); |
215 RefPtr<JSONObject> messageObject = parsedMessage->asObject(); | 215 RefPtr<JSONObject> messageObject = JSONObject::cast(parsedMessage.release())
; |
216 ASSERT(messageObject); | 216 ASSERT(messageObject); |
217 | 217 |
218 RefPtr<JSONValue> callIdValue = messageObject->get("id"); | 218 RefPtr<JSONValue> callIdValue = messageObject->get("id"); |
219 bool success = callIdValue->asNumber(&callId); | 219 bool success = callIdValue->asNumber(&callId); |
220 ASSERT_UNUSED(success, success); | 220 ASSERT_UNUSED(success, success); |
221 | 221 |
222 RefPtr<JSONValue> methodValue = messageObject->get("method"); | 222 RefPtr<JSONValue> methodValue = messageObject->get("method"); |
223 String method; | 223 String method; |
224 success = methodValue && methodValue->asString(&method); | 224 success = methodValue && methodValue->asString(&method); |
225 ASSERT_UNUSED(success, success); | 225 ASSERT_UNUSED(success, success); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 if (data) | 265 if (data) |
266 error->setValue("data", data); | 266 error->setValue("data", data); |
267 RefPtr<JSONObject> message = JSONObject::create(); | 267 RefPtr<JSONObject> message = JSONObject::create(); |
268 message->setObject("error", error); | 268 message->setObject("error", error); |
269 message->setNumber("id", callId); | 269 message->setNumber("id", callId); |
270 if (m_frontendChannel) | 270 if (m_frontendChannel) |
271 m_frontendChannel->sendProtocolResponse(sessionId, callId, message.relea
se()); | 271 m_frontendChannel->sendProtocolResponse(sessionId, callId, message.relea
se()); |
272 } | 272 } |
273 | 273 |
274 template<typename R, typename V, typename V0> | 274 template<typename R, typename V, typename V0> |
275 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) | 275 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 { | 276 { |
277 ASSERT(protocolErrors); | 277 ASSERT(protocolErrors); |
278 | 278 |
279 if (valueFound) | 279 if (valueFound) |
280 *valueFound = false; | 280 *valueFound = false; |
281 | 281 |
282 V value = initial_value; | 282 V value = initial_value; |
283 | 283 |
284 if (!object) { | 284 if (!object) { |
285 if (!valueFound) { | 285 if (!valueFound) { |
(...skipping 14 matching lines...) Expand all Loading... |
300 | 300 |
301 if (!as_method(valueIterator->value.get(), &value)) | 301 if (!as_method(valueIterator->value.get(), &value)) |
302 protocolErrors->pushString(String::format("Parameter '%s' has wrong type
. It must be '%s'.", name, type_name)); | 302 protocolErrors->pushString(String::format("Parameter '%s' has wrong type
. It must be '%s'.", name, type_name)); |
303 else | 303 else |
304 if (valueFound) | 304 if (valueFound) |
305 *valueFound = true; | 305 *valueFound = true; |
306 return value; | 306 return value; |
307 } | 307 } |
308 | 308 |
309 struct AsMethodBridges { | 309 struct AsMethodBridges { |
310 static bool asInteger(JSONValue* value, int* output) { return value->asNumbe
r(output); } | 310 static bool asInteger(PassRefPtr<JSONValue> value, int* output) { return val
ue->asNumber(output); } |
311 static bool asNumber(JSONValue* value, double* output) { return value->asNum
ber(output); } | 311 static bool asNumber(PassRefPtr<JSONValue> value, double* output) { return v
alue->asNumber(output); } |
312 static bool asString(JSONValue* value, String* output) { return value->asStr
ing(output); } | 312 static bool asString(PassRefPtr<JSONValue> value, String* output) { return v
alue->asString(output); } |
313 static bool asBoolean(JSONValue* value, bool* output) { return value->asBool
ean(output); } | 313 static bool asBoolean(PassRefPtr<JSONValue> value, bool* output) { return va
lue->asBoolean(output); } |
314 static bool asObject(JSONValue* value, RefPtr<JSONObject>* output) { return
value->asObject(output); } | 314 static bool asObject(PassRefPtr<JSONValue> value, RefPtr<JSONObject>* output
) { *output = JSONObject::cast(value); return *output; } |
315 static bool asArray(JSONValue* value, RefPtr<JSONArray>* output) { return va
lue->asArray(output); } | 315 static bool asArray(PassRefPtr<JSONValue> value, RefPtr<JSONArray>* output)
{ *output = JSONArray::cast(value); return *output; } |
316 }; | 316 }; |
317 | 317 |
318 Maybe<int> DispatcherImpl::getInteger(JSONObject* object, const char* name, bool
isOptional, JSONArray* protocolErrors) | 318 Maybe<int> DispatcherImpl::getInteger(JSONObject* object, const char* name, bool
isOptional, JSONArray* protocolErrors) |
319 { | 319 { |
320 bool valueFound = false; | 320 bool valueFound = false; |
321 int result = getPropertyValueImpl<int, int, int>(object, name, isOptional ?
&valueFound : 0, protocolErrors, 0, AsMethodBridges::asInteger, "Number"); | 321 int result = getPropertyValueImpl<int, int, int>(object, name, isOptional ?
&valueFound : 0, protocolErrors, 0, AsMethodBridges::asInteger, "Number"); |
322 return valueFound || !isOptional ? Maybe<int>(result) : Maybe<int>(); | 322 return valueFound || !isOptional ? Maybe<int>(result) : Maybe<int>(); |
323 } | 323 } |
324 | 324 |
325 Maybe<double> DispatcherImpl::getNumber(JSONObject* object, const char* name, bo
ol isOptional, JSONArray* protocolErrors) | 325 Maybe<double> DispatcherImpl::getNumber(JSONObject* object, const char* name, bo
ol isOptional, JSONArray* protocolErrors) |
(...skipping 28 matching lines...) Expand all Loading... |
354 bool valueFound = false; | 354 bool valueFound = false; |
355 return getPropertyValueImpl<PassRefPtr<JSONArray>, RefPtr<JSONArray>, JSONAr
ray*>(object, name, isOptional ? &valueFound : 0, protocolErrors, 0, AsMethodBri
dges::asArray, "Array"); | 355 return getPropertyValueImpl<PassRefPtr<JSONArray>, RefPtr<JSONArray>, JSONAr
ray*>(object, name, isOptional ? &valueFound : 0, protocolErrors, 0, AsMethodBri
dges::asArray, "Array"); |
356 } | 356 } |
357 | 357 |
358 bool Dispatcher::getCommandName(const String& message, String* result) | 358 bool Dispatcher::getCommandName(const String& message, String* result) |
359 { | 359 { |
360 RefPtr<JSONValue> value = parseJSON(message); | 360 RefPtr<JSONValue> value = parseJSON(message); |
361 if (!value) | 361 if (!value) |
362 return false; | 362 return false; |
363 | 363 |
364 RefPtr<JSONObject> object = value->asObject(); | 364 RefPtr<JSONObject> object = JSONObject::cast(value.release()); |
365 if (!object) | 365 if (!object) |
366 return false; | 366 return false; |
367 | 367 |
368 if (!object->getString("method", result)) | 368 if (!object->getString("method", result)) |
369 return false; | 369 return false; |
370 | 370 |
371 return true; | 371 return true; |
372 } | 372 } |
373 | 373 |
374 Dispatcher::CallbackBase::CallbackBase(PassRefPtr<DispatcherImpl> backendImpl, i
nt sessionId, int id) | 374 Dispatcher::CallbackBase::CallbackBase(PassRefPtr<DispatcherImpl> backendImpl, i
nt sessionId, int id) |
(...skipping 15 matching lines...) Expand all Loading... |
390 void Dispatcher::CallbackBase::sendIfActive(PassRefPtr<JSONObject> partialMessag
e, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData) | 390 void Dispatcher::CallbackBase::sendIfActive(PassRefPtr<JSONObject> partialMessag
e, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData) |
391 { | 391 { |
392 if (m_alreadySent) | 392 if (m_alreadySent) |
393 return; | 393 return; |
394 m_backendImpl->sendResponse(m_sessionId, m_id, invocationError, errorData, p
artialMessage); | 394 m_backendImpl->sendResponse(m_sessionId, m_id, invocationError, errorData, p
artialMessage); |
395 m_alreadySent = true; | 395 m_alreadySent = true; |
396 } | 396 } |
397 | 397 |
398 } // namespace protocol | 398 } // namespace protocol |
399 } // namespace blink | 399 } // namespace blink |
OLD | NEW |