Title: [209629] trunk
Revision
209629
Author
joep...@webkit.org
Date
2016-12-09 14:12:08 -0800 (Fri, 09 Dec 2016)

Log Message

Web Inspector: Some resources fetched via Fetch API do not have data
https://bugs.webkit.org/show_bug.cgi?id=165230
<rdar://problem/29449220>

Reviewed by Alex Christensen.

Source/_javascript_Core:

* inspector/protocol/Page.json:
Add new Fetch Page.ResourceType.

Source/WebCore:

Tests: http/tests/inspector/network/fetch-response-body.html
       http/tests/inspector/network/xhr-response-body.html

* platform/network/ResourceRequestBase.h:
Distinguish Fetch requests.

* Modules/fetch/FetchRequest.cpp:
(WebCore::FetchRequest::initializeWith):
Set the requester type as Fetch.

* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::didReceiveResponse):
* loader/DocumentThreadableLoader.h:
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::didReceiveThreadableLoaderResponseImpl):
(WebCore::InspectorInstrumentation::didReceiveXHRResponseImpl): Deleted.
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::didReceiveResourceResponse):
(WebCore::InspectorInstrumentation::didReceiveThreadableLoaderResponse):
(WebCore::InspectorInstrumentation::didReceiveXHRResponse): Deleted.
* inspector/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::didReceiveThreadableLoaderResponse):
(WebCore::InspectorNetworkAgent::didFinishXHRLoading):
(WebCore::InspectorNetworkAgent::didReceiveXHRResponse): Deleted.
Add a generic way for a ThreadableLoader load to update the type of a network request.
This will include both XHR and Fetch requests.

* inspector/InspectorPageAgent.cpp:
(WebCore::hasTextContent):
(WebCore::createXHRTextDecoder):
(WebCore::InspectorPageAgent::resourceTypeJson):
(WebCore::InspectorPageAgent::cachedResourceType):
(WebCore::InspectorPageAgent::createTextDecoder):
(WebCore::textContentForCachedResource):
* inspector/InspectorPageAgent.h:
* inspector/NetworkResourcesData.cpp:
(WebCore::createOtherResourceTextDecoder): Deleted.
Share the logic that creates a Text Decoders for XHR with other non-buffered requests
(like Fetch). This moves us to identical behavior for now.

* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::isSupportedJSONMIMEType):
(WebCore::MIMETypeRegistry::isTextMIMEType):
* platform/MIMETypeRegistry.h:
Better detect different JSON content based on MIME Type.

Source/WebInspectorUI:

* Localizations/en.lproj/localizedStrings.js:
New "Fetch" and "Fetches" localized strings.

* UserInterface/Models/Resource.js:
(WebInspector.Resource.displayNameForType):
* UserInterface/Models/ResourceCollection.js:
(WebInspector.ResourceCollection.verifierForType):
* UserInterface/Views/CollectionContentView.js:
(WebInspector.CollectionContentView):
* UserInterface/Views/ResourceClusterContentView.js:
(WebInspector.ResourceClusterContentView.prototype.get responseContentView):
* UserInterface/Views/ResourceTreeElement.js:
(WebInspector.ResourceTreeElement.compareResourceTreeElements):
New ResourceType.Fetch. Behave like XHR in most places.

LayoutTests:

* http/tests/inspector/network/fetch-response-body-expected.txt: Added.
* http/tests/inspector/network/fetch-response-body.html: Added.
* http/tests/inspector/network/resources/data.html: Added.
* http/tests/inspector/network/resources/data.json: Added.
* http/tests/inspector/network/resources/data.svg: Added.
* http/tests/inspector/network/resources/data.txt: Added.
* http/tests/inspector/network/resources/echo.php: Added.
* http/tests/inspector/network/xhr-response-body-expected.txt: Added.
* http/tests/inspector/network/xhr-response-body.html: Added.
Tests for viewing content of XHR and Fetch requested resources
with different kinds of content.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (209628 => 209629)


--- trunk/LayoutTests/ChangeLog	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/LayoutTests/ChangeLog	2016-12-09 22:12:08 UTC (rev 209629)
@@ -1,3 +1,23 @@
+2016-12-09  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Some resources fetched via Fetch API do not have data
+        https://bugs.webkit.org/show_bug.cgi?id=165230
+        <rdar://problem/29449220>
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/inspector/network/fetch-response-body-expected.txt: Added.
+        * http/tests/inspector/network/fetch-response-body.html: Added.
+        * http/tests/inspector/network/resources/data.html: Added.
+        * http/tests/inspector/network/resources/data.json: Added.
+        * http/tests/inspector/network/resources/data.svg: Added.
+        * http/tests/inspector/network/resources/data.txt: Added.
+        * http/tests/inspector/network/resources/echo.php: Added.
+        * http/tests/inspector/network/xhr-response-body-expected.txt: Added.
+        * http/tests/inspector/network/xhr-response-body.html: Added.
+        Tests for viewing content of XHR and Fetch requested resources
+        with different kinds of content.
+
 2016-12-09  Ryosuke Niwa  <rn...@webkit.org>
 
         document.webkitFullscreenElement leaks elements inside a shadow tree

Added: trunk/LayoutTests/http/tests/inspector/network/fetch-response-body-expected.txt (0 => 209629)


--- trunk/LayoutTests/http/tests/inspector/network/fetch-response-body-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/fetch-response-body-expected.txt	2016-12-09 22:12:08 UTC (rev 209629)
@@ -0,0 +1,39 @@
+Tests for getting the content of Fetch requests.
+
+
+== Running test suite: Network.getResponseBody.Fetch
+-- Running test case: Network.getResponseBody.Fetch.Text
+PASS: Resource should be Fetch type.
+PASS: MIMEType should be 'text/plain'.
+PASS: Text content should match data.txt.
+
+-- Running test case: Network.getResponseBody.Fetch.HTML
+PASS: Resource should be Fetch type.
+PASS: MIMEType should be 'text/html'.
+PASS: Text content should match data.html.
+
+-- Running test case: Network.getResponseBody.Fetch.JSON
+PASS: Resource should be Fetch type.
+PASS: MIMEType should be 'application/octet-stream'.
+PASS: JSON content should match data.json.
+
+-- Running test case: Network.getResponseBody.Fetch.JSON2
+PASS: Resource should be Fetch type.
+PASS: MIMEType should be 'application/json'.
+PASS: JSON content should match specified content.
+
+-- Running test case: Network.getResponseBody.Fetch.JSON3
+PASS: Resource should be Fetch type.
+PASS: MIMEType should be 'application/vnd.api+json'.
+PASS: JSON content should match specified content.
+
+-- Running test case: Network.getResponseBody.Fetch.SVG
+PASS: Resource should be Fetch type.
+PASS: MIMEType should be 'image/svg+xml'.
+PASS: SVG content should be text.
+
+-- Running test case: Network.getResponseBody.Fetch.PNG
+PASS: Resource should be Fetch type.
+PASS: MIMEType should be 'image/png'.
+PASS: Image content should be text.
+

Added: trunk/LayoutTests/http/tests/inspector/network/fetch-response-body.html (0 => 209629)


--- trunk/LayoutTests/http/tests/inspector/network/fetch-response-body.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/fetch-response-body.html	2016-12-09 22:12:08 UTC (rev 209629)
@@ -0,0 +1,139 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+<script>
+function createFetchForText() {
+    fetch("resources/data.txt");
+}
+
+function createFetchForHTML() {
+    fetch("resources/data.html");
+}
+
+function createFetchForJSON() {
+    fetch("resources/data.json");
+}
+
+function createFetchForJSON2() {
+    fetch(`resources/echo.php?mimetype=application/json&content={"json":true,"value":42}`);
+}
+
+function createFetchForJSON3() {
+    fetch(`resources/echo.php?mimetype=application/vnd.api%2Bjson&content={"json":true,"value":999}`);
+}
+
+function createFetchForSVG() {
+    fetch("resources/data.svg");
+}
+
+function createFetchForPNG() {
+    fetch("/resources/square100.png");
+}
+
+function test()
+{
+    let suite = InspectorTest.createAsyncSuite("Network.getResponseBody.Fetch");
+
+    function addTestCase({name, description, _expression_, contentHandler}) {
+        suite.addTestCase({
+            name, description,
+            test(resolve, reject) {
+                InspectorTest.evaluateInPage(_expression_);
+                WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
+                    .then((event) => {
+                        let resource = event.data.resource;
+                        InspectorTest.expectEqual(resource.type, WebInspector.Resource.Type.Fetch, "Resource should be Fetch type.");
+                        return resource.requestContent();
+                    })
+                    .then(contentHandler)
+                    .then(resolve, reject);
+            }
+        });
+    }
+
+    addTestCase({
+        name: "Network.getResponseBody.Fetch.Text",
+        description: "Get text/plain content as text.",
+        _expression_: "createFetchForText()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "text/plain", "MIMEType should be 'text/plain'.");
+            InspectorTest.expectEqual(content, "Plain text resource.\n", "Text content should match data.txt.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.Fetch.HTML",
+        description: "Get text/html content as text.",
+        _expression_: "createFetchForHTML()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "text/html", "MIMEType should be 'text/html'.");
+            InspectorTest.expectEqual(content, "<span>Hello World</span>\n", "Text content should match data.html.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.Fetch.JSON",
+        description: "Get application/octet-stream content as text.",
+        _expression_: "createFetchForJSON()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "application/octet-stream", "MIMEType should be 'application/octet-stream'.");
+            InspectorTest.expectEqual(content, `{"json": true, "value": 42}\n`, "JSON content should match data.json.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.Fetch.JSON2",
+        description: "Get application/json content as text.",
+        _expression_: "createFetchForJSON2()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "application/json", "MIMEType should be 'application/json'.");
+            InspectorTest.expectEqual(content, `{"json":true,"value":42}`, "JSON content should match specified content.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.Fetch.JSON3",
+        description: "Get arbitrary +json content as text.",
+        _expression_: "createFetchForJSON3()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "application/vnd.api+json", "MIMEType should be 'application/vnd.api+json'.");
+            InspectorTest.expectEqual(content, `{"json":true,"value":999}`, "JSON content should match specified content.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.Fetch.SVG",
+        description: "Get image/svg+xml content as text.",
+        _expression_: "createFetchForSVG()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "image/svg+xml", "MIMEType should be 'image/svg+xml'.");
+            InspectorTest.expectEqual(content,
+`<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 200">
+  <rect width="100%" height="50%" fill="green"/>
+</svg>
+`, "SVG content should be text.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.Fetch.PNG",
+        description: "Get image/png content.",
+        _expression_: "createFetchForPNG()",
+        contentHandler({error, sourceCode, content}) {
+            // FIXME: <https://webkit.org/b/165495> Web Inspector: XHR / Fetch for non-text content should not show garbled text
+            InspectorTest.expectEqual(sourceCode.mimeType, "image/png", "MIMEType should be 'image/png'.");
+            InspectorTest.expectEqual(typeof content, "string", "Image content should be text.");
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<p>Tests for getting the content of Fetch requests.</p>
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/inspector/network/resources/data.html (0 => 209629)


--- trunk/LayoutTests/http/tests/inspector/network/resources/data.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/resources/data.html	2016-12-09 22:12:08 UTC (rev 209629)
@@ -0,0 +1 @@
+<span>Hello World</span>

Added: trunk/LayoutTests/http/tests/inspector/network/resources/data.json (0 => 209629)


--- trunk/LayoutTests/http/tests/inspector/network/resources/data.json	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/resources/data.json	2016-12-09 22:12:08 UTC (rev 209629)
@@ -0,0 +1 @@
+{"json": true, "value": 42}

Added: trunk/LayoutTests/http/tests/inspector/network/resources/data.svg (0 => 209629)


--- trunk/LayoutTests/http/tests/inspector/network/resources/data.svg	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/resources/data.svg	2016-12-09 22:12:08 UTC (rev 209629)
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 200">
+  <rect width="100%" height="50%" fill="green"/>
+</svg>

Added: trunk/LayoutTests/http/tests/inspector/network/resources/data.txt (0 => 209629)


--- trunk/LayoutTests/http/tests/inspector/network/resources/data.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/resources/data.txt	2016-12-09 22:12:08 UTC (rev 209629)
@@ -0,0 +1 @@
+Plain text resource.

Added: trunk/LayoutTests/http/tests/inspector/network/resources/echo.php (0 => 209629)


--- trunk/LayoutTests/http/tests/inspector/network/resources/echo.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/resources/echo.php	2016-12-09 22:12:08 UTC (rev 209629)
@@ -0,0 +1,7 @@
+<?php
+$mimeType = isset($_GET['mimetype']) ? $_GET['mimetype'] : 'text/plain';
+$content = isset($_GET['content']) ? $_GET['content'] : 'Missing mimetype or content query parameter.';
+
+header("Content-Type: $mimeType");
+echo $content;
+?>

Added: trunk/LayoutTests/http/tests/inspector/network/xhr-response-body-expected.txt (0 => 209629)


--- trunk/LayoutTests/http/tests/inspector/network/xhr-response-body-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/xhr-response-body-expected.txt	2016-12-09 22:12:08 UTC (rev 209629)
@@ -0,0 +1,39 @@
+Tests for getting the content of XHR requests.
+
+
+== Running test suite: Network.getResponseBody.XHR
+-- Running test case: Network.getResponseBody.XHR.Text
+PASS: Resource should be XHR type.
+PASS: MIMEType should be 'text/plain'.
+PASS: Text content should match data.txt.
+
+-- Running test case: Network.getResponseBody.XHR.HTML
+PASS: Resource should be XHR type.
+PASS: MIMEType should be 'text/html'.
+PASS: Text content should match data.html.
+
+-- Running test case: Network.getResponseBody.XHR.JSON
+PASS: Resource should be XHR type.
+PASS: MIMEType should be 'application/octet-stream'.
+PASS: JSON content should match data.json.
+
+-- Running test case: Network.getResponseBody.XHR.JSON2
+PASS: Resource should be XHR type.
+PASS: MIMEType should be 'application/json'.
+PASS: JSON content should match specified content.
+
+-- Running test case: Network.getResponseBody.XHR.JSON3
+PASS: Resource should be XHR type.
+PASS: MIMEType should be 'application/vnd.api+json'.
+PASS: JSON content should match specified content.
+
+-- Running test case: Network.getResponseBody.XHR.SVG
+PASS: Resource should be XHR type.
+PASS: MIMEType should be 'image/svg+xml'.
+PASS: SVG content should be text.
+
+-- Running test case: Network.getResponseBody.XHR.PNG
+PASS: Resource should be XHR type.
+PASS: MIMEType should be 'image/png'.
+PASS: Image content should be text.
+

Added: trunk/LayoutTests/http/tests/inspector/network/xhr-response-body.html (0 => 209629)


--- trunk/LayoutTests/http/tests/inspector/network/xhr-response-body.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/xhr-response-body.html	2016-12-09 22:12:08 UTC (rev 209629)
@@ -0,0 +1,145 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+<script>
+function xhrGet(url) {
+    let xhr = new XMLHttpRequest;
+    xhr.open("GET", url, true);
+    xhr.send();
+}
+
+function createXHRForText() {
+    xhrGet("resources/data.txt");
+}
+
+function createXHRForHTML() {
+    xhrGet("resources/data.html");
+}
+
+function createXHRForJSON() {
+    xhrGet("resources/data.json");
+}
+
+function createXHRForJSON2() {
+    xhrGet(`resources/echo.php?mimetype=application/json&content={"json":true,"value":42}`);
+}
+
+function createXHRForJSON3() {
+    xhrGet(`resources/echo.php?mimetype=application/vnd.api%2Bjson&content={"json":true,"value":999}`);
+}
+
+function createXHRForSVG() {
+    xhrGet("resources/data.svg");
+}
+
+function createXHRForPNG() {
+    xhrGet("/resources/square100.png");
+}
+
+function test()
+{
+    let suite = InspectorTest.createAsyncSuite("Network.getResponseBody.XHR");
+
+    function addTestCase({name, description, _expression_, contentHandler}) {
+        suite.addTestCase({
+            name, description,
+            test(resolve, reject) {
+                InspectorTest.evaluateInPage(_expression_);
+                WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
+                    .then((event) => {
+                        let resource = event.data.resource;
+                        InspectorTest.expectEqual(resource.type, WebInspector.Resource.Type.XHR, "Resource should be XHR type.");
+                        return resource.requestContent();
+                    })
+                    .then(contentHandler)
+                    .then(resolve, reject);
+            }
+        });
+    }
+
+    addTestCase({
+        name: "Network.getResponseBody.XHR.Text",
+        description: "Get text/plain content as text.",
+        _expression_: "createXHRForText()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "text/plain", "MIMEType should be 'text/plain'.");
+            InspectorTest.expectEqual(content, "Plain text resource.\n", "Text content should match data.txt.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.XHR.HTML",
+        description: "Get text/html content as text.",
+        _expression_: "createXHRForHTML()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "text/html", "MIMEType should be 'text/html'.");
+            InspectorTest.expectEqual(content, "<span>Hello World</span>\n", "Text content should match data.html.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.XHR.JSON",
+        description: "Get application/octet-stream content as text.",
+        _expression_: "createXHRForJSON()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "application/octet-stream", "MIMEType should be 'application/octet-stream'.");
+            InspectorTest.expectEqual(content, `{"json": true, "value": 42}\n`, "JSON content should match data.json.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.XHR.JSON2",
+        description: "Get application/json content as text.",
+        _expression_: "createXHRForJSON2()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "application/json", "MIMEType should be 'application/json'.");
+            InspectorTest.expectEqual(content, `{"json":true,"value":42}`, "JSON content should match specified content.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.XHR.JSON3",
+        description: "Get arbitrary +json content as text.",
+        _expression_: "createXHRForJSON3()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "application/vnd.api+json", "MIMEType should be 'application/vnd.api+json'.");
+            InspectorTest.expectEqual(content, `{"json":true,"value":999}`, "JSON content should match specified content.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.XHR.SVG",
+        description: "Get image/svg+xml content as text.",
+        _expression_: "createXHRForSVG()",
+        contentHandler({error, sourceCode, content}) {
+            InspectorTest.expectEqual(sourceCode.mimeType, "image/svg+xml", "MIMEType should be 'image/svg+xml'.");
+            InspectorTest.expectEqual(content,
+`<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 200">
+  <rect width="100%" height="50%" fill="green"/>
+</svg>
+`, "SVG content should be text.");
+        }
+    });
+
+    addTestCase({
+        name: "Network.getResponseBody.XHR.PNG",
+        description: "Get image/png content.",
+        _expression_: "createXHRForPNG()",
+        contentHandler({error, sourceCode, content}) {
+            // FIXME: <https://webkit.org/b/165495> Web Inspector: XHR / Fetch for non-text content should not show garbled text
+            InspectorTest.expectEqual(sourceCode.mimeType, "image/png", "MIMEType should be 'image/png'.");
+            InspectorTest.expectEqual(typeof content, "string", "Image content should be text.");
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<p>Tests for getting the content of XHR requests.</p>
+</body>
+</html>

Modified: trunk/Source/_javascript_Core/ChangeLog (209628 => 209629)


--- trunk/Source/_javascript_Core/ChangeLog	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-12-09 22:12:08 UTC (rev 209629)
@@ -1,3 +1,14 @@
+2016-12-09  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Some resources fetched via Fetch API do not have data
+        https://bugs.webkit.org/show_bug.cgi?id=165230
+        <rdar://problem/29449220>
+
+        Reviewed by Alex Christensen.
+
+        * inspector/protocol/Page.json:
+        Add new Fetch Page.ResourceType.
+
 2016-12-09  Geoffrey Garen  <gga...@apple.com>
 
         TextPosition and OrdinalNumber should be more like idiomatic numbers

Modified: trunk/Source/_javascript_Core/inspector/protocol/Page.json (209628 => 209629)


--- trunk/Source/_javascript_Core/inspector/protocol/Page.json	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/_javascript_Core/inspector/protocol/Page.json	2016-12-09 22:12:08 UTC (rev 209629)
@@ -6,7 +6,7 @@
         {
             "id": "ResourceType",
             "type": "string",
-            "enum": ["Document", "Stylesheet", "Image", "Font", "Script", "XHR", "WebSocket", "Other"],
+            "enum": ["Document", "Stylesheet", "Image", "Font", "Script", "XHR", "Fetch", "WebSocket", "Other"],
             "description": "Resource type as it was perceived by the rendering engine."
         },
         {

Modified: trunk/Source/WebCore/ChangeLog (209628 => 209629)


--- trunk/Source/WebCore/ChangeLog	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/ChangeLog	2016-12-09 22:12:08 UTC (rev 209629)
@@ -1,3 +1,57 @@
+2016-12-09  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Some resources fetched via Fetch API do not have data
+        https://bugs.webkit.org/show_bug.cgi?id=165230
+        <rdar://problem/29449220>
+
+        Reviewed by Alex Christensen.
+
+        Tests: http/tests/inspector/network/fetch-response-body.html
+               http/tests/inspector/network/xhr-response-body.html
+
+        * platform/network/ResourceRequestBase.h:
+        Distinguish Fetch requests.
+
+        * Modules/fetch/FetchRequest.cpp:
+        (WebCore::FetchRequest::initializeWith):
+        Set the requester type as Fetch.
+
+        * loader/DocumentThreadableLoader.cpp:
+        (WebCore::DocumentThreadableLoader::didReceiveResponse):
+        * loader/DocumentThreadableLoader.h:
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::didReceiveThreadableLoaderResponseImpl):
+        (WebCore::InspectorInstrumentation::didReceiveXHRResponseImpl): Deleted.
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::didReceiveResourceResponse):
+        (WebCore::InspectorInstrumentation::didReceiveThreadableLoaderResponse):
+        (WebCore::InspectorInstrumentation::didReceiveXHRResponse): Deleted.
+        * inspector/InspectorNetworkAgent.cpp:
+        (WebCore::InspectorNetworkAgent::didReceiveThreadableLoaderResponse):
+        (WebCore::InspectorNetworkAgent::didFinishXHRLoading):
+        (WebCore::InspectorNetworkAgent::didReceiveXHRResponse): Deleted.
+        Add a generic way for a ThreadableLoader load to update the type of a network request.
+        This will include both XHR and Fetch requests.
+
+        * inspector/InspectorPageAgent.cpp:
+        (WebCore::hasTextContent):
+        (WebCore::createXHRTextDecoder):
+        (WebCore::InspectorPageAgent::resourceTypeJson):
+        (WebCore::InspectorPageAgent::cachedResourceType):
+        (WebCore::InspectorPageAgent::createTextDecoder):
+        (WebCore::textContentForCachedResource):
+        * inspector/InspectorPageAgent.h:
+        * inspector/NetworkResourcesData.cpp:
+        (WebCore::createOtherResourceTextDecoder): Deleted.
+        Share the logic that creates a Text Decoders for XHR with other non-buffered requests
+        (like Fetch). This moves us to identical behavior for now.
+
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::isSupportedJSONMIMEType):
+        (WebCore::MIMETypeRegistry::isTextMIMEType):
+        * platform/MIMETypeRegistry.h:
+        Better detect different JSON content based on MIME Type.
+
 2016-12-09  Ryosuke Niwa  <rn...@webkit.org>
 
         document.webkitFullscreenElement leaks elements inside a shadow tree

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (209628 => 209629)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2016-12-09 22:12:08 UTC (rev 209629)
@@ -151,6 +151,7 @@
     m_internalRequest.options.credentials = Credentials::Omit;
     m_internalRequest.referrer = ASCIILiteral("client");
     m_internalRequest.request.setURL(requestURL);
+    m_internalRequest.request.setRequester(ResourceRequest::Requester::Fetch);
     m_internalRequest.request.setInitiatorIdentifier(scriptExecutionContext()->resourceRequestIdentifier());
 
     return initializeOptions(init);

Modified: trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp (209628 => 209629)


--- trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp	2016-12-09 22:12:08 UTC (rev 209629)
@@ -1261,7 +1261,6 @@
         *nodeId = 0;
 }
 
-// static
 String InspectorDOMAgent::documentURLString(Document* document)
 {
     if (!document || document->url().isNull())

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (209628 => 209629)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2016-12-09 22:12:08 UTC (rev 209629)
@@ -627,6 +627,12 @@
     didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
 }
 
+void InspectorInstrumentation::didReceiveThreadableLoaderResponseImpl(InstrumentingAgents& instrumentingAgents, DocumentThreadableLoader& documentThreadableLoader, unsigned long identifier)
+{
+    if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
+        networkAgent->didReceiveThreadableLoaderResponse(identifier, documentThreadableLoader);
+}
+
 void InspectorInstrumentation::didReceiveDataImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
 {
     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
@@ -663,12 +669,6 @@
     }
 }
 
-void InspectorInstrumentation::didReceiveXHRResponseImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier)
-{
-    if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
-        networkAgent->didReceiveXHRResponse(identifier);
-}
-
 void InspectorInstrumentation::willLoadXHRSynchronouslyImpl(InstrumentingAgents& instrumentingAgents)
 {
     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (209628 => 209629)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2016-12-09 22:12:08 UTC (rev 209629)
@@ -32,6 +32,7 @@
 #pragma once
 
 #include "CSSSelector.h"
+#include "DocumentThreadableLoader.h"
 #include "Element.h"
 #include "FormData.h"
 #include "Frame.h"
@@ -158,11 +159,11 @@
     static void continueAfterXFrameOptionsDenied(Frame*, DocumentLoader&, unsigned long identifier, const ResourceResponse&);
     static void continueWithPolicyDownload(Frame*, DocumentLoader&, unsigned long identifier, const ResourceResponse&);
     static void continueWithPolicyIgnore(Frame*, DocumentLoader&, unsigned long identifier, const ResourceResponse&);
+    static void didReceiveThreadableLoaderResponse(DocumentThreadableLoader&, unsigned long identifier);
     static void didReceiveData(Frame*, unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
     static void didFinishLoading(Frame*, DocumentLoader*, unsigned long identifier, double finishTime);
     static void didFailLoading(Frame*, DocumentLoader*, unsigned long identifier, const ResourceError&);
     static void didFinishXHRLoading(ScriptExecutionContext*, unsigned long identifier, std::optional<String> decodedText, const String& url, const String& sendURL, unsigned sendLineNumber, unsigned sendColumnNumber);
-    static void didReceiveXHRResponse(ScriptExecutionContext*, unsigned long identifier);
     static void willLoadXHRSynchronously(ScriptExecutionContext*);
     static void didLoadXHRSynchronously(ScriptExecutionContext*);
     static void scriptImported(ScriptExecutionContext&, unsigned long identifier, const String& sourceString);
@@ -329,11 +330,11 @@
     static void continueAfterXFrameOptionsDeniedImpl(Frame*, DocumentLoader&, unsigned long identifier, const ResourceResponse&);
     static void continueWithPolicyDownloadImpl(Frame*, DocumentLoader&, unsigned long identifier, const ResourceResponse&);
     static void continueWithPolicyIgnoreImpl(Frame*, DocumentLoader&, unsigned long identifier, const ResourceResponse&);
+    static void didReceiveThreadableLoaderResponseImpl(InstrumentingAgents&, DocumentThreadableLoader&, unsigned long identifier);
     static void didReceiveDataImpl(InstrumentingAgents&, unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
     static void didFinishLoadingImpl(InstrumentingAgents&, unsigned long identifier, DocumentLoader*, double finishTime);
     static void didFailLoadingImpl(InstrumentingAgents&, unsigned long identifier, DocumentLoader*, const ResourceError&);
     static void didFinishXHRLoadingImpl(InstrumentingAgents&, unsigned long identifier, std::optional<String> decodedText, const String& url, const String& sendURL, unsigned sendLineNumber, unsigned sendColumnNumber);
-    static void didReceiveXHRResponseImpl(InstrumentingAgents&, unsigned long identifier);
     static void willLoadXHRSynchronouslyImpl(InstrumentingAgents&);
     static void didLoadXHRSynchronouslyImpl(InstrumentingAgents&);
     static void scriptImportedImpl(InstrumentingAgents&, unsigned long identifier, const String& sourceString);
@@ -859,8 +860,7 @@
 inline void InspectorInstrumentation::didReceiveResourceResponse(const InspectorInstrumentationCookie& cookie, unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
 {
     // Call this unconditionally so that we're able to log to console with no front-end attached.
-    if (cookie.isValid())
-        didReceiveResourceResponseImpl(cookie, identifier, loader, response, resourceLoader);
+    didReceiveResourceResponseImpl(cookie, identifier, loader, response, resourceLoader);
 }
 
 inline void InspectorInstrumentation::continueAfterXFrameOptionsDenied(Frame* frame, DocumentLoader& loader, unsigned long identifier, const ResourceResponse& r)
@@ -881,6 +881,12 @@
     InspectorInstrumentation::continueWithPolicyIgnoreImpl(frame, loader, identifier, r);
 }
 
+inline void InspectorInstrumentation::didReceiveThreadableLoaderResponse(DocumentThreadableLoader& documentThreadableLoader, unsigned long identifier)
+{
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(documentThreadableLoader.document()))
+        didReceiveThreadableLoaderResponseImpl(*instrumentingAgents, documentThreadableLoader, identifier);
+}
+    
 inline void InspectorInstrumentation::didReceiveData(Frame* frame, unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
 {
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
@@ -905,12 +911,6 @@
         didFinishXHRLoadingImpl(*instrumentingAgents, identifier, decodedText, url, sendURL, sendLineNumber, sendColumnNumber);
 }
 
-inline void InspectorInstrumentation::didReceiveXHRResponse(ScriptExecutionContext* context, unsigned long identifier)
-{
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
-        didReceiveXHRResponseImpl(*instrumentingAgents, identifier);
-}
-
 inline void InspectorInstrumentation::willLoadXHRSynchronously(ScriptExecutionContext* context)
 {
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))

Modified: trunk/Source/WebCore/inspector/InspectorNetworkAgent.cpp (209628 => 209629)


--- trunk/Source/WebCore/inspector/InspectorNetworkAgent.cpp	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/inspector/InspectorNetworkAgent.cpp	2016-12-09 22:12:08 UTC (rev 209629)
@@ -35,6 +35,7 @@
 #include "CachedRawResource.h"
 #include "CachedResource.h"
 #include "CachedResourceLoader.h"
+#include "CachedResourceRequestInitiators.h"
 #include "Document.h"
 #include "DocumentLoader.h"
 #include "DocumentThreadableLoader.h"
@@ -450,14 +451,18 @@
     m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::ScriptResource);
 }
 
-void InspectorNetworkAgent::didFinishXHRLoading(unsigned long identifier, const String& decodedText)
+void InspectorNetworkAgent::didReceiveThreadableLoaderResponse(unsigned long identifier, DocumentThreadableLoader& documentThreadableLoader)
 {
-    m_resourcesData->setResourceContent(IdentifiersFactory::requestId(identifier), decodedText);
+    String initiator = documentThreadableLoader.options().initiator;
+    if (initiator == cachedResourceRequestInitiators().fetch)
+        m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::FetchResource);
+    else if (initiator == cachedResourceRequestInitiators().xmlhttprequest)
+        m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::XHRResource);
 }
 
-void InspectorNetworkAgent::didReceiveXHRResponse(unsigned long identifier)
+void InspectorNetworkAgent::didFinishXHRLoading(unsigned long identifier, const String& decodedText)
 {
-    m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::XHRResource);
+    m_resourcesData->setResourceContent(IdentifiersFactory::requestId(identifier), decodedText);
 }
 
 void InspectorNetworkAgent::willLoadXHRSynchronously()

Modified: trunk/Source/WebCore/inspector/InspectorNetworkAgent.h (209628 => 209629)


--- trunk/Source/WebCore/inspector/InspectorNetworkAgent.h	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/inspector/InspectorNetworkAgent.h	2016-12-09 22:12:08 UTC (rev 209629)
@@ -47,6 +47,7 @@
 class CachedResource;
 class Document;
 class DocumentLoader;
+class DocumentThreadableLoader;
 class InspectorPageAgent;
 class NetworkLoadTiming;
 class NetworkResourcesData;
@@ -81,8 +82,8 @@
     void didFinishLoading(unsigned long identifier, DocumentLoader&, double finishTime);
     void didFailLoading(unsigned long identifier, DocumentLoader&, const ResourceError&);
     void didLoadResourceFromMemoryCache(DocumentLoader&, CachedResource&);
+    void didReceiveThreadableLoaderResponse(unsigned long identifier, DocumentThreadableLoader&);
     void didFinishXHRLoading(unsigned long identifier, const String& decodedText);
-    void didReceiveXHRResponse(unsigned long identifier);
     void willLoadXHRSynchronously();
     void didLoadXHRSynchronously();
     void didReceiveScriptResponse(unsigned long identifier);

Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (209628 => 209629)


--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp	2016-12-09 22:12:08 UTC (rev 209629)
@@ -114,28 +114,17 @@
 
 static bool hasTextContent(CachedResource* cachedResource)
 {
+    // FIXME: <https://webkit.org/b/165495> Web Inspector: XHR / Fetch for non-text content should not show garbled text
+    // We should not assume XHR / Fetch have text content.
+
     InspectorPageAgent::ResourceType type = InspectorPageAgent::cachedResourceType(*cachedResource);
     return type == InspectorPageAgent::DocumentResource
         || type == InspectorPageAgent::StylesheetResource
         || type == InspectorPageAgent::ScriptResource
-        || type == InspectorPageAgent::XHRResource;
+        || type == InspectorPageAgent::XHRResource
+        || type == InspectorPageAgent::FetchResource;
 }
 
-static RefPtr<TextResourceDecoder> createXHRTextDecoder(const String& mimeType, const String& textEncodingName)
-{
-    RefPtr<TextResourceDecoder> decoder;
-    if (!textEncodingName.isEmpty())
-        decoder = TextResourceDecoder::create("text/plain", textEncodingName);
-    else if (MIMETypeRegistry::isXMLMIMEType(mimeType)) {
-        decoder = TextResourceDecoder::create("application/xml");
-        decoder->useLenientXMLDecoding();
-    } else if (equalLettersIgnoringASCIICase(mimeType, "text/html"))
-        decoder = TextResourceDecoder::create("text/html", "UTF-8");
-    else
-        decoder = TextResourceDecoder::create("text/plain", "UTF-8");
-    return decoder;
-}
-
 bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, String* result, bool* base64Encoded)
 {
     // FIXME: result should be a String& and base64Encoded should be a bool&.
@@ -176,7 +165,7 @@
             auto* buffer = cachedResource->resourceBuffer();
             if (!buffer)
                 return false;
-            RefPtr<TextResourceDecoder> decoder = createXHRTextDecoder(cachedResource->response().mimeType(), cachedResource->response().textEncodingName());
+            RefPtr<TextResourceDecoder> decoder = InspectorPageAgent::createTextDecoder(cachedResource->response().mimeType(), cachedResource->response().textEncodingName());
             // We show content for raw resources only for certain mime types (text, html and xml). Otherwise decoder will be null.
             if (!decoder)
                 return false;
@@ -199,7 +188,6 @@
     return InspectorPageAgent::dataContent(buffer->data(), buffer->size(), frame->document()->encoding(), withBase64Encode, result);
 }
 
-// static
 bool InspectorPageAgent::sharedBufferContent(RefPtr<SharedBuffer>&& buffer, const String& textEncodingName, bool withBase64Encode, String* result)
 {
     return dataContent(buffer ? buffer->data() : nullptr, buffer ? buffer->size() : 0, textEncodingName, withBase64Encode, result);
@@ -215,7 +203,6 @@
     return decodeBuffer(data, size, textEncodingName, result);
 }
 
-// static
 void InspectorPageAgent::resourceContent(ErrorString& errorString, Frame* frame, const URL& url, String* result, bool* base64Encoded)
 {
     DocumentLoader* loader = assertDocumentLoader(errorString, frame);
@@ -297,6 +284,8 @@
         return Inspector::Protocol::Page::ResourceType::Script;
     case XHRResource:
         return Inspector::Protocol::Page::ResourceType::XHR;
+    case FetchResource:
+        return Inspector::Protocol::Page::ResourceType::Fetch;
     case WebSocketResource:
         return Inspector::Protocol::Page::ResourceType::WebSocket;
     case OtherResource:
@@ -315,19 +304,26 @@
 #endif
     case CachedResource::FontResource:
         return InspectorPageAgent::FontResource;
-    case CachedResource::CSSStyleSheet:
-        // Fall through.
 #if ENABLE(XSLT)
     case CachedResource::XSLStyleSheet:
 #endif
+    case CachedResource::CSSStyleSheet:
         return InspectorPageAgent::StylesheetResource;
     case CachedResource::Script:
         return InspectorPageAgent::ScriptResource;
-    case CachedResource::MediaResource:
-    case CachedResource::RawResource:
-        return InspectorPageAgent::XHRResource;
     case CachedResource::MainResource:
         return InspectorPageAgent::DocumentResource;
+    case CachedResource::MediaResource:
+    case CachedResource::RawResource: {
+        switch (cachedResource.resourceRequest().requester()) {
+        case ResourceRequest::Requester::Fetch:
+            return InspectorPageAgent::FetchResource;
+        case ResourceRequest::Requester::Main:
+            return InspectorPageAgent::DocumentResource;
+        default:
+            return InspectorPageAgent::XHRResource;
+        }
+    }
     default:
         break;
     }
@@ -339,6 +335,23 @@
     return resourceTypeJson(cachedResourceType(cachedResource));
 }
 
+RefPtr<TextResourceDecoder> InspectorPageAgent::createTextDecoder(const String& mimeType, const String& textEncodingName)
+{
+    if (!textEncodingName.isEmpty())
+        return TextResourceDecoder::create(ASCIILiteral("text/plain"), textEncodingName);
+
+    if (MIMETypeRegistry::isTextMIMEType(mimeType))
+        return TextResourceDecoder::create(mimeType, "UTF-8");
+
+    if (MIMETypeRegistry::isXMLMIMEType(mimeType)) {
+        RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create(ASCIILiteral("application/xml"));
+        decoder->useLenientXMLDecoding();
+        return decoder;
+    }
+
+    return TextResourceDecoder::create(ASCIILiteral("text/plain"), "UTF-8");
+}
+
 InspectorPageAgent::InspectorPageAgent(PageAgentContext& context, InspectorClient* client, InspectorOverlay* overlay)
     : InspectorAgentBase(ASCIILiteral("Page"), context)
     , m_frontendDispatcher(std::make_unique<Inspector::PageFrontendDispatcher>(context.frontendRouter))
@@ -562,7 +575,6 @@
 static bool textContentForCachedResource(CachedResource* cachedResource, String* result)
 {
     if (hasTextContent(cachedResource)) {
-        String content;
         bool base64Encoded;
         if (InspectorPageAgent::cachedResourceContent(cachedResource, result, &base64Encoded)) {
             ASSERT(!base64Encoded);
@@ -768,7 +780,6 @@
     return frame;
 }
 
-// static
 DocumentLoader* InspectorPageAgent::assertDocumentLoader(ErrorString& errorString, Frame* frame)
 {
     FrameLoader& frameLoader = frame->loader();

Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.h (209628 => 209629)


--- trunk/Source/WebCore/inspector/InspectorPageAgent.h	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.h	2016-12-09 22:12:08 UTC (rev 209629)
@@ -51,10 +51,11 @@
 class InspectorClient;
 class InspectorOverlay;
 class MainFrame;
-class URL;
 class Page;
 class RenderObject;
 class SharedBuffer;
+class TextResourceDecoder;
+class URL;
 
 typedef String ErrorString;
 
@@ -71,6 +72,7 @@
         FontResource,
         ScriptResource,
         XHRResource,
+        FetchResource,
         WebSocketResource,
         OtherResource
     };
@@ -84,6 +86,7 @@
     static Inspector::Protocol::Page::ResourceType resourceTypeJson(ResourceType);
     static ResourceType cachedResourceType(const CachedResource&);
     static Inspector::Protocol::Page::ResourceType cachedResourceTypeJson(const CachedResource&);
+    static RefPtr<TextResourceDecoder> createTextDecoder(const String& mimeType, const String& textEncodingName);
 
     // Page API for InspectorFrontend
     void enable(ErrorString&) override;

Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (209628 => 209629)


--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2016-12-09 22:12:08 UTC (rev 209629)
@@ -805,7 +805,6 @@
     return adoptRef(*new InspectorStyleSheet(pageAgent, id, WTFMove(pageStyleSheet), origin, documentURL, listener));
 }
 
-// static
 String InspectorStyleSheet::styleSheetURL(CSSStyleSheet* pageStyleSheet)
 {
     if (pageStyleSheet && !pageStyleSheet->contents().baseURL().isEmpty())

Modified: trunk/Source/WebCore/inspector/NetworkResourcesData.cpp (209628 => 209629)


--- trunk/Source/WebCore/inspector/NetworkResourcesData.cpp	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/inspector/NetworkResourcesData.cpp	2016-12-09 22:12:08 UTC (rev 209629)
@@ -129,21 +129,6 @@
     m_requestIdToResourceDataMap.set(requestId, new ResourceData(requestId, loaderId));
 }
 
-static RefPtr<TextResourceDecoder> createOtherResourceTextDecoder(const String& mimeType, const String& textEncodingName)
-{
-    RefPtr<TextResourceDecoder> decoder;
-    if (!textEncodingName.isEmpty())
-        decoder = TextResourceDecoder::create("text/plain", textEncodingName);
-    else if (MIMETypeRegistry::isXMLMIMEType(mimeType)) {
-        decoder = TextResourceDecoder::create("application/xml");
-        decoder->useLenientXMLDecoding();
-    } else if (equalLettersIgnoringASCIICase(mimeType, "text/html"))
-        decoder = TextResourceDecoder::create("text/html", "UTF-8");
-    else if (mimeType == "text/plain")
-        decoder = TextResourceDecoder::create("text/plain", "ISO-8859-1");
-    return decoder;
-}
-
 void NetworkResourcesData::responseReceived(const String& requestId, const String& frameId, const ResourceResponse& response)
 {
     ResourceData* resourceData = resourceDataForRequestId(requestId);
@@ -151,7 +136,7 @@
         return;
     resourceData->setFrameId(frameId);
     resourceData->setUrl(response.url());
-    resourceData->setDecoder(createOtherResourceTextDecoder(response.mimeType(), response.textEncodingName()));
+    resourceData->setDecoder(InspectorPageAgent::createTextDecoder(response.mimeType(), response.textEncodingName()));
     resourceData->setHTTPStatusCode(response.httpStatusCode());
 }
 

Modified: trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp (209628 => 209629)


--- trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp	2016-12-09 22:12:08 UTC (rev 209629)
@@ -294,6 +294,8 @@
 {
     ASSERT(m_client);
 
+    InspectorInstrumentation::didReceiveThreadableLoaderResponse(*this, identifier);
+
     ASSERT(response.type() != ResourceResponse::Type::Error);
     if (response.type() == ResourceResponse::Type::Default) {
         m_client->didReceiveResponse(identifier, ResourceResponse::filterResponse(response, tainting));

Modified: trunk/Source/WebCore/loader/DocumentThreadableLoader.h (209628 => 209629)


--- trunk/Source/WebCore/loader/DocumentThreadableLoader.h	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/loader/DocumentThreadableLoader.h	2016-12-09 22:12:08 UTC (rev 209629)
@@ -58,6 +58,8 @@
         virtual void setDefersLoading(bool);
 
         friend CrossOriginPreflightChecker;
+        friend class InspectorInstrumentation;
+        friend class InspectorNetworkAgent;
 
         using RefCounted<DocumentThreadableLoader>::ref;
         using RefCounted<DocumentThreadableLoader>::deref;

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (209628 => 209629)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2016-12-09 22:12:08 UTC (rev 209629)
@@ -516,6 +516,24 @@
     return supportedJavaScriptMIMETypes->contains(mimeType);
 }
 
+bool MIMETypeRegistry::isSupportedJSONMIMEType(const String& mimeType)
+{
+    if (mimeType.isEmpty())
+        return false;
+
+    if (equalLettersIgnoringASCIICase(mimeType, "application/json"))
+        return true;
+
+    // When detecting +json ensure there is a non-empty type / subtype preceeding the suffix.
+    if (mimeType.endsWith("+json", false) && mimeType.length() >= 8) {
+        size_t slashPosition = mimeType.find('/');
+        if (slashPosition != notFound && slashPosition > 0 && slashPosition <= mimeType.length() - 6)
+            return true;
+    }
+
+    return false;
+}
+
 bool MIMETypeRegistry::isSupportedNonImageMIMEType(const String& mimeType)
 {
     if (mimeType.isEmpty())
@@ -546,7 +564,7 @@
 bool MIMETypeRegistry::isTextMIMEType(const String& mimeType)
 {
     return isSupportedJavaScriptMIMEType(mimeType)
-        || equalLettersIgnoringASCIICase(mimeType, "application/json") // Render JSON as text/plain.
+        || isSupportedJSONMIMEType(mimeType) // Render JSON as text/plain.
         || (mimeType.startsWith("text/", false)
             && !equalLettersIgnoringASCIICase(mimeType, "text/html")
             && !equalLettersIgnoringASCIICase(mimeType, "text/xml")

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.h (209628 => 209629)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.h	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.h	2016-12-09 22:12:08 UTC (rev 209629)
@@ -54,8 +54,9 @@
     // Check to see if a MIME type is suitable for being encoded.
     static bool isSupportedImageMIMETypeForEncoding(const String& mimeType);
 
-    // Check to see if a MIME type is suitable for being loaded as a _javascript_ resource.
-    static bool isSupportedJavaScriptMIMEType(const String& mimeType);    
+    // Check to see if a MIME type is suitable for being loaded as a _javascript_ or JSON resource.
+    static bool isSupportedJavaScriptMIMEType(const String& mimeType);
+    static bool isSupportedJSONMIMEType(const String& mimeType);
 
     // Check to see if a non-image MIME type is suitable for being loaded as a
     // document in a frame. Includes supported _javascript_ MIME types.

Modified: trunk/Source/WebCore/platform/network/ResourceRequestBase.h (209628 => 209629)


--- trunk/Source/WebCore/platform/network/ResourceRequestBase.h	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/platform/network/ResourceRequestBase.h	2016-12-09 22:12:08 UTC (rev 209629)
@@ -160,7 +160,7 @@
     bool ignoreForRequestCount() const { return m_ignoreForRequestCount; }
     void setIgnoreForRequestCount(bool ignoreForRequestCount) { m_ignoreForRequestCount = ignoreForRequestCount; }
 
-    enum class Requester { Unspecified, Main, XHR, Media };
+    enum class Requester { Unspecified, Main, XHR, Fetch, Media };
     Requester requester() const { return m_requester; }
     void setRequester(Requester requester) { m_requester = requester; }
 

Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (209628 => 209629)


--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2016-12-09 22:12:08 UTC (rev 209629)
@@ -1015,10 +1015,8 @@
     }
 }
 
-void XMLHttpRequest::didReceiveResponse(unsigned long identifier, const ResourceResponse& response)
+void XMLHttpRequest::didReceiveResponse(unsigned long, const ResourceResponse& response)
 {
-    InspectorInstrumentation::didReceiveXHRResponse(scriptExecutionContext(), identifier);
-
     m_response = response;
     if (!m_mimeTypeOverride.isEmpty())
         m_response.setHTTPHeaderField(HTTPHeaderName::ContentType, m_mimeTypeOverride);

Modified: trunk/Source/WebInspectorUI/ChangeLog (209628 => 209629)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-12-09 22:12:08 UTC (rev 209629)
@@ -1,3 +1,26 @@
+2016-12-09  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Some resources fetched via Fetch API do not have data
+        https://bugs.webkit.org/show_bug.cgi?id=165230
+        <rdar://problem/29449220>
+
+        Reviewed by Alex Christensen.
+
+        * Localizations/en.lproj/localizedStrings.js:
+        New "Fetch" and "Fetches" localized strings.
+
+        * UserInterface/Models/Resource.js:
+        (WebInspector.Resource.displayNameForType):
+        * UserInterface/Models/ResourceCollection.js:
+        (WebInspector.ResourceCollection.verifierForType):
+        * UserInterface/Views/CollectionContentView.js:
+        (WebInspector.CollectionContentView):
+        * UserInterface/Views/ResourceClusterContentView.js:
+        (WebInspector.ResourceClusterContentView.prototype.get responseContentView):
+        * UserInterface/Views/ResourceTreeElement.js:
+        (WebInspector.ResourceTreeElement.compareResourceTreeElements):
+        New ResourceType.Fetch. Behave like XHR in most places.
+
 2016-12-08  Joseph Pecoraro  <pecor...@apple.com>
 
         Web Inspector: Unable to delete breakpoint from worker script

Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (209628 => 209629)


--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2016-12-09 22:12:08 UTC (rev 209629)
@@ -346,6 +346,8 @@
 localizedStrings["Failed to upgrade"] = "Failed to upgrade";
 localizedStrings["Family"] = "Family";
 localizedStrings["Features"] = "Features";
+localizedStrings["Fetch"] = "Fetch";
+localizedStrings["Fetches"] = "Fetches";
 localizedStrings["File or Resource"] = "File or Resource";
 localizedStrings["Filename"] = "Filename";
 localizedStrings["Fill"] = "Fill";

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js (209628 => 209629)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js	2016-12-09 22:12:08 UTC (rev 209629)
@@ -114,6 +114,10 @@
             if (plural)
                 return WebInspector.UIString("XHRs");
             return WebInspector.UIString("XHR");
+        case WebInspector.Resource.Type.Fetch:
+            if (plural)
+                return WebInspector.UIString("Fetches");
+            return WebInspector.UIString("Fetch");
         case WebInspector.Resource.Type.WebSocket:
             if (plural)
                 return WebInspector.UIString("Sockets");
@@ -753,6 +757,7 @@
     Font: "resource-type-font",
     Script: "resource-type-script",
     XHR: "resource-type-xhr",
+    Fetch: "resource-type-fetch",
     WebSocket: "resource-type-websocket",
     Other: "resource-type-other"
 };

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/ResourceCollection.js (209628 => 209629)


--- trunk/Source/WebInspectorUI/UserInterface/Models/ResourceCollection.js	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/ResourceCollection.js	2016-12-09 22:12:08 UTC (rev 209629)
@@ -51,6 +51,8 @@
             return WebInspector.ResourceCollection.TypeVerifier.Script;
         case WebInspector.Resource.Type.XHR:
             return WebInspector.ResourceCollection.TypeVerifier.XHR;
+        case WebInspector.Resource.Type.Fetch:
+            return WebInspector.ResourceCollection.TypeVerifier.Fetch;
         case WebInspector.Resource.Type.WebSocket:
             return WebInspector.ResourceCollection.TypeVerifier.WebSocket;
         case WebInspector.Resource.Type.Other:
@@ -191,6 +193,7 @@
     Font: (object) => WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.Font,
     Script: (object) => WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.Script,
     XHR: (object) => WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.XHR,
+    Fetch: (object) => WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.Fetch,
     WebSocket: (object) => WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.WebSocket,
     Other: (object) => WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.Other,
 };

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CollectionContentView.js (209628 => 209629)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CollectionContentView.js	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CollectionContentView.js	2016-12-09 22:12:08 UTC (rev 209629)
@@ -81,6 +81,10 @@
             title = WebInspector.Resource.displayNameForType(WebInspector.Resource.Type.XHR, true);
             break;
 
+        case WebInspector.ResourceCollection.TypeVerifier.Fetch:
+            title = WebInspector.Resource.displayNameForType(WebInspector.Resource.Type.Fetch, true);
+            break;
+
         case WebInspector.ResourceCollection.TypeVerifier.WebSocket:
             title = WebInspector.Resource.displayNameForType(WebInspector.Resource.Type.WebSocket, true);
             break;

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceClusterContentView.js (209628 => 209629)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceClusterContentView.js	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceClusterContentView.js	2016-12-09 22:12:08 UTC (rev 209629)
@@ -65,7 +65,13 @@
         case WebInspector.Resource.Type.Document:
         case WebInspector.Resource.Type.Script:
         case WebInspector.Resource.Type.Stylesheet:
+            this._responseContentView = new WebInspector.TextResourceContentView(this._resource);
+            break;
+
         case WebInspector.Resource.Type.XHR:
+        case WebInspector.Resource.Type.Fetch:
+            // FIXME: <https://webkit.org/b/165495> Web Inspector: XHR / Fetch for non-text content should not show garbled text
+            // XHR / Fetch content may not always be text.
             this._responseContentView = new WebInspector.TextResourceContentView(this._resource);
             break;
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js (209628 => 209629)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js	2016-12-09 22:06:29 UTC (rev 209628)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js	2016-12-09 22:12:08 UTC (rev 209629)
@@ -44,7 +44,9 @@
             return comparisonResult;
 
         // Compare async resource types by their first timestamp so they are in chronological order.
-        if (a.resource.type === WebInspector.Resource.Type.XHR || a.resource.type === WebInspector.Resource.Type.WebSocket)
+        if (a.resource.type === WebInspector.Resource.Type.XHR
+            || a.resource.type === WebInspector.Resource.Type.Fetch
+            || a.resource.type === WebInspector.Resource.Type.WebSocket)
             return a.resource.firstTimestamp - b.resource.firstTimestamp || 0;
 
         // Compare by subtitle when the types are the same. The subtitle is used to show the
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to