/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/NPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): */ //#define ENABLE_CRC //#define RICKG_DEBUG //#define ALLOW_TR_AS_CHILD_OF_TABLE //by setting this to true, TR is allowable directly in TABLE. #define ENABLE_RESIDUALSTYLE #ifdef RICKG_DEBUG #include #endif #include "nsDebug.h" #include "nsIDTDDebug.h" #include "CNavDTD.h" #include "nsHTMLTokens.h" #include "nsCRT.h" #include "nsParser.h" #include "nsIParser.h" #include "nsIHTMLContentSink.h" #include "nsScanner.h" #include "nsIDTDDebug.h" #include "prenv.h" //this is here for debug reasons... #include "prtypes.h" //this is here for debug reasons... #include "prio.h" #include "plstr.h" #include "nsDTDUtils.h" #include "nsTagHandler.h" #include "nsHTMLTokenizer.h" #include "nsTime.h" #include "nsIElementObserver.h" #include "nsViewSourceHTML.h" #include "nsParserNode.h" #include "nsHTMLEntities.h" #include "nsLinebreakConverter.h" #include "nsIFormProcessor.h" #include "nsVoidArray.h" #include "prmem.h" static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTML_CONTENT_SINK_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kClassIID, NS_INAVHTML_DTD_IID); static NS_DEFINE_IID(kFormProcessorCID, NS_IFORMPROCESSOR_CID); static const char* kNullToken = "Error: Null token given"; static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; static char* kVerificationDir = "c:/temp"; #ifdef ENABLE_CRC static char gShowCRC; #endif #include "nsElementTable.h" #ifdef MOZ_PERF_METRICS # define START_TIMER() \ if(mParser) MOZ_TIMER_START(mParser->mParseTime); \ if(mParser) MOZ_TIMER_START(mParser->mDTDTime); # define STOP_TIMER() \ if(mParser) MOZ_TIMER_STOP(mParser->mParseTime); \ if(mParser) MOZ_TIMER_STOP(mParser->mDTDTime); #else # define STOP_TIMER() # define START_TIMER() #endif /************************************************************************ And now for the main class -- CNavDTD... ************************************************************************/ /** * This method gets called as part of our COM-like interfaces. * Its purpose is to create an interface to parser object * of some type. * * @update gess 4/8/98 * @param nsIID id of object to discover * @param aInstancePtr ptr to newly discovered interface * @return NS_xxx result code */ nsresult CNavDTD::QueryInterface(const nsIID& aIID, void** aInstancePtr) { if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; } if(aIID.Equals(kISupportsIID)) { //do IUnknown... *aInstancePtr = (nsIDTD*)(this); } else if(aIID.Equals(kIDTDIID)) { //do IParser base class... *aInstancePtr = (nsIDTD*)(this); } else if(aIID.Equals(kClassIID)) { //do this class... *aInstancePtr = (CNavDTD*)(this); } else { *aInstancePtr=0; return NS_NOINTERFACE; } NS_ADDREF_THIS(); return NS_OK; } NS_IMPL_ADDREF(CNavDTD) NS_IMPL_RELEASE(CNavDTD) /** * Default constructor * * @update gess 4/9/98 * @param * @return */ CNavDTD::CNavDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0), mSharedNodes(0) { NS_INIT_REFCNT(); mSink = 0; mParser=0; mDTDDebug=0; mLineNumber=1; mHasOpenBody=PR_FALSE; mHasOpenHead=0; mHasOpenForm=PR_FALSE; mHasOpenMap=PR_FALSE; mHasOpenNoXXX=0; mHeadContext=new nsDTDContext(); mBodyContext=new nsDTDContext(); mFormContext=0; mMapContext=0; mTempContext=0; mTokenizer=0; mComputedCRC32=0; mExpectedCRC32=0; mDTDState=NS_OK; mStyleHandlingEnabled=PR_TRUE; mDocType=eHTML3Text; mRequestedHead=PR_FALSE; mIsFormContainer=PR_FALSE; if(!gHTMLElements) { InitializeElementTable(); } mNodeRecycler=0; #ifdef RICKG_DEBUG //DebugDumpContainmentRules2(*this,"c:/temp/DTDRules.new","New CNavDTD Containment Rules"); nsHTMLElement::DebugDumpContainment("c:/temp/contain.new","ElementTable Rules"); nsHTMLElement::DebugDumpMembership("c:/temp/membership.out"); nsHTMLElement::DebugDumpContainType("c:/temp/ctnrules.out"); #endif } void CNavDTD::ReleaseTable(void) { if(gHTMLElements) { delete gHTMLElements; gHTMLElements=0; } } /** * This method recycles the nodes on a nodestack. * NOTE: Unlike recycleNode(), we force the usecount * to 0 of all nodes, then force them to recycle. * @update gess1/8/99 * @param aNodeStack * @return nothing */ void CNavDTD::RecycleNodes(nsEntryStack *aNodeStack) { if(aNodeStack) { PRInt32 theCount=aNodeStack->mCount; PRInt32 theIndex=0; for(theIndex=0;theIndexNodeAt(theIndex); if(theNode) { theNode->mUseCount=0; if(theNode->mToken) { theNode->mToken->mUseCount=0; mTokenRecycler->RecycleToken(theNode->mToken); } CToken* theToken=0; while((theToken=(CToken*)theNode->PopAttributeToken())){ theNode->mToken->mUseCount=0; mTokenRecycler->RecycleToken(theToken); } mSharedNodes.Push(theNode); } //if } //while } //if } /** * * @update gess1/8/99 * @param * @return */ const nsIID& CNavDTD::GetMostDerivedIID(void)const { return kClassIID; } /** * Default destructor * * @update gess 4/9/98 * @param * @return */ CNavDTD::~CNavDTD(){ if(mHeadContext) { delete mHeadContext; mHeadContext=0; } if(mBodyContext) { delete mBodyContext; mBodyContext=0; } NS_IF_RELEASE(mTokenizer); if(mTempContext) { delete mTempContext; mTempContext=0; } // delete mNodeRecycler; NS_IF_RELEASE(mSink); NS_IF_RELEASE(mDTDDebug); } /** * Call this method if you want the DTD to construct a fresh * instance of itself. * @update gess 25May2000 * @param * @return */ nsresult CNavDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){ nsresult result=NS_NewNavHTMLDTD(aInstancePtrResult); if(aInstancePtrResult) { CNavDTD *theOtherDTD=(CNavDTD*)*aInstancePtrResult; if(theOtherDTD) { theOtherDTD->mDTDMode=mDTDMode; theOtherDTD->mParserCommand=mParserCommand; theOtherDTD->mDocType=mDocType; } } return result; } /** * Called by the parser to initiate dtd verification of the * internal context stack. * @update gess 7/23/98 * @param * @return */ PRBool CNavDTD::Verify(nsString& aURLRef,nsIParser* aParser){ PRBool result=PR_TRUE; /* * Disable some DTD debugging code in the parser that * breaks on some compilers because of some broken * streams code in prstrm.cpp. */ #if !defined(MOZ_DISABLE_DTD_DEBUG) if(!mDTDDebug){ nsresult rval = NS_NewDTDDebug(&mDTDDebug); if (NS_OK != rval) { fputs("Cannot create parser debugger.\n", stdout); result=-PR_FALSE; } else mDTDDebug->SetVerificationDirectory(kVerificationDir); } #endif if(mDTDDebug) { // mDTDDebug->Verify(this,aParser,mBodyContext->GetCount(),mBodyContext->mStack,aURLRef); } return result; } /** * This method is called to determine if the given DTD can parse * a document in a given source-type. * NOTE: Parsing always assumes that the end result will involve * storing the result in the main content model. * @update gess 02/24/00 * @param * @return TRUE if this DTD can satisfy the request; FALSE otherwise. */ eAutoDetectResult CNavDTD::CanParse(CParserContext& aParserContext,nsString& aBuffer, PRInt32 aVersion) { eAutoDetectResult result=eUnknownDetect; if(eViewSource==aParserContext.mParserCommand) { if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) { result=ePrimaryDetect; } else if(aParserContext.mMimeType.EqualsWithConversion(kRTFTextContentType)){ result=ePrimaryDetect; } } else { if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kHTMLTextContentType)) { result=(eDTDMode_strict==aParserContext.mDTDMode) ? eValidDetect : ePrimaryDetect; } else if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) { result=ePrimaryDetect; } else { //otherwise, look into the buffer to see if you recognize anything... PRBool theBufHasXML=PR_FALSE; if(BufferContainsHTML(aBuffer,theBufHasXML)){ result = eValidDetect ; if(0==aParserContext.mMimeType.Length()) { aParserContext.SetMimeType(NS_ConvertToString(kHTMLTextContentType)); if(!theBufHasXML) { result=(eDTDMode_strict==aParserContext.mDTDMode) ? eValidDetect : ePrimaryDetect; } else result=eValidDetect; } } } } return result; } /** * The parser uses a code sandwich to wrap the parsing process. Before * the process begins, WillBuildModel() is called. Afterwards the parser * calls DidBuildModel(). * @update rickg 03.20.2000 * @param aParserContext * @param aSink * @return error code (almost always 0) */ nsresult CNavDTD::WillBuildModel( const CParserContext& aParserContext,nsIContentSink* aSink) { nsresult result=NS_OK; mFilename=aParserContext.mScanner->GetFilename(); mHasOpenBody=PR_FALSE; mHadBody=PR_FALSE; mHadFrameset=PR_FALSE; mLineNumber=1; mHasOpenScript=PR_FALSE; mHasOpenNoXXX=0; mDTDMode=aParserContext.mDTDMode; mParserCommand=aParserContext.mParserCommand; mStyleHandlingEnabled=(eDTDMode_quirks==mDTDMode); mRequestedHead=PR_FALSE; mMimeType=aParserContext.mMimeType; if((!aParserContext.mPrevContext) && (aSink)) { STOP_TIMER(); MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this)); mBodyContext->ResetCounters(); mDocType=aParserContext.mDocType; mTokenRecycler=0; mStyleHandlingEnabled=PR_TRUE; if(aSink && (!mSink)) { result=aSink->QueryInterface(kIHTMLContentSinkIID, (void **)&mSink); } if(result==NS_OK) { result = aSink->WillBuildModel(); MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this)); START_TIMER(); mSkipTarget=eHTMLTag_unknown; mComputedCRC32=0; mExpectedCRC32=0; } } return result; } /** * This is called when it's time to read as many tokens from the tokenizer * as you can. Not all tokens may make sense, so you may not be able to * read them all (until more come in later). * * @update gess5/18/98 * @param aParser is the parser object that's driving this process * @return error code (almost always NS_OK) */ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink) { NS_PRECONDITION(mBodyContext!=nsnull,"Create a context before calling build model"); nsresult result=NS_OK; if(aTokenizer) { nsITokenizer* oldTokenizer=mTokenizer; mTokenizer=aTokenizer; mParser=(nsParser*)aParser; if(mTokenizer) { mTokenRecycler=(CTokenRecycler*)mTokenizer->GetTokenRecycler(); result=mBodyContext->GetNodeRecycler(mNodeRecycler); // Get a copy... if(NS_FAILED(result)) return result; if(mSink) { if(!mBodyContext->GetCount()) { CStartToken* theToken=nsnull; if(ePlainText==mDocType) { //we do this little trick for text files, in both normal and viewsource mode... theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_pre); if(theToken) { mTokenizer->PushTokenFront(theToken); } } //if the content model is empty, then begin by opening ... theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_html,NS_ConvertToString("html")); if(theToken) { mTokenizer->PushTokenFront(theToken); //this token should get pushed on the context stack. } } while(NS_SUCCEEDED(result)){ #if 0 int n=aTokenizer->GetCount(); if(n>50) n=50; for(int i=0;iGetTokenAt(i); printf("\nToken[%i],%p",i,theToken); } printf("\n"); #endif if(mDTDState!=NS_ERROR_HTMLPARSER_STOPPARSING) { CToken* theToken=mTokenizer->PopToken(); if(theToken) { result=HandleToken(theToken,aParser); } else break; } else { result=mDTDState; break; } }//while mTokenizer=oldTokenizer; } } } else result=NS_ERROR_HTMLPARSER_BADTOKENIZER; return result; } /** * * @update gess5/18/98 * @param * @return */ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink){ nsresult result=NS_OK; if(aSink) { if((NS_OK==anErrorCode) && (!mHadBody) && (!mHadFrameset)) { mSkipTarget=eHTMLTag_unknown; //clear this in case we were searching earlier. CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_body,NS_ConvertToString("body")); 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(aNotifySink){ if((NS_OK==anErrorCode) && (mBodyContext->GetCount()>0)) { if(mSkipTarget) { CHTMLToken* theEndToken=nsnull; theEndToken=(CHTMLToken*)mTokenRecycler->CreateTokenOfType(eToken_end,mSkipTarget); if(theEndToken) { result=HandleToken(theEndToken,mParser); } } if(!mBodyContext->mHadDocTypeDecl) { CToken* theDocTypeToken=mTokenRecycler->CreateTokenOfType(eToken_doctypeDecl,eHTMLTag_markupDecl); if(theDocTypeToken) { nsAutoString theDocTypeStr; theDocTypeStr.AssignWithConversion(""); theDocTypeToken->Reinitialize(eHTMLTag_markupDecl,theDocTypeStr); result=HandleToken(theDocTypeToken,mParser); } } if(result==NS_OK) { eHTMLTags theTarget; //now let's disable style handling to save time when closing remaining stack members... mStyleHandlingEnabled=PR_FALSE; while(mBodyContext->GetCount() > 0) { theTarget = mBodyContext->Last(); CloseContainersTo(theTarget,PR_FALSE); } } } else { //If you're here, then an error occured, but we still have nodes on the stack. //At a minimum, we should grab the nodes and recycle them. //Just to be correct, we'll also recycle the nodes. while(mBodyContext->GetCount() > 0) { nsEntryStack *theChildStyles=0; nsCParserNode* theNode=(nsCParserNode*)mBodyContext->Pop(theChildStyles); theNode->mUseCount=0; mNodeRecycler->RecycleNode(theNode,mTokenRecycler); if(theChildStyles) { delete theChildStyles; } } } STOP_TIMER(); MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::DidBuildModel(), this=%p\n", this)); #ifdef ENABLE_CRC //let's only grab this state once! if(!gShowCRC) { gShowCRC=1; //this only indicates we'll not initialize again. char* theEnvString = PR_GetEnv("RICKG_CRC"); if(theEnvString){ if(('1'==theEnvString[0]) || ('Y'==theEnvString[0]) || ('y'==theEnvString[0])){ gShowCRC=2; //this indicates that the CRC flag was found in the environment. } } } if(2==gShowCRC) { if(mComputedCRC32!=mExpectedCRC32) { if(mExpectedCRC32!=0) { printf("CRC Computed: %u Expected CRC: %u\n,",mComputedCRC32,mExpectedCRC32); result = aSink->DidBuildModel(2); } else { printf("Computed CRC: %u.\n",mComputedCRC32); result = aSink->DidBuildModel(3); } } else result = aSink->DidBuildModel(0); } else result=aSink->DidBuildModel(0); #endif MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::DidBuildModel(), this=%p\n", this)); START_TIMER(); //Now make sure the misplaced content list is empty, //by forcefully recycling any tokens we might find there. CToken* theToken=0; while((theToken=(CToken*)mMisplacedContent.Pop())) { mTokenRecycler->RecycleToken(theToken); } if(mDTDDebug) { mDTDDebug->DumpVectorRecord(); } } } //if aparser //No matter what, you need to call did build model. result=aSink->DidBuildModel(0); } //if asink 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 * moved over to the delegate. Ah, so much to do... * * @update gess 12/1/99 * @param aToken * @param aParser * @return */ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ nsresult result=NS_OK; if(aToken) { CHTMLToken* theToken= (CHTMLToken*)(aToken); eHTMLTokenTypes theType=eHTMLTokenTypes(theToken->GetTokenType()); eHTMLTags theTag=(eHTMLTags)theToken->GetTypeID(); PRBool execSkipContent=PR_FALSE; theToken->mUseCount=0; //assume every token coming into this system needs recycling. /* --------------------------------------------------------------------------------- To understand this little piece of code, you need to look below too. In essence, this code caches "skipped content" until we find a given skiptarget. Once we find the skiptarget, we take all skipped content up to that point and coallate it. Then we push those tokens back onto the tokenizer deque. --------------------------------------------------------------------------------- */ // printf("token: %p\n",aToken); if(mSkipTarget){ //handle a preexisting target... if((theTag==mSkipTarget) && (eToken_end==theType)){ mSkipTarget=eHTMLTag_unknown; //stop skipping. //mTokenizer->PushTokenFront(aToken); //push the end token... execSkipContent=PR_TRUE; mTokenRecycler->RecycleToken(aToken); theToken=(CHTMLToken*)mSkippedContent.PopFront(); theType=eToken_start; } else { mSkippedContent.Push(theToken); return result; } } /* --------------------------------------------------------------------------------- This section of code is used to "move" misplaced content from one location in our document model to another. (Consider what would happen if we found a

tag and text in the head.) To move content, we throw it onto the misplacedcontent deque until we can deal with it. --------------------------------------------------------------------------------- */ if(!execSkipContent) { switch(theTag) { case eHTMLTag_html: case eHTMLTag_comment: case eHTMLTag_script: case eHTMLTag_markupDecl: break; // simply pass these through to token handler without further ado... case eHTMLTag_newline: case eHTMLTag_whitespace: if(mMisplacedContent.GetSize()<=0) // fix for bugs 17017,18308,23765, and 24275 break; // Push only when it's absolutely necessary. default: if(!gHTMLElements[eHTMLTag_html].SectionContains(theTag,PR_FALSE)) { if((!mHadBody) && (!mHadFrameset)){ //For bug examples from this code, see bugs: 18928, 20989. //At this point we know the body/frameset aren't open. //If the child belongs in the head, then handle it (which may open the head); //otherwise, push it onto the misplaced stack. PRBool theExclusive=PR_FALSE; PRBool theChildBelongsInHead=gHTMLElements[eHTMLTag_head].IsChildOfHead(theTag,theExclusive); if(!theChildBelongsInHead) { //If you're here then we found a child of the body that was out of place. //We're going to move it to the body by storing it temporarily on the misplaced stack. //However, in quirks mode, a few tags request, ambiguosly, for a BODY. - Bugs 18928, 24204.- mMisplacedContent.Push(aToken); aToken->mUseCount++; if(mDTDMode==eDTDMode_quirks && (gHTMLElements[theTag].HasSpecialProperty(kRequiresBody))) { CToken* theBodyToken=(CToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_body,NS_ConvertToString("body")); result=HandleToken(theBodyToken,aParser); } return result; } } //if } //if }//switch } //if if(theToken){ //Before dealing with the token normally, we need to deal with skip targets if((!execSkipContent) && (theType!=eToken_end) && (eHTMLTag_unknown==mSkipTarget) && (gHTMLElements[theTag].mSkipTarget)){ //create a new target // Ref: Bug# 19977 // For optimization, determine if the skipped content is well // placed. This would avoid unnecessary node creation and // extra string append. BTW, watch out in handling the head // children ( especially the TITLE tag). PRBool theExclusive=PR_FALSE; if(!gHTMLElements[eHTMLTag_head].IsChildOfHead(theTag,theExclusive)) { eHTMLTags theParentTag = mBodyContext->Last(); PRBool theParentContains = -1; if(CanOmit(theParentTag,theTag,theParentContains)) { result=HandleOmittedTag(theToken,theTag,theParentTag,nsnull); return result; } } mSkipTarget=gHTMLElements[theTag].mSkipTarget; mSkippedContent.Push(theToken); } else { mParser=(nsParser*)aParser; switch(theType) { case eToken_text: case eToken_start: case eToken_whitespace: case eToken_newline: result=HandleStartToken(theToken); break; case eToken_end: result=HandleEndToken(theToken); break; case eToken_cdatasection: case eToken_comment: result=HandleCommentToken(theToken); break; case eToken_entity: result=HandleEntityToken(theToken); break; case eToken_attribute: result=HandleAttributeToken(theToken); break; case eToken_instruction: result=HandleProcessingInstructionToken(theToken); break; case eToken_doctypeDecl: result=HandleDocTypeDeclToken(theToken); break; default: break; }//switch if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) { if(0>=theToken->mUseCount) mTokenRecycler->RecycleToken(theToken); } else if(result==NS_ERROR_HTMLPARSER_STOPPARSING) mDTDState=result; else return NS_OK; /*************************************************************/ // CAUTION: Here we are forgetting to push the ATTRIBUTE Tokens. // So, before you uncomment this part please make sure // that the attribute tokens are also accounted for. //else if(NS_ERROR_HTMLPARSER_MISPLACED!=result) // mTokenizer->PushTokenFront(theToken); //else result=NS_OK; /***************************************************************/ #if 0 if (mDTDDebug) { mDTDDebug->Verify(this, mParser, mBodyContext->GetCount(), mBodyContext->mStack, mFilename); } #endif } } }//if return result; } /** * This gets called after we've handled a given start tag. * It's a generic hook to let us to post processing. * @param aToken contains the tag in question * @param aChildTag is the tag itself. * @return status */ nsresult CNavDTD::DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag){ nsresult result=NS_OK; switch(aChildTag){ case eHTMLTag_pre: case eHTMLTag_listing: { CToken* theNextToken=mTokenizer->PeekToken(); if(theNextToken) { eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType()); if(eToken_newline==theType){ mLineNumber++; theNextToken=mTokenizer->PopToken(); //skip 1st newline inside PRE and LISTING if(theNextToken) mTokenRecycler->RecycleToken(theNextToken); // fix for Bug 29379 }//if }//if } break; case eHTMLTag_plaintext: case eHTMLTag_xmp: //grab the skipped content and dump it out as text... { STOP_TIMER() MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::DidHandleStartTag(), this=%p\n", this)); const nsString& theString=aNode.GetSkippedContent(); if(0GetCount(); eHTMLTags theGrandParentTag=mBodyContext->TagAt(theCount-2); nsAutoString theNumber; PRInt32 theCounter=mBodyContext->IncrementCounter(theGrandParentTag,aNode,theNumber); CTextToken theToken(theNumber); PRInt32 theLineNumber=0; nsCParserNode theNode(&theToken,theLineNumber); result=mSink->AddLeaf(theNode); } break; case eHTMLTag_meta: { //we should only enable user-defined entities in debug builds... PRInt32 theCount=aNode.GetAttributeCount(); const nsString* theNamePtr=0; const nsString* theValuePtr=0; if(theCount) { PRInt32 theIndex=0; for(theIndex=0;theIndexRegisterEntity(*theNamePtr,*theValuePtr); } } break; default: break; }//switch return result; } /** * Determine whether the given tag is open anywhere * in our context stack. * * @update gess 4/2/98 * @param eHTMLTags tag to be searched for in stack * @return topmost index of tag on stack */ PRInt32 CNavDTD::LastOf(eHTMLTags aTagSet[],PRInt32 aCount) const { int theIndex=0; for(theIndex=mBodyContext->GetCount()-1;theIndex>=0;theIndex--){ if(FindTagInSet((*mBodyContext)[theIndex],aTagSet,aCount)) { return theIndex; } } return kNotFound; } /** * Call this to find the index of a given child, or (if not found) * the index of its nearest synonym. * * @update gess 3/25/98 * @param aTagStack -- list of open tags * @param aTag -- tag to test for containership * @return index of kNotFound */ static PRInt32 GetIndexOfChildOrSynonym(nsDTDContext& aContext,eHTMLTags aChildTag) { PRInt32 theChildIndex=aContext.LastOf(aChildTag); if(kNotFound==theChildIndex) { TagList* theSynTags=gHTMLElements[aChildTag].GetSynonymousTags(); //get the list of tags that THIS tag can close if(theSynTags) { theChildIndex=LastOf(aContext,*theSynTags); } else{ PRInt32 theGroup=nsHTMLElement::GetSynonymousGroups(aChildTag); if(theGroup) { theChildIndex=aContext.GetCount(); while(-1<--theChildIndex) { eHTMLTags theTag=aContext[theChildIndex]; if(gHTMLElements[theTag].IsMemberOf(theGroup)) { break; } } } } } return theChildIndex; } /** * This method is called to determine whether or not the child * tag is happy being OPENED in the context of the current * tag stack. This is only called if the current parent thinks * it wants to contain the given childtag. * * @param aChildTag -- tag enum of child to be opened * @param aTagStack -- ref to current tag stack in DTD. * @return PR_TRUE if child agrees to be opened here. */ static PRBool CanBeContained(eHTMLTags aChildTag,nsDTDContext& aContext) { /* # Interesting test cases: Result: * 1.