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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 $methodOutCode | 53 $methodOutCode |
54 $methodInCode | 54 $methodInCode |
55 RefPtr<JSONObject> result = JSONObject::create(); | 55 RefPtr<JSONObject> result = JSONObject::create(); |
56 RefPtr<JSONValue> resultErrorData; | 56 RefPtr<JSONValue> resultErrorData; |
57 ErrorString error; | 57 ErrorString error; |
58 if (!protocolErrors->length()) { | 58 if (!protocolErrors->length()) { |
59 $agentField->$methodName(&error$agentCallParams); | 59 $agentField->$methodName(&error$agentCallParams); |
60 | 60 |
61 $errorCook${responseCook} | 61 $errorCook${responseCook} |
62 } | 62 } |
63 sendResponse(callId, result, commandNames[$commandNameIndex], protocolErrors
, error, resultErrorData); | 63 sendResponse(callId, result, commandName($commandNameIndex), protocolErrors,
error, resultErrorData); |
64 } | 64 } |
65 """) | 65 """) |
66 | 66 |
67 frontend_method = ("""void InspectorFrontend::$domainName::$eventName($parameter
s) | 67 frontend_method = ("""void InspectorFrontend::$domainName::$eventName($parameter
s) |
68 { | 68 { |
69 RefPtr<JSONObject> jsonMessage = JSONObject::create(); | 69 RefPtr<JSONObject> jsonMessage = JSONObject::create(); |
70 jsonMessage->setString("method", "$domainName.$eventName"); | 70 jsonMessage->setString("method", "$domainName.$eventName"); |
71 $code if (m_inspectorFrontendChannel) | 71 $code if (m_inspectorFrontendChannel) |
72 m_inspectorFrontendChannel->sendMessageToFrontend(jsonMessage->toJSONStr
ing()); | 72 m_inspectorFrontendChannel->sendMessageToFrontend(jsonMessage->toJSONStr
ing()); |
73 } | 73 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 virtual void reportProtocolError(const long* const callId, CommonErrorCode,
const String& errorMessage, PassRefPtr<JSONValue> data) const = 0; | 189 virtual void reportProtocolError(const long* const callId, CommonErrorCode,
const String& errorMessage, PassRefPtr<JSONValue> data) const = 0; |
190 virtual void dispatch(const String& message) = 0; | 190 virtual void dispatch(const String& message) = 0; |
191 static bool getCommandName(const String& message, String* result); | 191 static bool getCommandName(const String& message, String* result); |
192 | 192 |
193 enum MethodNames { | 193 enum MethodNames { |
194 $methodNamesEnumContent | 194 $methodNamesEnumContent |
195 | 195 |
196 kMethodNamesEnumSize | 196 kMethodNamesEnumSize |
197 }; | 197 }; |
198 | 198 |
199 static const char* commandNames[]; | 199 static const char* commandName(MethodNames); |
| 200 |
| 201 private: |
| 202 static const char commandNames[]; |
| 203 static const size_t commandNamesIndex[]; |
200 }; | 204 }; |
201 | 205 |
202 } // namespace WebCore | 206 } // namespace WebCore |
203 #endif // !defined(InspectorBackendDispatcher_h) | 207 #endif // !defined(InspectorBackendDispatcher_h) |
204 | 208 |
205 | 209 |
206 """) | 210 """) |
207 | 211 |
208 backend_cpp = ( | 212 backend_cpp = ( |
209 """ | 213 """ |
210 | 214 |
211 #include "config.h" | 215 #include "config.h" |
212 #include "InspectorBackendDispatcher.h" | 216 #include "InspectorBackendDispatcher.h" |
213 | 217 |
214 #include "core/inspector/InspectorAgent.h" | 218 #include "core/inspector/InspectorAgent.h" |
215 #include "core/inspector/InspectorFrontendChannel.h" | 219 #include "core/inspector/InspectorFrontendChannel.h" |
216 #include "core/inspector/JSONParser.h" | 220 #include "core/inspector/JSONParser.h" |
217 #include "platform/JSONValues.h" | 221 #include "platform/JSONValues.h" |
218 #include "wtf/text/CString.h" | 222 #include "wtf/text/CString.h" |
219 #include "wtf/text/WTFString.h" | 223 #include "wtf/text/WTFString.h" |
220 | 224 |
221 namespace WebCore { | 225 namespace WebCore { |
222 | 226 |
223 const char* InspectorBackendDispatcher::commandNames[] = { | 227 const char InspectorBackendDispatcher::commandNames[] = { |
224 $methodNameDeclarations | 228 $methodNameDeclarations |
225 }; | 229 }; |
226 | 230 |
| 231 const size_t InspectorBackendDispatcher::commandNamesIndex[] = { |
| 232 $methodNameDeclarationsIndex |
| 233 }; |
| 234 |
| 235 const char* InspectorBackendDispatcher::commandName(MethodNames index) { |
| 236 COMPILE_ASSERT(static_cast<int>(kMethodNamesEnumSize) == WTF_ARRAY_LENGTH(co
mmandNamesIndex), command_name_array_problem); |
| 237 return commandNames + commandNamesIndex[index]; |
| 238 } |
227 | 239 |
228 class InspectorBackendDispatcherImpl : public InspectorBackendDispatcher { | 240 class InspectorBackendDispatcherImpl : public InspectorBackendDispatcher { |
229 public: | 241 public: |
230 InspectorBackendDispatcherImpl(InspectorFrontendChannel* inspectorFrontendCh
annel) | 242 InspectorBackendDispatcherImpl(InspectorFrontendChannel* inspectorFrontendCh
annel) |
231 : m_inspectorFrontendChannel(inspectorFrontendChannel) | 243 : m_inspectorFrontendChannel(inspectorFrontendChannel) |
232 $constructorInit | 244 $constructorInit |
233 { } | 245 { } |
234 | 246 |
235 virtual void clearFrontend() { m_inspectorFrontendChannel = 0; } | 247 virtual void clearFrontend() { m_inspectorFrontendChannel = 0; } |
236 virtual void dispatch(const String& message); | 248 virtual void dispatch(const String& message); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 RefPtr<InspectorBackendDispatcher> protect = this; | 286 RefPtr<InspectorBackendDispatcher> protect = this; |
275 typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, JSO
NObject* messageObject); | 287 typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, JSO
NObject* messageObject); |
276 typedef HashMap<String, CallHandler> DispatchMap; | 288 typedef HashMap<String, CallHandler> DispatchMap; |
277 DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, ); | 289 DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, ); |
278 long callId = 0; | 290 long callId = 0; |
279 | 291 |
280 if (dispatchMap.isEmpty()) { | 292 if (dispatchMap.isEmpty()) { |
281 static CallHandler handlers[] = { | 293 static CallHandler handlers[] = { |
282 $messageHandlers | 294 $messageHandlers |
283 }; | 295 }; |
284 size_t length = WTF_ARRAY_LENGTH(commandNames); | 296 for (size_t i = 0; i < kMethodNamesEnumSize; ++i) |
285 for (size_t i = 0; i < length; ++i) | 297 dispatchMap.add(commandName(static_cast<MethodNames>(i)), handlers[i
]); |
286 dispatchMap.add(commandNames[i], handlers[i]); | |
287 } | 298 } |
288 | 299 |
289 RefPtr<JSONValue> parsedMessage = parseJSON(message); | 300 RefPtr<JSONValue> parsedMessage = parseJSON(message); |
290 if (!parsedMessage) { | 301 if (!parsedMessage) { |
291 reportProtocolError(0, ParseError, "Message must be in JSON format"); | 302 reportProtocolError(0, ParseError, "Message must be in JSON format"); |
292 return; | 303 return; |
293 } | 304 } |
294 | 305 |
295 RefPtr<JSONObject> messageObject = parsedMessage->asObject(); | 306 RefPtr<JSONObject> messageObject = parsedMessage->asObject(); |
296 if (!messageObject) { | 307 if (!messageObject) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 } | 507 } |
497 | 508 |
498 void InspectorBackendDispatcher::CallbackBase::sendIfActive(PassRefPtr<JSONObjec
t> partialMessage, const ErrorString& invocationError, PassRefPtr<JSONValue> err
orData) | 509 void InspectorBackendDispatcher::CallbackBase::sendIfActive(PassRefPtr<JSONObjec
t> partialMessage, const ErrorString& invocationError, PassRefPtr<JSONValue> err
orData) |
499 { | 510 { |
500 if (m_alreadySent) | 511 if (m_alreadySent) |
501 return; | 512 return; |
502 m_backendImpl->sendResponse(m_id, partialMessage, invocationError, errorData
); | 513 m_backendImpl->sendResponse(m_id, partialMessage, invocationError, errorData
); |
503 m_alreadySent = true; | 514 m_alreadySent = true; |
504 } | 515 } |
505 | 516 |
506 COMPILE_ASSERT(static_cast<int>(InspectorBackendDispatcher::kMethodNamesEnumSize
) == WTF_ARRAY_LENGTH(InspectorBackendDispatcher::commandNames), command_name_ar
ray_problem); | |
507 | |
508 } // namespace WebCore | 517 } // namespace WebCore |
509 | 518 |
510 """) | 519 """) |
511 | 520 |
512 frontend_cpp = ( | 521 frontend_cpp = ( |
513 """ | 522 """ |
514 | 523 |
515 #include "config.h" | 524 #include "config.h" |
516 #include "InspectorFrontend.h" | 525 #include "InspectorFrontend.h" |
517 | 526 |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 }; | 940 }; |
932 | 941 |
933 """) | 942 """) |
934 | 943 |
935 class_binding_builder_part_4 = ( | 944 class_binding_builder_part_4 = ( |
936 """ static Builder<NoFieldsSet> create() | 945 """ static Builder<NoFieldsSet> create() |
937 { | 946 { |
938 return Builder<NoFieldsSet>(JSONObject::create()); | 947 return Builder<NoFieldsSet>(JSONObject::create()); |
939 } | 948 } |
940 """) | 949 """) |
OLD | NEW |