OLD | NEW |
1 # Copyright (c) 2013 Google Inc. All rights reserved. | 1 # Copyright (c) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 bool isActive() { return m_inspectorFrontendChannel; } | 251 bool isActive() { return m_inspectorFrontendChannel; } |
252 | 252 |
253 $setters | 253 $setters |
254 private: | 254 private: |
255 $methodDeclarations | 255 $methodDeclarations |
256 | 256 |
257 InspectorFrontendChannel* m_inspectorFrontendChannel; | 257 InspectorFrontendChannel* m_inspectorFrontendChannel; |
258 $fieldDeclarations | 258 $fieldDeclarations |
259 | 259 |
260 template<typename R, typename V, typename V0> | 260 template<typename R, typename V, typename V0> |
261 static R getPropertyValueImpl(JSONObject* object, const String& name, bool*
valueFound, JSONArray* protocolErrors, V0 initial_value, bool (*as_method)(JSONV
alue*, V*), const char* type_name); | 261 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); |
262 | 262 |
263 static int getInt(JSONObject* object, const String& name, bool* valueFound,
JSONArray* protocolErrors); | 263 static int getInt(JSONObject* object, const char* name, bool* valueFound, JS
ONArray* protocolErrors); |
264 static double getDouble(JSONObject* object, const String& name, bool* valueF
ound, JSONArray* protocolErrors); | 264 static double getDouble(JSONObject* object, const char* name, bool* valueFou
nd, JSONArray* protocolErrors); |
265 static String getString(JSONObject* object, const String& name, bool* valueF
ound, JSONArray* protocolErrors); | 265 static String getString(JSONObject* object, const char* name, bool* valueFou
nd, JSONArray* protocolErrors); |
266 static bool getBoolean(JSONObject* object, const String& name, bool* valueFo
und, JSONArray* protocolErrors); | 266 static bool getBoolean(JSONObject* object, const char* name, bool* valueFoun
d, JSONArray* protocolErrors); |
267 static PassRefPtr<JSONObject> getObject(JSONObject* object, const String& na
me, bool* valueFound, JSONArray* protocolErrors); | 267 static PassRefPtr<JSONObject> getObject(JSONObject* object, const char* name
, bool* valueFound, JSONArray* protocolErrors); |
268 static PassRefPtr<JSONArray> getArray(JSONObject* object, const String& name
, bool* valueFound, JSONArray* protocolErrors); | 268 static PassRefPtr<JSONArray> getArray(JSONObject* object, const char* name,
bool* valueFound, JSONArray* protocolErrors); |
269 | 269 |
270 void sendResponse(long callId, PassRefPtr<JSONObject> result, const char* co
mmandName, PassRefPtr<JSONArray> protocolErrors, ErrorString invocationError, Pa
ssRefPtr<JSONValue> errorData); | 270 void sendResponse(long callId, PassRefPtr<JSONObject> result, const char* co
mmandName, PassRefPtr<JSONArray> protocolErrors, ErrorString invocationError, Pa
ssRefPtr<JSONValue> errorData); |
271 | 271 |
272 }; | 272 }; |
273 | 273 |
274 $methods | 274 $methods |
275 | 275 |
276 PassRefPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::create(Inspec
torFrontendChannel* inspectorFrontendChannel) | 276 PassRefPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::create(Inspec
torFrontendChannel* inspectorFrontendChannel) |
277 { | 277 { |
278 return adoptRef(new InspectorBackendDispatcherImpl(inspectorFrontendChannel)
); | 278 return adoptRef(new InspectorBackendDispatcherImpl(inspectorFrontendChannel)
); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 message->setObject("error", error); | 392 message->setObject("error", error); |
393 if (callId) | 393 if (callId) |
394 message->setNumber("id", *callId); | 394 message->setNumber("id", *callId); |
395 else | 395 else |
396 message->setValue("id", JSONValue::null()); | 396 message->setValue("id", JSONValue::null()); |
397 if (m_inspectorFrontendChannel) | 397 if (m_inspectorFrontendChannel) |
398 m_inspectorFrontendChannel->sendMessageToFrontend(message.release()); | 398 m_inspectorFrontendChannel->sendMessageToFrontend(message.release()); |
399 } | 399 } |
400 | 400 |
401 template<typename R, typename V, typename V0> | 401 template<typename R, typename V, typename V0> |
402 R InspectorBackendDispatcherImpl::getPropertyValueImpl(JSONObject* object, const
String& name, bool* valueFound, JSONArray* protocolErrors, V0 initial_value, bo
ol (*as_method)(JSONValue*, V*), const char* type_name) | 402 R InspectorBackendDispatcherImpl::getPropertyValueImpl(JSONObject* object, const
char* name, bool* valueFound, JSONArray* protocolErrors, V0 initial_value, bool
(*as_method)(JSONValue*, V*), const char* type_name) |
403 { | 403 { |
404 ASSERT(protocolErrors); | 404 ASSERT(protocolErrors); |
405 | 405 |
406 if (valueFound) | 406 if (valueFound) |
407 *valueFound = false; | 407 *valueFound = false; |
408 | 408 |
409 V value = initial_value; | 409 V value = initial_value; |
410 | 410 |
411 if (!object) { | 411 if (!object) { |
412 if (!valueFound) { | 412 if (!valueFound) { |
413 // Required parameter in missing params container. | 413 // Required parameter in missing params container. |
414 protocolErrors->pushString(String::format("'params' object must cont
ain required parameter '%s' with type '%s'.", name.utf8().data(), type_name)); | 414 protocolErrors->pushString(String::format("'params' object must cont
ain required parameter '%s' with type '%s'.", name, type_name)); |
415 } | 415 } |
416 return value; | 416 return value; |
417 } | 417 } |
418 | 418 |
419 JSONObject::const_iterator end = object->end(); | 419 JSONObject::const_iterator end = object->end(); |
420 JSONObject::const_iterator valueIterator = object->find(name); | 420 JSONObject::const_iterator valueIterator = object->find(name); |
421 | 421 |
422 if (valueIterator == end) { | 422 if (valueIterator == end) { |
423 if (!valueFound) | 423 if (!valueFound) |
424 protocolErrors->pushString(String::format("Parameter '%s' with type
'%s' was not found.", name.utf8().data(), type_name)); | 424 protocolErrors->pushString(String::format("Parameter '%s' with type
'%s' was not found.", name, type_name)); |
425 return value; | 425 return value; |
426 } | 426 } |
427 | 427 |
428 if (!as_method(valueIterator->value.get(), &value)) | 428 if (!as_method(valueIterator->value.get(), &value)) |
429 protocolErrors->pushString(String::format("Parameter '%s' has wrong type
. It must be '%s'.", name.utf8().data(), type_name)); | 429 protocolErrors->pushString(String::format("Parameter '%s' has wrong type
. It must be '%s'.", name, type_name)); |
430 else | 430 else |
431 if (valueFound) | 431 if (valueFound) |
432 *valueFound = true; | 432 *valueFound = true; |
433 return value; | 433 return value; |
434 } | 434 } |
435 | 435 |
436 struct AsMethodBridges { | 436 struct AsMethodBridges { |
437 static bool asInt(JSONValue* value, int* output) { return value->asNumber(ou
tput); } | 437 static bool asInt(JSONValue* value, int* output) { return value->asNumber(ou
tput); } |
438 static bool asDouble(JSONValue* value, double* output) { return value->asNum
ber(output); } | 438 static bool asDouble(JSONValue* value, double* output) { return value->asNum
ber(output); } |
439 static bool asString(JSONValue* value, String* output) { return value->asStr
ing(output); } | 439 static bool asString(JSONValue* value, String* output) { return value->asStr
ing(output); } |
440 static bool asBoolean(JSONValue* value, bool* output) { return value->asBool
ean(output); } | 440 static bool asBoolean(JSONValue* value, bool* output) { return value->asBool
ean(output); } |
441 static bool asObject(JSONValue* value, RefPtr<JSONObject>* output) { return
value->asObject(output); } | 441 static bool asObject(JSONValue* value, RefPtr<JSONObject>* output) { return
value->asObject(output); } |
442 static bool asArray(JSONValue* value, RefPtr<JSONArray>* output) { return va
lue->asArray(output); } | 442 static bool asArray(JSONValue* value, RefPtr<JSONArray>* output) { return va
lue->asArray(output); } |
443 }; | 443 }; |
444 | 444 |
445 int InspectorBackendDispatcherImpl::getInt(JSONObject* object, const String& nam
e, bool* valueFound, JSONArray* protocolErrors) | 445 int InspectorBackendDispatcherImpl::getInt(JSONObject* object, const char* name,
bool* valueFound, JSONArray* protocolErrors) |
446 { | 446 { |
447 return getPropertyValueImpl<int, int, int>(object, name, valueFound, protoco
lErrors, 0, AsMethodBridges::asInt, "Number"); | 447 return getPropertyValueImpl<int, int, int>(object, name, valueFound, protoco
lErrors, 0, AsMethodBridges::asInt, "Number"); |
448 } | 448 } |
449 | 449 |
450 double InspectorBackendDispatcherImpl::getDouble(JSONObject* object, const Strin
g& name, bool* valueFound, JSONArray* protocolErrors) | 450 double InspectorBackendDispatcherImpl::getDouble(JSONObject* object, const char*
name, bool* valueFound, JSONArray* protocolErrors) |
451 { | 451 { |
452 return getPropertyValueImpl<double, double, double>(object, name, valueFound
, protocolErrors, 0, AsMethodBridges::asDouble, "Number"); | 452 return getPropertyValueImpl<double, double, double>(object, name, valueFound
, protocolErrors, 0, AsMethodBridges::asDouble, "Number"); |
453 } | 453 } |
454 | 454 |
455 String InspectorBackendDispatcherImpl::getString(JSONObject* object, const Strin
g& name, bool* valueFound, JSONArray* protocolErrors) | 455 String InspectorBackendDispatcherImpl::getString(JSONObject* object, const char*
name, bool* valueFound, JSONArray* protocolErrors) |
456 { | 456 { |
457 return getPropertyValueImpl<String, String, String>(object, name, valueFound
, protocolErrors, "", AsMethodBridges::asString, "String"); | 457 return getPropertyValueImpl<String, String, String>(object, name, valueFound
, protocolErrors, "", AsMethodBridges::asString, "String"); |
458 } | 458 } |
459 | 459 |
460 bool InspectorBackendDispatcherImpl::getBoolean(JSONObject* object, const String
& name, bool* valueFound, JSONArray* protocolErrors) | 460 bool InspectorBackendDispatcherImpl::getBoolean(JSONObject* object, const char*
name, bool* valueFound, JSONArray* protocolErrors) |
461 { | 461 { |
462 return getPropertyValueImpl<bool, bool, bool>(object, name, valueFound, prot
ocolErrors, false, AsMethodBridges::asBoolean, "Boolean"); | 462 return getPropertyValueImpl<bool, bool, bool>(object, name, valueFound, prot
ocolErrors, false, AsMethodBridges::asBoolean, "Boolean"); |
463 } | 463 } |
464 | 464 |
465 PassRefPtr<JSONObject> InspectorBackendDispatcherImpl::getObject(JSONObject* obj
ect, const String& name, bool* valueFound, JSONArray* protocolErrors) | 465 PassRefPtr<JSONObject> InspectorBackendDispatcherImpl::getObject(JSONObject* obj
ect, const char* name, bool* valueFound, JSONArray* protocolErrors) |
466 { | 466 { |
467 return getPropertyValueImpl<PassRefPtr<JSONObject>, RefPtr<JSONObject>, JSON
Object*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asObject,
"Object"); | 467 return getPropertyValueImpl<PassRefPtr<JSONObject>, RefPtr<JSONObject>, JSON
Object*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asObject,
"Object"); |
468 } | 468 } |
469 | 469 |
470 PassRefPtr<JSONArray> InspectorBackendDispatcherImpl::getArray(JSONObject* objec
t, const String& name, bool* valueFound, JSONArray* protocolErrors) | 470 PassRefPtr<JSONArray> InspectorBackendDispatcherImpl::getArray(JSONObject* objec
t, const char* name, bool* valueFound, JSONArray* protocolErrors) |
471 { | 471 { |
472 return getPropertyValueImpl<PassRefPtr<JSONArray>, RefPtr<JSONArray>, JSONAr
ray*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asArray, "Ar
ray"); | 472 return getPropertyValueImpl<PassRefPtr<JSONArray>, RefPtr<JSONArray>, JSONAr
ray*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asArray, "Ar
ray"); |
473 } | 473 } |
474 | 474 |
475 bool InspectorBackendDispatcher::getCommandName(const String& message, String* r
esult) | 475 bool InspectorBackendDispatcher::getCommandName(const String& message, String* r
esult) |
476 { | 476 { |
477 RefPtr<JSONValue> value = parseJSON(message); | 477 RefPtr<JSONValue> value = parseJSON(message); |
478 if (!value) | 478 if (!value) |
479 return false; | 479 return false; |
480 | 480 |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 }; | 951 }; |
952 | 952 |
953 """) | 953 """) |
954 | 954 |
955 class_binding_builder_part_4 = ( | 955 class_binding_builder_part_4 = ( |
956 """ static Builder<NoFieldsSet> create() | 956 """ static Builder<NoFieldsSet> create() |
957 { | 957 { |
958 return Builder<NoFieldsSet>(JSONObject::create()); | 958 return Builder<NoFieldsSet>(JSONObject::create()); |
959 } | 959 } |
960 """) | 960 """) |
OLD | NEW |