From d444ccf9895256e2712df4db5267aeebf8de9e5d Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Tue, 16 Feb 1999 07:38:27 +0000 Subject: [PATCH] fixed a wad of little bugs and added regression test git-svn-id: svn://10.0.0.236/trunk@20772 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLContentSink.cpp | 4 +- .../html/document/src/nsHTMLDocument.cpp | 6 +- .../xml/document/src/nsXMLDocument.cpp | 2 +- mozilla/htmlparser/src/CNavDTD.cpp | 94 +++++++++++++++++-- mozilla/htmlparser/src/CNavDTD.h | 4 + mozilla/htmlparser/src/COtherDTD.cpp | 1 - mozilla/htmlparser/src/nsDTDUtils.cpp | 49 +++++++++- mozilla/htmlparser/src/nsDTDUtils.h | 17 +++- mozilla/htmlparser/src/nsElementTable.cpp | 23 ++--- mozilla/htmlparser/src/nsHTMLTokens.cpp | 12 ++- mozilla/htmlparser/src/nsIParser.h | 16 +++- mozilla/htmlparser/src/nsParser.cpp | 51 +++++----- mozilla/htmlparser/src/nsParser.h | 2 +- mozilla/htmlparser/src/nsScanner.cpp | 5 +- mozilla/htmlparser/src/nsScanner.h | 2 +- mozilla/htmlparser/src/nsValidDTD.cpp | 1 - mozilla/htmlparser/src/nsViewSourceHTML.cpp | 27 ++---- mozilla/htmlparser/src/nsWellFormedDTD.cpp | 14 ++- mozilla/htmlparser/src/nsXIFDTD.cpp | 1 - .../html/document/src/nsHTMLContentSink.cpp | 4 +- .../html/document/src/nsHTMLDocument.cpp | 6 +- .../layout/xml/document/src/nsXMLDocument.cpp | 2 +- mozilla/parser/htmlparser/src/CNavDTD.cpp | 94 +++++++++++++++++-- mozilla/parser/htmlparser/src/CNavDTD.h | 4 + mozilla/parser/htmlparser/src/COtherDTD.cpp | 1 - mozilla/parser/htmlparser/src/nsDTDUtils.cpp | 49 +++++++++- mozilla/parser/htmlparser/src/nsDTDUtils.h | 17 +++- .../parser/htmlparser/src/nsElementTable.cpp | 23 ++--- .../parser/htmlparser/src/nsHTMLTokens.cpp | 12 ++- mozilla/parser/htmlparser/src/nsIParser.h | 16 +++- mozilla/parser/htmlparser/src/nsParser.cpp | 51 +++++----- mozilla/parser/htmlparser/src/nsParser.h | 2 +- mozilla/parser/htmlparser/src/nsScanner.cpp | 5 +- mozilla/parser/htmlparser/src/nsScanner.h | 2 +- mozilla/parser/htmlparser/src/nsValidDTD.cpp | 1 - .../htmlparser/src/nsViewSourceHTML.cpp | 27 ++---- .../parser/htmlparser/src/nsWellFormedDTD.cpp | 14 ++- mozilla/parser/htmlparser/src/nsXIFDTD.cpp | 1 - .../webshell/tests/viewer/nsBrowserWindow.cpp | 6 +- mozilla/webshell/tests/viewer/nsViewerApp.cpp | 2 +- 40 files changed, 486 insertions(+), 184 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 5b2dc5246a6..69e16c6f62b 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -28,7 +28,7 @@ #include "nsIPresShell.h" #include "nsIPresContext.h" #include "nsIViewManager.h" -#include "nsHTMLTokens.h" +#include "nsHTMLTokens.h" #include "nsHTMLEntities.h" #include "nsCRT.h" #include "prtime.h" @@ -1456,7 +1456,7 @@ HTMLContentSink::DidBuildModel(PRInt32 aQualityLevel) mHTMLDocument->SetTitle(""); } - // XXX this is silly; who cares? + // XXX this is silly; who cares? RickG cares. It's part of the regression test. So don't bug me. PRInt32 i, ns = mDocument->GetNumberOfShells(); for (i = 0; i < ns; i++) { nsCOMPtr shell(dont_AddRef(mDocument->GetShellAt(i))); diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index c1ead9bc866..770dfafa4fa 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -31,7 +31,7 @@ #include "nsIDOMNodeList.h" #include "nsIDOMElement.h" #include "nsIDOMText.h" -#include "nsIDOMComment.h" +#include "nsIDOMComment.h" #include "nsIDOMHTMLFormElement.h" #include "nsIPostToServer.h" #include "nsIStreamListener.h" @@ -1283,7 +1283,7 @@ nsHTMLDocument::Close() nsAutoString emptyStr(""); mWriteLevel++; result = mParser->Parse(emptyStr, NS_GENERATE_PARSER_KEY(), - PR_TRUE, PR_FALSE, PR_TRUE); + "text/html", PR_FALSE, PR_TRUE); mWriteLevel--; mIsWriting = 0; } @@ -1325,7 +1325,7 @@ nsHTMLDocument::WriteCommon(JSContext *cx, mWriteLevel++; result = mParser->Parse(str, NS_GENERATE_PARSER_KEY(), - PR_TRUE, PR_FALSE, + "text/html", PR_FALSE, (!mIsWriting || (mWriteLevel > 1))); mWriteLevel--; if (NS_OK != result) { diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index 3f544be4792..92524801260 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -307,7 +307,7 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl, } NS_RELEASE(sink); } - } + } return rv; } diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index a90f4f45220..f39046e67df 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -52,7 +52,6 @@ static NS_DEFINE_IID(kClassIID, NS_INAVHTML_DTD_IID); //static const char* kNullFilename= "Error: Null filename given"; static const char* kNullToken = "Error: Null token given"; static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kHTMLTextContentType = "text/html"; static char* kVerificationDir = "c:/temp"; static const char* kViewSourceCommand= "view-source"; @@ -130,12 +129,13 @@ public: the DTD. Uses a factory pattern ***************************************************************/ class CTagHandlerRegister { - - public: + CTagHandlerRegister() : mDeallocator(), mTagHandlerDeque(mDeallocator) { } + ~CTagHandlerRegister() { + } void RegisterTagHandler(nsITagHandler *aTagHandler){ mTagHandlerDeque.Push(aTagHandler); @@ -162,7 +162,7 @@ public: Note: This can also be attached to some object so it can be refcounted and destroyed if you want this to go away when not imbedded. ************************************************************************/ -CTagHandlerRegister gTagHandlerRegister; +//CTagHandlerRegister gTagHandlerRegister; /************************************************************************ @@ -357,6 +357,11 @@ CNavDTD::CNavDTD() : nsIDTD(){ mMapContext=0; mTokenizer=0; +#ifndef NS_DEBUG + mComputedCRC32=0; + mExpectedCRC32=0; +#endif + // DebugDumpContainmentRules2(*this,"c:/temp/DTDRules.new","New CNavDTD Containment Rules"); } @@ -435,7 +440,9 @@ PRBool CNavDTD::Verify(nsString& aURLRef,nsIParser* aParser){ PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){ PRBool result=PR_FALSE; if(!aCommand.Equals(kViewSourceCommand)) { - result=aContentType.Equals(kHTMLTextContentType); + if(PR_TRUE==aContentType.Equals(kHTMLTextContentType) || PR_TRUE==aContentType.Equals(kPlainTextContentType)) { + result=PR_TRUE; + } } return result; } @@ -448,8 +455,11 @@ PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVe */ eAutoDetectResult CNavDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){ eAutoDetectResult result=eUnknownDetect; - if(PR_TRUE==aType.Equals(kHTMLTextContentType)) + + if(PR_TRUE==aType.Equals(kHTMLTextContentType) || + PR_TRUE==aType.Equals(kPlainTextContentType)) { result=eValidDetect; + } else { //otherwise, look into the buffer to see if you recognize anything... if(BufferContainsHTML(aBuffer)){ @@ -479,6 +489,12 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParse if((aNotifySink) && (mSink)) { result = mSink->WillBuildModel(); } + +#ifdef NS_DEBUG + mComputedCRC32=0; + mExpectedCRC32=0; +#endif + } return result; } @@ -544,6 +560,15 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse result = mSink->DidBuildModel(1); +#ifdef DEBUG + if(mComputedCRC32!=mExpectedCRC32) { + if(mExpectedCRC32!=0) { + printf("Expected CRC: %u,",mExpectedCRC32); + } + printf("Computed CRC: %u.\n",mComputedCRC32); + } +#endif + if(mDTDDebug) { mDTDDebug->DumpVectorRecord(); } @@ -559,7 +584,6 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse * moved over to the delegate. Ah, so much to do... * * @update gess 5/21/98 - * @param aType * @param aToken * @param aParser * @return @@ -899,6 +923,7 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI * It's a generic hook to let us do pre processing. * @param aToken contains the tag in question * @param aChildTag is the tag itself. + * @param aNode is the node (tag) with associated attributes. * @return TRUE if tag processing should continue; FALSE if the tag has been handled. */ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode& aNode){ @@ -910,6 +935,44 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode result=CollectSkippedContent(aNode,theAttrCount); } + //********************************************************** + //XXX Hack until I get the node observer API in place... + + if(eHTMLTag_meta==aTag) { + PRInt32 theCount=aNode.GetAttributeCount(); + if(1 + const nsString& theKey=aNode.GetKeyAt(0); + if(theKey.EqualsIgnoreCase("HTTP-EQUIV")) { + const nsString& theKey2=aNode.GetKeyAt(1); + if(theKey2.EqualsIgnoreCase("CONTENT")) { + nsScanner* theScanner=mParser->GetScanner(); + if(theScanner) { + const nsString& theValue=aNode.GetValueAt(1); + theScanner->SetDocumentCharset(theValue); + } //if + } + } +#ifdef DEBUG + else if(theKey.EqualsIgnoreCase("NAME")) { + const nsString& theValue1=aNode.GetValueAt(0); + if(theValue1.EqualsIgnoreCase("\"CRC\"")) { + const nsString& theKey2=aNode.GetKeyAt(1); + if(theKey2.EqualsIgnoreCase("CONTENT")) { + const nsString& theValue2=aNode.GetValueAt(1); + PRInt32 err=0; + mExpectedCRC32=theValue2.ToInteger(&err); + } //if + } //if + } //else + } //if + }//if +#endif + + //XXX Hack until I get the node observer API in place... + //********************************************************** + if(NS_OK==result) { result=!gHTMLElements[aTag].HasSpecialProperty(kDiscardTag); } @@ -972,7 +1035,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) { // ahead and close the tag out anyway, since its // contents will be consumed. if (NS_SUCCEEDED(result)) { - nsresult rv = CloseHead(attrNode); + nsresult rv=CloseHead(attrNode); // XXX Only send along a failure. If the close // succeeded we still may need to indicate that the // parser has blocked (i.e. return the result of @@ -2192,6 +2255,7 @@ nsresult CNavDTD::CloseFrameset(const nsIParserNode& aNode){ } + /** * This method does two things: 1st, help construct * our own internal model of the content-stack; and @@ -2207,6 +2271,12 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){ nsresult result=NS_OK; eHTMLTags nodeType=(eHTMLTags)aNode.GetNodeType(); +#ifdef NS_DEBUG +#define K_OPENOP 100 + CRCStruct theStruct(nodeType,K_OPENOP); + mComputedCRC32=AccumulateCRC(mComputedCRC32,(char*)&theStruct,sizeof(theStruct)); +#endif + switch(nodeType) { case eHTMLTag_html: @@ -2288,8 +2358,12 @@ CNavDTD::CloseContainer(const nsIParserNode& aNode,eHTMLTags aTag, nsresult result=NS_OK; eHTMLTags nodeType=(eHTMLTags)aNode.GetNodeType(); - //XXX Hack! We know this is wrong, but it works - //for the general case until we get it right. +#ifdef NS_DEBUG +#define K_CLOSEOP 200 + CRCStruct theStruct(nodeType,K_CLOSEOP); + mComputedCRC32=AccumulateCRC(mComputedCRC32,(char*)&theStruct,sizeof(theStruct)); +#endif + switch(nodeType) { case eHTMLTag_html: diff --git a/mozilla/htmlparser/src/CNavDTD.h b/mozilla/htmlparser/src/CNavDTD.h index 5f8b4b11524..04825f6bcae 100644 --- a/mozilla/htmlparser/src/CNavDTD.h +++ b/mozilla/htmlparser/src/CNavDTD.h @@ -538,6 +538,10 @@ protected: PRInt32 mLineNumber; nsParser* mParser; nsITokenizer* mTokenizer; +#ifdef NS_DEBUG + PRUint32 mComputedCRC32; + PRUint32 mExpectedCRC32; +#endif }; extern NS_HTMLPARS nsresult NS_NewNavHTMLDTD(nsIDTD** aInstancePtrResult); diff --git a/mozilla/htmlparser/src/COtherDTD.cpp b/mozilla/htmlparser/src/COtherDTD.cpp index 9e7d08674a1..971333baefc 100644 --- a/mozilla/htmlparser/src/COtherDTD.cpp +++ b/mozilla/htmlparser/src/COtherDTD.cpp @@ -63,7 +63,6 @@ static NS_DEFINE_IID(kBaseClassIID, NS_INAVHTML_DTD_IID); //static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; //static const char* kNullToken = "Error: Null token given"; //static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -//static const char* kHTMLTextContentType = "text/html"; static nsAutoString gEmpty; diff --git a/mozilla/htmlparser/src/nsDTDUtils.cpp b/mozilla/htmlparser/src/nsDTDUtils.cpp index ff9c45e1c76..350ad994ab1 100644 --- a/mozilla/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/htmlparser/src/nsDTDUtils.cpp @@ -279,7 +279,10 @@ CTokenRecycler::~CTokenRecycler() { //We're also deleting the cache-deques themselves. int i; for(i=0;i> 24) ^ *data_blk_ptr++ ) & 0xff; + crc_accum = ( crc_accum << 8 ) ^ crc_table[i]; + } + return crc_accum; +} + diff --git a/mozilla/htmlparser/src/nsDTDUtils.h b/mozilla/htmlparser/src/nsDTDUtils.h index 5a772463eea..da57c8814f2 100644 --- a/mozilla/htmlparser/src/nsDTDUtils.h +++ b/mozilla/htmlparser/src/nsDTDUtils.h @@ -52,6 +52,7 @@ void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* aTitle); void DebugDumpContainmentRules2(nsIDTD& theDTD,const char* aFilename,const char* aTitle); +PRUint32 AccumulateCRC(PRUint32 crc_accum, char *data_blk_ptr, int data_blk_size); class nsTagStack { @@ -206,12 +207,26 @@ inline PRBool BufferContainsHTML(nsString& aBuffer){ nsString temp; aBuffer.Left(temp,200); temp.ToLowerCase(); - if((-1"); + findpos=aString.RFind("-->"); nsAutoString temp(""); while((kNotFound==findpos) && (NS_OK==result)) { result=aScanner.ReadUntil(temp,kMinus,PR_TRUE); if(NS_OK==result) { - result=aScanner.ReadWhile(temp,gMinus,PR_TRUE,PR_TRUE); //get all available '---' + result=aScanner.ReadWhile(temp,gEdibles,PR_TRUE,PR_TRUE); //get all available '---' } - findpos=temp.RFind("->"); + findpos=temp.RFind("-->"); + if(kNotFound==findpos) + findpos=temp.RFind("!>"); aString+=temp; temp=""; } //while @@ -964,7 +967,8 @@ nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScann PRUnichar ch=aString.Last(); if(ch!=aChar) aString+=aChar; - aString.StripChars("\r\n"); + aString.ReplaceChar(PRUnichar('\n'),PRUnichar(' ')); + aString.StripChars("\r"); //per the HTML spec, ignore linefeeds... return result; } diff --git a/mozilla/htmlparser/src/nsIParser.h b/mozilla/htmlparser/src/nsIParser.h index ddf17d2270c..7993f127a44 100644 --- a/mozilla/htmlparser/src/nsIParser.h +++ b/mozilla/htmlparser/src/nsIParser.h @@ -59,6 +59,12 @@ enum eParseMode { eParseMode_autodetect }; +enum eCRCQuality { + eCRCGood = 0, + eCRCFair, + eCRCPoor +}; + enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop}; /** @@ -128,7 +134,7 @@ class nsIParser : public nsISupports { virtual PRBool EnableParser(PRBool aState) = 0; virtual nsresult Parse(nsIURL* aURL,nsIStreamObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE) = 0; virtual nsresult Parse(fstream& aStream,PRBool aEnableVerify=PR_FALSE) = 0; - virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify,PRBool aLastCall) = 0; + virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall) = 0; /** * This method gets called when the tokens have been consumed, and it's time @@ -167,6 +173,7 @@ class nsIParser : public nsISupports { #define NS_ERROR_HTMLPARSER_INTERRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1007) #define NS_ERROR_HTMLPARSER_BADTOKENIZER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1008) #define NS_ERROR_HTMLPARSER_BADATTRIBUTE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1009) +#define NS_ERROR_HTMLPARSER_UNRESOLVEDDTD NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1010) /** * Return codes for parsing routines. @@ -221,4 +228,11 @@ const PRUint32 kLeftSquareBracket = '['; const PRUint32 kRightSquareBracket = ']'; const PRUnichar kNullCh = '\0'; +#define kHTMLTextContentType "text/html" +#define kXMLTextContentType "text/xml" +#define kXULTextContentType "text/xul" +#define kRDFTextContentType "text/rdf" +#define kXIFTextContentType "text/xif" +#define kPlainTextContentType "text/plain" + #endif diff --git a/mozilla/htmlparser/src/nsParser.cpp b/mozilla/htmlparser/src/nsParser.cpp index 642800e4185..e89b3e3577d 100644 --- a/mozilla/htmlparser/src/nsParser.cpp +++ b/mozilla/htmlparser/src/nsParser.cpp @@ -92,13 +92,12 @@ class CSharedParserObjects { public: CSharedParserObjects() : mDeallocator(), mDTDDeque(mDeallocator) { - /* - NS_NewWellFormed_DTD(&theDTD); - RegisterDTD(theDTD); - */ nsIDTD* theDTD; + NS_NewWellFormed_DTD(&theDTD); + RegisterDTD(theDTD); + NS_NewNavHTMLDTD(&theDTD); //do this as the default HTML DTD... mDTDDeque.Push(theDTD); @@ -608,7 +607,7 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){ CParserContext* pc=new CParserContext(new nsScanner(kUnknownFilename,aStream,PR_FALSE),&aStream,0); if(pc) { PushContext(*pc); - pc->mSourceType="text/html"; + pc->mSourceType=kHTMLTextContentType; pc->mStreamListenerState=eOnStart; pc->mMultipart=PR_FALSE; pc->mContextType=CParserContext::eCTStream; @@ -628,10 +627,10 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){ * * @update gess5/11/98 * @param aSourceBuffer contains a string-full of real content - * @param anHTMLString tells us whether we should assume the content is HTML (usually true) + * @param aContentType tells us what type of content to expect in the given string * @return error code -- 0 if ok, non-zero if error. */ -nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify,PRBool aLastCall){ +nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall){ #ifdef _rickgdebug { @@ -659,10 +658,7 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString, PushContext(*pc); pc->mStreamListenerState=eOnStart; pc->mContextType=CParserContext::eCTString; - if(PR_TRUE==anHTMLString) - pc->mSourceType="text/html"; - else - pc->mSourceType="text/xml"; // XXX rick is a fish + pc->mSourceType=aContentType; } else { NS_RELEASE(me); @@ -702,29 +698,30 @@ nsresult nsParser::ResumeParse(nsIDTD* aDefaultDTD) { nsresult result=NS_OK; if(mParserContext->mParserEnabled) { result=WillBuildModel(mParserContext->mScanner->GetFilename(),aDefaultDTD); - if (mParserContext->mDTD) { - mParserContext->mDTD->WillResumeParse(); - if(NS_OK==result) { - - result=Tokenize(); - result=BuildModel(); + if(mParserContext->mDTD) { + mParserContext->mDTD->WillResumeParse(); + if(NS_OK==result) { + + result=Tokenize(); + result=BuildModel(); if((!mParserContext->mMultipart) || ((eOnStop==mParserContext->mStreamListenerState) && (NS_OK==result))){ DidBuildModel(mStreamStatus); } else { mParserContext->mDTD->WillInterruptParse(); - // If we're told to block the parser, we disable - // all further parsing (and cache any data coming - // in) until the parser is enabled. - PRUint32 b1=NS_ERROR_HTMLPARSER_BLOCK; - if(NS_ERROR_HTMLPARSER_BLOCK==result) { - EnableParser(PR_FALSE); - result=NS_OK; - } - }//if - }//if + // If we're told to block the parser, we disable + // all further parsing (and cache any data coming + // in) until the parser is enabled. + PRUint32 b1=NS_ERROR_HTMLPARSER_BLOCK; + if(NS_ERROR_HTMLPARSER_BLOCK==result) { + EnableParser(PR_FALSE); + result=NS_OK; + } + }//if + }//if }//if + else result=NS_ERROR_HTMLPARSER_UNRESOLVEDDTD; }//if return result; } diff --git a/mozilla/htmlparser/src/nsParser.h b/mozilla/htmlparser/src/nsParser.h index 530c60e1466..da61602701c 100644 --- a/mozilla/htmlparser/src/nsParser.h +++ b/mozilla/htmlparser/src/nsParser.h @@ -166,7 +166,7 @@ friend class CTokenHandler; * @param appendTokens tells us whether we should insert tokens inline, or append them. * @return TRUE if all went well -- FALSE otherwise */ - virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE); + virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE); /** diff --git a/mozilla/htmlparser/src/nsScanner.cpp b/mozilla/htmlparser/src/nsScanner.cpp index 41a10b995e3..ed3950e1d72 100644 --- a/mozilla/htmlparser/src/nsScanner.cpp +++ b/mozilla/htmlparser/src/nsScanner.cpp @@ -119,7 +119,8 @@ void nsScanner::InitUnicodeDecoder() nsAutoString defaultCharset("ISO-8859-1"); SetDocumentCharset(defaultCharset); } -nsresult nsScanner::SetDocumentCharset(nsString& aCharset ) + +nsresult nsScanner::SetDocumentCharset(const nsString& aCharset ) { nsresult res = NS_OK; if(! mCharset.EqualsIgnoreCase(aCharset)) // see do we need to change a converter. @@ -372,7 +373,7 @@ nsresult nsScanner::PutBack(PRUnichar aChar) { * @return error status */ nsresult nsScanner::SkipWhitespace(void) { - static nsAutoString chars(" \n\r\t"); + static nsAutoString chars(" \n\r\t\b"); return SkipOver(chars); } diff --git a/mozilla/htmlparser/src/nsScanner.h b/mozilla/htmlparser/src/nsScanner.h index c27e400b24f..d6d19417938 100644 --- a/mozilla/htmlparser/src/nsScanner.h +++ b/mozilla/htmlparser/src/nsScanner.h @@ -269,7 +269,7 @@ class nsScanner { /** * Change the charset and the Unicode Decoder */ - nsresult SetDocumentCharset(nsString& aCharset); + nsresult SetDocumentCharset(const nsString& aCharset); protected: diff --git a/mozilla/htmlparser/src/nsValidDTD.cpp b/mozilla/htmlparser/src/nsValidDTD.cpp index 8f916d3d997..c4934c7fddc 100644 --- a/mozilla/htmlparser/src/nsValidDTD.cpp +++ b/mozilla/htmlparser/src/nsValidDTD.cpp @@ -60,7 +60,6 @@ static NS_DEFINE_IID(kClassIID, NS_VALID_DTD_IID); //static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; //static const char* kNullToken = "Error: Null token given"; //static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kXMLTextContentType = "text/xml"; static nsAutoString gEmpty; diff --git a/mozilla/htmlparser/src/nsViewSourceHTML.cpp b/mozilla/htmlparser/src/nsViewSourceHTML.cpp index ddc9dc3c303..79bb0cc65f1 100644 --- a/mozilla/htmlparser/src/nsViewSourceHTML.cpp +++ b/mozilla/htmlparser/src/nsViewSourceHTML.cpp @@ -57,8 +57,6 @@ static NS_DEFINE_IID(kClassIID, NS_VIEWSOURCE_HTML_IID); //static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; //static const char* kNullToken = "Error: Null token given"; //static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kHTMLTextContentType = "text/html"; -static const char* kXMLTextContentType = "text/xml"; static const char* kViewSourceCommand= "view-source"; static nsAutoString gEmpty; @@ -230,9 +228,13 @@ nsresult CViewSourceHTML::CreateNewInstance(nsIDTD** aInstancePtrResult){ * @return TRUE if this DTD can satisfy the request; FALSE otherwise. */ PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){ - PRBool result=(aContentType.Equals(kHTMLTextContentType) && (aCommand.Equals(kViewSourceCommand))); - if(!result) { - result=(aContentType.Equals(kXMLTextContentType) && (aCommand.Equals(kViewSourceCommand))); + PRBool result=PR_FALSE; + if(aCommand.Equals(kViewSourceCommand)) { + result=(aContentType.Equals(kXMLTextContentType) || + aContentType.Equals(kRDFTextContentType) || + aContentType.Equals(kHTMLTextContentType) || + aContentType.Equals(kPlainTextContentType) || + aContentType.Equals(kXULTextContentType)); } return result; } @@ -240,24 +242,15 @@ PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRI /** * This is called to ask the DTD if it recognizes either the aType or data in the buffer. + * We intentionally say NO to autodetect types so that XML and HTML dtds can do the right thing. + * If either of those DTD's say YES, then we'll agree and render either. + * * @update gess7/7/98 * @param * @return detect result */ eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsString& aType){ eAutoDetectResult result=eUnknownDetect; - if(PR_TRUE==aType.Equals(kHTMLTextContentType)) - result=eValidDetect; - else if(PR_TRUE==aType.Equals(kXMLTextContentType)) - result=eValidDetect; - else { - //otherwise, look into the buffer to see if you recognize anything... - if(BufferContainsHTML(aBuffer)){ - result=eValidDetect; - if(0==aType.Length()) - aType=kHTMLTextContentType; - } - } return result; } diff --git a/mozilla/htmlparser/src/nsWellFormedDTD.cpp b/mozilla/htmlparser/src/nsWellFormedDTD.cpp index 539df6ad97a..f392bbf438e 100644 --- a/mozilla/htmlparser/src/nsWellFormedDTD.cpp +++ b/mozilla/htmlparser/src/nsWellFormedDTD.cpp @@ -57,9 +57,6 @@ static NS_DEFINE_IID(kClassIID, NS_WELLFORMED_DTD_IID); //static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; //static const char* kNullToken = "Error: Null token given"; //static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kXMLTextContentType = "text/xml"; -static const char* kRDFTextContentType = "text/rdf"; -static const char* kXULTextContentType = "text/xul"; static const char* kViewSourceCommand= "view-source"; static nsAutoString gEmpty; @@ -187,7 +184,7 @@ PRBool CWellFormedDTD::CanParse(nsString& aContentType, nsString& aCommand, PRIn if(!aCommand.Equals(kViewSourceCommand)) { result=(aContentType.Equals(kXMLTextContentType) || aContentType.Equals(kRDFTextContentType) || - aContentType.Equals(kXULTextContentType)); + aContentType.Equals(kXULTextContentType)); } return result; } @@ -203,8 +200,15 @@ eAutoDetectResult CWellFormedDTD::AutoDetectContentType(nsString& aBuffer,nsStri eAutoDetectResult result=eUnknownDetect; if(PR_TRUE==aType.Equals(kXMLTextContentType) || PR_TRUE==aType.Equals(kRDFTextContentType) || - PR_TRUE==aType.Equals(kXULTextContentType)) + PR_TRUE==aType.Equals(kXULTextContentType)) { result=eValidDetect; + } + else { + if(-1SetTitle(""); } - // XXX this is silly; who cares? + // XXX this is silly; who cares? RickG cares. It's part of the regression test. So don't bug me. PRInt32 i, ns = mDocument->GetNumberOfShells(); for (i = 0; i < ns; i++) { nsCOMPtr shell(dont_AddRef(mDocument->GetShellAt(i))); diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index c1ead9bc866..770dfafa4fa 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -31,7 +31,7 @@ #include "nsIDOMNodeList.h" #include "nsIDOMElement.h" #include "nsIDOMText.h" -#include "nsIDOMComment.h" +#include "nsIDOMComment.h" #include "nsIDOMHTMLFormElement.h" #include "nsIPostToServer.h" #include "nsIStreamListener.h" @@ -1283,7 +1283,7 @@ nsHTMLDocument::Close() nsAutoString emptyStr(""); mWriteLevel++; result = mParser->Parse(emptyStr, NS_GENERATE_PARSER_KEY(), - PR_TRUE, PR_FALSE, PR_TRUE); + "text/html", PR_FALSE, PR_TRUE); mWriteLevel--; mIsWriting = 0; } @@ -1325,7 +1325,7 @@ nsHTMLDocument::WriteCommon(JSContext *cx, mWriteLevel++; result = mParser->Parse(str, NS_GENERATE_PARSER_KEY(), - PR_TRUE, PR_FALSE, + "text/html", PR_FALSE, (!mIsWriting || (mWriteLevel > 1))); mWriteLevel--; if (NS_OK != result) { diff --git a/mozilla/layout/xml/document/src/nsXMLDocument.cpp b/mozilla/layout/xml/document/src/nsXMLDocument.cpp index 3f544be4792..92524801260 100644 --- a/mozilla/layout/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/layout/xml/document/src/nsXMLDocument.cpp @@ -307,7 +307,7 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl, } NS_RELEASE(sink); } - } + } return rv; } diff --git a/mozilla/parser/htmlparser/src/CNavDTD.cpp b/mozilla/parser/htmlparser/src/CNavDTD.cpp index a90f4f45220..f39046e67df 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.cpp +++ b/mozilla/parser/htmlparser/src/CNavDTD.cpp @@ -52,7 +52,6 @@ static NS_DEFINE_IID(kClassIID, NS_INAVHTML_DTD_IID); //static const char* kNullFilename= "Error: Null filename given"; static const char* kNullToken = "Error: Null token given"; static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kHTMLTextContentType = "text/html"; static char* kVerificationDir = "c:/temp"; static const char* kViewSourceCommand= "view-source"; @@ -130,12 +129,13 @@ public: the DTD. Uses a factory pattern ***************************************************************/ class CTagHandlerRegister { - - public: + CTagHandlerRegister() : mDeallocator(), mTagHandlerDeque(mDeallocator) { } + ~CTagHandlerRegister() { + } void RegisterTagHandler(nsITagHandler *aTagHandler){ mTagHandlerDeque.Push(aTagHandler); @@ -162,7 +162,7 @@ public: Note: This can also be attached to some object so it can be refcounted and destroyed if you want this to go away when not imbedded. ************************************************************************/ -CTagHandlerRegister gTagHandlerRegister; +//CTagHandlerRegister gTagHandlerRegister; /************************************************************************ @@ -357,6 +357,11 @@ CNavDTD::CNavDTD() : nsIDTD(){ mMapContext=0; mTokenizer=0; +#ifndef NS_DEBUG + mComputedCRC32=0; + mExpectedCRC32=0; +#endif + // DebugDumpContainmentRules2(*this,"c:/temp/DTDRules.new","New CNavDTD Containment Rules"); } @@ -435,7 +440,9 @@ PRBool CNavDTD::Verify(nsString& aURLRef,nsIParser* aParser){ PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){ PRBool result=PR_FALSE; if(!aCommand.Equals(kViewSourceCommand)) { - result=aContentType.Equals(kHTMLTextContentType); + if(PR_TRUE==aContentType.Equals(kHTMLTextContentType) || PR_TRUE==aContentType.Equals(kPlainTextContentType)) { + result=PR_TRUE; + } } return result; } @@ -448,8 +455,11 @@ PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVe */ eAutoDetectResult CNavDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){ eAutoDetectResult result=eUnknownDetect; - if(PR_TRUE==aType.Equals(kHTMLTextContentType)) + + if(PR_TRUE==aType.Equals(kHTMLTextContentType) || + PR_TRUE==aType.Equals(kPlainTextContentType)) { result=eValidDetect; + } else { //otherwise, look into the buffer to see if you recognize anything... if(BufferContainsHTML(aBuffer)){ @@ -479,6 +489,12 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParse if((aNotifySink) && (mSink)) { result = mSink->WillBuildModel(); } + +#ifdef NS_DEBUG + mComputedCRC32=0; + mExpectedCRC32=0; +#endif + } return result; } @@ -544,6 +560,15 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse result = mSink->DidBuildModel(1); +#ifdef DEBUG + if(mComputedCRC32!=mExpectedCRC32) { + if(mExpectedCRC32!=0) { + printf("Expected CRC: %u,",mExpectedCRC32); + } + printf("Computed CRC: %u.\n",mComputedCRC32); + } +#endif + if(mDTDDebug) { mDTDDebug->DumpVectorRecord(); } @@ -559,7 +584,6 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse * moved over to the delegate. Ah, so much to do... * * @update gess 5/21/98 - * @param aType * @param aToken * @param aParser * @return @@ -899,6 +923,7 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI * It's a generic hook to let us do pre processing. * @param aToken contains the tag in question * @param aChildTag is the tag itself. + * @param aNode is the node (tag) with associated attributes. * @return TRUE if tag processing should continue; FALSE if the tag has been handled. */ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode& aNode){ @@ -910,6 +935,44 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode result=CollectSkippedContent(aNode,theAttrCount); } + //********************************************************** + //XXX Hack until I get the node observer API in place... + + if(eHTMLTag_meta==aTag) { + PRInt32 theCount=aNode.GetAttributeCount(); + if(1 + const nsString& theKey=aNode.GetKeyAt(0); + if(theKey.EqualsIgnoreCase("HTTP-EQUIV")) { + const nsString& theKey2=aNode.GetKeyAt(1); + if(theKey2.EqualsIgnoreCase("CONTENT")) { + nsScanner* theScanner=mParser->GetScanner(); + if(theScanner) { + const nsString& theValue=aNode.GetValueAt(1); + theScanner->SetDocumentCharset(theValue); + } //if + } + } +#ifdef DEBUG + else if(theKey.EqualsIgnoreCase("NAME")) { + const nsString& theValue1=aNode.GetValueAt(0); + if(theValue1.EqualsIgnoreCase("\"CRC\"")) { + const nsString& theKey2=aNode.GetKeyAt(1); + if(theKey2.EqualsIgnoreCase("CONTENT")) { + const nsString& theValue2=aNode.GetValueAt(1); + PRInt32 err=0; + mExpectedCRC32=theValue2.ToInteger(&err); + } //if + } //if + } //else + } //if + }//if +#endif + + //XXX Hack until I get the node observer API in place... + //********************************************************** + if(NS_OK==result) { result=!gHTMLElements[aTag].HasSpecialProperty(kDiscardTag); } @@ -972,7 +1035,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) { // ahead and close the tag out anyway, since its // contents will be consumed. if (NS_SUCCEEDED(result)) { - nsresult rv = CloseHead(attrNode); + nsresult rv=CloseHead(attrNode); // XXX Only send along a failure. If the close // succeeded we still may need to indicate that the // parser has blocked (i.e. return the result of @@ -2192,6 +2255,7 @@ nsresult CNavDTD::CloseFrameset(const nsIParserNode& aNode){ } + /** * This method does two things: 1st, help construct * our own internal model of the content-stack; and @@ -2207,6 +2271,12 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){ nsresult result=NS_OK; eHTMLTags nodeType=(eHTMLTags)aNode.GetNodeType(); +#ifdef NS_DEBUG +#define K_OPENOP 100 + CRCStruct theStruct(nodeType,K_OPENOP); + mComputedCRC32=AccumulateCRC(mComputedCRC32,(char*)&theStruct,sizeof(theStruct)); +#endif + switch(nodeType) { case eHTMLTag_html: @@ -2288,8 +2358,12 @@ CNavDTD::CloseContainer(const nsIParserNode& aNode,eHTMLTags aTag, nsresult result=NS_OK; eHTMLTags nodeType=(eHTMLTags)aNode.GetNodeType(); - //XXX Hack! We know this is wrong, but it works - //for the general case until we get it right. +#ifdef NS_DEBUG +#define K_CLOSEOP 200 + CRCStruct theStruct(nodeType,K_CLOSEOP); + mComputedCRC32=AccumulateCRC(mComputedCRC32,(char*)&theStruct,sizeof(theStruct)); +#endif + switch(nodeType) { case eHTMLTag_html: diff --git a/mozilla/parser/htmlparser/src/CNavDTD.h b/mozilla/parser/htmlparser/src/CNavDTD.h index 5f8b4b11524..04825f6bcae 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.h +++ b/mozilla/parser/htmlparser/src/CNavDTD.h @@ -538,6 +538,10 @@ protected: PRInt32 mLineNumber; nsParser* mParser; nsITokenizer* mTokenizer; +#ifdef NS_DEBUG + PRUint32 mComputedCRC32; + PRUint32 mExpectedCRC32; +#endif }; extern NS_HTMLPARS nsresult NS_NewNavHTMLDTD(nsIDTD** aInstancePtrResult); diff --git a/mozilla/parser/htmlparser/src/COtherDTD.cpp b/mozilla/parser/htmlparser/src/COtherDTD.cpp index 9e7d08674a1..971333baefc 100644 --- a/mozilla/parser/htmlparser/src/COtherDTD.cpp +++ b/mozilla/parser/htmlparser/src/COtherDTD.cpp @@ -63,7 +63,6 @@ static NS_DEFINE_IID(kBaseClassIID, NS_INAVHTML_DTD_IID); //static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; //static const char* kNullToken = "Error: Null token given"; //static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -//static const char* kHTMLTextContentType = "text/html"; static nsAutoString gEmpty; diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp index ff9c45e1c76..350ad994ab1 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp @@ -279,7 +279,10 @@ CTokenRecycler::~CTokenRecycler() { //We're also deleting the cache-deques themselves. int i; for(i=0;i> 24) ^ *data_blk_ptr++ ) & 0xff; + crc_accum = ( crc_accum << 8 ) ^ crc_table[i]; + } + return crc_accum; +} + diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.h b/mozilla/parser/htmlparser/src/nsDTDUtils.h index 5a772463eea..da57c8814f2 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.h +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.h @@ -52,6 +52,7 @@ void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* aTitle); void DebugDumpContainmentRules2(nsIDTD& theDTD,const char* aFilename,const char* aTitle); +PRUint32 AccumulateCRC(PRUint32 crc_accum, char *data_blk_ptr, int data_blk_size); class nsTagStack { @@ -206,12 +207,26 @@ inline PRBool BufferContainsHTML(nsString& aBuffer){ nsString temp; aBuffer.Left(temp,200); temp.ToLowerCase(); - if((-1"); + findpos=aString.RFind("-->"); nsAutoString temp(""); while((kNotFound==findpos) && (NS_OK==result)) { result=aScanner.ReadUntil(temp,kMinus,PR_TRUE); if(NS_OK==result) { - result=aScanner.ReadWhile(temp,gMinus,PR_TRUE,PR_TRUE); //get all available '---' + result=aScanner.ReadWhile(temp,gEdibles,PR_TRUE,PR_TRUE); //get all available '---' } - findpos=temp.RFind("->"); + findpos=temp.RFind("-->"); + if(kNotFound==findpos) + findpos=temp.RFind("!>"); aString+=temp; temp=""; } //while @@ -964,7 +967,8 @@ nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScann PRUnichar ch=aString.Last(); if(ch!=aChar) aString+=aChar; - aString.StripChars("\r\n"); + aString.ReplaceChar(PRUnichar('\n'),PRUnichar(' ')); + aString.StripChars("\r"); //per the HTML spec, ignore linefeeds... return result; } diff --git a/mozilla/parser/htmlparser/src/nsIParser.h b/mozilla/parser/htmlparser/src/nsIParser.h index ddf17d2270c..7993f127a44 100644 --- a/mozilla/parser/htmlparser/src/nsIParser.h +++ b/mozilla/parser/htmlparser/src/nsIParser.h @@ -59,6 +59,12 @@ enum eParseMode { eParseMode_autodetect }; +enum eCRCQuality { + eCRCGood = 0, + eCRCFair, + eCRCPoor +}; + enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop}; /** @@ -128,7 +134,7 @@ class nsIParser : public nsISupports { virtual PRBool EnableParser(PRBool aState) = 0; virtual nsresult Parse(nsIURL* aURL,nsIStreamObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE) = 0; virtual nsresult Parse(fstream& aStream,PRBool aEnableVerify=PR_FALSE) = 0; - virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify,PRBool aLastCall) = 0; + virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall) = 0; /** * This method gets called when the tokens have been consumed, and it's time @@ -167,6 +173,7 @@ class nsIParser : public nsISupports { #define NS_ERROR_HTMLPARSER_INTERRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1007) #define NS_ERROR_HTMLPARSER_BADTOKENIZER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1008) #define NS_ERROR_HTMLPARSER_BADATTRIBUTE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1009) +#define NS_ERROR_HTMLPARSER_UNRESOLVEDDTD NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1010) /** * Return codes for parsing routines. @@ -221,4 +228,11 @@ const PRUint32 kLeftSquareBracket = '['; const PRUint32 kRightSquareBracket = ']'; const PRUnichar kNullCh = '\0'; +#define kHTMLTextContentType "text/html" +#define kXMLTextContentType "text/xml" +#define kXULTextContentType "text/xul" +#define kRDFTextContentType "text/rdf" +#define kXIFTextContentType "text/xif" +#define kPlainTextContentType "text/plain" + #endif diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp index 642800e4185..e89b3e3577d 100644 --- a/mozilla/parser/htmlparser/src/nsParser.cpp +++ b/mozilla/parser/htmlparser/src/nsParser.cpp @@ -92,13 +92,12 @@ class CSharedParserObjects { public: CSharedParserObjects() : mDeallocator(), mDTDDeque(mDeallocator) { - /* - NS_NewWellFormed_DTD(&theDTD); - RegisterDTD(theDTD); - */ nsIDTD* theDTD; + NS_NewWellFormed_DTD(&theDTD); + RegisterDTD(theDTD); + NS_NewNavHTMLDTD(&theDTD); //do this as the default HTML DTD... mDTDDeque.Push(theDTD); @@ -608,7 +607,7 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){ CParserContext* pc=new CParserContext(new nsScanner(kUnknownFilename,aStream,PR_FALSE),&aStream,0); if(pc) { PushContext(*pc); - pc->mSourceType="text/html"; + pc->mSourceType=kHTMLTextContentType; pc->mStreamListenerState=eOnStart; pc->mMultipart=PR_FALSE; pc->mContextType=CParserContext::eCTStream; @@ -628,10 +627,10 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){ * * @update gess5/11/98 * @param aSourceBuffer contains a string-full of real content - * @param anHTMLString tells us whether we should assume the content is HTML (usually true) + * @param aContentType tells us what type of content to expect in the given string * @return error code -- 0 if ok, non-zero if error. */ -nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify,PRBool aLastCall){ +nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall){ #ifdef _rickgdebug { @@ -659,10 +658,7 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString, PushContext(*pc); pc->mStreamListenerState=eOnStart; pc->mContextType=CParserContext::eCTString; - if(PR_TRUE==anHTMLString) - pc->mSourceType="text/html"; - else - pc->mSourceType="text/xml"; // XXX rick is a fish + pc->mSourceType=aContentType; } else { NS_RELEASE(me); @@ -702,29 +698,30 @@ nsresult nsParser::ResumeParse(nsIDTD* aDefaultDTD) { nsresult result=NS_OK; if(mParserContext->mParserEnabled) { result=WillBuildModel(mParserContext->mScanner->GetFilename(),aDefaultDTD); - if (mParserContext->mDTD) { - mParserContext->mDTD->WillResumeParse(); - if(NS_OK==result) { - - result=Tokenize(); - result=BuildModel(); + if(mParserContext->mDTD) { + mParserContext->mDTD->WillResumeParse(); + if(NS_OK==result) { + + result=Tokenize(); + result=BuildModel(); if((!mParserContext->mMultipart) || ((eOnStop==mParserContext->mStreamListenerState) && (NS_OK==result))){ DidBuildModel(mStreamStatus); } else { mParserContext->mDTD->WillInterruptParse(); - // If we're told to block the parser, we disable - // all further parsing (and cache any data coming - // in) until the parser is enabled. - PRUint32 b1=NS_ERROR_HTMLPARSER_BLOCK; - if(NS_ERROR_HTMLPARSER_BLOCK==result) { - EnableParser(PR_FALSE); - result=NS_OK; - } - }//if - }//if + // If we're told to block the parser, we disable + // all further parsing (and cache any data coming + // in) until the parser is enabled. + PRUint32 b1=NS_ERROR_HTMLPARSER_BLOCK; + if(NS_ERROR_HTMLPARSER_BLOCK==result) { + EnableParser(PR_FALSE); + result=NS_OK; + } + }//if + }//if }//if + else result=NS_ERROR_HTMLPARSER_UNRESOLVEDDTD; }//if return result; } diff --git a/mozilla/parser/htmlparser/src/nsParser.h b/mozilla/parser/htmlparser/src/nsParser.h index 530c60e1466..da61602701c 100644 --- a/mozilla/parser/htmlparser/src/nsParser.h +++ b/mozilla/parser/htmlparser/src/nsParser.h @@ -166,7 +166,7 @@ friend class CTokenHandler; * @param appendTokens tells us whether we should insert tokens inline, or append them. * @return TRUE if all went well -- FALSE otherwise */ - virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE); + virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE); /** diff --git a/mozilla/parser/htmlparser/src/nsScanner.cpp b/mozilla/parser/htmlparser/src/nsScanner.cpp index 41a10b995e3..ed3950e1d72 100644 --- a/mozilla/parser/htmlparser/src/nsScanner.cpp +++ b/mozilla/parser/htmlparser/src/nsScanner.cpp @@ -119,7 +119,8 @@ void nsScanner::InitUnicodeDecoder() nsAutoString defaultCharset("ISO-8859-1"); SetDocumentCharset(defaultCharset); } -nsresult nsScanner::SetDocumentCharset(nsString& aCharset ) + +nsresult nsScanner::SetDocumentCharset(const nsString& aCharset ) { nsresult res = NS_OK; if(! mCharset.EqualsIgnoreCase(aCharset)) // see do we need to change a converter. @@ -372,7 +373,7 @@ nsresult nsScanner::PutBack(PRUnichar aChar) { * @return error status */ nsresult nsScanner::SkipWhitespace(void) { - static nsAutoString chars(" \n\r\t"); + static nsAutoString chars(" \n\r\t\b"); return SkipOver(chars); } diff --git a/mozilla/parser/htmlparser/src/nsScanner.h b/mozilla/parser/htmlparser/src/nsScanner.h index c27e400b24f..d6d19417938 100644 --- a/mozilla/parser/htmlparser/src/nsScanner.h +++ b/mozilla/parser/htmlparser/src/nsScanner.h @@ -269,7 +269,7 @@ class nsScanner { /** * Change the charset and the Unicode Decoder */ - nsresult SetDocumentCharset(nsString& aCharset); + nsresult SetDocumentCharset(const nsString& aCharset); protected: diff --git a/mozilla/parser/htmlparser/src/nsValidDTD.cpp b/mozilla/parser/htmlparser/src/nsValidDTD.cpp index 8f916d3d997..c4934c7fddc 100644 --- a/mozilla/parser/htmlparser/src/nsValidDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsValidDTD.cpp @@ -60,7 +60,6 @@ static NS_DEFINE_IID(kClassIID, NS_VALID_DTD_IID); //static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; //static const char* kNullToken = "Error: Null token given"; //static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kXMLTextContentType = "text/xml"; static nsAutoString gEmpty; diff --git a/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp b/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp index ddc9dc3c303..79bb0cc65f1 100644 --- a/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -57,8 +57,6 @@ static NS_DEFINE_IID(kClassIID, NS_VIEWSOURCE_HTML_IID); //static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; //static const char* kNullToken = "Error: Null token given"; //static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kHTMLTextContentType = "text/html"; -static const char* kXMLTextContentType = "text/xml"; static const char* kViewSourceCommand= "view-source"; static nsAutoString gEmpty; @@ -230,9 +228,13 @@ nsresult CViewSourceHTML::CreateNewInstance(nsIDTD** aInstancePtrResult){ * @return TRUE if this DTD can satisfy the request; FALSE otherwise. */ PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){ - PRBool result=(aContentType.Equals(kHTMLTextContentType) && (aCommand.Equals(kViewSourceCommand))); - if(!result) { - result=(aContentType.Equals(kXMLTextContentType) && (aCommand.Equals(kViewSourceCommand))); + PRBool result=PR_FALSE; + if(aCommand.Equals(kViewSourceCommand)) { + result=(aContentType.Equals(kXMLTextContentType) || + aContentType.Equals(kRDFTextContentType) || + aContentType.Equals(kHTMLTextContentType) || + aContentType.Equals(kPlainTextContentType) || + aContentType.Equals(kXULTextContentType)); } return result; } @@ -240,24 +242,15 @@ PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRI /** * This is called to ask the DTD if it recognizes either the aType or data in the buffer. + * We intentionally say NO to autodetect types so that XML and HTML dtds can do the right thing. + * If either of those DTD's say YES, then we'll agree and render either. + * * @update gess7/7/98 * @param * @return detect result */ eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsString& aType){ eAutoDetectResult result=eUnknownDetect; - if(PR_TRUE==aType.Equals(kHTMLTextContentType)) - result=eValidDetect; - else if(PR_TRUE==aType.Equals(kXMLTextContentType)) - result=eValidDetect; - else { - //otherwise, look into the buffer to see if you recognize anything... - if(BufferContainsHTML(aBuffer)){ - result=eValidDetect; - if(0==aType.Length()) - aType=kHTMLTextContentType; - } - } return result; } diff --git a/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp b/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp index 539df6ad97a..f392bbf438e 100644 --- a/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp @@ -57,9 +57,6 @@ static NS_DEFINE_IID(kClassIID, NS_WELLFORMED_DTD_IID); //static const char* kNullTokenizer = "Error: Unable to construct tokenizer"; //static const char* kNullToken = "Error: Null token given"; //static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; -static const char* kXMLTextContentType = "text/xml"; -static const char* kRDFTextContentType = "text/rdf"; -static const char* kXULTextContentType = "text/xul"; static const char* kViewSourceCommand= "view-source"; static nsAutoString gEmpty; @@ -187,7 +184,7 @@ PRBool CWellFormedDTD::CanParse(nsString& aContentType, nsString& aCommand, PRIn if(!aCommand.Equals(kViewSourceCommand)) { result=(aContentType.Equals(kXMLTextContentType) || aContentType.Equals(kRDFTextContentType) || - aContentType.Equals(kXULTextContentType)); + aContentType.Equals(kXULTextContentType)); } return result; } @@ -203,8 +200,15 @@ eAutoDetectResult CWellFormedDTD::AutoDetectContentType(nsString& aBuffer,nsStri eAutoDetectResult result=eUnknownDetect; if(PR_TRUE==aType.Equals(kXMLTextContentType) || PR_TRUE==aType.Equals(kRDFTextContentType) || - PR_TRUE==aType.Equals(kXULTextContentType)) + PR_TRUE==aType.Equals(kXULTextContentType)) { result=eValidDetect; + } + else { + if(-1RegisterDTD(dtd); //dtd->SetContentSink(sink); //dtd->SetParser(parser); - parser->Parse(buffer, 0, PR_FALSE,PR_FALSE,PR_TRUE); + parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE); } NS_IF_RELEASE(dtd); NS_IF_RELEASE(sink); @@ -2889,7 +2889,7 @@ nsBrowserWindow::DoDebugSave() parser->RegisterDTD(dtd); //dtd->SetContentSink(sink); //dtd->SetParser(parser); - parser->Parse(buffer, 0, PR_FALSE,PR_FALSE,PR_TRUE); + parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE); } out.close(); diff --git a/mozilla/webshell/tests/viewer/nsViewerApp.cpp b/mozilla/webshell/tests/viewer/nsViewerApp.cpp index d168d8d115e..8a1625e5a69 100644 --- a/mozilla/webshell/tests/viewer/nsViewerApp.cpp +++ b/mozilla/webshell/tests/viewer/nsViewerApp.cpp @@ -21,7 +21,7 @@ #define INITGUID #endif #include "nsCOMPtr.h" -#include "nsXPBaseWindow.h" +#include "nsXPBaseWindow.h" #include "nsViewerApp.h" #include "nsBrowserWindow.h" #include "nsWidgetsCID.h"