Title: [87146] trunk/Source
Revision
87146
Author
mnaga...@chromium.org
Date
2011-05-24 07:17:10 -0700 (Tue, 24 May 2011)

Log Message

2011-05-24  Mikhail Naganov  <mnaga...@chromium.org>

        Reviewed by Yury Semikhatsky.

        Web Inspector: Reorganize InspectorBackendDispatch code to eliminate duplication
        https://bugs.webkit.org/show_bug.cgi?id=61300

        * inspector/CodeGeneratorInspector.pm:

2011-05-24  Mikhail Naganov  <mnaga...@chromium.org>

        Reviewed by Yury Semikhatsky.

        Web Inspector: Reorganize InspectorBackendDispatch code to eliminate duplication
        https://bugs.webkit.org/show_bug.cgi?id=61300

        * src/WebDevToolsAgentImpl.cpp:
        (WebKit::WebDevToolsAgent::shouldInterruptForMessage):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (87145 => 87146)


--- trunk/Source/WebCore/ChangeLog	2011-05-24 12:38:13 UTC (rev 87145)
+++ trunk/Source/WebCore/ChangeLog	2011-05-24 14:17:10 UTC (rev 87146)
@@ -1,3 +1,12 @@
+2011-05-24  Mikhail Naganov  <mnaga...@chromium.org>
+
+        Reviewed by Yury Semikhatsky.
+
+        Web Inspector: Reorganize InspectorBackendDispatch code to eliminate duplication
+        https://bugs.webkit.org/show_bug.cgi?id=61300
+
+        * inspector/CodeGeneratorInspector.pm:
+
 2011-05-23  Yury Semikhatsky  <yu...@chromium.org>
 
         Reviewed by Adam Barth.

Modified: trunk/Source/WebCore/inspector/CodeGeneratorInspector.pm (87145 => 87146)


--- trunk/Source/WebCore/inspector/CodeGeneratorInspector.pm	2011-05-24 12:38:13 UTC (rev 87145)
+++ trunk/Source/WebCore/inspector/CodeGeneratorInspector.pm	2011-05-24 14:17:10 UTC (rev 87146)
@@ -416,11 +416,11 @@
     my $function = shift;
 
     my $functionName = $function->signature->name;
-    my $fullQualifiedFunctionName = $interface->name . "_" . $function->signature->name;
-    my $fullQualifiedFunctionNameDot = $interface->name . "." . $function->signature->name;
+    my $fullQualifiedFunctionName = $interface->name . "_" . $functionName;
+    my $fullQualifiedFunctionNameDot = $interface->name . "." . $functionName;
 
-    push(@backendConstantDeclarations, "    static const char* ${fullQualifiedFunctionName}Cmd;");
-    push(@backendConstantDefinitions, "const char* ${backendClassName}::${fullQualifiedFunctionName}Cmd = \"${fullQualifiedFunctionNameDot}\";");
+    push(@backendConstantDeclarations, "        k${fullQualifiedFunctionName}Cmd,");
+    push(@backendConstantDefinitions, "    \"${fullQualifiedFunctionNameDot}\",");
 
     map($backendTypes{$_->type} = 1, @{$function->parameters}); # register required types
     my @inArgs = grep($_->direction eq "in", @{$function->parameters});
@@ -457,13 +457,15 @@
     my $indent = "";
     if (scalar(@inArgs)) {
         push(@function, "    if (RefPtr<InspectorObject> paramsContainer = requestMessageObject->getObject(\"params\")) {");
+        push(@function, "        InspectorObject* paramsContainerPtr = paramsContainer.get();");
+        push(@function, "        InspectorArray* protocolErrorsPtr = protocolErrors.get();");
 
         foreach my $parameter (@inArgs) {
             my $name = $parameter->name;
             my $type = $parameter->type;
             my $typeString = camelCase($parameter->type);
             my $optional = $parameter->extendedAttributes->{"optional"} ? "true" : "false";
-            push(@function, "        " . typeTraits($type, "variable") . " in_$name = get$typeString(paramsContainer.get(), \"$name\", $optional, protocolErrors.get());");
+            push(@function, "        " . typeTraits($type, "variable") . " in_$name = get$typeString(paramsContainerPtr, \"$name\", $optional, protocolErrorsPtr);");
         }
         push(@function, "");
         $indent = "    ";
@@ -481,41 +483,52 @@
         push(@function, "    } else");
         push(@function, "        protocolErrors->pushString(\"'params' property with type 'object' was not found.\");");
     }
-
     push(@function, "");
-    push(@function, "    // use InspectorFrontend as a marker of WebInspector availability");
-    push(@function, "");
-    push(@function, "    if (protocolErrors->length()) {");
-    push(@function, "        reportProtocolError(&callId, InvalidParams, protocolErrors);");
-    push(@function, "        return;");
-    push(@function, "    }");
-    push(@function, "");
-    push(@function, "    if (error.length()) {");
-    push(@function, "        reportProtocolError(&callId, ServerError, error);");
-    push(@function, "        return;");
-    push(@function, "    }");
-    push(@function, "");
-    push(@function, "    RefPtr<InspectorObject> responseMessage = InspectorObject::create();");
     push(@function, "    RefPtr<InspectorObject> result = InspectorObject::create();");
-    foreach my $parameter (@outArgs) {
-        my $offset = "        ";
-        # Don't add optional boolean parameter to the result unless it is "true"
-        if ($parameter->extendedAttributes->{"optional"} && $parameter->type eq "boolean") {
-            push(@function, $offset . "if (out_" . $parameter->name . ")");
-            $offset .= "    ";
+    if (scalar(@outArgs)) {
+        push(@function, "    if (!protocolErrors->length() && !error.length()) {");
+        foreach my $parameter (@outArgs) {
+            my $offset = "        ";
+            # Don't add optional boolean parameter to the result unless it is "true"
+            if ($parameter->extendedAttributes->{"optional"} && $parameter->type eq "boolean") {
+                push(@function, $offset . "if (out_" . $parameter->name . ")");
+                $offset .= "    ";
+            }
+            push(@function, $offset . "result->set" . typeTraits($parameter->type, "JSONType") . "(\"" . $parameter->name . "\", out_" . $parameter->name . ");");
         }
-        push(@function, $offset . "result->set" . typeTraits($parameter->type, "JSONType") . "(\"" . $parameter->name . "\", out_" . $parameter->name . ");");
+        push(@function, "    }");
     }
-    push(@function, "    responseMessage->setObject(\"result\", result);");
-    push(@function, "");
-    push(@function, "    responseMessage->setNumber(\"id\", callId);");
-    push(@function, "    if (m_inspectorFrontendChannel)");
-    push(@function, "        m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage->toJSONString());");
+    push(@function, "    sendResponse(callId, result, protocolErrors, error);");
     push(@function, "}");
     push(@function, "");
     push(@backendMethodsImpl, @function);
 }
 
+sub generateBackendSendResponse
+{
+    my $sendResponse = << "EOF";
+
+void ${backendClassName}::sendResponse(long callId, PassRefPtr<InspectorObject> result, PassRefPtr<InspectorArray> protocolErrors, ErrorString invocationError)
+{
+    if (protocolErrors->length()) {
+        reportProtocolError(&callId, InvalidParams, protocolErrors);
+        return;
+    }
+    if (invocationError.length()) {
+        reportProtocolError(&callId, ServerError, invocationError);
+        return;
+    }
+
+    RefPtr<InspectorObject> responseMessage = InspectorObject::create();
+    responseMessage->setObject("result", result);
+    responseMessage->setNumber("id", callId);
+    if (m_inspectorFrontendChannel)
+        m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage->toJSONString());
+}    
+EOF
+    return split("\n", $sendResponse);
+}
+
 sub generateBackendReportProtocolError
 {
     my $reportProtocolError = << "EOF";
@@ -567,7 +580,7 @@
     my $return  = typeTraits($type, "return") ? typeTraits($type, "return") : typeTraits($type, "param");
 
     my $typeString = camelCase($type);
-    push(@backendConstantDeclarations, "    $return get$typeString(InspectorObject* object, const String& name, bool optional, InspectorArray* protocolErrors);");
+    push(@backendConstantDeclarations, "    static $return get$typeString(InspectorObject* object, const String& name, bool optional, InspectorArray* protocolErrors);");
     my $getterBody = << "EOF";
 
 $return InspectorBackendDispatcher::get$typeString(InspectorObject* object, const String& name, bool optional, InspectorArray* protocolErrors)
@@ -597,7 +610,7 @@
 sub generateBackendDispatcher
 {
     my @body;
-    my @mapEntries = map("        dispatchMap.add(${_}Cmd, &${backendClassName}::$_);", map ($backendMethodSignatures{$_}, @backendMethods));
+    my @mapEntries = map("        &${backendClassName}::$_,", map ($backendMethodSignatures{$_}, @backendMethods));
     my $mapEntries = join("\n", @mapEntries);
 
     my $backendDispatcherBody = << "EOF";
@@ -610,7 +623,12 @@
     long callId = 0;
 
     if (dispatchMap.isEmpty()) {
+        static CallHandler handlers[] = {
 $mapEntries
+        };
+        size_t length = sizeof(commandNames) / sizeof(commandNames[0]);
+        for (size_t i = 0; i < length; ++i)
+            dispatchMap.add(commandNames[i], handlers[i]);
     }
 
     RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message);
@@ -1037,6 +1055,8 @@
     push(@backendHead, "    void reportProtocolError(const long* const callId, CommonErrorCode, PassRefPtr<InspectorArray> data) const;");
     push(@backendHead, "    void dispatch(const String& message);");
     push(@backendHead, "    static bool getCommandName(const String& message, String* result);");
+    push(@backendHead, "");
+    push(@backendHead, "    enum MethodNames {");
     $backendConstructor = join("\n", @backendHead);
 }
 
@@ -1045,6 +1065,7 @@
     my $object = shift;
 
     push(@backendMethodsImpl, generateBackendDispatcher());
+    push(@backendMethodsImpl, generateBackendSendResponse());
     push(@backendMethodsImpl, generateBackendReportProtocolError());
     unshift(@frontendMethodsImpl, generateFrontendConstructorImpl(), "");
 
@@ -1058,8 +1079,14 @@
     close($HEADER);
     undef($HEADER);
 
+    unshift(@backendConstantDefinitions, "const char* InspectorBackendDispatcher::commandNames[] = {");
+    push(@backendConstantDefinitions, "};");
+
     # Make dispatcher methods private on the backend.
+    push(@backendConstantDeclarations, "};");
     push(@backendConstantDeclarations, "");
+    push(@backendConstantDeclarations, "    static const char* commandNames[];");    
+    push(@backendConstantDeclarations, "");
     push(@backendConstantDeclarations, "private:");
 
     foreach my $type (keys %backendTypes) {
@@ -1067,6 +1094,9 @@
             push(@backendMethodsImpl, generateArgumentGetters($type));
         }
     }
+
+    push(@backendConstantDeclarations, "    void sendResponse(long callId, PassRefPtr<InspectorObject> result, PassRefPtr<InspectorArray> protocolErrors, ErrorString invocationError);");
+
     generateBackendAgentFieldsAndConstructor();
 
     push(@backendMethodsImpl, generateBackendMessageParser());

Modified: trunk/Source/WebKit/chromium/ChangeLog (87145 => 87146)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-05-24 12:38:13 UTC (rev 87145)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-05-24 14:17:10 UTC (rev 87146)
@@ -1,3 +1,13 @@
+2011-05-24  Mikhail Naganov  <mnaga...@chromium.org>
+
+        Reviewed by Yury Semikhatsky.
+
+        Web Inspector: Reorganize InspectorBackendDispatch code to eliminate duplication
+        https://bugs.webkit.org/show_bug.cgi?id=61300
+
+        * src/WebDevToolsAgentImpl.cpp:
+        (WebKit::WebDevToolsAgent::shouldInterruptForMessage):
+
 2011-05-23  Gavin Peters  <gav...@chromium.org>
 
         Reviewed by Adam Barth.

Modified: trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.cpp (87145 => 87146)


--- trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.cpp	2011-05-24 12:38:13 UTC (rev 87145)
+++ trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.cpp	2011-05-24 14:17:10 UTC (rev 87146)
@@ -344,14 +344,14 @@
     String commandName;
     if (!InspectorBackendDispatcher::getCommandName(message, &commandName))
         return false;
-    return commandName == InspectorBackendDispatcher::Debugger_pauseCmd
-        || commandName == InspectorBackendDispatcher::Debugger_setBreakpointCmd
-        || commandName == InspectorBackendDispatcher::Debugger_setBreakpointByUrlCmd
-        || commandName == InspectorBackendDispatcher::Debugger_removeBreakpointCmd
-        || commandName == InspectorBackendDispatcher::Debugger_setBreakpointsActiveCmd
-        || commandName == InspectorBackendDispatcher::Profiler_startCmd
-        || commandName == InspectorBackendDispatcher::Profiler_stopCmd
-        || commandName == InspectorBackendDispatcher::Profiler_getProfileCmd;
+    return commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kDebugger_pauseCmd]
+        || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kDebugger_setBreakpointCmd]
+        || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kDebugger_setBreakpointByUrlCmd]
+        || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kDebugger_removeBreakpointCmd]
+        || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kDebugger_setBreakpointsActiveCmd]
+        || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kProfiler_startCmd]
+        || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kProfiler_stopCmd]
+        || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kProfiler_getProfileCmd];
 }
 
 void WebDevToolsAgent::processPendingMessages()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to