Changeset 83171 in webkit


Ignore:
Timestamp:
Apr 7, 2011 7:16:56 AM (13 years ago)
Author:
loislo@chromium.org
Message:

2011-04-06 Ilya Tikhonovsky <loislo@chromium.org>

Reviewed by Yury Semikhatsky.

Web Inspector: migrate Inspector protocol messages format to JSON-RPC.
https://bugs.webkit.org/show_bug.cgi?id=57957

There is not a significant difference between inspector messages spec and and JSON-RPC 2.0 messages spec.
Also JSON-RPC has a pretty clear specification for error descriptions which we haven't.
It was decided that we will use it.

the list of renames:
1) type-> /dev/null
2) domain + '.' + event => method for events
3) domain + '.' + command => method
for requests
4) requestId => id for responses
5) arguments => params
for requests
6) data => params for events
7) body => result
for responses

protocolErrors and error properties will be converted to JSON-RPC error format.
The order of properties in messages also will be adjusted.
The only thing that looks unnecessary is jsonrpc property.

  • inspector/protocol/console-agent-expected.txt:
  • inspector/protocol/runtime-agent-expected.txt:
  • inspector/report-API-errors-expected.txt:
  • inspector/report-API-errors.html:
  • inspector/report-protocol-errors-expected.txt:
  • inspector/report-protocol-errors.html:

2011-04-06 Ilya Tikhonovsky <loislo@chromium.org>

Reviewed by Yury Semikhatsky.

Web Inspector: migrate Inspector protocol messages format to JSON-RPC.
https://bugs.webkit.org/show_bug.cgi?id=57957

There is not a significant difference between inspector messages spec and and JSON-RPC 2.0 messages spec.
Also JSON-RPC has a pretty clear specification for error descriptions which we haven't.
It was decided that we will use it.

the list of renames:
1) type-> /dev/null
2) domain + '.' + event => method for events
3) domain + '.' + command => method
for requests
4) requestId => id for responses
5) arguments => params
for requests
6) data => params for events
7) body => result
for responses

protocolErrors and error properties will be converted to JSON-RPC error format.
The order of properties in messages also will be adjusted.
The only thing that looks unnecessary is jsonrpc property.

  • inspector/CodeGeneratorInspector.pm:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r83163 r83171  
     12011-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
    1322011-04-07  Kent Tamura  <tkent@chromium.org>
    233
  • trunk/LayoutTests/inspector/protocol/console-agent-expected.txt

    r82680 r83171  
    88request:
    99{
     10    method : "Console.disable"
    1011    id : <number>
    11     domain : "Console"
    12     command : "disable"
    13     arguments : {
    14     }
    1512}
    1613
    1714response:
    1815{
    19     requestId : <number>
     16    result : {
     17    }
     18    id : <number>
    2019}
    2120
     
    2524request:
    2625{
     26    method : "Console.enable"
    2727    id : <number>
    28     domain : "Console"
    29     command : "enable"
    30     arguments : {
    31     }
    3228}
    3329
    3430response:
    3531{
    36     requestId : <number>
    37     body : {
     32    result : {
    3833        expiredMessagesCount : 0
    3934    }
     35    id : <number>
    4036}
    4137
     
    4541request:
    4642{
    47     id : <number>
    48     domain : "Runtime"
    49     command : "evaluate"
    50     arguments : {
     43    method : "Runtime.evaluate"
     44    params : {
    5145        expression : "console.info('test'); console.info('test')"
    5246        objectGroup : "test-group"
    5347        includeCommandLineAPI : false
    5448    }
     49    id : <number>
    5550}
    5651
    5752event ConsoleAgent.consoleMessage
    5853{
    59     type : "event"
    60     domain : "Console"
    61     event : "consoleMessage"
    62     data : {
     54    method : "Console.consoleMessage"
     55    params : {
    6356        messageObj : {
    6457            source : 3
     
    8275event ConsoleAgent.consoleMessageRepeatCountUpdated
    8376{
    84     type : "event"
    85     domain : "Console"
    86     event : "consoleMessageRepeatCountUpdated"
    87     data : {
     77    method : "Console.consoleMessageRepeatCountUpdated"
     78    params : {
    8879        count : 2
    8980    }
     
    9283response:
    9384{
    94     requestId : <number>
    95     body : {
     85    result : {
    9686        result : {
    9787            type : "undefined"
     
    9989        }
    10090    }
     91    id : <number>
    10192}
    10293
     
    10697request:
    10798{
     99    method : "Console.clearConsoleMessages"
    108100    id : <number>
    109     domain : "Console"
    110     command : "clearConsoleMessages"
    111     arguments : {
    112     }
    113101}
    114102
    115103event ConsoleAgent.consoleMessagesCleared
    116104{
    117     type : "event"
    118     domain : "Console"
    119     event : "consoleMessagesCleared"
    120     data : {
    121     }
     105    method : "Console.consoleMessagesCleared"
    122106}
    123107
    124108response:
    125109{
    126     requestId : <number>
     110    result : {
     111    }
     112    id : <number>
    127113}
    128114
     
    132118request:
    133119{
    134     id : <number>
    135     domain : "Console"
    136     command : "setMonitoringXHREnabled"
    137     arguments : {
     120    method : "Console.setMonitoringXHREnabled"
     121    params : {
    138122        enabled : true
    139123    }
     124    id : <number>
    140125}
    141126
    142127response:
    143128{
    144     requestId : <number>
     129    result : {
     130    }
     131    id : <number>
    145132}
    146133
     
    150137request:
    151138{
    152     id : <number>
    153     domain : "Console"
    154     command : "setMonitoringXHREnabled"
    155     arguments : {
     139    method : "Console.setMonitoringXHREnabled"
     140    params : {
    156141        enabled : false
    157142    }
     143    id : <number>
    158144}
    159145
    160146response:
    161147{
    162     requestId : <number>
     148    result : {
     149    }
     150    id : <number>
    163151}
    164152
     
    168156request:
    169157{
    170     id : <number>
    171     domain : "Console"
    172     command : "addInspectedNode"
    173     arguments : {
     158    method : "Console.addInspectedNode"
     159    params : {
    174160        nodeId : 1
    175161    }
     162    id : <number>
    176163}
    177164
    178165response:
    179166{
    180     requestId : <number>
     167    result : {
     168    }
     169    id : <number>
    181170}
    182171
  • trunk/LayoutTests/inspector/protocol/runtime-agent-expected.txt

    r82804 r83171  
    66request:
    77{
    8     id : <number>
    9     domain : "Runtime"
    10     command : "evaluate"
    11     arguments : {
     8    method : "Runtime.evaluate"
     9    params : {
    1210        expression : "testObject"
    1311        objectGroup : "test"
    1412        includeCommandLineAPI : false
    1513    }
    16 }
    17 
    18 response:
    19 {
    20     requestId : <number>
    21     body : {
     14    id : <number>
     15}
     16
     17response:
     18{
     19    result : {
    2220        result : {
    2321            objectId : <string>
     
    2725        }
    2826    }
     27    id : <number>
    2928}
    3029
     
    3433request:
    3534{
    36     id : <number>
    37     domain : "Runtime"
    38     command : "evaluate"
    39     arguments : {
     35    method : "Runtime.evaluate"
     36    params : {
    4037        expression : "testObject"
    4138        objectGroup : "test"
    4239    }
    43 }
    44 
    45 response:
    46 {
    47     requestId : <number>
    48     body : {
     40    id : <number>
     41}
     42
     43response:
     44{
     45    result : {
    4946        result : {
    5047            objectId : <string>
     
    5451        }
    5552    }
     53    id : <number>
    5654}
    5755
     
    6159request:
    6260{
    63     id : <number>
    64     domain : "Runtime"
    65     command : "evaluateOn"
    66     arguments : {
     61    method : "Runtime.evaluateOn"
     62    params : {
    6763        objectId : <string>
    6864        expression : "this.assignedByEvaluateOn = "evaluateOn function works fine";"
    6965    }
    70 }
    71 
    72 response:
    73 {
    74     requestId : <number>
    75     body : {
     66    id : <number>
     67}
     68
     69response:
     70{
     71    result : {
    7672        result : {
    7773            type : "undefined"
     
    7975        }
    8076    }
     77    id : <number>
    8178}
    8279
     
    8683request:
    8784{
    88     id : <number>
    89     domain : "Runtime"
    90     command : "setPropertyValue"
    91     arguments : {
     85    method : "Runtime.setPropertyValue"
     86    params : {
    9287        objectId : <string>
    9388        propertyName : "assignedBySetPropertyValue"
    9489        expression : "true"
    9590    }
    96 }
    97 
    98 response:
    99 {
    100     requestId : <number>
     91    id : <number>
     92}
     93
     94response:
     95{
     96    result : {
     97    }
     98    id : <number>
    10199}
    102100
     
    106104request:
    107105{
    108     id : <number>
    109     domain : "Runtime"
    110     command : "setPropertyValue"
    111     arguments : {
     106    method : "Runtime.setPropertyValue"
     107    params : {
    112108        objectId : <string>
    113109        propertyName : "removedBySetPropertyValue"
    114110        expression : ""
    115111    }
    116 }
    117 
    118 response:
    119 {
    120     requestId : <number>
     112    id : <number>
     113}
     114
     115response:
     116{
     117    result : {
     118    }
     119    id : <number>
    121120}
    122121
     
    126125request:
    127126{
    128     id : <number>
    129     domain : "Runtime"
    130     command : "getProperties"
    131     arguments : {
     127    method : "Runtime.getProperties"
     128    params : {
    132129        objectId : <string>
    133130        ignoreHasOwnProperty : false
    134131    }
    135 }
    136 
    137 response:
    138 {
    139     requestId : <number>
    140     body : {
     132    id : <number>
     133}
     134
     135response:
     136{
     137    result : {
    141138        result : {
    142139            0 : {
     
    165162        }
    166163    }
     164    id : <number>
    167165}
    168166
     
    172170request:
    173171{
    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
     179response:
     180{
     181    result : {
     182    }
     183    id : <number>
    185184}
    186185
     
    190189request:
    191190{
    192     id : <number>
    193     domain : "Runtime"
    194     command : "releaseObjectGroup"
    195     arguments : {
     191    method : "Runtime.releaseObjectGroup"
     192    params : {
    196193        objectGroup : "test"
    197194    }
    198 }
    199 
    200 response:
    201 {
    202     requestId : <number>
     195    id : <number>
     196}
     197
     198response:
     199{
     200    result : {
     201    }
     202    id : <number>
    203203}
    204204
  • trunk/LayoutTests/inspector/report-API-errors-expected.txt

    r82804 r83171  
    11Tests that InspectorBackendStub is catching incorrect arguments.
    22
    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'.
     3Protocol Error: Invalid type of argument 'enabled' for method 'ConsoleAgent.setMonitoringXHREnabled' call. It should be 'boolean' but it is 'number'.
     4Protocol Error: Invalid number of arguments for method 'ConsoleAgent.setMonitoringXHREnabled' call. It should have the next arguments '{"enabled":{"optional":false,"type":"boolean"}}'.
     5Protocol Error: Optional callback argument for method 'ConsoleAgent.setMonitoringXHREnabled' call should be a function but its type is 'string'.
    66Protocol Error: the message is for non-existing domain 'wrongDomain'
    77Protocol Error: Attempted to dispatch an unimplemented method 'Inspector.something-strange'
  • trunk/LayoutTests/inspector/report-API-errors.html

    r82804 r83171  
    1919    RuntimeAgent.evaluate("true", "test", function(){});
    2020    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": {}}');
    2323
    2424    InspectorTest.completeTest();
  • trunk/LayoutTests/inspector/report-protocol-errors-expected.txt

    r82804 r83171  
    22
    33{
    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        }
    710    }
     11    id : 0
    812}
    913{
    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        }
    1320    }
     21    id : 0
    1422}
    1523{
    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        }
    1930    }
     31    id : 0
    2032}
    2133{
    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        }
    2540    }
     41    id : 0
    2642}
    2743{
    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        }
    3150    }
     51    id : 0
    3252}
    3353{
    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        }
    3760    }
     61    id : 1
    3862}
    3963{
    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        }
    4370    }
     71    id : 2
    4472}
    4573{
    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        }
    4980    }
     81    id : 3
    5082}
    5183{
    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        }
    5691    }
     92    id : 4
    5793}
    5894{
    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        }
    62101    }
     102    id : 5
    63103}
    64104
  • trunk/LayoutTests/inspector/report-protocol-errors.html

    r82804 r83171  
    99        'some wrong string',
    1010        '{}',
    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"}}',
    1919    ];
    2020    var numberOfReports = 0;
  • trunk/Source/WebCore/ChangeLog

    r83165 r83171  
     12011-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
    1272011-04-07  Ryosuke Niwa  <rniwa@webkit.org>
    228
  • trunk/Source/WebCore/inspector/CodeGeneratorInspector.pm

    r82810 r83171  
    192192    "forward" => "",
    193193    "header" => ""
     194};
     195$typeTransform{"Vector"} = {
     196    "header" => "wtf/Vector.h"
    194197};
    195198
     
    370373    push(@function, "{");
    371374    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    }
    379382    push(@function, "    m_inspectorFrontendChannel->sendMessageToFrontend(${functionName}Message->toJSONString());");
    380383    push(@function, "}");
     
    398401    my $functionName = $function->signature->name;
    399402    my $fullQualifiedFunctionName = $interface->name . "_" . $function->signature->name;
     403    my $fullQualifiedFunctionNameDot = $interface->name . "." . $function->signature->name;
    400404
    401405    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}\";");
    403407
    404408    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});
    406410    my @outArgs = grep($_->direction eq "out", @{$function->parameters});
    407411   
     
    423427    $backendDomains{$domain} = 1;
    424428    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.\");");
    426430    push(@function, "");
    427431
    428432    # 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    }
    431437    push(@function, "    ErrorString error;");
    432438    push(@function, "");
     
    434440    my $indent = "";
    435441    if (scalar(@inArgs)) {
    436         push(@function, "    if (RefPtr<InspectorObject> argumentsContainer = requestMessageObject->getObject(\"arguments\")) {");
     442        push(@function, "    if (RefPtr<InspectorObject> paramsContainer = requestMessageObject->getObject(\"params\")) {");
    437443
    438444        foreach my $parameter (@inArgs) {
     
    441447            my $typeString = camelCase($parameter->type);
    442448            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());");
    444450        }
    445451        push(@function, "");
     
    456462    push(@function, "$indent        $domainAccessor->$functionName($args);");
    457463    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, "");
    463469    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);");
    467470    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;");
    480474    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());");
    483488    push(@function, "}");
    484489    push(@function, "");
     
    490495    my $reportProtocolError = << "EOF";
    491496
    492 void ${backendClassName}::reportProtocolError(const long callId, const String& errorText) const
    493 {
     497void ${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
     504void ${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);
    494522    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);
    499525    m_inspectorFrontendChannel->sendMessageToFrontend(message->toJSONString());
    500526}
     
    526552    if (valueIterator == end) {
    527553        if (!optional)
    528             protocolErrors->pushString(String::format("Protocol 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()));
    529555        return value;
    530556    }
    531557
    532558    if (!valueIterator->second->as$json(&value))
    533         protocolErrors->pushString(String::format("Protocol 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()));
    534560    return value;
    535561}
     
    546572
    547573    my $backendDispatcherBody = << "EOF";
    548 static String commandName(const String& domain, const String& command)
    549 {
    550     return makeString(domain, "_", command);
    551 }
    552 
    553574void ${backendClassName}::dispatch(const String& message)
    554575{
     
    564585    RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message);
    565586    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.");
    567588        return;
    568589    }
     
    570591    RefPtr<InspectorObject> messageObject = parsedMessage->asObject();
    571592    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.");
    573594        return;
    574595    }
    575596
    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.");
    579600        return;
    580601    }
    581602
    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.");
    597606        return;
    598607    }
     
    600609    RefPtr<InspectorValue> callIdValue = messageObject->get("id");
    601610    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.");
    603612        return;
    604613    }
    605614
    606615    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.");
    608617        return;
    609618    }
    610619
    611     HashMap<String, CallHandler>::iterator it = dispatchMap.find(commandName(domain, command));
     620    HashMap<String, CallHandler>::iterator it = dispatchMap.find(method);
    612621    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."));
    614623        return;
    615624    }
     
    634643        return false;
    635644
    636     String domain;
    637     if (!object->getString("domain", &domain))
     645    if (!object->getString("method", result))
    638646        return false;
    639647
    640     String command;
    641     if (!object->getString("command", &command))
    642         return false;
    643 
    644     *result = commandName(domain, command);
    645648    return true;
    646649}
     
    657660    foreach my $function (@functions) {
    658661        my $name = $function->signature->name;
     662        my @inArgs = grep($_->direction eq "in", @{$function->parameters});
    659663        my $argumentNames = join(
    660664            ",",
     
    663667                . "\"type\": \"" . typeTraits($_->type, "JSType") . "\""
    664668                . "}",
    665                 grep($_->direction eq "in", @{$function->parameters})));
     669                 @inArgs));
    666670        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" .
    671674        "}');");
    672675    }
     
    696699    },
    697700
    698     _registerDelegate: function(commandInfo)
     701    _registerDelegate: function(requestString)
    699702    {
    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";
    702705        if (!window[agentName])
    703706            window[agentName] = {};
    704         window[agentName][commandObject.command] = this.sendMessageToBackend.bind(this, commandInfo);
     707        window[agentName][domainAndFunction[1]] = this.sendMessageToBackend.bind(this, requestString);
    705708    },
    706709
     
    710713        var request = JSON.parse(args.shift());
    711714        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;
    720740            }
    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;
    734741        }
    735742
    736743        if (args.length === 1 && !callback) {
    737744            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] + "'.");
    739746                return;
    740747            }
     
    763770        var messageObject = (typeof message === "string") ? JSON.parse(message) : message;
    764771
    765         if ("requestId" in messageObject) { // just a response for some request
    766             if (messageObject.protocolErrors)
     772        if ("id" in messageObject) { // just a response for some request
     773            if (messageObject.error && messageObject.error.code !== -32000)
    767774                this.reportProtocolError(messageObject);
    768775
    769776            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]);
    773780            }
    774781
    775             var callback = this._callbacks[messageObject.requestId];
     782            var callback = this._callbacks[messageObject.id];
    776783            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);
    781786                --this._pendingResponsesCount;
    782                 delete this._callbacks[messageObject.requestId];
     787                delete this._callbacks[messageObject.id];
    783788            }
    784789
     
    787792
    788793            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 + "'");
    794800                return;
    795801            }
    796             var dispatcher = this._domainDispatchers[messageObject.domain];
    797             if (!(messageObject.event in 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 + "'");
    799805                return;
    800806            }
    801807
    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]);
    806812            }
    807813
    808             dispatcher[messageObject.event].apply(dispatcher, arguments);
     814            dispatcher[functionName].apply(dispatcher, params);
    809815        }
    810816    },
     
    812818    reportProtocolError: function(messageObject)
    813819    {
    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]);
    817824    },
    818825
     
    955962    push(@backendHead, @fieldInitializers);
    956963    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;");
    958977    push(@backendHead, "    void dispatch(const String& message);");
    959978    push(@backendHead, "    static bool getCommandName(const String& message, String* result);");
Note: See TracChangeset for help on using the changeset viewer.