Changeset 83171 in webkit
- Timestamp:
- Apr 7, 2011 7:16:56 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r83163 r83171 1 2011-04-06 Ilya Tikhonovsky <loislo@chromium.org> 2 3 Reviewed by Yury Semikhatsky. 4 5 Web Inspector: migrate Inspector protocol messages format to JSON-RPC. 6 https://bugs.webkit.org/show_bug.cgi?id=57957 7 8 There is not a significant difference between inspector messages spec and and JSON-RPC 2.0 messages spec. 9 Also JSON-RPC has a pretty clear specification for error descriptions which we haven't. 10 It was decided that we will use it. 11 12 the list of renames: 13 1) type-> /dev/null 14 2) domain + '.' + event => method // for events 15 3) domain + '.' + command => method // for requests 16 4) requestId => id // for responses 17 5) arguments => params // for requests 18 6) data => params // for events 19 7) body => result // for responses 20 21 protocolErrors and error properties will be converted to JSON-RPC error format. 22 The order of properties in messages also will be adjusted. 23 The only thing that looks unnecessary is jsonrpc property. 24 25 * inspector/protocol/console-agent-expected.txt: 26 * inspector/protocol/runtime-agent-expected.txt: 27 * inspector/report-API-errors-expected.txt: 28 * inspector/report-API-errors.html: 29 * inspector/report-protocol-errors-expected.txt: 30 * inspector/report-protocol-errors.html: 31 1 32 2011-04-07 Kent Tamura <tkent@chromium.org> 2 33 -
trunk/LayoutTests/inspector/protocol/console-agent-expected.txt
r82680 r83171 8 8 request: 9 9 { 10 method : "Console.disable" 10 11 id : <number> 11 domain : "Console"12 command : "disable"13 arguments : {14 }15 12 } 16 13 17 14 response: 18 15 { 19 requestId : <number> 16 result : { 17 } 18 id : <number> 20 19 } 21 20 … … 25 24 request: 26 25 { 26 method : "Console.enable" 27 27 id : <number> 28 domain : "Console"29 command : "enable"30 arguments : {31 }32 28 } 33 29 34 30 response: 35 31 { 36 requestId : <number> 37 body : { 32 result : { 38 33 expiredMessagesCount : 0 39 34 } 35 id : <number> 40 36 } 41 37 … … 45 41 request: 46 42 { 47 id : <number> 48 domain : "Runtime" 49 command : "evaluate" 50 arguments : { 43 method : "Runtime.evaluate" 44 params : { 51 45 expression : "console.info('test'); console.info('test')" 52 46 objectGroup : "test-group" 53 47 includeCommandLineAPI : false 54 48 } 49 id : <number> 55 50 } 56 51 57 52 event ConsoleAgent.consoleMessage 58 53 { 59 type : "event" 60 domain : "Console" 61 event : "consoleMessage" 62 data : { 54 method : "Console.consoleMessage" 55 params : { 63 56 messageObj : { 64 57 source : 3 … … 82 75 event ConsoleAgent.consoleMessageRepeatCountUpdated 83 76 { 84 type : "event" 85 domain : "Console" 86 event : "consoleMessageRepeatCountUpdated" 87 data : { 77 method : "Console.consoleMessageRepeatCountUpdated" 78 params : { 88 79 count : 2 89 80 } … … 92 83 response: 93 84 { 94 requestId : <number> 95 body : { 85 result : { 96 86 result : { 97 87 type : "undefined" … … 99 89 } 100 90 } 91 id : <number> 101 92 } 102 93 … … 106 97 request: 107 98 { 99 method : "Console.clearConsoleMessages" 108 100 id : <number> 109 domain : "Console"110 command : "clearConsoleMessages"111 arguments : {112 }113 101 } 114 102 115 103 event ConsoleAgent.consoleMessagesCleared 116 104 { 117 type : "event" 118 domain : "Console" 119 event : "consoleMessagesCleared" 120 data : { 121 } 105 method : "Console.consoleMessagesCleared" 122 106 } 123 107 124 108 response: 125 109 { 126 requestId : <number> 110 result : { 111 } 112 id : <number> 127 113 } 128 114 … … 132 118 request: 133 119 { 134 id : <number> 135 domain : "Console" 136 command : "setMonitoringXHREnabled" 137 arguments : { 120 method : "Console.setMonitoringXHREnabled" 121 params : { 138 122 enabled : true 139 123 } 124 id : <number> 140 125 } 141 126 142 127 response: 143 128 { 144 requestId : <number> 129 result : { 130 } 131 id : <number> 145 132 } 146 133 … … 150 137 request: 151 138 { 152 id : <number> 153 domain : "Console" 154 command : "setMonitoringXHREnabled" 155 arguments : { 139 method : "Console.setMonitoringXHREnabled" 140 params : { 156 141 enabled : false 157 142 } 143 id : <number> 158 144 } 159 145 160 146 response: 161 147 { 162 requestId : <number> 148 result : { 149 } 150 id : <number> 163 151 } 164 152 … … 168 156 request: 169 157 { 170 id : <number> 171 domain : "Console" 172 command : "addInspectedNode" 173 arguments : { 158 method : "Console.addInspectedNode" 159 params : { 174 160 nodeId : 1 175 161 } 162 id : <number> 176 163 } 177 164 178 165 response: 179 166 { 180 requestId : <number> 167 result : { 168 } 169 id : <number> 181 170 } 182 171 -
trunk/LayoutTests/inspector/protocol/runtime-agent-expected.txt
r82804 r83171 6 6 request: 7 7 { 8 id : <number> 9 domain : "Runtime" 10 command : "evaluate" 11 arguments : { 8 method : "Runtime.evaluate" 9 params : { 12 10 expression : "testObject" 13 11 objectGroup : "test" 14 12 includeCommandLineAPI : false 15 13 } 16 } 17 18 response: 19 { 20 requestId : <number> 21 body: {14 id : <number> 15 } 16 17 response: 18 { 19 result : { 22 20 result : { 23 21 objectId : <string> … … 27 25 } 28 26 } 27 id : <number> 29 28 } 30 29 … … 34 33 request: 35 34 { 36 id : <number> 37 domain : "Runtime" 38 command : "evaluate" 39 arguments : { 35 method : "Runtime.evaluate" 36 params : { 40 37 expression : "testObject" 41 38 objectGroup : "test" 42 39 } 43 } 44 45 response: 46 { 47 requestId : <number> 48 body: {40 id : <number> 41 } 42 43 response: 44 { 45 result : { 49 46 result : { 50 47 objectId : <string> … … 54 51 } 55 52 } 53 id : <number> 56 54 } 57 55 … … 61 59 request: 62 60 { 63 id : <number> 64 domain : "Runtime" 65 command : "evaluateOn" 66 arguments : { 61 method : "Runtime.evaluateOn" 62 params : { 67 63 objectId : <string> 68 64 expression : "this.assignedByEvaluateOn = "evaluateOn function works fine";" 69 65 } 70 } 71 72 response: 73 { 74 requestId : <number> 75 body: {66 id : <number> 67 } 68 69 response: 70 { 71 result : { 76 72 result : { 77 73 type : "undefined" … … 79 75 } 80 76 } 77 id : <number> 81 78 } 82 79 … … 86 83 request: 87 84 { 88 id : <number> 89 domain : "Runtime" 90 command : "setPropertyValue" 91 arguments : { 85 method : "Runtime.setPropertyValue" 86 params : { 92 87 objectId : <string> 93 88 propertyName : "assignedBySetPropertyValue" 94 89 expression : "true" 95 90 } 96 } 97 98 response: 99 { 100 requestId : <number> 91 id : <number> 92 } 93 94 response: 95 { 96 result : { 97 } 98 id : <number> 101 99 } 102 100 … … 106 104 request: 107 105 { 108 id : <number> 109 domain : "Runtime" 110 command : "setPropertyValue" 111 arguments : { 106 method : "Runtime.setPropertyValue" 107 params : { 112 108 objectId : <string> 113 109 propertyName : "removedBySetPropertyValue" 114 110 expression : "" 115 111 } 116 } 117 118 response: 119 { 120 requestId : <number> 112 id : <number> 113 } 114 115 response: 116 { 117 result : { 118 } 119 id : <number> 121 120 } 122 121 … … 126 125 request: 127 126 { 128 id : <number> 129 domain : "Runtime" 130 command : "getProperties" 131 arguments : { 127 method : "Runtime.getProperties" 128 params : { 132 129 objectId : <string> 133 130 ignoreHasOwnProperty : false 134 131 } 135 } 136 137 response: 138 { 139 requestId : <number> 140 body: {132 id : <number> 133 } 134 135 response: 136 { 137 result : { 141 138 result : { 142 139 0 : { … … 165 162 } 166 163 } 164 id : <number> 167 165 } 168 166 … … 172 170 request: 173 171 { 174 id : <number> 175 domain : "Runtime" 176 command : "releaseObject" 177 arguments : { 178 objectId : <string> 179 } 180 } 181 182 response: 183 { 184 requestId : <number> 172 method : "Runtime.releaseObject" 173 params : { 174 objectId : <string> 175 } 176 id : <number> 177 } 178 179 response: 180 { 181 result : { 182 } 183 id : <number> 185 184 } 186 185 … … 190 189 request: 191 190 { 192 id : <number> 193 domain : "Runtime" 194 command : "releaseObjectGroup" 195 arguments : { 191 method : "Runtime.releaseObjectGroup" 192 params : { 196 193 objectGroup : "test" 197 194 } 198 } 199 200 response: 201 { 202 requestId : <number> 195 id : <number> 196 } 197 198 response: 199 { 200 result : { 201 } 202 id : <number> 203 203 } 204 204 -
trunk/LayoutTests/inspector/report-API-errors-expected.txt
r82804 r83171 1 1 Tests that InspectorBackendStub is catching incorrect arguments. 2 2 3 Protocol Error: Invalid type of argument 'enabled' for 'ConsoleAgent.setMonitoringXHREnabled' call. It should be 'boolean' but it is 'number'.4 Protocol Error: Invalid number of arguments for 'ConsoleAgent.setMonitoringXHREnabled' call. It should have the next arguments '{"enabled":{"optional":false,"type":"boolean"}}'.5 Protocol Error: Optional callback argument for 'ConsoleAgent.setMonitoringXHREnabled' call should be a function but its type is 'string'.3 Protocol Error: Invalid type of argument 'enabled' for method 'ConsoleAgent.setMonitoringXHREnabled' call. It should be 'boolean' but it is 'number'. 4 Protocol Error: Invalid number of arguments for method 'ConsoleAgent.setMonitoringXHREnabled' call. It should have the next arguments '{"enabled":{"optional":false,"type":"boolean"}}'. 5 Protocol Error: Optional callback argument for method 'ConsoleAgent.setMonitoringXHREnabled' call should be a function but its type is 'string'. 6 6 Protocol Error: the message is for non-existing domain 'wrongDomain' 7 7 Protocol Error: Attempted to dispatch an unimplemented method 'Inspector.something-strange' -
trunk/LayoutTests/inspector/report-API-errors.html
r82804 r83171 19 19 RuntimeAgent.evaluate("true", "test", function(){}); 20 20 RuntimeAgent.evaluate("true", "test", undefined, function(){}); 21 InspectorBackend.dispatch('{" type": "event", "domain": "wrongDomain", "event": "something-strange", "data": {}}');22 InspectorBackend.dispatch('{" type": "event", "domain": "Inspector", "event": "something-strange", "data": {}}');21 InspectorBackend.dispatch('{"method": "wrongDomain.something-strange", "params": {}}'); 22 InspectorBackend.dispatch('{"method": "Inspector.something-strange", "params": {}}'); 23 23 24 24 InspectorTest.completeTest(); -
trunk/LayoutTests/inspector/report-protocol-errors-expected.txt
r82804 r83171 2 2 3 3 { 4 requestId : 0 5 protocolErrors : { 6 0 : "Protocol Error: Invalid message format. Message should be in JSON format." 4 error : { 5 code : -32700 6 message : "Parse error." 7 data : { 8 0 : "Message should be in JSON format." 9 } 7 10 } 11 id : 0 8 12 } 9 13 { 10 requestId : 0 11 protocolErrors : { 12 0 : "Protocol Error: Invalid message format. 'command' property wasn't found." 14 error : { 15 code : -32600 16 message : "Invalid Request." 17 data : { 18 0 : "Invalid message format. 'method' property wasn't found." 19 } 13 20 } 21 id : 0 14 22 } 15 23 { 16 requestId : 0 17 protocolErrors : { 18 0 : "Protocol Error: Invalid message format. The type of 'command' property should be string." 24 error : { 25 code : -32600 26 message : "Invalid Request." 27 data : { 28 0 : "Invalid message format. The type of 'method' property should be string." 29 } 19 30 } 31 id : 0 20 32 } 21 33 { 22 requestId : 0 23 protocolErrors : { 24 0 : "Protocol Error: Invalid message format. 'id' property was not found in the request." 34 error : { 35 code : -32600 36 message : "Invalid Request." 37 data : { 38 0 : "Invalid message format. 'id' property was not found in the request." 39 } 25 40 } 41 id : 0 26 42 } 27 43 { 28 requestId : 0 29 protocolErrors : { 30 0 : "Protocol Error: Invalid message format. The type of 'id' property should be number." 44 error : { 45 code : -32600 46 message : "Invalid Request." 47 data : { 48 0 : "Invalid message format. The type of 'id' property should be number." 49 } 31 50 } 51 id : 0 32 52 } 33 53 { 34 requestId : 1 35 protocolErrors : { 36 0 : "Protocol Error: Invalid command was received. 'test' wasn't found in domain DOM." 54 error : { 55 code : -32601 56 message : "Method not found." 57 data : { 58 0 : "Invalid method name was received. 'DOM.test' wasn't found." 59 } 37 60 } 61 id : 1 38 62 } 39 63 { 40 requestId : 2 41 protocolErrors : { 42 0 : "Protocol Error: 'arguments' property with type 'object' was not found." 64 error : { 65 code : -32602 66 message : "Invalid params." 67 data : { 68 0 : "'params' property with type 'object' was not found." 69 } 43 70 } 71 id : 2 44 72 } 45 73 { 46 requestId : 3 47 protocolErrors : { 48 0 : "Protocol Error: 'arguments' property with type 'object' was not found." 74 error : { 75 code : -32602 76 message : "Invalid params." 77 data : { 78 0 : "'params' property with type 'object' was not found." 79 } 49 80 } 81 id : 3 50 82 } 51 83 { 52 requestId : 4 53 protocolErrors : { 54 0 : "Protocol Error: Argument 'frameId' with type 'String' was not found." 55 1 : "Protocol Error: Argument 'url' with type 'String' was not found." 84 error : { 85 code : -32602 86 message : "Invalid params." 87 data : { 88 0 : "Parameter 'frameId' with type 'String' was not found." 89 1 : "Parameter 'url' with type 'String' was not found." 90 } 56 91 } 92 id : 4 57 93 } 58 94 { 59 requestId : 5 60 protocolErrors : { 61 0 : "Protocol Error: Argument 'url' with type 'String' was not found." 95 error : { 96 code : -32602 97 message : "Invalid params." 98 data : { 99 0 : "Parameter 'url' with type 'String' was not found." 100 } 62 101 } 102 id : 5 63 103 } 64 104 -
trunk/LayoutTests/inspector/report-protocol-errors.html
r82804 r83171 9 9 'some wrong string', 10 10 '{}', 11 '{" command":1}',12 '{" domain":"Network","command":"resourceContent"}',13 '{"id":"not a number"," domain":"Network","command":"resourceContent"}',14 '{"id":1," domain":"DOM","command":"test"}',15 '{"id":2," domain":"Network","command":"getResourceContent"}',16 '{"id":3," domain":"Network","command":"getResourceContent","arguments":[]}',17 '{"id":4," domain":"Network","command":"getResourceContent","arguments":{}}',18 '{"id":5," domain":"Network","command":"getResourceContent","arguments":{"frameId":"not a number"}}',11 '{"method":1}', 12 '{"method":"resourceContent"}', 13 '{"id":"not a number","method":"Network.resourceContent"}', 14 '{"id":1,"method":"DOM.test"}', 15 '{"id":2,"method":"Network.getResourceContent"}', 16 '{"id":3,"method":"Network.getResourceContent","params":[]}', 17 '{"id":4,"method":"Network.getResourceContent","params":{}}', 18 '{"id":5,"method":"Network.getResourceContent","params":{"frameId":"not a number"}}', 19 19 ]; 20 20 var numberOfReports = 0; -
trunk/Source/WebCore/ChangeLog
r83165 r83171 1 2011-04-06 Ilya Tikhonovsky <loislo@chromium.org> 2 3 Reviewed by Yury Semikhatsky. 4 5 Web Inspector: migrate Inspector protocol messages format to JSON-RPC. 6 https://bugs.webkit.org/show_bug.cgi?id=57957 7 8 There is not a significant difference between inspector messages spec and and JSON-RPC 2.0 messages spec. 9 Also JSON-RPC has a pretty clear specification for error descriptions which we haven't. 10 It was decided that we will use it. 11 12 the list of renames: 13 1) type-> /dev/null 14 2) domain + '.' + event => method // for events 15 3) domain + '.' + command => method // for requests 16 4) requestId => id // for responses 17 5) arguments => params // for requests 18 6) data => params // for events 19 7) body => result // for responses 20 21 protocolErrors and error properties will be converted to JSON-RPC error format. 22 The order of properties in messages also will be adjusted. 23 The only thing that looks unnecessary is jsonrpc property. 24 25 * inspector/CodeGeneratorInspector.pm: 26 1 27 2011-04-07 Ryosuke Niwa <rniwa@webkit.org> 2 28 -
trunk/Source/WebCore/inspector/CodeGeneratorInspector.pm
r82810 r83171 192 192 "forward" => "", 193 193 "header" => "" 194 }; 195 $typeTransform{"Vector"} = { 196 "header" => "wtf/Vector.h" 194 197 }; 195 198 … … 370 373 push(@function, "{"); 371 374 push(@function, " RefPtr<InspectorObject> ${functionName}Message = InspectorObject::create();"); 372 push(@function, " ${functionName}Message->setString(\" type\", \"event\");");373 push(@function, " ${functionName}Message->setString(\"domain\", \"$domain\");");374 push(@function, " ${functionName}Message->setString(\"event\", \"$functionName\");");375 push(@function, " RefPtr<InspectorObject> dataObject = InspectorObject::create();");376 my @pushArguments = map(" dataObject->set" . typeTraits($_->type, "JSONType") . "(\"" . $_->name . "\", " . $_->name . ");", @argsFiltered);377 push(@function, @pushArguments);378 push(@function, " ${functionName}Message->setObject(\"data\", dataObject);");375 push(@function, " ${functionName}Message->setString(\"method\", \"$domain.$functionName\");"); 376 if (scalar(@argsFiltered)) { 377 push(@function, " RefPtr<InspectorObject> paramsObject = InspectorObject::create();"); 378 my @pushArguments = map(" paramsObject->set" . typeTraits($_->type, "JSONType") . "(\"" . $_->name . "\", " . $_->name . ");", @argsFiltered); 379 push(@function, @pushArguments); 380 push(@function, " ${functionName}Message->setObject(\"params\", paramsObject);"); 381 } 379 382 push(@function, " m_inspectorFrontendChannel->sendMessageToFrontend(${functionName}Message->toJSONString());"); 380 383 push(@function, "}"); … … 398 401 my $functionName = $function->signature->name; 399 402 my $fullQualifiedFunctionName = $interface->name . "_" . $function->signature->name; 403 my $fullQualifiedFunctionNameDot = $interface->name . "." . $function->signature->name; 400 404 401 405 push(@backendConstantDeclarations, " static const char* ${fullQualifiedFunctionName}Cmd;"); 402 push(@backendConstantDefinitions, "const char* ${backendClassName}::${fullQualifiedFunctionName}Cmd = \"${fullQualifiedFunctionName }\";");406 push(@backendConstantDefinitions, "const char* ${backendClassName}::${fullQualifiedFunctionName}Cmd = \"${fullQualifiedFunctionNameDot}\";"); 403 407 404 408 map($backendTypes{$_->type} = 1, @{$function->parameters}); # register required types 405 my @inArgs = grep($_->direction eq "in" && !($_->name eq "callId"), @{$function->parameters});409 my @inArgs = grep($_->direction eq "in", @{$function->parameters}); 406 410 my @outArgs = grep($_->direction eq "out", @{$function->parameters}); 407 411 … … 423 427 $backendDomains{$domain} = 1; 424 428 push(@function, " if (!$domainAccessor)"); 425 push(@function, " protocolErrors->pushString(\" Protocol Error:$domain handler is not available.\");");429 push(@function, " protocolErrors->pushString(\"$domain handler is not available.\");"); 426 430 push(@function, ""); 427 431 428 432 # declare local variables for out arguments. 429 push(@function, map(" " . typeTraits($_->type, "variable") . " out_" . $_->name . " = " . typeTraits($_->type, "defaultValue") . ";", @outArgs)); 430 push(@function, ""); 433 if (scalar(@outArgs)) { 434 push(@function, map(" " . typeTraits($_->type, "variable") . " out_" . $_->name . " = " . typeTraits($_->type, "defaultValue") . ";", @outArgs)); 435 push(@function, ""); 436 } 431 437 push(@function, " ErrorString error;"); 432 438 push(@function, ""); … … 434 440 my $indent = ""; 435 441 if (scalar(@inArgs)) { 436 push(@function, " if (RefPtr<InspectorObject> argumentsContainer = requestMessageObject->getObject(\"arguments\")) {");442 push(@function, " if (RefPtr<InspectorObject> paramsContainer = requestMessageObject->getObject(\"params\")) {"); 437 443 438 444 foreach my $parameter (@inArgs) { … … 441 447 my $typeString = camelCase($parameter->type); 442 448 my $optional = $parameter->extendedAttributes->{"optional"} ? "true" : "false"; 443 push(@function, " " . typeTraits($type, "variable") . " in_$name = get$typeString( argumentsContainer.get(), \"$name\", $optional, protocolErrors.get());");449 push(@function, " " . typeTraits($type, "variable") . " in_$name = get$typeString(paramsContainer.get(), \"$name\", $optional, protocolErrors.get());"); 444 450 } 445 451 push(@function, ""); … … 456 462 push(@function, "$indent $domainAccessor->$functionName($args);"); 457 463 if (scalar(@inArgs)) { 458 push(@function, " } else {");459 push(@function, " protocolErrors->pushString(\" Protocol Error: 'arguments' property with type 'object' was not found.\");");460 push(@function, " }");461 } 462 464 push(@function, " } else"); 465 push(@function, " protocolErrors->pushString(\"'params' property with type 'object' was not found.\");"); 466 } 467 468 push(@function, ""); 463 469 push(@function, " // use InspectorFrontend as a marker of WebInspector availability"); 464 push(@function, " if (callId || protocolErrors->length()) {");465 push(@function, " RefPtr<InspectorObject> responseMessage = InspectorObject::create();");466 push(@function, " responseMessage->setNumber(\"requestId\", callId);");467 470 push(@function, ""); 468 push(@function, " if (protocolErrors->length())"); 469 push(@function, " responseMessage->setArray(\"protocolErrors\", protocolErrors);"); 470 if (scalar(@outArgs)) { 471 push(@function, " else {"); 472 push(@function, " if (error.length())"); 473 push(@function, " responseMessage->setString(\"error\", error);"); 474 push(@function, " RefPtr<InspectorObject> responseBody = InspectorObject::create();"); 475 push(@function, map(" responseBody->set" . typeTraits($_->type, "JSONType") . "(\"" . $_->name . "\", out_" . $_->name . ");", @outArgs)); 476 push(@function, " responseMessage->setObject(\"body\", responseBody);"); 477 push(@function, " }"); 478 } 479 push(@function, " m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage->toJSONString());"); 471 push(@function, " if (protocolErrors->length()) {"); 472 push(@function, " reportProtocolError(callId, InvalidParams, protocolErrors);"); 473 push(@function, " return;"); 480 474 push(@function, " }"); 481 482 475 push(@function, ""); 476 push(@function, " if (error.length()) {"); 477 push(@function, " reportProtocolError(callId, ServerError, error);"); 478 push(@function, " return;"); 479 push(@function, " }"); 480 push(@function, ""); 481 push(@function, " RefPtr<InspectorObject> responseMessage = InspectorObject::create();"); 482 push(@function, " RefPtr<InspectorObject> result = InspectorObject::create();"); 483 push(@function, map(" result->set" . typeTraits($_->type, "JSONType") . "(\"" . $_->name . "\", out_" . $_->name . ");", @outArgs)); 484 push(@function, " responseMessage->setObject(\"result\", result);"); 485 push(@function, ""); 486 push(@function, " responseMessage->setNumber(\"id\", callId);"); 487 push(@function, " m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage->toJSONString());"); 483 488 push(@function, "}"); 484 489 push(@function, ""); … … 490 495 my $reportProtocolError = << "EOF"; 491 496 492 void ${backendClassName}::reportProtocolError(const long callId, const String& errorText) const 493 { 497 void ${backendClassName}::reportProtocolError(const long callId, CommonErrorCode code, const String& customText) const 498 { 499 RefPtr<InspectorArray> data = InspectorArray::create(); 500 data->pushString(customText); 501 reportProtocolError(callId, code, data.release()); 502 } 503 504 void ${backendClassName}::reportProtocolError(const long callId, CommonErrorCode code, PassRefPtr<InspectorArray> data) const 505 { 506 DEFINE_STATIC_LOCAL(Vector<String>,s_commonErrors,); 507 if (!s_commonErrors.size()) { 508 s_commonErrors.insert(ParseError, "{\\\"code\\\":-32700,\\\"message\\\":\\\"Parse error.\\\"}"); 509 s_commonErrors.insert(InvalidRequest, "{\\\"code\\\":-32600,\\\"message\\\":\\\"Invalid Request.\\\"}"); 510 s_commonErrors.insert(MethodNotFound, "{\\\"code\\\":-32601,\\\"message\\\":\\\"Method not found.\\\"}"); 511 s_commonErrors.insert(InvalidParams, "{\\\"code\\\":-32602,\\\"message\\\":\\\"Invalid params.\\\"}"); 512 s_commonErrors.insert(InternalError, "{\\\"code\\\":-32603,\\\"message\\\":\\\"Internal error.\\\"}"); 513 s_commonErrors.insert(ServerError, "{\\\"code\\\":-32000,\\\"message\\\":\\\"Server error.\\\"}"); 514 } 515 ASSERT(code >=0); 516 ASSERT((unsigned)code < s_commonErrors.size()); 517 ASSERT(s_commonErrors[code]); 518 ASSERT(InspectorObject::parseJSON(s_commonErrors[code])); 519 RefPtr<InspectorObject> error = InspectorObject::parseJSON(s_commonErrors[code])->asObject(); 520 ASSERT(error); 521 error->setArray("data", data); 494 522 RefPtr<InspectorObject> message = InspectorObject::create(); 495 message->setNumber("requestId", callId); 496 RefPtr<InspectorArray> errors = InspectorArray::create(); 497 errors->pushString(errorText); 498 message->setArray("protocolErrors", errors); 523 message->setObject("error", error); 524 message->setNumber("id", callId); 499 525 m_inspectorFrontendChannel->sendMessageToFrontend(message->toJSONString()); 500 526 } … … 526 552 if (valueIterator == end) { 527 553 if (!optional) 528 protocolErrors->pushString(String::format("P rotocol Error: Argument'\%s' with type '$json' was not found.", name.utf8().data()));554 protocolErrors->pushString(String::format("Parameter '\%s' with type '$json' was not found.", name.utf8().data())); 529 555 return value; 530 556 } 531 557 532 558 if (!valueIterator->second->as$json(&value)) 533 protocolErrors->pushString(String::format("P rotocol Error: Argument'\%s' has wrong type. It should be '$json'.", name.utf8().data()));559 protocolErrors->pushString(String::format("Parameter '\%s' has wrong type. It should be '$json'.", name.utf8().data())); 534 560 return value; 535 561 } … … 546 572 547 573 my $backendDispatcherBody = << "EOF"; 548 static String commandName(const String& domain, const String& command)549 {550 return makeString(domain, "_", command);551 }552 553 574 void ${backendClassName}::dispatch(const String& message) 554 575 { … … 564 585 RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message); 565 586 if (!parsedMessage) { 566 reportProtocolError(callId, "Protocol Error: Invalid message format.Message should be in JSON format.");587 reportProtocolError(callId, ParseError, "Message should be in JSON format."); 567 588 return; 568 589 } … … 570 591 RefPtr<InspectorObject> messageObject = parsedMessage->asObject(); 571 592 if (!messageObject) { 572 reportProtocolError(callId, "Protocol Error:Invalid message format. The message should be a JSONified object.");593 reportProtocolError(callId, InvalidRequest, "Invalid message format. The message should be a JSONified object."); 573 594 return; 574 595 } 575 596 576 RefPtr<InspectorValue> commandValue = messageObject->get("command");577 if (! commandValue) {578 reportProtocolError(callId, "Protocol Error: Invalid message format. 'command' property wasn't found.");597 RefPtr<InspectorValue> methodValue = messageObject->get("method"); 598 if (!methodValue) { 599 reportProtocolError(callId, InvalidRequest, "Invalid message format. 'method' property wasn't found."); 579 600 return; 580 601 } 581 602 582 String command; 583 if (!commandValue->asString(&command)) { 584 reportProtocolError(callId, "Protocol Error: Invalid message format. The type of 'command' property should be string."); 585 return; 586 } 587 588 RefPtr<InspectorValue> domainValue = messageObject->get("domain"); 589 if (!domainValue) { 590 reportProtocolError(callId, "Protocol Error: Invalid message format. 'domain' property wasn't found."); 591 return; 592 } 593 594 String domain; 595 if (!domainValue->asString(&domain)) { 596 reportProtocolError(callId, "Protocol Error: Invalid message format. The type of 'domain' property should be string."); 603 String method; 604 if (!methodValue->asString(&method)) { 605 reportProtocolError(callId, InvalidRequest, "Invalid message format. The type of 'method' property should be string."); 597 606 return; 598 607 } … … 600 609 RefPtr<InspectorValue> callIdValue = messageObject->get("id"); 601 610 if (!callIdValue) { 602 reportProtocolError(callId, "Protocol Error:Invalid message format. 'id' property was not found in the request.");611 reportProtocolError(callId, InvalidRequest, "Invalid message format. 'id' property was not found in the request."); 603 612 return; 604 613 } 605 614 606 615 if (!callIdValue->asNumber(&callId)) { 607 reportProtocolError(callId, "Protocol Error:Invalid message format. The type of 'id' property should be number.");616 reportProtocolError(callId, InvalidRequest, "Invalid message format. The type of 'id' property should be number."); 608 617 return; 609 618 } 610 619 611 HashMap<String, CallHandler>::iterator it = dispatchMap.find( commandName(domain, command));620 HashMap<String, CallHandler>::iterator it = dispatchMap.find(method); 612 621 if (it == dispatchMap.end()) { 613 reportProtocolError(callId, makeString("Protocol Error: Invalid command was received. '", command, "' wasn't found in domain ", domain, "."));622 reportProtocolError(callId, MethodNotFound, makeString("Invalid method name was received. '", method, "' wasn't found.")); 614 623 return; 615 624 } … … 634 643 return false; 635 644 636 String domain; 637 if (!object->getString("domain", &domain)) 645 if (!object->getString("method", result)) 638 646 return false; 639 647 640 String command;641 if (!object->getString("command", &command))642 return false;643 644 *result = commandName(domain, command);645 648 return true; 646 649 } … … 657 660 foreach my $function (@functions) { 658 661 my $name = $function->signature->name; 662 my @inArgs = grep($_->direction eq "in", @{$function->parameters}); 659 663 my $argumentNames = join( 660 664 ",", … … 663 667 . "\"type\": \"" . typeTraits($_->type, "JSType") . "\"" 664 668 . "}", 665 grep($_->direction eq "in", @{$function->parameters})));669 @inArgs)); 666 670 push(@backendJSStubs, " this._registerDelegate('{" . 667 "\"id\": 0, " . 668 "\"domain\": \"$domain\", " . 669 "\"command\": \"$name\", " . 670 "\"arguments\": {$argumentNames}" . 671 "\"method\": \"$domain.$name\", " . 672 (scalar(@inArgs) ? "\"params\": {$argumentNames}, " : "") . 673 "\"id\": 0" . 671 674 "}');"); 672 675 } … … 696 699 }, 697 700 698 _registerDelegate: function( commandInfo)701 _registerDelegate: function(requestString) 699 702 { 700 var commandObject = JSON.parse(commandInfo);701 var agentName = commandObject.domain+ "Agent";703 var domainAndFunction = JSON.parse(requestString).method.split("."); 704 var agentName = domainAndFunction[0] + "Agent"; 702 705 if (!window[agentName]) 703 706 window[agentName] = {}; 704 window[agentName][ commandObject.command] = this.sendMessageToBackend.bind(this, commandInfo);707 window[agentName][domainAndFunction[1]] = this.sendMessageToBackend.bind(this, requestString); 705 708 }, 706 709 … … 710 713 var request = JSON.parse(args.shift()); 711 714 var callback = (args.length && typeof args[args.length - 1] === "function") ? args.pop() : 0; 712 713 for (var key in request.arguments) { 714 var typeName = request.arguments[key].type; 715 var optionalFlag = request.arguments[key].optional; 716 717 if (args.length === 0 && !optionalFlag) { 718 console.error("Protocol Error: Invalid number of arguments for '" + request.domain + "Agent." + request.command + "' call. It should have the next arguments '" + JSON.stringify(request.arguments) + "'."); 719 return; 715 var domainAndMethod = request.method.split("."); 716 var agentMethod = domainAndMethod[0] + "Agent." + domainAndMethod[1]; 717 718 if (request.params) { 719 for (var key in request.params) { 720 var typeName = request.params[key].type; 721 var optionalFlag = request.params[key].optional; 722 723 if (args.length === 0 && !optionalFlag) { 724 console.error("Protocol Error: Invalid number of arguments for method '" + agentMethod + "' call. It should have the next arguments '" + JSON.stringify(request.params) + "'."); 725 return; 726 } 727 728 var value = args.shift(); 729 if (optionalFlag && typeof value === "undefined") { 730 delete request.params[key]; 731 continue; 732 } 733 734 if (typeof value !== typeName) { 735 console.error("Protocol Error: Invalid type of argument '" + key + "' for method '" + agentMethod + "' call. It should be '" + typeName + "' but it is '" + typeof value + "'."); 736 return; 737 } 738 739 request.params[key] = value; 720 740 } 721 722 var value = args.shift();723 if (optionalFlag && typeof value === "undefined") {724 delete request.arguments[key];725 continue;726 }727 728 if (typeof value !== typeName) {729 console.error("Protocol Error: Invalid type of argument '" + key + "' for '" + request.domain + "Agent." + request.command + "' call. It should be '" + typeName + "' but it is '" + typeof value + "'.");730 return;731 }732 733 request.arguments[key] = value;734 741 } 735 742 736 743 if (args.length === 1 && !callback) { 737 744 if (typeof args[0] !== "undefined") { 738 console.error("Protocol Error: Optional callback argument for '" + request.domain + "Agent." + request.command + "' call should be a function but its type is '" + typeof args[0] + "'.");745 console.error("Protocol Error: Optional callback argument for method '" + agentMethod + "' call should be a function but its type is '" + typeof args[0] + "'."); 739 746 return; 740 747 } … … 763 770 var messageObject = (typeof message === "string") ? JSON.parse(message) : message; 764 771 765 if (" requestId" in messageObject) { // just a response for some request766 if (messageObject. protocolErrors)772 if ("id" in messageObject) { // just a response for some request 773 if (messageObject.error && messageObject.error.code !== -32000) 767 774 this.reportProtocolError(messageObject); 768 775 769 776 var arguments = []; 770 if (messageObject. body) {771 for (var key in messageObject. body)772 arguments.push(messageObject. body[key]);777 if (messageObject.result) { 778 for (var key in messageObject.result) 779 arguments.push(messageObject.result[key]); 773 780 } 774 781 775 var callback = this._callbacks[messageObject. requestId];782 var callback = this._callbacks[messageObject.id]; 776 783 if (callback) { 777 if (!messageObject.protocolErrors) { 778 arguments.unshift(messageObject.error); 779 callback.apply(null, arguments); 780 } 784 arguments.unshift(messageObject.error); 785 callback.apply(null, arguments); 781 786 --this._pendingResponsesCount; 782 delete this._callbacks[messageObject. requestId];787 delete this._callbacks[messageObject.id]; 783 788 } 784 789 … … 787 792 788 793 return; 789 } 790 791 if (messageObject.type === "event") { 792 if (!(messageObject.domain in this._domainDispatchers)) { 793 console.error("Protocol Error: the message is for non-existing domain '" + messageObject.domain + "'"); 794 } else { 795 var method = messageObject.method.split("."); 796 var domainName = method[0]; 797 var functionName = method[1]; 798 if (!(domainName in this._domainDispatchers)) { 799 console.error("Protocol Error: the message is for non-existing domain '" + domainName + "'"); 794 800 return; 795 801 } 796 var dispatcher = this._domainDispatchers[ messageObject.domain];797 if (!( messageObject.eventin dispatcher)) {798 console.error("Protocol Error: Attempted to dispatch an unimplemented method '" + messageObject. domain + "." + messageObject.event+ "'");802 var dispatcher = this._domainDispatchers[domainName]; 803 if (!(functionName in dispatcher)) { 804 console.error("Protocol Error: Attempted to dispatch an unimplemented method '" + messageObject.method + "'"); 799 805 return; 800 806 } 801 807 802 var arguments = [];803 if (messageObject. data) {804 for (var key in messageObject. data)805 arguments.push(messageObject.data[key]);808 var params = []; 809 if (messageObject.params) { 810 for (var key in messageObject.params) 811 params.push(messageObject.params[key]); 806 812 } 807 813 808 dispatcher[ messageObject.event].apply(dispatcher, arguments);814 dispatcher[functionName].apply(dispatcher, params); 809 815 } 810 816 }, … … 812 818 reportProtocolError: function(messageObject) 813 819 { 814 console.error("Protocol Error: InspectorBackend request with id = " + messageObject.requestId + " failed."); 815 for (var i = 0; i < messageObject.protocolErrors.length; ++i) 816 console.error(" " + messageObject.protocolErrors[i]); 820 var error = messageObject.error; 821 console.error(error.message + "(" + error.code + "): request with id = " + messageObject.id + " failed."); 822 for (var i = 0; i < error.data.length; ++i) 823 console.error(" " + error.data[i]); 817 824 }, 818 825 … … 955 962 push(@backendHead, @fieldInitializers); 956 963 push(@backendHead, " { }"); 957 push(@backendHead, " void reportProtocolError(const long callId, const String& errorText) const;"); 964 push(@backendHead, ""); 965 push(@backendHead, " enum CommonErrorCode {"); 966 push(@backendHead, " ParseError = 0,"); 967 push(@backendHead, " InvalidRequest,"); 968 push(@backendHead, " MethodNotFound,"); 969 push(@backendHead, " InvalidParams,"); 970 push(@backendHead, " InternalError,"); 971 push(@backendHead, " ServerError,"); 972 push(@backendHead, " LastEntry,"); 973 push(@backendHead, " };"); 974 push(@backendHead, ""); 975 push(@backendHead, " void reportProtocolError(const long callId, CommonErrorCode, const String& errorText) const;"); 976 push(@backendHead, " void reportProtocolError(const long callId, CommonErrorCode, PassRefPtr<InspectorArray> data) const;"); 958 977 push(@backendHead, " void dispatch(const String& message);"); 959 978 push(@backendHead, " static bool getCommandName(const String& message, String* result);");
Note: See TracChangeset
for help on using the changeset viewer.