diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 18f4dbfb65a0..5de319c6f39c 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -4632,8 +4632,8 @@ bool nsContentUtils::IsChildOfSameType(Document* aDoc) { } bool nsContentUtils::IsPlainTextType(const nsACString& aContentType) { - // NOTE: if you add a type here, add it to the CONTENTDLF_CATEGORIES - // define in nsContentDLF.h as well. + // NOTE: if you add a type here, add it to the content_types array in + // layout/build/components.conf as well. return aContentType.EqualsLiteral(TEXT_PLAIN) || aContentType.EqualsLiteral(TEXT_CSS) || aContentType.EqualsLiteral(TEXT_CACHE_MANIFEST) || @@ -4644,7 +4644,8 @@ bool nsContentUtils::IsPlainTextType(const nsACString& aContentType) { aContentType.EqualsLiteral(APPLICATION_ECMASCRIPT) || aContentType.EqualsLiteral(TEXT_JAVASCRIPT) || aContentType.EqualsLiteral(APPLICATION_JSON) || - aContentType.EqualsLiteral(TEXT_JSON); + aContentType.EqualsLiteral(TEXT_JSON) || + aContentType.EqualsLiteral(TEXT_EVENT_STREAM); } bool nsContentUtils::IsUtf8OnlyPlainTextType(const nsACString& aContentType) { diff --git a/layout/build/components.conf b/layout/build/components.conf index 2df60e3a84da..ec9eb24aeb0f 100644 --- a/layout/build/components.conf +++ b/layout/build/components.conf @@ -28,6 +28,7 @@ content_types = [ 'text/cache-manifest', 'text/css', 'text/ecmascript', + 'text/event-stream', 'text/html', 'text/javascript', 'text/json', diff --git a/layout/build/nsContentDLF.h b/layout/build/nsContentDLF.h index b16ec7550368..4743f4ee877d 100644 --- a/layout/build/nsContentDLF.h +++ b/layout/build/nsContentDLF.h @@ -55,38 +55,4 @@ class nsContentDLF final : public nsIDocumentLoaderFactory { nsresult NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult); -// clang-format off -#ifdef MOZ_WEBM -#define CONTENTDLF_WEBM_CATEGORIES \ - { "Gecko-Content-Viewers", VIDEO_WEBM, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", AUDIO_WEBM, "@mozilla.org/content/document-loader-factory;1" }, -#else -#define CONTENTDLF_WEBM_CATEGORIES -#endif - -#define CONTENTDLF_CATEGORIES \ - { "Gecko-Content-Viewers", TEXT_HTML, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", TEXT_PLAIN, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", TEXT_CACHE_MANIFEST, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", TEXT_CSS, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", TEXT_JAVASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", TEXT_ECMASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", APPLICATION_JAVASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", APPLICATION_ECMASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", APPLICATION_XJAVASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", APPLICATION_JSON, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", TEXT_JSON, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", APPLICATION_XHTML_XML, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", TEXT_XML, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", APPLICATION_XML, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", APPLICATION_RDF_XML, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", TEXT_RDF, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", VIEWSOURCE_CONTENT_TYPE, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", IMAGE_SVG_XML, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", APPLICATION_MATHML_XML, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", TEXT_VTT, "@mozilla.org/content/document-loader-factory;1" }, \ - { "Gecko-Content-Viewers", APPLICATION_WAPXHTML_XML, "@mozilla.org/content/document-loader-factory;1" }, \ - CONTENTDLF_WEBM_CATEGORIES -// clang-format on - #endif diff --git a/netwerk/test/browser/browser.toml b/netwerk/test/browser/browser.toml index 87296e917b36..39db35f2a27b 100644 --- a/netwerk/test/browser/browser.toml +++ b/netwerk/test/browser/browser.toml @@ -160,6 +160,9 @@ skip-if = ["os == 'win'"] # Bug 1775761 ["browser_cookie_sync_across_tabs.js"] +["browser_display_plaintext_types.js"] +support-files = ["res_hello_h1.sjs"] + ["browser_dns_prefetch_link_header.js"] ["browser_fetch_lnk.js"] diff --git a/netwerk/test/browser/browser_display_plaintext_types.js b/netwerk/test/browser/browser_display_plaintext_types.js new file mode 100644 index 000000000000..1b47be6f0c91 --- /dev/null +++ b/netwerk/test/browser/browser_display_plaintext_types.js @@ -0,0 +1,64 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const BASE_URI = + "http://mochi.test:8888/browser/netwerk/test/browser/res_hello_h1.sjs?type="; + +async function expectOutcome(aContentType, aBehavior) { + info(`Expecting ${aContentType} to be loaded as ${aBehavior}`); + const url = BASE_URI + aContentType; + + await BrowserTestUtils.withNewTab(url, async browser => { + await SpecialPowers.spawn(browser, [url, aBehavior], (url, aBehavior) => { + is(content.location.href, url, "expected url was loaded"); + switch (aBehavior) { + case "html": + is( + content.document.querySelector("h1").textContent, + "hello", + "parsed as HTML, so document should contain an

element" + ); + break; + case "text": + is( + content.document.body.textContent, + "

hello

", + "parsed as text, so document should contain bare text" + ); + break; + case "jsonviewer": + ok( + content.wrappedJSObject.JSONView, + "page has loaded the DevTools JSONViewer" + ); + break; + default: + ok(false, "unexpected behavior"); + break; + } + }); + }); +} + +add_task(async function test_display_plaintext_type() { + // Make sure that if the data is HTML it loads as HTML. + await expectOutcome("text/html", "html"); + + // For other text-like types, make sure we load as plain text. + await expectOutcome("text/plain", "text"); + + await expectOutcome("application/ecmascript", "text"); + await expectOutcome("application/javascript", "text"); + await expectOutcome("application/x-javascript", "text"); + await expectOutcome("text/cache-manifest", "text"); + await expectOutcome("text/css", "text"); + await expectOutcome("text/ecmascript", "text"); + await expectOutcome("text/event-stream", "text"); + await expectOutcome("text/javascript", "text"); + + await expectOutcome("application/json", "jsonviewer"); + // NOTE: text/json does not load JSON viewer? + await expectOutcome("text/json", "text"); +}); diff --git a/netwerk/test/browser/res_hello_h1.sjs b/netwerk/test/browser/res_hello_h1.sjs new file mode 100644 index 000000000000..7ff3e250f0b0 --- /dev/null +++ b/netwerk/test/browser/res_hello_h1.sjs @@ -0,0 +1,14 @@ +"use strict"; + +function handleRequest(request, response) { + const query = new URLSearchParams(request.queryString); + + // If the + let type = "text/html"; + if (query.has("type")) { + type = query.get("type"); + } + response.setHeader("Content-Type", type, false); + + response.write(`

hello

`); +} diff --git a/uriloader/docs/uriloader.rst b/uriloader/docs/uriloader.rst index e0763233e5ab..8cfa765f064b 100644 --- a/uriloader/docs/uriloader.rst +++ b/uriloader/docs/uriloader.rst @@ -43,4 +43,4 @@ flags passed to the loader service): For the most part the process ends at step 1 because nsDocShell passes a ``nsDSURIContentListener`` for the ``nsIURIContentListener`` consulted first and it accepts most of the -`web content types `_. +`web content types `_.