From b4206a6f8f97e711cf9bc551f6793e84d3de2a7c Mon Sep 17 00:00:00 2001 From: "harishd%netscape.com" Date: Fri, 10 Sep 1999 18:51:16 +0000 Subject: [PATCH] Fix for bug 12184. Changed Notify() method, in nsDTDUtils, to support viewing source in the desired charset. --- htmlparser/src/CNavDTD.cpp | 15 +++--- htmlparser/src/nsDTDUtils.cpp | 9 +++- htmlparser/src/nsDTDUtils.h | 4 +- htmlparser/src/nsViewSourceHTML.cpp | 63 +++++++++++++--------- parser/htmlparser/src/CNavDTD.cpp | 15 +++--- parser/htmlparser/src/nsDTDUtils.cpp | 9 +++- parser/htmlparser/src/nsDTDUtils.h | 4 +- parser/htmlparser/src/nsViewSourceHTML.cpp | 63 +++++++++++++--------- 8 files changed, 116 insertions(+), 66 deletions(-) diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index 09413001b87..d89178a3df4 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -714,7 +714,7 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ if(gHTMLElements[eHTMLTag_body].SectionContains(theTag,PR_TRUE)){ mTokenizer->PushTokenFront(aToken); //put this token back... mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content - theToken=(CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,eHTMLTag_body); + theToken=(CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,theTag=eHTMLTag_body); //now open a body... } } @@ -1087,12 +1087,15 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode } if(mParser) { - nsAutoString charsetValue; - nsCharsetSource charsetSource; + nsAutoString charsetValue; + nsCharsetSource charsetSource; + CObserverService& theService=mParser->GetObserverService(); + CParserContext* pc=mParser->PeekContext(); + void* theDocID=(pc)? pc->mKey:0; + mParser->GetDocumentCharset(charsetValue,charsetSource); - CParserContext* pc=mParser->PeekContext(); - void* theDocID=(pc) ? pc->mKey : 0; - result=(mParser->GetObserverService()).Notify(aTag,aNode,(PRUint32)theDocID,this,charsetValue,charsetSource); + result=theService.Notify(aTag,aNode,(PRUint32)theDocID,kHTMLTextContentType, + charsetValue,charsetSource); } diff --git a/htmlparser/src/nsDTDUtils.cpp b/htmlparser/src/nsDTDUtils.cpp index 4c7dd21dbbf..4047f8c9048 100644 --- a/htmlparser/src/nsDTDUtils.cpp +++ b/htmlparser/src/nsDTDUtils.cpp @@ -752,7 +752,7 @@ void CObserverService::RegisterObservers(nsString& aTopic) { * @param aCharsetSource - * @return if SUCCESS return NS_OK else return ERROR code. */ -nsresult CObserverService::Notify(eHTMLTags aTag,nsIParserNode& aNode,PRUint32 aUniqueID, nsIDTD* aDTD, +nsresult CObserverService::Notify(eHTMLTags aTag,nsIParserNode& aNode,PRUint32 aUniqueID, const char* aCommand, nsAutoString& aCharsetValue,nsCharsetSource& aCharsetSource) { nsresult result=NS_OK; nsDeque* theDeque=GetObserversForTag(aTag); @@ -783,6 +783,13 @@ nsresult CObserverService::Notify(eHTMLTags aTag,nsIParserNode& aNode,PRUint32 a theValues[index] = intValue.GetUnicode(); index++; } + if(index < 50) { + nsAutoString theDTDKey("X_COMMAND"); + nsAutoString theDTDValue(aCommand); + theKeys[index]=theDTDKey.GetUnicode(); + theValues[index]=theDTDValue.GetUnicode(); + index++; + } nsAutoString theTagStr(nsHTMLTags::GetStringValue(aTag)); nsObserverNotifier theNotifier(theTagStr.GetUnicode(),aUniqueID,index,theKeys,theValues); theDeque->FirstThat(theNotifier); diff --git a/htmlparser/src/nsDTDUtils.h b/htmlparser/src/nsDTDUtils.h index 08ff65c72f5..00b11327c10 100644 --- a/htmlparser/src/nsDTDUtils.h +++ b/htmlparser/src/nsDTDUtils.h @@ -251,8 +251,8 @@ public: nsDeque* GetObserversForTag(eHTMLTags aTag); nsresult Notify(eHTMLTags aTag,nsIParserNode& aNode, - PRUint32 aUniqueID, nsIDTD* aDTD, - nsAutoString& aCharsetValue,nsCharsetSource& aCharsetSource) ; + PRUint32 aUniqueID, const char* aCommand, + nsAutoString& aCharsetValue,nsCharsetSource& aCharsetSource); protected: void RegisterObservers(nsString& aTopicList); diff --git a/htmlparser/src/nsViewSourceHTML.cpp b/htmlparser/src/nsViewSourceHTML.cpp index 7cb0750bf3a..ef036d557bf 100644 --- a/htmlparser/src/nsViewSourceHTML.cpp +++ b/htmlparser/src/nsViewSourceHTML.cpp @@ -389,7 +389,7 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke mNeedsFontSpec=PR_FALSE; } - while(NS_OK==result){ + while(NS_SUCCEEDED(result)){ CToken* theToken=mTokenizer->PopToken(); if(theToken) { result=HandleToken(theToken,aParser); @@ -971,33 +971,48 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) { else return kEOF; } } - } - - WriteTag(theContext.mTokenNode,*mSink,theEndTag,mIsHTML,mIsPlaintext,theContext); - - // We make sure to display the title on the view source window. - - if(eHTMLTag_title == theTag){ - nsCParserNode attrNode(theToken,mLineNumber,GetTokenRecycler()); - CToken* theNextToken = mTokenizer->PopToken(); - if(theNextToken) { - theType=eHTMLTokenTypes(theNextToken->GetTokenType()); - if(eToken_text==theType) { - attrNode.SetSkippedContent(theNextToken->GetStringValueXXX()); - } +#if 0 + if(mParser) { + nsAutoString charsetValue; + nsCharsetSource charsetSource; + CObserverService& theService=mParser->GetObserverService(); + CParserContext* pc=mParser->PeekContext(); + void* theDocID=(pc)? pc->mKey:0; + + mParser->GetDocumentCharset(charsetValue,charsetSource); + result=theService.Notify(theTag,theContext.mTokenNode,(PRUint32)theDocID, + kViewSourceCommand,charsetValue,charsetSource); } - result= OpenHead(attrNode); - if(NS_OK==result) { - if(mSink) { - mSink->SetTitle(attrNode.GetSkippedContent()); +#endif + if(NS_SUCCEEDED(result)) { + + WriteTag(theContext.mTokenNode,*mSink,theEndTag,mIsHTML,mIsPlaintext,theContext); + + // We make sure to display the title on the view source window. + + if(eHTMLTag_title == theTag){ + nsCParserNode attrNode(theToken,mLineNumber,GetTokenRecycler()); + CToken* theNextToken = mTokenizer->PopToken(); + if(theNextToken) { + theType=eHTMLTokenTypes(theNextToken->GetTokenType()); + if(eToken_text==theType) { + attrNode.SetSkippedContent(theNextToken->GetStringValueXXX()); + } + } + result= OpenHead(attrNode); + if(NS_OK==result) { + if(mSink) { + mSink->SetTitle(attrNode.GetSkippedContent()); + } + if(NS_OK==result) + result=CloseHead(attrNode); + } + const nsString& theText=attrNode.GetSkippedContent(); + ::WriteText(theText,*mSink,PR_FALSE,mIsPlaintext,theContext); } - if(NS_OK==result) - result=CloseHead(attrNode); } - const nsString& theText=attrNode.GetSkippedContent(); - ::WriteText(theText,*mSink,PR_FALSE,mIsPlaintext,theContext); + break; } - break; case eToken_end: WriteTag(theContext.mTokenNode,*mSink,theEndTag,mIsHTML,mIsPlaintext,theContext); break; diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index 09413001b87..d89178a3df4 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -714,7 +714,7 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ if(gHTMLElements[eHTMLTag_body].SectionContains(theTag,PR_TRUE)){ mTokenizer->PushTokenFront(aToken); //put this token back... mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content - theToken=(CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,eHTMLTag_body); + theToken=(CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,theTag=eHTMLTag_body); //now open a body... } } @@ -1087,12 +1087,15 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode } if(mParser) { - nsAutoString charsetValue; - nsCharsetSource charsetSource; + nsAutoString charsetValue; + nsCharsetSource charsetSource; + CObserverService& theService=mParser->GetObserverService(); + CParserContext* pc=mParser->PeekContext(); + void* theDocID=(pc)? pc->mKey:0; + mParser->GetDocumentCharset(charsetValue,charsetSource); - CParserContext* pc=mParser->PeekContext(); - void* theDocID=(pc) ? pc->mKey : 0; - result=(mParser->GetObserverService()).Notify(aTag,aNode,(PRUint32)theDocID,this,charsetValue,charsetSource); + result=theService.Notify(aTag,aNode,(PRUint32)theDocID,kHTMLTextContentType, + charsetValue,charsetSource); } diff --git a/parser/htmlparser/src/nsDTDUtils.cpp b/parser/htmlparser/src/nsDTDUtils.cpp index 4c7dd21dbbf..4047f8c9048 100644 --- a/parser/htmlparser/src/nsDTDUtils.cpp +++ b/parser/htmlparser/src/nsDTDUtils.cpp @@ -752,7 +752,7 @@ void CObserverService::RegisterObservers(nsString& aTopic) { * @param aCharsetSource - * @return if SUCCESS return NS_OK else return ERROR code. */ -nsresult CObserverService::Notify(eHTMLTags aTag,nsIParserNode& aNode,PRUint32 aUniqueID, nsIDTD* aDTD, +nsresult CObserverService::Notify(eHTMLTags aTag,nsIParserNode& aNode,PRUint32 aUniqueID, const char* aCommand, nsAutoString& aCharsetValue,nsCharsetSource& aCharsetSource) { nsresult result=NS_OK; nsDeque* theDeque=GetObserversForTag(aTag); @@ -783,6 +783,13 @@ nsresult CObserverService::Notify(eHTMLTags aTag,nsIParserNode& aNode,PRUint32 a theValues[index] = intValue.GetUnicode(); index++; } + if(index < 50) { + nsAutoString theDTDKey("X_COMMAND"); + nsAutoString theDTDValue(aCommand); + theKeys[index]=theDTDKey.GetUnicode(); + theValues[index]=theDTDValue.GetUnicode(); + index++; + } nsAutoString theTagStr(nsHTMLTags::GetStringValue(aTag)); nsObserverNotifier theNotifier(theTagStr.GetUnicode(),aUniqueID,index,theKeys,theValues); theDeque->FirstThat(theNotifier); diff --git a/parser/htmlparser/src/nsDTDUtils.h b/parser/htmlparser/src/nsDTDUtils.h index 08ff65c72f5..00b11327c10 100644 --- a/parser/htmlparser/src/nsDTDUtils.h +++ b/parser/htmlparser/src/nsDTDUtils.h @@ -251,8 +251,8 @@ public: nsDeque* GetObserversForTag(eHTMLTags aTag); nsresult Notify(eHTMLTags aTag,nsIParserNode& aNode, - PRUint32 aUniqueID, nsIDTD* aDTD, - nsAutoString& aCharsetValue,nsCharsetSource& aCharsetSource) ; + PRUint32 aUniqueID, const char* aCommand, + nsAutoString& aCharsetValue,nsCharsetSource& aCharsetSource); protected: void RegisterObservers(nsString& aTopicList); diff --git a/parser/htmlparser/src/nsViewSourceHTML.cpp b/parser/htmlparser/src/nsViewSourceHTML.cpp index 7cb0750bf3a..ef036d557bf 100644 --- a/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -389,7 +389,7 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke mNeedsFontSpec=PR_FALSE; } - while(NS_OK==result){ + while(NS_SUCCEEDED(result)){ CToken* theToken=mTokenizer->PopToken(); if(theToken) { result=HandleToken(theToken,aParser); @@ -971,33 +971,48 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) { else return kEOF; } } - } - - WriteTag(theContext.mTokenNode,*mSink,theEndTag,mIsHTML,mIsPlaintext,theContext); - - // We make sure to display the title on the view source window. - - if(eHTMLTag_title == theTag){ - nsCParserNode attrNode(theToken,mLineNumber,GetTokenRecycler()); - CToken* theNextToken = mTokenizer->PopToken(); - if(theNextToken) { - theType=eHTMLTokenTypes(theNextToken->GetTokenType()); - if(eToken_text==theType) { - attrNode.SetSkippedContent(theNextToken->GetStringValueXXX()); - } +#if 0 + if(mParser) { + nsAutoString charsetValue; + nsCharsetSource charsetSource; + CObserverService& theService=mParser->GetObserverService(); + CParserContext* pc=mParser->PeekContext(); + void* theDocID=(pc)? pc->mKey:0; + + mParser->GetDocumentCharset(charsetValue,charsetSource); + result=theService.Notify(theTag,theContext.mTokenNode,(PRUint32)theDocID, + kViewSourceCommand,charsetValue,charsetSource); } - result= OpenHead(attrNode); - if(NS_OK==result) { - if(mSink) { - mSink->SetTitle(attrNode.GetSkippedContent()); +#endif + if(NS_SUCCEEDED(result)) { + + WriteTag(theContext.mTokenNode,*mSink,theEndTag,mIsHTML,mIsPlaintext,theContext); + + // We make sure to display the title on the view source window. + + if(eHTMLTag_title == theTag){ + nsCParserNode attrNode(theToken,mLineNumber,GetTokenRecycler()); + CToken* theNextToken = mTokenizer->PopToken(); + if(theNextToken) { + theType=eHTMLTokenTypes(theNextToken->GetTokenType()); + if(eToken_text==theType) { + attrNode.SetSkippedContent(theNextToken->GetStringValueXXX()); + } + } + result= OpenHead(attrNode); + if(NS_OK==result) { + if(mSink) { + mSink->SetTitle(attrNode.GetSkippedContent()); + } + if(NS_OK==result) + result=CloseHead(attrNode); + } + const nsString& theText=attrNode.GetSkippedContent(); + ::WriteText(theText,*mSink,PR_FALSE,mIsPlaintext,theContext); } - if(NS_OK==result) - result=CloseHead(attrNode); } - const nsString& theText=attrNode.GetSkippedContent(); - ::WriteText(theText,*mSink,PR_FALSE,mIsPlaintext,theContext); + break; } - break; case eToken_end: WriteTag(theContext.mTokenNode,*mSink,theEndTag,mIsHTML,mIsPlaintext,theContext); break;