#112793 fine tune frame charset mechanism

Besides charset, document now records charset source as well.
nsCharsetSource was replaced by PRInt32.
Some code relocation in nsHTMLDocument.cpp
r=yokoyama sr=waterson


git-svn-id: svn://10.0.0.236/trunk@111062 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
shanjian%netscape.com
2001-12-26 03:17:59 +00:00
parent 46c1c88486
commit 3356940ad2
35 changed files with 507 additions and 332 deletions

View File

@@ -92,22 +92,23 @@ enum eParserDocType {
};
typedef enum {
kCharsetUninitialized = 0,
kCharsetFromWeakDocTypeDefault,
kCharsetFromUserDefault ,
kCharsetFromDocTypeDefault,
kCharsetFromCache,
kCharsetFromParentFrame,
kCharsetFromBookmarks,
kCharsetFromAutoDetection,
kCharsetFromMetaTag,
kCharsetFromByteOrderMark,
kCharsetFromHTTPHeader,
kCharsetFromUserForced,
kCharsetFromOtherComponent,
kCharsetFromPreviousLoading
} nsCharsetSource;
// define Charset source constants
// note: the value order define the priority
#define kCharsetUninitialized 0
#define kCharsetFromWeakDocTypeDefault 1
#define kCharsetFromUserDefault 2
#define kCharsetFromDocTypeDefault 3
#define kCharsetFromCache 4
#define kCharsetFromParentFrame 5
#define kCharsetFromBookmarks 6
#define kCharsetFromAutoDetection 7
#define kCharsetFromMetaTag 8
#define kCharsetFromByteOrderMark 9
#define kCharsetFromHTTPHeader 10
#define kCharsetFromParentForced 11
#define kCharsetFromUserForced 12
#define kCharsetFromOtherComponent 13
#define kCharsetFromPreviousLoading 14
enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
@@ -186,8 +187,8 @@ class nsIParser : public nsISupports {
* @param aCharsetSource- the soure of the chares
* @return nada
*/
virtual void SetDocumentCharset(nsString& aCharset, nsCharsetSource aSource)=0;
virtual void GetDocumentCharset(nsString& oCharset, nsCharsetSource& oSource)=0;
virtual void SetDocumentCharset(nsString& aCharset, PRInt32 aSource)=0;
virtual void GetDocumentCharset(nsString& oCharset, PRInt32& oSource)=0;
virtual nsIParserFilter* SetParserFilter(nsIParserFilter* aFilter) = 0;

View File

@@ -1517,7 +1517,7 @@ nsObserverEntry::Notify(nsIParserNode* aNode,
nsVoidArray* theObservers = mObservers[theTag];
if (theObservers) {
nsAutoString theCharsetValue;
nsCharsetSource theCharsetSource;
PRInt32 theCharsetSource;
aParser->GetDocumentCharset(theCharsetValue,theCharsetSource);
PRInt32 theAttrCount = aNode->GetAttributeCount();

View File

@@ -501,7 +501,7 @@ void nsParser::SetCommand(eParserCommands aParserCommand){
* @param aCharsetSource- the soure of the chares
* @return nada
*/
void nsParser::SetDocumentCharset(nsString& aCharset, nsCharsetSource aCharsetSource){
void nsParser::SetDocumentCharset(nsString& aCharset, PRInt32 aCharsetSource){
mCharset = aCharset;
mCharsetSource = aCharsetSource;
if(mParserContext && mParserContext->mScanner)
@@ -2062,7 +2062,7 @@ nsresult nsParser::OnStartRequest(nsIRequest *request, nsISupports* aContext) {
#define UCS4_3412 "X-ISO-10646-UCS-4-3412"
#define UTF8 "UTF-8"
static PRBool DetectByteOrderMark(const unsigned char* aBytes, PRInt32 aLen, nsString& oCharset, nsCharsetSource& oCharsetSource) {
static PRBool DetectByteOrderMark(const unsigned char* aBytes, PRInt32 aLen, nsString& oCharset, PRInt32& oCharsetSource) {
oCharsetSource= kCharsetFromAutoDetection;
oCharset.Truncate();
// See http://www.w3.org/TR/2000/REC-xml-20001006#sec-guessing
@@ -2229,7 +2229,7 @@ PRBool
nsParser::DetectMetaTag(const char* aBytes,
PRInt32 aLen,
nsString& aCharset,
nsCharsetSource& aCharsetSource)
PRInt32& aCharsetSource)
{
PRBool foundContentType = PR_FALSE;
aCharsetSource= kCharsetFromMetaTag;
@@ -2358,7 +2358,7 @@ ParserWriteFunc(nsIInputStream* in,
}
if(pws->mNeedCharsetCheck) {
nsCharsetSource guessSource;
PRInt32 guessSource;
nsAutoString guess, preferred;
pws->mNeedCharsetCheck = PR_FALSE;

View File

@@ -160,9 +160,9 @@ class nsParser : public nsIParser,
* @param aCharsetSource- the soure of the chares
* @return nada
*/
virtual void SetDocumentCharset(nsString& aCharset, nsCharsetSource aSource);
virtual void SetDocumentCharset(nsString& aCharset, PRInt32 aSource);
void GetDocumentCharset(nsString& oCharset, nsCharsetSource& oSource)
void GetDocumentCharset(nsString& oCharset, PRInt32& oSource)
{
oCharset = mCharset;
oSource = mCharsetSource;
@@ -338,7 +338,7 @@ class nsParser : public nsIParser,
PRBool DetectMetaTag(const char* aBytes,
PRInt32 aLen,
nsString& oCharset,
nsCharsetSource& oCharsetSource);
PRInt32& oCharsetSource);
void SetSinkCharset(nsAWritableString& aCharset);
@@ -466,7 +466,7 @@ protected:
nsITokenObserver* mTokenObserver;
nsString mUnusedInput;
nsString mCharset;
nsCharsetSource mCharsetSource;
PRInt32 mCharsetSource;
nsresult mInternalState;
PRBool mObserversEnabled;
nsString mCommandStr;

View File

@@ -105,7 +105,7 @@ MOZ_DECL_CTOR_COUNTER(nsScanner)
* @param aMode represents the parser mode (nav, other)
* @return
*/
nsScanner::nsScanner(nsString& anHTMLString, const nsString& aCharset, nsCharsetSource aSource)
nsScanner::nsScanner(nsString& anHTMLString, const nsString& aCharset, PRInt32 aSource)
{
MOZ_COUNT_CTOR(nsScanner);
@@ -134,7 +134,7 @@ nsScanner::nsScanner(nsString& anHTMLString, const nsString& aCharset, nsCharset
* @param aFilename --
* @return
*/
nsScanner::nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& aCharset, nsCharsetSource aSource) :
nsScanner::nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& aCharset, PRInt32 aSource) :
mFilename(aFilename)
{
MOZ_COUNT_CTOR(nsScanner);
@@ -163,7 +163,7 @@ nsScanner::nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& a
* @param aFilename --
* @return
*/
nsScanner::nsScanner(nsString& aFilename,nsInputStream& aStream,const nsString& aCharset, nsCharsetSource aSource) :
nsScanner::nsScanner(nsString& aFilename,nsInputStream& aStream,const nsString& aCharset, PRInt32 aSource) :
mFilename(aFilename)
{
MOZ_COUNT_CTOR(nsScanner);
@@ -181,7 +181,7 @@ nsScanner::nsScanner(nsString& aFilename,nsInputStream& aStream,const nsString&
}
nsresult nsScanner::SetDocumentCharset(const nsString& aCharset , nsCharsetSource aSource) {
nsresult nsScanner::SetDocumentCharset(const nsString& aCharset , PRInt32 aSource) {
nsresult res = NS_OK;

View File

@@ -94,7 +94,7 @@ class nsScanner {
* @param aMode represents the parser mode (nav, other)
* @return
*/
nsScanner(nsString& anHTMLString, const nsString& aCharset, nsCharsetSource aSource);
nsScanner(nsString& anHTMLString, const nsString& aCharset, PRInt32 aSource);
/**
* Use this constructor if you want i/o to be based on
@@ -106,7 +106,7 @@ class nsScanner {
* @param aMode represents the parser mode (nav, other)
* @return
*/
nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& aCharset, nsCharsetSource aSource);
nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& aCharset, PRInt32 aSource);
/**
* Use this constructor if you want i/o to be stream based.
@@ -117,7 +117,7 @@ class nsScanner {
* @param aMode represents the parser mode (nav, other)
* @return
*/
nsScanner(nsString& aFilename, nsInputStream& aStream, const nsString& aCharset, nsCharsetSource aSource);
nsScanner(nsString& aFilename, nsInputStream& aStream, const nsString& aCharset, PRInt32 aSource);
~nsScanner();
@@ -343,7 +343,7 @@ class nsScanner {
* @param aCharsetSource- where the charset info came from
* @return
*/
nsresult SetDocumentCharset(const nsString& aCharset, nsCharsetSource aSource);
nsresult SetDocumentCharset(const nsString& aCharset, PRInt32 aSource);
void BindSubstring(nsSlidingSubstring& aSubstring, const nsReadingIterator<PRUnichar>& aStart, const nsReadingIterator<PRUnichar>& aEnd);
void CurrentPosition(nsReadingIterator<PRUnichar>& aPosition);
@@ -393,7 +393,7 @@ class nsScanner {
PRUint32 mTotalRead;
PRBool mOwnsStream;
PRBool mIncremental;
nsCharsetSource mCharsetSource;
PRInt32 mCharsetSource;
nsString mCharset;
nsIUnicodeDecoder *mUnicodeDecoder;
PRInt32 mNewlinesSkipped;