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 26 matching lines...) Expand all Loading... |
37 InspectorFrontendChannel* getInspectorFrontendChannel() { return m_inspe
ctorFrontendChannel; } | 37 InspectorFrontendChannel* getInspectorFrontendChannel() { return m_inspe
ctorFrontendChannel; } |
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, I
nspectorObject*$requestMessageObject) | 47 """void InspectorBackendDispatcherImpl::${domainName}_$methodName(long callId, J
SONObject*$requestMessageObject) |
48 { | 48 { |
49 RefPtr<InspectorArray> protocolErrors = InspectorArray::create(); | 49 RefPtr<JSONArray> protocolErrors = JSONArray::create(); |
50 | 50 |
51 if (!$agentField) | 51 if (!$agentField) |
52 protocolErrors->pushString("${domainName} handler is not available."); | 52 protocolErrors->pushString("${domainName} handler is not available."); |
53 $methodOutCode | 53 $methodOutCode |
54 $methodInCode | 54 $methodInCode |
55 RefPtr<InspectorObject> result = InspectorObject::create(); | 55 RefPtr<JSONObject> result = JSONObject::create(); |
| 56 RefPtr<JSONValue> resultErrorData; |
56 ErrorString error; | 57 ErrorString error; |
57 if (!protocolErrors->length()) { | 58 if (!protocolErrors->length()) { |
58 $agentField->$methodName(&error$agentCallParams); | 59 $agentField->$methodName(&error$agentCallParams); |
59 | 60 |
60 ${responseCook} | 61 $errorCook${responseCook} |
61 } | 62 } |
62 sendResponse(callId, result, commandNames[$commandNameIndex], protocolErrors
, error); | 63 sendResponse(callId, result, commandNames[$commandNameIndex], protocolErrors
, error, resultErrorData); |
63 } | 64 } |
64 """) | 65 """) |
65 | 66 |
66 frontend_method = ("""void InspectorFrontend::$domainName::$eventName($parameter
s) | 67 frontend_method = ("""void InspectorFrontend::$domainName::$eventName($parameter
s) |
67 { | 68 { |
68 RefPtr<InspectorObject> jsonMessage = InspectorObject::create(); | 69 RefPtr<JSONObject> jsonMessage = JSONObject::create(); |
69 jsonMessage->setString("method", "$domainName.$eventName"); | 70 jsonMessage->setString("method", "$domainName.$eventName"); |
70 $code if (m_inspectorFrontendChannel) | 71 $code if (m_inspectorFrontendChannel) |
71 m_inspectorFrontendChannel->sendMessageToFrontend(jsonMessage->toJSONStr
ing()); | 72 m_inspectorFrontendChannel->sendMessageToFrontend(jsonMessage->toJSONStr
ing()); |
72 } | 73 } |
73 """) | 74 """) |
74 | 75 |
75 callback_method = ( | 76 callback_main_methods = ( |
76 """InspectorBackendDispatcher::$agentName::$callbackName::$callbackName(PassRefP
tr<InspectorBackendDispatcherImpl> backendImpl, int id) : CallbackBase(backendIm
pl, id) {} | 77 """InspectorBackendDispatcher::$agentName::$callbackName::$callbackName(PassRefP
tr<InspectorBackendDispatcherImpl> backendImpl, int id) : CallbackBase(backendIm
pl, id) {} |
77 | 78 |
78 void InspectorBackendDispatcher::$agentName::$callbackName::sendSuccess($paramet
ers) | 79 void InspectorBackendDispatcher::$agentName::$callbackName::sendSuccess($paramet
ers) |
79 { | 80 { |
80 RefPtr<InspectorObject> jsonMessage = InspectorObject::create(); | 81 RefPtr<JSONObject> jsonMessage = JSONObject::create(); |
81 $code sendIfActive(jsonMessage, ErrorString()); | 82 $code sendIfActive(jsonMessage, ErrorString(), PassRefPtr<JSONValue>()); |
82 } | 83 } |
83 """) | 84 """) |
84 | 85 |
| 86 callback_failure_method = ( |
| 87 """void InspectorBackendDispatcher::$agentName::$callbackName::sendFailure(const
ErrorString& error, $parameter) |
| 88 { |
| 89 ASSERT(error.length()); |
| 90 RefPtr<JSONValue> errorDataValue; |
| 91 if (error) { |
| 92 errorDataValue = $argument; |
| 93 } |
| 94 sendIfActive(0, error, errorDataValue.release()); |
| 95 } |
| 96 """) |
| 97 |
| 98 |
85 frontend_h = ( | 99 frontend_h = ( |
86 """#ifndef InspectorFrontend_h | 100 """#ifndef InspectorFrontend_h |
87 #define InspectorFrontend_h | 101 #define InspectorFrontend_h |
88 | 102 |
89 #include "InspectorTypeBuilder.h" | 103 #include "InspectorTypeBuilder.h" |
90 #include "core/inspector/InspectorValues.h" | 104 #include "core/platform/JSONValues.h" |
91 #include <wtf/PassRefPtr.h> | 105 #include "wtf/PassRefPtr.h" |
92 #include <wtf/text/WTFString.h> | 106 #include "wtf/text/WTFString.h" |
93 | 107 |
94 namespace WebCore { | 108 namespace WebCore { |
95 | 109 |
96 class InspectorFrontendChannel; | 110 class InspectorFrontendChannel; |
97 | 111 |
98 typedef String ErrorString; | 112 typedef String ErrorString; |
99 | 113 |
100 class InspectorFrontend { | 114 class InspectorFrontend { |
101 public: | 115 public: |
102 InspectorFrontend(InspectorFrontendChannel*); | 116 InspectorFrontend(InspectorFrontendChannel*); |
(...skipping 13 matching lines...) Expand all Loading... |
116 | 130 |
117 #include "InspectorTypeBuilder.h" | 131 #include "InspectorTypeBuilder.h" |
118 | 132 |
119 #include <wtf/PassRefPtr.h> | 133 #include <wtf/PassRefPtr.h> |
120 #include <wtf/RefCounted.h> | 134 #include <wtf/RefCounted.h> |
121 #include <wtf/text/WTFString.h> | 135 #include <wtf/text/WTFString.h> |
122 | 136 |
123 namespace WebCore { | 137 namespace WebCore { |
124 | 138 |
125 class InspectorAgent; | 139 class InspectorAgent; |
126 class InspectorObject; | 140 class JSONObject; |
127 class InspectorArray; | 141 class JSONArray; |
128 class InspectorFrontendChannel; | 142 class InspectorFrontendChannel; |
129 | 143 |
130 typedef String ErrorString; | 144 typedef String ErrorString; |
131 | 145 |
132 class InspectorBackendDispatcherImpl; | 146 class InspectorBackendDispatcherImpl; |
133 | 147 |
134 class InspectorBackendDispatcher: public RefCounted<InspectorBackendDispatcher>
{ | 148 class InspectorBackendDispatcher: public RefCounted<InspectorBackendDispatcher>
{ |
135 public: | 149 public: |
136 static PassRefPtr<InspectorBackendDispatcher> create(InspectorFrontendChanne
l* inspectorFrontendChannel); | 150 static PassRefPtr<InspectorBackendDispatcher> create(InspectorFrontendChanne
l* inspectorFrontendChannel); |
137 virtual ~InspectorBackendDispatcher() { } | 151 virtual ~InspectorBackendDispatcher() { } |
138 | 152 |
139 class CallbackBase: public RefCounted<CallbackBase> { | 153 class CallbackBase: public RefCounted<CallbackBase> { |
140 public: | 154 public: |
141 CallbackBase(PassRefPtr<InspectorBackendDispatcherImpl> backendImpl, int
id); | 155 CallbackBase(PassRefPtr<InspectorBackendDispatcherImpl> backendImpl, int
id); |
142 virtual ~CallbackBase(); | 156 virtual ~CallbackBase(); |
143 void sendFailure(const ErrorString&); | 157 void sendFailure(const ErrorString&); |
144 bool isActive(); | 158 bool isActive(); |
145 | 159 |
146 protected: | 160 protected: |
147 void sendIfActive(PassRefPtr<InspectorObject> partialMessage, const Erro
rString& invocationError); | 161 void sendIfActive(PassRefPtr<JSONObject> partialMessage, const ErrorStri
ng& invocationError, PassRefPtr<JSONValue> errorData); |
148 | 162 |
149 private: | 163 private: |
150 void disable() { m_alreadySent = true; } | 164 void disable() { m_alreadySent = true; } |
151 | 165 |
152 RefPtr<InspectorBackendDispatcherImpl> m_backendImpl; | 166 RefPtr<InspectorBackendDispatcherImpl> m_backendImpl; |
153 int m_id; | 167 int m_id; |
154 bool m_alreadySent; | 168 bool m_alreadySent; |
155 | 169 |
156 friend class InspectorBackendDispatcherImpl; | 170 friend class InspectorBackendDispatcherImpl; |
157 }; | 171 }; |
158 | 172 |
159 $agentInterfaces | 173 $agentInterfaces |
160 $virtualSetters | 174 $virtualSetters |
161 | 175 |
162 virtual void clearFrontend() = 0; | 176 virtual void clearFrontend() = 0; |
163 | 177 |
164 enum CommonErrorCode { | 178 enum CommonErrorCode { |
165 ParseError = 0, | 179 ParseError = 0, |
166 InvalidRequest, | 180 InvalidRequest, |
167 MethodNotFound, | 181 MethodNotFound, |
168 InvalidParams, | 182 InvalidParams, |
169 InternalError, | 183 InternalError, |
170 ServerError, | 184 ServerError, |
171 LastEntry, | 185 LastEntry, |
172 }; | 186 }; |
173 | 187 |
174 void reportProtocolError(const long* const callId, CommonErrorCode, const St
ring& errorMessage) const; | 188 void reportProtocolError(const long* const callId, CommonErrorCode, const St
ring& errorMessage) const; |
175 virtual void reportProtocolError(const long* const callId, CommonErrorCode,
const String& errorMessage, PassRefPtr<InspectorArray> data) const = 0; | 189 virtual void reportProtocolError(const long* const callId, CommonErrorCode,
const String& errorMessage, PassRefPtr<JSONValue> data) const = 0; |
176 virtual void dispatch(const String& message) = 0; | 190 virtual void dispatch(const String& message) = 0; |
177 static bool getCommandName(const String& message, String* result); | 191 static bool getCommandName(const String& message, String* result); |
178 | 192 |
179 enum MethodNames { | 193 enum MethodNames { |
180 $methodNamesEnumContent | 194 $methodNamesEnumContent |
181 | 195 |
182 kMethodNamesEnumSize | 196 kMethodNamesEnumSize |
183 }; | 197 }; |
184 | 198 |
185 static const char* commandNames[]; | 199 static const char* commandNames[]; |
186 }; | 200 }; |
187 | 201 |
188 } // namespace WebCore | 202 } // namespace WebCore |
189 #endif // !defined(InspectorBackendDispatcher_h) | 203 #endif // !defined(InspectorBackendDispatcher_h) |
190 | 204 |
191 | 205 |
192 """) | 206 """) |
193 | 207 |
194 backend_cpp = ( | 208 backend_cpp = ( |
195 """ | 209 """ |
196 | 210 |
197 #include "config.h" | 211 #include "config.h" |
198 #include "InspectorBackendDispatcher.h" | 212 #include "InspectorBackendDispatcher.h" |
199 | 213 |
200 | |
201 #include "core/inspector/InspectorAgent.h" | 214 #include "core/inspector/InspectorAgent.h" |
202 #include "core/inspector/InspectorFrontendChannel.h" | 215 #include "core/inspector/InspectorFrontendChannel.h" |
203 #include "core/inspector/InspectorValues.h" | 216 #include "core/inspector/JSONParser.h" |
204 #include <wtf/text/CString.h> | 217 #include "core/platform/JSONValues.h" |
205 #include <wtf/text/WTFString.h> | 218 #include "wtf/text/CString.h" |
| 219 #include "wtf/text/WTFString.h" |
206 | 220 |
207 namespace WebCore { | 221 namespace WebCore { |
208 | 222 |
209 const char* InspectorBackendDispatcher::commandNames[] = { | 223 const char* InspectorBackendDispatcher::commandNames[] = { |
210 $methodNameDeclarations | 224 $methodNameDeclarations |
211 }; | 225 }; |
212 | 226 |
213 | 227 |
214 class InspectorBackendDispatcherImpl : public InspectorBackendDispatcher { | 228 class InspectorBackendDispatcherImpl : public InspectorBackendDispatcher { |
215 public: | 229 public: |
216 InspectorBackendDispatcherImpl(InspectorFrontendChannel* inspectorFrontendCh
annel) | 230 InspectorBackendDispatcherImpl(InspectorFrontendChannel* inspectorFrontendCh
annel) |
217 : m_inspectorFrontendChannel(inspectorFrontendChannel) | 231 : m_inspectorFrontendChannel(inspectorFrontendChannel) |
218 $constructorInit | 232 $constructorInit |
219 { } | 233 { } |
220 | 234 |
221 virtual void clearFrontend() { m_inspectorFrontendChannel = 0; } | 235 virtual void clearFrontend() { m_inspectorFrontendChannel = 0; } |
222 virtual void dispatch(const String& message); | 236 virtual void dispatch(const String& message); |
223 virtual void reportProtocolError(const long* const callId, CommonErrorCode,
const String& errorMessage, PassRefPtr<InspectorArray> data) const; | 237 virtual void reportProtocolError(const long* const callId, CommonErrorCode,
const String& errorMessage, PassRefPtr<JSONValue> data) const; |
224 using InspectorBackendDispatcher::reportProtocolError; | 238 using InspectorBackendDispatcher::reportProtocolError; |
225 | 239 |
226 void sendResponse(long callId, PassRefPtr<InspectorObject> result, const Err
orString& invocationError); | 240 void sendResponse(long callId, PassRefPtr<JSONObject> result, const ErrorStr
ing&invocationError, PassRefPtr<JSONValue> errorData); |
227 bool isActive() { return m_inspectorFrontendChannel; } | 241 bool isActive() { return m_inspectorFrontendChannel; } |
228 | 242 |
229 $setters | 243 $setters |
230 private: | 244 private: |
231 $methodDeclarations | 245 $methodDeclarations |
232 | 246 |
233 InspectorFrontendChannel* m_inspectorFrontendChannel; | 247 InspectorFrontendChannel* m_inspectorFrontendChannel; |
234 $fieldDeclarations | 248 $fieldDeclarations |
235 | 249 |
236 template<typename R, typename V, typename V0> | 250 template<typename R, typename V, typename V0> |
237 static R getPropertyValueImpl(InspectorObject* object, const String& name, b
ool* valueFound, InspectorArray* protocolErrors, V0 initial_value, bool (*as_met
hod)(InspectorValue*, V*), const char* type_name); | 251 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); |
238 | 252 |
239 static int getInt(InspectorObject* object, const String& name, bool* valueFo
und, InspectorArray* protocolErrors); | 253 static int getInt(JSONObject* object, const String& name, bool* valueFound,
JSONArray* protocolErrors); |
240 static double getDouble(InspectorObject* object, const String& name, bool* v
alueFound, InspectorArray* protocolErrors); | 254 static double getDouble(JSONObject* object, const String& name, bool* valueF
ound, JSONArray* protocolErrors); |
241 static String getString(InspectorObject* object, const String& name, bool* v
alueFound, InspectorArray* protocolErrors); | 255 static String getString(JSONObject* object, const String& name, bool* valueF
ound, JSONArray* protocolErrors); |
242 static bool getBoolean(InspectorObject* object, const String& name, bool* va
lueFound, InspectorArray* protocolErrors); | 256 static bool getBoolean(JSONObject* object, const String& name, bool* valueFo
und, JSONArray* protocolErrors); |
243 static PassRefPtr<InspectorObject> getObject(InspectorObject* object, const
String& name, bool* valueFound, InspectorArray* protocolErrors); | 257 static PassRefPtr<JSONObject> getObject(JSONObject* object, const String& na
me, bool* valueFound, JSONArray* protocolErrors); |
244 static PassRefPtr<InspectorArray> getArray(InspectorObject* object, const St
ring& name, bool* valueFound, InspectorArray* protocolErrors); | 258 static PassRefPtr<JSONArray> getArray(JSONObject* object, const String& name
, bool* valueFound, JSONArray* protocolErrors); |
245 | 259 |
246 void sendResponse(long callId, PassRefPtr<InspectorObject> result, const cha
r* commandName, PassRefPtr<InspectorArray> protocolErrors, ErrorString invocatio
nError); | 260 void sendResponse(long callId, PassRefPtr<JSONObject> result, const char* co
mmandName, PassRefPtr<JSONArray> protocolErrors, ErrorString invocationError, Pa
ssRefPtr<JSONValue> errorData); |
247 | 261 |
248 }; | 262 }; |
249 | 263 |
250 $methods | 264 $methods |
251 | 265 |
252 PassRefPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::create(Inspec
torFrontendChannel* inspectorFrontendChannel) | 266 PassRefPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::create(Inspec
torFrontendChannel* inspectorFrontendChannel) |
253 { | 267 { |
254 return adoptRef(new InspectorBackendDispatcherImpl(inspectorFrontendChannel)
); | 268 return adoptRef(new InspectorBackendDispatcherImpl(inspectorFrontendChannel)
); |
255 } | 269 } |
256 | 270 |
257 | 271 |
258 void InspectorBackendDispatcherImpl::dispatch(const String& message) | 272 void InspectorBackendDispatcherImpl::dispatch(const String& message) |
259 { | 273 { |
260 RefPtr<InspectorBackendDispatcher> protect = this; | 274 RefPtr<InspectorBackendDispatcher> protect = this; |
261 typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, Ins
pectorObject* messageObject); | 275 typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, JSO
NObject* messageObject); |
262 typedef HashMap<String, CallHandler> DispatchMap; | 276 typedef HashMap<String, CallHandler> DispatchMap; |
263 DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, ); | 277 DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, ); |
264 long callId = 0; | 278 long callId = 0; |
265 | 279 |
266 if (dispatchMap.isEmpty()) { | 280 if (dispatchMap.isEmpty()) { |
267 static CallHandler handlers[] = { | 281 static CallHandler handlers[] = { |
268 $messageHandlers | 282 $messageHandlers |
269 }; | 283 }; |
270 size_t length = WTF_ARRAY_LENGTH(commandNames); | 284 size_t length = WTF_ARRAY_LENGTH(commandNames); |
271 for (size_t i = 0; i < length; ++i) | 285 for (size_t i = 0; i < length; ++i) |
272 dispatchMap.add(commandNames[i], handlers[i]); | 286 dispatchMap.add(commandNames[i], handlers[i]); |
273 } | 287 } |
274 | 288 |
275 RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message); | 289 RefPtr<JSONValue> parsedMessage = parseJSON(message); |
276 if (!parsedMessage) { | 290 if (!parsedMessage) { |
277 reportProtocolError(0, ParseError, "Message must be in JSON format"); | 291 reportProtocolError(0, ParseError, "Message must be in JSON format"); |
278 return; | 292 return; |
279 } | 293 } |
280 | 294 |
281 RefPtr<InspectorObject> messageObject = parsedMessage->asObject(); | 295 RefPtr<JSONObject> messageObject = parsedMessage->asObject(); |
282 if (!messageObject) { | 296 if (!messageObject) { |
283 reportProtocolError(0, InvalidRequest, "Message must be a JSONified obje
ct"); | 297 reportProtocolError(0, InvalidRequest, "Message must be a JSONified obje
ct"); |
284 return; | 298 return; |
285 } | 299 } |
286 | 300 |
287 RefPtr<InspectorValue> callIdValue = messageObject->get("id"); | 301 RefPtr<JSONValue> callIdValue = messageObject->get("id"); |
288 if (!callIdValue) { | 302 if (!callIdValue) { |
289 reportProtocolError(0, InvalidRequest, "'id' property was not found"); | 303 reportProtocolError(0, InvalidRequest, "'id' property was not found"); |
290 return; | 304 return; |
291 } | 305 } |
292 | 306 |
293 if (!callIdValue->asNumber(&callId)) { | 307 if (!callIdValue->asNumber(&callId)) { |
294 reportProtocolError(0, InvalidRequest, "The type of 'id' property must b
e number"); | 308 reportProtocolError(0, InvalidRequest, "The type of 'id' property must b
e number"); |
295 return; | 309 return; |
296 } | 310 } |
297 | 311 |
298 RefPtr<InspectorValue> methodValue = messageObject->get("method"); | 312 RefPtr<JSONValue> methodValue = messageObject->get("method"); |
299 if (!methodValue) { | 313 if (!methodValue) { |
300 reportProtocolError(&callId, InvalidRequest, "'method' property wasn't f
ound"); | 314 reportProtocolError(&callId, InvalidRequest, "'method' property wasn't f
ound"); |
301 return; | 315 return; |
302 } | 316 } |
303 | 317 |
304 String method; | 318 String method; |
305 if (!methodValue->asString(&method)) { | 319 if (!methodValue->asString(&method)) { |
306 reportProtocolError(&callId, InvalidRequest, "The type of 'method' prope
rty must be string"); | 320 reportProtocolError(&callId, InvalidRequest, "The type of 'method' prope
rty must be string"); |
307 return; | 321 return; |
308 } | 322 } |
309 | 323 |
310 HashMap<String, CallHandler>::iterator it = dispatchMap.find(method); | 324 HashMap<String, CallHandler>::iterator it = dispatchMap.find(method); |
311 if (it == dispatchMap.end()) { | 325 if (it == dispatchMap.end()) { |
312 reportProtocolError(&callId, MethodNotFound, "'" + method + "' wasn't fo
und"); | 326 reportProtocolError(&callId, MethodNotFound, "'" + method + "' wasn't fo
und"); |
313 return; | 327 return; |
314 } | 328 } |
315 | 329 |
316 ((*this).*it->value)(callId, messageObject.get()); | 330 ((*this).*it->value)(callId, messageObject.get()); |
317 } | 331 } |
318 | 332 |
319 void InspectorBackendDispatcherImpl::sendResponse(long callId, PassRefPtr<Inspec
torObject> result, const char* commandName, PassRefPtr<InspectorArray> protocolE
rrors, ErrorString invocationError) | 333 void InspectorBackendDispatcherImpl::sendResponse(long callId, PassRefPtr<JSONOb
ject> result, const char* commandName, PassRefPtr<JSONArray> protocolErrors, Err
orString invocationError, PassRefPtr<JSONValue> errorData) |
320 { | 334 { |
321 if (protocolErrors->length()) { | 335 if (protocolErrors->length()) { |
322 String errorMessage = String::format("Some arguments of method '%s' can'
t be processed", commandName); | 336 String errorMessage = String::format("Some arguments of method '%s' can'
t be processed", commandName); |
323 reportProtocolError(&callId, InvalidParams, errorMessage, protocolErrors
); | 337 reportProtocolError(&callId, InvalidParams, errorMessage, protocolErrors
); |
324 return; | 338 return; |
325 } | 339 } |
326 sendResponse(callId, result, invocationError); | 340 sendResponse(callId, result, invocationError, errorData); |
327 } | 341 } |
328 | 342 |
329 void InspectorBackendDispatcherImpl::sendResponse(long callId, PassRefPtr<Inspec
torObject> result, const ErrorString& invocationError) | 343 void InspectorBackendDispatcherImpl::sendResponse(long callId, PassRefPtr<JSONOb
ject> result, const ErrorString& invocationError, PassRefPtr<JSONValue> errorDat
a) |
330 { | 344 { |
331 if (invocationError.length()) { | 345 if (invocationError.length()) { |
332 reportProtocolError(&callId, ServerError, invocationError); | 346 reportProtocolError(&callId, ServerError, invocationError, errorData); |
333 return; | 347 return; |
334 } | 348 } |
335 | 349 |
336 RefPtr<InspectorObject> responseMessage = InspectorObject::create(); | 350 RefPtr<JSONObject> responseMessage = JSONObject::create(); |
337 responseMessage->setObject("result", result); | 351 responseMessage->setObject("result", result); |
338 responseMessage->setNumber("id", callId); | 352 responseMessage->setNumber("id", callId); |
339 if (m_inspectorFrontendChannel) | 353 if (m_inspectorFrontendChannel) |
340 m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage->toJSO
NString()); | 354 m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage->toJSO
NString()); |
341 } | 355 } |
342 | 356 |
343 void InspectorBackendDispatcher::reportProtocolError(const long* const callId, C
ommonErrorCode code, const String& errorMessage) const | 357 void InspectorBackendDispatcher::reportProtocolError(const long* const callId, C
ommonErrorCode code, const String& errorMessage) const |
344 { | 358 { |
345 reportProtocolError(callId, code, errorMessage, 0); | 359 reportProtocolError(callId, code, errorMessage, PassRefPtr<JSONValue>()); |
346 } | 360 } |
347 | 361 |
348 void InspectorBackendDispatcherImpl::reportProtocolError(const long* const callI
d, CommonErrorCode code, const String& errorMessage, PassRefPtr<InspectorArray>
data) const | 362 void InspectorBackendDispatcherImpl::reportProtocolError(const long* const callI
d, CommonErrorCode code, const String& errorMessage, PassRefPtr<JSONValue> data)
const |
349 { | 363 { |
350 DEFINE_STATIC_LOCAL(Vector<int>,s_commonErrors,); | 364 DEFINE_STATIC_LOCAL(Vector<int>,s_commonErrors,); |
351 if (!s_commonErrors.size()) { | 365 if (!s_commonErrors.size()) { |
352 s_commonErrors.insert(ParseError, -32700); | 366 s_commonErrors.insert(ParseError, -32700); |
353 s_commonErrors.insert(InvalidRequest, -32600); | 367 s_commonErrors.insert(InvalidRequest, -32600); |
354 s_commonErrors.insert(MethodNotFound, -32601); | 368 s_commonErrors.insert(MethodNotFound, -32601); |
355 s_commonErrors.insert(InvalidParams, -32602); | 369 s_commonErrors.insert(InvalidParams, -32602); |
356 s_commonErrors.insert(InternalError, -32603); | 370 s_commonErrors.insert(InternalError, -32603); |
357 s_commonErrors.insert(ServerError, -32000); | 371 s_commonErrors.insert(ServerError, -32000); |
358 } | 372 } |
359 ASSERT(code >=0); | 373 ASSERT(code >=0); |
360 ASSERT((unsigned)code < s_commonErrors.size()); | 374 ASSERT((unsigned)code < s_commonErrors.size()); |
361 ASSERT(s_commonErrors[code]); | 375 ASSERT(s_commonErrors[code]); |
362 RefPtr<InspectorObject> error = InspectorObject::create(); | 376 RefPtr<JSONObject> error = JSONObject::create(); |
363 error->setNumber("code", s_commonErrors[code]); | 377 error->setNumber("code", s_commonErrors[code]); |
364 error->setString("message", errorMessage); | 378 error->setString("message", errorMessage); |
365 ASSERT(error); | 379 ASSERT(error); |
366 if (data) | 380 if (data) |
367 error->setArray("data", data); | 381 error->setValue("data", data); |
368 RefPtr<InspectorObject> message = InspectorObject::create(); | 382 RefPtr<JSONObject> message = JSONObject::create(); |
369 message->setObject("error", error); | 383 message->setObject("error", error); |
370 if (callId) | 384 if (callId) |
371 message->setNumber("id", *callId); | 385 message->setNumber("id", *callId); |
372 else | 386 else |
373 message->setValue("id", InspectorValue::null()); | 387 message->setValue("id", JSONValue::null()); |
374 if (m_inspectorFrontendChannel) | 388 if (m_inspectorFrontendChannel) |
375 m_inspectorFrontendChannel->sendMessageToFrontend(message->toJSONString(
)); | 389 m_inspectorFrontendChannel->sendMessageToFrontend(message->toJSONString(
)); |
376 } | 390 } |
377 | 391 |
378 template<typename R, typename V, typename V0> | 392 template<typename R, typename V, typename V0> |
379 R InspectorBackendDispatcherImpl::getPropertyValueImpl(InspectorObject* object,
const String& name, bool* valueFound, InspectorArray* protocolErrors, V0 initial
_value, bool (*as_method)(InspectorValue*, V*), const char* type_name) | 393 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) |
380 { | 394 { |
381 ASSERT(protocolErrors); | 395 ASSERT(protocolErrors); |
382 | 396 |
383 if (valueFound) | 397 if (valueFound) |
384 *valueFound = false; | 398 *valueFound = false; |
385 | 399 |
386 V value = initial_value; | 400 V value = initial_value; |
387 | 401 |
388 if (!object) { | 402 if (!object) { |
389 if (!valueFound) { | 403 if (!valueFound) { |
390 // Required parameter in missing params container. | 404 // Required parameter in missing params container. |
391 protocolErrors->pushString(String::format("'params' object must cont
ain required parameter '%s' with type '%s'.", name.utf8().data(), type_name)); | 405 protocolErrors->pushString(String::format("'params' object must cont
ain required parameter '%s' with type '%s'.", name.utf8().data(), type_name)); |
392 } | 406 } |
393 return value; | 407 return value; |
394 } | 408 } |
395 | 409 |
396 InspectorObject::const_iterator end = object->end(); | 410 JSONObject::const_iterator end = object->end(); |
397 InspectorObject::const_iterator valueIterator = object->find(name); | 411 JSONObject::const_iterator valueIterator = object->find(name); |
398 | 412 |
399 if (valueIterator == end) { | 413 if (valueIterator == end) { |
400 if (!valueFound) | 414 if (!valueFound) |
401 protocolErrors->pushString(String::format("Parameter '%s' with type
'%s' was not found.", name.utf8().data(), type_name)); | 415 protocolErrors->pushString(String::format("Parameter '%s' with type
'%s' was not found.", name.utf8().data(), type_name)); |
402 return value; | 416 return value; |
403 } | 417 } |
404 | 418 |
405 if (!as_method(valueIterator->value.get(), &value)) | 419 if (!as_method(valueIterator->value.get(), &value)) |
406 protocolErrors->pushString(String::format("Parameter '%s' has wrong type
. It must be '%s'.", name.utf8().data(), type_name)); | 420 protocolErrors->pushString(String::format("Parameter '%s' has wrong type
. It must be '%s'.", name.utf8().data(), type_name)); |
407 else | 421 else |
408 if (valueFound) | 422 if (valueFound) |
409 *valueFound = true; | 423 *valueFound = true; |
410 return value; | 424 return value; |
411 } | 425 } |
412 | 426 |
413 struct AsMethodBridges { | 427 struct AsMethodBridges { |
414 static bool asInt(InspectorValue* value, int* output) { return value->asNumb
er(output); } | 428 static bool asInt(JSONValue* value, int* output) { return value->asNumber(ou
tput); } |
415 static bool asDouble(InspectorValue* value, double* output) { return value->
asNumber(output); } | 429 static bool asDouble(JSONValue* value, double* output) { return value->asNum
ber(output); } |
416 static bool asString(InspectorValue* value, String* output) { return value->
asString(output); } | 430 static bool asString(JSONValue* value, String* output) { return value->asStr
ing(output); } |
417 static bool asBoolean(InspectorValue* value, bool* output) { return value->a
sBoolean(output); } | 431 static bool asBoolean(JSONValue* value, bool* output) { return value->asBool
ean(output); } |
418 static bool asObject(InspectorValue* value, RefPtr<InspectorObject>* output)
{ return value->asObject(output); } | 432 static bool asObject(JSONValue* value, RefPtr<JSONObject>* output) { return
value->asObject(output); } |
419 static bool asArray(InspectorValue* value, RefPtr<InspectorArray>* output) {
return value->asArray(output); } | 433 static bool asArray(JSONValue* value, RefPtr<JSONArray>* output) { return va
lue->asArray(output); } |
420 }; | 434 }; |
421 | 435 |
422 int InspectorBackendDispatcherImpl::getInt(InspectorObject* object, const String
& name, bool* valueFound, InspectorArray* protocolErrors) | 436 int InspectorBackendDispatcherImpl::getInt(JSONObject* object, const String& nam
e, bool* valueFound, JSONArray* protocolErrors) |
423 { | 437 { |
424 return getPropertyValueImpl<int, int, int>(object, name, valueFound, protoco
lErrors, 0, AsMethodBridges::asInt, "Number"); | 438 return getPropertyValueImpl<int, int, int>(object, name, valueFound, protoco
lErrors, 0, AsMethodBridges::asInt, "Number"); |
425 } | 439 } |
426 | 440 |
427 double InspectorBackendDispatcherImpl::getDouble(InspectorObject* object, const
String& name, bool* valueFound, InspectorArray* protocolErrors) | 441 double InspectorBackendDispatcherImpl::getDouble(JSONObject* object, const Strin
g& name, bool* valueFound, JSONArray* protocolErrors) |
428 { | 442 { |
429 return getPropertyValueImpl<double, double, double>(object, name, valueFound
, protocolErrors, 0, AsMethodBridges::asDouble, "Number"); | 443 return getPropertyValueImpl<double, double, double>(object, name, valueFound
, protocolErrors, 0, AsMethodBridges::asDouble, "Number"); |
430 } | 444 } |
431 | 445 |
432 String InspectorBackendDispatcherImpl::getString(InspectorObject* object, const
String& name, bool* valueFound, InspectorArray* protocolErrors) | 446 String InspectorBackendDispatcherImpl::getString(JSONObject* object, const Strin
g& name, bool* valueFound, JSONArray* protocolErrors) |
433 { | 447 { |
434 return getPropertyValueImpl<String, String, String>(object, name, valueFound
, protocolErrors, "", AsMethodBridges::asString, "String"); | 448 return getPropertyValueImpl<String, String, String>(object, name, valueFound
, protocolErrors, "", AsMethodBridges::asString, "String"); |
435 } | 449 } |
436 | 450 |
437 bool InspectorBackendDispatcherImpl::getBoolean(InspectorObject* object, const S
tring& name, bool* valueFound, InspectorArray* protocolErrors) | 451 bool InspectorBackendDispatcherImpl::getBoolean(JSONObject* object, const String
& name, bool* valueFound, JSONArray* protocolErrors) |
438 { | 452 { |
439 return getPropertyValueImpl<bool, bool, bool>(object, name, valueFound, prot
ocolErrors, false, AsMethodBridges::asBoolean, "Boolean"); | 453 return getPropertyValueImpl<bool, bool, bool>(object, name, valueFound, prot
ocolErrors, false, AsMethodBridges::asBoolean, "Boolean"); |
440 } | 454 } |
441 | 455 |
442 PassRefPtr<InspectorObject> InspectorBackendDispatcherImpl::getObject(InspectorO
bject* object, const String& name, bool* valueFound, InspectorArray* protocolErr
ors) | 456 PassRefPtr<JSONObject> InspectorBackendDispatcherImpl::getObject(JSONObject* obj
ect, const String& name, bool* valueFound, JSONArray* protocolErrors) |
443 { | 457 { |
444 return getPropertyValueImpl<PassRefPtr<InspectorObject>, RefPtr<InspectorObj
ect>, InspectorObject*>(object, name, valueFound, protocolErrors, 0, AsMethodBri
dges::asObject, "Object"); | 458 return getPropertyValueImpl<PassRefPtr<JSONObject>, RefPtr<JSONObject>, JSON
Object*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asObject,
"Object"); |
445 } | 459 } |
446 | 460 |
447 PassRefPtr<InspectorArray> InspectorBackendDispatcherImpl::getArray(InspectorObj
ect* object, const String& name, bool* valueFound, InspectorArray* protocolError
s) | 461 PassRefPtr<JSONArray> InspectorBackendDispatcherImpl::getArray(JSONObject* objec
t, const String& name, bool* valueFound, JSONArray* protocolErrors) |
448 { | 462 { |
449 return getPropertyValueImpl<PassRefPtr<InspectorArray>, RefPtr<InspectorArra
y>, InspectorArray*>(object, name, valueFound, protocolErrors, 0, AsMethodBridge
s::asArray, "Array"); | 463 return getPropertyValueImpl<PassRefPtr<JSONArray>, RefPtr<JSONArray>, JSONAr
ray*>(object, name, valueFound, protocolErrors, 0, AsMethodBridges::asArray, "Ar
ray"); |
450 } | 464 } |
451 | 465 |
452 bool InspectorBackendDispatcher::getCommandName(const String& message, String* r
esult) | 466 bool InspectorBackendDispatcher::getCommandName(const String& message, String* r
esult) |
453 { | 467 { |
454 RefPtr<InspectorValue> value = InspectorValue::parseJSON(message); | 468 RefPtr<JSONValue> value = parseJSON(message); |
455 if (!value) | 469 if (!value) |
456 return false; | 470 return false; |
457 | 471 |
458 RefPtr<InspectorObject> object = value->asObject(); | 472 RefPtr<JSONObject> object = value->asObject(); |
459 if (!object) | 473 if (!object) |
460 return false; | 474 return false; |
461 | 475 |
462 if (!object->getString("method", result)) | 476 if (!object->getString("method", result)) |
463 return false; | 477 return false; |
464 | 478 |
465 return true; | 479 return true; |
466 } | 480 } |
467 | 481 |
468 InspectorBackendDispatcher::CallbackBase::CallbackBase(PassRefPtr<InspectorBacke
ndDispatcherImpl> backendImpl, int id) | 482 InspectorBackendDispatcher::CallbackBase::CallbackBase(PassRefPtr<InspectorBacke
ndDispatcherImpl> backendImpl, int id) |
469 : m_backendImpl(backendImpl), m_id(id), m_alreadySent(false) {} | 483 : m_backendImpl(backendImpl), m_id(id), m_alreadySent(false) {} |
470 | 484 |
471 InspectorBackendDispatcher::CallbackBase::~CallbackBase() {} | 485 InspectorBackendDispatcher::CallbackBase::~CallbackBase() {} |
472 | 486 |
473 void InspectorBackendDispatcher::CallbackBase::sendFailure(const ErrorString& er
ror) | 487 void InspectorBackendDispatcher::CallbackBase::sendFailure(const ErrorString& er
ror) |
474 { | 488 { |
475 ASSERT(error.length()); | 489 ASSERT(error.length()); |
476 sendIfActive(0, error); | 490 sendIfActive(0, error, PassRefPtr<JSONValue>()); |
477 } | 491 } |
478 | 492 |
479 bool InspectorBackendDispatcher::CallbackBase::isActive() | 493 bool InspectorBackendDispatcher::CallbackBase::isActive() |
480 { | 494 { |
481 return !m_alreadySent && m_backendImpl->isActive(); | 495 return !m_alreadySent && m_backendImpl->isActive(); |
482 } | 496 } |
483 | 497 |
484 void InspectorBackendDispatcher::CallbackBase::sendIfActive(PassRefPtr<Inspector
Object> partialMessage, const ErrorString& invocationError) | 498 void InspectorBackendDispatcher::CallbackBase::sendIfActive(PassRefPtr<JSONObjec
t> partialMessage, const ErrorString& invocationError, PassRefPtr<JSONValue> err
orData) |
485 { | 499 { |
486 if (m_alreadySent) | 500 if (m_alreadySent) |
487 return; | 501 return; |
488 m_backendImpl->sendResponse(m_id, partialMessage, invocationError); | 502 m_backendImpl->sendResponse(m_id, partialMessage, invocationError, errorData
); |
489 m_alreadySent = true; | 503 m_alreadySent = true; |
490 } | 504 } |
491 | 505 |
492 COMPILE_ASSERT(static_cast<int>(InspectorBackendDispatcher::kMethodNamesEnumSize
) == WTF_ARRAY_LENGTH(InspectorBackendDispatcher::commandNames), command_name_ar
ray_problem); | 506 COMPILE_ASSERT(static_cast<int>(InspectorBackendDispatcher::kMethodNamesEnumSize
) == WTF_ARRAY_LENGTH(InspectorBackendDispatcher::commandNames), command_name_ar
ray_problem); |
493 | 507 |
494 } // namespace WebCore | 508 } // namespace WebCore |
495 | 509 |
496 """) | 510 """) |
497 | 511 |
498 frontend_cpp = ( | 512 frontend_cpp = ( |
499 """ | 513 """ |
500 | 514 |
501 #include "config.h" | 515 #include "config.h" |
| 516 #include "InspectorFrontend.h" |
502 | 517 |
503 #include "InspectorFrontend.h" | |
504 #include "core/inspector/InspectorFrontendChannel.h" | 518 #include "core/inspector/InspectorFrontendChannel.h" |
505 #include "core/inspector/InspectorValues.h" | 519 #include "core/platform/JSONValues.h" |
506 | 520 #include "wtf/text/CString.h" |
507 #include <wtf/text/CString.h> | 521 #include "wtf/text/WTFString.h" |
508 #include <wtf/text/WTFString.h> | |
509 | 522 |
510 namespace WebCore { | 523 namespace WebCore { |
511 | 524 |
512 InspectorFrontend::InspectorFrontend(InspectorFrontendChannel* inspectorFrontend
Channel) | 525 InspectorFrontend::InspectorFrontend(InspectorFrontendChannel* inspectorFrontend
Channel) |
513 : $constructorInit{ | 526 : $constructorInit{ |
514 } | 527 } |
515 | 528 |
516 $methods | 529 $methods |
517 | 530 |
518 } // namespace WebCore | 531 } // namespace WebCore |
519 | 532 |
520 """) | 533 """) |
521 | 534 |
522 typebuilder_h = ( | 535 typebuilder_h = ( |
523 """ | 536 """ |
524 #ifndef InspectorTypeBuilder_h | 537 #ifndef InspectorTypeBuilder_h |
525 #define InspectorTypeBuilder_h | 538 #define InspectorTypeBuilder_h |
526 | 539 |
527 #include "core/inspector/InspectorValues.h" | 540 #include "core/platform/JSONValues.h" |
528 | 541 #include "wtf/Assertions.h" |
529 #include <wtf/Assertions.h> | 542 #include "wtf/PassRefPtr.h" |
530 #include <wtf/PassRefPtr.h> | |
531 | 543 |
532 namespace WebCore { | 544 namespace WebCore { |
533 | 545 |
534 namespace TypeBuilder { | 546 namespace TypeBuilder { |
535 | 547 |
536 template<typename T> | 548 template<typename T> |
537 class OptOutput { | 549 class OptOutput { |
538 public: | 550 public: |
539 OptOutput() : m_assigned(false) { } | 551 OptOutput() : m_assigned(false) { } |
540 | 552 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 | 591 |
580 template<> | 592 template<> |
581 inline int ExactlyInt::cast_to_int<int>(int i) { return i; } | 593 inline int ExactlyInt::cast_to_int<int>(int i) { return i; } |
582 | 594 |
583 template<> | 595 template<> |
584 inline int ExactlyInt::cast_to_int<unsigned int>(unsigned int i) { return i; } | 596 inline int ExactlyInt::cast_to_int<unsigned int>(unsigned int i) { return i; } |
585 | 597 |
586 class RuntimeCastHelper { | 598 class RuntimeCastHelper { |
587 public: | 599 public: |
588 #if $validatorIfdefName | 600 #if $validatorIfdefName |
589 template<InspectorValue::Type TYPE> | 601 template<JSONValue::Type TYPE> |
590 static void assertType(InspectorValue* value) | 602 static void assertType(JSONValue* value) |
591 { | 603 { |
592 ASSERT(value->type() == TYPE); | 604 ASSERT(value->type() == TYPE); |
593 } | 605 } |
594 static void assertAny(InspectorValue*); | 606 static void assertAny(JSONValue*); |
595 static void assertInt(InspectorValue* value); | 607 static void assertInt(JSONValue* value); |
596 #endif | 608 #endif |
597 }; | 609 }; |
598 | 610 |
599 | 611 |
600 // This class provides "Traits" type for the input type T. It is programmed usin
g C++ template specialization | 612 // This class provides "Traits" type for the input type T. It is programmed usin
g C++ template specialization |
601 // technique. By default it simply takes "ItemTraits" type from T, but it doesn'
t work with the base types. | 613 // technique. By default it simply takes "ItemTraits" type from T, but it doesn'
t work with the base types. |
602 template<typename T> | 614 template<typename T> |
603 struct ArrayItemHelper { | 615 struct ArrayItemHelper { |
604 typedef typename T::ItemTraits Traits; | 616 typedef typename T::ItemTraits Traits; |
605 }; | 617 }; |
606 | 618 |
607 template<typename T> | 619 template<typename T> |
608 class Array : public InspectorArrayBase { | 620 class Array : public JSONArrayBase { |
609 private: | 621 private: |
610 Array() { } | 622 Array() { } |
611 | 623 |
612 InspectorArray* openAccessors() { | 624 JSONArray* openAccessors() { |
613 COMPILE_ASSERT(sizeof(InspectorArray) == sizeof(Array<T>), cannot_cast); | 625 COMPILE_ASSERT(sizeof(JSONArray) == sizeof(Array<T>), cannot_cast); |
614 return static_cast<InspectorArray*>(static_cast<InspectorArrayBase*>(thi
s)); | 626 return static_cast<JSONArray*>(static_cast<JSONArrayBase*>(this)); |
615 } | 627 } |
616 | 628 |
617 public: | 629 public: |
618 void addItem(PassRefPtr<T> value) | 630 void addItem(PassRefPtr<T> value) |
619 { | 631 { |
620 ArrayItemHelper<T>::Traits::pushRefPtr(this->openAccessors(), value); | 632 ArrayItemHelper<T>::Traits::pushRefPtr(this->openAccessors(), value); |
621 } | 633 } |
622 | 634 |
623 void addItem(T value) | 635 void addItem(T value) |
624 { | 636 { |
625 ArrayItemHelper<T>::Traits::pushRaw(this->openAccessors(), value); | 637 ArrayItemHelper<T>::Traits::pushRaw(this->openAccessors(), value); |
626 } | 638 } |
627 | 639 |
628 static PassRefPtr<Array<T> > create() | 640 static PassRefPtr<Array<T> > create() |
629 { | 641 { |
630 return adoptRef(new Array<T>()); | 642 return adoptRef(new Array<T>()); |
631 } | 643 } |
632 | 644 |
633 static PassRefPtr<Array<T> > runtimeCast(PassRefPtr<InspectorValue> value) | 645 static PassRefPtr<Array<T> > runtimeCast(PassRefPtr<JSONValue> value) |
634 { | 646 { |
635 RefPtr<InspectorArray> array; | 647 RefPtr<JSONArray> array; |
636 bool castRes = value->asArray(&array); | 648 bool castRes = value->asArray(&array); |
637 ASSERT_UNUSED(castRes, castRes); | 649 ASSERT_UNUSED(castRes, castRes); |
638 #if $validatorIfdefName | 650 #if $validatorIfdefName |
639 assertCorrectValue(array.get()); | 651 assertCorrectValue(array.get()); |
640 #endif // $validatorIfdefName | 652 #endif // $validatorIfdefName |
641 COMPILE_ASSERT(sizeof(Array<T>) == sizeof(InspectorArray), type_cast_pro
blem); | 653 COMPILE_ASSERT(sizeof(Array<T>) == sizeof(JSONArray), type_cast_problem)
; |
642 return static_cast<Array<T>*>(static_cast<InspectorArrayBase*>(array.get
())); | 654 return static_cast<Array<T>*>(static_cast<JSONArrayBase*>(array.get())); |
643 } | 655 } |
644 | 656 |
645 #if $validatorIfdefName | 657 #if $validatorIfdefName |
646 static void assertCorrectValue(InspectorValue* value) | 658 static void assertCorrectValue(JSONValue* value) |
647 { | 659 { |
648 RefPtr<InspectorArray> array; | 660 RefPtr<JSONArray> array; |
649 bool castRes = value->asArray(&array); | 661 bool castRes = value->asArray(&array); |
650 ASSERT_UNUSED(castRes, castRes); | 662 ASSERT_UNUSED(castRes, castRes); |
651 for (unsigned i = 0; i < array->length(); i++) | 663 for (unsigned i = 0; i < array->length(); i++) |
652 ArrayItemHelper<T>::Traits::template assertCorrectValue<T>(array->ge
t(i).get()); | 664 ArrayItemHelper<T>::Traits::template assertCorrectValue<T>(array->ge
t(i).get()); |
653 } | 665 } |
654 | 666 |
655 #endif // $validatorIfdefName | 667 #endif // $validatorIfdefName |
656 }; | 668 }; |
657 | 669 |
658 struct StructItemTraits { | 670 struct StructItemTraits { |
659 static void pushRefPtr(InspectorArray* array, PassRefPtr<InspectorValue> val
ue) | 671 static void pushRefPtr(JSONArray* array, PassRefPtr<JSONValue> value) |
660 { | 672 { |
661 array->pushValue(value); | 673 array->pushValue(value); |
662 } | 674 } |
663 | 675 |
664 #if $validatorIfdefName | 676 #if $validatorIfdefName |
665 template<typename T> | 677 template<typename T> |
666 static void assertCorrectValue(InspectorValue* value) { | 678 static void assertCorrectValue(JSONValue* value) { |
667 T::assertCorrectValue(value); | 679 T::assertCorrectValue(value); |
668 } | 680 } |
669 #endif // $validatorIfdefName | 681 #endif // $validatorIfdefName |
670 }; | 682 }; |
671 | 683 |
672 template<> | 684 template<> |
673 struct ArrayItemHelper<String> { | 685 struct ArrayItemHelper<String> { |
674 struct Traits { | 686 struct Traits { |
675 static void pushRaw(InspectorArray* array, const String& value) | 687 static void pushRaw(JSONArray* array, const String& value) |
676 { | 688 { |
677 array->pushString(value); | 689 array->pushString(value); |
678 } | 690 } |
679 | 691 |
680 #if $validatorIfdefName | 692 #if $validatorIfdefName |
681 template<typename T> | 693 template<typename T> |
682 static void assertCorrectValue(InspectorValue* value) { | 694 static void assertCorrectValue(JSONValue* value) { |
683 RuntimeCastHelper::assertType<InspectorValue::TypeString>(value); | 695 RuntimeCastHelper::assertType<JSONValue::TypeString>(value); |
684 } | 696 } |
685 #endif // $validatorIfdefName | 697 #endif // $validatorIfdefName |
686 }; | 698 }; |
687 }; | 699 }; |
688 | 700 |
689 template<> | 701 template<> |
690 struct ArrayItemHelper<int> { | 702 struct ArrayItemHelper<int> { |
691 struct Traits { | 703 struct Traits { |
692 static void pushRaw(InspectorArray* array, int value) | 704 static void pushRaw(JSONArray* array, int value) |
693 { | 705 { |
694 array->pushInt(value); | 706 array->pushInt(value); |
695 } | 707 } |
696 | 708 |
697 #if $validatorIfdefName | 709 #if $validatorIfdefName |
698 template<typename T> | 710 template<typename T> |
699 static void assertCorrectValue(InspectorValue* value) { | 711 static void assertCorrectValue(JSONValue* value) { |
700 RuntimeCastHelper::assertInt(value); | 712 RuntimeCastHelper::assertInt(value); |
701 } | 713 } |
702 #endif // $validatorIfdefName | 714 #endif // $validatorIfdefName |
703 }; | 715 }; |
704 }; | 716 }; |
705 | 717 |
706 template<> | 718 template<> |
707 struct ArrayItemHelper<double> { | 719 struct ArrayItemHelper<double> { |
708 struct Traits { | 720 struct Traits { |
709 static void pushRaw(InspectorArray* array, double value) | 721 static void pushRaw(JSONArray* array, double value) |
710 { | 722 { |
711 array->pushNumber(value); | 723 array->pushNumber(value); |
712 } | 724 } |
713 | 725 |
714 #if $validatorIfdefName | 726 #if $validatorIfdefName |
715 template<typename T> | 727 template<typename T> |
716 static void assertCorrectValue(InspectorValue* value) { | 728 static void assertCorrectValue(JSONValue* value) { |
717 RuntimeCastHelper::assertType<InspectorValue::TypeNumber>(value); | 729 RuntimeCastHelper::assertType<JSONValue::TypeNumber>(value); |
718 } | 730 } |
719 #endif // $validatorIfdefName | 731 #endif // $validatorIfdefName |
720 }; | 732 }; |
721 }; | 733 }; |
722 | 734 |
723 template<> | 735 template<> |
724 struct ArrayItemHelper<bool> { | 736 struct ArrayItemHelper<bool> { |
725 struct Traits { | 737 struct Traits { |
726 static void pushRaw(InspectorArray* array, bool value) | 738 static void pushRaw(JSONArray* array, bool value) |
727 { | 739 { |
728 array->pushBoolean(value); | 740 array->pushBoolean(value); |
729 } | 741 } |
730 | 742 |
731 #if $validatorIfdefName | 743 #if $validatorIfdefName |
732 template<typename T> | 744 template<typename T> |
733 static void assertCorrectValue(InspectorValue* value) { | 745 static void assertCorrectValue(JSONValue* value) { |
734 RuntimeCastHelper::assertType<InspectorValue::TypeBoolean>(value); | 746 RuntimeCastHelper::assertType<JSONValue::TypeBoolean>(value); |
735 } | 747 } |
736 #endif // $validatorIfdefName | 748 #endif // $validatorIfdefName |
737 }; | 749 }; |
738 }; | 750 }; |
739 | 751 |
740 template<> | 752 template<> |
741 struct ArrayItemHelper<InspectorValue> { | 753 struct ArrayItemHelper<JSONValue> { |
742 struct Traits { | 754 struct Traits { |
743 static void pushRefPtr(InspectorArray* array, PassRefPtr<InspectorValue>
value) | 755 static void pushRefPtr(JSONArray* array, PassRefPtr<JSONValue> value) |
744 { | 756 { |
745 array->pushValue(value); | 757 array->pushValue(value); |
746 } | 758 } |
747 | 759 |
748 #if $validatorIfdefName | 760 #if $validatorIfdefName |
749 template<typename T> | 761 template<typename T> |
750 static void assertCorrectValue(InspectorValue* value) { | 762 static void assertCorrectValue(JSONValue* value) { |
751 RuntimeCastHelper::assertAny(value); | 763 RuntimeCastHelper::assertAny(value); |
752 } | 764 } |
753 #endif // $validatorIfdefName | 765 #endif // $validatorIfdefName |
754 }; | 766 }; |
755 }; | 767 }; |
756 | 768 |
757 template<> | 769 template<> |
758 struct ArrayItemHelper<InspectorObject> { | 770 struct ArrayItemHelper<JSONObject> { |
759 struct Traits { | 771 struct Traits { |
760 static void pushRefPtr(InspectorArray* array, PassRefPtr<InspectorValue>
value) | 772 static void pushRefPtr(JSONArray* array, PassRefPtr<JSONValue> value) |
761 { | 773 { |
762 array->pushValue(value); | 774 array->pushValue(value); |
763 } | 775 } |
764 | 776 |
765 #if $validatorIfdefName | 777 #if $validatorIfdefName |
766 template<typename T> | 778 template<typename T> |
767 static void assertCorrectValue(InspectorValue* value) { | 779 static void assertCorrectValue(JSONValue* value) { |
768 RuntimeCastHelper::assertType<InspectorValue::TypeObject>(value); | 780 RuntimeCastHelper::assertType<JSONValue::TypeObject>(value); |
769 } | 781 } |
770 #endif // $validatorIfdefName | 782 #endif // $validatorIfdefName |
771 }; | 783 }; |
772 }; | 784 }; |
773 | 785 |
774 template<> | 786 template<> |
775 struct ArrayItemHelper<InspectorArray> { | 787 struct ArrayItemHelper<JSONArray> { |
776 struct Traits { | 788 struct Traits { |
777 static void pushRefPtr(InspectorArray* array, PassRefPtr<InspectorArray>
value) | 789 static void pushRefPtr(JSONArray* array, PassRefPtr<JSONArray> value) |
778 { | 790 { |
779 array->pushArray(value); | 791 array->pushArray(value); |
780 } | 792 } |
781 | 793 |
782 #if $validatorIfdefName | 794 #if $validatorIfdefName |
783 template<typename T> | 795 template<typename T> |
784 static void assertCorrectValue(InspectorValue* value) { | 796 static void assertCorrectValue(JSONValue* value) { |
785 RuntimeCastHelper::assertType<InspectorValue::TypeArray>(value); | 797 RuntimeCastHelper::assertType<JSONValue::TypeArray>(value); |
786 } | 798 } |
787 #endif // $validatorIfdefName | 799 #endif // $validatorIfdefName |
788 }; | 800 }; |
789 }; | 801 }; |
790 | 802 |
791 template<typename T> | 803 template<typename T> |
792 struct ArrayItemHelper<TypeBuilder::Array<T> > { | 804 struct ArrayItemHelper<TypeBuilder::Array<T> > { |
793 struct Traits { | 805 struct Traits { |
794 static void pushRefPtr(InspectorArray* array, PassRefPtr<TypeBuilder::Ar
ray<T> > value) | 806 static void pushRefPtr(JSONArray* array, PassRefPtr<TypeBuilder::Array<T
> > value) |
795 { | 807 { |
796 array->pushValue(value); | 808 array->pushValue(value); |
797 } | 809 } |
798 | 810 |
799 #if $validatorIfdefName | 811 #if $validatorIfdefName |
800 template<typename S> | 812 template<typename S> |
801 static void assertCorrectValue(InspectorValue* value) { | 813 static void assertCorrectValue(JSONValue* value) { |
802 S::assertCorrectValue(value); | 814 S::assertCorrectValue(value); |
803 } | 815 } |
804 #endif // $validatorIfdefName | 816 #endif // $validatorIfdefName |
805 }; | 817 }; |
806 }; | 818 }; |
807 | 819 |
808 ${forwards} | 820 ${forwards} |
809 | 821 |
810 String getEnumConstantValue(int code); | 822 String getEnumConstantValue(int code); |
811 | 823 |
812 ${typeBuilders} | 824 ${typeBuilders} |
813 } // namespace TypeBuilder | 825 } // namespace TypeBuilder |
814 | 826 |
815 | 827 |
816 } // namespace WebCore | 828 } // namespace WebCore |
817 | 829 |
818 #endif // !defined(InspectorTypeBuilder_h) | 830 #endif // !defined(InspectorTypeBuilder_h) |
819 | 831 |
820 """) | 832 """) |
821 | 833 |
822 typebuilder_cpp = ( | 834 typebuilder_cpp = ( |
823 """ | 835 """ |
824 | 836 |
825 #include "config.h" | 837 #include "config.h" |
826 | 838 |
827 #include "InspectorTypeBuilder.h" | 839 #include "InspectorTypeBuilder.h" |
828 | 840 #include "wtf/text/CString.h" |
829 #include <wtf/text/CString.h> | |
830 | 841 |
831 namespace WebCore { | 842 namespace WebCore { |
832 | 843 |
833 namespace TypeBuilder { | 844 namespace TypeBuilder { |
834 | 845 |
835 const char* const enum_constant_values[] = { | 846 const char* const enum_constant_values[] = { |
836 $enumConstantValues}; | 847 $enumConstantValues}; |
837 | 848 |
838 String getEnumConstantValue(int code) { | 849 String getEnumConstantValue(int code) { |
839 return enum_constant_values[code]; | 850 return enum_constant_values[code]; |
840 } | 851 } |
841 | 852 |
842 } // namespace TypeBuilder | 853 } // namespace TypeBuilder |
843 | 854 |
844 $implCode | 855 $implCode |
845 | 856 |
846 #if $validatorIfdefName | 857 #if $validatorIfdefName |
847 | 858 |
848 void TypeBuilder::RuntimeCastHelper::assertAny(InspectorValue*) | 859 void TypeBuilder::RuntimeCastHelper::assertAny(JSONValue*) |
849 { | 860 { |
850 // No-op. | 861 // No-op. |
851 } | 862 } |
852 | 863 |
853 | 864 |
854 void TypeBuilder::RuntimeCastHelper::assertInt(InspectorValue* value) | 865 void TypeBuilder::RuntimeCastHelper::assertInt(JSONValue* value) |
855 { | 866 { |
856 double v; | 867 double v; |
857 bool castRes = value->asNumber(&v); | 868 bool castRes = value->asNumber(&v); |
858 ASSERT_UNUSED(castRes, castRes); | 869 ASSERT_UNUSED(castRes, castRes); |
859 ASSERT(static_cast<double>(static_cast<int>(v)) == v); | 870 ASSERT(static_cast<double>(static_cast<int>(v)) == v); |
860 } | 871 } |
861 | 872 |
862 $validatorCode | 873 $validatorCode |
863 | 874 |
864 #endif // $validatorIfdefName | 875 #endif // $validatorIfdefName |
865 | 876 |
866 } // namespace WebCore | 877 } // namespace WebCore |
867 | 878 |
868 """) | 879 """) |
869 | 880 |
870 param_container_access_code = """ | 881 param_container_access_code = """ |
871 RefPtr<InspectorObject> paramsContainer = requestMessageObject->getObject("p
arams"); | 882 RefPtr<JSONObject> paramsContainer = requestMessageObject->getObject("params
"); |
872 InspectorObject* paramsContainerPtr = paramsContainer.get(); | 883 JSONObject* paramsContainerPtr = paramsContainer.get(); |
873 InspectorArray* protocolErrorsPtr = protocolErrors.get(); | 884 JSONArray* protocolErrorsPtr = protocolErrors.get(); |
874 """ | 885 """ |
875 | 886 |
876 class_binding_builder_part_1 = ( | 887 class_binding_builder_part_1 = ( |
877 """ AllFieldsSet = %s | 888 """ AllFieldsSet = %s |
878 }; | 889 }; |
879 | 890 |
880 template<int STATE> | 891 template<int STATE> |
881 class Builder { | 892 class Builder { |
882 private: | 893 private: |
883 RefPtr<InspectorObject> m_result; | 894 RefPtr<JSONObject> m_result; |
884 | 895 |
885 template<int STEP> Builder<STATE | STEP>& castState() | 896 template<int STEP> Builder<STATE | STEP>& castState() |
886 { | 897 { |
887 return *reinterpret_cast<Builder<STATE | STEP>*>(this); | 898 return *reinterpret_cast<Builder<STATE | STEP>*>(this); |
888 } | 899 } |
889 | 900 |
890 Builder(PassRefPtr</*%s*/InspectorObject> ptr) | 901 Builder(PassRefPtr</*%s*/JSONObject> ptr) |
891 { | 902 { |
892 COMPILE_ASSERT(STATE == NoFieldsSet, builder_created_in_non_init_sta
te); | 903 COMPILE_ASSERT(STATE == NoFieldsSet, builder_created_in_non_init_sta
te); |
893 m_result = ptr; | 904 m_result = ptr; |
894 } | 905 } |
895 friend class %s; | 906 friend class %s; |
896 public: | 907 public: |
897 """) | 908 """) |
898 | 909 |
899 class_binding_builder_part_2 = (""" | 910 class_binding_builder_part_2 = (""" |
900 Builder<STATE | %s>& set%s(%s value) | 911 Builder<STATE | %s>& set%s(%s value) |
901 { | 912 { |
902 COMPILE_ASSERT(!(STATE & %s), property_%s_already_set); | 913 COMPILE_ASSERT(!(STATE & %s), property_%s_already_set); |
903 m_result->set%s("%s", %s); | 914 m_result->set%s("%s", %s); |
904 return castState<%s>(); | 915 return castState<%s>(); |
905 } | 916 } |
906 """) | 917 """) |
907 | 918 |
908 class_binding_builder_part_3 = (""" | 919 class_binding_builder_part_3 = (""" |
909 operator RefPtr<%s>& () | 920 operator RefPtr<%s>& () |
910 { | 921 { |
911 COMPILE_ASSERT(STATE == AllFieldsSet, result_is_not_ready); | 922 COMPILE_ASSERT(STATE == AllFieldsSet, result_is_not_ready); |
912 COMPILE_ASSERT(sizeof(%s) == sizeof(InspectorObject), cannot_cast); | 923 COMPILE_ASSERT(sizeof(%s) == sizeof(JSONObject), cannot_cast); |
913 return *reinterpret_cast<RefPtr<%s>*>(&m_result); | 924 return *reinterpret_cast<RefPtr<%s>*>(&m_result); |
914 } | 925 } |
915 | 926 |
916 PassRefPtr<%s> release() | 927 PassRefPtr<%s> release() |
917 { | 928 { |
918 return RefPtr<%s>(*this).release(); | 929 return RefPtr<%s>(*this).release(); |
919 } | 930 } |
920 }; | 931 }; |
921 | 932 |
922 """) | 933 """) |
923 | 934 |
924 class_binding_builder_part_4 = ( | 935 class_binding_builder_part_4 = ( |
925 """ static Builder<NoFieldsSet> create() | 936 """ static Builder<NoFieldsSet> create() |
926 { | 937 { |
927 return Builder<NoFieldsSet>(InspectorObject::create()); | 938 return Builder<NoFieldsSet>(JSONObject::create()); |
928 } | 939 } |
929 """) | 940 """) |
OLD | NEW |