Title: [225546] trunk
Revision
225546
Author
[email protected]
Date
2017-12-05 14:09:36 -0800 (Tue, 05 Dec 2017)

Log Message

Web Inspector: content views for resources loaded through XHR do not reflect declared mime-type
https://bugs.webkit.org/show_bug.cgi?id=141389
<rdar://problem/19767070>

Patch by Joseph Pecoraro <[email protected]> on 2017-12-05
Reviewed by Brian Burg.

Source/WebCore:

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

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::didFinishLoading):
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::didFinishXHRLoadingImpl): Deleted.
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::didFinishXHRLoading): Deleted.
Remove special handling of XHR content that decoded output as text.

* inspector/NetworkResourcesData.h:
(WebCore::NetworkResourcesData::ResourceData::requestId const):
(WebCore::NetworkResourcesData::ResourceData::loaderId const):
(WebCore::NetworkResourcesData::ResourceData::frameId const):
(WebCore::NetworkResourcesData::ResourceData::url const):
(WebCore::NetworkResourcesData::ResourceData::content const):
(WebCore::NetworkResourcesData::ResourceData::isContentEvicted const):
(WebCore::NetworkResourcesData::ResourceData::textEncodingName const):
* inspector/NetworkResourcesData.cpp:
(WebCore::NetworkResourcesData::ResourceData::ResourceData):
(WebCore::NetworkResourcesData::ResourceData::decodeDataToContent):
(WebCore::NetworkResourcesData::responseReceived):
(WebCore::NetworkResourcesData::setResourceContent):
(WebCore::shouldBufferResourceData):
(WebCore::NetworkResourcesData::maybeAddResourceData):
(WebCore::NetworkResourcesData::maybeDecodeDataToContent):

Make NetworkResourcesData only create a text decoder for resources we
really think are text, and buffer resource data if it is text data
or if it is a resource that would otherwise not be buffered by WebCore
(such as XHRs with a DoNotBufferData policy). This ensures that the
Inspector will have data to show for resources that won't be cached.

* inspector/agents/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::resourceContent):
(WebCore::InspectorPageAgent::sourceMapURLForResource):
(WebCore::InspectorPageAgent::searchInResource):
(WebCore::InspectorPageAgent::searchInResources):
(WebCore::hasTextContent): Deleted.
(WebCore::InspectorPageAgent::cachedResourceContent): Deleted.
(WebCore::InspectorPageAgent::createTextDecoder): Deleted.
(WebCore::textContentForCachedResource): Deleted.
* inspector/agents/InspectorPageAgent.h:
* inspector/agents/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::didReceiveData):
(WebCore::InspectorNetworkAgent::willDestroyCachedResource):
(WebCore::InspectorNetworkAgent::getResponseBody):
(WebCore::InspectorNetworkAgent::shouldTreatAsText):
(WebCore::InspectorNetworkAgent::createTextDecoder):
(WebCore::InspectorNetworkAgent::textContentForCachedResource):
(WebCore::InspectorNetworkAgent::cachedResourceContent):
(WebCore::textContentForResourceData):
(WebCore::InspectorNetworkAgent::searchOtherRequests):
(WebCore::isErrorStatusCode): Deleted.
(WebCore::InspectorNetworkAgent::didFinishXHRLoading): Deleted.
* inspector/agents/InspectorNetworkAgent.h:
Move static PageAgent functions related to the generic data tuple
(content, base64Encoded) to NetworkAgent. Also generalize it to
not rely on the CachedResourceType, but instead rely on the MIME type.
This has a few changes in behavior:

    - Images, may now be text if they have a text mime type (image/svg+xml).
    - XHR / Fetch / Other may be sent as text if they have a text mime type.
    - XHR / Fetch / Other are not assumed to be text, and may be sent as base64 encoded.

For this to be useful the frontend should also check the mime type and
display an appropriate ContentView.

Source/WebInspectorUI:

* UserInterface/Base/Utilities.js:
Blob <-> Text conversion helpers.

* UserInterface/Models/Resource.js:
(WI.Resource.prototype.createObjectURL):
Previously all Image resources were assumed to have base64Encoded data
which we automatically convert to a Blob. Now that some image data
can be transfered as text, convert that to a Blob here since the output
is expected to be a Blob.

* UserInterface/Views/ResourceContentView.js:
(WI.ResourceContentView.prototype.showGenericNoContentMessage):
* UserInterface/Views/TextResourceContentView.js:
(WI.TextResourceContentView.prototype.contentAvailable):
(WI.TextResourceContentView.prototype._contentDidPopulate):
* UserInterface/Views/ImageResourceContentView.js:
(WI.ImageResourceContentView.prototype.contentAvailable):
Better handle no content cases.

* UserInterface/Views/ResourceClusterContentView.js:
(WI.ResourceClusterContentView.prototype.get responseContentView):
(WI.ResourceClusterContentView.prototype._contentViewForResourceType):
Make a best effort to find a good ContentView to show the resource data.
This is done by looking at the ResourceType and MIME Type.

* UserInterface/Views/SVGImageResourceClusterContentView.js:
(WI.SVGImageResourceClusterContentView.prototype._showContentViewForIdentifier):
Handle if image data is now text (the image/svg+xml case).

LayoutTests:

* http/tests/inspector/network/fetch-response-body-expected.txt:
* http/tests/inspector/network/fetch-response-body.html:
* http/tests/inspector/network/xhr-response-body-expected.txt:
* http/tests/inspector/network/xhr-response-body.html:
Update tests for new expectations now that binary data shows as binary.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225545 => 225546)


--- trunk/LayoutTests/ChangeLog	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/LayoutTests/ChangeLog	2017-12-05 22:09:36 UTC (rev 225546)
@@ -1,3 +1,17 @@
+2017-12-05  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: content views for resources loaded through XHR do not reflect declared mime-type
+        https://bugs.webkit.org/show_bug.cgi?id=141389
+        <rdar://problem/19767070>
+
+        Reviewed by Brian Burg.
+
+        * http/tests/inspector/network/fetch-response-body-expected.txt:
+        * http/tests/inspector/network/fetch-response-body.html:
+        * http/tests/inspector/network/xhr-response-body-expected.txt:
+        * http/tests/inspector/network/xhr-response-body.html:
+        Update tests for new expectations now that binary data shows as binary.        
+
 2017-12-05  Youenn Fablet  <[email protected]>
 
         Implement https://w3c.github.io/ServiceWorker/#clients-claim

Modified: trunk/LayoutTests/http/tests/inspector/network/fetch-response-body-expected.txt (225545 => 225546)


--- trunk/LayoutTests/http/tests/inspector/network/fetch-response-body-expected.txt	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/LayoutTests/http/tests/inspector/network/fetch-response-body-expected.txt	2017-12-05 22:09:36 UTC (rev 225546)
@@ -5,35 +5,42 @@
 -- Running test case: Network.getResponseBody.Fetch.Text
 PASS: Resource should be Fetch type.
 PASS: MIMEType should be 'text/plain'.
+PASS: Content should not be base64Encoded.
 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: Content should not be base64Encoded.
 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: Content should be base64Encoded.
 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: Content should not be base64Encoded.
 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: Content should not be base64Encoded.
 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: Content should not be base64Encoded.
 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.
+PASS: Content should be base64Encoded.
+PASS: Image content should be a Blob.
 

Modified: trunk/LayoutTests/http/tests/inspector/network/fetch-response-body.html (225545 => 225546)


--- trunk/LayoutTests/http/tests/inspector/network/fetch-response-body.html	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/LayoutTests/http/tests/inspector/network/fetch-response-body.html	2017-12-05 22:09:36 UTC (rev 225546)
@@ -36,6 +36,18 @@
 {
     let suite = InspectorTest.createAsyncSuite("Network.getResponseBody.Fetch");
 
+    function contentAsText(content) {
+        return new Promise((resolve) => {
+            if (typeof content === "string") {
+                resolve(content)
+                return;
+            }
+            blobAsText(content, (text) => {
+                resolve(text);
+            });
+        });
+    }
+
     function addTestCase({name, description, _expression_, contentHandler}) {
         suite.addTestCase({
             name, description,
@@ -57,8 +69,9 @@
         name: "Network.getResponseBody.Fetch.Text",
         description: "Get text/plain content as text.",
         _expression_: "createFetchForText()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "text/plain", "MIMEType should be 'text/plain'.");
+            InspectorTest.expectEqual(rawBase64Encoded, false, "Content should not be base64Encoded.");
             InspectorTest.expectEqual(content, "Plain text resource.\n", "Text content should match data.txt.");
         }
     });
@@ -67,8 +80,9 @@
         name: "Network.getResponseBody.Fetch.HTML",
         description: "Get text/html content as text.",
         _expression_: "createFetchForHTML()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "text/html", "MIMEType should be 'text/html'.");
+            InspectorTest.expectEqual(rawBase64Encoded, false, "Content should not be base64Encoded.");
             InspectorTest.expectEqual(content, "<span>Hello World</span>\n", "Text content should match data.html.");
         }
     });
@@ -75,11 +89,14 @@
 
     addTestCase({
         name: "Network.getResponseBody.Fetch.JSON",
-        description: "Get application/octet-stream content as text.",
+        description: "Get application/octet-stream content as base64Encoded text.",
         _expression_: "createFetchForJSON()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             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.");
+            InspectorTest.expectEqual(rawBase64Encoded, true, "Content should be base64Encoded.");
+            return contentAsText(content).then((text) => {
+                InspectorTest.expectEqual(text, `{"json": true, "value": 42}\n`, "JSON content should match data.json.");
+            });
         }
     });
 
@@ -87,8 +104,9 @@
         name: "Network.getResponseBody.Fetch.JSON2",
         description: "Get application/json content as text.",
         _expression_: "createFetchForJSON2()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "application/json", "MIMEType should be 'application/json'.");
+            InspectorTest.expectEqual(rawBase64Encoded, false, "Content should not be base64Encoded.");
             InspectorTest.expectEqual(content, `{"json":true,"value":42}`, "JSON content should match specified content.");
         }
     });
@@ -97,8 +115,9 @@
         name: "Network.getResponseBody.Fetch.JSON3",
         description: "Get arbitrary +json content as text.",
         _expression_: "createFetchForJSON3()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "application/vnd.api+json", "MIMEType should be 'application/vnd.api+json'.");
+            InspectorTest.expectEqual(rawBase64Encoded, false, "Content should not be base64Encoded.");
             InspectorTest.expectEqual(content, `{"json":true,"value":999}`, "JSON content should match specified content.");
         }
     });
@@ -107,8 +126,9 @@
         name: "Network.getResponseBody.Fetch.SVG",
         description: "Get image/svg+xml content as text.",
         _expression_: "createFetchForSVG()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "image/svg+xml", "MIMEType should be 'image/svg+xml'.");
+            InspectorTest.expectEqual(rawBase64Encoded, false, "Content should not be base64Encoded.");
             InspectorTest.expectEqual(content,
 `<?xml version="1.0" encoding="UTF-8"?>
 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 200">
@@ -122,10 +142,10 @@
         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
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "image/png", "MIMEType should be 'image/png'.");
-            InspectorTest.expectEqual(typeof content, "string", "Image content should be text.");
+            InspectorTest.expectEqual(rawBase64Encoded, true, "Content should be base64Encoded.");
+            InspectorTest.expectThat(content instanceof Blob, "Image content should be a Blob.");
         }
     });
 

Modified: trunk/LayoutTests/http/tests/inspector/network/xhr-response-body-expected.txt (225545 => 225546)


--- trunk/LayoutTests/http/tests/inspector/network/xhr-response-body-expected.txt	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/LayoutTests/http/tests/inspector/network/xhr-response-body-expected.txt	2017-12-05 22:09:36 UTC (rev 225546)
@@ -5,35 +5,42 @@
 -- Running test case: Network.getResponseBody.XHR.Text
 PASS: Resource should be XHR type.
 PASS: MIMEType should be 'text/plain'.
+PASS: Content should not be base64Encoded.
 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: Content should not be base64Encoded.
 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: Content should be base64Encoded.
 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: Content should not be base64Encoded.
 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: Content should not be base64Encoded.
 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: Content should not be base64Encoded.
 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.
+PASS: Content should be base64Encoded.
+PASS: Image content should be a Blob.
 

Modified: trunk/LayoutTests/http/tests/inspector/network/xhr-response-body.html (225545 => 225546)


--- trunk/LayoutTests/http/tests/inspector/network/xhr-response-body.html	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/LayoutTests/http/tests/inspector/network/xhr-response-body.html	2017-12-05 22:09:36 UTC (rev 225546)
@@ -42,6 +42,18 @@
 {
     let suite = InspectorTest.createAsyncSuite("Network.getResponseBody.XHR");
 
+    function contentAsText(content) {
+        return new Promise((resolve) => {
+            if (typeof content === "string") {
+                resolve(content)
+                return;
+            }
+            blobAsText(content, (text) => {
+                resolve(text);
+            });
+        });
+    }
+
     function addTestCase({name, description, _expression_, contentHandler}) {
         suite.addTestCase({
             name, description,
@@ -63,8 +75,9 @@
         name: "Network.getResponseBody.XHR.Text",
         description: "Get text/plain content as text.",
         _expression_: "createXHRForText()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "text/plain", "MIMEType should be 'text/plain'.");
+            InspectorTest.expectEqual(rawBase64Encoded, false, "Content should not be base64Encoded.");
             InspectorTest.expectEqual(content, "Plain text resource.\n", "Text content should match data.txt.");
         }
     });
@@ -73,8 +86,9 @@
         name: "Network.getResponseBody.XHR.HTML",
         description: "Get text/html content as text.",
         _expression_: "createXHRForHTML()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "text/html", "MIMEType should be 'text/html'.");
+            InspectorTest.expectEqual(rawBase64Encoded, false, "Content should not be base64Encoded.");
             InspectorTest.expectEqual(content, "<span>Hello World</span>\n", "Text content should match data.html.");
         }
     });
@@ -81,11 +95,14 @@
 
     addTestCase({
         name: "Network.getResponseBody.XHR.JSON",
-        description: "Get application/octet-stream content as text.",
+        description: "Get application/octet-stream content as base64Encoded text.",
         _expression_: "createXHRForJSON()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             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.");
+            InspectorTest.expectEqual(rawBase64Encoded, true, "Content should be base64Encoded.");
+            return contentAsText(content).then((text) => {
+                InspectorTest.expectEqual(text, `{"json": true, "value": 42}\n`, "JSON content should match data.json.");
+            });
         }
     });
 
@@ -93,8 +110,9 @@
         name: "Network.getResponseBody.XHR.JSON2",
         description: "Get application/json content as text.",
         _expression_: "createXHRForJSON2()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "application/json", "MIMEType should be 'application/json'.");
+            InspectorTest.expectEqual(rawBase64Encoded, false, "Content should not be base64Encoded.");
             InspectorTest.expectEqual(content, `{"json":true,"value":42}`, "JSON content should match specified content.");
         }
     });
@@ -103,8 +121,9 @@
         name: "Network.getResponseBody.XHR.JSON3",
         description: "Get arbitrary +json content as text.",
         _expression_: "createXHRForJSON3()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "application/vnd.api+json", "MIMEType should be 'application/vnd.api+json'.");
+            InspectorTest.expectEqual(rawBase64Encoded, false, "Content should not be base64Encoded.");
             InspectorTest.expectEqual(content, `{"json":true,"value":999}`, "JSON content should match specified content.");
         }
     });
@@ -113,8 +132,9 @@
         name: "Network.getResponseBody.XHR.SVG",
         description: "Get image/svg+xml content as text.",
         _expression_: "createXHRForSVG()",
-        contentHandler({error, sourceCode, content}) {
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "image/svg+xml", "MIMEType should be 'image/svg+xml'.");
+            InspectorTest.expectEqual(rawBase64Encoded, false, "Content should not be base64Encoded.");
             InspectorTest.expectEqual(content,
 `<?xml version="1.0" encoding="UTF-8"?>
 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 200">
@@ -128,10 +148,10 @@
         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
+        contentHandler({error, sourceCode, content, rawBase64Encoded}) {
             InspectorTest.expectEqual(sourceCode.mimeType, "image/png", "MIMEType should be 'image/png'.");
-            InspectorTest.expectEqual(typeof content, "string", "Image content should be text.");
+            InspectorTest.expectEqual(rawBase64Encoded, true, "Content should be base64Encoded.");
+            InspectorTest.expectThat(content instanceof Blob, "Image content should be a Blob.");
         }
     });
 

Modified: trunk/Source/WebCore/ChangeLog (225545 => 225546)


--- trunk/Source/WebCore/ChangeLog	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebCore/ChangeLog	2017-12-05 22:09:36 UTC (rev 225546)
@@ -1,3 +1,80 @@
+2017-12-05  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: content views for resources loaded through XHR do not reflect declared mime-type
+        https://bugs.webkit.org/show_bug.cgi?id=141389
+        <rdar://problem/19767070>
+
+        Reviewed by Brian Burg.
+
+        Updated: http/tests/inspector/network/xhr-response-body.html:
+                 http/tests/inspector/network/fetch-response-body.html:
+
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::didFinishLoading):
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::didFinishXHRLoadingImpl): Deleted.
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::didFinishXHRLoading): Deleted.
+        Remove special handling of XHR content that decoded output as text.
+
+        * inspector/NetworkResourcesData.h:
+        (WebCore::NetworkResourcesData::ResourceData::requestId const):
+        (WebCore::NetworkResourcesData::ResourceData::loaderId const):
+        (WebCore::NetworkResourcesData::ResourceData::frameId const):
+        (WebCore::NetworkResourcesData::ResourceData::url const):
+        (WebCore::NetworkResourcesData::ResourceData::content const):
+        (WebCore::NetworkResourcesData::ResourceData::isContentEvicted const):
+        (WebCore::NetworkResourcesData::ResourceData::textEncodingName const):
+        * inspector/NetworkResourcesData.cpp:
+        (WebCore::NetworkResourcesData::ResourceData::ResourceData):
+        (WebCore::NetworkResourcesData::ResourceData::decodeDataToContent):
+        (WebCore::NetworkResourcesData::responseReceived):
+        (WebCore::NetworkResourcesData::setResourceContent):
+        (WebCore::shouldBufferResourceData):
+        (WebCore::NetworkResourcesData::maybeAddResourceData):
+        (WebCore::NetworkResourcesData::maybeDecodeDataToContent):
+
+        Make NetworkResourcesData only create a text decoder for resources we
+        really think are text, and buffer resource data if it is text data
+        or if it is a resource that would otherwise not be buffered by WebCore
+        (such as XHRs with a DoNotBufferData policy). This ensures that the
+        Inspector will have data to show for resources that won't be cached.
+
+        * inspector/agents/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::resourceContent):
+        (WebCore::InspectorPageAgent::sourceMapURLForResource):
+        (WebCore::InspectorPageAgent::searchInResource):
+        (WebCore::InspectorPageAgent::searchInResources):
+        (WebCore::hasTextContent): Deleted.
+        (WebCore::InspectorPageAgent::cachedResourceContent): Deleted.
+        (WebCore::InspectorPageAgent::createTextDecoder): Deleted.
+        (WebCore::textContentForCachedResource): Deleted.
+        * inspector/agents/InspectorPageAgent.h:
+        * inspector/agents/InspectorNetworkAgent.cpp:
+        (WebCore::InspectorNetworkAgent::didReceiveData):
+        (WebCore::InspectorNetworkAgent::willDestroyCachedResource):
+        (WebCore::InspectorNetworkAgent::getResponseBody):
+        (WebCore::InspectorNetworkAgent::shouldTreatAsText):
+        (WebCore::InspectorNetworkAgent::createTextDecoder):
+        (WebCore::InspectorNetworkAgent::textContentForCachedResource):
+        (WebCore::InspectorNetworkAgent::cachedResourceContent):
+        (WebCore::textContentForResourceData):
+        (WebCore::InspectorNetworkAgent::searchOtherRequests):
+        (WebCore::isErrorStatusCode): Deleted.
+        (WebCore::InspectorNetworkAgent::didFinishXHRLoading): Deleted.
+        * inspector/agents/InspectorNetworkAgent.h:
+        Move static PageAgent functions related to the generic data tuple
+        (content, base64Encoded) to NetworkAgent. Also generalize it to
+        not rely on the CachedResourceType, but instead rely on the MIME type.
+        This has a few changes in behavior:
+
+            - Images, may now be text if they have a text mime type (image/svg+xml).
+            - XHR / Fetch / Other may be sent as text if they have a text mime type.
+            - XHR / Fetch / Other are not assumed to be text, and may be sent as base64 encoded.
+        
+        For this to be useful the frontend should also check the mime type and
+        display an appropriate ContentView.
+
 2017-12-05  Youenn Fablet  <[email protected]>
 
         Implement https://w3c.github.io/ServiceWorker/#clients-claim

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (225545 => 225546)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2017-12-05 22:09:36 UTC (rev 225546)
@@ -617,14 +617,6 @@
         consoleAgent->didFailLoading(identifier, error); // This should come AFTER resource notification, front-end relies on this.
 }
 
-void InspectorInstrumentation::didFinishXHRLoadingImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, std::optional<String> decodedText)
-{
-    if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent()) {
-        if (decodedText)
-            networkAgent->didFinishXHRLoading(identifier, *decodedText);
-    }
-}
-
 void InspectorInstrumentation::willLoadXHRSynchronouslyImpl(InstrumentingAgents& instrumentingAgents)
 {
     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (225545 => 225546)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2017-12-05 22:09:36 UTC (rev 225546)
@@ -195,7 +195,6 @@
     static void continueAfterXFrameOptionsDenied(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
     static void continueWithPolicyDownload(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
     static void continueWithPolicyIgnore(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
-    static void didFinishXHRLoading(ScriptExecutionContext*, unsigned long identifier, std::optional<String> decodedText);
     static void willLoadXHRSynchronously(ScriptExecutionContext*);
     static void didLoadXHRSynchronously(ScriptExecutionContext*);
     static void scriptImported(ScriptExecutionContext&, unsigned long identifier, const String& sourceString);
@@ -366,7 +365,6 @@
     static void didReceiveDataImpl(InstrumentingAgents&, unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
     static void didFinishLoadingImpl(InstrumentingAgents&, unsigned long identifier, DocumentLoader*, const NetworkLoadMetrics&, ResourceLoader*);
     static void didFailLoadingImpl(InstrumentingAgents&, unsigned long identifier, DocumentLoader*, const ResourceError&);
-    static void didFinishXHRLoadingImpl(InstrumentingAgents&, unsigned long identifier, std::optional<String> decodedText);
     static void willLoadXHRSynchronouslyImpl(InstrumentingAgents&);
     static void didLoadXHRSynchronouslyImpl(InstrumentingAgents&);
     static void scriptImportedImpl(InstrumentingAgents&, unsigned long identifier, const String& sourceString);
@@ -1011,13 +1009,6 @@
         didReceiveResourceResponseImpl(*instrumentingAgents, identifier, &loader, response, nullptr);
 }
 
-inline void InspectorInstrumentation::didFinishXHRLoading(ScriptExecutionContext* context, unsigned long identifier, std::optional<String> decodedText)
-{
-    FAST_RETURN_IF_NO_FRONTENDS(void());
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
-        didFinishXHRLoadingImpl(*instrumentingAgents, identifier, decodedText);
-}
-
 inline void InspectorInstrumentation::willLoadXHRSynchronously(ScriptExecutionContext* context)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());

Modified: trunk/Source/WebCore/inspector/NetworkResourcesData.cpp (225545 => 225546)


--- trunk/Source/WebCore/inspector/NetworkResourcesData.cpp	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebCore/inspector/NetworkResourcesData.cpp	2017-12-05 22:09:36 UTC (rev 225546)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -30,9 +31,11 @@
 #include "NetworkResourcesData.h"
 
 #include "CachedResource.h"
+#include "InspectorNetworkAgent.h"
 #include "ResourceResponse.h"
 #include "SharedBuffer.h"
 #include "TextResourceDecoder.h"
+#include <wtf/text/Base64.h>
 
 namespace WebCore {
 
@@ -44,10 +47,6 @@
 NetworkResourcesData::ResourceData::ResourceData(const String& requestId, const String& loaderId)
     : m_requestId(requestId)
     , m_loaderId(loaderId)
-    , m_base64Encoded(false)
-    , m_isContentEvicted(false)
-    , m_type(InspectorPageAgent::OtherResource)
-    , m_cachedResource(nullptr)
 {
 }
 
@@ -104,10 +103,22 @@
 size_t NetworkResourcesData::ResourceData::decodeDataToContent()
 {
     ASSERT(!hasContent());
+
     size_t dataLength = m_dataBuffer->size();
-    m_content = m_decoder->decodeAndFlush(m_dataBuffer->data(), m_dataBuffer->size());
+
+    if (m_decoder) {
+        m_base64Encoded = false;
+        m_content = m_decoder->decodeAndFlush(m_dataBuffer->data(), dataLength);
+    } else {
+        m_base64Encoded = true;
+        m_content = base64Encode(m_dataBuffer->data(), dataLength);
+    }
+
     m_dataBuffer = nullptr;
-    return contentSizeInBytes(m_content) - dataLength;
+
+    size_t decodedLength = contentSizeInBytes(m_content);
+    ASSERT(decodedLength >= dataLength);
+    return decodedLength - dataLength;
 }
 
 NetworkResourcesData::NetworkResourcesData()
@@ -144,11 +155,14 @@
     ResourceData* resourceData = resourceDataForRequestId(requestId);
     if (!resourceData)
         return;
+
     resourceData->setFrameId(frameId);
     resourceData->setURL(response.url());
-    resourceData->setDecoder(InspectorPageAgent::createTextDecoder(response.mimeType(), response.textEncodingName()));
     resourceData->setHTTPStatusCode(response.httpStatusCode());
     resourceData->setType(type);
+
+    if (InspectorNetworkAgent::shouldTreatAsText(response.mimeType()))
+        resourceData->setDecoder(InspectorNetworkAgent::createTextDecoder(response.mimeType(), response.textEncodingName()));
 }
 
 void NetworkResourcesData::setResourceType(const String& requestId, InspectorPageAgent::ResourceType type)
@@ -172,11 +186,13 @@
     ResourceData* resourceData = resourceDataForRequestId(requestId);
     if (!resourceData)
         return;
+
     size_t dataLength = contentSizeInBytes(content);
     if (dataLength > m_maximumSingleResourceContentSize)
         return;
     if (resourceData->isContentEvicted())
         return;
+
     if (ensureFreeSpace(dataLength) && !resourceData->isContentEvicted()) {
         // We can not be sure that we didn't try to save this request data while it was loading, so remove it, if any.
         if (resourceData->hasContent() || resourceData->hasData())
@@ -187,17 +203,32 @@
     }
 }
 
+static bool shouldBufferResourceData(const NetworkResourcesData::ResourceData& resourceData)
+{
+    if (resourceData.decoder())
+        return true;
+
+    // Buffer data for Web Inspector when the rest of the system would not normally buffer.
+    if (resourceData.cachedResource() && resourceData.cachedResource()->dataBufferingPolicy() == DoNotBufferData)
+        return true;
+
+    return false;
+}
+
 void NetworkResourcesData::maybeAddResourceData(const String& requestId, const char* data, size_t dataLength)
 {
     ResourceData* resourceData = resourceDataForRequestId(requestId);
     if (!resourceData)
         return;
-    if (!resourceData->decoder())
+
+    if (!shouldBufferResourceData(*resourceData))
         return;
+
     if (resourceData->dataLength() + dataLength > m_maximumSingleResourceContentSize)
         m_contentSize -= resourceData->evictContent();
     if (resourceData->isContentEvicted())
         return;
+
     if (ensureFreeSpace(dataLength) && !resourceData->isContentEvicted()) {
         m_requestIdsDeque.append(requestId);
         resourceData->appendData(data, dataLength);
@@ -210,8 +241,10 @@
     ResourceData* resourceData = resourceDataForRequestId(requestId);
     if (!resourceData)
         return;
+
     if (!resourceData->hasData())
         return;
+
     m_contentSize += resourceData->decodeDataToContent();
     size_t dataLength = contentSizeInBytes(resourceData->content());
     if (dataLength > m_maximumSingleResourceContentSize)

Modified: trunk/Source/WebCore/inspector/NetworkResourcesData.h (225545 => 225546)


--- trunk/Source/WebCore/inspector/NetworkResourcesData.h	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebCore/inspector/NetworkResourcesData.h	2017-12-05 22:09:36 UTC (rev 225546)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -29,7 +30,6 @@
 #pragma once
 
 #include "InspectorPageAgent.h"
-#include "TextResourceDecoder.h"
 #include <wtf/Deque.h>
 #include <wtf/HashMap.h>
 #include <wtf/text/WTFString.h>
@@ -38,6 +38,7 @@
 
 class CachedResource;
 class ResourceResponse;
+class TextResourceDecoder;
 class SharedBuffer;
 
 class NetworkResourcesData {
@@ -49,24 +50,24 @@
     public:
         ResourceData(const String& requestId, const String& loaderId);
 
-        String requestId() const { return m_requestId; }
-        String loaderId() const { return m_loaderId; }
+        const String& requestId() const { return m_requestId; }
+        const String& loaderId() const { return m_loaderId; }
 
-        String frameId() const { return m_frameId; }
+        const String& frameId() const { return m_frameId; }
         void setFrameId(const String& frameId) { m_frameId = frameId; }
 
-        String url() const { return m_url; }
+        const String& url() const { return m_url; }
         void setURL(const String& url) { m_url = url; }
 
         bool hasContent() const { return !m_content.isNull(); }
-        String content() const { return m_content; }
+        const String& content() const { return m_content; }
         void setContent(const String&, bool base64Encoded);
 
         bool base64Encoded() const { return m_base64Encoded; }
 
         unsigned removeContent();
+        unsigned evictContent();
         bool isContentEvicted() const { return m_isContentEvicted; }
-        unsigned evictContent();
 
         InspectorPageAgent::ResourceType type() const { return m_type; }
         void setType(InspectorPageAgent::ResourceType type) { m_type = type; }
@@ -74,7 +75,7 @@
         int httpStatusCode() const { return m_httpStatusCode; }
         void setHTTPStatusCode(int httpStatusCode) { m_httpStatusCode = httpStatusCode; }
 
-        String textEncodingName() const { return m_textEncodingName; }
+        const String& textEncodingName() const { return m_textEncodingName; }
         void setTextEncodingName(const String& textEncodingName) { m_textEncodingName = textEncodingName; }
 
         RefPtr<TextResourceDecoder> decoder() const { return m_decoder.copyRef(); }
@@ -97,17 +98,15 @@
         String m_frameId;
         String m_url;
         String m_content;
-        bool m_base64Encoded;
-        RefPtr<SharedBuffer> m_dataBuffer;
-        bool m_isContentEvicted;
-        InspectorPageAgent::ResourceType m_type;
-        int m_httpStatusCode;
-
         String m_textEncodingName;
         RefPtr<TextResourceDecoder> m_decoder;
-
+        RefPtr<SharedBuffer> m_dataBuffer;
         RefPtr<SharedBuffer> m_buffer;
-        CachedResource* m_cachedResource;
+        CachedResource* m_cachedResource { nullptr };
+        InspectorPageAgent::ResourceType m_type { InspectorPageAgent::OtherResource };
+        int m_httpStatusCode { 0 };
+        bool m_isContentEvicted { false };
+        bool m_base64Encoded { false };
     };
 
     NetworkResourcesData();

Modified: trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp (225545 => 225546)


--- trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp	2017-12-05 22:09:36 UTC (rev 225546)
@@ -32,10 +32,12 @@
 #include "config.h"
 #include "InspectorNetworkAgent.h"
 
+#include "CachedCSSStyleSheet.h"
 #include "CachedRawResource.h"
 #include "CachedResource.h"
 #include "CachedResourceLoader.h"
 #include "CachedResourceRequestInitiators.h"
+#include "CachedScript.h"
 #include "Document.h"
 #include "DocumentLoader.h"
 #include "DocumentThreadableLoader.h"
@@ -47,6 +49,7 @@
 #include "InstrumentingAgents.h"
 #include "JSMainThreadExecState.h"
 #include "JSWebSocket.h"
+#include "MIMETypeRegistry.h"
 #include "MemoryCache.h"
 #include "NetworkResourcesData.h"
 #include "Page.h"
@@ -58,6 +61,7 @@
 #include "ScriptState.h"
 #include "ScriptableDocumentParser.h"
 #include "SubresourceLoader.h"
+#include "TextResourceDecoder.h"
 #include "ThreadableLoaderClient.h"
 #include "URL.h"
 #include "WebSocket.h"
@@ -67,7 +71,6 @@
 #include <inspector/IdentifiersFactory.h>
 #include <inspector/InjectedScript.h>
 #include <inspector/InjectedScriptManager.h>
-#include <inspector/InspectorFrontendRouter.h>
 #include <inspector/ScriptCallStack.h>
 #include <inspector/ScriptCallStackFactory.h>
 #include <runtime/JSCInlines.h>
@@ -75,6 +78,7 @@
 #include <wtf/Lock.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Stopwatch.h>
+#include <wtf/text/Base64.h>
 #include <wtf/text/StringBuilder.h>
 
 typedef Inspector::NetworkBackendDispatcherHandler::LoadResourceCallback LoadResourceCallback;
@@ -456,11 +460,6 @@
         didReceiveData(identifier, nullptr, cachedResource->encodedSize(), 0);
 }
 
-static bool isErrorStatusCode(int statusCode)
-{
-    return statusCode >= 400;
-}
-
 void InspectorNetworkAgent::didReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
 {
     if (m_hiddenRequestIdentifiers.contains(identifier))
@@ -470,7 +469,7 @@
 
     if (data) {
         NetworkResourcesData::ResourceData const* resourceData = m_resourcesData->data(requestId);
-        if (resourceData && !m_loadingXHRSynchronously && (!resourceData->cachedResource() || resourceData->cachedResource()->dataBufferingPolicy() == DoNotBufferData || isErrorStatusCode(resourceData->httpStatusCode())))
+        if (resourceData && !m_loadingXHRSynchronously)
             m_resourcesData->maybeAddResourceData(requestId, data, dataLength);
     }
 
@@ -567,11 +566,6 @@
         m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::XHRResource);
 }
 
-void InspectorNetworkAgent::didFinishXHRLoading(unsigned long identifier, const String& decodedText)
-{
-    m_resourcesData->setResourceContent(IdentifiersFactory::requestId(identifier), decodedText);
-}
-
 void InspectorNetworkAgent::willLoadXHRSynchronously()
 {
     m_loadingXHRSynchronously = true;
@@ -590,8 +584,9 @@
 
     String content;
     bool base64Encoded;
-    if (!InspectorPageAgent::cachedResourceContent(&cachedResource, &content, &base64Encoded))
+    if (!InspectorNetworkAgent::cachedResourceContent(cachedResource, &content, &base64Encoded))
         return;
+
     for (auto& id : requestIds)
         m_resourcesData->setResourceContent(id, content, base64Encoded);
 }
@@ -778,7 +773,7 @@
     }
 
     if (resourceData->cachedResource()) {
-        if (InspectorPageAgent::cachedResourceContent(resourceData->cachedResource(), content, base64Encoded))
+        if (InspectorNetworkAgent::cachedResourceContent(*resourceData->cachedResource(), content, base64Encoded))
             return;
     }
 
@@ -868,6 +863,84 @@
     result = injectedScript.wrapObject(webSocketAsScriptValue(state, webSocket), objectGroupName);
 }
 
+bool InspectorNetworkAgent::shouldTreatAsText(const String& mimeType)
+{
+    return startsWithLettersIgnoringASCIICase(mimeType, "text/")
+        || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType)
+        || MIMETypeRegistry::isSupportedJSONMIMEType(mimeType)
+        || MIMETypeRegistry::isXMLMIMEType(mimeType);
+}
+
+Ref<TextResourceDecoder> InspectorNetworkAgent::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)) {
+        auto decoder = TextResourceDecoder::create(ASCIILiteral("application/xml"));
+        decoder->useLenientXMLDecoding();
+        return decoder;
+    }
+
+    return TextResourceDecoder::create(ASCIILiteral("text/plain"), "UTF-8");
+}
+
+std::optional<String> InspectorNetworkAgent::textContentForCachedResource(CachedResource& cachedResource)
+{
+    if (!InspectorNetworkAgent::shouldTreatAsText(cachedResource.mimeType()))
+        return std::nullopt;
+
+    String result;
+    bool base64Encoded;
+    if (InspectorNetworkAgent::cachedResourceContent(cachedResource, &result, &base64Encoded)) {
+        ASSERT(!base64Encoded);
+        return result;
+    }
+
+    return std::nullopt;
+}
+
+bool InspectorNetworkAgent::cachedResourceContent(CachedResource& resource, String* result, bool* base64Encoded)
+{
+    ASSERT(result);
+    ASSERT(base64Encoded);
+
+    if (!resource.encodedSize()) {
+        *base64Encoded = false;
+        *result = String();
+        return true;
+    }
+
+    switch (resource.type()) {
+    case CachedResource::CSSStyleSheet:
+        *base64Encoded = false;
+        *result = downcast<CachedCSSStyleSheet>(resource).sheetText();
+        // The above can return a null String if the MIME type is invalid.
+        return !result->isNull();
+    case CachedResource::Script:
+        *base64Encoded = false;
+        *result = downcast<CachedScript>(resource).script().toString();
+        return true;
+    default:
+        auto* buffer = resource.resourceBuffer();
+        if (!buffer)
+            return false;
+
+        if (InspectorNetworkAgent::shouldTreatAsText(resource.mimeType())) {
+            auto decoder = InspectorNetworkAgent::createTextDecoder(resource.mimeType(), resource.response().textEncodingName());
+            *base64Encoded = false;
+            *result = decoder->decodeAndFlush(buffer->data(), buffer->size());
+            return true;
+        }
+
+        *base64Encoded = true;
+        *result = base64Encode(buffer->data(), buffer->size());
+        return true;
+    }
+}
+
 static Ref<Inspector::Protocol::Page::SearchResult> buildObjectForSearchResult(const String& requestId, const String& frameId, const String& url, int matchesCount)
 {
     auto searchResult = Inspector::Protocol::Page::SearchResult::create()
@@ -879,11 +952,22 @@
     return searchResult;
 }
 
+static std::optional<String> textContentForResourceData(const NetworkResourcesData::ResourceData& resourceData)
+{
+    if (resourceData.hasContent() && !resourceData.base64Encoded())
+        return resourceData.content();
+
+    if (resourceData.cachedResource())
+        return InspectorNetworkAgent::textContentForCachedResource(*resourceData.cachedResource());
+
+    return std::nullopt;
+}
+
 void InspectorNetworkAgent::searchOtherRequests(const JSC::Yarr::RegularExpression& regex, RefPtr<JSON::ArrayOf<Inspector::Protocol::Page::SearchResult>>& result)
 {
     Vector<NetworkResourcesData::ResourceData*> resources = m_resourcesData->resources();
     for (auto* resourceData : resources) {
-        if (resourceData->hasContent()) {
+        if (auto textContent = textContentForResourceData(*resourceData)) {
             int matchesCount = ContentSearchUtilities::countRegularExpressionMatches(regex, resourceData->content());
             if (matchesCount)
                 result->addItem(buildObjectForSearchResult(resourceData->requestId(), resourceData->frameId(), resourceData->url(), matchesCount));

Modified: trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.h (225545 => 225546)


--- trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.h	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.h	2017-12-05 22:09:36 UTC (rev 225546)
@@ -57,6 +57,7 @@
 class ResourceLoader;
 class ResourceRequest;
 class ResourceResponse;
+class TextResourceDecoder;
 class URL;
 class WebSocket;
 
@@ -71,6 +72,11 @@
     explicit InspectorNetworkAgent(WebAgentContext&);
     virtual ~InspectorNetworkAgent();
 
+    static bool shouldTreatAsText(const String& mimeType);
+    static Ref<TextResourceDecoder> createTextDecoder(const String& mimeType, const String& textEncodingName);
+    static std::optional<String> textContentForCachedResource(CachedResource&);
+    static bool cachedResourceContent(CachedResource&, String* result, bool* base64Encoded);
+
     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
     void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
 
@@ -85,7 +91,6 @@
     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 willLoadXHRSynchronously();
     void didLoadXHRSynchronously();
     void didReceiveScriptResponse(unsigned long identifier);
@@ -104,8 +109,6 @@
     void searchOtherRequests(const JSC::Yarr::RegularExpression&, RefPtr<JSON::ArrayOf<Inspector::Protocol::Page::SearchResult>>&);
     void searchInRequest(ErrorString&, const String& requestId, const String& query, bool caseSensitive, bool isRegex, RefPtr<JSON::ArrayOf<Inspector::Protocol::GenericTypes::SearchMatch>>&);
 
-    RefPtr<Inspector::Protocol::Network::Initiator> buildInitiatorObject(Document*);
-
     // Called from frontend.
     void enable(ErrorString&) final;
     void disable(ErrorString&) final;
@@ -128,6 +131,7 @@
 
     WebSocket* webSocketForRequestId(const String& requestId);
 
+    RefPtr<Inspector::Protocol::Network::Initiator> buildInitiatorObject(Document*);
     Ref<Inspector::Protocol::Network::ResourceTiming> buildObjectForTiming(const NetworkLoadMetrics&, ResourceLoader&);
     Ref<Inspector::Protocol::Network::Metrics> buildObjectForMetrics(const NetworkLoadMetrics&);
     RefPtr<Inspector::Protocol::Network::Response> buildObjectForResourceResponse(const ResourceResponse&, ResourceLoader*);

Modified: trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp (225545 => 225546)


--- trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp	2017-12-05 22:09:36 UTC (rev 225546)
@@ -32,12 +32,8 @@
 #include "config.h"
 #include "InspectorPageAgent.h"
 
-#include "CachedCSSStyleSheet.h"
-#include "CachedFont.h"
-#include "CachedImage.h"
 #include "CachedResource.h"
 #include "CachedResourceLoader.h"
-#include "CachedScript.h"
 #include "Cookie.h"
 #include "CookieJar.h"
 #include "Document.h"
@@ -65,7 +61,6 @@
 #include "Settings.h"
 #include "StyleScope.h"
 #include "TextEncoding.h"
-#include "TextResourceDecoder.h"
 #include "UserGestureIndicator.h"
 #include <inspector/ContentSearchUtilities.h>
 #include <inspector/IdentifiersFactory.h>
@@ -96,69 +91,6 @@
     return false;
 }
 
-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::inspectorResourceType(*cachedResource);
-    return type == InspectorPageAgent::DocumentResource
-        || type == InspectorPageAgent::StylesheetResource
-        || type == InspectorPageAgent::ScriptResource
-        || type == InspectorPageAgent::XHRResource
-        || type == InspectorPageAgent::FetchResource;
-}
-
-bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, String* result, bool* base64Encoded)
-{
-    if (!cachedResource)
-        return false;
-
-    *base64Encoded = !hasTextContent(cachedResource);
-
-    if (!cachedResource->encodedSize()) {
-        *result = emptyString();
-        return true;
-    }
-
-    if (*base64Encoded) {
-        if (auto* buffer = cachedResource->resourceBuffer()) {
-            *result = base64Encode(buffer->data(), buffer->size());
-            return true;
-        }
-        return false;
-    }
-
-    if (cachedResource) {
-        switch (cachedResource->type()) {
-        case CachedResource::CSSStyleSheet:
-            // This can return a null String if the MIME type is invalid.
-            *result = downcast<CachedCSSStyleSheet>(*cachedResource).sheetText();
-            return !result->isNull();
-        case CachedResource::Script:
-            *result = downcast<CachedScript>(*cachedResource).script().toString();
-            return true;
-        case CachedResource::MediaResource:
-        case CachedResource::Icon:
-        case CachedResource::RawResource: {
-            auto* buffer = cachedResource->resourceBuffer();
-            if (!buffer)
-                return false;
-            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;
-            *result = decoder->decodeAndFlush(buffer->data(), buffer->size());
-            return true;
-        }
-        default:
-            auto* buffer = cachedResource->resourceBuffer();
-            return decodeBuffer(buffer ? buffer->data() : nullptr, buffer ? buffer->size() : 0, cachedResource->encoding(), result);
-        }
-    }
-    return false;
-}
-
 bool InspectorPageAgent::mainResourceContent(Frame* frame, bool withBase64Encode, String* result)
 {
     RefPtr<SharedBuffer> buffer = frame->loader().documentLoader()->mainResourceData();
@@ -195,14 +127,15 @@
         success = mainResourceContent(frame, *base64Encoded, result);
     }
 
-    if (!success)
-        success = cachedResourceContent(cachedResource(frame, url), result, base64Encoded);
+    if (!success) {
+        if (auto* resource = cachedResource(frame, url))
+            success = InspectorNetworkAgent::cachedResourceContent(*resource, result, base64Encoded);
+    }
 
     if (!success)
         errorString = ASCIILiteral("No resource with given URL found");
 }
 
-//static
 String InspectorPageAgent::sourceMapURLForResource(CachedResource* cachedResource)
 {
     static NeverDestroyed<String> sourceMapHTTPHeader(MAKE_STATIC_STRING_IMPL("SourceMap"));
@@ -225,7 +158,7 @@
 
     String content;
     bool base64Encoded;
-    if (InspectorPageAgent::cachedResourceContent(cachedResource, &content, &base64Encoded) && !base64Encoded)
+    if (InspectorNetworkAgent::cachedResourceContent(*cachedResource, &content, &base64Encoded) && !base64Encoded)
         return ContentSearchUtilities::findStylesheetSourceMapURL(content);
 
     return String();
@@ -325,23 +258,6 @@
     return resourceTypeJSON(inspectorResourceType(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))
@@ -543,18 +459,6 @@
     resourceContent(errorString, frame, URL(ParsedURLString, url), content, base64Encoded);
 }
 
-static bool textContentForCachedResource(CachedResource* cachedResource, String* result)
-{
-    if (hasTextContent(cachedResource)) {
-        bool base64Encoded;
-        if (InspectorPageAgent::cachedResourceContent(cachedResource, result, &base64Encoded)) {
-            ASSERT(!base64Encoded);
-            return true;
-        }
-    }
-    return false;
-}
-
 void InspectorPageAgent::searchInResource(ErrorString& errorString, const String& frameId, const String& url, const String& query, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, const String* optionalRequestId, RefPtr<JSON::ArrayOf<Inspector::Protocol::GenericTypes::SearchMatch>>& results)
 {
     results = JSON::ArrayOf<Inspector::Protocol::GenericTypes::SearchMatch>::create();
@@ -585,9 +489,12 @@
         success = mainResourceContent(frame, false, &content);
 
     if (!success) {
-        CachedResource* resource = cachedResource(frame, kurl);
-        if (resource)
-            success = textContentForCachedResource(resource, &content);
+        if (auto* resource = cachedResource(frame, kurl)) {
+            if (auto textContent = InspectorNetworkAgent::textContentForCachedResource(*resource)) {
+                content = *textContent;
+                success = true;
+            }
+        }
     }
 
     if (!success)
@@ -614,21 +521,13 @@
     JSC::Yarr::RegularExpression regex = ContentSearchUtilities::createSearchRegex(text, caseSensitive, isRegex);
 
     for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
-        String content;
-
         for (auto* cachedResource : cachedResourcesForFrame(frame)) {
-            if (textContentForCachedResource(cachedResource, &content)) {
-                int matchesCount = ContentSearchUtilities::countRegularExpressionMatches(regex, content);
+            if (auto textContent = InspectorNetworkAgent::textContentForCachedResource(*cachedResource)) {
+                int matchesCount = ContentSearchUtilities::countRegularExpressionMatches(regex, *textContent);
                 if (matchesCount)
                     result->addItem(buildObjectForSearchResult(frameId(frame), cachedResource->url(), matchesCount));
             }
         }
-
-        if (mainResourceContent(frame, false, &content)) {
-            int matchesCount = ContentSearchUtilities::countRegularExpressionMatches(regex, content);
-            if (matchesCount)
-                result->addItem(buildObjectForSearchResult(frameId(frame), frame->document()->url(), matchesCount));
-        }
     }
 
     if (InspectorNetworkAgent* networkAgent = m_instrumentingAgents.inspectorNetworkAgent())

Modified: trunk/Source/WebCore/inspector/agents/InspectorPageAgent.h (225545 => 225546)


--- trunk/Source/WebCore/inspector/agents/InspectorPageAgent.h	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebCore/inspector/agents/InspectorPageAgent.h	2017-12-05 22:09:36 UTC (rev 225546)
@@ -50,7 +50,6 @@
 class Page;
 class RenderObject;
 class SharedBuffer;
-class TextResourceDecoder;
 class URL;
 
 typedef String ErrorString;
@@ -75,7 +74,6 @@
         OtherResource,
     };
 
-    static bool cachedResourceContent(CachedResource*, String* result, bool* base64Encoded);
     static bool sharedBufferContent(RefPtr<SharedBuffer>&&, const String& textEncodingName, bool withBase64Encode, String* result);
     static void resourceContent(ErrorString&, Frame*, const URL&, String* result, bool* base64Encoded);
     static String sourceMapURLForResource(CachedResource*);
@@ -85,7 +83,6 @@
     static ResourceType inspectorResourceType(CachedResource::Type);
     static ResourceType inspectorResourceType(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/xml/XMLHttpRequest.cpp (225545 => 225546)


--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2017-12-05 22:09:36 UTC (rev 225546)
@@ -925,7 +925,7 @@
     networkError();
 }
 
-void XMLHttpRequest::didFinishLoading(unsigned long identifier)
+void XMLHttpRequest::didFinishLoading(unsigned long)
 {
     if (m_error)
         return;
@@ -938,11 +938,6 @@
 
     m_responseBuilder.shrinkToFit();
 
-    std::optional<String> decodedText;
-    if (!m_binaryResponseBuilder)
-        decodedText = m_responseBuilder.toStringPreserveCapacity();
-    InspectorInstrumentation::didFinishXHRLoading(scriptExecutionContext(), identifier, decodedText);
-
     bool hadLoader = m_loader;
     m_loader = nullptr;
 

Modified: trunk/Source/WebInspectorUI/ChangeLog (225545 => 225546)


--- trunk/Source/WebInspectorUI/ChangeLog	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebInspectorUI/ChangeLog	2017-12-05 22:09:36 UTC (rev 225546)
@@ -1,3 +1,40 @@
+2017-12-05  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: content views for resources loaded through XHR do not reflect declared mime-type
+        https://bugs.webkit.org/show_bug.cgi?id=141389
+        <rdar://problem/19767070>
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Base/Utilities.js:
+        Blob <-> Text conversion helpers.
+
+        * UserInterface/Models/Resource.js:
+        (WI.Resource.prototype.createObjectURL):
+        Previously all Image resources were assumed to have base64Encoded data
+        which we automatically convert to a Blob. Now that some image data
+        can be transfered as text, convert that to a Blob here since the output
+        is expected to be a Blob.
+
+        * UserInterface/Views/ResourceContentView.js:
+        (WI.ResourceContentView.prototype.showGenericNoContentMessage):
+        * UserInterface/Views/TextResourceContentView.js:
+        (WI.TextResourceContentView.prototype.contentAvailable):
+        (WI.TextResourceContentView.prototype._contentDidPopulate):
+        * UserInterface/Views/ImageResourceContentView.js:
+        (WI.ImageResourceContentView.prototype.contentAvailable):
+        Better handle no content cases.
+
+        * UserInterface/Views/ResourceClusterContentView.js:
+        (WI.ResourceClusterContentView.prototype.get responseContentView):
+        (WI.ResourceClusterContentView.prototype._contentViewForResourceType):
+        Make a best effort to find a good ContentView to show the resource data.
+        This is done by looking at the ResourceType and MIME Type.
+
+        * UserInterface/Views/SVGImageResourceClusterContentView.js:
+        (WI.SVGImageResourceClusterContentView.prototype._showContentViewForIdentifier):
+        Handle if image data is now text (the image/svg+xml case).
+
 2017-12-05  Simon Fraser  <[email protected]>
 
         Remove webkitGetImageDataHD and webkitPutImageDataHD from canvas API

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js (225545 => 225546)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2017-12-05 22:09:36 UTC (rev 225546)
@@ -1594,6 +1594,19 @@
     return new Blob(byteArrays, {type: mimeType});
 }
 
+function textToBlob(text, mimeType)
+{
+    return new Blob([text], {type: mimeType});
+}
+
+function blobAsText(blob, callback)
+{
+    console.assert(blob instanceof Blob);
+    let fileReader = new FileReader;
+    fileReader.addEventListener("loadend", () => { callback(fileReader.result); });
+    fileReader.readAsText(blob);
+}
+
 if (!window.handlePromiseException) {
     window.handlePromiseException = function handlePromiseException(error)
     {

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js (225545 => 225546)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js	2017-12-05 22:09:36 UTC (rev 225546)
@@ -380,6 +380,11 @@
         if (content instanceof Blob)
             return URL.createObjectURL(content);
 
+        if (typeof content === "string") {
+            let blob = textToBlob(content, this._mimeType);
+            return URL.createObjectURL(blob);
+        }
+
         return null;
     }
 
@@ -1129,7 +1134,6 @@
     "text/xml": WI.Resource.Type.Document,
     "text/plain": WI.Resource.Type.Document,
     "application/xhtml+xml": WI.Resource.Type.Document,
-    "image/svg+xml": WI.Resource.Type.Document,
 
     "text/css": WI.Resource.Type.Stylesheet,
     "text/xsl": WI.Resource.Type.Stylesheet,
@@ -1138,6 +1142,7 @@
     "text/x-scss": WI.Resource.Type.Stylesheet,
 
     "application/pdf": WI.Resource.Type.Image,
+    "image/svg+xml": WI.Resource.Type.Image,
 
     "application/x-font-type1": WI.Resource.Type.Font,
     "application/x-font-ttf": WI.Resource.Type.Font,

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ImageResourceContentView.js (225545 => 225546)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ImageResourceContentView.js	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ImageResourceContentView.js	2017-12-05 22:09:36 UTC (rev 225546)
@@ -48,6 +48,13 @@
 
     contentAvailable(content, base64Encoded)
     {
+        this.removeLoadingIndicator();
+
+        if (!content) {
+            this.showGenericNoContentMessage();
+            return;
+        }
+
         let objectURL = this.resource.createObjectURL();
         if (!objectURL) {
             this.showGenericErrorMessage();
@@ -54,8 +61,6 @@
             return;
         }
 
-        this.removeLoadingIndicator();
-
         this._imageElement = document.createElement("img");
         this._imageElement.addEventListener("load", function() { URL.revokeObjectURL(objectURL); });
         this._imageElement.src = ""

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceClusterContentView.js (225545 => 225546)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceClusterContentView.js	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceClusterContentView.js	2017-12-05 22:09:36 UTC (rev 225546)
@@ -76,42 +76,21 @@
         if (this._responseContentView)
             return this._responseContentView;
 
-        switch (this._resource.type) {
-        case WI.Resource.Type.Document:
-        case WI.Resource.Type.Script:
-        case WI.Resource.Type.Stylesheet:
-            this._responseContentView = new WI.TextResourceContentView(this._resource);
-            break;
+        this._responseContentView = this._contentViewForResourceType(this._resource.type);
+        if (this._responseContentView)
+            return this._responseContentView;
 
-        case WI.Resource.Type.XHR:
-        case WI.Resource.Type.Fetch:
-        case WI.Resource.Type.Ping:
-        case WI.Resource.Type.Beacon:
-            // FIXME: <https://webkit.org/b/165495> Web Inspector: XHR / Fetch for non-text content should not show garbled text
-            // The response content for these requests may not always be text.
+        let typeFromMIMEType = WI.Resource.typeFromMIMEType(this._resource.mimeType);
+        this._responseContentView = this._contentViewForResourceType(typeFromMIMEType);
+        if (this._responseContentView)
+            return this._responseContentView;
+
+        if (WI.shouldTreatMIMETypeAsText(this._resource.mimeType)) {
             this._responseContentView = new WI.TextResourceContentView(this._resource);
-            break;
-
-        case WI.Resource.Type.Image:
-            if (this._resource.mimeTypeComponents.type === "image/svg+xml")
-                this._responseContentView = new WI.SVGImageResourceClusterContentView(this._resource);
-            else
-                this._responseContentView = new WI.ImageResourceContentView(this._resource);
-            break;
-
-        case WI.Resource.Type.Font:
-            this._responseContentView = new WI.FontResourceContentView(this._resource);
-            break;
-
-        case WI.Resource.Type.WebSocket:
-            this._responseContentView = new WI.WebSocketContentView(this._resource);
-            break;
-
-        default:
-            this._responseContentView = new WI.GenericResourceContentView(this._resource);
-            break;
+            return this._responseContentView;
         }
 
+        this._responseContentView = new WI.GenericResourceContentView(this._resource);
         return this._responseContentView;
     }
 
@@ -224,6 +203,30 @@
         return !!this._customResponseContentViewConstructor;
     }
 
+    _contentViewForResourceType(type)
+    {
+        switch (type) {
+        case WI.Resource.Type.Document:
+        case WI.Resource.Type.Script:
+        case WI.Resource.Type.Stylesheet:
+            return new WI.TextResourceContentView(this._resource);
+
+        case WI.Resource.Type.Image:
+            if (this._resource.mimeTypeComponents.type === "image/svg+xml")
+                return new WI.SVGImageResourceClusterContentView(this._resource);
+            return new WI.ImageResourceContentView(this._resource);
+
+        case WI.Resource.Type.Font:
+            return new WI.FontResourceContentView(this._resource);
+
+        case WI.Resource.Type.WebSocket:
+            return new WI.WebSocketContentView(this._resource);
+
+        default:
+            return null;
+        }
+    }
+
     _pathComponentForContentView(contentView)
     {
         console.assert(contentView);

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js (225545 => 225546)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js	2017-12-05 22:09:36 UTC (rev 225546)
@@ -81,6 +81,11 @@
         throw WI.NotImplementedError.subclassMustOverride();
     }
 
+    showGenericNoContentMessage()
+    {
+        this.showMessage(WI.UIString("Resource has no content"));
+    }
+
     showGenericErrorMessage()
     {
         this._contentError(WI.UIString("An error occurred trying to load the resource."));

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SVGImageResourceClusterContentView.js (225545 => 225546)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SVGImageResourceClusterContentView.js	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SVGImageResourceClusterContentView.js	2017-12-05 22:09:36 UTC (rev 225546)
@@ -136,11 +136,14 @@
             contentViewToShow = new WI.TextContentView("", this._resource.mimeType);
 
             this._resource.requestContent().then((result) => {
-                let fileReader = new FileReader;
-                fileReader.addEventListener("loadend", () => {
-                    contentViewToShow.textEditor.string = fileReader.result;
+                if (typeof result.content === "string") {
+                    contentViewToShow.textEditor.string = result.content;
+                    return;
+                }
+
+                blobAsText(result.content, (text) => {
+                    contentViewToShow.textEditor.string = text;
                 });
-                fileReader.readAsText(result.content);
             });
             break;
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js (225545 => 225546)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js	2017-12-05 22:09:04 UTC (rev 225545)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js	2017-12-05 22:09:36 UTC (rev 225546)
@@ -130,6 +130,11 @@
         this._textEditor.close();
     }
 
+    contentAvailable(content, base64Encoded)
+    {
+        // Do nothing.
+    }
+
     get supportsSave()
     {
         return super.supportsSave || this.resource instanceof WI.CSSStyleSheet;
@@ -210,7 +215,7 @@
         this._codeCoverageButtonNavigationItem.activated = WI.enableControlFlowProfilerSetting.value;
 
         if (!this._textEditor.string)
-            this.showMessage(WI.UIString("Resource has no content"));
+            this.showGenericNoContentMessage();
     }
 
     _togglePrettyPrint(event)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to