Title: [101670] trunk/Source/WebCore
Revision
101670
Author
pfeld...@chromium.org
Date
2011-12-01 08:20:51 -0800 (Thu, 01 Dec 2011)

Log Message

Web Inspector: extract static part of the InspectorBackend from the generator.
https://bugs.webkit.org/show_bug.cgi?id=73562

Reviewed by Timothy Hatcher.

We should only generate the mapping between the command parameters and slots,
rest of the backend is static.

* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* inspector/CodeGeneratorInspector.py:
(Generator.go):
(Generator.process_event):
(Generator.process_command):
* inspector/compile-front-end.sh:
* inspector/front-end/InspectorBackend.js: Added.
(InspectorBackendClass):
(InspectorBackendClass.prototype.registerCommand):
(InspectorBackendClass.prototype.registerEvent):
(InspectorBackendClass.prototype._invoke):
(InspectorBackendClass.prototype._sendMessageToBackend):
(InspectorBackendClass.prototype._wrapCallbackAndSendMessageObject):
(InspectorBackendClass.prototype.sendMessageObjectToBackend):
(InspectorBackendClass.prototype.registerDomainDispatcher):
(InspectorBackendClass.prototype.dispatch.messageObject.error.__proto__.getDescription):
(InspectorBackendClass.prototype.dispatch.messageObject.error.__proto__.toString):
(InspectorBackendClass.prototype.dispatch.messageObject.error.__proto__.getMessage):
(InspectorBackendClass.prototype.dispatch):
(InspectorBackendClass.prototype.reportProtocolError):
(InspectorBackendClass.prototype.runAfterPendingDispatches):
* inspector/front-end/WebKit.qrc:
* inspector/front-end/inspector.html:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (101669 => 101670)


--- trunk/Source/WebCore/ChangeLog	2011-12-01 16:07:12 UTC (rev 101669)
+++ trunk/Source/WebCore/ChangeLog	2011-12-01 16:20:51 UTC (rev 101670)
@@ -1,3 +1,38 @@
+2011-12-01  Pavel Feldman  <pfeld...@google.com>
+
+        Web Inspector: extract static part of the InspectorBackend from the generator.
+        https://bugs.webkit.org/show_bug.cgi?id=73562
+
+        Reviewed by Timothy Hatcher.
+
+        We should only generate the mapping between the command parameters and slots,
+        rest of the backend is static.
+
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * inspector/CodeGeneratorInspector.py:
+        (Generator.go):
+        (Generator.process_event):
+        (Generator.process_command):
+        * inspector/compile-front-end.sh:
+        * inspector/front-end/InspectorBackend.js: Added.
+        (InspectorBackendClass):
+        (InspectorBackendClass.prototype.registerCommand):
+        (InspectorBackendClass.prototype.registerEvent):
+        (InspectorBackendClass.prototype._invoke):
+        (InspectorBackendClass.prototype._sendMessageToBackend):
+        (InspectorBackendClass.prototype._wrapCallbackAndSendMessageObject):
+        (InspectorBackendClass.prototype.sendMessageObjectToBackend):
+        (InspectorBackendClass.prototype.registerDomainDispatcher):
+        (InspectorBackendClass.prototype.dispatch.messageObject.error.__proto__.getDescription):
+        (InspectorBackendClass.prototype.dispatch.messageObject.error.__proto__.toString):
+        (InspectorBackendClass.prototype.dispatch.messageObject.error.__proto__.getMessage):
+        (InspectorBackendClass.prototype.dispatch):
+        (InspectorBackendClass.prototype.reportProtocolError):
+        (InspectorBackendClass.prototype.runAfterPendingDispatches):
+        * inspector/front-end/WebKit.qrc:
+        * inspector/front-end/inspector.html:
+
 2011-12-01  Kentaro Hara  <hara...@chromium.org>
 
         Use the [Supplemental] IDL for webaudio attributes in Chromium

Modified: trunk/Source/WebCore/WebCore.gypi (101669 => 101670)


--- trunk/Source/WebCore/WebCore.gypi	2011-12-01 16:07:12 UTC (rev 101669)
+++ trunk/Source/WebCore/WebCore.gypi	2011-12-01 16:20:51 UTC (rev 101670)
@@ -6368,6 +6368,7 @@
             'inspector/front-end/HeapSnapshotWorkerDispatcher.js',
             'inspector/front-end/HelpScreen.js',
             'inspector/front-end/ImageView.js',
+            'inspector/front-end/InspectorBackend.js',
             'inspector/front-end/InspectorFrontendAPI.js',
             'inspector/front-end/InspectorFrontendHostStub.js',
             'inspector/front-end/InspectorView.js',

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (101669 => 101670)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-12-01 16:07:12 UTC (rev 101669)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-12-01 16:20:51 UTC (rev 101670)
@@ -69145,6 +69145,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\inspector\front-end\InspectorBackend.js"
+					>
+				</File>
+				<File
 					RelativePath="..\inspector\front-end\InspectorFrontendAPI.js"
 					>
 				</File>

Modified: trunk/Source/WebCore/inspector/CodeGeneratorInspector.py (101669 => 101670)


--- trunk/Source/WebCore/inspector/CodeGeneratorInspector.py	2011-12-01 16:07:12 UTC (rev 101669)
+++ trunk/Source/WebCore/inspector/CodeGeneratorInspector.py	2011-12-01 16:20:51 UTC (rev 101670)
@@ -935,248 +935,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+$delegates
+$eventArgs
+$replyArgs$domainDispatchers
+""")
 
-InspectorBackendStub = function()
-{
-    this._lastCallbackId = 1;
-    this._pendingResponsesCount = 0;
-    this._callbacks = {};
-    this._domainDispatchers = {};
-    this._eventArgs = {};
-    this._replyArgs = {};
-$delegates$eventArgs$replyArgs$domainDispatchers}
-
-InspectorBackendStub.prototype = {
-    dumpInspectorTimeStats: 0,
-    dumpInspectorProtocolMessages: 0,
-
-    _wrap: function(callback)
-    {
-        var callbackId = this._lastCallbackId++;
-        this._callbacks[callbackId] = callback || function() {};
-        return callbackId;
-    },
-
-    _registerDelegate: function(requestString)
-    {
-        var domainAndFunction = JSON.parse(requestString).method.split(".");
-        var agentName = domainAndFunction[0] + "Agent";
-        if (!window[agentName])
-            window[agentName] = {};
-        window[agentName][domainAndFunction[1]] = this._sendMessageToBackend.bind(this, requestString);
-        window[agentName][domainAndFunction[1]]["invoke"] = this._invoke.bind(this, requestString)
-    },
-
-    _invoke: function(requestString, args, callback)
-    {
-        var request = JSON.parse(requestString);
-        request.params = args;
-        this._wrapCallbackAndSendMessageObject(request, callback);
-    },
-
-    _sendMessageToBackend: function()
-    {
-        var args = Array.prototype.slice.call(arguments);
-        var request = JSON.parse(args.shift());
-        var callback = (args.length && typeof args[args.length - 1] === "function") ? args.pop() : 0;
-        var domainAndMethod = request.method.split(".");
-        var agentMethod = domainAndMethod[0] + "Agent." + domainAndMethod[1];
-
-        var hasParams = false;
-        if (request.params) {
-            for (var key in request.params) {
-                var typeName = request.params[key].type;
-                var optionalFlag = request.params[key].optional;
-
-                if (args.length === 0 && !optionalFlag) {
-                    console.error("Protocol Error: Invalid number of arguments for method '" + agentMethod + "' call. It must have the next arguments '" + JSON.stringify(request.params) + "'.");
-                    return;
-                }
-
-                var value = args.shift();
-                if (optionalFlag && typeof value === "undefined") {
-                    delete request.params[key];
-                    continue;
-                }
-
-                if (typeof value !== typeName) {
-                    console.error("Protocol Error: Invalid type of argument '" + key + "' for method '" + agentMethod + "' call. It must be '" + typeName + "' but it is '" + typeof value + "'.");
-                    return;
-                }
-
-                request.params[key] = value;
-                hasParams = true;
-            }
-            if (!hasParams)
-                delete request.params;
-        }
-
-        if (args.length === 1 && !callback) {
-            if (typeof args[0] !== "undefined") {
-                console.error("Protocol Error: Optional callback argument for method '" + agentMethod + "' call must be a function but its type is '" + typeof args[0] + "'.");
-                return;
-            }
-        }
-
-        this._wrapCallbackAndSendMessageObject(request, callback);
-    },
-
-    _wrapCallbackAndSendMessageObject: function(messageObject, callback)
-    {
-        messageObject.id = this._wrap(callback);
-
-        var wrappedCallback = this._callbacks[messageObject.id];
-        wrappedCallback.methodName = messageObject.method;
-
-        if (this.dumpInspectorTimeStats)
-            wrappedCallback.sendRequestTime = Date.now();
-
-        if (this.dumpInspectorProtocolMessages)
-            console.log("frontend: " + JSON.stringify(messageObject));
-
-        ++this._pendingResponsesCount;
-        this.sendMessageObjectToBackend(messageObject);
-    },
-
-    sendMessageObjectToBackend: function(messageObject)
-    {
-        console.timeStamp(messageObject.method);
-        var message = JSON.stringify(messageObject);
-        InspectorFrontendHost.sendMessageToBackend(message);
-    },
-
-    _registerDomainDispatcher: function(domain, dispatcher)
-    {
-        this._domainDispatchers[domain] = dispatcher;
-    },
-
-    dispatch: function(message)
-    {
-        if (this.dumpInspectorProtocolMessages)
-            console.log("backend: " + ((typeof message === "string") ? message : JSON.stringify(message)));
-
-        var messageObject = (typeof message === "string") ? JSON.parse(message) : message;
-
-        if ("id" in messageObject) { // just a response for some request
-            if (messageObject.error) {
-                messageObject.error.__proto__ = {
-                    getDescription: function()
-                    {
-                        switch(this.code) {
-                            case -32700: return "Parse error";
-                            case -32600: return "Invalid Request";
-                            case -32601: return "Method not found";
-                            case -32602: return "Invalid params";
-                            case -32603: return "Internal error";;
-                            case -32000: return "Server error";
-                        }
-                    },
-
-                    toString: function()
-                    {
-                        var description ="Unknown error code";
-                        return this.getDescription() + "(" + this.code + "): " + this.message + "." + (this.data ? " " + this.data.join(" ") : "");
-                    },
-
-                    getMessage: function()
-                    {
-                        return this.message;
-                    }
-                }
-
-                if (messageObject.error.code !== -32000)
-                    this.reportProtocolError(messageObject);
-            }
-
-            var callback = this._callbacks[messageObject.id];
-            if (callback) {
-                var argumentsArray = [];
-                if (messageObject.result) {
-                    var paramNames = this._replyArgs[callback.methodName];
-                    if (paramNames) {
-                        for (var i = 0; i < paramNames.length; ++i)
-                            argumentsArray.push(messageObject.result[paramNames[i]]);
-                    }
-                }
-
-                var processingStartTime;
-                if (this.dumpInspectorTimeStats && callback.methodName)
-                    processingStartTime = Date.now();
-
-                argumentsArray.unshift(messageObject.error);
-                callback.apply(null, argumentsArray);
-                --this._pendingResponsesCount;
-                delete this._callbacks[messageObject.id];
-
-                if (this.dumpInspectorTimeStats && callback.methodName)
-                    console.log("time-stats: " + callback.methodName + " = " + (processingStartTime - callback.sendRequestTime) + " + " + (Date.now() - processingStartTime));
-            }
-
-            if (this._scripts && !this._pendingResponsesCount)
-                this.runAfterPendingDispatches();
-
-            return;
-        } else {
-            var method = messageObject.method.split(".");
-            var domainName = method[0];
-            var functionName = method[1];
-            if (!(domainName in this._domainDispatchers)) {
-                console.error("Protocol Error: the message is for non-existing domain '" + domainName + "'");
-                return;
-            }
-            var dispatcher = this._domainDispatchers[domainName];
-            if (!(functionName in dispatcher)) {
-                console.error("Protocol Error: Attempted to dispatch an unimplemented method '" + messageObject.method + "'");
-                return;
-            }
-
-            if (!this._eventArgs[messageObject.method]) {
-                console.error("Protocol Error: Attempted to dispatch an unspecified method '" + messageObject.method + "'");
-                return;
-            }
-
-            var params = [];
-            if (messageObject.params) {
-                var paramNames = this._eventArgs[messageObject.method];
-                for (var i = 0; i < paramNames.length; ++i)
-                    params.push(messageObject.params[paramNames[i]]);
-            }
-
-            var processingStartTime;
-            if (this.dumpInspectorTimeStats)
-                processingStartTime = Date.now();
-
-            dispatcher[functionName].apply(dispatcher, params);
-
-            if (this.dumpInspectorTimeStats)
-                console.log("time-stats: " + messageObject.method + " = " + (Date.now() - processingStartTime));
-        }
-    },
-
-    reportProtocolError: function(messageObject)
-    {
-        console.error("Request with id = " + messageObject.id + " failed. " + messageObject.error);
-    },
-
-    runAfterPendingDispatches: function(script)
-    {
-        if (!this._scripts)
-            this._scripts = [];
-
-        if (script)
-            this._scripts.push(script);
-
-        if (!this._pendingResponsesCount) {
-            var scripts = this._scripts;
-            this._scripts = []
-            for (var id = 0; id < scripts.length; ++id)
-                 scripts[id].call(this);
-        }
-    }
-}
-
-InspectorBackend = new InspectorBackendStub();""")
-
     param_container_access_code = """
     RefPtr<InspectorObject> paramsContainer = requestMessageObject->getObject("params");
     InspectorObject* paramsContainerPtr = paramsContainer.get();
@@ -1239,7 +1002,7 @@
                     Generator.process_command(json_command, domain_name, agent_field_name)
 
             if not domain_data.skip_js_bind:
-                Generator.backend_js_domain_dispatcher_list.append("    this.register%sDispatcher = this._registerDomainDispatcher.bind(this, \"%s\");\n" % (domain_name, domain_name))
+                Generator.backend_js_domain_dispatcher_list.append("InspectorBackend.register%sDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, \"%s\");\n" % (domain_name, domain_name))
 
         sorted_json_domains = list(json_api["domains"])
         sorted_json_domains.sort(key=lambda o: o["domain"])
@@ -1300,7 +1063,7 @@
             parameters=join(parameter_list, ", "),
             code=join(method_line_list, "")))
 
-        Generator.backend_js_event_list.append("    this._eventArgs[\"%s.%s\"] = [%s];\n" % (
+        Generator.backend_js_event_list.append("InspectorBackend.registerEvent(\"%s.%s\", [%s]);\n" % (
             domain_name, event_name, join(backend_js_event_param_list, ", ")))
 
     @staticmethod
@@ -1351,9 +1114,10 @@
 
                 js_param_list.append(js_param_text)
 
-            js_parameters_text = ", \"params\": {" + join(js_param_list, ", ") + "}"
+            js_parameters_text = join(js_param_list, ", ")
 
         response_cook_text = ""
+        js_reply_list = "[]"
         if "returns" in json_command:
             method_out_code += "\n"
             for json_return in json_command["returns"]:
@@ -1376,8 +1140,7 @@
 
                 backend_js_reply_param_list.append("\"%s\"" % json_return_name)
 
-            Generator.backend_js_reply_list.append("    this._replyArgs[\"%s.%s\"] = [%s];\n" % (
-                domain_name, json_command_name, join(backend_js_reply_param_list, ", ")))
+            js_reply_list = "[%s]" % join(backend_js_reply_param_list, ", ")
 
             response_cook_text = "    if (!protocolErrors->length() && !error.length()) {\n%s    }\n" % join(response_cook_list, "")
 
@@ -1391,7 +1154,7 @@
             responseCook=response_cook_text))
         Generator.backend_method_name_declaration_list.append("    \"%s.%s\"," % (domain_name, json_command_name))
 
-        Generator.backend_js_initializer_list.append("    this._registerDelegate('{\"method\": \"%s.%s\"%s, \"id\": 0}');\n" % (domain_name, json_command_name, js_parameters_text))
+        Generator.backend_js_initializer_list.append("InspectorBackend.registerCommand(\"%s.%s\", {%s}, %s);\n" % (domain_name, json_command_name, js_parameters_text, js_reply_list))
 
 Generator.go()
 

Modified: trunk/Source/WebCore/inspector/compile-front-end.sh (101669 => 101670)


--- trunk/Source/WebCore/inspector/compile-front-end.sh	2011-12-01 16:07:12 UTC (rev 101669)
+++ trunk/Source/WebCore/inspector/compile-front-end.sh	2011-12-01 16:20:51 UTC (rev 101670)
@@ -45,7 +45,8 @@
         --js Source/WebCore/inspector/front-end/UserMetrics.js \
         --js Source/WebCore/inspector/front-end/HandlerRegistry.js \
         --js Source/WebCore/inspector/front-end/InspectorFrontendHostStub.js \
-    --module jsmodule_sdk:25:jsmodule_common \
+    --module jsmodule_sdk:26:jsmodule_common \
+        --js Source/WebCore/inspector/front-end/InspectorBackend.js \
         --js Source/WebCore/inspector/front-end/ApplicationCacheModel.js \
         --js Source/WebCore/inspector/front-end/CompilerSourceMapping.js \
         --js Source/WebCore/inspector/front-end/ConsoleModel.js \

Added: trunk/Source/WebCore/inspector/front-end/InspectorBackend.js (0 => 101670)


--- trunk/Source/WebCore/inspector/front-end/InspectorBackend.js	                        (rev 0)
+++ trunk/Source/WebCore/inspector/front-end/InspectorBackend.js	2011-12-01 16:20:51 UTC (rev 101670)
@@ -0,0 +1,285 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @constructor
+ */
+function InspectorBackendClass()
+{
+    this._lastCallbackId = 1;
+    this._pendingResponsesCount = 0;
+    this._callbacks = {};
+    this._domainDispatchers = {};
+    this._eventArgs = {};
+    this._replyArgs = {};
+
+    this.dumpInspectorTimeStats = false;
+    this.dumpInspectorProtocolMessages = false;
+}
+
+InspectorBackendClass.prototype = {
+    _wrap: function(callback)
+    {
+        var callbackId = this._lastCallbackId++;
+        this._callbacks[callbackId] = callback || function() {};
+        return callbackId;
+    },
+
+    registerCommand: function(method, signature, replyArgs)
+    {
+        var domainAndFunction = method.split(".");
+        var agentName = domainAndFunction[0] + "Agent";
+        if (!window[agentName])
+            window[agentName] = {};
+
+        var request = { method: method, params: signature };
+        var requestString = JSON.stringify(request);
+        window[agentName][domainAndFunction[1]] = this._sendMessageToBackend.bind(this, requestString);
+        window[agentName][domainAndFunction[1]]["invoke"] = this._invoke.bind(this, requestString);
+        this._replyArgs[method] = replyArgs;
+    },
+
+    registerEvent: function(eventName, params)
+    {
+        this._eventArgs[eventName] = params;
+    },
+
+    _invoke: function(requestString, args, callback)
+    {
+        var request = JSON.parse(requestString);
+        request.params = args;
+        this._wrapCallbackAndSendMessageObject(request, callback);
+    },
+
+    _sendMessageToBackend: function()
+    {
+        var args = Array.prototype.slice.call(arguments);
+        var request = JSON.parse(args.shift());
+        var callback = (args.length && typeof args[args.length - 1] === "function") ? args.pop() : 0;
+        var domainAndMethod = request.method.split(".");
+        var agentMethod = domainAndMethod[0] + "Agent." + domainAndMethod[1];
+
+        var hasParams = false;
+        if (request.params) {
+            for (var key in request.params) {
+                var typeName = request.params[key].type;
+                var optionalFlag = request.params[key]["optional"];
+
+                if (args.length === 0 && !optionalFlag) {
+                    console.error("Protocol Error: Invalid number of arguments for method '" + agentMethod + "' call. It must have the next arguments '" + JSON.stringify(request.params) + "'.");
+                    return;
+                }
+
+                var value = args.shift();
+                if (optionalFlag && typeof value === "undefined") {
+                    delete request.params[key];
+                    continue;
+                }
+
+                if (typeof value !== typeName) {
+                    console.error("Protocol Error: Invalid type of argument '" + key + "' for method '" + agentMethod + "' call. It must be '" + typeName + "' but it is '" + typeof value + "'.");
+                    return;
+                }
+
+                request.params[key] = value;
+                hasParams = true;
+            }
+            if (!hasParams)
+                delete request.params;
+        }
+
+        if (args.length === 1 && !callback) {
+            if (typeof args[0] !== "undefined") {
+                console.error("Protocol Error: Optional callback argument for method '" + agentMethod + "' call must be a function but its type is '" + typeof args[0] + "'.");
+                return;
+            }
+        }
+
+        this._wrapCallbackAndSendMessageObject(request, callback);
+    },
+
+    _wrapCallbackAndSendMessageObject: function(messageObject, callback)
+    {
+        messageObject.id = this._wrap(callback);
+
+        var wrappedCallback = this._callbacks[messageObject.id];
+        wrappedCallback.methodName = messageObject.method;
+
+        if (this.dumpInspectorTimeStats)
+            wrappedCallback.sendRequestTime = Date.now();
+
+        if (this.dumpInspectorProtocolMessages)
+            console.log("frontend: " + JSON.stringify(messageObject));
+
+        ++this._pendingResponsesCount;
+        this.sendMessageObjectToBackend(messageObject);
+    },
+
+    sendMessageObjectToBackend: function(messageObject)
+    {
+        console.timeStamp(messageObject.method);
+        var message = JSON.stringify(messageObject);
+        InspectorFrontendHost.sendMessageToBackend(message);
+    },
+
+    registerDomainDispatcher: function(domain, dispatcher)
+    {
+        this._domainDispatchers[domain] = dispatcher;
+    },
+
+    dispatch: function(message)
+    {
+        if (this.dumpInspectorProtocolMessages)
+            console.log("backend: " + ((typeof message === "string") ? message : JSON.stringify(message)));
+
+        var messageObject = (typeof message === "string") ? JSON.parse(message) : message;
+
+        if ("id" in messageObject) { // just a response for some request
+            if (messageObject.error) {
+                messageObject.error.__proto__ = {
+                    getDescription: function()
+                    {
+                        switch(this.code) {
+                            case -32700: return "Parse error";
+                            case -32600: return "Invalid Request";
+                            case -32601: return "Method not found";
+                            case -32602: return "Invalid params";
+                            case -32603: return "Internal error";;
+                            case -32000: return "Server error";
+                        }
+                    },
+
+                    toString: function()
+                    {
+                        var description ="Unknown error code";
+                        return this.getDescription() + "(" + this.code + "): " + this.message + "." + (this.data ? " " + this.data.join(" ") : "");
+                    },
+
+                    getMessage: function()
+                    {
+                        return this.message;
+                    }
+                }
+
+                if (messageObject.error.code !== -32000)
+                    this.reportProtocolError(messageObject);
+            }
+
+            var callback = this._callbacks[messageObject.id];
+            if (callback) {
+                var argumentsArray = [];
+                if (messageObject.result) {
+                    var paramNames = this._replyArgs[callback.methodName];
+                    if (paramNames) {
+                        for (var i = 0; i < paramNames.length; ++i)
+                            argumentsArray.push(messageObject.result[paramNames[i]]);
+                    }
+                }
+
+                var processingStartTime;
+                if (this.dumpInspectorTimeStats && callback.methodName)
+                    processingStartTime = Date.now();
+
+                argumentsArray.unshift(messageObject.error);
+                callback.apply(null, argumentsArray);
+                --this._pendingResponsesCount;
+                delete this._callbacks[messageObject.id];
+
+                if (this.dumpInspectorTimeStats && callback.methodName)
+                    console.log("time-stats: " + callback.methodName + " = " + (processingStartTime - callback.sendRequestTime) + " + " + (Date.now() - processingStartTime));
+            }
+
+            if (this._scripts && !this._pendingResponsesCount)
+                this.runAfterPendingDispatches();
+
+            return;
+        } else {
+            var method = messageObject.method.split(".");
+            var domainName = method[0];
+            var functionName = method[1];
+            if (!(domainName in this._domainDispatchers)) {
+                console.error("Protocol Error: the message is for non-existing domain '" + domainName + "'");
+                return;
+            }
+            var dispatcher = this._domainDispatchers[domainName];
+            if (!(functionName in dispatcher)) {
+                console.error("Protocol Error: Attempted to dispatch an unimplemented method '" + messageObject.method + "'");
+                return;
+            }
+
+            if (!this._eventArgs[messageObject.method]) {
+                console.error("Protocol Error: Attempted to dispatch an unspecified method '" + messageObject.method + "'");
+                return;
+            }
+
+            var params = [];
+            if (messageObject.params) {
+                var paramNames = this._eventArgs[messageObject.method];
+                for (var i = 0; i < paramNames.length; ++i)
+                    params.push(messageObject.params[paramNames[i]]);
+            }
+
+            var processingStartTime;
+            if (this.dumpInspectorTimeStats)
+                processingStartTime = Date.now();
+
+            dispatcher[functionName].apply(dispatcher, params);
+
+            if (this.dumpInspectorTimeStats)
+                console.log("time-stats: " + messageObject.method + " = " + (Date.now() - processingStartTime));
+        }
+    },
+
+    reportProtocolError: function(messageObject)
+    {
+        console.error("Request with id = " + messageObject.id + " failed. " + messageObject.error);
+    },
+
+    /**
+     * @param {string=} script
+     */
+    runAfterPendingDispatches: function(script)
+    {
+        if (!this._scripts)
+            this._scripts = [];
+
+        if (script)
+            this._scripts.push(script);
+
+        if (!this._pendingResponsesCount) {
+            var scripts = this._scripts;
+            this._scripts = []
+            for (var id = 0; id < scripts.length; ++id)
+                 scripts[id].call(this);
+        }
+    }
+}
+
+InspectorBackend = new InspectorBackendClass();
Property changes on: trunk/Source/WebCore/inspector/front-end/InspectorBackend.js
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/inspector/front-end/WebKit.qrc (101669 => 101670)


--- trunk/Source/WebCore/inspector/front-end/WebKit.qrc	2011-12-01 16:07:12 UTC (rev 101669)
+++ trunk/Source/WebCore/inspector/front-end/WebKit.qrc	2011-12-01 16:20:51 UTC (rev 101670)
@@ -66,6 +66,7 @@
     <file>ImageView.js</file>
     <file>InjectedFakeWorker.js</file>
     <file>inspector.js</file>
+    <file>InspectorBackend.js</file>
     <file>InspectorFrontendAPI.js</file>
     <file>InspectorFrontendHostStub.js</file>
     <file>InspectorView.js</file>

Modified: trunk/Source/WebCore/inspector/front-end/inspector.html (101669 => 101670)


--- trunk/Source/WebCore/inspector/front-end/inspector.html	2011-12-01 16:07:12 UTC (rev 101669)
+++ trunk/Source/WebCore/inspector/front-end/inspector.html	2011-12-01 16:20:51 UTC (rev 101670)
@@ -40,6 +40,7 @@
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
+    <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""

Modified: trunk/Source/WebCore/inspector/front-end/utilities.js (101669 => 101670)


--- trunk/Source/WebCore/inspector/front-end/utilities.js	2011-12-01 16:07:12 UTC (rev 101669)
+++ trunk/Source/WebCore/inspector/front-end/utilities.js	2011-12-01 16:20:51 UTC (rev 101670)
@@ -311,7 +311,7 @@
 }
 
 /**
- * @param {DOMWindow} targetWindow
+ * @param {Window} targetWindow
  * @return {AnchorBox}
  */
 Element.prototype.offsetRelativeToWindow = function(targetWindow)
@@ -333,7 +333,7 @@
 }
 
 /**
- * @param {DOMWindow} targetWindow
+ * @param {Window} targetWindow
  * @return {AnchorBox}
  */
 Element.prototype.boxInWindow = function(targetWindow)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to