Backed out 3 changesets (bug 1718673, bug 196078) for causing wpt failures on report-frame-ancestors-with-x-frame-options.sub.html CLOSED TREE

Backed out changeset 6a54aa5039e7 (bug 196078)
Backed out changeset 0582d2fa1401 (bug 196078)
Backed out changeset d8d9a0fe366b (bug 1718673)
This commit is contained in:
Norisz Fay 2024-06-01 03:33:07 +03:00
parent adb0e480f5
commit f31e183290
14 changed files with 124 additions and 194 deletions

View file

@ -17,9 +17,10 @@ webidl Document;
/**
* To get a component that implements nsIDocumentLoaderFactory
* for a given mimetype, use nsContentUtils::FindInternalDocumentViewer.
* This will look up the MIME type within the "Gecko-Content-Viewers" category,
* with additional handlers for other content types.
* for a given mimetype, use nsICategoryManager to find an entry
* with the mimetype as its name in the category "Gecko-Content-Viewers".
* The value of the entry is the contractid of the component.
* The component is a service, so use GetService, not CreateInstance to get it.
*/
[scriptable, uuid(e795239e-9d3c-47c4-b063-9e600fb3b287)]

View file

@ -1081,13 +1081,21 @@ nsresult ExternalResourceMap::PendingLoad::SetupViewer(
new LoadgroupCallbacks(callbacks);
newLoadGroup->SetNotificationCallbacks(newCallbacks);
// This is some serious hackery cribbed from docshell
nsCOMPtr<nsICategoryManager> catMan =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
NS_ENSURE_TRUE(catMan, NS_ERROR_NOT_AVAILABLE);
nsCString contractId;
nsresult rv =
catMan->GetCategoryEntry("Gecko-Content-Viewers", type, contractId);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
nsContentUtils::FindInternalDocumentViewer(type);
do_GetService(contractId.get());
NS_ENSURE_TRUE(docLoaderFactory, NS_ERROR_NOT_AVAILABLE);
nsCOMPtr<nsIDocumentViewer> viewer;
nsCOMPtr<nsIStreamListener> listener;
nsresult rv = docLoaderFactory->CreateInstance(
rv = docLoaderFactory->CreateInstance(
"external-resource", chan, newLoadGroup, type, nullptr, nullptr,
getter_AddRefs(listener), getter_AddRefs(viewer));
NS_ENSURE_SUCCESS(rv, rv);

View file

@ -4626,66 +4626,27 @@ bool nsContentUtils::IsChildOfSameType(Document* aDoc) {
return false;
}
static bool IsJSONType(const nsACString& aContentType) {
return aContentType.EqualsLiteral(TEXT_JSON) ||
aContentType.EqualsLiteral(APPLICATION_JSON);
}
static bool IsNonPlainTextType(const nsACString& aContentType) {
// MIME type suffixes which should not be plain text.
static constexpr std::string_view kNonPlainTextTypes[] = {
"html",
"xml",
"xsl",
"calendar",
"x-calendar",
"x-vcalendar",
"vcalendar",
"vcard",
"x-vcard",
"directory",
"ldif",
"qif",
"x-qif",
"x-csv",
"x-vcf",
"rtf",
"comma-separated-values",
"csv",
"tab-separated-values",
"tsv",
"ofx",
"vnd.sun.j2me.app-descriptor",
"x-ms-iqy",
"x-ms-odc",
"x-ms-rqy",
"x-ms-contact"};
// Trim off the "text/" prefix for comparison.
MOZ_ASSERT(StringBeginsWith(aContentType, "text/"_ns));
std::string_view suffix = aContentType;
suffix.remove_prefix(5);
for (std::string_view type : kNonPlainTextTypes) {
if (type == suffix) {
return true;
}
}
return false;
}
bool nsContentUtils::IsPlainTextType(const nsACString& aContentType) {
// All `text/*`, any JSON type and any JavaScript type are considered "plain
// text" types for the purposes of how to render them as a document.
return (StringBeginsWith(aContentType, "text/"_ns) &&
!IsNonPlainTextType(aContentType)) ||
IsJSONType(aContentType) || IsJavascriptMIMEType(aContentType);
// NOTE: if you add a type here, add it to the CONTENTDLF_CATEGORIES
// define in nsContentDLF.h as well.
return aContentType.EqualsLiteral(TEXT_PLAIN) ||
aContentType.EqualsLiteral(TEXT_CSS) ||
aContentType.EqualsLiteral(TEXT_CACHE_MANIFEST) ||
aContentType.EqualsLiteral(TEXT_VTT) ||
aContentType.EqualsLiteral(APPLICATION_JAVASCRIPT) ||
aContentType.EqualsLiteral(APPLICATION_XJAVASCRIPT) ||
aContentType.EqualsLiteral(TEXT_ECMASCRIPT) ||
aContentType.EqualsLiteral(APPLICATION_ECMASCRIPT) ||
aContentType.EqualsLiteral(TEXT_JAVASCRIPT) ||
aContentType.EqualsLiteral(APPLICATION_JSON) ||
aContentType.EqualsLiteral(TEXT_JSON);
}
bool nsContentUtils::IsUtf8OnlyPlainTextType(const nsACString& aContentType) {
// NOTE: This must be a subset of the list in IsPlainTextType().
return IsJSONType(aContentType) ||
aContentType.EqualsLiteral(TEXT_CACHE_MANIFEST) ||
return aContentType.EqualsLiteral(TEXT_CACHE_MANIFEST) ||
aContentType.EqualsLiteral(APPLICATION_JSON) ||
aContentType.EqualsLiteral(TEXT_JSON) ||
aContentType.EqualsLiteral(TEXT_VTT);
}
@ -7251,12 +7212,9 @@ nsContentUtils::FindInternalDocumentViewer(const nsACString& aType,
return docFactory.forget();
}
// If the type wasn't registered in `Gecko-Content-Viewers`, check if it's
// another type which we may dynamically support, such as `text/*` types or
// video document types. These types are all backed by the nsContentDLF.
if (IsPlainTextType(aType) ||
DecoderTraits::IsSupportedInVideoDocument(aType)) {
docFactory = do_GetService(CONTENT_DLF_CONTRACTID);
if (DecoderTraits::IsSupportedInVideoDocument(aType)) {
docFactory =
do_GetService("@mozilla.org/content/document-loader-factory;1");
if (docFactory && aLoaderType) {
*aLoaderType = TYPE_CONTENT;
}
@ -7966,40 +7924,32 @@ void nsContentUtils::DestroyMatchString(void* aData) {
}
}
// Table ordered from most to least likely JS MIME types.
static constexpr std::string_view kJavascriptMIMETypes[] = {
"text/javascript",
"text/ecmascript",
"application/javascript",
"application/ecmascript",
"application/x-javascript",
"application/x-ecmascript",
"text/javascript1.0",
"text/javascript1.1",
"text/javascript1.2",
"text/javascript1.3",
"text/javascript1.4",
"text/javascript1.5",
"text/jscript",
"text/livescript",
"text/x-ecmascript",
"text/x-javascript"};
bool nsContentUtils::IsJavascriptMIMEType(const nsAString& aMIMEType) {
for (std::string_view type : kJavascriptMIMETypes) {
if (aMIMEType.LowerCaseEqualsASCII(type.data(), type.length())) {
return true;
}
}
return false;
}
// Table ordered from most to least likely JS MIME types.
static const char* jsTypes[] = {"text/javascript",
"text/ecmascript",
"application/javascript",
"application/ecmascript",
"application/x-javascript",
"application/x-ecmascript",
"text/javascript1.0",
"text/javascript1.1",
"text/javascript1.2",
"text/javascript1.3",
"text/javascript1.4",
"text/javascript1.5",
"text/jscript",
"text/livescript",
"text/x-ecmascript",
"text/x-javascript",
nullptr};
bool nsContentUtils::IsJavascriptMIMEType(const nsACString& aMIMEType) {
for (std::string_view type : kJavascriptMIMETypes) {
if (aMIMEType.LowerCaseEqualsASCII(type.data(), type.length())) {
for (uint32_t i = 0; jsTypes[i]; ++i) {
if (aMIMEType.LowerCaseEqualsASCII(jsTypes[i])) {
return true;
}
}
return false;
}

View file

@ -2764,7 +2764,6 @@ class nsContentUtils {
static bool IsJavaScriptLanguage(const nsString& aName);
static bool IsJavascriptMIMEType(const nsAString& aMIMEType);
static bool IsJavascriptMIMEType(const nsACString& aMIMEType);
static void SplitMimeType(const nsAString& aValue, nsString& aType,
nsString& aParams);

View file

@ -131,13 +131,20 @@ gfxSVGGlyphsDocument* gfxSVGGlyphs::FindOrCreateGlyphsDocument(
}
nsresult gfxSVGGlyphsDocument::SetupPresentation() {
nsCOMPtr<nsICategoryManager> catMan =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
nsCString contractId;
nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers",
"image/svg+xml", contractId);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
nsContentUtils::FindInternalDocumentViewer("image/svg+xml"_ns);
do_GetService(contractId.get());
NS_ASSERTION(docLoaderFactory, "Couldn't get DocumentLoaderFactory");
nsCOMPtr<nsIDocumentViewer> viewer;
nsresult rv = docLoaderFactory->CreateInstanceForDocument(
nullptr, mDocument, nullptr, getter_AddRefs(viewer));
rv = docLoaderFactory->CreateInstanceForDocument(nullptr, mDocument, nullptr,
getter_AddRefs(viewer));
NS_ENSURE_SUCCESS(rv, rv);
auto upem = mOwner->FontEntry()->UnitsPerEm();

View file

@ -283,14 +283,20 @@ nsresult SVGDocumentWrapper::SetupViewer(nsIRequest* aRequest,
NS_ENSURE_TRUE(newLoadGroup, NS_ERROR_OUT_OF_MEMORY);
newLoadGroup->SetLoadGroup(loadGroup);
nsCOMPtr<nsICategoryManager> catMan =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
NS_ENSURE_TRUE(catMan, NS_ERROR_NOT_AVAILABLE);
nsCString contractId;
nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", IMAGE_SVG_XML,
contractId);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
nsContentUtils::FindInternalDocumentViewer(
nsLiteralCString(IMAGE_SVG_XML));
do_GetService(contractId.get());
NS_ENSURE_TRUE(docLoaderFactory, NS_ERROR_NOT_AVAILABLE);
nsCOMPtr<nsIDocumentViewer> viewer;
nsCOMPtr<nsIStreamListener> listener;
nsresult rv = docLoaderFactory->CreateInstance(
rv = docLoaderFactory->CreateInstance(
"external-resource", chan, newLoadGroup, nsLiteralCString(IMAGE_SVG_XML),
nullptr, nullptr, getter_AddRefs(listener), getter_AddRefs(viewer));
NS_ENSURE_SUCCESS(rv, rv);

View file

@ -14,14 +14,23 @@ UnloadFunc = 'nsLayoutModuleDtor'
Priority = 100
content_types = [
'application/ecmascript',
'application/javascript',
'application/json',
'application/mathml+xml',
'application/rdf+xml',
'application/vnd.wap.xhtml+xml',
'application/x-javascript',
'application/x-view-source',
'application/xhtml+xml',
'application/xml',
'image/svg+xml',
'text/cache-manifest',
'text/css',
'text/ecmascript',
'text/html',
'text/javascript',
'text/json',
'text/plain',
'text/rdf',
'text/vtt',

View file

@ -101,7 +101,8 @@ nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel,
IsTypeInList(type, gHTMLTypes)) ||
nsContentUtils::IsPlainTextType(type) ||
IsTypeInList(type, gXMLTypes) ||
IsTypeInList(type, gSVGTypes);
IsTypeInList(type, gSVGTypes) ||
IsTypeInList(type, gXMLTypes);
if (knownType) {
viewSourceChannel->SetContentType(type);

View file

@ -55,4 +55,38 @@ 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

View file

@ -160,9 +160,6 @@ 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"]

View file

@ -1,67 +0,0 @@
/* 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");
// Unknown text/ types should be loadable as plain text documents.
await expectOutcome("text/unknown-type", "text");
});

View file

@ -1,14 +0,0 @@
"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>`);
}

View file

@ -166,12 +166,11 @@ HttpIndexViewer.prototype = {
aChannel.contentType = contentType;
// NOTE: This assumes that both text/html and text/plain will continue to be
// handled by nsContentDLF. If this ever changes this logic will need to be
// updated.
let factory = Cc[
"@mozilla.org/content/document-loader-factory;1"
].getService(Ci.nsIDocumentLoaderFactory);
let contract = Services.catMan.getCategoryEntry(
"Gecko-Content-Viewers",
contentType
);
let factory = Cc[contract].getService(Ci.nsIDocumentLoaderFactory);
let listener = {};
let res = factory.createInstance(

View file

@ -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/source/layout/build/components.conf>`_.
`web content types <https://searchfox.org/mozilla-central/search?q=CONTENTDLF_CATEGORIES&redirect=false>`_.