Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: Source/core/inspector/CodeGeneratorInspectorStrings.py

Issue 325833002: DevTools: eliminate 1k lines of generated code in InspectorBackendDispatcher.cpp (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/inspector/CodeGeneratorInspector.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 26 matching lines...) Expand all
37 void flush() { m_inspectorFrontendChannel->flush(); } 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();
yurys 2014/06/10 07:36:19 I'd rather we left previous implementation where p
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;
55 }
57 ErrorString error; 56 ErrorString error;
58 if (!protocolErrors->length()) { 57 $agentField->$methodName(&error$agentCallParams);
59 $agentField->$methodName(&error$agentCallParams); 58 $responseCook
60 59 sendResponse(callId, $sendResponseCallParams);
61 $errorCook${responseCook}
62 }
63 sendResponse(callId, result, commandName($commandNameIndex), protocolErrors, error, resultErrorData);
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.release()) ; 68 m_inspectorFrontendChannel->sendMessageToFrontend(jsonMessage.release()) ;
73 } 69 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 char* name, bool* va lueFound, JSONArray* protocolErrors, V0 initial_value, bool (*as_method)(JSONVal ue*, 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 char* name, bool* valueFound, JS ONArray* protocolErrors); 259 static int getInt(JSONObject* object, const char* name, bool* valueFound, JS ONArray* protocolErrors);
264 static double getDouble(JSONObject* object, const char* name, bool* valueFou nd, JSONArray* protocolErrors); 260 static double getDouble(JSONObject* object, const char* name, bool* valueFou nd, JSONArray* protocolErrors);
265 static String getString(JSONObject* object, const char* name, bool* valueFou nd, JSONArray* protocolErrors); 261 static String getString(JSONObject* object, const char* name, bool* valueFou nd, JSONArray* protocolErrors);
266 static bool getBoolean(JSONObject* object, const char* name, bool* valueFoun d, JSONArray* protocolErrors); 262 static bool getBoolean(JSONObject* object, const char* name, bool* valueFoun d, JSONArray* protocolErrors);
267 static PassRefPtr<JSONObject> getObject(JSONObject* object, const char* name , 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 char* 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
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();
360 responseMessage->setNumber("id", callId); 356 responseMessage->setNumber("id", callId);
361 responseMessage->setObject("result", result); 357 responseMessage->setObject("result", result);
362 if (m_inspectorFrontendChannel) 358 if (m_inspectorFrontendChannel)
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 890
895 #endif // $validatorIfdefName 891 #endif // $validatorIfdefName
896 892
897 } // namespace WebCore 893 } // namespace WebCore
898 894
899 """) 895 """)
900 896
901 param_container_access_code = """ 897 param_container_access_code = """
902 RefPtr<JSONObject> paramsContainer = requestMessageObject->getObject("params "); 898 RefPtr<JSONObject> paramsContainer = requestMessageObject->getObject("params ");
903 JSONObject* paramsContainerPtr = paramsContainer.get(); 899 JSONObject* paramsContainerPtr = paramsContainer.get();
904 JSONArray* protocolErrorsPtr = protocolErrors.get();
905 """ 900 """
906 901
907 class_binding_builder_part_1 = ( 902 class_binding_builder_part_1 = (
908 """ AllFieldsSet = %s 903 """ AllFieldsSet = %s
909 }; 904 };
910 905
911 template<int STATE> 906 template<int STATE>
912 class Builder { 907 class Builder {
913 private: 908 private:
914 RefPtr<JSONObject> m_result; 909 RefPtr<JSONObject> m_result;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 }; 946 };
952 947
953 """) 948 """)
954 949
955 class_binding_builder_part_4 = ( 950 class_binding_builder_part_4 = (
956 """ static Builder<NoFieldsSet> create() 951 """ static Builder<NoFieldsSet> create()
957 { 952 {
958 return Builder<NoFieldsSet>(JSONObject::create()); 953 return Builder<NoFieldsSet>(JSONObject::create());
959 } 954 }
960 """) 955 """)
OLDNEW
« no previous file with comments | « Source/core/inspector/CodeGeneratorInspector.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698