From 0fc90867a33080b293ed2e025fafdba00d128ec3 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Wed, 31 Aug 2005 17:33:54 +0000 Subject: [PATCH] Sync up the MIME type list in parser with what nsContentDLF has, and improve the error handling for cases when a mismatch does happen. Bug 306502, r=mrbkap, sr=brendan git-svn-id: svn://10.0.0.236/trunk@179398 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/build/nsContentDLF.cpp | 2 ++ mozilla/parser/htmlparser/public/nsIParser.h | 8 ++++++-- mozilla/parser/htmlparser/src/nsExpatDriver.cpp | 9 ++++++--- mozilla/parser/htmlparser/src/nsParser.cpp | 7 ++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/mozilla/layout/build/nsContentDLF.cpp b/mozilla/layout/build/nsContentDLF.cpp index 29fd8647964..7e55e2a6f39 100644 --- a/mozilla/layout/build/nsContentDLF.cpp +++ b/mozilla/layout/build/nsContentDLF.cpp @@ -86,6 +86,8 @@ static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID); nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult); +// XXXbz if you change the MIME types here, be sure to update +// nsIParser.h and DetermineParseMode in nsParser.cpp accordingly. static const char* const gHTMLTypes[] = { "text/html", "text/plain", diff --git a/mozilla/parser/htmlparser/public/nsIParser.h b/mozilla/parser/htmlparser/public/nsIParser.h index df12c314dad..098bcf230da 100644 --- a/mozilla/parser/htmlparser/public/nsIParser.h +++ b/mozilla/parser/htmlparser/public/nsIParser.h @@ -383,7 +383,8 @@ const PRUnichar kLeftSquareBracket = '['; const PRUnichar kRightSquareBracket = ']'; const PRUnichar kNullCh = '\0'; -// XXXbz these type defines should really just go away.... +// XXXbz these type defines should really just go away.... Until they +// do, changes here should be reflected in nsContentDLF.cpp #define kHTMLTextContentType "text/html" #define kXMLTextContentType "text/xml" #define kXMLApplicationContentType "application/xml" @@ -396,7 +397,10 @@ const PRUnichar kNullCh = '\0'; #define kViewSourceCommand "view-source" #define kViewFragmentCommand "view-fragment" #define kTextCSSContentType "text/css" -#define kApplicationJSContentType "application/x-javascript" +#define kApplicationJSContentType "application/javascript" +#define kApplicationXJSContentType "application/x-javascript" +#define kTextECMAScriptContentType "text/ecmascript" +#define kApplicationECMAScriptContentType "application/ecmascript" #define kTextJSContentType "text/javascript" #define kSGMLTextContentType "text/sgml" #define kSVGTextContentType "image/svg+xml" diff --git a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp index eca64080332..edd3c461908 100644 --- a/mozilla/parser/htmlparser/src/nsExpatDriver.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatDriver.cpp @@ -1003,10 +1003,13 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext, nsITokenizer* aTokenizer, nsIContentSink* aSink) { - NS_ENSURE_ARG_POINTER(aSink); - mSink = do_QueryInterface(aSink); - NS_ENSURE_TRUE(mSink, NS_ERROR_FAILURE); + if (!mSink) { + NS_ERROR("nsExpatDriver didn't get an nsIExpatSink"); + // Make sure future calls to us bail out as needed + mInternalState = NS_ERROR_UNEXPECTED; + return mInternalState; + } static const XML_Memory_Handling_Suite memsuite = { diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp index 6ba3fe84c2e..a0133845d82 100644 --- a/mozilla/parser/htmlparser/src/nsParser.cpp +++ b/mozilla/parser/htmlparser/src/nsParser.cpp @@ -1151,6 +1151,9 @@ void DetermineParseMode(const nsString& aBuffer, } else if (aMimeType.EqualsLiteral(kPlainTextContentType) || aMimeType.EqualsLiteral(kTextCSSContentType) || aMimeType.EqualsLiteral(kApplicationJSContentType) || + aMimeType.EqualsLiteral(kApplicationXJSContentType) || + aMimeType.EqualsLiteral(kTextECMAScriptContentType) || + aMimeType.EqualsLiteral(kApplicationECMAScriptContentType) || aMimeType.EqualsLiteral(kTextJSContentType)) { aDocType = ePlainText; aParseMode = eDTDMode_quirks; @@ -2716,7 +2719,9 @@ nsresult nsParser::OnStopRequest(nsIRequest *request, nsISupports* aContext, if (mParserFilter) mParserFilter->Finish(); - rv = ResumeParse(PR_TRUE, PR_TRUE); + if (NS_SUCCEEDED(rv)) { + rv = ResumeParse(PR_TRUE, PR_TRUE); + } // If the parser isn't enabled, we don't finish parsing till // it is reenabled.