No need to tokenize the input stream if the DTD ( NavDTD ) cannot create a content sink. b=138071, r=heikki, sr=jst

This commit is contained in:
harishd%netscape.com 2002-05-07 23:18:15 +00:00
parent ddb0295dca
commit e0ad4815d7
4 changed files with 148 additions and 130 deletions

View File

@ -389,69 +389,65 @@ nsresult CNavDTD::WillBuildModel(const CParserContext& aParserContext,
mFilename=aParserContext.mScanner->GetFilename(); mFilename=aParserContext.mScanner->GetFilename();
mFlags = NS_DTD_FLAG_ENABLE_RESIDUAL_STYLE; // residual style is always on. This will also reset the flags mFlags = NS_DTD_FLAG_ENABLE_RESIDUAL_STYLE; // residual style is always on. This will also reset the flags
mLineNumber=1; mLineNumber = 1;
mDTDMode=aParserContext.mDTDMode; mDTDMode = aParserContext.mDTDMode;
mParserCommand=aParserContext.mParserCommand; mParserCommand = aParserContext.mParserCommand;
mMimeType=aParserContext.mMimeType; mMimeType = aParserContext.mMimeType;
mDocType = aParserContext.mDocType;
mSkipTarget = eHTMLTag_unknown;
mTokenizer = aTokenizer; mTokenizer = aTokenizer;
mBodyContext->SetNodeAllocator(&mNodeAllocator); mBodyContext->SetNodeAllocator(&mNodeAllocator);
if((!aParserContext.mPrevContext) && (aSink)) { if(!aParserContext.mPrevContext && aSink) {
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this));
#ifdef DEBUG #ifdef DEBUG
mBodyContext->ResetCounters(); mBodyContext->ResetCounters();
#endif #endif
mDocType=aParserContext.mDocType; STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this));
result = aSink->WillBuildModel();
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this));
START_TIMER();
if(aSink && (!mSink)) { if (NS_SUCCEEDED(result) && !mSink) {
result=aSink->QueryInterface(kIHTMLContentSinkIID, (void **)&mSink); result = CallQueryInterface(aSink, &mSink);
} if (NS_FAILED(result)) {
mFlags |= NS_DTD_FLAG_STOP_PARSING;
if(result==NS_OK) { return result;
//let's see if the environment is set up for us to write output to
//a logging sink. If so, then we'll create one, and make it the
//proxy for the real sink we're given from the parser.
#ifdef NS_DEBUG
nsLoggingSink *theLogSink=GetLoggingSink();
if(theLogSink) {
theLogSink->SetProxySink(mSink);
mSink=theLogSink;
} }
}
//let's see if the environment is set up for us to write output to
//a logging sink. If so, then we'll create one, and make it the
//proxy for the real sink we're given from the parser.
#ifdef NS_DEBUG
nsLoggingSink *theLogSink=GetLoggingSink();
if(theLogSink) {
theLogSink->SetProxySink(mSink);
mSink=theLogSink;
}
#endif #endif
result = aSink->WillBuildModel(); if(mSink) {
PRBool enabled;
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this)); mSink->GetPref(eHTMLTag_frameset,enabled);
START_TIMER(); if(enabled) {
mFlags |= NS_DTD_FLAG_FRAMES_ENABLED;
if(mSink) {
PRBool enabled;
mSink->GetPref(eHTMLTag_frameset,enabled);
if(enabled) {
mFlags |= NS_DTD_FLAG_FRAMES_ENABLED;
}
mSink->GetPref(eHTMLTag_script,enabled);
if(enabled) {
mFlags |= NS_DTD_FLAG_SCRIPT_ENABLED;
}
} }
mSkipTarget=eHTMLTag_unknown; mSink->GetPref(eHTMLTag_script,enabled);
if(enabled) {
#ifdef ENABLE_CRC mFlags |= NS_DTD_FLAG_SCRIPT_ENABLED;
mComputedCRC32=0; }
mExpectedCRC32=0;
#endif
} }
#ifdef ENABLE_CRC
mComputedCRC32=0;
mExpectedCRC32=0;
#endif
} }
return result; return result;
@ -537,6 +533,9 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke
}//while }//while
mTokenizer = oldTokenizer; mTokenizer = oldTokenizer;
} }
else {
result = mFlags & NS_DTD_FLAG_STOP_PARSING ? NS_ERROR_HTMLPARSER_STOPPARSING : result;
}
} }
return result; return result;
@ -557,26 +556,30 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse
mSkipTarget=eHTMLTag_unknown; //clear this in case we were searching earlier. mSkipTarget=eHTMLTag_unknown; //clear this in case we were searching earlier.
CStartToken *theToken=NS_STATIC_CAST(CStartToken*,mTokenAllocator->CreateTokenOfType(eToken_start,eHTMLTag_body,NS_LITERAL_STRING("body"))); if (mTokenAllocator) {
mTokenizer->PushTokenFront(theToken); //this token should get pushed on the context stack, don't recycle it CStartToken *theToken = NS_STATIC_CAST(CStartToken*, mTokenAllocator->CreateTokenOfType(eToken_start,eHTMLTag_body,NS_LITERAL_STRING("body")));
result=BuildModel(aParser,mTokenizer,0,aSink); mTokenizer->PushTokenFront(theToken); //this token should get pushed on the context stack, don't recycle it
result = BuildModel(aParser,mTokenizer, 0, aSink);
}
} }
if(aParser && (NS_OK==result)){ if(aParser && (NS_OK==result)){
if(aNotifySink){ if(aNotifySink){
if((NS_OK==anErrorCode) && (mBodyContext->GetCount()>0)) { if((NS_OK==anErrorCode) && (mBodyContext->GetCount()>0)) {
if(mSkipTarget) { if (mTokenAllocator) {
CHTMLToken* theEndToken=nsnull; if(mSkipTarget) {
theEndToken=NS_STATIC_CAST(CHTMLToken*,mTokenAllocator->CreateTokenOfType(eToken_end,mSkipTarget)); CHTMLToken* theEndToken=nsnull;
if(theEndToken) { theEndToken=NS_STATIC_CAST(CHTMLToken*,mTokenAllocator->CreateTokenOfType(eToken_end,mSkipTarget));
result=HandleToken(theEndToken,mParser); if(theEndToken) {
result=HandleToken(theEndToken,mParser);
}
} }
} if(mFlags & NS_DTD_FLAG_MISPLACED_CONTENT) {
if(mFlags & NS_DTD_FLAG_MISPLACED_CONTENT) { // Create an end table token to flush tokens off the misplaced list...
// Create an end table token to flush tokens off the misplaced list... CHTMLToken* theTableToken=NS_STATIC_CAST(CHTMLToken*,mTokenAllocator->CreateTokenOfType(eToken_end,eHTMLTag_table));
CHTMLToken* theTableToken=NS_STATIC_CAST(CHTMLToken*,mTokenAllocator->CreateTokenOfType(eToken_end,eHTMLTag_table)); if(theTableToken) {
if(theTableToken) { result=HandleToken(theTableToken,mParser);
result=HandleToken(theTableToken,mParser); }
} }
} }
if(NS_SUCCEEDED(result)) { if(NS_SUCCEEDED(result)) {

View File

@ -73,6 +73,7 @@
#define NS_PARSER_FLAG_PENDING_CONTINUE_EVENT 0x00000008 #define NS_PARSER_FLAG_PENDING_CONTINUE_EVENT 0x00000008
#define NS_PARSER_FLAG_CAN_INTERRUPT 0x00000010 #define NS_PARSER_FLAG_CAN_INTERRUPT 0x00000010
#define NS_PARSER_FLAG_FLUSH_TOKENS 0x00000020 #define NS_PARSER_FLAG_FLUSH_TOKENS 0x00000020
#define NS_PARSER_FLAG_CAN_TOKENIZE 0x00000040
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
@ -310,7 +311,7 @@ nsParser::nsParser(nsITokenObserver* anObserver) {
mCharsetSource=kCharsetUninitialized; mCharsetSource=kCharsetUninitialized;
mInternalState=NS_OK;; mInternalState=NS_OK;;
mCommand=eViewNormal; mCommand=eViewNormal;
mFlags = NS_PARSER_FLAG_OBSERVERS_ENABLED | NS_PARSER_FLAG_PARSER_ENABLED; mFlags = NS_PARSER_FLAG_OBSERVERS_ENABLED | NS_PARSER_FLAG_PARSER_ENABLED | NS_PARSER_FLAG_CAN_TOKENIZE;
MOZ_TIMER_DEBUGLOG(("Reset: Parse Time: nsParser::nsParser(), this=%p\n", this)); MOZ_TIMER_DEBUGLOG(("Reset: Parse Time: nsParser::nsParser(), this=%p\n", this));
MOZ_TIMER_RESET(mParseTime); MOZ_TIMER_RESET(mParseTime);
@ -1224,7 +1225,7 @@ nsresult nsParser::WillBuildModel(nsString& aFilename){
if(PR_TRUE==FindSuitableDTD(*mParserContext,theBuffer)) { if(PR_TRUE==FindSuitableDTD(*mParserContext,theBuffer)) {
nsITokenizer* tokenizer; nsITokenizer* tokenizer;
mParserContext->GetTokenizer(mParserContext->mDTD->GetType(), tokenizer); mParserContext->GetTokenizer(mParserContext->mDTD->GetType(), tokenizer);
mParserContext->mDTD->WillBuildModel(*mParserContext, tokenizer, mSink); result = mParserContext->mDTD->WillBuildModel(*mParserContext, tokenizer, mSink);
}//if }//if
}//if }//if
} }
@ -1705,6 +1706,11 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
MOZ_TIMER_START(mParseTime); MOZ_TIMER_START(mParseTime);
result=WillBuildModel(mParserContext->mScanner->GetFilename()); result=WillBuildModel(mParserContext->mScanner->GetFilename());
if (NS_FAILED(result)) {
mFlags &= ~NS_PARSER_FLAG_CAN_TOKENIZE;
return result;
}
if(mParserContext->mDTD) { if(mParserContext->mDTD) {
mParserContext->mDTD->WillResumeParse(mSink); mParserContext->mDTD->WillResumeParse(mSink);
@ -1727,7 +1733,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
//Only allow parsing to be interuptted in the subsequent call //Only allow parsing to be interuptted in the subsequent call
//to build model. //to build model.
SetCanInterrupt(aCanInterrupt); SetCanInterrupt(aCanInterrupt);
nsresult theTokenizerResult = Tokenize(aIsFinalChunk); // kEOF==2152596456 nsresult theTokenizerResult = mFlags & NS_PARSER_FLAG_CAN_TOKENIZE ? Tokenize(aIsFinalChunk) : NS_OK; // kEOF==2152596456
result=BuildModel(); result=BuildModel();
if(result==NS_ERROR_HTMLPARSER_INTERRUPTED) { if(result==NS_ERROR_HTMLPARSER_INTERRUPTED) {

View File

@ -389,69 +389,65 @@ nsresult CNavDTD::WillBuildModel(const CParserContext& aParserContext,
mFilename=aParserContext.mScanner->GetFilename(); mFilename=aParserContext.mScanner->GetFilename();
mFlags = NS_DTD_FLAG_ENABLE_RESIDUAL_STYLE; // residual style is always on. This will also reset the flags mFlags = NS_DTD_FLAG_ENABLE_RESIDUAL_STYLE; // residual style is always on. This will also reset the flags
mLineNumber=1; mLineNumber = 1;
mDTDMode=aParserContext.mDTDMode; mDTDMode = aParserContext.mDTDMode;
mParserCommand=aParserContext.mParserCommand; mParserCommand = aParserContext.mParserCommand;
mMimeType=aParserContext.mMimeType; mMimeType = aParserContext.mMimeType;
mDocType = aParserContext.mDocType;
mSkipTarget = eHTMLTag_unknown;
mTokenizer = aTokenizer; mTokenizer = aTokenizer;
mBodyContext->SetNodeAllocator(&mNodeAllocator); mBodyContext->SetNodeAllocator(&mNodeAllocator);
if((!aParserContext.mPrevContext) && (aSink)) { if(!aParserContext.mPrevContext && aSink) {
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this));
#ifdef DEBUG #ifdef DEBUG
mBodyContext->ResetCounters(); mBodyContext->ResetCounters();
#endif #endif
mDocType=aParserContext.mDocType; STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this));
result = aSink->WillBuildModel();
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this));
START_TIMER();
if(aSink && (!mSink)) { if (NS_SUCCEEDED(result) && !mSink) {
result=aSink->QueryInterface(kIHTMLContentSinkIID, (void **)&mSink); result = CallQueryInterface(aSink, &mSink);
} if (NS_FAILED(result)) {
mFlags |= NS_DTD_FLAG_STOP_PARSING;
if(result==NS_OK) { return result;
//let's see if the environment is set up for us to write output to
//a logging sink. If so, then we'll create one, and make it the
//proxy for the real sink we're given from the parser.
#ifdef NS_DEBUG
nsLoggingSink *theLogSink=GetLoggingSink();
if(theLogSink) {
theLogSink->SetProxySink(mSink);
mSink=theLogSink;
} }
}
//let's see if the environment is set up for us to write output to
//a logging sink. If so, then we'll create one, and make it the
//proxy for the real sink we're given from the parser.
#ifdef NS_DEBUG
nsLoggingSink *theLogSink=GetLoggingSink();
if(theLogSink) {
theLogSink->SetProxySink(mSink);
mSink=theLogSink;
}
#endif #endif
result = aSink->WillBuildModel(); if(mSink) {
PRBool enabled;
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this)); mSink->GetPref(eHTMLTag_frameset,enabled);
START_TIMER(); if(enabled) {
mFlags |= NS_DTD_FLAG_FRAMES_ENABLED;
if(mSink) {
PRBool enabled;
mSink->GetPref(eHTMLTag_frameset,enabled);
if(enabled) {
mFlags |= NS_DTD_FLAG_FRAMES_ENABLED;
}
mSink->GetPref(eHTMLTag_script,enabled);
if(enabled) {
mFlags |= NS_DTD_FLAG_SCRIPT_ENABLED;
}
} }
mSkipTarget=eHTMLTag_unknown; mSink->GetPref(eHTMLTag_script,enabled);
if(enabled) {
#ifdef ENABLE_CRC mFlags |= NS_DTD_FLAG_SCRIPT_ENABLED;
mComputedCRC32=0; }
mExpectedCRC32=0;
#endif
} }
#ifdef ENABLE_CRC
mComputedCRC32=0;
mExpectedCRC32=0;
#endif
} }
return result; return result;
@ -537,6 +533,9 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke
}//while }//while
mTokenizer = oldTokenizer; mTokenizer = oldTokenizer;
} }
else {
result = mFlags & NS_DTD_FLAG_STOP_PARSING ? NS_ERROR_HTMLPARSER_STOPPARSING : result;
}
} }
return result; return result;
@ -557,26 +556,30 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse
mSkipTarget=eHTMLTag_unknown; //clear this in case we were searching earlier. mSkipTarget=eHTMLTag_unknown; //clear this in case we were searching earlier.
CStartToken *theToken=NS_STATIC_CAST(CStartToken*,mTokenAllocator->CreateTokenOfType(eToken_start,eHTMLTag_body,NS_LITERAL_STRING("body"))); if (mTokenAllocator) {
mTokenizer->PushTokenFront(theToken); //this token should get pushed on the context stack, don't recycle it CStartToken *theToken = NS_STATIC_CAST(CStartToken*, mTokenAllocator->CreateTokenOfType(eToken_start,eHTMLTag_body,NS_LITERAL_STRING("body")));
result=BuildModel(aParser,mTokenizer,0,aSink); mTokenizer->PushTokenFront(theToken); //this token should get pushed on the context stack, don't recycle it
result = BuildModel(aParser,mTokenizer, 0, aSink);
}
} }
if(aParser && (NS_OK==result)){ if(aParser && (NS_OK==result)){
if(aNotifySink){ if(aNotifySink){
if((NS_OK==anErrorCode) && (mBodyContext->GetCount()>0)) { if((NS_OK==anErrorCode) && (mBodyContext->GetCount()>0)) {
if(mSkipTarget) { if (mTokenAllocator) {
CHTMLToken* theEndToken=nsnull; if(mSkipTarget) {
theEndToken=NS_STATIC_CAST(CHTMLToken*,mTokenAllocator->CreateTokenOfType(eToken_end,mSkipTarget)); CHTMLToken* theEndToken=nsnull;
if(theEndToken) { theEndToken=NS_STATIC_CAST(CHTMLToken*,mTokenAllocator->CreateTokenOfType(eToken_end,mSkipTarget));
result=HandleToken(theEndToken,mParser); if(theEndToken) {
result=HandleToken(theEndToken,mParser);
}
} }
} if(mFlags & NS_DTD_FLAG_MISPLACED_CONTENT) {
if(mFlags & NS_DTD_FLAG_MISPLACED_CONTENT) { // Create an end table token to flush tokens off the misplaced list...
// Create an end table token to flush tokens off the misplaced list... CHTMLToken* theTableToken=NS_STATIC_CAST(CHTMLToken*,mTokenAllocator->CreateTokenOfType(eToken_end,eHTMLTag_table));
CHTMLToken* theTableToken=NS_STATIC_CAST(CHTMLToken*,mTokenAllocator->CreateTokenOfType(eToken_end,eHTMLTag_table)); if(theTableToken) {
if(theTableToken) { result=HandleToken(theTableToken,mParser);
result=HandleToken(theTableToken,mParser); }
} }
} }
if(NS_SUCCEEDED(result)) { if(NS_SUCCEEDED(result)) {

View File

@ -73,6 +73,7 @@
#define NS_PARSER_FLAG_PENDING_CONTINUE_EVENT 0x00000008 #define NS_PARSER_FLAG_PENDING_CONTINUE_EVENT 0x00000008
#define NS_PARSER_FLAG_CAN_INTERRUPT 0x00000010 #define NS_PARSER_FLAG_CAN_INTERRUPT 0x00000010
#define NS_PARSER_FLAG_FLUSH_TOKENS 0x00000020 #define NS_PARSER_FLAG_FLUSH_TOKENS 0x00000020
#define NS_PARSER_FLAG_CAN_TOKENIZE 0x00000040
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
@ -310,7 +311,7 @@ nsParser::nsParser(nsITokenObserver* anObserver) {
mCharsetSource=kCharsetUninitialized; mCharsetSource=kCharsetUninitialized;
mInternalState=NS_OK;; mInternalState=NS_OK;;
mCommand=eViewNormal; mCommand=eViewNormal;
mFlags = NS_PARSER_FLAG_OBSERVERS_ENABLED | NS_PARSER_FLAG_PARSER_ENABLED; mFlags = NS_PARSER_FLAG_OBSERVERS_ENABLED | NS_PARSER_FLAG_PARSER_ENABLED | NS_PARSER_FLAG_CAN_TOKENIZE;
MOZ_TIMER_DEBUGLOG(("Reset: Parse Time: nsParser::nsParser(), this=%p\n", this)); MOZ_TIMER_DEBUGLOG(("Reset: Parse Time: nsParser::nsParser(), this=%p\n", this));
MOZ_TIMER_RESET(mParseTime); MOZ_TIMER_RESET(mParseTime);
@ -1224,7 +1225,7 @@ nsresult nsParser::WillBuildModel(nsString& aFilename){
if(PR_TRUE==FindSuitableDTD(*mParserContext,theBuffer)) { if(PR_TRUE==FindSuitableDTD(*mParserContext,theBuffer)) {
nsITokenizer* tokenizer; nsITokenizer* tokenizer;
mParserContext->GetTokenizer(mParserContext->mDTD->GetType(), tokenizer); mParserContext->GetTokenizer(mParserContext->mDTD->GetType(), tokenizer);
mParserContext->mDTD->WillBuildModel(*mParserContext, tokenizer, mSink); result = mParserContext->mDTD->WillBuildModel(*mParserContext, tokenizer, mSink);
}//if }//if
}//if }//if
} }
@ -1705,6 +1706,11 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
MOZ_TIMER_START(mParseTime); MOZ_TIMER_START(mParseTime);
result=WillBuildModel(mParserContext->mScanner->GetFilename()); result=WillBuildModel(mParserContext->mScanner->GetFilename());
if (NS_FAILED(result)) {
mFlags &= ~NS_PARSER_FLAG_CAN_TOKENIZE;
return result;
}
if(mParserContext->mDTD) { if(mParserContext->mDTD) {
mParserContext->mDTD->WillResumeParse(mSink); mParserContext->mDTD->WillResumeParse(mSink);
@ -1727,7 +1733,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo
//Only allow parsing to be interuptted in the subsequent call //Only allow parsing to be interuptted in the subsequent call
//to build model. //to build model.
SetCanInterrupt(aCanInterrupt); SetCanInterrupt(aCanInterrupt);
nsresult theTokenizerResult = Tokenize(aIsFinalChunk); // kEOF==2152596456 nsresult theTokenizerResult = mFlags & NS_PARSER_FLAG_CAN_TOKENIZE ? Tokenize(aIsFinalChunk) : NS_OK; // kEOF==2152596456
result=BuildModel(); result=BuildModel();
if(result==NS_ERROR_HTMLPARSER_INTERRUPTED) { if(result==NS_ERROR_HTMLPARSER_INTERRUPTED) {