mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 1718673 - Allow loading text/event-stream in-browser as plain-text, r=smaug,necko-reviewers,kershaw
This patch also updates some documentation which was telling folks supporting new content types to update dead code. Differential Revision: https://phabricator.services.mozilla.com/D211797
This commit is contained in:
parent
83e10bcf4c
commit
9306cb7c3e
@ -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) {
|
||||
|
@ -28,6 +28,7 @@ content_types = [
|
||||
'text/cache-manifest',
|
||||
'text/css',
|
||||
'text/ecmascript',
|
||||
'text/event-stream',
|
||||
'text/html',
|
||||
'text/javascript',
|
||||
'text/json',
|
||||
|
@ -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
|
||||
|
@ -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"]
|
||||
|
64
netwerk/test/browser/browser_display_plaintext_types.js
Normal file
64
netwerk/test/browser/browser_display_plaintext_types.js
Normal file
@ -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 <h1> element"
|
||||
);
|
||||
break;
|
||||
case "text":
|
||||
is(
|
||||
content.document.body.textContent,
|
||||
"<h1>hello</h1>",
|
||||
"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");
|
||||
});
|
14
netwerk/test/browser/res_hello_h1.sjs
Normal file
14
netwerk/test/browser/res_hello_h1.sjs
Normal file
@ -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(`<h1>hello</h1>`);
|
||||
}
|
@ -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 <https://searchfox.org/mozilla-central/search?q=CONTENTDLF_CATEGORIES&redirect=false>`_.
|
||||
`web content types <https://searchfox.org/mozilla-central/source/layout/build/components.conf>`_.
|
||||
|
Loading…
Reference in New Issue
Block a user