diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp
index a2458e86a7b..e8520df7d5f 100644
--- a/htmlparser/src/CNavDTD.cpp
+++ b/htmlparser/src/CNavDTD.cpp
@@ -423,6 +423,14 @@ eAutoDetectResult CNavDTD::AutoDetectContentType(nsString& aBuffer,nsString& aTy
eAutoDetectResult result=eUnknownDetect;
if(PR_TRUE==aType.Equals(kHTMLTextContentType))
result=eValidDetect;
+ else {
+ //otherwise, look into the buffer to see if you recognize anything...
+ if(BufferContainsHTML(aBuffer)){
+ result=eValidDetect;
+ if(0==aType.Length())
+ aType=kHTMLTextContentType;
+ }
+ }
return result;
}
diff --git a/htmlparser/src/nsDTDUtils.h b/htmlparser/src/nsDTDUtils.h
index 07c2b879c1b..6ca2b34cd58 100644
--- a/htmlparser/src/nsDTDUtils.h
+++ b/htmlparser/src/nsDTDUtils.h
@@ -64,6 +64,24 @@ inline PRBool FindTagInSet(PRInt32 aTag,const eHTMLTags aTagSet[],PRInt32 aCount
}
+/**
+ * Called from various DTD's to determine the type of data in the buffer...
+ * @update gess11/20/98
+ * @param
+ * @return
+ */
+inline PRBool BufferContainsHTML(nsString& aBuffer){
+ PRBool result=PR_FALSE;
+ nsString temp;
+ aBuffer.Left(temp,200);
+ temp.ToLowerCase();
+ if((-1mAutoDetectStatus=eUnknownDetect;
- while((bmAutoDetectStatus)){
+ while(bmAutoDetectStatus=theDTD->AutoDetectContentType(aBuffer,aType);
+ if(eValidDetect==mParserContext->mAutoDetectStatus)
+ break;
}
b++;
}
@@ -820,9 +827,12 @@ nsParser::OnStatus(nsIURL* aURL, const nsString &aMsg)
* @return error code -- 0 if ok, non-zero if error.
*/
nsresult nsParser::OnStartBinding(nsIURL* aURL, const char *aSourceType){
+ NS_PRECONDITION((eNone==mStreamListenerState),kBadListenerInit);
+
if (nsnull != mObserver) {
mObserver->OnStartBinding(aURL, aSourceType);
}
+ mStreamListenerState=eOnStart;
mParserContext->mAutoDetectStatus=eUnknownDetect;
mParserContext->mDTD=0;
mParserContext->mSourceType=aSourceType;
@@ -844,7 +854,9 @@ nsresult nsParser::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRInt
mListener->OnDataAvailable(pIStream, length);
}
*/
+ NS_PRECONDITION(((eOnStart==mStreamListenerState)||(eOnDataAvail==mStreamListenerState)),kOnStartNotCalled);
+ mStreamListenerState=eOnDataAvail;
if(eInvalidDetect==mParserContext->mAutoDetectStatus) {
if(mParserContext->mScanner) {
mParserContext->mScanner->GetBuffer().Truncate();
@@ -902,6 +914,7 @@ nsresult nsParser::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRInt
* @return
*/
nsresult nsParser::OnStopBinding(nsIURL* aURL, PRInt32 status, const nsString& aMsg){
+ mStreamListenerState=eOnStop;
nsresult result=DidBuildModel(status);
if (nsnull != mObserver) {
mObserver->OnStopBinding(aURL, status, aMsg);
diff --git a/htmlparser/src/nsParser.h b/htmlparser/src/nsParser.h
index 3e152fe1645..bf491af9bba 100644
--- a/htmlparser/src/nsParser.h
+++ b/htmlparser/src/nsParser.h
@@ -297,8 +297,9 @@ protected:
//*********************************************
// And now, some data members...
//*********************************************
-
-
+
+ enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
+
CParserContext* mParserContext;
PRInt32 mMajorIteration;
PRInt32 mMinorIteration;
@@ -309,6 +310,7 @@ protected:
PRBool mDTDVerification;
PRBool mParserEnabled;
nsString mCommand;
+ eStreamState mStreamListenerState; //this is really only here for debug purposes.
};
diff --git a/htmlparser/src/nsViewSourceHTML.cpp b/htmlparser/src/nsViewSourceHTML.cpp
index 3a76eec60ed..da7a01f85b6 100644
--- a/htmlparser/src/nsViewSourceHTML.cpp
+++ b/htmlparser/src/nsViewSourceHTML.cpp
@@ -227,10 +227,10 @@ PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRI
/**
- *
- * @update gess7/7/98
+ * This is called to ask the DTD if it recognizes either the aType or data in the buffer.
+ * @update gess7/7/98
* @param
- * @return
+ * @return detect result
*/
eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsString& aType){
eAutoDetectResult result=eUnknownDetect;
@@ -238,9 +238,18 @@ eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsStr
result=eValidDetect;
else if(PR_TRUE==aType.Equals(kXMLTextContentType))
result=eValidDetect;
+ else {
+ //otherwise, look into the buffer to see if you recognize anything...
+ if(BufferContainsHTML(aBuffer)){
+ result=eValidDetect;
+ if(0==aType.Length())
+ aType=kHTMLTextContentType;
+ }
+ }
return result;
}
+
/**
*
* @update gess5/18/98
diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp
index a2458e86a7b..e8520df7d5f 100644
--- a/parser/htmlparser/src/CNavDTD.cpp
+++ b/parser/htmlparser/src/CNavDTD.cpp
@@ -423,6 +423,14 @@ eAutoDetectResult CNavDTD::AutoDetectContentType(nsString& aBuffer,nsString& aTy
eAutoDetectResult result=eUnknownDetect;
if(PR_TRUE==aType.Equals(kHTMLTextContentType))
result=eValidDetect;
+ else {
+ //otherwise, look into the buffer to see if you recognize anything...
+ if(BufferContainsHTML(aBuffer)){
+ result=eValidDetect;
+ if(0==aType.Length())
+ aType=kHTMLTextContentType;
+ }
+ }
return result;
}
diff --git a/parser/htmlparser/src/nsDTDUtils.h b/parser/htmlparser/src/nsDTDUtils.h
index 07c2b879c1b..6ca2b34cd58 100644
--- a/parser/htmlparser/src/nsDTDUtils.h
+++ b/parser/htmlparser/src/nsDTDUtils.h
@@ -64,6 +64,24 @@ inline PRBool FindTagInSet(PRInt32 aTag,const eHTMLTags aTagSet[],PRInt32 aCount
}
+/**
+ * Called from various DTD's to determine the type of data in the buffer...
+ * @update gess11/20/98
+ * @param
+ * @return
+ */
+inline PRBool BufferContainsHTML(nsString& aBuffer){
+ PRBool result=PR_FALSE;
+ nsString temp;
+ aBuffer.Left(temp,200);
+ temp.ToLowerCase();
+ if((-1mAutoDetectStatus=eUnknownDetect;
- while((bmAutoDetectStatus)){
+ while(bmAutoDetectStatus=theDTD->AutoDetectContentType(aBuffer,aType);
+ if(eValidDetect==mParserContext->mAutoDetectStatus)
+ break;
}
b++;
}
@@ -820,9 +827,12 @@ nsParser::OnStatus(nsIURL* aURL, const nsString &aMsg)
* @return error code -- 0 if ok, non-zero if error.
*/
nsresult nsParser::OnStartBinding(nsIURL* aURL, const char *aSourceType){
+ NS_PRECONDITION((eNone==mStreamListenerState),kBadListenerInit);
+
if (nsnull != mObserver) {
mObserver->OnStartBinding(aURL, aSourceType);
}
+ mStreamListenerState=eOnStart;
mParserContext->mAutoDetectStatus=eUnknownDetect;
mParserContext->mDTD=0;
mParserContext->mSourceType=aSourceType;
@@ -844,7 +854,9 @@ nsresult nsParser::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRInt
mListener->OnDataAvailable(pIStream, length);
}
*/
+ NS_PRECONDITION(((eOnStart==mStreamListenerState)||(eOnDataAvail==mStreamListenerState)),kOnStartNotCalled);
+ mStreamListenerState=eOnDataAvail;
if(eInvalidDetect==mParserContext->mAutoDetectStatus) {
if(mParserContext->mScanner) {
mParserContext->mScanner->GetBuffer().Truncate();
@@ -902,6 +914,7 @@ nsresult nsParser::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRInt
* @return
*/
nsresult nsParser::OnStopBinding(nsIURL* aURL, PRInt32 status, const nsString& aMsg){
+ mStreamListenerState=eOnStop;
nsresult result=DidBuildModel(status);
if (nsnull != mObserver) {
mObserver->OnStopBinding(aURL, status, aMsg);
diff --git a/parser/htmlparser/src/nsParser.h b/parser/htmlparser/src/nsParser.h
index 3e152fe1645..bf491af9bba 100644
--- a/parser/htmlparser/src/nsParser.h
+++ b/parser/htmlparser/src/nsParser.h
@@ -297,8 +297,9 @@ protected:
//*********************************************
// And now, some data members...
//*********************************************
-
-
+
+ enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
+
CParserContext* mParserContext;
PRInt32 mMajorIteration;
PRInt32 mMinorIteration;
@@ -309,6 +310,7 @@ protected:
PRBool mDTDVerification;
PRBool mParserEnabled;
nsString mCommand;
+ eStreamState mStreamListenerState; //this is really only here for debug purposes.
};
diff --git a/parser/htmlparser/src/nsViewSourceHTML.cpp b/parser/htmlparser/src/nsViewSourceHTML.cpp
index 3a76eec60ed..da7a01f85b6 100644
--- a/parser/htmlparser/src/nsViewSourceHTML.cpp
+++ b/parser/htmlparser/src/nsViewSourceHTML.cpp
@@ -227,10 +227,10 @@ PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRI
/**
- *
- * @update gess7/7/98
+ * This is called to ask the DTD if it recognizes either the aType or data in the buffer.
+ * @update gess7/7/98
* @param
- * @return
+ * @return detect result
*/
eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsString& aType){
eAutoDetectResult result=eUnknownDetect;
@@ -238,9 +238,18 @@ eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsStr
result=eValidDetect;
else if(PR_TRUE==aType.Equals(kXMLTextContentType))
result=eValidDetect;
+ else {
+ //otherwise, look into the buffer to see if you recognize anything...
+ if(BufferContainsHTML(aBuffer)){
+ result=eValidDetect;
+ if(0==aType.Length())
+ aType=kHTMLTextContentType;
+ }
+ }
return result;
}
+
/**
*
* @update gess5/18/98