diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index ccdf7fd4b7a..a59b6f2f4e9 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -347,6 +347,7 @@ CNavDTD::CNavDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0), mShared mComputedCRC32=0; mExpectedCRC32=0; mSaveBadTokens = PR_FALSE; + mDTDState=NS_OK; // DebugDumpContainmentRules2(*this,"c:/temp/DTDRules.new","New CNavDTD Containment Rules"); #ifdef RICKG_DEBUG nsHTMLElement::DebugDumpContainment("c:/temp/rules.new","ElementTable Rules"); @@ -542,11 +543,17 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke NS_ADDREF(mSink); gRecycler=(CTokenRecycler*)mTokenizer->GetTokenRecycler(); while(NS_SUCCEEDED(result)){ - CToken* theToken=mTokenizer->PopToken(); - if(theToken) { - result=HandleToken(theToken,aParser); + if(mDTDState!=NS_ERROR_HTMLPARSER_STOPPARSING) { + CToken* theToken=mTokenizer->PopToken(); + if(theToken) { + result=HandleToken(theToken,aParser); + } + else break; + } + else { + result=mDTDState; + break; } - else break; }//while mTokenizer=oldTokenizer; NS_IF_RELEASE(mSink); @@ -636,6 +643,7 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse } return result; } + /** * This big dispatch method is used to route token handler calls to the right place. * What's wrong with it? This table, and the dispatch methods themselves need to be diff --git a/htmlparser/src/CNavDTD.h b/htmlparser/src/CNavDTD.h index 3e4d1cf352a..3223b5f595e 100644 --- a/htmlparser/src/CNavDTD.h +++ b/htmlparser/src/CNavDTD.h @@ -369,6 +369,18 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { */ virtual PRInt32 GetTopmostIndexOf(eHTMLTags aTagSet[],PRInt32 aCount) const; + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void) { return mDTDState=NS_ERROR_HTMLPARSER_STOPPARSING; } + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. @@ -520,6 +532,7 @@ protected: PRBool mHasOpenBody; PRBool mHadFrameset; PRBool mHadBody; + PRBool mDTDState; nsString mFilename; nsIDTDDebug* mDTDDebug; PRInt32 mLineNumber; diff --git a/htmlparser/src/CRtfDTD.cpp b/htmlparser/src/CRtfDTD.cpp index 82b4f2dd5a9..c3b71d1aa6b 100644 --- a/htmlparser/src/CRtfDTD.cpp +++ b/htmlparser/src/CRtfDTD.cpp @@ -478,6 +478,21 @@ nsITokenRecycler* CRtfDTD::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult CRtfDTD::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} + /*************************************************************** Heres's the RTFControlWord subclass... ***************************************************************/ diff --git a/htmlparser/src/CRtfDTD.h b/htmlparser/src/CRtfDTD.h index eb0696245ab..9c5069cfec7 100644 --- a/htmlparser/src/CRtfDTD.h +++ b/htmlparser/src/CRtfDTD.h @@ -338,6 +338,18 @@ class CRtfDTD : public nsIDTD { */ virtual nsITokenRecycler* GetTokenRecycler(void); + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/htmlparser/src/nsExpatDTD.cpp b/htmlparser/src/nsExpatDTD.cpp index 7bfbe70f49a..7b131eaec43 100644 --- a/htmlparser/src/nsExpatDTD.cpp +++ b/htmlparser/src/nsExpatDTD.cpp @@ -279,6 +279,20 @@ nsITokenRecycler* nsExpatDTD::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult nsExpatDTD::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} /** * Sets up the callbacks for the expat parser diff --git a/htmlparser/src/nsExpatDTD.h b/htmlparser/src/nsExpatDTD.h index b2f018a9e6e..be30df0805c 100644 --- a/htmlparser/src/nsExpatDTD.h +++ b/htmlparser/src/nsExpatDTD.h @@ -213,6 +213,18 @@ class nsExpatDTD : public nsIDTD { */ virtual PRBool IsContainer(PRInt32 aTag) const; + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/htmlparser/src/nsIDTD.h b/htmlparser/src/nsIDTD.h index 6bca3fe8b10..080bd169448 100644 --- a/htmlparser/src/nsIDTD.h +++ b/htmlparser/src/nsIDTD.h @@ -200,6 +200,18 @@ class nsIDTD : public nsISupports { */ virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser)=0; + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void) = 0; + /* XXX Temporary measure, pending further work by RickG */ /** @@ -207,6 +219,7 @@ class nsIDTD : public nsISupports { * become useful. */ NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const =0; + }; diff --git a/htmlparser/src/nsParser.cpp b/htmlparser/src/nsParser.cpp index de922574d69..e272ee44d33 100644 --- a/htmlparser/src/nsParser.cpp +++ b/htmlparser/src/nsParser.cpp @@ -191,7 +191,6 @@ nsParser::nsParser(nsITokenObserver* anObserver) : mCommand(""), mUnusedInput("" mTokenObserver=anObserver; mStreamStatus=0; mDTDVerification=PR_FALSE; - mParserTerminated=PR_FALSE; mCharsetSource=kCharsetUninitialized; mInternalState=NS_OK; } @@ -585,8 +584,11 @@ void nsParser::SetUnusedInput(nsString& aBuffer) { * @return should return NS_OK once implemented */ nsresult nsParser::Terminate(void){ - mParserTerminated=PR_TRUE; - return NS_OK; + nsresult result=NS_OK; + if(mParserContext && mParserContext->mDTD) + result=mParserContext->mDTD->Terminate(); + mInternalState=result; + return result; } /** @@ -612,7 +614,12 @@ PRBool nsParser::EnableParser(PRBool aState){ // If we're reenabling the parser mParserContext->mParserEnabled=aState; - nsresult result=(aState) ? ResumeParse() : NS_OK; + nsresult result=NS_OK; + if(aState) { + result=ResumeParse(); + if(result!=NS_OK) + result=mInternalState; + } // Release reference if we added one at the top of this routine NS_IF_RELEASE(me); @@ -870,17 +877,20 @@ nsresult nsParser::ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITag nsresult nsParser::ResumeParse(nsIDTD* aDefaultDTD, PRBool aIsFinalChunk) { nsresult result=NS_OK; - if(mParserContext->mParserEnabled && !mParserTerminated) { + if(mParserContext->mParserEnabled && mInternalState!=NS_ERROR_HTMLPARSER_STOPPARSING) { result=WillBuildModel(mParserContext->mScanner->GetFilename(),aDefaultDTD); if(mParserContext->mDTD) { mParserContext->mDTD->WillResumeParse(); if(NS_OK==result) { result=Tokenize(aIsFinalChunk); result=BuildModel(); + + if(result==NS_ERROR_HTMLPARSER_STOPPARSING) mInternalState=result; - if((!mParserContext->mMultipart) || (mParserTerminated) || + if((!mParserContext->mMultipart) || (mInternalState==NS_ERROR_HTMLPARSER_STOPPARSING) || ((eOnStop==mParserContext->mStreamListenerState) && (NS_OK==result))){ DidBuildModel(mStreamStatus); + return mInternalState; } else { mParserContext->mDTD->WillInterruptParse(); @@ -928,11 +938,8 @@ nsresult nsParser::BuildModel() { } nsIDTD* theRootDTD=theRootContext->mDTD; - if(theRootDTD) { + if(theRootDTD) result=theRootDTD->BuildModel(this,theTokenizer,mTokenObserver,mSink); - if(NS_ERROR_HTMLPARSER_STOPPARSING==result) - Terminate(); - } } else{ mInternalState=result=NS_ERROR_HTMLPARSER_BADTOKENIZER; @@ -1254,7 +1261,7 @@ nsresult nsParser::Tokenize(PRBool aIsFinalChunk){ break; } else if(NS_ERROR_HTMLPARSER_STOPPARSING==result) - Terminate(); + return Terminate(); } } DidTokenize(aIsFinalChunk); diff --git a/htmlparser/src/nsParser.h b/htmlparser/src/nsParser.h index ddbddf64d06..98ca88e9a02 100644 --- a/htmlparser/src/nsParser.h +++ b/htmlparser/src/nsParser.h @@ -370,7 +370,6 @@ protected: nsIContentSink* mSink; nsIParserFilter* mParserFilter; PRBool mDTDVerification; - PRBool mParserTerminated; nsString mCommand; PRInt32 mStreamStatus; nsITokenObserver* mTokenObserver; diff --git a/htmlparser/src/nsValidDTD.cpp b/htmlparser/src/nsValidDTD.cpp index 6f108046421..187aed7f3d7 100644 --- a/htmlparser/src/nsValidDTD.cpp +++ b/htmlparser/src/nsValidDTD.cpp @@ -366,3 +366,17 @@ nsITokenRecycler* CValidDTD::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult CValidDTD::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} \ No newline at end of file diff --git a/htmlparser/src/nsValidDTD.h b/htmlparser/src/nsValidDTD.h index 073cd1167bb..92ef3fef470 100644 --- a/htmlparser/src/nsValidDTD.h +++ b/htmlparser/src/nsValidDTD.h @@ -231,6 +231,18 @@ class CValidDTD : public nsIDTD { */ virtual nsITokenRecycler* GetTokenRecycler(void); + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/htmlparser/src/nsViewSourceHTML.cpp b/htmlparser/src/nsViewSourceHTML.cpp index dc22e0b5fcd..7cb0750bf3a 100644 --- a/htmlparser/src/nsViewSourceHTML.cpp +++ b/htmlparser/src/nsViewSourceHTML.cpp @@ -467,6 +467,21 @@ nsITokenRecycler* CViewSourceHTML::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult CViewSourceHTML::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} + /** * Retrieve the preferred tokenizer for use by this DTD. * @update gess12/28/98 diff --git a/htmlparser/src/nsViewSourceHTML.h b/htmlparser/src/nsViewSourceHTML.h index 3f492cd941a..b33ae6540d1 100644 --- a/htmlparser/src/nsViewSourceHTML.h +++ b/htmlparser/src/nsViewSourceHTML.h @@ -214,6 +214,18 @@ class CViewSourceHTML: public nsIDTD { */ virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const; + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/htmlparser/src/nsWellFormedDTD.cpp b/htmlparser/src/nsWellFormedDTD.cpp index c8aaedad1af..91d73611a0d 100644 --- a/htmlparser/src/nsWellFormedDTD.cpp +++ b/htmlparser/src/nsWellFormedDTD.cpp @@ -320,6 +320,21 @@ nsITokenRecycler* CWellFormedDTD::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult CWellFormedDTD::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} + /** * Retrieve the preferred tokenizer for use by this DTD. * @update gess12/28/98 diff --git a/htmlparser/src/nsWellFormedDTD.h b/htmlparser/src/nsWellFormedDTD.h index 50023bf491e..613556e19af 100644 --- a/htmlparser/src/nsWellFormedDTD.h +++ b/htmlparser/src/nsWellFormedDTD.h @@ -216,6 +216,18 @@ class CWellFormedDTD : public nsIDTD { */ virtual nsITokenRecycler* GetTokenRecycler(void); + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/htmlparser/src/nsXIFDTD.cpp b/htmlparser/src/nsXIFDTD.cpp index 15b2e62cb1e..6effa49186e 100644 --- a/htmlparser/src/nsXIFDTD.cpp +++ b/htmlparser/src/nsXIFDTD.cpp @@ -1556,6 +1556,21 @@ nsITokenRecycler* nsXIFDTD::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult nsXIFDTD::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} + /** * Retrieve the attributes for this node, and add then into * the node. diff --git a/htmlparser/src/nsXIFDTD.h b/htmlparser/src/nsXIFDTD.h index 612074d8a73..cfcb7fc83e6 100644 --- a/htmlparser/src/nsXIFDTD.h +++ b/htmlparser/src/nsXIFDTD.h @@ -254,6 +254,18 @@ class nsXIFDTD : public nsIDTD { */ virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index ccdf7fd4b7a..a59b6f2f4e9 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -347,6 +347,7 @@ CNavDTD::CNavDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0), mShared mComputedCRC32=0; mExpectedCRC32=0; mSaveBadTokens = PR_FALSE; + mDTDState=NS_OK; // DebugDumpContainmentRules2(*this,"c:/temp/DTDRules.new","New CNavDTD Containment Rules"); #ifdef RICKG_DEBUG nsHTMLElement::DebugDumpContainment("c:/temp/rules.new","ElementTable Rules"); @@ -542,11 +543,17 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke NS_ADDREF(mSink); gRecycler=(CTokenRecycler*)mTokenizer->GetTokenRecycler(); while(NS_SUCCEEDED(result)){ - CToken* theToken=mTokenizer->PopToken(); - if(theToken) { - result=HandleToken(theToken,aParser); + if(mDTDState!=NS_ERROR_HTMLPARSER_STOPPARSING) { + CToken* theToken=mTokenizer->PopToken(); + if(theToken) { + result=HandleToken(theToken,aParser); + } + else break; + } + else { + result=mDTDState; + break; } - else break; }//while mTokenizer=oldTokenizer; NS_IF_RELEASE(mSink); @@ -636,6 +643,7 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse } return result; } + /** * This big dispatch method is used to route token handler calls to the right place. * What's wrong with it? This table, and the dispatch methods themselves need to be diff --git a/parser/htmlparser/src/CNavDTD.h b/parser/htmlparser/src/CNavDTD.h index 3e4d1cf352a..3223b5f595e 100644 --- a/parser/htmlparser/src/CNavDTD.h +++ b/parser/htmlparser/src/CNavDTD.h @@ -369,6 +369,18 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { */ virtual PRInt32 GetTopmostIndexOf(eHTMLTags aTagSet[],PRInt32 aCount) const; + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void) { return mDTDState=NS_ERROR_HTMLPARSER_STOPPARSING; } + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. @@ -520,6 +532,7 @@ protected: PRBool mHasOpenBody; PRBool mHadFrameset; PRBool mHadBody; + PRBool mDTDState; nsString mFilename; nsIDTDDebug* mDTDDebug; PRInt32 mLineNumber; diff --git a/parser/htmlparser/src/CRtfDTD.cpp b/parser/htmlparser/src/CRtfDTD.cpp index 82b4f2dd5a9..c3b71d1aa6b 100644 --- a/parser/htmlparser/src/CRtfDTD.cpp +++ b/parser/htmlparser/src/CRtfDTD.cpp @@ -478,6 +478,21 @@ nsITokenRecycler* CRtfDTD::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult CRtfDTD::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} + /*************************************************************** Heres's the RTFControlWord subclass... ***************************************************************/ diff --git a/parser/htmlparser/src/CRtfDTD.h b/parser/htmlparser/src/CRtfDTD.h index eb0696245ab..9c5069cfec7 100644 --- a/parser/htmlparser/src/CRtfDTD.h +++ b/parser/htmlparser/src/CRtfDTD.h @@ -338,6 +338,18 @@ class CRtfDTD : public nsIDTD { */ virtual nsITokenRecycler* GetTokenRecycler(void); + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/parser/htmlparser/src/nsExpatDTD.cpp b/parser/htmlparser/src/nsExpatDTD.cpp index 7bfbe70f49a..7b131eaec43 100644 --- a/parser/htmlparser/src/nsExpatDTD.cpp +++ b/parser/htmlparser/src/nsExpatDTD.cpp @@ -279,6 +279,20 @@ nsITokenRecycler* nsExpatDTD::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult nsExpatDTD::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} /** * Sets up the callbacks for the expat parser diff --git a/parser/htmlparser/src/nsExpatDTD.h b/parser/htmlparser/src/nsExpatDTD.h index b2f018a9e6e..be30df0805c 100644 --- a/parser/htmlparser/src/nsExpatDTD.h +++ b/parser/htmlparser/src/nsExpatDTD.h @@ -213,6 +213,18 @@ class nsExpatDTD : public nsIDTD { */ virtual PRBool IsContainer(PRInt32 aTag) const; + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/parser/htmlparser/src/nsIDTD.h b/parser/htmlparser/src/nsIDTD.h index 6bca3fe8b10..080bd169448 100644 --- a/parser/htmlparser/src/nsIDTD.h +++ b/parser/htmlparser/src/nsIDTD.h @@ -200,6 +200,18 @@ class nsIDTD : public nsISupports { */ virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser)=0; + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void) = 0; + /* XXX Temporary measure, pending further work by RickG */ /** @@ -207,6 +219,7 @@ class nsIDTD : public nsISupports { * become useful. */ NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const =0; + }; diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp index de922574d69..e272ee44d33 100644 --- a/parser/htmlparser/src/nsParser.cpp +++ b/parser/htmlparser/src/nsParser.cpp @@ -191,7 +191,6 @@ nsParser::nsParser(nsITokenObserver* anObserver) : mCommand(""), mUnusedInput("" mTokenObserver=anObserver; mStreamStatus=0; mDTDVerification=PR_FALSE; - mParserTerminated=PR_FALSE; mCharsetSource=kCharsetUninitialized; mInternalState=NS_OK; } @@ -585,8 +584,11 @@ void nsParser::SetUnusedInput(nsString& aBuffer) { * @return should return NS_OK once implemented */ nsresult nsParser::Terminate(void){ - mParserTerminated=PR_TRUE; - return NS_OK; + nsresult result=NS_OK; + if(mParserContext && mParserContext->mDTD) + result=mParserContext->mDTD->Terminate(); + mInternalState=result; + return result; } /** @@ -612,7 +614,12 @@ PRBool nsParser::EnableParser(PRBool aState){ // If we're reenabling the parser mParserContext->mParserEnabled=aState; - nsresult result=(aState) ? ResumeParse() : NS_OK; + nsresult result=NS_OK; + if(aState) { + result=ResumeParse(); + if(result!=NS_OK) + result=mInternalState; + } // Release reference if we added one at the top of this routine NS_IF_RELEASE(me); @@ -870,17 +877,20 @@ nsresult nsParser::ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITag nsresult nsParser::ResumeParse(nsIDTD* aDefaultDTD, PRBool aIsFinalChunk) { nsresult result=NS_OK; - if(mParserContext->mParserEnabled && !mParserTerminated) { + if(mParserContext->mParserEnabled && mInternalState!=NS_ERROR_HTMLPARSER_STOPPARSING) { result=WillBuildModel(mParserContext->mScanner->GetFilename(),aDefaultDTD); if(mParserContext->mDTD) { mParserContext->mDTD->WillResumeParse(); if(NS_OK==result) { result=Tokenize(aIsFinalChunk); result=BuildModel(); + + if(result==NS_ERROR_HTMLPARSER_STOPPARSING) mInternalState=result; - if((!mParserContext->mMultipart) || (mParserTerminated) || + if((!mParserContext->mMultipart) || (mInternalState==NS_ERROR_HTMLPARSER_STOPPARSING) || ((eOnStop==mParserContext->mStreamListenerState) && (NS_OK==result))){ DidBuildModel(mStreamStatus); + return mInternalState; } else { mParserContext->mDTD->WillInterruptParse(); @@ -928,11 +938,8 @@ nsresult nsParser::BuildModel() { } nsIDTD* theRootDTD=theRootContext->mDTD; - if(theRootDTD) { + if(theRootDTD) result=theRootDTD->BuildModel(this,theTokenizer,mTokenObserver,mSink); - if(NS_ERROR_HTMLPARSER_STOPPARSING==result) - Terminate(); - } } else{ mInternalState=result=NS_ERROR_HTMLPARSER_BADTOKENIZER; @@ -1254,7 +1261,7 @@ nsresult nsParser::Tokenize(PRBool aIsFinalChunk){ break; } else if(NS_ERROR_HTMLPARSER_STOPPARSING==result) - Terminate(); + return Terminate(); } } DidTokenize(aIsFinalChunk); diff --git a/parser/htmlparser/src/nsParser.h b/parser/htmlparser/src/nsParser.h index ddbddf64d06..98ca88e9a02 100644 --- a/parser/htmlparser/src/nsParser.h +++ b/parser/htmlparser/src/nsParser.h @@ -370,7 +370,6 @@ protected: nsIContentSink* mSink; nsIParserFilter* mParserFilter; PRBool mDTDVerification; - PRBool mParserTerminated; nsString mCommand; PRInt32 mStreamStatus; nsITokenObserver* mTokenObserver; diff --git a/parser/htmlparser/src/nsValidDTD.cpp b/parser/htmlparser/src/nsValidDTD.cpp index 6f108046421..187aed7f3d7 100644 --- a/parser/htmlparser/src/nsValidDTD.cpp +++ b/parser/htmlparser/src/nsValidDTD.cpp @@ -366,3 +366,17 @@ nsITokenRecycler* CValidDTD::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult CValidDTD::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} \ No newline at end of file diff --git a/parser/htmlparser/src/nsValidDTD.h b/parser/htmlparser/src/nsValidDTD.h index 073cd1167bb..92ef3fef470 100644 --- a/parser/htmlparser/src/nsValidDTD.h +++ b/parser/htmlparser/src/nsValidDTD.h @@ -231,6 +231,18 @@ class CValidDTD : public nsIDTD { */ virtual nsITokenRecycler* GetTokenRecycler(void); + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/parser/htmlparser/src/nsViewSourceHTML.cpp b/parser/htmlparser/src/nsViewSourceHTML.cpp index dc22e0b5fcd..7cb0750bf3a 100644 --- a/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -467,6 +467,21 @@ nsITokenRecycler* CViewSourceHTML::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult CViewSourceHTML::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} + /** * Retrieve the preferred tokenizer for use by this DTD. * @update gess12/28/98 diff --git a/parser/htmlparser/src/nsViewSourceHTML.h b/parser/htmlparser/src/nsViewSourceHTML.h index 3f492cd941a..b33ae6540d1 100644 --- a/parser/htmlparser/src/nsViewSourceHTML.h +++ b/parser/htmlparser/src/nsViewSourceHTML.h @@ -214,6 +214,18 @@ class CViewSourceHTML: public nsIDTD { */ virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const; + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/parser/htmlparser/src/nsWellFormedDTD.cpp b/parser/htmlparser/src/nsWellFormedDTD.cpp index c8aaedad1af..91d73611a0d 100644 --- a/parser/htmlparser/src/nsWellFormedDTD.cpp +++ b/parser/htmlparser/src/nsWellFormedDTD.cpp @@ -320,6 +320,21 @@ nsITokenRecycler* CWellFormedDTD::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult CWellFormedDTD::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} + /** * Retrieve the preferred tokenizer for use by this DTD. * @update gess12/28/98 diff --git a/parser/htmlparser/src/nsWellFormedDTD.h b/parser/htmlparser/src/nsWellFormedDTD.h index 50023bf491e..613556e19af 100644 --- a/parser/htmlparser/src/nsWellFormedDTD.h +++ b/parser/htmlparser/src/nsWellFormedDTD.h @@ -216,6 +216,18 @@ class CWellFormedDTD : public nsIDTD { */ virtual nsITokenRecycler* GetTokenRecycler(void); + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful. diff --git a/parser/htmlparser/src/nsXIFDTD.cpp b/parser/htmlparser/src/nsXIFDTD.cpp index 15b2e62cb1e..6effa49186e 100644 --- a/parser/htmlparser/src/nsXIFDTD.cpp +++ b/parser/htmlparser/src/nsXIFDTD.cpp @@ -1556,6 +1556,21 @@ nsITokenRecycler* nsXIFDTD::GetTokenRecycler(void){ return 0; } +/** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ +nsresult nsXIFDTD::Terminate(void) +{ + return NS_ERROR_HTMLPARSER_STOPPARSING; +} + /** * Retrieve the attributes for this node, and add then into * the node. diff --git a/parser/htmlparser/src/nsXIFDTD.h b/parser/htmlparser/src/nsXIFDTD.h index 612074d8a73..cfcb7fc83e6 100644 --- a/parser/htmlparser/src/nsXIFDTD.h +++ b/parser/htmlparser/src/nsXIFDTD.h @@ -254,6 +254,18 @@ class nsXIFDTD : public nsIDTD { */ virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); + /** + * Use this id you want to stop the building content model + * --------------[ Sets DTD to STOP mode ]---------------- + * It's recommended to use this method in accordance with + * the parser's terminate() method. + * + * @update harishd 07/22/99 + * @param + * @return + */ + virtual nsresult Terminate(void); + /** * Give rest of world access to our tag enums, so that CanContain(), etc, * become useful.