Changeset 65803 in webkit


Ignore:
Timestamp:
Aug 23, 2010 5:14:15 AM (14 years ago)
Author:
loislo@chromium.org
Message:

2010-08-23 Ilya Tikhonovsky <loislo@chromium.org>

Reviewed by Yury Semikhatsky.

WebInspector: inspector protocol should be switched from array based
message format to object based message format.
Almost all the protocol related things is generated by CodeGeneratorInspector.pm
It was changed a bit. As result InspectorBackendStub.js wraps the
calls into Request objects. InspectorBackendDispatcher.cpp unwraps
these objects and calls corresponding agents. These two files and
RemoteInspectorFrontend are generated by CodeGeneratorInspector.pm
Dispatching part of WebInspector also was adjusted for handling Event
objects produced by RemoteInspectorFrontend.cpp and Response objects
produced by InspectorBackendDispatcher.cpp
https://bugs.webkit.org/show_bug.cgi?id=44338

  • inspector/CodeGeneratorInspector.pm:
  • inspector/Inspector.idl:
  • inspector/InspectorController.cpp: (WebCore::InspectorController::setAttachedWindow):
  • inspector/InspectorController.h:
  • inspector/InspectorFrontendClientLocal.cpp: (WebCore::InspectorFrontendClientLocal::setAttachedWindow):
  • inspector/InspectorValues.h: (WebCore::InspectorObject::find):
  • inspector/front-end/Callback.js: (WebInspector.Callback.prototype.processResponse):
  • inspector/front-end/inspector.js: (WebInspector.dispatch): (WebInspector_syncDispatch): (WebInspector.dispatchMessageFromBackend): (WebInspector.reportProtocolError):
Location:
trunk/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r65802 r65803  
     12010-08-23  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Reviewed by Yury Semikhatsky.
     4
     5        WebInspector: inspector protocol should be switched from array based
     6        message format to object based message format.
     7        Almost all the protocol related things is generated by CodeGeneratorInspector.pm
     8        It was changed a bit. As result InspectorBackendStub.js wraps the
     9        calls into Request objects. InspectorBackendDispatcher.cpp unwraps
     10        these objects and calls corresponding agents. These two files and
     11        RemoteInspectorFrontend are generated by CodeGeneratorInspector.pm
     12        Dispatching part of WebInspector also was adjusted for handling Event
     13        objects produced by RemoteInspectorFrontend.cpp and Response objects
     14        produced by InspectorBackendDispatcher.cpp
     15        https://bugs.webkit.org/show_bug.cgi?id=44338
     16
     17        * inspector/CodeGeneratorInspector.pm:
     18        * inspector/Inspector.idl:
     19        * inspector/InspectorController.cpp:
     20        (WebCore::InspectorController::setAttachedWindow):
     21        * inspector/InspectorController.h:
     22        * inspector/InspectorFrontendClientLocal.cpp:
     23        (WebCore::InspectorFrontendClientLocal::setAttachedWindow):
     24        * inspector/InspectorValues.h:
     25        (WebCore::InspectorObject::find):
     26        * inspector/front-end/Callback.js:
     27        (WebInspector.Callback.prototype.processResponse):
     28        * inspector/front-end/inspector.js:
     29        (WebInspector.dispatch):
     30        (WebInspector_syncDispatch):
     31        (WebInspector.dispatchMessageFromBackend):
     32        (WebInspector.reportProtocolError):
     33
    1342010-08-23  Alejandro G. Castro  <alex@igalia.com>
    235
  • trunk/WebCore/inspector/CodeGeneratorInspector.pm

    r65797 r65803  
    1818    "forward" => "InspectorBackend",
    1919    "header" => "InspectorBackend.h",
    20     "handlerAccessor" => "m_inspectorController->inspectorBackend()",
     20    "domainAccessor" => "m_inspectorController->inspectorBackend()",
    2121};
    2222$typeTransform{"Controller"} = {
    2323    "forwardHeader" => "InspectorController.h",
    24     "handlerAccessor" => "m_inspectorController",
     24    "domainAccessor" => "m_inspectorController",
    2525};
    2626$typeTransform{"Debug"} = {
    2727    "forward" => "InspectorDebuggerAgent",
    2828    "header" => "InspectorDebuggerAgent.h",
    29     "handlerAccessor" => "m_inspectorController->debuggerAgent()",
     29    "domainAccessor" => "m_inspectorController->debuggerAgent()",
    3030};
    3131$typeTransform{"DOM"} = {
    3232    "forward" => "InspectorDOMAgent",
    3333    "header" => "InspectorDOMAgent.h",
    34     "handlerAccessor" => "m_inspectorController->domAgent()",
     34    "domainAccessor" => "m_inspectorController->domAgent()",
    3535};
    3636$typeTransform{"ApplicationCache"} = {
    3737    "forward" => "InspectorApplicationCacheAgent",
    3838    "header" => "InspectorApplicationCacheAgent.h",
    39     "handlerAccessor" => "m_inspectorController->applicationCacheAgent()",
     39    "domainAccessor" => "m_inspectorController->applicationCacheAgent()",
    4040};
    4141$typeTransform{"Profiler"} = {
    4242    "forward" => "InspectorProfilerAgent",
    4343    "header" => "InspectorProfilerAgent.h",
    44     "handlerAccessor" => "m_inspectorController->profilerAgent()",
     44    "domainAccessor" => "m_inspectorController->profilerAgent()",
    4545};
    4646$typeTransform{"Frontend"} = {
     
    5757    "forward" => "InspectorObject",
    5858    "header" => "InspectorValues.h",
    59     "accessorSuffix" => "Object"
     59    "JSONType" => "Object"
    6060};
    6161$typeTransform{"Array"} = {
     
    6565    "forward" => "InspectorArray",
    6666    "header" => "InspectorValues.h",
    67     "accessorSuffix" => "Array"
     67    "JSONType" => "Array"
    6868};
    6969$typeTransform{"Value"} = {
     
    7373    "forward" => "InspectorValue",
    7474    "header" => "InspectorValues.h",
    75     "accessorSuffix" => "Value"
     75    "JSONType" => "Value"
    7676};
    7777$typeTransform{"String"} = {
     
    8080    "forwardHeader" => "wtf/Forward.h",
    8181    "header" => "PlatformString.h",
    82     "accessorSuffix" => "String"
     82    "JSONType" => "String"
    8383};
    8484$typeTransform{"long"} = {
     
    8888    "forward" => "",
    8989    "header" => "",
    90     "accessorSuffix" => "Number"
     90    "JSONType" => "Number"
    9191};
    9292$typeTransform{"int"} = {
     
    9696    "forward" => "",
    9797    "header" => "",
    98     "accessorSuffix" => "Number",
     98    "JSONType" => "Number",
    9999};
    100100$typeTransform{"unsigned long"} = {
     
    104104    "forward" => "",
    105105    "header" => "",
    106     "accessorSuffix" => "Number"
     106    "JSONType" => "Number"
    107107};
    108108$typeTransform{"unsigned int"} = {
     
    112112    "forward" => "",
    113113    "header" => "",
    114     "accessorSuffix" => "Number"
     114    "JSONType" => "Number"
    115115};
    116116$typeTransform{"boolean"} = {
     
    120120    "forward" => "",
    121121    "header" => "",
    122     "accessorSuffix" => "Bool"
     122    "JSONType" => "Bool"
    123123};
    124124$typeTransform{"void"} = {
     
    162162my @frontendConstantDefinitions;
    163163my $frontendFooter;
    164 
    165 my $callId = new domSignature(); # it is just structure for describing parameters from IDLStructure.pm.
    166 $callId->type("long");
    167 $callId->name("callId");
    168164
    169165# Default constructor
     
    223219    $backendTypes{"InspectorClient"} = 1;
    224220    $backendTypes{"PassRefPtr"} = 1;
    225     $backendTypes{"Array"} = 1;
    226 
    227     push(@backendMethodsImpl, generateBackendPrivateFunctions());
     221    $backendTypes{"Object"} = 1;
     222
    228223    push(@backendMethodsImpl, generateBackendMessageParser());
    229224    generateFunctions($interface);
     
    260255    map($frontendTypes{$_->type} = 1, @argsFiltered); # register required types.
    261256    my $arguments = join(", ", map($typeTransform{$_->type}->{"param"} . " " . $_->name, @argsFiltered)); # prepare arguments for function signature.
    262     my @pushArguments = map("    arguments->push" . $typeTransform{$_->type}->{"accessorSuffix"} . "(" . $_->name . ");", @argsFiltered);
    263257
    264258    my $signature = "    void ${functionName}(${arguments});";
     
    269263        push(@function, "void ${frontendClassName}::${functionName}(${arguments})");
    270264        push(@function, "{");
    271         push(@function, "    RefPtr<InspectorArray> arguments = InspectorArray::create();");
    272         push(@function, "    arguments->pushString(\"$functionName\");");
     265        push(@function, "    RefPtr<InspectorObject> ${functionName}Message = InspectorObject::create();");
     266        push(@function, "    ${functionName}Message->setString(\"type\", \"event\");");
     267        push(@function, "    ${functionName}Message->setString(\"event\", \"$functionName\");");
     268        push(@function, "    RefPtr<InspectorObject> payloadDataObject = InspectorObject::create();");
     269        my @pushArguments = map("    payloadDataObject->set" . $typeTransform{$_->type}->{"JSONType"} . "(\"" . $_->name . "\", " . $_->name . ");", @argsFiltered);
    273270        push(@function, @pushArguments);
    274         push(@function, "    m_inspectorClient->sendMessageToFrontend(arguments->toJSONString());");
     271        push(@function, "    ${functionName}Message->setObject(\"data\", payloadDataObject);");
     272        push(@function, "    m_inspectorClient->sendMessageToFrontend(${functionName}Message->toJSONString());");
    275273
    276274        push(@function, "}");
     
    280278}
    281279
    282 sub generateBackendPrivateFunctions
    283 {
    284     my $privateFunctions = << "EOF";
    285 static String formatWrongArgumentsCountMessage(unsigned expected, unsigned actual)
    286 {
    287     return String::format("Wrong number of parameters: %d (expected: %d)", actual, expected);
    288 }
    289 
    290 static String formatWrongArgumentTypeMessage(unsigned position, const char* name, const char* expectedType)
    291 {
    292     return String::format("Failed to convert parameter %d (%s) to %s", position, name, expectedType);
    293 }
    294 EOF
    295     return split("\n", $privateFunctions);
    296 }
    297 
    298280sub generateBackendFunction
    299281{
     
    306288
    307289    map($backendTypes{$_->type} = 1, @{$function->parameters}); # register required types
    308     my @inArgs = grep($_->direction eq "in", @{$function->parameters});
     290    my @inArgs = grep($_->direction eq "in" && !($_->name eq "callId") , @{$function->parameters});
    309291    my @outArgs = grep($_->direction eq "out", @{$function->parameters});
    310292
    311     my $signature = "    void ${functionName}(PassRefPtr<InspectorArray> args);";
     293    my $signature = "    void ${functionName}(long callId, InspectorObject* requestMessageObject);";
    312294    !$backendMethods{${signature}} || die "Duplicate function was detected for signature '$signature'.";
    313295    $backendMethods{${signature}} = $functionName;
    314296
    315297    my @function;
    316     push(@function, "void ${backendClassName}::${functionName}(PassRefPtr<InspectorArray> args)");
     298    my $requestMessageObject = scalar(@inArgs) ? " requestMessageObject" : "";
     299    push(@function, "void ${backendClassName}::${functionName}(long callId, InspectorObject*$requestMessageObject)");
    317300    push(@function, "{");
    318     push(@function, "    long callId = 0;");
     301    push(@function, "    RefPtr<InspectorArray> protocolErrors = InspectorArray::create();");
    319302    push(@function, "");
    320303
    321     my $expectedParametersCount = scalar(@inArgs);
    322     my $expectedParametersCountWithMethodName = scalar(@inArgs) + 1;
    323     push(@function, "    if (args->length() != $expectedParametersCountWithMethodName) {");
    324     push(@function, "        ASSERT_NOT_REACHED();");
    325     push(@function, "        reportProtocolError(callId, ${functionName}Cmd, formatWrongArgumentsCountMessage(args->length() - 1, $expectedParametersCount));");
    326     push(@function, "        return;");
    327     push(@function, "    }");
     304    my $domain = $function->signature->extendedAttributes->{"handler"} || "Controller";
     305    my $domainAccessor = $typeTransform{$domain}->{"domainAccessor"};
     306    $backendTypes{$domain} = 1;
     307    push(@function, "    if (!$domainAccessor)");
     308    push(@function, "        protocolErrors->pushString(String::format(\"Error: %s handler is not available.\", \"$domain\"));");
    328309    push(@function, "");
    329310
    330     my $i = 1; # zero element is the method name.
    331     foreach my $parameter (@inArgs) {
    332         my $type = $parameter->type;
    333         my $argumentType = $typeTransform{$type}->{"variable"};
    334         push(@function, "    $argumentType " . $parameter->name . ";") if !($parameter->name eq "callId");
    335         push(@function, "    if (!args->get($i)->as" . $typeTransform{$type}->{"accessorSuffix"} . "(&" . $parameter->name . ")) {");
     311    if (scalar(@inArgs)) {
     312        # declare variables for all 'in' args;
     313        push(@function, map("    " . $typeTransform{$_->type}->{"variable"} . " " . $_->name . ";", @inArgs));
     314
     315        push(@function, "");
     316        push(@function, "    RefPtr<InspectorObject> argumentsContainer;");
     317        push(@function, "    if (!(argumentsContainer = requestMessageObject->getObject(\"arguments\"))) {");
    336318        push(@function, "        ASSERT_NOT_REACHED();");
    337         push(@function, "        reportProtocolError(callId, ${functionName}Cmd, formatWrongArgumentTypeMessage($i, \"" . $parameter->name . "\", \"$type\"));");
    338         push(@function, "        return;");
     319        push(@function, "        protocolErrors->pushString(String::format(\"Error: arguments object was not found.\"));");
     320        push(@function, "    } else {");
     321        push(@function, "        InspectorObject::const_iterator argumentsEndIterator = argumentsContainer->end();");
     322
     323        foreach my $parameter (@inArgs) {
     324            my $name = $parameter->name;
     325            my $type = $parameter->type;
     326            my $variableType = $typeTransform{$type}->{"variable"};
     327            my $JSONType = $typeTransform{$type}->{"JSONType"};
     328
     329            push(@function, "");
     330            push(@function, "        InspectorObject::const_iterator ${name}ValueIterator = argumentsContainer->find(\"$name\");");
     331            push(@function, "        if (${name}ValueIterator == argumentsEndIterator) {");
     332            push(@function, "            ASSERT_NOT_REACHED();");
     333            push(@function, "            protocolErrors->pushString(String::format(\"Error: Argument '%s' with type '%s' was not found.\", \"$name\", \"$JSONType\"));");
     334            push(@function, "        } else {");
     335            push(@function, "            if (!${name}ValueIterator->second->as$JSONType(&$name)) {");
     336            push(@function, "                ASSERT_NOT_REACHED();");
     337            push(@function, "                protocolErrors->pushString(String::format(\"Error: Argument '%s' has wrong type. It should be '%s'.\", \"$name\", \"$JSONType\"));");
     338            push(@function, "            }");
     339            push(@function, "        }");
     340        }
    339341        push(@function, "    }");
    340         push(@function, "");
    341         ++$i;
    342     }
    343 
    344     my $handler = $function->signature->extendedAttributes->{"handler"} || "Controller";
    345     my $handlerAccessor = $typeTransform{$handler}->{"handlerAccessor"};
    346     $backendTypes{$handler} = 1;
    347     push(@function, "    if (!$handlerAccessor) {");
    348     push(@function, "        reportProtocolError(callId, ${functionName}Cmd, \"Error: $handler handler is not available.\");");
    349     push(@function, "        return;");
    350     push(@function, "    }");
    351     push(@function, "");
    352 
     342    }
    353343
    354344    foreach (@outArgs) { # declare local variables for out arguments.
    355345        my $initializer = $typeTransform{$_->type}->{"defaultValue"} ? " = " . $typeTransform{$_->type}->{"defaultValue"} : "";
    356         push(@function, "    " . $typeTransform{$_->type}->{"variable"} . " " . $_->name . "$initializer;");
    357     }
    358 
    359     my $args = join(", ", (grep(!($_ eq "callId"), map($_->name, @inArgs)), map("&" . $_->name, @outArgs)));
    360     push(@function, "    $handlerAccessor->$functionName($args);");
    361 
    362     # The results of function call should be transfered back to frontend.
    363     if (scalar(grep($_->name eq "callId", @inArgs))) {
    364         my @pushArguments = map("        arguments->push" . $typeTransform{$_->type}->{"accessorSuffix"} . "(" . $_->name . ");", @outArgs);
    365 
    366         push(@function, "");
    367         push(@function, "    // use InspectorFrontend as a marker of WebInspector availability");
    368         push(@function, "    if (m_inspectorController->hasFrontend()) {");
    369         push(@function, "        RefPtr<InspectorArray> arguments = InspectorArray::create();");
    370         push(@function, "        arguments->pushString(\"processResponse\");");
    371         push(@function, "        arguments->pushNumber(callId);");
    372         push(@function, @pushArguments);
    373         push(@function, "        m_inspectorController->inspectorClient()->sendMessageToFrontend(arguments->toJSONString());");
    374         push(@function, "    }");
    375     }
     346        push(@function, "        " . $typeTransform{$_->type}->{"variable"} . " " . $_->name . "$initializer;");
     347    }
     348
     349    my $args = join(", ", (map($_->name, @inArgs), map("&" . $_->name, @outArgs)));
     350    push(@function, "    if (!protocolErrors->length())");
     351    push(@function, "        $domainAccessor->$functionName($args);");
     352    push(@function, "");
     353
     354    push(@function, "    // use InspectorFrontend as a marker of WebInspector availability");
     355    push(@function, "    if (callId && m_inspectorController->hasFrontend()) {");
     356    push(@function, "        RefPtr<InspectorObject> responseMessage = InspectorObject::create();");
     357    push(@function, "        responseMessage->setNumber(\"seq\", callId);");
     358    push(@function, "        responseMessage->setString(\"type\", \"response\");");
     359    push(@function, "        responseMessage->setString(\"domain\", \"$domain\");");
     360    push(@function, "        responseMessage->setString(\"command\", \"$functionName\");");
     361    push(@function, "        responseMessage->setBool(\"success\", !protocolErrors->length());");
     362    push(@function, "");
     363    push(@function, "        if (protocolErrors->length())");
     364    push(@function, "            responseMessage->setArray(\"errors\", protocolErrors);");
     365    if (scalar(@outArgs)) {
     366        push(@function, "        else {");
     367        push(@function, "            RefPtr<InspectorObject> responseData = InspectorObject::create();");
     368        push(@function, map("            responseData->set" . $typeTransform{$_->type}->{"JSONType"} . "(\"" . $_->name . "\", " . $_->name . ");", @outArgs));
     369        push(@function, "            responseMessage->setObject(\"data\", responseData);");
     370        push(@function, "        }");
     371    }
     372    push(@function, "        m_inspectorController->inspectorClient()->sendMessageToFrontend(responseMessage->toJSONString());");
     373    push(@function, "    }");
     374
     375
    376376    push(@function, "}");
    377377    push(@function, "");
     
    385385void ${backendClassName}::reportProtocolError(const long callId, const String& method, const String& errorText) const
    386386{
    387     RefPtr<InspectorArray> arguments = InspectorArray::create();
    388     arguments->pushString("reportProtocolError");
    389     arguments->pushNumber(callId);
    390     arguments->pushString(method);
    391     arguments->pushString(errorText);
    392     m_inspectorController->inspectorClient()->sendMessageToFrontend(arguments->toJSONString());
     387    RefPtr<InspectorObject> message = InspectorObject::create();
     388    message->setNumber("seq", callId);
     389    message->setString("type", "error");
     390    message->setString("domain", "inspectorProtocol");
     391    message->setString("command", method);
     392    message->setBool("success", false);
     393    RefPtr<InspectorArray> errors = InspectorArray::create();
     394    errors->pushString(errorText);
     395    message->setArray("errors", errors);
     396    m_inspectorController->inspectorClient()->sendMessageToFrontend(message->toJSONString());
    393397}
    394398EOF
    395399    return split("\n", $reportProtocolError);
    396400}
     401
    397402
    398403sub generateBackendDispatcher
     
    406411void ${backendClassName}::dispatch(const String& message)
    407412{
    408     typedef void (${backendClassName}::*CallHandler)(PassRefPtr<InspectorArray> args);
     413    typedef void (${backendClassName}::*CallHandler)(long callId, InspectorObject* messageObject);
    409414    typedef HashMap<String, CallHandler> DispatchMap;
    410415    DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, );
     416    long callId = 0;
     417
    411418    if (dispatchMap.isEmpty()) {
    412419$mapEntries
     
    416423    if (!parsedMessage) {
    417424        ASSERT_NOT_REACHED();
    418         reportProtocolError(0, "dispatch", "Error: Invalid message format. Message should be in JSON format.");
     425        reportProtocolError(callId, "dispatch", "Error: Invalid message format. Message should be in JSON format.");
    419426        return;
    420427    }
    421428
    422     RefPtr<InspectorArray> messageArray = parsedMessage->asArray();
    423     if (!messageArray) {
     429    RefPtr<InspectorObject> messageObject = parsedMessage->asObject();
     430    if (!messageObject) {
    424431        ASSERT_NOT_REACHED();
    425         reportProtocolError(0, "dispatch", "Error: Invalid message format. The message should be a JSONified array of arguments.");
     432        reportProtocolError(callId, "dispatch", "Error: Invalid message format. The message should be a JSONified object.");
    426433        return;
    427434    }
    428435
    429     if (!messageArray->length()) {
     436    RefPtr<InspectorValue> callIdValue = messageObject->get("seq");
     437    if (!callIdValue) {
    430438        ASSERT_NOT_REACHED();
    431         reportProtocolError(0, "dispatch", "Error: Invalid message format. Empty message was received.");
     439        reportProtocolError(callId, "dispatch", "Error: Invalid message format. 'seq' property was not found in the request.");
    432440        return;
    433441    }
    434442
    435     String methodName;
    436     if (!messageArray->get(0)->asString(&methodName)) {
     443    if (!callIdValue->asNumber(&callId)) {
    437444        ASSERT_NOT_REACHED();
    438         reportProtocolError(0, "dispatch", "Error: Invalid message format. The first element of the message should be method name.");
     445        reportProtocolError(callId, "dispatch", "Error: Invalid message format. the type of 'seq' property should be number.");
    439446        return;
    440447    }
    441448
    442     HashMap<String, CallHandler>::iterator it = dispatchMap.find(methodName);
     449    RefPtr<InspectorValue> commandValue = messageObject->get("command");
     450    if (!commandValue) {
     451        ASSERT_NOT_REACHED();
     452        reportProtocolError(callId, "dispatch", "Error: Invalid message format. 'command' property wasn't found.");
     453        return;
     454    }
     455
     456    String command;
     457    if (!commandValue->asString(&command)) {
     458        ASSERT_NOT_REACHED();
     459        reportProtocolError(callId, "dispatch", "Error: Invalid message format. The type of 'command' property should be string.");
     460        return;
     461    }
     462
     463    HashMap<String, CallHandler>::iterator it = dispatchMap.find(command);
    443464    if (it == dispatchMap.end()) {
    444465        ASSERT_NOT_REACHED();
    445         reportProtocolError(0, "dispatch", String::format("Error: Invalid method name. '%s' wasn't found.", methodName.utf8().data()));
     466        reportProtocolError(callId, "dispatch", String::format("Error: Invalid command was received. '%s' wasn't found.", command.utf8().data()));
    446467        return;
    447468    }
    448469
    449     ((*this).*it->second)(messageArray);
     470    ((*this).*it->second)(callId, messageObject.get());
    450471}
    451472EOF
     
    461482    if (!value)
    462483        return false;
    463     RefPtr<InspectorArray> array = value->asArray();
    464     if (!array)
     484
     485    RefPtr<InspectorObject> object = value->asObject();
     486    if (!object)
    465487        return false;
    466488
    467     if (!array->length())
     489    RefPtr<InspectorValue> commandValue = object->get("command");
     490    if (!commandValue)
    468491        return false;
    469     return array->get(0)->asString(result);
    470 }
     492
     493    return commandValue->asString(result);
     494}
     495
    471496EOF
    472497    return split("\n", $messageParserBody);
     
    477502    my $interface = shift;
    478503    my @backendFunctions = grep(!$_->signature->extendedAttributes->{"notify"}, @{$interface->functions});
    479     my @JSStubs = map("    this._registerDelegate(\"" . $_->signature->name . "\");", @backendFunctions);
     504    my @JSStubs;
     505
     506    foreach my $function (@backendFunctions) {
     507        my $name = $function->signature->name;
     508        my $domain = $function->signature->extendedAttributes->{"handler"};
     509        my $argumentNames = join(",", map("\"" . $_->name . "\": null", grep($_->direction eq "in", @{$function->parameters})));
     510        push(@JSStubs, "    this._registerDelegate('{" .
     511            "\"seq\": 0, " .
     512            "\"type\": \"request\", " .
     513            "\"domain\": \"$domain\", " .
     514            "\"command\": \"$name\", " .
     515            "\"arguments\": {$argumentNames}" .
     516        "}');");
     517    }
    480518
    481519    my $JSStubs = join("\n", @JSStubs);
     
    489527
    490528WebInspector.InspectorBackendStub.prototype = {
    491     _registerDelegate: function(methodName)
     529    _registerDelegate: function(commandInfo)
    492530    {
    493         this[methodName] = this.sendMessageToBackend.bind(this, methodName);
     531        var commandObject = JSON.parse(commandInfo);
     532        this[commandObject.command] = this.sendMessageToBackend.bind(this, commandInfo);
    494533    },
    495534
    496535    sendMessageToBackend: function()
    497536    {
    498         var message = JSON.stringify(Array.prototype.slice.call(arguments));
     537        var args = Array.prototype.slice.call(arguments);
     538        var request = JSON.parse(args.shift());
     539        for (var key in request.arguments) {
     540            if (key === "callId")
     541                request.seq = args.shift();
     542            else
     543                request.arguments[key] = args.shift();
     544        }
     545        if (args.length === 1 && typeof args[0] === "function")
     546            request.seq = WebInspector.Callback.wrap(args[0]);
     547
     548        var message = JSON.stringify(request);
    499549        InspectorFrontendHost.sendMessageToBackend(message);
    500550    }
  • trunk/WebCore/inspector/Inspector.idl

    r65797 r65803  
    5858        [notify] void searchingForNodeWasEnabled();
    5959        [notify] void searchingForNodeWasDisabled();
     60        [notify] void setAttachedWindow(out boolean attached);
    6061        [notify] void setChildNodes(out long parentId, out Array nodes);
    6162        [notify] void setDetachedRoot(out Object root);
  • trunk/WebCore/inspector/InspectorController.cpp

    r65797 r65803  
    421421}
    422422
     423void InspectorController::setAttachedWindow(bool attached)
     424{
     425    if (!m_remoteFrontend) {
     426        ASSERT_NOT_REACHED();
     427        return;
     428    }
     429    m_remoteFrontend->setAttachedWindow(attached);
     430}
     431
    423432void InspectorController::inspectedWindowScriptObjectCleared(Frame* frame)
    424433{
  • trunk/WebCore/inspector/InspectorController.h

    r65797 r65803  
    148148    void setInspectorFrontendClient(PassOwnPtr<InspectorFrontendClient> client);
    149149    bool hasInspectorFrontendClient() const { return m_inspectorFrontendClient; }
     150    void setAttachedWindow(bool attached);
    150151
    151152    void inspectedWindowScriptObjectCleared(Frame*);
  • trunk/WebCore/inspector/InspectorFrontendClientLocal.cpp

    r65053 r65803  
    122122void InspectorFrontendClientLocal::setAttachedWindow(bool attached)
    123123{
    124     ScriptObject webInspectorObj;
    125     if (!ScriptGlobalObject::get(m_frontendScriptState, "WebInspector", webInspectorObj)) {
    126         ASSERT_NOT_REACHED();
    127         return;
    128     }
    129     ScriptFunctionCall function(webInspectorObj, "dispatch");
    130     function.appendArgument("setAttachedWindow");
    131     function.appendArgument(attached);
    132     function.call();
     124    m_inspectorController->setAttachedWindow(attached);
    133125}
    134126
  • trunk/WebCore/inspector/InspectorValues.h

    r65320 r65803  
    177177    void setArray(const String& name, PassRefPtr<InspectorArray>);
    178178
     179    const_iterator find(const String& name) const;
    179180    bool getBool(const String& name, bool* output) const;
    180181    bool getNumber(const String& name, double* output) const;
     
    225226};
    226227
     228inline InspectorObject::const_iterator InspectorObject::find(const String& name) const
     229{
     230    return m_data.find(name);
     231}
     232
    227233inline void InspectorObject::setBool(const String& name, bool value)
    228234{
  • trunk/WebCore/inspector/front-end/Callback.js

    r65052 r65803  
    4343    },
    4444
    45     processResponse: function(callbackId, opt_vararg)
     45    processResponse: function(callbackId, args)
    4646    {
    47         var args = Array.prototype.slice.call(arguments, 1);
    4847        var callback = this._callbacks[callbackId];
    4948        callback.apply(null, args);
  • trunk/WebCore/inspector/front-end/inspector.js

    r65677 r65803  
    590590window.addEventListener("load", windowLoaded, false);
    591591
    592 WebInspector.dispatch = function() {
    593     var methodName = arguments[0];
    594     var parameters = Array.prototype.slice.call(arguments, 1);
    595 
     592WebInspector.dispatch = function(message) {
    596593    // We'd like to enforce asynchronous interaction between the inspector controller and the frontend.
    597594    // This is important to LayoutTests.
    598595    function delayDispatch()
    599596    {
    600         if (!(methodName in WebInspector)) {
    601             console.error("Attempted to dispatch unimplemented WebInspector method: %s", methodName);
    602             return;
    603         }
    604 
    605         WebInspector[methodName].apply(WebInspector, parameters);
     597        WebInspector_syncDispatch(message);
    606598        WebInspector.pendingDispatches--;
    607599    }
     
    613605WebInspector_syncDispatch = function(message)
    614606{
    615     var args = JSON.parse(message);
    616     var methodName = args[0];
    617     var parameters = args.slice(1);
    618     WebInspector[methodName].apply(WebInspector, parameters);
    619 }
    620 
    621 WebInspector.dispatchMessageFromBackend = function(arguments)
    622 {
    623     WebInspector.dispatch.apply(this, arguments);
    624 }
    625 
    626 WebInspector.reportProtocolError = function(callId, methodName, errorText)
    627 {
    628     console.error("InspectorBackend." + methodName + " failed with error text: '" + errorText + "'");
    629     WebInspector.removeResponseCallbackEntry(callId);
     607    var messageObject = (typeof message === "string") ? JSON.parse(message) : message;
     608    if (messageObject.type === "response" && !messageObject.success) {
     609        WebInspector.removeResponseCallbackEntry(messageObject.seq)
     610        WebInspector.reportProtocolError(messageObject);
     611        return;
     612    }
     613
     614    var arguments = [];
     615    if (messageObject.data)
     616        for (var key in messageObject.data)
     617            arguments.push(messageObject.data[key]);
     618
     619    if (messageObject.type === "event") {
     620        if (!messageObject.event in WebInspector) {
     621            console.error("Attempted to dispatch unimplemented WebInspector method: %s", messageObject.event);
     622            return;
     623        }
     624        WebInspector[messageObject.event].apply(WebInspector, arguments);
     625    }
     626
     627    if (messageObject.type === "response")
     628        WebInspector.processResponse(messageObject.seq, arguments);
     629}
     630
     631WebInspector.dispatchMessageFromBackend = function(messageObject)
     632{
     633    WebInspector.dispatch(messageObject);
     634}
     635
     636WebInspector.reportProtocolError = function(messageObject)
     637{
     638    console.error("Error: InspectorBackend." + messageObject.command + " failed.");
     639    for (var error in messageObject.errors)
     640        console.error("    " + error);
     641    WebInspector.removeResponseCallbackEntry(messageObject.seq);
    630642}
    631643
Note: See TracChangeset for help on using the changeset viewer.