Add suport for a "text/plain" first arg to document.open() (no support for any

other types, and none really planned).  Bug 73409, r+sr=jst
This commit is contained in:
bzbarsky%mit.edu 2004-05-21 21:32:11 +00:00
Родитель 7572cc8684
Коммит f396e147a2
5 изменённых файлов: 44 добавлений и 15 удалений

Просмотреть файл

@ -1957,7 +1957,8 @@ nsHTMLDocument::GetSourceDocumentURI(nsIURI** sourceURI)
// XXX TBI: accepting arguments to the open method.
nsresult
nsHTMLDocument::OpenCommon(nsIURI* aSourceURI, PRBool aReplace)
nsHTMLDocument::OpenCommon(nsIURI* aSourceURI, const nsACString& aContentType,
PRBool aReplace)
{
// If we already have a parser we ignore the document.open call.
if (mParser) {
@ -2077,6 +2078,9 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURI, PRBool aReplace)
mParser = do_CreateInstance(kCParserCID, &rv);
// This will be propagated to the parser when someone actually calls write()
mContentType = aContentType;
mIsWriting = 1;
if (NS_SUCCEEDED(rv)) {
@ -2137,11 +2141,12 @@ NS_IMETHODIMP
nsHTMLDocument::Open()
{
nsCOMPtr<nsIDOMDocument> doc;
return Open(PR_FALSE, getter_AddRefs(doc));
return Open(NS_LITERAL_CSTRING("text/html"), PR_FALSE, getter_AddRefs(doc));
}
NS_IMETHODIMP
nsHTMLDocument::Open(PRBool aReplace, nsIDOMDocument** aReturn)
nsHTMLDocument::Open(const nsACString& aContentType, PRBool aReplace,
nsIDOMDocument** aReturn)
{
// XXX The URI of the newly created document will match
// that of the source document. Is this right?
@ -2157,7 +2162,7 @@ nsHTMLDocument::Open(PRBool aReplace, nsIDOMDocument** aReturn)
}
NS_ENSURE_SUCCESS(rv, rv);
rv = OpenCommon(sourceURI, aReplace);
rv = OpenCommon(sourceURI, aContentType, aReplace);
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(this, aReturn);
@ -2179,10 +2184,12 @@ nsHTMLDocument::Close()
if (mParser && mIsWriting) {
++mWriteLevel;
rv = mParser->Parse(NS_LITERAL_STRING("</HTML>"),
NS_GENERATE_PARSER_KEY(),
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
PR_TRUE);
if (mContentType.EqualsLiteral("text/html")) {
rv = mParser->Parse(NS_LITERAL_STRING("</HTML>"),
NS_GENERATE_PARSER_KEY(),
mContentType, PR_FALSE,
PR_TRUE);
}
--mWriteLevel;
mIsWriting = 0;
mParser = nsnull;
@ -2260,12 +2267,12 @@ nsHTMLDocument::WriteCommon(const nsAString& aText,
if (aNewlineTerminate) {
rv = mParser->Parse(aText + new_line,
NS_GENERATE_PARSER_KEY(),
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
mContentType, PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
} else {
rv = mParser->Parse(aText,
NS_GENERATE_PARSER_KEY(),
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
mContentType, PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
}

Просмотреть файл

@ -247,7 +247,8 @@ protected:
nsresult WriteCommon(const nsAString& aText,
PRBool aNewlineTerminate);
nsresult ScriptWriteCommon(PRBool aNewlineTerminate);
nsresult OpenCommon(nsIURI* aUrl, PRBool aReplace);
nsresult OpenCommon(nsIURI* aUrl, const nsACString& aContentType,
PRBool aReplace);
nsresult CreateAndAddWyciwygChannel(void);
nsresult RemoveWyciwygChannel(void);

Просмотреть файл

@ -57,9 +57,13 @@ interface nsIDOMNSHTMLDocument : nsISupports
// This is the internal version of open(); note that the version
// scriptable with JS is defined entirely in classinfo.
// If aContentType is not something supported by nsHTMLDocument and
// the HTML content sink, trying to write to the document will
// probably throw.
// Pass aReplace = true to trigger a replacement of the previous
// document in session history; pass false for normal history handling.
nsIDOMDocument open(in boolean aReplace);
nsIDOMDocument open(in ACString aContentType,
in boolean aReplace);
// Scriptable versions of write(), writeln(), clear().
void write();

Просмотреть файл

@ -5396,6 +5396,22 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc,
nsCOMPtr<nsIDOMNSHTMLDocument> doc(do_QueryInterface(native));
NS_ENSURE_TRUE(doc, JS_FALSE);
nsCAutoString contentType;
if (argc > 0) {
JSString* jsstr = JS_ValueToString(cx, argv[0]);
if (!jsstr) {
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_OUT_OF_MEMORY);
return JS_FALSE;
}
CopyUTF16toUTF8(NS_REINTERPRET_CAST(const PRUnichar*,
::JS_GetStringChars(jsstr)),
contentType);
ToLowerCase(contentType);
}
if (!contentType.EqualsLiteral("text/plain")){
contentType = "text/html";
}
PRBool replace = PR_FALSE;
if (argc > 1) {
JSString* jsstr = JS_ValueToString(cx, argv[1]);
@ -5410,7 +5426,7 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc,
}
nsCOMPtr<nsIDOMDocument> retval;
rv = doc->Open(replace, getter_AddRefs(retval));
rv = doc->Open(contentType, replace, getter_AddRefs(retval));
if (NS_FAILED(rv)) {
nsDOMClassInfo::ThrowJSException(cx, rv);

Просмотреть файл

@ -1099,8 +1099,9 @@ nsExpatDriver::GetMostDerivedIID(void) const
NS_IMETHODIMP_(void)
nsExpatDriver::Terminate()
{
// XXX - not sure what happens to the unparsed data.
XML_BlockParser(mExpatParser);
if (mExpatParser) {
XML_BlockParser(mExpatParser); // XXX - not sure what happens to the unparsed data.
}
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
}