Diff
Modified: trunk/LayoutTests/ChangeLog (92371 => 92372)
--- trunk/LayoutTests/ChangeLog 2011-08-04 13:54:18 UTC (rev 92371)
+++ trunk/LayoutTests/ChangeLog 2011-08-04 14:39:16 UTC (rev 92372)
@@ -1,3 +1,13 @@
+2011-08-04 Vsevolod Vlasov <[email protected]>
+
+ Web Inspector: Pretty print JSONP in network panel preview tab.
+ https://bugs.webkit.org/show_bug.cgi?id=65559
+
+ Reviewed by Pavel Feldman.
+
+ * http/tests/inspector/network/network-preview-json-expected.txt: Added.
+ * http/tests/inspector/network/network-preview-json.html: Added.
+
2011-08-04 Pavel Feldman <[email protected]>
Web Inspector: replace isRegex with urlRegex in setBreakpointByUrl
Added: trunk/LayoutTests/http/tests/inspector/network/network-preview-json-expected.txt (0 => 92372)
--- trunk/LayoutTests/http/tests/inspector/network/network-preview-json-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/network-preview-json-expected.txt 2011-08-04 14:39:16 UTC (rev 92372)
@@ -0,0 +1,3 @@
+Tests ResourceJSONView ability to parse JSON passed in XHR, JSONP
+
+Bug 65559
Property changes on: trunk/LayoutTests/http/tests/inspector/network/network-preview-json-expected.txt
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/http/tests/inspector/network/network-preview-json.html (0 => 92372)
--- trunk/LayoutTests/http/tests/inspector/network/network-preview-json.html (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/network-preview-json.html 2011-08-04 14:39:16 UTC (rev 92372)
@@ -0,0 +1,54 @@
+<html>
+<head>
+<script src=""
+<script>
+
+function test()
+{
+ var testData;
+
+ testData = "while(1);";
+ InspectorTest.assertTrue(!WebInspector.ResourceJSONView.parseJSON(testData), "Should not be able to parse \"" + testData + "\".");
+
+ testData = "{\"name\": \"value\"";
+ InspectorTest.assertTrue(!WebInspector.ResourceJSONView.parseJSON(testData), "Should not be able to parse \"" + testData + "\".");
+
+ testData = "{\"name\": \"value\"}";
+ var parsedJSON = WebInspector.ResourceJSONView.parseJSON(testData);
+ InspectorTest.assertEquals(parsedJSON.prefix, "");
+ InspectorTest.assertEquals(parsedJSON.data.name, "value");
+ InspectorTest.assertEquals(parsedJSON.suffix, "");
+
+ testData = "while(1); {\"name\": \"value\"}";
+ parsedJSON = WebInspector.ResourceJSONView.parseJSON(testData);
+ InspectorTest.assertEquals(parsedJSON.prefix, "while(1); ");
+ InspectorTest.assertEquals(parsedJSON.data.name, "value");
+ InspectorTest.assertEquals(parsedJSON.suffix, "");
+
+ testData = "func({)";
+ InspectorTest.assertTrue(!WebInspector.ResourceJSONView.parseJSONP(testData), "Should not be able to parse \"" + testData + "\".");
+
+ testData = "func){(";
+ InspectorTest.assertTrue(!WebInspector.ResourceJSONView.parseJSONP(testData), "Should not be able to parse \"" + testData + "\".");
+
+ testData = "func({\"name\": \"value\"}";
+ InspectorTest.assertTrue(!WebInspector.ResourceJSONView.parseJSONP(testData), "Should not be able to parse \"" + testData + "\".");
+
+ testData = "func{\"name\": \"value\"})";
+ InspectorTest.assertTrue(!WebInspector.ResourceJSONView.parseJSONP(testData), "Should not be able to parse \"" + testData + "\".");
+
+ testData = "func({\"name\": \"value\"})";
+ var parsedJSONP = WebInspector.ResourceJSONView.parseJSONP(testData);
+ InspectorTest.assertEquals(parsedJSONP.prefix, "func(");
+ InspectorTest.assertEquals(parsedJSONP.data.name, "value");
+ InspectorTest.assertEquals(parsedJSONP.suffix, ")");
+
+ InspectorTest.completeTest();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<p>Tests ResourceJSONView ability to parse JSON passed in XHR, JSONP</p>
+<a href="" 65559</a>
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/inspector/network/network-preview-json.html
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/Source/WebCore/ChangeLog (92371 => 92372)
--- trunk/Source/WebCore/ChangeLog 2011-08-04 13:54:18 UTC (rev 92371)
+++ trunk/Source/WebCore/ChangeLog 2011-08-04 14:39:16 UTC (rev 92372)
@@ -1,3 +1,19 @@
+2011-08-04 Vsevolod Vlasov <[email protected]>
+
+ Web Inspector: Pretty print JSONP in network panel preview tab.
+ https://bugs.webkit.org/show_bug.cgi?id=65559
+
+ Reviewed by Pavel Feldman.
+
+ Test: http/tests/inspector/network/network-preview-json.html
+
+ * inspector/front-end/ResourceJSONView.js:
+ (WebInspector.ResourceJSONView.parseJSON.WebInspector.ResourceJSONView.parseJSONP):
+ (WebInspector.ResourceJSONView.parseJSON.WebInspector.ResourceJSONView.prototype._initialize):
+ (WebInspector.ResourceJSONView.parseJSON.WebInspector.ParsedJSON):
+ * inspector/front-end/ResourcePreviewView.js:
+ (WebInspector.ResourcePreviewView.prototype._createPreviewView):
+
2011-08-04 Pavel Feldman <[email protected]>
Web Inspector: replace isRegex with urlRegex in setBreakpointByUrl
Modified: trunk/Source/WebCore/inspector/front-end/ResourceJSONView.js (92371 => 92372)
--- trunk/Source/WebCore/inspector/front-end/ResourceJSONView.js 2011-08-04 13:54:18 UTC (rev 92371)
+++ trunk/Source/WebCore/inspector/front-end/ResourceJSONView.js 2011-08-04 14:39:16 UTC (rev 92372)
@@ -37,18 +37,41 @@
WebInspector.ResourceJSONView.parseJSON = function(text)
{
+ var prefix = "";
+
// Trim while(1), for(;;), weird numbers, etc. We need JSON start.
var start = /[{[]/.exec(text);
- if (start && start.index)
+ if (start && start.index) {
+ prefix = text.substring(0, start.index);
text = text.substring(start.index);
+ }
try {
- return JSON.parse(text);
+ return new WebInspector.ParsedJSON(JSON.parse(text), prefix, "");
} catch (e) {
return;
}
}
+WebInspector.ResourceJSONView.parseJSONP = function(text)
+{
+ // Taking everything between first and last parentheses
+ var start = text.indexOf("(");
+ var end = text.lastIndexOf(")");
+ if (start == -1 || end == -1 || end < start)
+ return;
+
+ var prefix = text.substring(0, start + 1);
+ var suffix = text.substring(end);
+ var text = text.substring(start + 1, end);
+
+ try {
+ return new WebInspector.ParsedJSON(JSON.parse(text), prefix, suffix);
+ } catch (e) {
+ return;
+ }
+}
+
WebInspector.ResourceJSONView.prototype = {
hasContent: function()
{
@@ -67,9 +90,20 @@
return;
this._initialized = true;
- var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON);
- this.element.appendChild(new WebInspector.ObjectPropertiesSection(obj, obj.description).element);
+ var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON.data);
+ var title = this._parsedJSON.prefix + obj.description + this._parsedJSON.suffix;
+ var section = new WebInspector.ObjectPropertiesSection(obj, title);
+ section.expand();
+ section.editable = false;
+ this.element.appendChild(section.element);
}
}
WebInspector.ResourceJSONView.prototype.__proto__ = WebInspector.ResourceView.prototype;
+
+WebInspector.ParsedJSON = function(data, prefix, suffix)
+{
+ this.data = ""
+ this.prefix = prefix;
+ this.suffix = suffix;
+}
Modified: trunk/Source/WebCore/inspector/front-end/ResourcePreviewView.js (92371 => 92372)
--- trunk/Source/WebCore/inspector/front-end/ResourcePreviewView.js 2011-08-04 13:54:18 UTC (rev 92371)
+++ trunk/Source/WebCore/inspector/front-end/ResourcePreviewView.js 2011-08-04 14:39:16 UTC (rev 92372)
@@ -71,6 +71,12 @@
return new WebInspector.ResourceJSONView(this.resource, parsedJSON);
}
+ if (this.resource.content && this.resource.category === WebInspector.resourceCategories.scripts && this.resource.mimeType === "application/json") {
+ var parsedJSONP = WebInspector.ResourceJSONView.parseJSONP(this.resource.content);
+ if (parsedJSONP)
+ return new WebInspector.ResourceJSONView(this.resource, parsedJSONP);
+ }
+
if (this._responseView.sourceView)
return this._responseView.sourceView;