Web Inspector: m3u8 content not shown, it should be text
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 19:18:44 +0000 (19:18 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 19:18:44 +0000 (19:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192731
<rdar://problem/46747728>

Reviewed by Devin Rousso.

Source/WebCore:

* inspector/NetworkResourcesData.cpp:
(WebCore::NetworkResourcesData::setResourceContent):
Don't clobber data if setting empty content on a resource that has content.

* inspector/agents/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::shouldTreatAsText):
Additional non-"text/" mime types that can be treated as text.

* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::isTextMediaPlaylistMIMEType):
* platform/MIMETypeRegistry.h:
Detect media playlist mime types that are text (m3u8/m3u).

Source/WebInspectorUI:

* UserInterface/Base/MIMETypeUtilities.js:
(WI.shouldTreatMIMETypeAsText):
Support m3u8/m3u files as text.

LayoutTests:

* inspector/unit-tests/mimetype-utilities-expected.txt:
* inspector/unit-tests/mimetype-utilities.html:
Tests for shouldTreatMIMETypeAsText.

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

LayoutTests/ChangeLog
LayoutTests/inspector/unit-tests/mimetype-utilities-expected.txt
LayoutTests/inspector/unit-tests/mimetype-utilities.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/NetworkResourcesData.cpp
Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp
Source/WebCore/platform/MIMETypeRegistry.cpp
Source/WebCore/platform/MIMETypeRegistry.h
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/MIMETypeUtilities.js
Source/WebInspectorUI/UserInterface/Test/TestHarness.js

index f8998cc..9909214 100644 (file)
@@ -1,3 +1,15 @@
+2018-12-18  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: m3u8 content not shown, it should be text
+        https://bugs.webkit.org/show_bug.cgi?id=192731
+        <rdar://problem/46747728>
+
+        Reviewed by Devin Rousso.
+
+        * inspector/unit-tests/mimetype-utilities-expected.txt:
+        * inspector/unit-tests/mimetype-utilities.html:
+        Tests for shouldTreatMIMETypeAsText.
+
 2018-12-18  Daniel Bates  <dabates@apple.com>
 
         Remove <meta http-equiv=set-cookie> support
index acce625..fe1c7de 100644 (file)
@@ -28,3 +28,21 @@ PASS: File extension for "application/xhtml+xml" should be "xhtml".
 PASS: File extension for "image/svg+xml" should be "svg".
 PASS: File extension for "text/foo+xml" should be "xml".
 
+-- Running test case: shouldTreatMIMETypeAsText
+PASS: null mime type should not be treated as text.
+PASS: "application/unknown" should not be treated as text.
+PASS: "text/plain" should be treated as text.
+PASS: "text/javascript" should be treated as text.
+PASS: "application/json" should be treated as text.
+PASS: "application/vnd.api+json" should be treated as text.
+PASS: "application/vnd.apple.mpegurl" should be treated as text.
+PASS: "image/svg+xml" should be treated as text.
+PASS: "text/x-coffeescript" should be treated as text.
+PASS: "image/jpeg" should not be treated as text.
+PASS: "image/png" should not be treated as text.
+PASS: "image/gif" should not be treated as text.
+PASS: "font/woff" should not be treated as text.
+PASS: "video/mpeg" should not be treated as text.
+PASS: "audio/ogg" should not be treated as text.
+PASS: "application/pdf" should not be treated as text.
+
index 3f28ca6..ce954d9 100644 (file)
@@ -51,6 +51,39 @@ function test()
         }
     });
 
+    suite.addTestCase({
+        name: "shouldTreatMIMETypeAsText",
+        test() {
+            function expectText(mimeType) {
+                InspectorTest.expectTrue(WI.shouldTreatMIMETypeAsText(mimeType), `"${mimeType}" should be treated as text.`);
+            }
+            function expectNotText(mimeType) {
+                InspectorTest.expectFalse(WI.shouldTreatMIMETypeAsText(mimeType), `"${mimeType}" should not be treated as text.`);
+            }
+
+            InspectorTest.expectFalse(WI.shouldTreatMIMETypeAsText(null), `null mime type should not be treated as text.`);
+            expectNotText("application/unknown");
+
+            expectText("text/plain");
+            expectText("text/javascript");
+            expectText("application/json");
+            expectText("application/vnd.api+json");
+            expectText("application/vnd.apple.mpegurl");
+            expectText("image/svg+xml");
+            expectText("text/x-coffeescript");
+
+            expectNotText("image/jpeg");
+            expectNotText("image/png");
+            expectNotText("image/gif");
+            expectNotText("font/woff");
+            expectNotText("video/mpeg");
+            expectNotText("audio/ogg");
+            expectNotText("application/pdf");
+
+            return true;
+        }
+    })
+
     suite.runTestCasesAndFinish();
 }
 </script>
index 9da0b62..c169dad 100644 (file)
@@ -1,3 +1,24 @@
+2018-12-18  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: m3u8 content not shown, it should be text
+        https://bugs.webkit.org/show_bug.cgi?id=192731
+        <rdar://problem/46747728>
+
+        Reviewed by Devin Rousso.
+
+        * inspector/NetworkResourcesData.cpp:
+        (WebCore::NetworkResourcesData::setResourceContent):
+        Don't clobber data if setting empty content on a resource that has content.
+
+        * inspector/agents/InspectorNetworkAgent.cpp:
+        (WebCore::InspectorNetworkAgent::shouldTreatAsText):
+        Additional non-"text/" mime types that can be treated as text.
+
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::isTextMediaPlaylistMIMEType):
+        * platform/MIMETypeRegistry.h:
+        Detect media playlist mime types that are text (m3u8/m3u).
+
 2018-12-18  Daniel Bates  <dabates@apple.com>
 
         Remove <meta http-equiv=set-cookie> support
index 90520f3..df4c628 100644 (file)
@@ -187,6 +187,9 @@ InspectorPageAgent::ResourceType NetworkResourcesData::resourceType(const String
 
 void NetworkResourcesData::setResourceContent(const String& requestId, const String& content, bool base64Encoded)
 {
+    if (content.isNull())
+        return;
+
     ResourceData* resourceData = resourceDataForRequestId(requestId);
     if (!resourceData)
         return;
index 2230993..b662b68 100644 (file)
@@ -978,7 +978,8 @@ bool InspectorNetworkAgent::shouldTreatAsText(const String& mimeType)
     return startsWithLettersIgnoringASCIICase(mimeType, "text/")
         || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType)
         || MIMETypeRegistry::isSupportedJSONMIMEType(mimeType)
-        || MIMETypeRegistry::isXMLMIMEType(mimeType);
+        || MIMETypeRegistry::isXMLMIMEType(mimeType)
+        || MIMETypeRegistry::isTextMediaPlaylistMIMEType(mimeType);
 }
 
 Ref<TextResourceDecoder> InspectorNetworkAgent::createTextDecoder(const String& mimeType, const String& textEncodingName)
index c6bb703..15d3028 100644 (file)
@@ -499,6 +499,26 @@ bool MIMETypeRegistry::isSupportedFontMIMEType(const String& mimeType)
         || equalLettersIgnoringASCIICase(subtype, "sfnt");
 }
 
+bool MIMETypeRegistry::isTextMediaPlaylistMIMEType(const String& mimeType)
+{
+    if (startsWithLettersIgnoringASCIICase(mimeType, "application/")) {
+        static const unsigned applicationLength = 12;
+        auto subtype = StringView { mimeType }.substring(applicationLength);
+        return equalLettersIgnoringASCIICase(subtype, "vnd.apple.mpegurl")
+            || equalLettersIgnoringASCIICase(subtype, "mpegurl")
+            || equalLettersIgnoringASCIICase(subtype, "x-mpegurl");
+    }
+
+    if (startsWithLettersIgnoringASCIICase(mimeType, "audio/")) {
+        static const unsigned audioLength = 6;
+        auto subtype = StringView { mimeType }.substring(audioLength);
+        return equalLettersIgnoringASCIICase(subtype, "mpegurl")
+            || equalLettersIgnoringASCIICase(subtype, "x-mpegurl");
+    }
+
+    return false;
+}
+
 bool MIMETypeRegistry::isSupportedJSONMIMEType(const String& mimeType)
 {
     if (mimeType.isEmpty())
index 7c929be..19331ba 100644 (file)
@@ -63,6 +63,9 @@ public:
     // Check to see if a MIME type is suitable for being loaded as a font.
     static bool isSupportedFontMIMEType(const String& mimeType);
 
+    // Check to see if a MIME type is a text media playlist type, such as an m3u8.
+    static bool isTextMediaPlaylistMIMEType(const String& mimeType);
+
     // Check to see if a non-image MIME type is suitable for being loaded as a
     // document in a frame. Does not include supported JavaScript and JSON MIME types.
     WEBCORE_EXPORT static bool isSupportedNonImageMIMEType(const String& mimeType);
index e1b058d..7d0af5a 100644 (file)
@@ -1,3 +1,15 @@
+2018-12-18  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: m3u8 content not shown, it should be text
+        https://bugs.webkit.org/show_bug.cgi?id=192731
+        <rdar://problem/46747728>
+
+        Reviewed by Devin Rousso.
+
+        * UserInterface/Base/MIMETypeUtilities.js:
+        (WI.shouldTreatMIMETypeAsText):
+        Support m3u8/m3u files as text.
+
 2018-12-17  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: Canvas: path view is misaligned
index ed53a1f..b2837aa 100644 (file)
@@ -315,7 +315,14 @@ WI.shouldTreatMIMETypeAsText = function(mimeType)
     if (mimeType.endsWith("+json") || mimeType.endsWith("+xml"))
         return true;
 
+    // Various media text mime types.
+    let extension = WI.fileExtensionForMIMEType(mimeType);
+    if (extension === "m3u8" || extension === "m3u")
+        return true;
+
     // Various script and JSON mime types.
+    if (extension === "js" || extension === "json")
+        return true;
     if (mimeType.startsWith("application/"))
         return mimeType.endsWith("script") || mimeType.endsWith("json");
 
index ff66aca..64534d6 100644 (file)
@@ -116,6 +116,11 @@ TestHarness = class TestHarness extends WI.Object
         this._expect(TestHarness.ExpectationType.True, !!actual, message, actual);
     }
 
+    expectTrue(actual, message)
+    {
+        this._expect(TestHarness.ExpectationType.True, !!actual, message, actual);
+    }
+
     expectFalse(actual, message)
     {
         this._expect(TestHarness.ExpectationType.False, !actual, message, actual);