Bug 1444872. Remove support for the 'type' parameter to document.open. r=qdot

This commit is contained in:
Boris Zbarsky 2018-03-28 18:01:46 -04:00
parent 8d268c6ce7
commit 9bdcd1eca8
12 changed files with 92 additions and 24 deletions

View File

@ -12259,6 +12259,7 @@ nsIDocument::SetContentTypeInternal(const nsACString& aType)
mCachedEncoder = nullptr;
mContentType = aType;
mContentTypeForWriteCalls = aType;
}
nsILoadContext*

View File

@ -4239,6 +4239,8 @@ protected:
private:
nsCString mContentType;
protected:
// For document.write() we may need a different content type than mContentType.
nsCString mContentTypeForWriteCalls;
// The document's security info
nsCOMPtr<nsISupports> mSecurityInfo;

View File

@ -1205,7 +1205,7 @@ nsHTMLDocument::Open(JSContext* /* unused */,
already_AddRefed<nsIDocument>
nsHTMLDocument::Open(JSContext* cx,
const nsAString& aType,
const Optional<nsAString>& /* unused */,
const nsAString& aReplace,
ErrorResult& aError)
{
@ -1225,18 +1225,6 @@ nsHTMLDocument::Open(JSContext* cx,
return nullptr;
}
nsAutoCString contentType;
contentType.AssignLiteral("text/html");
nsAutoString type;
nsContentUtils::ASCIIToLower(aType, type);
nsAutoCString actualType, dummy;
NS_ParseRequestContentType(NS_ConvertUTF16toUTF8(type), actualType, dummy);
if (!actualType.EqualsLiteral("text/html") &&
!type.EqualsLiteral("replace")) {
contentType.AssignLiteral("text/plain");
}
// If we already have a parser we ignore the document.open call.
if (mParser || mParserAborted) {
// The WHATWG spec says: "If the document has an active parser that isn't
@ -1489,12 +1477,17 @@ nsHTMLDocument::Open(JSContext* cx,
mDidDocumentOpen = true;
nsAutoCString contentType(GetContentTypeInternal());
// Call Reset(), this will now do the full reset
Reset(channel, group);
if (baseURI) {
mDocumentBaseURI = baseURI;
}
// Restore our type, since Reset() resets it.
SetContentTypeInternal(contentType);
// Store the security info of the caller now that we're done
// resetting the document.
mSecurityInfo = securityInfo;
@ -1512,8 +1505,7 @@ nsHTMLDocument::Open(JSContext* cx,
}
}
// This will be propagated to the parser when someone actually calls write()
SetContentTypeInternal(contentType);
mContentTypeForWriteCalls.AssignLiteral("text/html");
// Prepare the docshell and the document viewer for the impending
// out of band document.write()
@ -1579,7 +1571,7 @@ nsHTMLDocument::Close(ErrorResult& rv)
++mWriteLevel;
rv = (static_cast<nsHtml5Parser*>(mParser.get()))->Parse(
EmptyString(), nullptr, GetContentTypeInternal(), true);
EmptyString(), nullptr, mContentTypeForWriteCalls, true);
--mWriteLevel;
// Even if that Parse() call failed, do the rest of this method
@ -1711,7 +1703,7 @@ nsHTMLDocument::WriteCommon(JSContext *cx,
mDocumentURI);
return;
}
nsCOMPtr<nsIDocument> ignored = Open(cx, NS_LITERAL_STRING("text/html"),
nsCOMPtr<nsIDocument> ignored = Open(cx, Optional<nsAString>(),
EmptyString(), aRv);
// If Open() fails, or if it didn't create a parser (as it won't
@ -1745,10 +1737,10 @@ nsHTMLDocument::WriteCommon(JSContext *cx,
// why pay that price when we don't need to?
if (aNewlineTerminate) {
aRv = (static_cast<nsHtml5Parser*>(mParser.get()))->Parse(
aText + new_line, key, GetContentTypeInternal(), false);
aText + new_line, key, mContentTypeForWriteCalls, false);
} else {
aRv = (static_cast<nsHtml5Parser*>(mParser.get()))->Parse(
aText, key, GetContentTypeInternal(), false);
aText, key, mContentTypeForWriteCalls, false);
}
--mWriteLevel;

View File

@ -167,7 +167,7 @@ public:
mozilla::ErrorResult& rv);
void GetSupportedNames(nsTArray<nsString>& aNames);
already_AddRefed<nsIDocument> Open(JSContext* cx,
const nsAString& aType,
const mozilla::dom::Optional<nsAString>& /* unused */,
const nsAString& aReplace,
mozilla::ErrorResult& aError);
already_AddRefed<nsPIDOMWindowOuter>

View File

@ -16,7 +16,7 @@ interface HTMLDocument : Document {
// dynamic markup insertion
[CEReactions, Throws]
Document open(optional DOMString type = "text/html", optional DOMString replace = "");
Document open(optional DOMString type, optional DOMString replace = ""); // type is ignored
[CEReactions, Throws]
WindowProxy? open(DOMString url, DOMString name, DOMString features, optional boolean replace = false);
[CEReactions, Throws]

View File

@ -1,2 +1,2 @@
<!DOCTYPE html>
<iframe src="data:text/plain,<i>foo</i>"></iframe>
<iframe src="data:text/html,<i>foo</i>"></iframe>

View File

@ -1,2 +1,2 @@
<!DOCTYPE html>
<iframe src="data:text/plain,<i>foo</i>"></iframe>
<iframe src="data:text/html,<i>foo</i>"></iframe>

View File

@ -1,2 +1,2 @@
<!DOCTYPE html>
<iframe src="data:text/plain,<i>foo</i>"></iframe>
<iframe src="data:text/html,<i>foo</i>"></iframe>

View File

@ -272039,6 +272039,11 @@
{}
]
],
"html/dom/dynamic-markup-insertion/opening-the-input-stream/type-argument-plaintext-subframe.txt": [
[
{}
]
],
"html/dom/elements-embedded.js": [
[
{}
@ -324095,6 +324100,18 @@
{}
]
],
"html/dom/dynamic-markup-insertion/opening-the-input-stream/type-argument-plaintext.window.js": [
[
"/html/dom/dynamic-markup-insertion/opening-the-input-stream/type-argument-plaintext.window.html",
{}
]
],
"html/dom/dynamic-markup-insertion/opening-the-input-stream/type-argument.window.js": [
[
"/html/dom/dynamic-markup-insertion/opening-the-input-stream/type-argument.window.html",
{}
]
],
"html/dom/elements/elements-in-the-dom/historical.html": [
[
"/html/dom/elements/elements-in-the-dom/historical.html",
@ -548258,6 +548275,18 @@
"a2a5acc9dfe53c7482eeaa4be3a4819238f8e120",
"testharness"
],
"html/dom/dynamic-markup-insertion/opening-the-input-stream/type-argument-plaintext-subframe.txt": [
"8d06cea05d408d70c59b1dbc5df3bda374d869a4",
"support"
],
"html/dom/dynamic-markup-insertion/opening-the-input-stream/type-argument-plaintext.window.js": [
"1f440ff93300a0ab715982feb067dd3162c8fce9",
"testharness"
],
"html/dom/dynamic-markup-insertion/opening-the-input-stream/type-argument.window.js": [
"0f0020e1d7d8050892ef146d687178cfe8eedcd2",
"testharness"
],
"html/dom/elements-embedded.js": [
"99489e3a8ac2be0d7dcfb22f7f45c30b00511358",
"support"

View File

@ -0,0 +1,23 @@
["replace",
"NOBODY",
"@ FD ;",
"it does not matter, you see \f",
"text/plain",
"text/xml",
"application/octet-stream",
"\0"].forEach(type => {
async_test(t => {
const frame = document.createElement("iframe");
frame.src = "type-argument-plaintext-subframe.txt";
document.body.appendChild(frame);
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func_done(() => {
frame.contentDocument.open(type);
frame.contentDocument.write("<B>heya</b>");
frame.contentDocument.close();
assert_equals(frame.contentDocument.body.firstChild.localName, "b");
assert_equals(frame.contentDocument.body.textContent, "heya");
assert_equals(frame.contentDocument.contentType, "text/plain");
});
}, "document.open() on plaintext document with type set to: " + type + " (type argument is supposed to be ignored)");
});

View File

@ -0,0 +1,20 @@
["replace",
"NOBODY",
"@ FD ;",
"it does not matter, you see \f",
"text/plain",
"text/xml",
"application/octet-stream",
"\0"].forEach(type => {
async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.contentDocument.open(type);
frame.contentDocument.write("<B>heya</b>");
frame.contentDocument.close();
assert_equals(frame.contentDocument.body.firstChild.localName, "b");
assert_equals(frame.contentDocument.body.textContent, "heya");
assert_equals(frame.contentDocument.contentType, "text/html");
t.done();
}, "document.open() with type set to: " + type + " (type argument is supposed to be ignored)");
});