diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index c42b8e1fd381..d22cc58ef750 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -1196,18 +1196,35 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode PRInt32 index = 0; const PRUnichar* theKeys[50] = {0,0,0,0,0}; // XXX - should be dynamic const PRUnichar* theValues[50]= {0,0,0,0,0}; // XXX - should be dynamic - for(index=0; indexGetDocumentCharset(charsetValue, charsetSource); + // Add pseudo attribute in the end + if(index < 50) { + nsAutoString theCharsetKey("charset"); + theKeys[index]=theCharsetKey.GetUnicode(); + theValues[index] = charsetValue.GetUnicode(); + index++; + } + + if(index < 50) { + nsAutoString theCharsetKey("charsetSource"); + theKeys[index]=theCharsetKey.GetUnicode(); + PRInt32 sourceInt = charsetSource; + nsAutoString intValue; + intValue.Append(sourceInt,10); + theValues[index] = intValue.GetUnicode(); + index++; + } CParserContext* pc=mParser->PeekContext(); void* theDocID=(pc) ? pc-> mKey : 0; - nsObserverNotifier theNotifier(aTag,theAttrCount,theKeys,theValues,(PRUint32)theDocID); + nsObserverNotifier theNotifier(aTag,index,theKeys,theValues,(PRUint32)theDocID); theDeque->FirstThat(theNotifier); result=theNotifier.mResult; @@ -1216,23 +1233,21 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode } - //********************************************************** - //XXX Hack until I get the node observer API in place... - - if(eHTMLTag_meta==aTag) { - PRInt32 theCount=aNode.GetAttributeCount(); - if(1 - const nsString& theKey=aNode.GetKeyAt(0); - if(theKey.EqualsIgnoreCase("HTTP-EQUIV")) { - const nsString& theKey2=aNode.GetKeyAt(1); - if(theKey2.EqualsIgnoreCase("CONTENT")) { - nsScanner* theScanner=mParser->GetScanner(); - if(theScanner) { - const nsString& theValue=aNode.GetValueAt(1); - PRInt32 charsetValueStart = theValue.RFind("charset=", PR_TRUE ) ; - if(kNotFound != charsetValueStart) { + if(eHTMLTag_meta==aTag) { + PRInt32 theCount=aNode.GetAttributeCount(); + if(1 + if(theKey.EqualsIgnoreCase("HTTP-EQUIV")) { + const nsString& theKey2=aNode.GetKeyAt(1); + if(theKey2.EqualsIgnoreCase("CONTENT")) { + nsScanner* theScanner=mParser->GetScanner(); + if(theScanner) { + const nsString& theValue=aNode.GetValueAt(1); + PRInt32 charsetValueStart = theValue.RFind("charset=", PR_TRUE ) ; + if(kNotFound != charsetValueStart) { charsetValueStart += 8; // 8 = "charset=".length PRInt32 charsetValueEnd = theValue.FindCharInSet("\'\";", charsetValueStart ); if(kNotFound == charsetValueEnd ) @@ -1247,29 +1262,27 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode } } //if - else if(theKey.EqualsIgnoreCase("NAME")) { - const nsString& theValue1=aNode.GetValueAt(0); - if(theValue1.EqualsIgnoreCase("\"CRC\"")) { - const nsString& theKey2=aNode.GetKeyAt(1); - if(theKey2.EqualsIgnoreCase("CONTENT")) { - const nsString& theValue2=aNode.GetValueAt(1); - PRInt32 err=0; - mExpectedCRC32=theValue2.ToInteger(&err); - } //if - } //if - } //else + else +#endif + if(theKey.EqualsIgnoreCase("NAME")) { + const nsString& theValue1=aNode.GetValueAt(0); + if(theValue1.EqualsIgnoreCase("\"CRC\"")) { + const nsString& theKey2=aNode.GetKeyAt(1); + if(theKey2.EqualsIgnoreCase("CONTENT")) { + const nsString& theValue2=aNode.GetValueAt(1); + PRInt32 err=0; + mExpectedCRC32=theValue2.ToInteger(&err); + } //if + } //if + } //else - } //if - }//if - - //XXX Hack until I get the node observer API in place... - //********************************************************** + } //if + }//if if(NS_OK==result) { result=gHTMLElements[aTag].HasSpecialProperty(kDiscardTag) ? 1 : NS_OK; } - PRBool isHeadChild=gHTMLElements[eHTMLTag_head].IsChildOfHead(aTag); //this code is here to make sure the head is closed before we deal diff --git a/htmlparser/src/nsParser.cpp b/htmlparser/src/nsParser.cpp index 3c1be67405cd..82d0bde4fdde 100644 --- a/htmlparser/src/nsParser.cpp +++ b/htmlparser/src/nsParser.cpp @@ -121,8 +121,8 @@ public: //static CSharedParserObjects* gSharedParserObjects=0; -nsString nsParser::gHackMetaCharset = ""; -nsString nsParser::gHackMetaCharsetURL = ""; + +//------------------------------------------------------------------------- /********************************************************************************** This class is used as an interface between an external agent (like the DOM) and @@ -161,9 +161,6 @@ public: nsDeque mTags; //will hold a deque of prunichars... }; -//------------------------------------------------------------------- - - CSharedParserObjects& GetSharedObjects() { static CSharedParserObjects gSharedParserObjects; return gSharedParserObjects; @@ -624,31 +621,6 @@ nsresult nsParser::Parse(nsIURL* aURL,nsIStreamObserver* aListener,PRBool aVerif if (rv != NS_OK) return rv; nsAutoString theName(spec); - // XXX temp hack to make parser use UTF-8 as default charset for XML, RDF, XUL - // XXX This should be removed once we have the SetDefaultCharset in the nsIParser interface - nsString last4; - theName.Right(last4, 4); - if(last4.EqualsIgnoreCase(".xul") || last4.EqualsIgnoreCase(".xml") || last4.EqualsIgnoreCase(".rdf") ) - { - if(kCharsetFromDocTypeDefault >= mCharsetSource) { - mCharset = "UTF-8"; - mCharsetSource = kCharsetFromDocTypeDefault; - } - } - - // XXX begin of meta tag charset hack - - if(theName.Equals(nsParser::gHackMetaCharsetURL) && (! nsParser::gHackMetaCharset.Equals(""))) - { - if(kCharsetFromMetaTag > mCharsetSource) { - mCharset = nsParser::gHackMetaCharset; - mCharsetSource = kCharsetFromMetaTag; - } - } - nsParser::gHackMetaCharsetURL = theName; - nsParser::gHackMetaCharset = ""; - // XXX end of meta tag charset hack - CParserContext* pc=new CParserContext(new nsScanner(theName,PR_FALSE, mCharset, mCharsetSource),aKey,aListener); if(pc) { pc->mMultipart=PR_TRUE; @@ -675,20 +647,7 @@ nsresult nsParser::Parse(nsIInputStream& aStream,PRBool aVerifyEnabled, void* aK //ok, time to create our tokenizer and begin the process nsAutoString theUnknownFilename("unknown"); - // XXX begin of meta tag charset hack - if(theUnknownFilename.Equals(nsParser::gHackMetaCharsetURL) && (! nsParser::gHackMetaCharset.Equals(""))) - { - - if(kCharsetFromMetaTag > mCharsetSource) { - mCharset = nsParser::gHackMetaCharset; - mCharsetSource = kCharsetFromMetaTag; - } - } - nsParser::gHackMetaCharsetURL = theUnknownFilename; - nsParser::gHackMetaCharset = ""; - // XXX end of meta tag charset hack - - nsInputStream input(&aStream); + nsInputStream input(&aStream); CParserContext* pc=new CParserContext(new nsScanner(theUnknownFilename, input, mCharset, mCharsetSource,PR_FALSE),aKey,0); if(pc) { PushContext(*pc); @@ -724,27 +683,6 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aCon } #endif - if(aContentType.EqualsIgnoreCase("text/xul") || aContentType.EqualsIgnoreCase("text/xml") || aContentType.EqualsIgnoreCase("text/rdf") ) - { - if(kCharsetFromDocTypeDefault >= mCharsetSource) { - mCharset = "UTF-8"; - mCharsetSource = kCharsetFromDocTypeDefault; - } - } - - // XXX begin of meta tag charset hack - nsAutoString theFakeURL("fromString"); - if(theFakeURL.Equals(nsParser::gHackMetaCharsetURL) && (! nsParser::gHackMetaCharset.Equals(""))) - { - if(kCharsetFromMetaTag > mCharsetSource) { - mCharset = nsParser::gHackMetaCharset; - mCharsetSource = kCharsetFromMetaTag; - } - } - nsParser::gHackMetaCharsetURL = theFakeURL; - nsParser::gHackMetaCharset = ""; - // XXX end of meta tag charset hack - //NOTE: Make sure that updates to this method don't cause // bug #2361 to break again! diff --git a/htmlparser/src/nsParser.h b/htmlparser/src/nsParser.h index 32e5c467545e..2ab56cdf2184 100644 --- a/htmlparser/src/nsParser.h +++ b/htmlparser/src/nsParser.h @@ -137,6 +137,12 @@ friend class CTokenHandler; */ virtual void SetDocumentCharset(nsString& aCharset, nsCharsetSource aSource); + void GetDocumentCharset(nsString& oCharset, nsCharsetSource& oSource) + { + oCharset = mCharset; + oSource = mCharsetSource; + } + virtual nsIParserFilter* SetParserFilter(nsIParserFilter* aFilter); @@ -258,12 +264,6 @@ friend class CTokenHandler; */ virtual nsresult CreateTagStack(nsITagStack** aTagStack); - /* - * The following two should be removed once our Meta Charset work complete - */ - static nsString gHackMetaCharset; - static nsString gHackMetaCharsetURL; - protected: /** diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index c42b8e1fd381..d22cc58ef750 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -1196,18 +1196,35 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode PRInt32 index = 0; const PRUnichar* theKeys[50] = {0,0,0,0,0}; // XXX - should be dynamic const PRUnichar* theValues[50]= {0,0,0,0,0}; // XXX - should be dynamic - for(index=0; indexGetDocumentCharset(charsetValue, charsetSource); + // Add pseudo attribute in the end + if(index < 50) { + nsAutoString theCharsetKey("charset"); + theKeys[index]=theCharsetKey.GetUnicode(); + theValues[index] = charsetValue.GetUnicode(); + index++; + } + + if(index < 50) { + nsAutoString theCharsetKey("charsetSource"); + theKeys[index]=theCharsetKey.GetUnicode(); + PRInt32 sourceInt = charsetSource; + nsAutoString intValue; + intValue.Append(sourceInt,10); + theValues[index] = intValue.GetUnicode(); + index++; + } CParserContext* pc=mParser->PeekContext(); void* theDocID=(pc) ? pc-> mKey : 0; - nsObserverNotifier theNotifier(aTag,theAttrCount,theKeys,theValues,(PRUint32)theDocID); + nsObserverNotifier theNotifier(aTag,index,theKeys,theValues,(PRUint32)theDocID); theDeque->FirstThat(theNotifier); result=theNotifier.mResult; @@ -1216,23 +1233,21 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode } - //********************************************************** - //XXX Hack until I get the node observer API in place... - - if(eHTMLTag_meta==aTag) { - PRInt32 theCount=aNode.GetAttributeCount(); - if(1 - const nsString& theKey=aNode.GetKeyAt(0); - if(theKey.EqualsIgnoreCase("HTTP-EQUIV")) { - const nsString& theKey2=aNode.GetKeyAt(1); - if(theKey2.EqualsIgnoreCase("CONTENT")) { - nsScanner* theScanner=mParser->GetScanner(); - if(theScanner) { - const nsString& theValue=aNode.GetValueAt(1); - PRInt32 charsetValueStart = theValue.RFind("charset=", PR_TRUE ) ; - if(kNotFound != charsetValueStart) { + if(eHTMLTag_meta==aTag) { + PRInt32 theCount=aNode.GetAttributeCount(); + if(1 + if(theKey.EqualsIgnoreCase("HTTP-EQUIV")) { + const nsString& theKey2=aNode.GetKeyAt(1); + if(theKey2.EqualsIgnoreCase("CONTENT")) { + nsScanner* theScanner=mParser->GetScanner(); + if(theScanner) { + const nsString& theValue=aNode.GetValueAt(1); + PRInt32 charsetValueStart = theValue.RFind("charset=", PR_TRUE ) ; + if(kNotFound != charsetValueStart) { charsetValueStart += 8; // 8 = "charset=".length PRInt32 charsetValueEnd = theValue.FindCharInSet("\'\";", charsetValueStart ); if(kNotFound == charsetValueEnd ) @@ -1247,29 +1262,27 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode } } //if - else if(theKey.EqualsIgnoreCase("NAME")) { - const nsString& theValue1=aNode.GetValueAt(0); - if(theValue1.EqualsIgnoreCase("\"CRC\"")) { - const nsString& theKey2=aNode.GetKeyAt(1); - if(theKey2.EqualsIgnoreCase("CONTENT")) { - const nsString& theValue2=aNode.GetValueAt(1); - PRInt32 err=0; - mExpectedCRC32=theValue2.ToInteger(&err); - } //if - } //if - } //else + else +#endif + if(theKey.EqualsIgnoreCase("NAME")) { + const nsString& theValue1=aNode.GetValueAt(0); + if(theValue1.EqualsIgnoreCase("\"CRC\"")) { + const nsString& theKey2=aNode.GetKeyAt(1); + if(theKey2.EqualsIgnoreCase("CONTENT")) { + const nsString& theValue2=aNode.GetValueAt(1); + PRInt32 err=0; + mExpectedCRC32=theValue2.ToInteger(&err); + } //if + } //if + } //else - } //if - }//if - - //XXX Hack until I get the node observer API in place... - //********************************************************** + } //if + }//if if(NS_OK==result) { result=gHTMLElements[aTag].HasSpecialProperty(kDiscardTag) ? 1 : NS_OK; } - PRBool isHeadChild=gHTMLElements[eHTMLTag_head].IsChildOfHead(aTag); //this code is here to make sure the head is closed before we deal diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp index 3c1be67405cd..82d0bde4fdde 100644 --- a/parser/htmlparser/src/nsParser.cpp +++ b/parser/htmlparser/src/nsParser.cpp @@ -121,8 +121,8 @@ public: //static CSharedParserObjects* gSharedParserObjects=0; -nsString nsParser::gHackMetaCharset = ""; -nsString nsParser::gHackMetaCharsetURL = ""; + +//------------------------------------------------------------------------- /********************************************************************************** This class is used as an interface between an external agent (like the DOM) and @@ -161,9 +161,6 @@ public: nsDeque mTags; //will hold a deque of prunichars... }; -//------------------------------------------------------------------- - - CSharedParserObjects& GetSharedObjects() { static CSharedParserObjects gSharedParserObjects; return gSharedParserObjects; @@ -624,31 +621,6 @@ nsresult nsParser::Parse(nsIURL* aURL,nsIStreamObserver* aListener,PRBool aVerif if (rv != NS_OK) return rv; nsAutoString theName(spec); - // XXX temp hack to make parser use UTF-8 as default charset for XML, RDF, XUL - // XXX This should be removed once we have the SetDefaultCharset in the nsIParser interface - nsString last4; - theName.Right(last4, 4); - if(last4.EqualsIgnoreCase(".xul") || last4.EqualsIgnoreCase(".xml") || last4.EqualsIgnoreCase(".rdf") ) - { - if(kCharsetFromDocTypeDefault >= mCharsetSource) { - mCharset = "UTF-8"; - mCharsetSource = kCharsetFromDocTypeDefault; - } - } - - // XXX begin of meta tag charset hack - - if(theName.Equals(nsParser::gHackMetaCharsetURL) && (! nsParser::gHackMetaCharset.Equals(""))) - { - if(kCharsetFromMetaTag > mCharsetSource) { - mCharset = nsParser::gHackMetaCharset; - mCharsetSource = kCharsetFromMetaTag; - } - } - nsParser::gHackMetaCharsetURL = theName; - nsParser::gHackMetaCharset = ""; - // XXX end of meta tag charset hack - CParserContext* pc=new CParserContext(new nsScanner(theName,PR_FALSE, mCharset, mCharsetSource),aKey,aListener); if(pc) { pc->mMultipart=PR_TRUE; @@ -675,20 +647,7 @@ nsresult nsParser::Parse(nsIInputStream& aStream,PRBool aVerifyEnabled, void* aK //ok, time to create our tokenizer and begin the process nsAutoString theUnknownFilename("unknown"); - // XXX begin of meta tag charset hack - if(theUnknownFilename.Equals(nsParser::gHackMetaCharsetURL) && (! nsParser::gHackMetaCharset.Equals(""))) - { - - if(kCharsetFromMetaTag > mCharsetSource) { - mCharset = nsParser::gHackMetaCharset; - mCharsetSource = kCharsetFromMetaTag; - } - } - nsParser::gHackMetaCharsetURL = theUnknownFilename; - nsParser::gHackMetaCharset = ""; - // XXX end of meta tag charset hack - - nsInputStream input(&aStream); + nsInputStream input(&aStream); CParserContext* pc=new CParserContext(new nsScanner(theUnknownFilename, input, mCharset, mCharsetSource,PR_FALSE),aKey,0); if(pc) { PushContext(*pc); @@ -724,27 +683,6 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aCon } #endif - if(aContentType.EqualsIgnoreCase("text/xul") || aContentType.EqualsIgnoreCase("text/xml") || aContentType.EqualsIgnoreCase("text/rdf") ) - { - if(kCharsetFromDocTypeDefault >= mCharsetSource) { - mCharset = "UTF-8"; - mCharsetSource = kCharsetFromDocTypeDefault; - } - } - - // XXX begin of meta tag charset hack - nsAutoString theFakeURL("fromString"); - if(theFakeURL.Equals(nsParser::gHackMetaCharsetURL) && (! nsParser::gHackMetaCharset.Equals(""))) - { - if(kCharsetFromMetaTag > mCharsetSource) { - mCharset = nsParser::gHackMetaCharset; - mCharsetSource = kCharsetFromMetaTag; - } - } - nsParser::gHackMetaCharsetURL = theFakeURL; - nsParser::gHackMetaCharset = ""; - // XXX end of meta tag charset hack - //NOTE: Make sure that updates to this method don't cause // bug #2361 to break again! diff --git a/parser/htmlparser/src/nsParser.h b/parser/htmlparser/src/nsParser.h index 32e5c467545e..2ab56cdf2184 100644 --- a/parser/htmlparser/src/nsParser.h +++ b/parser/htmlparser/src/nsParser.h @@ -137,6 +137,12 @@ friend class CTokenHandler; */ virtual void SetDocumentCharset(nsString& aCharset, nsCharsetSource aSource); + void GetDocumentCharset(nsString& oCharset, nsCharsetSource& oSource) + { + oCharset = mCharset; + oSource = mCharsetSource; + } + virtual nsIParserFilter* SetParserFilter(nsIParserFilter* aFilter); @@ -258,12 +264,6 @@ friend class CTokenHandler; */ virtual nsresult CreateTagStack(nsITagStack** aTagStack); - /* - * The following two should be removed once our Meta Charset work complete - */ - static nsString gHackMetaCharset; - static nsString gHackMetaCharsetURL; - protected: /**