diff --git a/mozilla/htmlparser/src/CParserContext.cpp b/mozilla/htmlparser/src/CParserContext.cpp
index b7d352696f0..2d0f31a2c59 100644
--- a/mozilla/htmlparser/src/CParserContext.cpp
+++ b/mozilla/htmlparser/src/CParserContext.cpp
@@ -61,6 +61,7 @@ CParserContext::CParserContext(nsScanner* aScanner,
mMultipart=PR_TRUE;
mContextType=eCTNone;
mCopyUnused=aCopyUnused;
+ mChannel=0;
}
/**
@@ -95,6 +96,7 @@ CParserContext::CParserContext(const CParserContext &aContext) :
mMultipart=aContext.mMultipart;
mContextType=aContext.mContextType;
mCopyUnused;
+ mChannel=aContext.mChannel;
}
diff --git a/mozilla/htmlparser/src/CParserContext.h b/mozilla/htmlparser/src/CParserContext.h
index 65410eff9fa..aeac0b5f258 100644
--- a/mozilla/htmlparser/src/CParserContext.h
+++ b/mozilla/htmlparser/src/CParserContext.h
@@ -68,7 +68,7 @@ public:
PRBool mMultipart;
eContextType mContextType;
eAutoDetectResult mAutoDetectStatus;
-
+ nsIChannel* mChannel; // provided by necko to differnciate different input streams
nsString mSourceType;
diff --git a/mozilla/htmlparser/src/nsParser.cpp b/mozilla/htmlparser/src/nsParser.cpp
index c275743e6f5..40034d4805b 100644
--- a/mozilla/htmlparser/src/nsParser.cpp
+++ b/mozilla/htmlparser/src/nsParser.cpp
@@ -958,7 +958,7 @@ aContentType,PRBool aVerifyEnabled,PRBool aLastCall,eParseMode aMode){
eAutoDetectResult theStatus=eUnknownDetect;
if(mParserContext && (mParserContext->mSourceType==aContentType)) {
- mParserContext->mDTD->CreateNewInstance(&theDTD); // To fix bug 32263
+ mParserContext->mDTD->CreateNewInstance(&theDTD); // To fix 32263
theStatus=mParserContext->mAutoDetectStatus;
//added this to fix bug 32022.
@@ -1370,6 +1370,7 @@ nsresult nsParser::OnStartRequest(nsIChannel* channel, nsISupports* aContext)
}
mParserContext->mStreamListenerState=eOnStart;
mParserContext->mAutoDetectStatus=eUnknownDetect;
+ mParserContext->mChannel=channel;
mParserContext->mDTD=0;
nsresult rv;
char* contentType = nsnull;
@@ -1377,7 +1378,7 @@ nsresult nsParser::OnStartRequest(nsIChannel* channel, nsISupports* aContext)
if (NS_SUCCEEDED(rv))
{
mParserContext->mSourceType = contentType;
- nsCRT::free(contentType);
+ nsCRT::free(contentType);
}
else
NS_ASSERTION(contentType, "parser needs a content type to find a dtd");
@@ -1500,91 +1501,107 @@ static PRBool detectByteOrderMark(const unsigned char* aBytes, PRInt32 aLen, nsS
* @param length is the number of bytes waiting input
* @return error code (usually 0)
*/
-nsresult nsParser::OnDataAvailable(nsIChannel* channel, nsISupports* aContext,
- nsIInputStream *pIStream, PRUint32 sourceOffset, PRUint32 aLength)
-{
- NS_PRECONDITION(((eOnStart==mParserContext->mStreamListenerState)||(eOnDataAvail==mParserContext->mStreamListenerState)),kOnStartNotCalled);
+nsresult nsParser::OnDataAvailable(nsIChannel* channel, nsISupports* aContext,
+ nsIInputStream *pIStream, PRUint32 sourceOffset, PRUint32 aLength)
+{
- mParserContext->mStreamListenerState=eOnDataAvail;
+
+NS_PRECONDITION(((eOnStart==mParserContext->mStreamListenerState)||(eOnDataAvail==mParserContext->mStreamListenerState)),kOnStartNotCalled);
- if(eInvalidDetect==mParserContext->mAutoDetectStatus) {
- if(mParserContext->mScanner) {
- mParserContext->mScanner->GetBuffer().Truncate();
- }
- }
+ nsresult result=NS_OK;
- PRInt32 newLength=(aLength>mParserContext->mTransferBufferSize) ? aLength : mParserContext->mTransferBufferSize;
- if(!mParserContext->mTransferBuffer) {
- mParserContext->mTransferBufferSize=newLength;
- mParserContext->mTransferBuffer=new char[newLength+20];
- }
- else if(aLength>mParserContext->mTransferBufferSize){
- delete [] mParserContext->mTransferBuffer;
- mParserContext->mTransferBufferSize=newLength;
- mParserContext->mTransferBuffer=new char[newLength+20];
- }
+ CParserContext *theContext=mParserContext;
+
+ while(theContext) {
+ if(theContext->mChannel!=channel && theContext->mPrevContext)
+ theContext=theContext->mPrevContext;
+ else break;
+ }
- nsresult result=NS_OK;
+ if(theContext && theContext->mChannel==channel) {
- if(mParserContext->mTransferBuffer) {
+ theContext->mStreamListenerState=eOnDataAvail;
- //We need to add code to defensively deal with the case where the transfer buffer is null.
+ if(eInvalidDetect==theContext->mAutoDetectStatus) {
+ if(theContext->mScanner) {
+ theContext->mScanner->GetBuffer().Truncate();
+ }
+ }
- PRUint32 theTotalRead=0;
- PRUint32 theNumRead=1; //init to a non-zero value
- int theStartPos=0;
+ PRInt32 newLength=(aLength>theContext->mTransferBufferSize) ? aLength :
+theContext->mTransferBufferSize;
+ if(!theContext->mTransferBuffer) {
+ theContext->mTransferBufferSize=newLength;
+ theContext->mTransferBuffer=new char[newLength+20];
+ }
+ else if(aLength>theContext->mTransferBufferSize){
+ delete [] theContext->mTransferBuffer;
+ theContext->mTransferBufferSize=newLength;
+ theContext->mTransferBuffer=new char[newLength+20];
+ }
- PRBool needCheckFirst4Bytes =
- ((0 == sourceOffset) && (mCharsetSource0) && (aLength>theTotalRead) && (NS_OK==result)) {
- result = pIStream->Read(mParserContext->mTransferBuffer, aLength, &theNumRead);
- if(NS_SUCCEEDED(result) && (theNumRead>0)) {
- if(needCheckFirst4Bytes && (theNumRead >= 4)) {
- nsCharsetSource guessSource;
- nsAutoString guess("");
-
- needCheckFirst4Bytes = PR_FALSE;
- if(detectByteOrderMark((const unsigned char*)mParserContext->mTransferBuffer,
- theNumRead, guess, guessSource))
- {
- #ifdef DEBUG_XMLENCODING
- printf("xmlencoding detect- %s\n", guess.ToNewCString());
- #endif
- this->SetDocumentCharset(guess, guessSource);
- }
- }
- theTotalRead+=theNumRead;
- if(mParserFilter)
- mParserFilter->RawBuffer(mParserContext->mTransferBuffer, &theNumRead);
+ if(theContext->mTransferBuffer) {
- #ifdef NS_DEBUG
- unsigned int index=0;
- for(index=0;indexmTransferBuffer[index]){
- printf("\nNull found at buffer[%i] provided by netlib...\n",index);
- break;
- }
- }
- #endif
+ //We need to add code to defensively deal with the case where the transfer buffer is null.
- mParserContext->mScanner->Append(mParserContext->mTransferBuffer,theNumRead);
+ PRUint32 theTotalRead=0;
+ PRUint32 theNumRead=1; //init to a non-zero value
+ int theStartPos=0;
- #ifdef rickgdebug
- mParserContext->mTransferBuffer[theNumRead]=0;
- mParserContext->mTransferBuffer[theNumRead+1]=0;
- mParserContext->mTransferBuffer[theNumRead+2]=0;
- (*gOutFile) << mParserContext->mTransferBuffer;
- #endif
+ PRBool needCheckFirst4Bytes =
+ ((0 == sourceOffset) && (mCharsetSource0) && (aLength>theTotalRead) && (NS_OK==result)) {
+ result = pIStream->Read(theContext->mTransferBuffer, aLength, &theNumRead);
+ if(NS_SUCCEEDED(result) && (theNumRead>0)) {
+ if(needCheckFirst4Bytes && (theNumRead >= 4)) {
+ nsCharsetSource guessSource;
+ nsAutoString guess("");
+
+ needCheckFirst4Bytes = PR_FALSE;
+ if(detectByteOrderMark((const unsigned char*)theContext->mTransferBuffer,
+ theNumRead, guess, guessSource))
+ {
+ #ifdef DEBUG_XMLENCODING
+ printf("xmlencoding detect- %s\n", guess.ToNewCString());
+ #endif
+ this->SetDocumentCharset(guess, guessSource);
+ }
+ }
+ theTotalRead+=theNumRead;
+ if(mParserFilter)
+ mParserFilter->RawBuffer(theContext->mTransferBuffer, &theNumRead);
- } //if
- theStartPos+=theNumRead;
- }//while
+ #ifdef NS_DEBUG
+ unsigned int index=0;
+ for(index=0;indexmTransferBuffer[index]){
+ printf("\nNull found at buffer[%i] provided by netlib...\n",index);
+ break;
+ }
+ }
+ #endif
- result=ResumeParse();
- }
- return result;
-}
+ theContext->mScanner->Append(theContext->mTransferBuffer,theNumRead);
+
+ #ifdef rickgdebug
+ theContext->mTransferBuffer[theNumRead]=0;
+ theContext->mTransferBuffer[theNumRead+1]=0;
+ theContext->mTransferBuffer[theNumRead+2]=0;
+ cout << theContext->mTransferBuffer;
+ #endif
+
+ } //if
+ theStartPos+=theNumRead;
+ }//while
+
+ result=ResumeParse();
+ } //if
+
+ } //if
+
+ return result;
+}
/**
* This is called by the networking library once the last block of data
diff --git a/mozilla/parser/htmlparser/src/CParserContext.cpp b/mozilla/parser/htmlparser/src/CParserContext.cpp
index b7d352696f0..2d0f31a2c59 100644
--- a/mozilla/parser/htmlparser/src/CParserContext.cpp
+++ b/mozilla/parser/htmlparser/src/CParserContext.cpp
@@ -61,6 +61,7 @@ CParserContext::CParserContext(nsScanner* aScanner,
mMultipart=PR_TRUE;
mContextType=eCTNone;
mCopyUnused=aCopyUnused;
+ mChannel=0;
}
/**
@@ -95,6 +96,7 @@ CParserContext::CParserContext(const CParserContext &aContext) :
mMultipart=aContext.mMultipart;
mContextType=aContext.mContextType;
mCopyUnused;
+ mChannel=aContext.mChannel;
}
diff --git a/mozilla/parser/htmlparser/src/CParserContext.h b/mozilla/parser/htmlparser/src/CParserContext.h
index 65410eff9fa..aeac0b5f258 100644
--- a/mozilla/parser/htmlparser/src/CParserContext.h
+++ b/mozilla/parser/htmlparser/src/CParserContext.h
@@ -68,7 +68,7 @@ public:
PRBool mMultipart;
eContextType mContextType;
eAutoDetectResult mAutoDetectStatus;
-
+ nsIChannel* mChannel; // provided by necko to differnciate different input streams
nsString mSourceType;
diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp
index c275743e6f5..40034d4805b 100644
--- a/mozilla/parser/htmlparser/src/nsParser.cpp
+++ b/mozilla/parser/htmlparser/src/nsParser.cpp
@@ -958,7 +958,7 @@ aContentType,PRBool aVerifyEnabled,PRBool aLastCall,eParseMode aMode){
eAutoDetectResult theStatus=eUnknownDetect;
if(mParserContext && (mParserContext->mSourceType==aContentType)) {
- mParserContext->mDTD->CreateNewInstance(&theDTD); // To fix bug 32263
+ mParserContext->mDTD->CreateNewInstance(&theDTD); // To fix 32263
theStatus=mParserContext->mAutoDetectStatus;
//added this to fix bug 32022.
@@ -1370,6 +1370,7 @@ nsresult nsParser::OnStartRequest(nsIChannel* channel, nsISupports* aContext)
}
mParserContext->mStreamListenerState=eOnStart;
mParserContext->mAutoDetectStatus=eUnknownDetect;
+ mParserContext->mChannel=channel;
mParserContext->mDTD=0;
nsresult rv;
char* contentType = nsnull;
@@ -1377,7 +1378,7 @@ nsresult nsParser::OnStartRequest(nsIChannel* channel, nsISupports* aContext)
if (NS_SUCCEEDED(rv))
{
mParserContext->mSourceType = contentType;
- nsCRT::free(contentType);
+ nsCRT::free(contentType);
}
else
NS_ASSERTION(contentType, "parser needs a content type to find a dtd");
@@ -1500,91 +1501,107 @@ static PRBool detectByteOrderMark(const unsigned char* aBytes, PRInt32 aLen, nsS
* @param length is the number of bytes waiting input
* @return error code (usually 0)
*/
-nsresult nsParser::OnDataAvailable(nsIChannel* channel, nsISupports* aContext,
- nsIInputStream *pIStream, PRUint32 sourceOffset, PRUint32 aLength)
-{
- NS_PRECONDITION(((eOnStart==mParserContext->mStreamListenerState)||(eOnDataAvail==mParserContext->mStreamListenerState)),kOnStartNotCalled);
+nsresult nsParser::OnDataAvailable(nsIChannel* channel, nsISupports* aContext,
+ nsIInputStream *pIStream, PRUint32 sourceOffset, PRUint32 aLength)
+{
- mParserContext->mStreamListenerState=eOnDataAvail;
+
+NS_PRECONDITION(((eOnStart==mParserContext->mStreamListenerState)||(eOnDataAvail==mParserContext->mStreamListenerState)),kOnStartNotCalled);
- if(eInvalidDetect==mParserContext->mAutoDetectStatus) {
- if(mParserContext->mScanner) {
- mParserContext->mScanner->GetBuffer().Truncate();
- }
- }
+ nsresult result=NS_OK;
- PRInt32 newLength=(aLength>mParserContext->mTransferBufferSize) ? aLength : mParserContext->mTransferBufferSize;
- if(!mParserContext->mTransferBuffer) {
- mParserContext->mTransferBufferSize=newLength;
- mParserContext->mTransferBuffer=new char[newLength+20];
- }
- else if(aLength>mParserContext->mTransferBufferSize){
- delete [] mParserContext->mTransferBuffer;
- mParserContext->mTransferBufferSize=newLength;
- mParserContext->mTransferBuffer=new char[newLength+20];
- }
+ CParserContext *theContext=mParserContext;
+
+ while(theContext) {
+ if(theContext->mChannel!=channel && theContext->mPrevContext)
+ theContext=theContext->mPrevContext;
+ else break;
+ }
- nsresult result=NS_OK;
+ if(theContext && theContext->mChannel==channel) {
- if(mParserContext->mTransferBuffer) {
+ theContext->mStreamListenerState=eOnDataAvail;
- //We need to add code to defensively deal with the case where the transfer buffer is null.
+ if(eInvalidDetect==theContext->mAutoDetectStatus) {
+ if(theContext->mScanner) {
+ theContext->mScanner->GetBuffer().Truncate();
+ }
+ }
- PRUint32 theTotalRead=0;
- PRUint32 theNumRead=1; //init to a non-zero value
- int theStartPos=0;
+ PRInt32 newLength=(aLength>theContext->mTransferBufferSize) ? aLength :
+theContext->mTransferBufferSize;
+ if(!theContext->mTransferBuffer) {
+ theContext->mTransferBufferSize=newLength;
+ theContext->mTransferBuffer=new char[newLength+20];
+ }
+ else if(aLength>theContext->mTransferBufferSize){
+ delete [] theContext->mTransferBuffer;
+ theContext->mTransferBufferSize=newLength;
+ theContext->mTransferBuffer=new char[newLength+20];
+ }
- PRBool needCheckFirst4Bytes =
- ((0 == sourceOffset) && (mCharsetSource0) && (aLength>theTotalRead) && (NS_OK==result)) {
- result = pIStream->Read(mParserContext->mTransferBuffer, aLength, &theNumRead);
- if(NS_SUCCEEDED(result) && (theNumRead>0)) {
- if(needCheckFirst4Bytes && (theNumRead >= 4)) {
- nsCharsetSource guessSource;
- nsAutoString guess("");
-
- needCheckFirst4Bytes = PR_FALSE;
- if(detectByteOrderMark((const unsigned char*)mParserContext->mTransferBuffer,
- theNumRead, guess, guessSource))
- {
- #ifdef DEBUG_XMLENCODING
- printf("xmlencoding detect- %s\n", guess.ToNewCString());
- #endif
- this->SetDocumentCharset(guess, guessSource);
- }
- }
- theTotalRead+=theNumRead;
- if(mParserFilter)
- mParserFilter->RawBuffer(mParserContext->mTransferBuffer, &theNumRead);
+ if(theContext->mTransferBuffer) {
- #ifdef NS_DEBUG
- unsigned int index=0;
- for(index=0;indexmTransferBuffer[index]){
- printf("\nNull found at buffer[%i] provided by netlib...\n",index);
- break;
- }
- }
- #endif
+ //We need to add code to defensively deal with the case where the transfer buffer is null.
- mParserContext->mScanner->Append(mParserContext->mTransferBuffer,theNumRead);
+ PRUint32 theTotalRead=0;
+ PRUint32 theNumRead=1; //init to a non-zero value
+ int theStartPos=0;
- #ifdef rickgdebug
- mParserContext->mTransferBuffer[theNumRead]=0;
- mParserContext->mTransferBuffer[theNumRead+1]=0;
- mParserContext->mTransferBuffer[theNumRead+2]=0;
- (*gOutFile) << mParserContext->mTransferBuffer;
- #endif
+ PRBool needCheckFirst4Bytes =
+ ((0 == sourceOffset) && (mCharsetSource0) && (aLength>theTotalRead) && (NS_OK==result)) {
+ result = pIStream->Read(theContext->mTransferBuffer, aLength, &theNumRead);
+ if(NS_SUCCEEDED(result) && (theNumRead>0)) {
+ if(needCheckFirst4Bytes && (theNumRead >= 4)) {
+ nsCharsetSource guessSource;
+ nsAutoString guess("");
+
+ needCheckFirst4Bytes = PR_FALSE;
+ if(detectByteOrderMark((const unsigned char*)theContext->mTransferBuffer,
+ theNumRead, guess, guessSource))
+ {
+ #ifdef DEBUG_XMLENCODING
+ printf("xmlencoding detect- %s\n", guess.ToNewCString());
+ #endif
+ this->SetDocumentCharset(guess, guessSource);
+ }
+ }
+ theTotalRead+=theNumRead;
+ if(mParserFilter)
+ mParserFilter->RawBuffer(theContext->mTransferBuffer, &theNumRead);
- } //if
- theStartPos+=theNumRead;
- }//while
+ #ifdef NS_DEBUG
+ unsigned int index=0;
+ for(index=0;indexmTransferBuffer[index]){
+ printf("\nNull found at buffer[%i] provided by netlib...\n",index);
+ break;
+ }
+ }
+ #endif
- result=ResumeParse();
- }
- return result;
-}
+ theContext->mScanner->Append(theContext->mTransferBuffer,theNumRead);
+
+ #ifdef rickgdebug
+ theContext->mTransferBuffer[theNumRead]=0;
+ theContext->mTransferBuffer[theNumRead+1]=0;
+ theContext->mTransferBuffer[theNumRead+2]=0;
+ cout << theContext->mTransferBuffer;
+ #endif
+
+ } //if
+ theStartPos+=theNumRead;
+ }//while
+
+ result=ResumeParse();
+ } //if
+
+ } //if
+
+ return result;
+}
/**
* This is called by the networking library once the last block of data