зеркало из https://github.com/mozilla/pjs.git
assertions for bug 1375 and better autodetection code
This commit is contained in:
Родитель
eea3dd8ded
Коммит
86d66b8198
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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((-1<temp.Find("<html") || (-1<temp.Find("!doctype html public \"-//w3c//dtd html")))) {
|
||||
result=PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//#define _dynstack 1
|
||||
class nsTagStack {
|
||||
enum {eStackSize=200};
|
||||
|
|
|
@ -43,6 +43,9 @@ static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
|
|||
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
||||
|
||||
static const char* kNullURL = "Error: Null URL given";
|
||||
static const char* kOnStartNotCalled = "Error: OnStartBinding() must be called before OnDataAvailable()";
|
||||
static const char* kOnStopNotCalled = "Error: OnStopBinding() must be called upon termination of netlib process";
|
||||
static const char* kBadListenerInit = "Error: Parser's IStreamListener API was not setup correctly in constructor.";
|
||||
static nsString kUnknownFilename("unknown");
|
||||
static nsString kEmptyString("unknown");
|
||||
|
||||
|
@ -185,6 +188,7 @@ MakeConversionTable()
|
|||
*/
|
||||
nsParser::nsParser() : mCommand() {
|
||||
NS_INIT_REFCNT();
|
||||
mStreamListenerState=eNone;
|
||||
mParserFilter = 0;
|
||||
mObserver = 0;
|
||||
mSink=0;
|
||||
|
@ -205,6 +209,7 @@ nsParser::~nsParser() {
|
|||
NS_IF_RELEASE(mObserver);
|
||||
NS_RELEASE(mSink);
|
||||
|
||||
NS_POSTCONDITION(eOnStop==mStreamListenerState,kOnStopNotCalled);
|
||||
//don't forget to add code here to delete
|
||||
//what may be several contexts...
|
||||
delete mParserContext;
|
||||
|
@ -409,10 +414,12 @@ eAutoDetectResult nsParser::AutoDetectContentType(nsString& aBuffer,nsString& aT
|
|||
nsDequeIterator e=gSharedParserObjects.mDTDDeque.End();
|
||||
|
||||
mParserContext->mAutoDetectStatus=eUnknownDetect;
|
||||
while((b<e) && (eUnknownDetect==mParserContext->mAutoDetectStatus)){
|
||||
while(b<e){
|
||||
nsIDTD* theDTD=(nsIDTD*)b.GetCurrent();
|
||||
if(theDTD) {
|
||||
mParserContext->mAutoDetectStatus=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);
|
||||
|
|
|
@ -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.
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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((-1<temp.Find("<html") || (-1<temp.Find("!doctype html public \"-//w3c//dtd html")))) {
|
||||
result=PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//#define _dynstack 1
|
||||
class nsTagStack {
|
||||
enum {eStackSize=200};
|
||||
|
|
|
@ -43,6 +43,9 @@ static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
|
|||
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
||||
|
||||
static const char* kNullURL = "Error: Null URL given";
|
||||
static const char* kOnStartNotCalled = "Error: OnStartBinding() must be called before OnDataAvailable()";
|
||||
static const char* kOnStopNotCalled = "Error: OnStopBinding() must be called upon termination of netlib process";
|
||||
static const char* kBadListenerInit = "Error: Parser's IStreamListener API was not setup correctly in constructor.";
|
||||
static nsString kUnknownFilename("unknown");
|
||||
static nsString kEmptyString("unknown");
|
||||
|
||||
|
@ -185,6 +188,7 @@ MakeConversionTable()
|
|||
*/
|
||||
nsParser::nsParser() : mCommand() {
|
||||
NS_INIT_REFCNT();
|
||||
mStreamListenerState=eNone;
|
||||
mParserFilter = 0;
|
||||
mObserver = 0;
|
||||
mSink=0;
|
||||
|
@ -205,6 +209,7 @@ nsParser::~nsParser() {
|
|||
NS_IF_RELEASE(mObserver);
|
||||
NS_RELEASE(mSink);
|
||||
|
||||
NS_POSTCONDITION(eOnStop==mStreamListenerState,kOnStopNotCalled);
|
||||
//don't forget to add code here to delete
|
||||
//what may be several contexts...
|
||||
delete mParserContext;
|
||||
|
@ -409,10 +414,12 @@ eAutoDetectResult nsParser::AutoDetectContentType(nsString& aBuffer,nsString& aT
|
|||
nsDequeIterator e=gSharedParserObjects.mDTDDeque.End();
|
||||
|
||||
mParserContext->mAutoDetectStatus=eUnknownDetect;
|
||||
while((b<e) && (eUnknownDetect==mParserContext->mAutoDetectStatus)){
|
||||
while(b<e){
|
||||
nsIDTD* theDTD=(nsIDTD*)b.GetCurrent();
|
||||
if(theDTD) {
|
||||
mParserContext->mAutoDetectStatus=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);
|
||||
|
|
|
@ -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.
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче