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

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

Issue 1660113002: Updated to Chrome 45 (2454) moved from SVN to git. Base URL: https://github.com/dart-lang/webcore.git@roll_45
Patch Set: Created 4 years, 10 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
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 12 matching lines...) Expand all
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 CORE_EXPORT $domainClassName {
34 public: 34 public:
35 static $domainClassName* from(InspectorFrontend* frontend) { return &(fr ontend->m_$domainFieldName) ;}
35 $domainClassName(InspectorFrontendChannel* inspectorFrontendChannel) : m _inspectorFrontendChannel(inspectorFrontendChannel) { } 36 $domainClassName(InspectorFrontendChannel* inspectorFrontendChannel) : m _inspectorFrontendChannel(inspectorFrontendChannel) { }
36 ${frontendDomainMethodDeclarations} 37 ${frontendDomainMethodDeclarations}
37 void flush() { m_inspectorFrontendChannel->flush(); } 38 void flush() { m_inspectorFrontendChannel->flush(); }
38 private: 39 private:
39 InspectorFrontendChannel* m_inspectorFrontendChannel; 40 InspectorFrontendChannel* m_inspectorFrontendChannel;
40 }; 41 };
41 42
42 $domainClassName* $domainFieldName() { return &m_$domainFieldName; }
43
44 """) 43 """)
45 44
46 backend_method = ( 45 backend_method = (
47 """void InspectorBackendDispatcherImpl::${domainName}_$methodName(long callId, J SONObject*$requestMessageObject, JSONArray* protocolErrors) 46 """void InspectorBackendDispatcherImpl::${domainName}_$methodName(int callId, JS ONObject*$requestMessageObject, JSONArray* protocolErrors)
48 { 47 {
49 if (!$agentField) 48 if (!$agentField)
50 protocolErrors->pushString("${domainName} handler is not available."); 49 protocolErrors->pushString("${domainName} handler is not available.");
51 $methodCode 50 $methodCode
52 if (protocolErrors->length()) { 51 if (protocolErrors->length()) {
53 reportProtocolError(&callId, InvalidParams, String::format(InvalidParams FormatString, commandName($commandNameIndex)), protocolErrors); 52 reportProtocolError(callId, InvalidParams, String::format(InvalidParamsF ormatString, commandName($commandNameIndex)), protocolErrors);
54 return; 53 return;
55 } 54 }
56 $agentCallParamsDeclaration 55 $agentCallParamsDeclaration
57 $agentField->$methodName($agentCallParams); 56 $agentField->$methodName($agentCallParams);
58 $responseCook 57 $responseCook
59 sendResponse(callId, $sendResponseCallParams); 58 sendResponse(callId, $sendResponseCallParams);
60 } 59 }
61 """) 60 """)
62 61
63 frontend_method = ("""void InspectorFrontend::$domainName::$eventName($parameter s) 62 frontend_method = ("""void InspectorFrontend::$domainName::$eventName($parameter s)
64 { 63 {
65 RefPtr<JSONObject> jsonMessage = JSONObject::create(); 64 RefPtr<JSONObject> jsonMessage = JSONObject::create();
66 jsonMessage->setString("method", "$domainName.$eventName"); 65 jsonMessage->setString("method", "$domainName.$eventName");
67 $code if (m_inspectorFrontendChannel) 66 $code if (m_inspectorFrontendChannel)
68 m_inspectorFrontendChannel->sendMessageToFrontend(jsonMessage.release()) ; 67 m_inspectorFrontendChannel->sendProtocolNotification(jsonMessage.release ());
69 } 68 }
70 """) 69 """)
71 70
72 callback_main_methods = ( 71 callback_main_methods = (
73 """InspectorBackendDispatcher::$agentName::$callbackName::$callbackName(PassRefP trWillBeRawPtr<InspectorBackendDispatcherImpl> backendImpl, int id) : CallbackBa se(backendImpl, id) {} 72 """InspectorBackendDispatcher::$agentName::$callbackName::$callbackName(PassRefP trWillBeRawPtr<InspectorBackendDispatcherImpl> backendImpl, int id) : CallbackBa se(backendImpl, id) {}
74 73
75 void InspectorBackendDispatcher::$agentName::$callbackName::sendSuccess($paramet ers) 74 void InspectorBackendDispatcher::$agentName::$callbackName::sendSuccess($paramet ers)
76 { 75 {
77 RefPtr<JSONObject> jsonMessage = JSONObject::create(); 76 RefPtr<JSONObject> jsonMessage = JSONObject::create();
78 $code sendIfActive(jsonMessage, ErrorString(), PassRefPtr<JSONValue>()); 77 $code sendIfActive(jsonMessage, ErrorString(), PassRefPtr<JSONValue>());
(...skipping 11 matching lines...) Expand all
90 sendIfActive(nullptr, error, errorDataValue.release()); 89 sendIfActive(nullptr, error, errorDataValue.release());
91 } 90 }
92 """) 91 """)
93 92
94 93
95 frontend_h = ( 94 frontend_h = (
96 """#ifndef InspectorFrontend_h 95 """#ifndef InspectorFrontend_h
97 #define InspectorFrontend_h 96 #define InspectorFrontend_h
98 97
99 #include "InspectorTypeBuilder.h" 98 #include "InspectorTypeBuilder.h"
99 #include "core/CoreExport.h"
100 #include "core/inspector/InspectorFrontendChannel.h" 100 #include "core/inspector/InspectorFrontendChannel.h"
101 #include "platform/JSONValues.h" 101 #include "platform/JSONValues.h"
102 #include "wtf/PassRefPtr.h" 102 #include "wtf/PassRefPtr.h"
103 #include "wtf/text/WTFString.h" 103 #include "wtf/text/WTFString.h"
104 104
105 namespace blink { 105 namespace blink {
106 106
107 typedef String ErrorString; 107 typedef String ErrorString;
108 108
109 class InspectorFrontend { 109 class CORE_EXPORT InspectorFrontend {
110 public: 110 public:
111 InspectorFrontend(InspectorFrontendChannel*); 111 InspectorFrontend(InspectorFrontendChannel*);
112 InspectorFrontendChannel* channel() { return m_inspectorFrontendChannel; } 112 InspectorFrontendChannel* channel() { return m_inspectorFrontendChannel; }
113 113
114 $domainClassList 114 $domainClassList
115 private: 115 private:
116 InspectorFrontendChannel* m_inspectorFrontendChannel; 116 InspectorFrontendChannel* m_inspectorFrontendChannel;
117 ${fieldDeclarations}}; 117 ${fieldDeclarations}};
118 118
119 } // namespace blink 119 } // namespace blink
120 #endif // !defined(InspectorFrontend_h) 120 #endif // !defined(InspectorFrontend_h)
121 """) 121 """)
122 122
123 backend_h = ( 123 backend_h = (
124 """#ifndef InspectorBackendDispatcher_h 124 """#ifndef InspectorBackendDispatcher_h
125 #define InspectorBackendDispatcher_h 125 #define InspectorBackendDispatcher_h
126 126
127 #include "InspectorTypeBuilder.h" 127 #include "InspectorTypeBuilder.h"
128 128
129 #include "core/CoreExport.h"
129 #include "platform/heap/Handle.h" 130 #include "platform/heap/Handle.h"
130 #include "wtf/PassRefPtr.h" 131 #include "wtf/PassRefPtr.h"
131 #include "wtf/RefCounted.h" 132 #include "wtf/RefCounted.h"
132 #include "wtf/text/WTFString.h" 133 #include "wtf/text/WTFString.h"
133 134
134 namespace blink { 135 namespace blink {
135 136
136 class JSONObject; 137 class JSONObject;
137 class JSONArray; 138 class JSONArray;
138 class InspectorFrontendChannel; 139 class InspectorFrontendChannel;
139 140
140 typedef String ErrorString; 141 typedef String ErrorString;
141 142
142 class InspectorBackendDispatcherImpl; 143 class InspectorBackendDispatcherImpl;
143 144
144 class InspectorBackendDispatcher: public RefCountedWillBeGarbageCollectedFinaliz ed<InspectorBackendDispatcher> { 145 class CORE_EXPORT InspectorBackendDispatcher: public RefCountedWillBeGarbageColl ectedFinalized<InspectorBackendDispatcher> {
145 public: 146 public:
146 static PassRefPtrWillBeRawPtr<InspectorBackendDispatcher> create(InspectorFr ontendChannel* inspectorFrontendChannel); 147 static PassRefPtrWillBeRawPtr<InspectorBackendDispatcher> create(InspectorFr ontendChannel* inspectorFrontendChannel);
147 virtual ~InspectorBackendDispatcher() { } 148 virtual ~InspectorBackendDispatcher() { }
148 virtual void trace(Visitor*) { } 149 DEFINE_INLINE_VIRTUAL_TRACE() { }
149 150
150 class CallbackBase: public RefCountedWillBeGarbageCollectedFinalized<Callbac kBase> { 151 class CORE_EXPORT CallbackBase: public RefCountedWillBeGarbageCollectedFinal ized<CallbackBase> {
151 public: 152 public:
152 CallbackBase(PassRefPtrWillBeRawPtr<InspectorBackendDispatcherImpl> back endImpl, int id); 153 CallbackBase(PassRefPtrWillBeRawPtr<InspectorBackendDispatcherImpl> back endImpl, int id);
153 virtual ~CallbackBase(); 154 virtual ~CallbackBase();
154 virtual void trace(Visitor*); 155 DECLARE_VIRTUAL_TRACE();
155 void sendFailure(const ErrorString&); 156 void sendFailure(const ErrorString&);
156 bool isActive(); 157 bool isActive();
157 158
158 protected: 159 protected:
159 void sendIfActive(PassRefPtr<JSONObject> partialMessage, const ErrorStri ng& invocationError, PassRefPtr<JSONValue> errorData); 160 void sendIfActive(PassRefPtr<JSONObject> partialMessage, const ErrorStri ng& invocationError, PassRefPtr<JSONValue> errorData);
160 161
161 private: 162 private:
162 void disable() { m_alreadySent = true; } 163 void disable() { m_alreadySent = true; }
163 164
164 RefPtrWillBeMember<InspectorBackendDispatcherImpl> m_backendImpl; 165 RefPtrWillBeMember<InspectorBackendDispatcherImpl> m_backendImpl;
(...skipping 11 matching lines...) Expand all
176 enum CommonErrorCode { 177 enum CommonErrorCode {
177 ParseError = 0, 178 ParseError = 0,
178 InvalidRequest, 179 InvalidRequest,
179 MethodNotFound, 180 MethodNotFound,
180 InvalidParams, 181 InvalidParams,
181 InternalError, 182 InternalError,
182 ServerError, 183 ServerError,
183 LastEntry, 184 LastEntry,
184 }; 185 };
185 186
186 void reportProtocolError(const long* const callId, CommonErrorCode, const St ring& errorMessage) const; 187 void reportProtocolError(int callId, CommonErrorCode, const String& errorMes sage) const;
187 virtual void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage, PassRefPtr<JSONValue> data) const = 0; 188 virtual void reportProtocolError(int callId, CommonErrorCode, const String& errorMessage, PassRefPtr<JSONValue> data) const = 0;
188 virtual void dispatch(const String& message) = 0; 189 virtual void dispatch(const String& message) = 0;
189 static bool getCommandName(const String& message, String* result); 190 static bool getCommandName(const String& message, String* result);
190 191
191 enum MethodNames { 192 enum MethodNames {
192 $methodNamesEnumContent 193 $methodNamesEnumContent
193 194
194 kMethodNamesEnumSize 195 kMethodNamesEnumSize
195 }; 196 };
196 197
197 static const char* commandName(MethodNames); 198 static const char* commandName(MethodNames);
198 199
199 private: 200 private:
200 static const char commandNames[]; 201 static const char commandNames[];
201 static const size_t commandNamesIndex[]; 202 static const unsigned short commandNamesIndex[];
202 }; 203 };
203 204
204 } // namespace blink 205 } // namespace blink
205 #endif // !defined(InspectorBackendDispatcher_h) 206 #endif // !defined(InspectorBackendDispatcher_h)
206 207
207 208
208 """) 209 """)
209 210
210 backend_cpp = ( 211 backend_cpp = (
211 """ 212 """
212 213
213 #include "config.h" 214 #include "config.h"
214 #include "InspectorBackendDispatcher.h" 215 #include "InspectorBackendDispatcher.h"
215 216
216 #include "core/inspector/InspectorFrontendChannel.h" 217 #include "core/inspector/InspectorFrontendChannel.h"
217 #include "core/inspector/JSONParser.h" 218 #include "core/inspector/JSONParser.h"
218 #include "platform/JSONValues.h" 219 #include "platform/JSONValues.h"
219 #include "wtf/text/CString.h" 220 #include "wtf/text/CString.h"
220 #include "wtf/text/WTFString.h" 221 #include "wtf/text/WTFString.h"
221 222
222 namespace blink { 223 namespace blink {
223 224
224 const char InspectorBackendDispatcher::commandNames[] = { 225 const char InspectorBackendDispatcher::commandNames[] = {
225 $methodNameDeclarations 226 $methodNameDeclarations
226 }; 227 };
227 228
228 const size_t InspectorBackendDispatcher::commandNamesIndex[] = { 229 const unsigned short InspectorBackendDispatcher::commandNamesIndex[] = {
229 $methodNameDeclarationsIndex 230 $methodNameDeclarationsIndex
230 }; 231 };
231 232
232 const char* InspectorBackendDispatcher::commandName(MethodNames index) { 233 const char* InspectorBackendDispatcher::commandName(MethodNames index) {
233 COMPILE_ASSERT(static_cast<int>(kMethodNamesEnumSize) == WTF_ARRAY_LENGTH(co mmandNamesIndex), command_name_array_problem); 234 static_assert(static_cast<int>(kMethodNamesEnumSize) == WTF_ARRAY_LENGTH(com mandNamesIndex), "MethodNames enum should have the same number of elements as co mmandNamesIndex");
234 return commandNames + commandNamesIndex[index]; 235 return commandNames + commandNamesIndex[index];
235 } 236 }
236 237
237 class InspectorBackendDispatcherImpl : public InspectorBackendDispatcher { 238 class InspectorBackendDispatcherImpl : public InspectorBackendDispatcher {
238 public: 239 public:
239 InspectorBackendDispatcherImpl(InspectorFrontendChannel* inspectorFrontendCh annel) 240 InspectorBackendDispatcherImpl(InspectorFrontendChannel* inspectorFrontendCh annel)
240 : m_inspectorFrontendChannel(inspectorFrontendChannel) 241 : m_inspectorFrontendChannel(inspectorFrontendChannel)
241 $constructorInit 242 $constructorInit
242 { } 243 {
244 // Initialize dispatch map.
245 const CallHandler handlers[] = {
246 $messageHandlers
247 };
248 for (size_t i = 0; i < kMethodNamesEnumSize; ++i)
249 m_dispatchMap.add(commandName(static_cast<MethodNames>(i)), handlers [i]);
250
251 // Initialize common errors.
252 m_commonErrors.insert(ParseError, -32700);
253 m_commonErrors.insert(InvalidRequest, -32600);
254 m_commonErrors.insert(MethodNotFound, -32601);
255 m_commonErrors.insert(InvalidParams, -32602);
256 m_commonErrors.insert(InternalError, -32603);
257 m_commonErrors.insert(ServerError, -32000);
258 }
243 259
244 virtual void clearFrontend() { m_inspectorFrontendChannel = 0; } 260 virtual void clearFrontend() { m_inspectorFrontendChannel = 0; }
245 virtual void dispatch(const String& message); 261 virtual void dispatch(const String& message);
246 virtual void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage, PassRefPtr<JSONValue> data) const; 262 virtual void reportProtocolError(int callId, CommonErrorCode, const String& errorMessage, PassRefPtr<JSONValue> data) const;
247 using InspectorBackendDispatcher::reportProtocolError; 263 using InspectorBackendDispatcher::reportProtocolError;
248 264
249 void sendResponse(long callId, const ErrorString& invocationError, PassRefPt r<JSONValue> errorData, PassRefPtr<JSONObject> result); 265 void sendResponse(int callId, const ErrorString& invocationError, PassRefPtr <JSONValue> errorData, PassRefPtr<JSONObject> result);
250 bool isActive() { return m_inspectorFrontendChannel; } 266 bool isActive() { return m_inspectorFrontendChannel; }
251 267
252 $setters 268 $setters
253 private: 269 private:
270 using CallHandler = void (InspectorBackendDispatcherImpl::*)(int callId, JSO NObject* messageObject, JSONArray* protocolErrors);
271 using DispatchMap = HashMap<String, CallHandler>;
272
254 $methodDeclarations 273 $methodDeclarations
255 274
256 InspectorFrontendChannel* m_inspectorFrontendChannel; 275 InspectorFrontendChannel* m_inspectorFrontendChannel;
257 $fieldDeclarations 276 $fieldDeclarations
258 277
259 template<typename R, typename V, typename V0> 278 template<typename R, typename V, typename V0>
260 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); 279 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);
261 280
262 static int getInt(JSONObject* object, const char* name, bool* valueFound, JS ONArray* protocolErrors); 281 static int getInt(JSONObject* object, const char* name, bool* valueFound, JS ONArray* protocolErrors);
263 static double getDouble(JSONObject* object, const char* name, bool* valueFou nd, JSONArray* protocolErrors); 282 static double getDouble(JSONObject* object, const char* name, bool* valueFou nd, JSONArray* protocolErrors);
264 static String getString(JSONObject* object, const char* name, bool* valueFou nd, JSONArray* protocolErrors); 283 static String getString(JSONObject* object, const char* name, bool* valueFou nd, JSONArray* protocolErrors);
265 static bool getBoolean(JSONObject* object, const char* name, bool* valueFoun d, JSONArray* protocolErrors); 284 static bool getBoolean(JSONObject* object, const char* name, bool* valueFoun d, JSONArray* protocolErrors);
266 static PassRefPtr<JSONObject> getObject(JSONObject* object, const char* name , bool* valueFound, JSONArray* protocolErrors); 285 static PassRefPtr<JSONObject> getObject(JSONObject* object, const char* name , bool* valueFound, JSONArray* protocolErrors);
267 static PassRefPtr<JSONArray> getArray(JSONObject* object, const char* name, bool* valueFound, JSONArray* protocolErrors); 286 static PassRefPtr<JSONArray> getArray(JSONObject* object, const char* name, bool* valueFound, JSONArray* protocolErrors);
268 287
269 void sendResponse(long callId, ErrorString invocationError, PassRefPtr<JSONO bject> result) 288 void sendResponse(int callId, ErrorString invocationError, PassRefPtr<JSONOb ject> result)
270 { 289 {
271 sendResponse(callId, invocationError, RefPtr<JSONValue>(), result); 290 sendResponse(callId, invocationError, RefPtr<JSONValue>(), result);
272 } 291 }
273 void sendResponse(long callId, ErrorString invocationError) 292 void sendResponse(int callId, ErrorString invocationError)
274 { 293 {
275 sendResponse(callId, invocationError, RefPtr<JSONValue>(), JSONObject::c reate()); 294 sendResponse(callId, invocationError, RefPtr<JSONValue>(), JSONObject::c reate());
276 } 295 }
277 static const char InvalidParamsFormatString[]; 296 static const char InvalidParamsFormatString[];
297
298 DispatchMap m_dispatchMap;
299 Vector<int> m_commonErrors;
278 }; 300 };
279 301
280 const char InspectorBackendDispatcherImpl::InvalidParamsFormatString[] = "Some a rguments of method '%s' can't be processed"; 302 const char InspectorBackendDispatcherImpl::InvalidParamsFormatString[] = "Some a rguments of method '%s' can't be processed";
281 303
282 $methods 304 $methods
283 305
284 PassRefPtrWillBeRawPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::c reate(InspectorFrontendChannel* inspectorFrontendChannel) 306 PassRefPtrWillBeRawPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::c reate(InspectorFrontendChannel* inspectorFrontendChannel)
285 { 307 {
286 return adoptRefWillBeNoop(new InspectorBackendDispatcherImpl(inspectorFronte ndChannel)); 308 return adoptRefWillBeNoop(new InspectorBackendDispatcherImpl(inspectorFronte ndChannel));
287 } 309 }
288 310
289 311
290 void InspectorBackendDispatcherImpl::dispatch(const String& message) 312 void InspectorBackendDispatcherImpl::dispatch(const String& message)
291 { 313 {
292 RefPtrWillBeRawPtr<InspectorBackendDispatcher> protect(this); 314 RefPtrWillBeRawPtr<InspectorBackendDispatcher> protect(this);
293 typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, JSO NObject* messageObject, JSONArray* protocolErrors); 315 int callId = 0;
294 typedef HashMap<String, CallHandler> DispatchMap; 316 RefPtr<JSONValue> parsedMessage = parseJSON(message);
295 DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, ); 317 ASSERT(parsedMessage);
296 long callId = 0; 318 RefPtr<JSONObject> messageObject = parsedMessage->asObject();
319 ASSERT(messageObject);
297 320
298 if (dispatchMap.isEmpty()) { 321 RefPtr<JSONValue> callIdValue = messageObject->get("id");
299 static const CallHandler handlers[] = { 322 bool success = callIdValue->asNumber(&callId);
300 $messageHandlers 323 ASSERT_UNUSED(success, success);
301 };
302 for (size_t i = 0; i < kMethodNamesEnumSize; ++i)
303 dispatchMap.add(commandName(static_cast<MethodNames>(i)), handlers[i ]);
304 }
305 324
306 RefPtr<JSONValue> parsedMessage = parseJSON(message); 325 RefPtr<JSONValue> methodValue = messageObject->get("method");
307 if (!parsedMessage) { 326 String method;
308 reportProtocolError(0, ParseError, "Message must be in JSON format"); 327 success = methodValue && methodValue->asString(&method);
328 ASSERT_UNUSED(success, success);
329
330 HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
331 if (it == m_dispatchMap.end()) {
332 reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't fou nd");
309 return; 333 return;
310 } 334 }
311 335
312 RefPtr<JSONObject> messageObject = parsedMessage->asObject();
313 if (!messageObject) {
314 reportProtocolError(0, InvalidRequest, "Message must be a JSONified obje ct");
315 return;
316 }
317
318 RefPtr<JSONValue> callIdValue = messageObject->get("id");
319 if (!callIdValue) {
320 reportProtocolError(0, InvalidRequest, "'id' property was not found");
321 return;
322 }
323
324 if (!callIdValue->asNumber(&callId)) {
325 reportProtocolError(0, InvalidRequest, "The type of 'id' property must b e number");
326 return;
327 }
328
329 RefPtr<JSONValue> methodValue = messageObject->get("method");
330 if (!methodValue) {
331 reportProtocolError(&callId, InvalidRequest, "'method' property wasn't f ound");
332 return;
333 }
334
335 String method;
336 if (!methodValue->asString(&method)) {
337 reportProtocolError(&callId, InvalidRequest, "The type of 'method' prope rty must be string");
338 return;
339 }
340
341 HashMap<String, CallHandler>::iterator it = dispatchMap.find(method);
342 if (it == dispatchMap.end()) {
343 reportProtocolError(&callId, MethodNotFound, "'" + method + "' wasn't fo und");
344 return;
345 }
346
347 RefPtr<JSONArray> protocolErrors = JSONArray::create(); 336 RefPtr<JSONArray> protocolErrors = JSONArray::create();
348 ((*this).*it->value)(callId, messageObject.get(), protocolErrors.get()); 337 ((*this).*it->value)(callId, messageObject.get(), protocolErrors.get());
349 } 338 }
350 339
351 void InspectorBackendDispatcherImpl::sendResponse(long callId, const ErrorString & invocationError, PassRefPtr<JSONValue> errorData, PassRefPtr<JSONObject> resul t) 340 void InspectorBackendDispatcherImpl::sendResponse(int callId, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData, PassRefPtr<JSONObject> result )
352 { 341 {
353 if (invocationError.length()) { 342 if (invocationError.length()) {
354 reportProtocolError(&callId, ServerError, invocationError, errorData); 343 reportProtocolError(callId, ServerError, invocationError, errorData);
355 return; 344 return;
356 } 345 }
357 346
358 RefPtr<JSONObject> responseMessage = JSONObject::create(); 347 RefPtr<JSONObject> responseMessage = JSONObject::create();
359 responseMessage->setNumber("id", callId); 348 responseMessage->setNumber("id", callId);
360 responseMessage->setObject("result", result); 349 responseMessage->setObject("result", result);
361 if (m_inspectorFrontendChannel) 350 if (m_inspectorFrontendChannel)
362 m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage.releas e()); 351 m_inspectorFrontendChannel->sendProtocolResponse(callId, responseMessage .release());
363 } 352 }
364 353
365 void InspectorBackendDispatcher::reportProtocolError(const long* const callId, C ommonErrorCode code, const String& errorMessage) const 354 void InspectorBackendDispatcher::reportProtocolError(int callId, CommonErrorCode code, const String& errorMessage) const
366 { 355 {
367 reportProtocolError(callId, code, errorMessage, PassRefPtr<JSONValue>()); 356 reportProtocolError(callId, code, errorMessage, PassRefPtr<JSONValue>());
368 } 357 }
369 358
370 void InspectorBackendDispatcherImpl::reportProtocolError(const long* const callI d, CommonErrorCode code, const String& errorMessage, PassRefPtr<JSONValue> data) const 359 void InspectorBackendDispatcherImpl::reportProtocolError(int callId, CommonError Code code, const String& errorMessage, PassRefPtr<JSONValue> data) const
371 { 360 {
372 DEFINE_STATIC_LOCAL(Vector<int>,s_commonErrors,);
373 if (!s_commonErrors.size()) {
374 s_commonErrors.insert(ParseError, -32700);
375 s_commonErrors.insert(InvalidRequest, -32600);
376 s_commonErrors.insert(MethodNotFound, -32601);
377 s_commonErrors.insert(InvalidParams, -32602);
378 s_commonErrors.insert(InternalError, -32603);
379 s_commonErrors.insert(ServerError, -32000);
380 }
381 ASSERT(code >=0); 361 ASSERT(code >=0);
382 ASSERT((unsigned)code < s_commonErrors.size()); 362 ASSERT((unsigned)code < m_commonErrors.size());
383 ASSERT(s_commonErrors[code]); 363 ASSERT(m_commonErrors[code]);
384 RefPtr<JSONObject> error = JSONObject::create(); 364 RefPtr<JSONObject> error = JSONObject::create();
385 error->setNumber("code", s_commonErrors[code]); 365 error->setNumber("code", m_commonErrors[code]);
386 error->setString("message", errorMessage); 366 error->setString("message", errorMessage);
387 ASSERT(error); 367 ASSERT(error);
388 if (data) 368 if (data)
389 error->setValue("data", data); 369 error->setValue("data", data);
390 RefPtr<JSONObject> message = JSONObject::create(); 370 RefPtr<JSONObject> message = JSONObject::create();
391 message->setObject("error", error); 371 message->setObject("error", error);
392 if (callId) 372 message->setNumber("id", callId);
393 message->setNumber("id", *callId);
394 else
395 message->setValue("id", JSONValue::null());
396 if (m_inspectorFrontendChannel) 373 if (m_inspectorFrontendChannel)
397 m_inspectorFrontendChannel->sendMessageToFrontend(message.release()); 374 m_inspectorFrontendChannel->sendProtocolResponse(callId, message.release ());
398 } 375 }
399 376
400 template<typename R, typename V, typename V0> 377 template<typename R, typename V, typename V0>
401 R InspectorBackendDispatcherImpl::getPropertyValueImpl(JSONObject* object, const char* name, bool* valueFound, JSONArray* protocolErrors, V0 initial_value, bool (*as_method)(JSONValue*, V*), const char* type_name) 378 R InspectorBackendDispatcherImpl::getPropertyValueImpl(JSONObject* object, const char* name, bool* valueFound, JSONArray* protocolErrors, V0 initial_value, bool (*as_method)(JSONValue*, V*), const char* type_name)
402 { 379 {
403 ASSERT(protocolErrors); 380 ASSERT(protocolErrors);
404 381
405 if (valueFound) 382 if (valueFound)
406 *valueFound = false; 383 *valueFound = false;
407 384
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 return false; 462 return false;
486 463
487 return true; 464 return true;
488 } 465 }
489 466
490 InspectorBackendDispatcher::CallbackBase::CallbackBase(PassRefPtrWillBeRawPtr<In spectorBackendDispatcherImpl> backendImpl, int id) 467 InspectorBackendDispatcher::CallbackBase::CallbackBase(PassRefPtrWillBeRawPtr<In spectorBackendDispatcherImpl> backendImpl, int id)
491 : m_backendImpl(backendImpl), m_id(id), m_alreadySent(false) {} 468 : m_backendImpl(backendImpl), m_id(id), m_alreadySent(false) {}
492 469
493 InspectorBackendDispatcher::CallbackBase::~CallbackBase() {} 470 InspectorBackendDispatcher::CallbackBase::~CallbackBase() {}
494 471
495 void InspectorBackendDispatcher::CallbackBase::trace(Visitor* visitor) 472 DEFINE_TRACE(InspectorBackendDispatcher::CallbackBase)
496 { 473 {
497 visitor->trace(m_backendImpl); 474 visitor->trace(m_backendImpl);
498 } 475 }
499 476
500 void InspectorBackendDispatcher::CallbackBase::sendFailure(const ErrorString& er ror) 477 void InspectorBackendDispatcher::CallbackBase::sendFailure(const ErrorString& er ror)
501 { 478 {
502 ASSERT(error.length()); 479 ASSERT(error.length());
503 sendIfActive(nullptr, error, PassRefPtr<JSONValue>()); 480 sendIfActive(nullptr, error, PassRefPtr<JSONValue>());
504 } 481 }
505 482
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 520
544 } // namespace blink 521 } // namespace blink
545 522
546 """) 523 """)
547 524
548 typebuilder_h = ( 525 typebuilder_h = (
549 """ 526 """
550 #ifndef InspectorTypeBuilder_h 527 #ifndef InspectorTypeBuilder_h
551 #define InspectorTypeBuilder_h 528 #define InspectorTypeBuilder_h
552 529
530 #include "core/CoreExport.h"
553 #include "platform/JSONValues.h" 531 #include "platform/JSONValues.h"
554 #include "wtf/Assertions.h" 532 #include "wtf/Assertions.h"
555 #include "wtf/PassRefPtr.h" 533 #include "wtf/PassRefPtr.h"
556 534
557 namespace blink { 535 namespace blink {
558 536
559 namespace TypeBuilder { 537 namespace TypeBuilder {
560 538
561 template<typename T> 539 template<typename T>
562 class OptOutput { 540 class OptOutput {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 struct ArrayItemHelper { 582 struct ArrayItemHelper {
605 typedef typename T::ItemTraits Traits; 583 typedef typename T::ItemTraits Traits;
606 }; 584 };
607 585
608 template<typename T> 586 template<typename T>
609 class Array : public JSONArrayBase { 587 class Array : public JSONArrayBase {
610 private: 588 private:
611 Array() { } 589 Array() { }
612 590
613 JSONArray* openAccessors() { 591 JSONArray* openAccessors() {
614 COMPILE_ASSERT(sizeof(JSONArray) == sizeof(Array<T>), cannot_cast); 592 static_assert(sizeof(JSONArray) == sizeof(Array<T>), "JSONArray should b e the same size as Array<T>");
615 return static_cast<JSONArray*>(static_cast<JSONArrayBase*>(this)); 593 return static_cast<JSONArray*>(static_cast<JSONArrayBase*>(this));
616 } 594 }
617 595
618 public: 596 public:
619 void addItem(PassRefPtr<T> value) 597 void addItem(PassRefPtr<T> value)
620 { 598 {
621 ArrayItemHelper<T>::Traits::pushRefPtr(this->openAccessors(), value); 599 ArrayItemHelper<T>::Traits::pushRefPtr(this->openAccessors(), value);
622 } 600 }
623 601
624 void addItem(T value) 602 void addItem(T value)
625 { 603 {
626 ArrayItemHelper<T>::Traits::pushRaw(this->openAccessors(), value); 604 ArrayItemHelper<T>::Traits::pushRaw(this->openAccessors(), value);
627 } 605 }
628 606
629 static PassRefPtr<Array<T> > create() 607 static PassRefPtr<Array<T> > create()
630 { 608 {
631 return adoptRef(new Array<T>()); 609 return adoptRef(new Array<T>());
632 } 610 }
633 611
634 static PassRefPtr<Array<T> > runtimeCast(PassRefPtr<JSONValue> value) 612 static PassRefPtr<Array<T> > runtimeCast(PassRefPtr<JSONValue> value)
635 { 613 {
636 RefPtr<JSONArray> array; 614 RefPtr<JSONArray> array;
637 bool castRes = value->asArray(&array); 615 bool castRes = value->asArray(&array);
638 ASSERT_UNUSED(castRes, castRes); 616 ASSERT_UNUSED(castRes, castRes);
639 #if $validatorIfdefName 617 #if $validatorIfdefName
640 assertCorrectValue(array.get()); 618 assertCorrectValue(array.get());
641 #endif // $validatorIfdefName 619 #endif // $validatorIfdefName
642 COMPILE_ASSERT(sizeof(Array<T>) == sizeof(JSONArray), type_cast_problem) ; 620 static_assert(sizeof(Array<T>) == sizeof(JSONArray), "Array<T> should be the same size as JSONArray");
643 return static_cast<Array<T>*>(static_cast<JSONArrayBase*>(array.get())); 621 return static_cast<Array<T>*>(static_cast<JSONArrayBase*>(array.get()));
644 } 622 }
645 623
646 void concat(PassRefPtr<Array<T> > array) 624 void concat(PassRefPtr<Array<T> > array)
647 { 625 {
648 return ArrayItemHelper<T>::Traits::concat(this->openAccessors(), array-> openAccessors()); 626 return ArrayItemHelper<T>::Traits::concat(this->openAccessors(), array-> openAccessors());
649 } 627 }
650 628
651 #if $validatorIfdefName 629 #if $validatorIfdefName
652 static void assertCorrectValue(JSONValue* value) 630 static void assertCorrectValue(JSONValue* value)
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 template<typename S> 790 template<typename S>
813 static void assertCorrectValue(JSONValue* value) { 791 static void assertCorrectValue(JSONValue* value) {
814 S::assertCorrectValue(value); 792 S::assertCorrectValue(value);
815 } 793 }
816 #endif // $validatorIfdefName 794 #endif // $validatorIfdefName
817 }; 795 };
818 }; 796 };
819 797
820 ${forwards} 798 ${forwards}
821 799
822 String getEnumConstantValue(int code); 800 CORE_EXPORT String getEnumConstantValue(int code);
823 801
824 ${typeBuilders} 802 ${typeBuilders}
825 } // namespace TypeBuilder 803 } // namespace TypeBuilder
826 804
827 805
828 } // namespace blink 806 } // namespace blink
829 807
830 #endif // !defined(InspectorTypeBuilder_h) 808 #endif // !defined(InspectorTypeBuilder_h)
831 809
832 """) 810 """)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 private: 870 private:
893 RefPtr<JSONObject> m_result; 871 RefPtr<JSONObject> m_result;
894 872
895 template<int STEP> Builder<STATE | STEP>& castState() 873 template<int STEP> Builder<STATE | STEP>& castState()
896 { 874 {
897 return *reinterpret_cast<Builder<STATE | STEP>*>(this); 875 return *reinterpret_cast<Builder<STATE | STEP>*>(this);
898 } 876 }
899 877
900 Builder(PassRefPtr</*%s*/JSONObject> ptr) 878 Builder(PassRefPtr</*%s*/JSONObject> ptr)
901 { 879 {
902 COMPILE_ASSERT(STATE == NoFieldsSet, builder_created_in_non_init_sta te); 880 static_assert(STATE == NoFieldsSet, "builder should not be created i n non-init state");
903 m_result = ptr; 881 m_result = ptr;
904 } 882 }
905 friend class %s; 883 friend class %s;
906 public: 884 public:
907 """) 885 """)
908 886
909 class_binding_builder_part_2 = (""" 887 class_binding_builder_part_2 = ("""
910 Builder<STATE | %s>& set%s(%s value) 888 Builder<STATE | %s>& set%s(%s value)
911 { 889 {
912 COMPILE_ASSERT(!(STATE & %s), property_%s_already_set); 890 static_assert(!(STATE & %s), "property %s should not be set yet");
913 m_result->set%s("%s", %s); 891 m_result->set%s("%s", %s);
914 return castState<%s>(); 892 return castState<%s>();
915 } 893 }
916 """) 894 """)
917 895
918 class_binding_builder_part_3 = (""" 896 class_binding_builder_part_3 = ("""
919 operator RefPtr<%s>& () 897 operator RefPtr<%s>& ()
920 { 898 {
921 COMPILE_ASSERT(STATE == AllFieldsSet, result_is_not_ready); 899 static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet") ;
922 COMPILE_ASSERT(sizeof(%s) == sizeof(JSONObject), cannot_cast); 900 static_assert(sizeof(%s) == sizeof(JSONObject), "%s should be the sa me size as JSONObject");
923 return *reinterpret_cast<RefPtr<%s>*>(&m_result); 901 return *reinterpret_cast<RefPtr<%s>*>(&m_result);
924 } 902 }
925 903
926 PassRefPtr<%s> release() 904 PassRefPtr<%s> release()
927 { 905 {
928 return RefPtr<%s>(*this).release(); 906 return RefPtr<%s>(*this).release();
929 } 907 }
930 }; 908 };
931 909
932 """) 910 """)
933 911
934 class_binding_builder_part_4 = ( 912 class_binding_builder_part_4 = (
935 """ static Builder<NoFieldsSet> create() 913 """ static Builder<NoFieldsSet> create()
936 { 914 {
937 return Builder<NoFieldsSet>(JSONObject::create()); 915 return Builder<NoFieldsSet>(JSONObject::create());
938 } 916 }
939 """) 917 """)
OLDNEW
« no previous file with comments | « core/inspector/CodeGeneratorInspector.py ('k') | core/inspector/CodeGeneratorInstrumentation.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698