Bug 74728, redux. Fix without leaking tokens: make sure that nsCParserNode always has an nsTokenAllocator object. r=harishd, sr=shaver

git-svn-id: svn://10.0.0.236/trunk@91383 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
waterson%netscape.com 2001-04-05 00:27:11 +00:00
parent 81dbdbc713
commit 17ec076943
14 changed files with 150 additions and 110 deletions

View File

@ -952,7 +952,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
const nsString& theString=aNode.GetSkippedContent();
if(0<theString.Length()) {
CTextToken *theToken=NS_STATIC_CAST(CTextToken*,mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,theString));
nsCParserNode theNode(theToken,0);
nsCParserNode theNode(theToken,0,mTokenAllocator);
result=mSink->AddLeaf(theNode); //when the node get's destructed, so does the new token
}
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::DidHandleStartTag(), this=%p\n", this));
@ -971,7 +971,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
CTextToken theToken(theNumber);
PRInt32 theLineNumber=0;
nsCParserNode theNode(&theToken,theLineNumber);
nsCParserNode theNode(&theToken,theLineNumber,mTokenAllocator);
result=mSink->AddLeaf(theNode);
}
break;
@ -1420,7 +1420,7 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsIParserNode
//because this code calls CloseHead() directly, stack-based token/nodes are ok.
CEndToken theToken(eHTMLTag_head);
nsCParserNode theNode(&theToken,mLineNumber);
nsCParserNode theNode(&theToken,mLineNumber,mTokenAllocator);
result=CloseHead(&theNode);
}
}
@ -1903,7 +1903,7 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) {
case eHTMLTag_form:
{
//this is safe because we call close container directly. This node/token is not cached.
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber);
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenAllocator);
result=CloseContainer(&theNode,theChildTag,PR_FALSE);
}
break;

View File

@ -250,14 +250,14 @@ public:
nsresult result=NS_OK;
CStartToken theToken(*aTagList);
nsCParserNode theNode(&theToken,theLineNumber);
nsCParserNode theNode(&theToken,theLineNumber,aContext->mTokenAllocator);
result=OpenContainer(&theNode,*aTagList,aContext,aSink);
if(eHTMLTag_unknown!=*(aTagList+1)) {
AutoGenerateStructure(++aTagList,aContext,aSink);
}
CEndToken theEndToken(*aTagList--);
nsCParserNode theEndNode(&theEndToken,theLineNumber);
nsCParserNode theEndNode(&theEndToken,theLineNumber,aContext->mTokenAllocator);
result=CloseContainer(&theEndNode,*aTagList,aContext,aSink);
return result;
@ -1005,7 +1005,7 @@ public:
CTextToken theToken(theNumber);
PRInt32 theLineNumber=0;
nsCParserNode theNewNode(&theToken,theLineNumber);
nsCParserNode theNewNode(&theToken,theLineNumber,aContext->mTokenAllocator);
result=aSink->AddLeaf(theNewNode);
return result;
}

View File

@ -455,7 +455,7 @@ NS_IMETHODIMP nsExpatDTD::HandleToken(CToken* aToken,nsIParser* aParser) {
mParser=(nsParser*)aParser;
mSink=aParser->GetContentSink();
nsCParserNode theNode(theToken,mLineNumber);
nsCParserNode theNode(theToken,mLineNumber,mTokenizer->GetTokenAllocator());
switch(theType) {
case eToken_newline:

View File

@ -40,7 +40,25 @@ const nsString& GetEmptyString() {
/**
* Default constructor
* Default Constructor
*/
nsCParserNode::nsCParserNode()
: mLineNumber(1),
mToken(nsnull),
mAttributes(nsnull),
mSkippedContent(nsnull),
mUseCount(0),
mGenericState(PR_FALSE),
mTokenAllocator(nsnull)
{
MOZ_COUNT_CTOR(nsCParserNode);
#ifdef HEAP_ALLOCATED_NODES
mNodeAllocator=nsnull;
#endif
}
/**
* Constructor
*
* @update gess 3/25/98
* @param aToken -- token to init internal token
@ -343,13 +361,11 @@ void nsCParserNode::GetSource(nsString& aString) {
* @return void
*/
nsresult nsCParserNode::ReleaseAll() {
NS_ASSERTION(mTokenAllocator != nsnull, "aiee! no token allocator!");
if(mAttributes) {
CToken* theAttrToken=0;
while((theAttrToken=NS_STATIC_CAST(CToken*,mAttributes->Pop()))) {
// nsViewSourceHTML.cpp:513 creates nsCParserNodes with a NULL token allocator
// need to check to see if mTokenAllocator is non-null
if(mTokenAllocator)
IF_FREE(theAttrToken, mTokenAllocator);
IF_FREE(theAttrToken, mTokenAllocator);
}
delete mAttributes;
mAttributes=0;

View File

@ -108,10 +108,15 @@ class nsCParserNode : public nsIParserNode {
/**
* Default constructor
*/
nsCParserNode();
/**
* Constructor
* @update gess5/11/98
* @param aToken is the token this node "refers" to
*/
nsCParserNode(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsTokenAllocator* aTokenAllocator=0,nsNodeAllocator* aNodeAllocator=0);
nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsTokenAllocator* aTokenAllocator,nsNodeAllocator* aNodeAllocator=0);
/**
* Destructor
@ -123,7 +128,7 @@ class nsCParserNode : public nsIParserNode {
* Init
* @update gess5/11/98
*/
virtual nsresult Init(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsTokenAllocator* aTokenAllocator=0,nsNodeAllocator* aNodeAllocator=0);
virtual nsresult Init(CToken* aToken,PRInt32 aLineNumber,nsTokenAllocator* aTokenAllocator,nsNodeAllocator* aNodeAllocator=0);
/**
* Retrieve the name of the node

View File

@ -141,7 +141,7 @@ class CToken {
* @update harishd 08/02/00
*/
void Release(nsFixedSizeAllocator& aArenaPool) {
if(--mUseCount==0)
if(--mUseCount==0)
Destroy(this, aArenaPool);
}

View File

@ -188,15 +188,12 @@ class CSharedVSContext {
public:
CSharedVSContext() :
mEndNode(),
mEndNode(),
mStartNode(),
mTokenNode(),
mErrorNode(),
mITextToken(),
mITextNode(&mITextToken),
mTextToken(),
mErrorToken(NS_ConvertASCIItoUCS2("error")),
mTextNode(&mTextToken){
mErrorToken(NS_ConvertASCIItoUCS2("error")) {
}
~CSharedVSContext() {
@ -212,10 +209,7 @@ public:
nsCParserNode mTokenNode;
nsCParserNode mErrorNode;
CIndirectTextToken mITextToken;
nsCParserNode mITextNode;
CTextToken mTextToken;
CTextToken mErrorToken;
nsCParserNode mTextNode;
};
#ifdef VIEW_SOURCE_HTML
@ -449,24 +443,6 @@ nsresult CViewSourceHTML::WillBuildModel( const CParserContext& aParserContext,
mErrorCount=0;
mTagCount=0;
#ifdef VIEW_SOURCE_HTML
nsAutoString tag;
tag.AssignWithConversion("HTML");
CStartToken htmlToken(tag, eHTMLTag_html);
nsCParserNode htmlNode(&htmlToken,0);
mSink->OpenHTML(htmlNode);
tag.AssignWithConversion("BODY");
CStartToken bodyToken(tag, eHTMLTag_body);
nsCParserNode bodyNode(&bodyToken,0);
mSink->OpenBody(bodyNode);
#else
CCommentToken ssToken(NS_LITERAL_STRING("<?xml version=\"1.0\"?>"));
nsCParserNode ssNode(&ssToken);
result= mSink->AddCharacterData(ssNode);
#endif // VIEW_SOURCE_HTML
#ifdef rickgdebug
(*gDumpFile) << theHeader << endl;
(*gDumpFile) << "<viewsource xmlns=\"viewsource\">" << endl;
@ -503,17 +479,37 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke
if(!mHasOpenRoot) {
#ifdef VIEW_SOURCE_HTML
// For the stack-allocated tokens below, it's safe to pass a null
// token allocator, because there are no attributes on the tokens.
nsAutoString tag;
tag.AssignWithConversion("HTML");
CStartToken htmlToken(tag, eHTMLTag_html);
nsCParserNode htmlNode(&htmlToken,0,mTokenizer->GetTokenAllocator());
mSink->OpenHTML(htmlNode);
tag.AssignWithConversion("BODY");
CStartToken bodyToken(tag, eHTMLTag_body);
nsCParserNode bodyNode(&bodyToken,0,mTokenizer->GetTokenAllocator());
mSink->OpenBody(bodyNode);
#else
CCommentToken ssToken(NS_LITERAL_STRING("<?xml version=\"1.0\"?>"));
nsCParserNode ssNode(&ssToken,0,nsnull);
result= mSink->AddCharacterData(ssNode,0,mTokenizer->GetTokenAllocator());
#endif // VIEW_SOURCE_HTML
#ifdef VIEW_SOURCE_HTML
tag.AssignWithConversion("PRE");
CStartToken theToken(tag, eHTMLTag_pre);
#else
//now let's automatically open the root container...
CStartToken theToken(NS_LITERAL_STRING("viewsource"));
#endif // VIEW_SOURCE_HTML
nsCParserNode theNode(&theToken,0);
CAttributeToken *theAttr=nsnull;
nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
nsCParserNode theNode(&theToken,0,theAllocator);
if(theAllocator) {
#ifdef VIEW_SOURCE_HTML
theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreStyle));
@ -607,15 +603,15 @@ NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,PRBool aNotify
if(ePlainText!=mDocType) {
#ifdef VIEW_SOURCE_HTML
CEndToken theToken(eHTMLTag_pre);
nsCParserNode preNode(&theToken,0);
nsCParserNode preNode(&theToken,0,mTokenizer->GetTokenAllocator());
mSink->CloseContainer(preNode);
CEndToken bodyToken(eHTMLTag_body);
nsCParserNode bodyNode(&bodyToken,0);
nsCParserNode bodyNode(&bodyToken,0,mTokenizer->GetTokenAllocator());
mSink->CloseBody(bodyNode);
CEndToken htmlToken(eHTMLTag_html);
nsCParserNode htmlNode(&htmlToken,0);
nsCParserNode htmlNode(&htmlToken,0,mTokenizer->GetTokenAllocator());
mSink->CloseHTML(htmlNode);
#else
//now let's automatically close the root container...
@ -886,7 +882,8 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri
nsAutoString beforeText;
beforeText.AssignWithConversion(kBeforeText[aTagType]);
theContext.mITextToken.SetIndirectString(beforeText);
mSink->AddLeaf(theContext.mITextNode);
nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator());
mSink->AddLeaf(theNode);
}
#ifdef VIEW_SOURCE_COLORING
@ -900,7 +897,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri
#ifdef VIEW_SOURCE_COLORING
if (syntaxHighlight)
{
theContext.mStartNode.Init(&theTagToken,mLineNumber);
theContext.mStartNode.Init(&theTagToken,mLineNumber,mTokenizer->GetTokenAllocator());
#ifdef VIEW_SOURCE_HTML
nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
if(theAllocator) {
@ -931,7 +928,8 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri
theContext.mITextToken.SetIndirectString(aText); //now emit the tag name...
mSink->AddLeaf(theContext.mITextNode);
nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator());
mSink->AddLeaf(theNode);
if(attrCount){
result=WriteAttributes(attrCount);
@ -943,7 +941,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri
{
theContext.mStartNode.ReleaseAll();
CEndToken theEndToken(eHTMLTag_span);
theContext.mEndNode.Init(&theEndToken,mLineNumber);
theContext.mEndNode.Init(&theEndToken,mLineNumber,mTokenizer->GetTokenAllocator());
mSink->CloseContainer(theContext.mEndNode); //emit </starttag>...
}
#endif // VIEW_SOURCE_COLORING
@ -951,7 +949,8 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri
nsAutoString afterText;
afterText.AssignWithConversion(kAfterText[aTagType]);
theContext.mITextToken.SetIndirectString(afterText);
mSink->AddLeaf(theContext.mITextNode);
nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator());
mSink->AddLeaf(theNode);
}
#else
theContext.mEndNode.Init(&theTagToken,mLineNumber);
@ -990,7 +989,7 @@ nsresult CViewSourceHTML::WriteTagWithError(nsString &theXMLTagName,const nsARea
//first write the error tag itself...
theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber);
theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber,mTokenizer->GetTokenAllocator());
result=mSink->OpenContainer(theContext.mErrorNode); //emit <error>...
}
@ -1005,7 +1004,7 @@ nsresult CViewSourceHTML::WriteTagWithError(nsString &theXMLTagName,const nsARea
//now close the error tag...
STOP_TIMER();
theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber);
theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber,mTokenizer->GetTokenAllocator());
mSink->CloseContainer(theContext.mErrorNode);
START_TIMER();
}
@ -1057,7 +1056,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
#endif // VIEW_SOURCE_HTML
CSharedVSContext& theContext=CSharedVSContext::GetSharedContext();
theContext.mTokenNode.Init(theToken,mLineNumber);
theContext.mTokenNode.Init(theToken,mLineNumber,mTokenizer->GetTokenAllocator());
eHTMLTags theParent=(mTags.Length()) ? (eHTMLTags)mTags.Last() : eHTMLTag_unknown;
eHTMLTags theChild=(eHTMLTags)aToken->GetTypeID();

View File

@ -952,7 +952,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
const nsString& theString=aNode.GetSkippedContent();
if(0<theString.Length()) {
CTextToken *theToken=NS_STATIC_CAST(CTextToken*,mTokenAllocator->CreateTokenOfType(eToken_text,eHTMLTag_text,theString));
nsCParserNode theNode(theToken,0);
nsCParserNode theNode(theToken,0,mTokenAllocator);
result=mSink->AddLeaf(theNode); //when the node get's destructed, so does the new token
}
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::DidHandleStartTag(), this=%p\n", this));
@ -971,7 +971,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
CTextToken theToken(theNumber);
PRInt32 theLineNumber=0;
nsCParserNode theNode(&theToken,theLineNumber);
nsCParserNode theNode(&theToken,theLineNumber,mTokenAllocator);
result=mSink->AddLeaf(theNode);
}
break;
@ -1420,7 +1420,7 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsIParserNode
//because this code calls CloseHead() directly, stack-based token/nodes are ok.
CEndToken theToken(eHTMLTag_head);
nsCParserNode theNode(&theToken,mLineNumber);
nsCParserNode theNode(&theToken,mLineNumber,mTokenAllocator);
result=CloseHead(&theNode);
}
}
@ -1903,7 +1903,7 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) {
case eHTMLTag_form:
{
//this is safe because we call close container directly. This node/token is not cached.
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber);
nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenAllocator);
result=CloseContainer(&theNode,theChildTag,PR_FALSE);
}
break;

View File

@ -250,14 +250,14 @@ public:
nsresult result=NS_OK;
CStartToken theToken(*aTagList);
nsCParserNode theNode(&theToken,theLineNumber);
nsCParserNode theNode(&theToken,theLineNumber,aContext->mTokenAllocator);
result=OpenContainer(&theNode,*aTagList,aContext,aSink);
if(eHTMLTag_unknown!=*(aTagList+1)) {
AutoGenerateStructure(++aTagList,aContext,aSink);
}
CEndToken theEndToken(*aTagList--);
nsCParserNode theEndNode(&theEndToken,theLineNumber);
nsCParserNode theEndNode(&theEndToken,theLineNumber,aContext->mTokenAllocator);
result=CloseContainer(&theEndNode,*aTagList,aContext,aSink);
return result;
@ -1005,7 +1005,7 @@ public:
CTextToken theToken(theNumber);
PRInt32 theLineNumber=0;
nsCParserNode theNewNode(&theToken,theLineNumber);
nsCParserNode theNewNode(&theToken,theLineNumber,aContext->mTokenAllocator);
result=aSink->AddLeaf(theNewNode);
return result;
}

View File

@ -455,7 +455,7 @@ NS_IMETHODIMP nsExpatDTD::HandleToken(CToken* aToken,nsIParser* aParser) {
mParser=(nsParser*)aParser;
mSink=aParser->GetContentSink();
nsCParserNode theNode(theToken,mLineNumber);
nsCParserNode theNode(theToken,mLineNumber,mTokenizer->GetTokenAllocator());
switch(theType) {
case eToken_newline:

View File

@ -40,7 +40,25 @@ const nsString& GetEmptyString() {
/**
* Default constructor
* Default Constructor
*/
nsCParserNode::nsCParserNode()
: mLineNumber(1),
mToken(nsnull),
mAttributes(nsnull),
mSkippedContent(nsnull),
mUseCount(0),
mGenericState(PR_FALSE),
mTokenAllocator(nsnull)
{
MOZ_COUNT_CTOR(nsCParserNode);
#ifdef HEAP_ALLOCATED_NODES
mNodeAllocator=nsnull;
#endif
}
/**
* Constructor
*
* @update gess 3/25/98
* @param aToken -- token to init internal token
@ -343,13 +361,11 @@ void nsCParserNode::GetSource(nsString& aString) {
* @return void
*/
nsresult nsCParserNode::ReleaseAll() {
NS_ASSERTION(mTokenAllocator != nsnull, "aiee! no token allocator!");
if(mAttributes) {
CToken* theAttrToken=0;
while((theAttrToken=NS_STATIC_CAST(CToken*,mAttributes->Pop()))) {
// nsViewSourceHTML.cpp:513 creates nsCParserNodes with a NULL token allocator
// need to check to see if mTokenAllocator is non-null
if(mTokenAllocator)
IF_FREE(theAttrToken, mTokenAllocator);
IF_FREE(theAttrToken, mTokenAllocator);
}
delete mAttributes;
mAttributes=0;

View File

@ -108,10 +108,15 @@ class nsCParserNode : public nsIParserNode {
/**
* Default constructor
*/
nsCParserNode();
/**
* Constructor
* @update gess5/11/98
* @param aToken is the token this node "refers" to
*/
nsCParserNode(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsTokenAllocator* aTokenAllocator=0,nsNodeAllocator* aNodeAllocator=0);
nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsTokenAllocator* aTokenAllocator,nsNodeAllocator* aNodeAllocator=0);
/**
* Destructor
@ -123,7 +128,7 @@ class nsCParserNode : public nsIParserNode {
* Init
* @update gess5/11/98
*/
virtual nsresult Init(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsTokenAllocator* aTokenAllocator=0,nsNodeAllocator* aNodeAllocator=0);
virtual nsresult Init(CToken* aToken,PRInt32 aLineNumber,nsTokenAllocator* aTokenAllocator,nsNodeAllocator* aNodeAllocator=0);
/**
* Retrieve the name of the node

View File

@ -141,7 +141,7 @@ class CToken {
* @update harishd 08/02/00
*/
void Release(nsFixedSizeAllocator& aArenaPool) {
if(--mUseCount==0)
if(--mUseCount==0)
Destroy(this, aArenaPool);
}

View File

@ -188,15 +188,12 @@ class CSharedVSContext {
public:
CSharedVSContext() :
mEndNode(),
mEndNode(),
mStartNode(),
mTokenNode(),
mErrorNode(),
mITextToken(),
mITextNode(&mITextToken),
mTextToken(),
mErrorToken(NS_ConvertASCIItoUCS2("error")),
mTextNode(&mTextToken){
mErrorToken(NS_ConvertASCIItoUCS2("error")) {
}
~CSharedVSContext() {
@ -212,10 +209,7 @@ public:
nsCParserNode mTokenNode;
nsCParserNode mErrorNode;
CIndirectTextToken mITextToken;
nsCParserNode mITextNode;
CTextToken mTextToken;
CTextToken mErrorToken;
nsCParserNode mTextNode;
};
#ifdef VIEW_SOURCE_HTML
@ -449,24 +443,6 @@ nsresult CViewSourceHTML::WillBuildModel( const CParserContext& aParserContext,
mErrorCount=0;
mTagCount=0;
#ifdef VIEW_SOURCE_HTML
nsAutoString tag;
tag.AssignWithConversion("HTML");
CStartToken htmlToken(tag, eHTMLTag_html);
nsCParserNode htmlNode(&htmlToken,0);
mSink->OpenHTML(htmlNode);
tag.AssignWithConversion("BODY");
CStartToken bodyToken(tag, eHTMLTag_body);
nsCParserNode bodyNode(&bodyToken,0);
mSink->OpenBody(bodyNode);
#else
CCommentToken ssToken(NS_LITERAL_STRING("<?xml version=\"1.0\"?>"));
nsCParserNode ssNode(&ssToken);
result= mSink->AddCharacterData(ssNode);
#endif // VIEW_SOURCE_HTML
#ifdef rickgdebug
(*gDumpFile) << theHeader << endl;
(*gDumpFile) << "<viewsource xmlns=\"viewsource\">" << endl;
@ -503,17 +479,37 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke
if(!mHasOpenRoot) {
#ifdef VIEW_SOURCE_HTML
// For the stack-allocated tokens below, it's safe to pass a null
// token allocator, because there are no attributes on the tokens.
nsAutoString tag;
tag.AssignWithConversion("HTML");
CStartToken htmlToken(tag, eHTMLTag_html);
nsCParserNode htmlNode(&htmlToken,0,mTokenizer->GetTokenAllocator());
mSink->OpenHTML(htmlNode);
tag.AssignWithConversion("BODY");
CStartToken bodyToken(tag, eHTMLTag_body);
nsCParserNode bodyNode(&bodyToken,0,mTokenizer->GetTokenAllocator());
mSink->OpenBody(bodyNode);
#else
CCommentToken ssToken(NS_LITERAL_STRING("<?xml version=\"1.0\"?>"));
nsCParserNode ssNode(&ssToken,0,nsnull);
result= mSink->AddCharacterData(ssNode,0,mTokenizer->GetTokenAllocator());
#endif // VIEW_SOURCE_HTML
#ifdef VIEW_SOURCE_HTML
tag.AssignWithConversion("PRE");
CStartToken theToken(tag, eHTMLTag_pre);
#else
//now let's automatically open the root container...
CStartToken theToken(NS_LITERAL_STRING("viewsource"));
#endif // VIEW_SOURCE_HTML
nsCParserNode theNode(&theToken,0);
CAttributeToken *theAttr=nsnull;
nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
nsCParserNode theNode(&theToken,0,theAllocator);
if(theAllocator) {
#ifdef VIEW_SOURCE_HTML
theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreStyle));
@ -607,15 +603,15 @@ NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,PRBool aNotify
if(ePlainText!=mDocType) {
#ifdef VIEW_SOURCE_HTML
CEndToken theToken(eHTMLTag_pre);
nsCParserNode preNode(&theToken,0);
nsCParserNode preNode(&theToken,0,mTokenizer->GetTokenAllocator());
mSink->CloseContainer(preNode);
CEndToken bodyToken(eHTMLTag_body);
nsCParserNode bodyNode(&bodyToken,0);
nsCParserNode bodyNode(&bodyToken,0,mTokenizer->GetTokenAllocator());
mSink->CloseBody(bodyNode);
CEndToken htmlToken(eHTMLTag_html);
nsCParserNode htmlNode(&htmlToken,0);
nsCParserNode htmlNode(&htmlToken,0,mTokenizer->GetTokenAllocator());
mSink->CloseHTML(htmlNode);
#else
//now let's automatically close the root container...
@ -886,7 +882,8 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri
nsAutoString beforeText;
beforeText.AssignWithConversion(kBeforeText[aTagType]);
theContext.mITextToken.SetIndirectString(beforeText);
mSink->AddLeaf(theContext.mITextNode);
nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator());
mSink->AddLeaf(theNode);
}
#ifdef VIEW_SOURCE_COLORING
@ -900,7 +897,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri
#ifdef VIEW_SOURCE_COLORING
if (syntaxHighlight)
{
theContext.mStartNode.Init(&theTagToken,mLineNumber);
theContext.mStartNode.Init(&theTagToken,mLineNumber,mTokenizer->GetTokenAllocator());
#ifdef VIEW_SOURCE_HTML
nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
if(theAllocator) {
@ -931,7 +928,8 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri
theContext.mITextToken.SetIndirectString(aText); //now emit the tag name...
mSink->AddLeaf(theContext.mITextNode);
nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator());
mSink->AddLeaf(theNode);
if(attrCount){
result=WriteAttributes(attrCount);
@ -943,7 +941,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri
{
theContext.mStartNode.ReleaseAll();
CEndToken theEndToken(eHTMLTag_span);
theContext.mEndNode.Init(&theEndToken,mLineNumber);
theContext.mEndNode.Init(&theEndToken,mLineNumber,mTokenizer->GetTokenAllocator());
mSink->CloseContainer(theContext.mEndNode); //emit </starttag>...
}
#endif // VIEW_SOURCE_COLORING
@ -951,7 +949,8 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri
nsAutoString afterText;
afterText.AssignWithConversion(kAfterText[aTagType]);
theContext.mITextToken.SetIndirectString(afterText);
mSink->AddLeaf(theContext.mITextNode);
nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator());
mSink->AddLeaf(theNode);
}
#else
theContext.mEndNode.Init(&theTagToken,mLineNumber);
@ -990,7 +989,7 @@ nsresult CViewSourceHTML::WriteTagWithError(nsString &theXMLTagName,const nsARea
//first write the error tag itself...
theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber);
theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber,mTokenizer->GetTokenAllocator());
result=mSink->OpenContainer(theContext.mErrorNode); //emit <error>...
}
@ -1005,7 +1004,7 @@ nsresult CViewSourceHTML::WriteTagWithError(nsString &theXMLTagName,const nsARea
//now close the error tag...
STOP_TIMER();
theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber);
theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber,mTokenizer->GetTokenAllocator());
mSink->CloseContainer(theContext.mErrorNode);
START_TIMER();
}
@ -1057,7 +1056,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
#endif // VIEW_SOURCE_HTML
CSharedVSContext& theContext=CSharedVSContext::GetSharedContext();
theContext.mTokenNode.Init(theToken,mLineNumber);
theContext.mTokenNode.Init(theToken,mLineNumber,mTokenizer->GetTokenAllocator());
eHTMLTags theParent=(mTags.Length()) ? (eHTMLTags)mTags.Last() : eHTMLTag_unknown;
eHTMLTags theChild=(eHTMLTags)aToken->GetTypeID();