| 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 15 matching lines...) Expand all Loading... |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 # THis file contains string resources for CodeGeneratorInspector. | 29 # THis file contains string resources for CodeGeneratorInspector. |
| 30 # Its syntax is a Python syntax subset, suitable for manual parsing. | 30 # Its syntax is a Python syntax subset, suitable for manual parsing. |
| 31 | 31 |
| 32 frontend_domain_class = ( | 32 frontend_domain_class = ( |
| 33 """ class $domainClassName { | 33 """ class $domainClassName { |
| 34 public: | 34 public: |
| 35 $domainClassName(InspectorFrontendChannel* inspectorFrontendChannel) : m
_inspectorFrontendChannel(inspectorFrontendChannel) { } | 35 $domainClassName(InspectorFrontendChannel* inspectorFrontendChannel) : m
_inspectorFrontendChannel(inspectorFrontendChannel) { } |
| 36 ${frontendDomainMethodDeclarations} void setInspectorFrontendChannel(Insp
ectorFrontendChannel* inspectorFrontendChannel) { m_inspectorFrontendChannel = i
nspectorFrontendChannel; } | 36 ${frontendDomainMethodDeclarations} |
| 37 InspectorFrontendChannel* getInspectorFrontendChannel() { return m_inspe
ctorFrontendChannel; } | 37 void flush() { m_inspectorFrontendChannel->flush(); } |
| 38 private: | 38 private: |
| 39 InspectorFrontendChannel* m_inspectorFrontendChannel; | 39 InspectorFrontendChannel* m_inspectorFrontendChannel; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 $domainClassName* $domainFieldName() { return &m_$domainFieldName; } | 42 $domainClassName* $domainFieldName() { return &m_$domainFieldName; } |
| 43 | 43 |
| 44 """) | 44 """) |
| 45 | 45 |
| 46 backend_method = ( | 46 backend_method = ( |
| 47 """void InspectorBackendDispatcherImpl::${domainName}_$methodName(long callId, J
SONObject*$requestMessageObject) | 47 """void InspectorBackendDispatcherImpl::${domainName}_$methodName(long callId, J
SONObject*$requestMessageObject, JSONArray* protocolErrors) |
| 48 { | 48 { |
| 49 RefPtr<JSONArray> protocolErrors = JSONArray::create(); | |
| 50 | |
| 51 if (!$agentField) | 49 if (!$agentField) |
| 52 protocolErrors->pushString("${domainName} handler is not available."); | 50 protocolErrors->pushString("${domainName} handler is not available."); |
| 53 $methodOutCode | 51 $methodCode |
| 54 $methodInCode | 52 if (protocolErrors->length()) { |
| 55 RefPtr<JSONObject> result = JSONObject::create(); | 53 reportProtocolError(&callId, InvalidParams, String::format(InvalidParams
FormatString, commandName($commandNameIndex)), protocolErrors); |
| 56 RefPtr<JSONValue> resultErrorData; | 54 return; |
| 57 ErrorString error; | |
| 58 if (!protocolErrors->length()) { | |
| 59 $agentField->$methodName(&error$agentCallParams); | |
| 60 | |
| 61 $errorCook${responseCook} | |
| 62 } | 55 } |
| 63 sendResponse(callId, result, commandName($commandNameIndex), protocolErrors,
error, resultErrorData); | 56 $agentCallParamsDeclaration |
| 57 $agentField->$methodName($agentCallParams); |
| 58 $responseCook |
| 59 sendResponse(callId, $sendResponseCallParams); |
| 64 } | 60 } |
| 65 """) | 61 """) |
| 66 | 62 |
| 67 frontend_method = ("""void InspectorFrontend::$domainName::$eventName($parameter
s) | 63 frontend_method = ("""void InspectorFrontend::$domainName::$eventName($parameter
s) |
| 68 { | 64 { |
| 69 RefPtr<JSONObject> jsonMessage = JSONObject::create(); | 65 RefPtr<JSONObject> jsonMessage = JSONObject::create(); |
| 70 jsonMessage->setString("method", "$domainName.$eventName"); | 66 jsonMessage->setString("method", "$domainName.$eventName"); |
| 71 $code if (m_inspectorFrontendChannel) | 67 $code if (m_inspectorFrontendChannel) |
| 72 m_inspectorFrontendChannel->sendMessageToFrontend(jsonMessage->toJSONStr
ing()); | 68 m_inspectorFrontendChannel->sendMessageToFrontend(jsonMessage.release())
; |
| 73 } | 69 } |
| 74 """) | 70 """) |
| 75 | 71 |
| 76 callback_main_methods = ( | 72 callback_main_methods = ( |
| 77 """InspectorBackendDispatcher::$agentName::$callbackName::$callbackName(PassRefP
tr<InspectorBackendDispatcherImpl> backendImpl, int id) : CallbackBase(backendIm
pl, id) {} | 73 """InspectorBackendDispatcher::$agentName::$callbackName::$callbackName(PassRefP
tr<InspectorBackendDispatcherImpl> backendImpl, int id) : CallbackBase(backendIm
pl, id) {} |
| 78 | 74 |
| 79 void InspectorBackendDispatcher::$agentName::$callbackName::sendSuccess($paramet
ers) | 75 void InspectorBackendDispatcher::$agentName::$callbackName::sendSuccess($paramet
ers) |
| 80 { | 76 { |
| 81 RefPtr<JSONObject> jsonMessage = JSONObject::create(); | 77 RefPtr<JSONObject> jsonMessage = JSONObject::create(); |
| 82 $code sendIfActive(jsonMessage, ErrorString(), PassRefPtr<JSONValue>()); | 78 $code sendIfActive(jsonMessage, ErrorString(), PassRefPtr<JSONValue>()); |
| 83 } | 79 } |
| 84 """) | 80 """) |
| 85 | 81 |
| 86 callback_failure_method = ( | 82 callback_failure_method = ( |
| 87 """void InspectorBackendDispatcher::$agentName::$callbackName::sendFailure(const
ErrorString& error, $parameter) | 83 """void InspectorBackendDispatcher::$agentName::$callbackName::sendFailure(const
ErrorString& error, $parameter) |
| 88 { | 84 { |
| 89 ASSERT(error.length()); | 85 ASSERT(error.length()); |
| 90 RefPtr<JSONValue> errorDataValue; | 86 RefPtr<JSONValue> errorDataValue; |
| 91 if (error) { | 87 if (error) { |
| 92 errorDataValue = $argument; | 88 errorDataValue = $argument; |
| 93 } | 89 } |
| 94 sendIfActive(0, error, errorDataValue.release()); | 90 sendIfActive(nullptr, error, errorDataValue.release()); |
| 95 } | 91 } |
| 96 """) | 92 """) |
| 97 | 93 |
| 98 | 94 |
| 99 frontend_h = ( | 95 frontend_h = ( |
| 100 """#ifndef InspectorFrontend_h | 96 """#ifndef InspectorFrontend_h |
| 101 #define InspectorFrontend_h | 97 #define InspectorFrontend_h |
| 102 | 98 |
| 103 #include "InspectorTypeBuilder.h" | 99 #include "InspectorTypeBuilder.h" |
| 100 #include "core/inspector/InspectorFrontendChannel.h" |
| 104 #include "platform/JSONValues.h" | 101 #include "platform/JSONValues.h" |
| 105 #include "wtf/PassRefPtr.h" | 102 #include "wtf/PassRefPtr.h" |
| 106 #include "wtf/text/WTFString.h" | 103 #include "wtf/text/WTFString.h" |
| 107 | 104 |
| 108 namespace WebCore { | 105 namespace WebCore { |
| 109 | 106 |
| 110 class InspectorFrontendChannel; | |
| 111 | |
| 112 typedef String ErrorString; | 107 typedef String ErrorString; |
| 113 | 108 |
| 114 class InspectorFrontend { | 109 class InspectorFrontend { |
| 115 public: | 110 public: |
| 116 InspectorFrontend(InspectorFrontendChannel*); | 111 InspectorFrontend(InspectorFrontendChannel*); |
| 117 | 112 InspectorFrontendChannel* channel() { return m_inspectorFrontendChannel; } |
| 118 | 113 |
| 119 $domainClassList | 114 $domainClassList |
| 120 private: | 115 private: |
| 116 InspectorFrontendChannel* m_inspectorFrontendChannel; |
| 121 ${fieldDeclarations}}; | 117 ${fieldDeclarations}}; |
| 122 | 118 |
| 123 } // namespace WebCore | 119 } // namespace WebCore |
| 124 #endif // !defined(InspectorFrontend_h) | 120 #endif // !defined(InspectorFrontend_h) |
| 125 """) | 121 """) |
| 126 | 122 |
| 127 backend_h = ( | 123 backend_h = ( |
| 128 """#ifndef InspectorBackendDispatcher_h | 124 """#ifndef InspectorBackendDispatcher_h |
| 129 #define InspectorBackendDispatcher_h | 125 #define InspectorBackendDispatcher_h |
| 130 | 126 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 InspectorBackendDispatcherImpl(InspectorFrontendChannel* inspectorFrontendCh
annel) | 236 InspectorBackendDispatcherImpl(InspectorFrontendChannel* inspectorFrontendCh
annel) |
| 241 : m_inspectorFrontendChannel(inspectorFrontendChannel) | 237 : m_inspectorFrontendChannel(inspectorFrontendChannel) |
| 242 $constructorInit | 238 $constructorInit |
| 243 { } | 239 { } |
| 244 | 240 |
| 245 virtual void clearFrontend() { m_inspectorFrontendChannel = 0; } | 241 virtual void clearFrontend() { m_inspectorFrontendChannel = 0; } |
| 246 virtual void dispatch(const String& message); | 242 virtual void dispatch(const String& message); |
| 247 virtual void reportProtocolError(const long* const callId, CommonErrorCode,
const String& errorMessage, PassRefPtr<JSONValue> data) const; | 243 virtual void reportProtocolError(const long* const callId, CommonErrorCode,
const String& errorMessage, PassRefPtr<JSONValue> data) const; |
| 248 using InspectorBackendDispatcher::reportProtocolError; | 244 using InspectorBackendDispatcher::reportProtocolError; |
| 249 | 245 |
| 250 void sendResponse(long callId, PassRefPtr<JSONObject> result, const ErrorStr
ing&invocationError, PassRefPtr<JSONValue> errorData); | 246 void sendResponse(long callId, const ErrorString& invocationError, PassRefPt
r<JSONValue> errorData, PassRefPtr<JSONObject> result); |
| 251 bool isActive() { return m_inspectorFrontendChannel; } | 247 bool isActive() { return m_inspectorFrontendChannel; } |
| 252 | 248 |
| 253 $setters | 249 $setters |
| 254 private: | 250 private: |
| 255 $methodDeclarations | 251 $methodDeclarations |
| 256 | 252 |
| 257 InspectorFrontendChannel* m_inspectorFrontendChannel; | 253 InspectorFrontendChannel* m_inspectorFrontendChannel; |
| 258 $fieldDeclarations | 254 $fieldDeclarations |
| 259 | 255 |
| 260 template<typename R, typename V, typename V0> | 256 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); | 257 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 | 258 |
| 263 static int getInt(JSONObject* object, const String& name, bool* valueFound,
JSONArray* protocolErrors); | 259 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); | 260 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); | 261 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); | 262 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); | 263 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); | 264 static PassRefPtr<JSONArray> getArray(JSONObject* object, const char* name,
bool* valueFound, JSONArray* protocolErrors); |
| 269 | 265 |
| 270 void sendResponse(long callId, PassRefPtr<JSONObject> result, const char* co
mmandName, PassRefPtr<JSONArray> protocolErrors, ErrorString invocationError, Pa
ssRefPtr<JSONValue> errorData); | 266 void sendResponse(long callId, ErrorString invocationError, PassRefPtr<JSONO
bject> result) |
| 267 { |
| 268 sendResponse(callId, invocationError, RefPtr<JSONValue>(), result); |
| 269 } |
| 270 void sendResponse(long callId, ErrorString invocationError) |
| 271 { |
| 272 sendResponse(callId, invocationError, RefPtr<JSONValue>(), JSONObject::c
reate()); |
| 273 } |
| 274 static const char InvalidParamsFormatString[]; |
| 275 }; |
| 271 | 276 |
| 272 }; | 277 const char InspectorBackendDispatcherImpl::InvalidParamsFormatString[] = "Some a
rguments of method '%s' can't be processed"; |
| 273 | 278 |
| 274 $methods | 279 $methods |
| 275 | 280 |
| 276 PassRefPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::create(Inspec
torFrontendChannel* inspectorFrontendChannel) | 281 PassRefPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::create(Inspec
torFrontendChannel* inspectorFrontendChannel) |
| 277 { | 282 { |
| 278 return adoptRef(new InspectorBackendDispatcherImpl(inspectorFrontendChannel)
); | 283 return adoptRef(new InspectorBackendDispatcherImpl(inspectorFrontendChannel)
); |
| 279 } | 284 } |
| 280 | 285 |
| 281 | 286 |
| 282 void InspectorBackendDispatcherImpl::dispatch(const String& message) | 287 void InspectorBackendDispatcherImpl::dispatch(const String& message) |
| 283 { | 288 { |
| 284 RefPtr<InspectorBackendDispatcher> protect = this; | 289 RefPtr<InspectorBackendDispatcher> protect = this; |
| 285 typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, JSO
NObject* messageObject); | 290 typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, JSO
NObject* messageObject, JSONArray* protocolErrors); |
| 286 typedef HashMap<String, CallHandler> DispatchMap; | 291 typedef HashMap<String, CallHandler> DispatchMap; |
| 287 DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, ); | 292 DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, ); |
| 288 long callId = 0; | 293 long callId = 0; |
| 289 | 294 |
| 290 if (dispatchMap.isEmpty()) { | 295 if (dispatchMap.isEmpty()) { |
| 291 static const CallHandler handlers[] = { | 296 static const CallHandler handlers[] = { |
| 292 $messageHandlers | 297 $messageHandlers |
| 293 }; | 298 }; |
| 294 for (size_t i = 0; i < kMethodNamesEnumSize; ++i) | 299 for (size_t i = 0; i < kMethodNamesEnumSize; ++i) |
| 295 dispatchMap.add(commandName(static_cast<MethodNames>(i)), handlers[i
]); | 300 dispatchMap.add(commandName(static_cast<MethodNames>(i)), handlers[i
]); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 reportProtocolError(&callId, InvalidRequest, "The type of 'method' prope
rty must be string"); | 334 reportProtocolError(&callId, InvalidRequest, "The type of 'method' prope
rty must be string"); |
| 330 return; | 335 return; |
| 331 } | 336 } |
| 332 | 337 |
| 333 HashMap<String, CallHandler>::iterator it = dispatchMap.find(method); | 338 HashMap<String, CallHandler>::iterator it = dispatchMap.find(method); |
| 334 if (it == dispatchMap.end()) { | 339 if (it == dispatchMap.end()) { |
| 335 reportProtocolError(&callId, MethodNotFound, "'" + method + "' wasn't fo
und"); | 340 reportProtocolError(&callId, MethodNotFound, "'" + method + "' wasn't fo
und"); |
| 336 return; | 341 return; |
| 337 } | 342 } |
| 338 | 343 |
| 339 ((*this).*it->value)(callId, messageObject.get()); | 344 RefPtr<JSONArray> protocolErrors = JSONArray::create(); |
| 345 ((*this).*it->value)(callId, messageObject.get(), protocolErrors.get()); |
| 340 } | 346 } |
| 341 | 347 |
| 342 void InspectorBackendDispatcherImpl::sendResponse(long callId, PassRefPtr<JSONOb
ject> result, const char* commandName, PassRefPtr<JSONArray> protocolErrors, Err
orString invocationError, PassRefPtr<JSONValue> errorData) | 348 void InspectorBackendDispatcherImpl::sendResponse(long callId, const ErrorString
& invocationError, PassRefPtr<JSONValue> errorData, PassRefPtr<JSONObject> resul
t) |
| 343 { | |
| 344 if (protocolErrors->length()) { | |
| 345 String errorMessage = String::format("Some arguments of method '%s' can'
t be processed", commandName); | |
| 346 reportProtocolError(&callId, InvalidParams, errorMessage, protocolErrors
); | |
| 347 return; | |
| 348 } | |
| 349 sendResponse(callId, result, invocationError, errorData); | |
| 350 } | |
| 351 | |
| 352 void InspectorBackendDispatcherImpl::sendResponse(long callId, PassRefPtr<JSONOb
ject> result, const ErrorString& invocationError, PassRefPtr<JSONValue> errorDat
a) | |
| 353 { | 349 { |
| 354 if (invocationError.length()) { | 350 if (invocationError.length()) { |
| 355 reportProtocolError(&callId, ServerError, invocationError, errorData); | 351 reportProtocolError(&callId, ServerError, invocationError, errorData); |
| 356 return; | 352 return; |
| 357 } | 353 } |
| 358 | 354 |
| 359 RefPtr<JSONObject> responseMessage = JSONObject::create(); | 355 RefPtr<JSONObject> responseMessage = JSONObject::create(); |
| 356 responseMessage->setNumber("id", callId); |
| 360 responseMessage->setObject("result", result); | 357 responseMessage->setObject("result", result); |
| 361 responseMessage->setNumber("id", callId); | |
| 362 if (m_inspectorFrontendChannel) | 358 if (m_inspectorFrontendChannel) |
| 363 m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage->toJSO
NString()); | 359 m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage.releas
e()); |
| 364 } | 360 } |
| 365 | 361 |
| 366 void InspectorBackendDispatcher::reportProtocolError(const long* const callId, C
ommonErrorCode code, const String& errorMessage) const | 362 void InspectorBackendDispatcher::reportProtocolError(const long* const callId, C
ommonErrorCode code, const String& errorMessage) const |
| 367 { | 363 { |
| 368 reportProtocolError(callId, code, errorMessage, PassRefPtr<JSONValue>()); | 364 reportProtocolError(callId, code, errorMessage, PassRefPtr<JSONValue>()); |
| 369 } | 365 } |
| 370 | 366 |
| 371 void InspectorBackendDispatcherImpl::reportProtocolError(const long* const callI
d, CommonErrorCode code, const String& errorMessage, PassRefPtr<JSONValue> data)
const | 367 void InspectorBackendDispatcherImpl::reportProtocolError(const long* const callI
d, CommonErrorCode code, const String& errorMessage, PassRefPtr<JSONValue> data)
const |
| 372 { | 368 { |
| 373 DEFINE_STATIC_LOCAL(Vector<int>,s_commonErrors,); | 369 DEFINE_STATIC_LOCAL(Vector<int>,s_commonErrors,); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 388 ASSERT(error); | 384 ASSERT(error); |
| 389 if (data) | 385 if (data) |
| 390 error->setValue("data", data); | 386 error->setValue("data", data); |
| 391 RefPtr<JSONObject> message = JSONObject::create(); | 387 RefPtr<JSONObject> message = JSONObject::create(); |
| 392 message->setObject("error", error); | 388 message->setObject("error", error); |
| 393 if (callId) | 389 if (callId) |
| 394 message->setNumber("id", *callId); | 390 message->setNumber("id", *callId); |
| 395 else | 391 else |
| 396 message->setValue("id", JSONValue::null()); | 392 message->setValue("id", JSONValue::null()); |
| 397 if (m_inspectorFrontendChannel) | 393 if (m_inspectorFrontendChannel) |
| 398 m_inspectorFrontendChannel->sendMessageToFrontend(message->toJSONString(
)); | 394 m_inspectorFrontendChannel->sendMessageToFrontend(message.release()); |
| 399 } | 395 } |
| 400 | 396 |
| 401 template<typename R, typename V, typename V0> | 397 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) | 398 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 { | 399 { |
| 404 ASSERT(protocolErrors); | 400 ASSERT(protocolErrors); |
| 405 | 401 |
| 406 if (valueFound) | 402 if (valueFound) |
| 407 *valueFound = false; | 403 *valueFound = false; |
| 408 | 404 |
| 409 V value = initial_value; | 405 V value = initial_value; |
| 410 | 406 |
| 411 if (!object) { | 407 if (!object) { |
| 412 if (!valueFound) { | 408 if (!valueFound) { |
| 413 // Required parameter in missing params container. | 409 // 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)); | 410 protocolErrors->pushString(String::format("'params' object must cont
ain required parameter '%s' with type '%s'.", name, type_name)); |
| 415 } | 411 } |
| 416 return value; | 412 return value; |
| 417 } | 413 } |
| 418 | 414 |
| 419 JSONObject::const_iterator end = object->end(); | 415 JSONObject::const_iterator end = object->end(); |
| 420 JSONObject::const_iterator valueIterator = object->find(name); | 416 JSONObject::const_iterator valueIterator = object->find(name); |
| 421 | 417 |
| 422 if (valueIterator == end) { | 418 if (valueIterator == end) { |
| 423 if (!valueFound) | 419 if (!valueFound) |
| 424 protocolErrors->pushString(String::format("Parameter '%s' with type
'%s' was not found.", name.utf8().data(), type_name)); | 420 protocolErrors->pushString(String::format("Parameter '%s' with type
'%s' was not found.", name, type_name)); |
| 425 return value; | 421 return value; |
| 426 } | 422 } |
| 427 | 423 |
| 428 if (!as_method(valueIterator->value.get(), &value)) | 424 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)); | 425 protocolErrors->pushString(String::format("Parameter '%s' has wrong type
. It must be '%s'.", name, type_name)); |
| 430 else | 426 else |
| 431 if (valueFound) | 427 if (valueFound) |
| 432 *valueFound = true; | 428 *valueFound = true; |
| 433 return value; | 429 return value; |
| 434 } | 430 } |
| 435 | 431 |
| 436 struct AsMethodBridges { | 432 struct AsMethodBridges { |
| 437 static bool asInt(JSONValue* value, int* output) { return value->asNumber(ou
tput); } | 433 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); } | 434 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); } | 435 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); } | 436 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); } | 437 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); } | 438 static bool asArray(JSONValue* value, RefPtr<JSONArray>* output) { return va
lue->asArray(output); } |
| 443 }; | 439 }; |
| 444 | 440 |
| 445 int InspectorBackendDispatcherImpl::getInt(JSONObject* object, const String& nam
e, bool* valueFound, JSONArray* protocolErrors) | 441 int InspectorBackendDispatcherImpl::getInt(JSONObject* object, const char* name,
bool* valueFound, JSONArray* protocolErrors) |
| 446 { | 442 { |
| 447 return getPropertyValueImpl<int, int, int>(object, name, valueFound, protoco
lErrors, 0, AsMethodBridges::asInt, "Number"); | 443 return getPropertyValueImpl<int, int, int>(object, name, valueFound, protoco
lErrors, 0, AsMethodBridges::asInt, "Number"); |
| 448 } | 444 } |
| 449 | 445 |
| 450 double InspectorBackendDispatcherImpl::getDouble(JSONObject* object, const Strin
g& name, bool* valueFound, JSONArray* protocolErrors) | 446 double InspectorBackendDispatcherImpl::getDouble(JSONObject* object, const char*
name, bool* valueFound, JSONArray* protocolErrors) |
| 451 { | 447 { |
| 452 return getPropertyValueImpl<double, double, double>(object, name, valueFound
, protocolErrors, 0, AsMethodBridges::asDouble, "Number"); | 448 return getPropertyValueImpl<double, double, double>(object, name, valueFound
, protocolErrors, 0, AsMethodBridges::asDouble, "Number"); |
| 453 } | 449 } |
| 454 | 450 |
| 455 String InspectorBackendDispatcherImpl::getString(JSONObject* object, const Strin
g& name, bool* valueFound, JSONArray* protocolErrors) | 451 String InspectorBackendDispatcherImpl::getString(JSONObject* object, const char*
name, bool* valueFound, JSONArray* protocolErrors) |
| 456 { | 452 { |
| 457 return getPropertyValueImpl<String, String, String>(object, name, valueFound
, protocolErrors, "", AsMethodBridges::asString, "String"); | 453 return getPropertyValueImpl<String, String, String>(object, name, valueFound
, protocolErrors, "", AsMethodBridges::asString, "String"); |
| 458 } | 454 } |
| 459 | 455 |
| 460 bool InspectorBackendDispatcherImpl::getBoolean(JSONObject* object, const String
& name, bool* valueFound, JSONArray* protocolErrors) | 456 bool InspectorBackendDispatcherImpl::getBoolean(JSONObject* object, const char*
name, bool* valueFound, JSONArray* protocolErrors) |
| 461 { | 457 { |
| 462 return getPropertyValueImpl<bool, bool, bool>(object, name, valueFound, prot
ocolErrors, false, AsMethodBridges::asBoolean, "Boolean"); | 458 return getPropertyValueImpl<bool, bool, bool>(object, name, valueFound, prot
ocolErrors, false, AsMethodBridges::asBoolean, "Boolean"); |
| 463 } | 459 } |
| 464 | 460 |
| 465 PassRefPtr<JSONObject> InspectorBackendDispatcherImpl::getObject(JSONObject* obj
ect, const String& name, bool* valueFound, JSONArray* protocolErrors) | 461 PassRefPtr<JSONObject> InspectorBackendDispatcherImpl::getObject(JSONObject* obj
ect, const char* name, bool* valueFound, JSONArray* protocolErrors) |
| 466 { | 462 { |
| 467 return getPropertyValueImpl<PassRefPtr<JSONObject>, RefPtr<JSONObject>, JSON
Object*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asObject,
"Object"); | 463 return getPropertyValueImpl<PassRefPtr<JSONObject>, RefPtr<JSONObject>, JSON
Object*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asObject,
"Object"); |
| 468 } | 464 } |
| 469 | 465 |
| 470 PassRefPtr<JSONArray> InspectorBackendDispatcherImpl::getArray(JSONObject* objec
t, const String& name, bool* valueFound, JSONArray* protocolErrors) | 466 PassRefPtr<JSONArray> InspectorBackendDispatcherImpl::getArray(JSONObject* objec
t, const char* name, bool* valueFound, JSONArray* protocolErrors) |
| 471 { | 467 { |
| 472 return getPropertyValueImpl<PassRefPtr<JSONArray>, RefPtr<JSONArray>, JSONAr
ray*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asArray, "Ar
ray"); | 468 return getPropertyValueImpl<PassRefPtr<JSONArray>, RefPtr<JSONArray>, JSONAr
ray*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asArray, "Ar
ray"); |
| 473 } | 469 } |
| 474 | 470 |
| 475 bool InspectorBackendDispatcher::getCommandName(const String& message, String* r
esult) | 471 bool InspectorBackendDispatcher::getCommandName(const String& message, String* r
esult) |
| 476 { | 472 { |
| 477 RefPtr<JSONValue> value = parseJSON(message); | 473 RefPtr<JSONValue> value = parseJSON(message); |
| 478 if (!value) | 474 if (!value) |
| 479 return false; | 475 return false; |
| 480 | 476 |
| 481 RefPtr<JSONObject> object = value->asObject(); | 477 RefPtr<JSONObject> object = value->asObject(); |
| 482 if (!object) | 478 if (!object) |
| 483 return false; | 479 return false; |
| 484 | 480 |
| 485 if (!object->getString("method", result)) | 481 if (!object->getString("method", result)) |
| 486 return false; | 482 return false; |
| 487 | 483 |
| 488 return true; | 484 return true; |
| 489 } | 485 } |
| 490 | 486 |
| 491 InspectorBackendDispatcher::CallbackBase::CallbackBase(PassRefPtr<InspectorBacke
ndDispatcherImpl> backendImpl, int id) | 487 InspectorBackendDispatcher::CallbackBase::CallbackBase(PassRefPtr<InspectorBacke
ndDispatcherImpl> backendImpl, int id) |
| 492 : m_backendImpl(backendImpl), m_id(id), m_alreadySent(false) {} | 488 : m_backendImpl(backendImpl), m_id(id), m_alreadySent(false) {} |
| 493 | 489 |
| 494 InspectorBackendDispatcher::CallbackBase::~CallbackBase() {} | 490 InspectorBackendDispatcher::CallbackBase::~CallbackBase() {} |
| 495 | 491 |
| 496 void InspectorBackendDispatcher::CallbackBase::sendFailure(const ErrorString& er
ror) | 492 void InspectorBackendDispatcher::CallbackBase::sendFailure(const ErrorString& er
ror) |
| 497 { | 493 { |
| 498 ASSERT(error.length()); | 494 ASSERT(error.length()); |
| 499 sendIfActive(0, error, PassRefPtr<JSONValue>()); | 495 sendIfActive(nullptr, error, PassRefPtr<JSONValue>()); |
| 500 } | 496 } |
| 501 | 497 |
| 502 bool InspectorBackendDispatcher::CallbackBase::isActive() | 498 bool InspectorBackendDispatcher::CallbackBase::isActive() |
| 503 { | 499 { |
| 504 return !m_alreadySent && m_backendImpl->isActive(); | 500 return !m_alreadySent && m_backendImpl->isActive(); |
| 505 } | 501 } |
| 506 | 502 |
| 507 void InspectorBackendDispatcher::CallbackBase::sendIfActive(PassRefPtr<JSONObjec
t> partialMessage, const ErrorString& invocationError, PassRefPtr<JSONValue> err
orData) | 503 void InspectorBackendDispatcher::CallbackBase::sendIfActive(PassRefPtr<JSONObjec
t> partialMessage, const ErrorString& invocationError, PassRefPtr<JSONValue> err
orData) |
| 508 { | 504 { |
| 509 if (m_alreadySent) | 505 if (m_alreadySent) |
| 510 return; | 506 return; |
| 511 m_backendImpl->sendResponse(m_id, partialMessage, invocationError, errorData
); | 507 m_backendImpl->sendResponse(m_id, invocationError, errorData, partialMessage
); |
| 512 m_alreadySent = true; | 508 m_alreadySent = true; |
| 513 } | 509 } |
| 514 | 510 |
| 515 } // namespace WebCore | 511 } // namespace WebCore |
| 516 | 512 |
| 517 """) | 513 """) |
| 518 | 514 |
| 519 frontend_cpp = ( | 515 frontend_cpp = ( |
| 520 """ | 516 """ |
| 521 | 517 |
| 522 #include "config.h" | 518 #include "config.h" |
| 523 #include "InspectorFrontend.h" | 519 #include "InspectorFrontend.h" |
| 524 | 520 |
| 525 #include "core/inspector/InspectorFrontendChannel.h" | 521 #include "core/inspector/InspectorFrontendChannel.h" |
| 526 #include "platform/JSONValues.h" | 522 #include "platform/JSONValues.h" |
| 527 #include "wtf/text/CString.h" | 523 #include "wtf/text/CString.h" |
| 528 #include "wtf/text/WTFString.h" | 524 #include "wtf/text/WTFString.h" |
| 529 | 525 |
| 530 namespace WebCore { | 526 namespace WebCore { |
| 531 | 527 |
| 532 InspectorFrontend::InspectorFrontend(InspectorFrontendChannel* inspectorFrontend
Channel) | 528 InspectorFrontend::InspectorFrontend(InspectorFrontendChannel* inspectorFrontend
Channel) |
| 533 : $constructorInit{ | 529 : m_inspectorFrontendChannel(inspectorFrontendChannel) |
| 530 , $constructorInit |
| 531 { |
| 534 } | 532 } |
| 535 | 533 |
| 536 $methods | 534 $methods |
| 537 | 535 |
| 538 } // namespace WebCore | 536 } // namespace WebCore |
| 539 | 537 |
| 540 """) | 538 """) |
| 541 | 539 |
| 542 typebuilder_h = ( | 540 typebuilder_h = ( |
| 543 """ | 541 """ |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 RefPtr<JSONArray> array; | 652 RefPtr<JSONArray> array; |
| 655 bool castRes = value->asArray(&array); | 653 bool castRes = value->asArray(&array); |
| 656 ASSERT_UNUSED(castRes, castRes); | 654 ASSERT_UNUSED(castRes, castRes); |
| 657 #if $validatorIfdefName | 655 #if $validatorIfdefName |
| 658 assertCorrectValue(array.get()); | 656 assertCorrectValue(array.get()); |
| 659 #endif // $validatorIfdefName | 657 #endif // $validatorIfdefName |
| 660 COMPILE_ASSERT(sizeof(Array<T>) == sizeof(JSONArray), type_cast_problem)
; | 658 COMPILE_ASSERT(sizeof(Array<T>) == sizeof(JSONArray), type_cast_problem)
; |
| 661 return static_cast<Array<T>*>(static_cast<JSONArrayBase*>(array.get())); | 659 return static_cast<Array<T>*>(static_cast<JSONArrayBase*>(array.get())); |
| 662 } | 660 } |
| 663 | 661 |
| 662 void concat(PassRefPtr<Array<T> > array) |
| 663 { |
| 664 return ArrayItemHelper<T>::Traits::concat(this->openAccessors(), array->
openAccessors()); |
| 665 } |
| 666 |
| 664 #if $validatorIfdefName | 667 #if $validatorIfdefName |
| 665 static void assertCorrectValue(JSONValue* value) | 668 static void assertCorrectValue(JSONValue* value) |
| 666 { | 669 { |
| 667 RefPtr<JSONArray> array; | 670 RefPtr<JSONArray> array; |
| 668 bool castRes = value->asArray(&array); | 671 bool castRes = value->asArray(&array); |
| 669 ASSERT_UNUSED(castRes, castRes); | 672 ASSERT_UNUSED(castRes, castRes); |
| 670 for (unsigned i = 0; i < array->length(); i++) | 673 for (unsigned i = 0; i < array->length(); i++) |
| 671 ArrayItemHelper<T>::Traits::template assertCorrectValue<T>(array->ge
t(i).get()); | 674 ArrayItemHelper<T>::Traits::template assertCorrectValue<T>(array->ge
t(i).get()); |
| 672 } | 675 } |
| 673 | 676 |
| 674 #endif // $validatorIfdefName | 677 #endif // $validatorIfdefName |
| 675 }; | 678 }; |
| 676 | 679 |
| 677 struct StructItemTraits { | 680 struct StructItemTraits { |
| 678 static void pushRefPtr(JSONArray* array, PassRefPtr<JSONValue> value) | 681 static void pushRefPtr(JSONArray* array, PassRefPtr<JSONValue> value) |
| 679 { | 682 { |
| 680 array->pushValue(value); | 683 array->pushValue(value); |
| 681 } | 684 } |
| 682 | 685 |
| 686 static void concat(JSONArray* array, JSONArray* anotherArray) |
| 687 { |
| 688 for (JSONArray::iterator it = anotherArray->begin(); it != anotherArray-
>end(); ++it) |
| 689 array->pushValue(*it); |
| 690 } |
| 691 |
| 683 #if $validatorIfdefName | 692 #if $validatorIfdefName |
| 684 template<typename T> | 693 template<typename T> |
| 685 static void assertCorrectValue(JSONValue* value) { | 694 static void assertCorrectValue(JSONValue* value) { |
| 686 T::assertCorrectValue(value); | 695 T::assertCorrectValue(value); |
| 687 } | 696 } |
| 688 #endif // $validatorIfdefName | 697 #endif // $validatorIfdefName |
| 689 }; | 698 }; |
| 690 | 699 |
| 691 template<> | 700 template<> |
| 692 struct ArrayItemHelper<String> { | 701 struct ArrayItemHelper<String> { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 | 890 |
| 882 #endif // $validatorIfdefName | 891 #endif // $validatorIfdefName |
| 883 | 892 |
| 884 } // namespace WebCore | 893 } // namespace WebCore |
| 885 | 894 |
| 886 """) | 895 """) |
| 887 | 896 |
| 888 param_container_access_code = """ | 897 param_container_access_code = """ |
| 889 RefPtr<JSONObject> paramsContainer = requestMessageObject->getObject("params
"); | 898 RefPtr<JSONObject> paramsContainer = requestMessageObject->getObject("params
"); |
| 890 JSONObject* paramsContainerPtr = paramsContainer.get(); | 899 JSONObject* paramsContainerPtr = paramsContainer.get(); |
| 891 JSONArray* protocolErrorsPtr = protocolErrors.get(); | |
| 892 """ | 900 """ |
| 893 | 901 |
| 894 class_binding_builder_part_1 = ( | 902 class_binding_builder_part_1 = ( |
| 895 """ AllFieldsSet = %s | 903 """ AllFieldsSet = %s |
| 896 }; | 904 }; |
| 897 | 905 |
| 898 template<int STATE> | 906 template<int STATE> |
| 899 class Builder { | 907 class Builder { |
| 900 private: | 908 private: |
| 901 RefPtr<JSONObject> m_result; | 909 RefPtr<JSONObject> m_result; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 }; | 946 }; |
| 939 | 947 |
| 940 """) | 948 """) |
| 941 | 949 |
| 942 class_binding_builder_part_4 = ( | 950 class_binding_builder_part_4 = ( |
| 943 """ static Builder<NoFieldsSet> create() | 951 """ static Builder<NoFieldsSet> create() |
| 944 { | 952 { |
| 945 return Builder<NoFieldsSet>(JSONObject::create()); | 953 return Builder<NoFieldsSet>(JSONObject::create()); |
| 946 } | 954 } |
| 947 """) | 955 """) |
| OLD | NEW |