Web Inspector: XMLHttpRequest console logging messages should link to network panel...
authorvsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Sep 2011 20:06:55 +0000 (20:06 +0000)
committervsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Sep 2011 20:06:55 +0000 (20:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67399

Reviewed by Pavel Feldman.

* inspector/ConsoleMessage.cpp:
(WebCore::ConsoleMessage::ConsoleMessage):
* inspector/ConsoleMessage.h:
* inspector/InspectorConsoleAgent.cpp:
(WebCore::InspectorConsoleAgent::resourceRetrievedByXMLHttpRequest):
* inspector/InspectorConsoleAgent.h:
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::resourceRetrievedByXMLHttpRequestImpl):
* inspector/front-end/ConsoleMessage.js:
(WebInspector.ConsoleMessage.prototype._formatMessage.else.else.linkifier):
(WebInspector.ConsoleMessage.prototype._formatMessage):
* inspector/front-end/ResourcesPanel.js:
(WebInspector.ResourcesPanel.prototype.showAnchorLocation):
* inspector/front-end/inspector.js:
(WebInspector.linkifyStringAsFragmentWithCustomLinkifier):
(WebInspector.linkifyStringAsFragment):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95984 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/ConsoleMessage.cpp
Source/WebCore/inspector/ConsoleMessage.h
Source/WebCore/inspector/InspectorConsoleAgent.cpp
Source/WebCore/inspector/InspectorConsoleAgent.h
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/front-end/ConsoleMessage.js
Source/WebCore/inspector/front-end/ResourcesPanel.js
Source/WebCore/inspector/front-end/inspector.js

index d25a3f2..1597bb0 100644 (file)
@@ -1,3 +1,27 @@
+2011-09-26  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: XMLHttpRequest console logging messages should link to network panel when possible.
+        https://bugs.webkit.org/show_bug.cgi?id=67399
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/ConsoleMessage.cpp:
+        (WebCore::ConsoleMessage::ConsoleMessage):
+        * inspector/ConsoleMessage.h:
+        * inspector/InspectorConsoleAgent.cpp:
+        (WebCore::InspectorConsoleAgent::resourceRetrievedByXMLHttpRequest):
+        * inspector/InspectorConsoleAgent.h:
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::resourceRetrievedByXMLHttpRequestImpl):
+        * inspector/front-end/ConsoleMessage.js:
+        (WebInspector.ConsoleMessage.prototype._formatMessage.else.else.linkifier):
+        (WebInspector.ConsoleMessage.prototype._formatMessage):
+        * inspector/front-end/ResourcesPanel.js:
+        (WebInspector.ResourcesPanel.prototype.showAnchorLocation):
+        * inspector/front-end/inspector.js:
+        (WebInspector.linkifyStringAsFragmentWithCustomLinkifier):
+        (WebInspector.linkifyStringAsFragment):
+
 2011-09-26  Jer Noble  <jer.noble@apple.com>
 
         White flash when entering full-screen using element.webkitRequestFullScreen()
index d44a495..62d6394 100644 (file)
@@ -44,7 +44,7 @@
 
 namespace WebCore {
 
-ConsoleMessage::ConsoleMessage(MessageSource s, MessageType t, MessageLevel l, const String& m, unsigned li, const String& u)
+ConsoleMessage::ConsoleMessage(MessageSource s, MessageType t, MessageLevel l, const String& m, unsigned li, const String& u, const String& requestId)
     : m_source(s)
     , m_type(t)
     , m_level(l)
@@ -52,6 +52,7 @@ ConsoleMessage::ConsoleMessage(MessageSource s, MessageType t, MessageLevel l, c
     , m_line(li)
     , m_url(u)
     , m_repeatCount(1)
+    , m_requestId(requestId)
 {
 }
 
index c0b2588..88354d0 100644 (file)
@@ -51,7 +51,7 @@ class ScriptValue;
 class ConsoleMessage {
     WTF_MAKE_NONCOPYABLE(ConsoleMessage); WTF_MAKE_FAST_ALLOCATED;
 public:
-    ConsoleMessage(MessageSource, MessageType, MessageLevel, const String& m, unsigned li, const String& u);
+    ConsoleMessage(MessageSource, MessageType, MessageLevel, const String& m, unsigned li, const String& u, const String& requestId = String());
     ConsoleMessage(MessageSource, MessageType, MessageLevel, const String& m, PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>);
     ConsoleMessage(MessageSource, MessageType, MessageLevel, const String& m, const String& responseUrl, const String& requestId);
     ~ConsoleMessage();
index 91e4027..26762f8 100644 (file)
@@ -211,12 +211,17 @@ void InspectorConsoleAgent::frameWindowDiscarded(DOMWindow* window)
     m_injectedScriptManager->discardInjectedScriptsFor(window);
 }
 
-void InspectorConsoleAgent::resourceRetrievedByXMLHttpRequest(const String& url, const String& sendURL, unsigned sendLineNumber)
+void InspectorConsoleAgent::resourceRetrievedByXMLHttpRequest(unsigned long identifier, const String& url, const String& sendURL, unsigned sendLineNumber)
 {
     if (!m_inspectorAgent->enabled())
         return;
-    if (m_inspectorState->getBoolean(ConsoleAgentState::monitoringXHR))
-        addMessageToConsole(JSMessageSource, LogMessageType, LogMessageLevel, "XHR finished loading: \"" + url + "\".", sendLineNumber, sendURL);
+    if (m_frontend && m_inspectorState->getBoolean(ConsoleAgentState::monitoringXHR)) {
+        String message = "XHR finished loading: \"" + url + "\".";
+        String requestId = IdentifiersFactory::requestId(identifier);
+        addConsoleMessage(adoptPtr(new ConsoleMessage(NetworkMessageSource, LogMessageType, LogMessageLevel, message, sendLineNumber, sendURL, requestId)));
+    }
+
+
 }
 
 void InspectorConsoleAgent::didReceiveResponse(unsigned long identifier, const ResourceResponse& response)
index 2576a74..5556a09 100644 (file)
@@ -76,7 +76,7 @@ public:
 
     void frameWindowDiscarded(DOMWindow*);
 
-    void resourceRetrievedByXMLHttpRequest(const String& url, const String& sendURL, unsigned sendLineNumber);
+    void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const String& url, const String& sendURL, unsigned sendLineNumber);
     void didReceiveResponse(unsigned long identifier, const ResourceResponse&);
     void didFailLoading(unsigned long identifier, const ResourceError&);
 #if ENABLE(JAVASCRIPT_DEBUGGER)
index 3c94d42..1331c48 100644 (file)
@@ -542,7 +542,7 @@ void InspectorInstrumentation::didFailLoadingImpl(InstrumentingAgents* instrumen
 void InspectorInstrumentation::resourceRetrievedByXMLHttpRequestImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber)
 {
     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
-        consoleAgent->resourceRetrievedByXMLHttpRequest(url, sendURL, sendLineNumber);
+        consoleAgent->resourceRetrievedByXMLHttpRequest(identifier, url, sendURL, sendLineNumber);
     if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
         resourceAgent->setInitialXHRContent(identifier, sourceString);
 }
index 5f50e65..056583e 100644 (file)
@@ -105,17 +105,35 @@ WebInspector.ConsoleMessage.prototype = {
             }
         } else if (this.source === WebInspector.ConsoleMessage.MessageSource.Network) {
             if (this._request) {
-                this._stackTrace = this._request.stackTrace;
-                messageText = document.createElement("span");
-                messageText.appendChild(document.createTextNode(this._request.requestMethod + " "));
-                var anchor = WebInspector.linkifyURLAsNode(this._request.url);
-                anchor.setAttribute("request_id", this._request.requestId);
-                anchor.setAttribute("preferred_panel", "network");
-                messageText.appendChild(anchor);
-                if (this._request.failed)
-                    messageText.appendChild(document.createTextNode(" " + this._request.localizedFailDescription));
-                else
-                    messageText.appendChild(document.createTextNode(" " + this._request.statusCode + " (" + this._request.statusText + ")"));
+                if (this.level === WebInspector.ConsoleMessage.MessageLevel.Error) {
+                    this._stackTrace = this._request.stackTrace;
+                    messageText = document.createElement("span");
+                    messageText.appendChild(document.createTextNode(this._request.requestMethod + " "));
+                    var anchor = WebInspector.linkifyURLAsNode(this._request.url);
+                    anchor.setAttribute("request_id", this._request.requestId);
+                    anchor.setAttribute("preferred_panel", "network");
+                    messageText.appendChild(anchor);
+                    if (this._request.failed)
+                        messageText.appendChild(document.createTextNode(" " + this._request.localizedFailDescription));
+                    else
+                        messageText.appendChild(document.createTextNode(" " + this._request.statusCode + " (" + this._request.statusText + ")"));
+                } else {
+                    messageText = document.createElement("span");
+                    
+                    function linkifier(title, url, lineNumber)
+                    {
+                        var isExternal = !this._request;
+                        var anchor = WebInspector.linkifyURLAsNode(url, title, null, isExternal);
+                        if (this._request) {
+                            anchor.setAttribute("request_id", this._request.requestId);
+                            anchor.setAttribute("preferred_panel", "network");
+                        }
+                        return anchor;
+                    }
+                    
+                    var fragment = WebInspector.linkifyStringAsFragmentWithCustomLinkifier(this._messageText, linkifier.bind(this));
+                    messageText.appendChild(fragment);
+                }
             } else {
                 var isExternal = !WebInspector.resourceForURL(this.url);
                 var anchor = WebInspector.linkifyURLAsNode(this.url, this.url, "console-message-url", isExternal);
index fe341ca..2a88c1e 100644 (file)
@@ -327,14 +327,6 @@ WebInspector.ResourcesPanel.prototype = {
     showAnchorLocation: function(anchor)
     {
         var resource = WebInspector.resourceForURL(anchor.href);
-        if (resource.type === WebInspector.Resource.Type.XHR) {
-            // Show XHRs in the network panel only.
-            if (WebInspector.panels.network && WebInspector.panels.network.canShowAnchorLocation(anchor)) {
-                WebInspector.setCurrentPanel(WebInspector.panels.network);
-                WebInspector.panels.network.showAnchorLocation(anchor);
-            }
-            return;
-        }
         var lineNumber = anchor.hasAttribute("line_number") ? parseInt(anchor.getAttribute("line_number")) : undefined;
         this.showResource(resource, lineNumber);
     },
index 1bc7adb..fc2b59a 100644 (file)
@@ -1256,7 +1256,7 @@ WebInspector._showAnchorLocationInPanel = function(anchor, panel)
     return true;
 }
 
-WebInspector.linkifyStringAsFragment = function(string)
+WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linkifier)
 {
     var container = document.createDocumentFragment();
     var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|www\.)[\w$\-_+*'=\|\/\\(){}[\]%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({%@&#~]/;
@@ -1268,27 +1268,18 @@ WebInspector.linkifyStringAsFragment = function(string)
             break;
 
         linkString = linkString[0];
-        var title = linkString;
         var linkIndex = string.indexOf(linkString);
         var nonLink = string.substring(0, linkIndex);
         container.appendChild(document.createTextNode(nonLink));
 
-        var profileStringMatches = WebInspector.ProfileType.URLRegExp.exec(title);
-        if (profileStringMatches)
-            title = WebInspector.panels.profiles.displayTitleForProfileLink(profileStringMatches[2], profileStringMatches[1]);
-
+        var title = linkString;
         var realURL = (linkString.indexOf("www.") === 0 ? "http://" + linkString : linkString);
         var lineColumnMatch = lineColumnRegEx.exec(realURL);
         if (lineColumnMatch)
             realURL = realURL.substring(0, realURL.length - lineColumnMatch[0].length);
 
-        var hasResourceWithURL = !!WebInspector.resourceForURL(realURL);
-        var urlNode = WebInspector.linkifyURLAsNode(realURL, title, null, hasResourceWithURL);
-        container.appendChild(urlNode);
-        if (lineColumnMatch) {
-            urlNode.setAttribute("line_number", lineColumnMatch[1]);
-            urlNode.setAttribute("preferred_panel", "scripts");
-        }
+        var linkNode = linkifier(title, realURL, lineColumnMatch ? lineColumnMatch[1] : undefined);
+        container.appendChild(linkNode);
         string = string.substring(linkIndex + linkString.length, string.length);
     }
 
@@ -1298,6 +1289,27 @@ WebInspector.linkifyStringAsFragment = function(string)
     return container;
 }
 
+WebInspector.linkifyStringAsFragment = function(string)
+{
+    function linkifier(title, url, lineNumber)
+    {
+        var profileStringMatches = WebInspector.ProfileType.URLRegExp.exec(title);
+        if (profileStringMatches)
+            title = WebInspector.panels.profiles.displayTitleForProfileLink(profileStringMatches[2], profileStringMatches[1]);
+
+        var isExternal = !WebInspector.resourceForURL(url);
+        var urlNode = WebInspector.linkifyURLAsNode(url, title, null, isExternal);
+        if (typeof(lineNumber) !== "undefined") {
+            urlNode.setAttribute("line_number", lineNumber);
+            urlNode.setAttribute("preferred_panel", "scripts");
+        }
+        
+        return urlNode; 
+    }
+    
+    return WebInspector.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier);
+}
+
 WebInspector.showProfileForURL = function(url)
 {
     WebInspector.showPanel("profiles");