зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
7572cc8684
Коммит
f396e147a2
|
@ -1957,7 +1957,8 @@ nsHTMLDocument::GetSourceDocumentURI(nsIURI** sourceURI)
|
||||||
|
|
||||||
// XXX TBI: accepting arguments to the open method.
|
// XXX TBI: accepting arguments to the open method.
|
||||||
nsresult
|
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 we already have a parser we ignore the document.open call.
|
||||||
if (mParser) {
|
if (mParser) {
|
||||||
|
@ -2077,6 +2078,9 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURI, PRBool aReplace)
|
||||||
|
|
||||||
mParser = do_CreateInstance(kCParserCID, &rv);
|
mParser = do_CreateInstance(kCParserCID, &rv);
|
||||||
|
|
||||||
|
// This will be propagated to the parser when someone actually calls write()
|
||||||
|
mContentType = aContentType;
|
||||||
|
|
||||||
mIsWriting = 1;
|
mIsWriting = 1;
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
@ -2137,11 +2141,12 @@ NS_IMETHODIMP
|
||||||
nsHTMLDocument::Open()
|
nsHTMLDocument::Open()
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIDOMDocument> doc;
|
nsCOMPtr<nsIDOMDocument> doc;
|
||||||
return Open(PR_FALSE, getter_AddRefs(doc));
|
return Open(NS_LITERAL_CSTRING("text/html"), PR_FALSE, getter_AddRefs(doc));
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
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
|
// XXX The URI of the newly created document will match
|
||||||
// that of the source document. Is this right?
|
// that of the source document. Is this right?
|
||||||
|
@ -2157,7 +2162,7 @@ nsHTMLDocument::Open(PRBool aReplace, nsIDOMDocument** aReturn)
|
||||||
}
|
}
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
rv = OpenCommon(sourceURI, aReplace);
|
rv = OpenCommon(sourceURI, aContentType, aReplace);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
return CallQueryInterface(this, aReturn);
|
return CallQueryInterface(this, aReturn);
|
||||||
|
@ -2179,10 +2184,12 @@ nsHTMLDocument::Close()
|
||||||
|
|
||||||
if (mParser && mIsWriting) {
|
if (mParser && mIsWriting) {
|
||||||
++mWriteLevel;
|
++mWriteLevel;
|
||||||
rv = mParser->Parse(NS_LITERAL_STRING("</HTML>"),
|
if (mContentType.EqualsLiteral("text/html")) {
|
||||||
NS_GENERATE_PARSER_KEY(),
|
rv = mParser->Parse(NS_LITERAL_STRING("</HTML>"),
|
||||||
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
|
NS_GENERATE_PARSER_KEY(),
|
||||||
PR_TRUE);
|
mContentType, PR_FALSE,
|
||||||
|
PR_TRUE);
|
||||||
|
}
|
||||||
--mWriteLevel;
|
--mWriteLevel;
|
||||||
mIsWriting = 0;
|
mIsWriting = 0;
|
||||||
mParser = nsnull;
|
mParser = nsnull;
|
||||||
|
@ -2260,12 +2267,12 @@ nsHTMLDocument::WriteCommon(const nsAString& aText,
|
||||||
if (aNewlineTerminate) {
|
if (aNewlineTerminate) {
|
||||||
rv = mParser->Parse(aText + new_line,
|
rv = mParser->Parse(aText + new_line,
|
||||||
NS_GENERATE_PARSER_KEY(),
|
NS_GENERATE_PARSER_KEY(),
|
||||||
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
|
mContentType, PR_FALSE,
|
||||||
(!mIsWriting || (mWriteLevel > 1)));
|
(!mIsWriting || (mWriteLevel > 1)));
|
||||||
} else {
|
} else {
|
||||||
rv = mParser->Parse(aText,
|
rv = mParser->Parse(aText,
|
||||||
NS_GENERATE_PARSER_KEY(),
|
NS_GENERATE_PARSER_KEY(),
|
||||||
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
|
mContentType, PR_FALSE,
|
||||||
(!mIsWriting || (mWriteLevel > 1)));
|
(!mIsWriting || (mWriteLevel > 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -247,7 +247,8 @@ protected:
|
||||||
nsresult WriteCommon(const nsAString& aText,
|
nsresult WriteCommon(const nsAString& aText,
|
||||||
PRBool aNewlineTerminate);
|
PRBool aNewlineTerminate);
|
||||||
nsresult ScriptWriteCommon(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 CreateAndAddWyciwygChannel(void);
|
||||||
nsresult RemoveWyciwygChannel(void);
|
nsresult RemoveWyciwygChannel(void);
|
||||||
|
|
|
@ -57,9 +57,13 @@ interface nsIDOMNSHTMLDocument : nsISupports
|
||||||
|
|
||||||
// This is the internal version of open(); note that the version
|
// This is the internal version of open(); note that the version
|
||||||
// scriptable with JS is defined entirely in classinfo.
|
// 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
|
// Pass aReplace = true to trigger a replacement of the previous
|
||||||
// document in session history; pass false for normal history handling.
|
// 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().
|
// Scriptable versions of write(), writeln(), clear().
|
||||||
void write();
|
void write();
|
||||||
|
|
|
@ -5396,6 +5396,22 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc,
|
||||||
nsCOMPtr<nsIDOMNSHTMLDocument> doc(do_QueryInterface(native));
|
nsCOMPtr<nsIDOMNSHTMLDocument> doc(do_QueryInterface(native));
|
||||||
NS_ENSURE_TRUE(doc, JS_FALSE);
|
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;
|
PRBool replace = PR_FALSE;
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
JSString* jsstr = JS_ValueToString(cx, argv[1]);
|
JSString* jsstr = JS_ValueToString(cx, argv[1]);
|
||||||
|
@ -5410,7 +5426,7 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc,
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMDocument> retval;
|
nsCOMPtr<nsIDOMDocument> retval;
|
||||||
rv = doc->Open(replace, getter_AddRefs(retval));
|
rv = doc->Open(contentType, replace, getter_AddRefs(retval));
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||||
|
|
||||||
|
|
|
@ -1099,8 +1099,9 @@ nsExpatDriver::GetMostDerivedIID(void) const
|
||||||
NS_IMETHODIMP_(void)
|
NS_IMETHODIMP_(void)
|
||||||
nsExpatDriver::Terminate()
|
nsExpatDriver::Terminate()
|
||||||
{
|
{
|
||||||
// XXX - not sure what happens to the unparsed data.
|
if (mExpatParser) {
|
||||||
XML_BlockParser(mExpatParser);
|
XML_BlockParser(mExpatParser); // XXX - not sure what happens to the unparsed data.
|
||||||
|
}
|
||||||
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче