fixed a wad of little bugs and added regression test

This commit is contained in:
rickg%netscape.com 1999-02-16 07:38:27 +00:00
Родитель de5fffb57b
Коммит 359e6e5567
40 изменённых файлов: 486 добавлений и 184 удалений

Просмотреть файл

@ -1456,7 +1456,7 @@ HTMLContentSink::DidBuildModel(PRInt32 aQualityLevel)
mHTMLDocument->SetTitle("");
}
// XXX this is silly; who cares?
// XXX this is silly; who cares? RickG cares. It's part of the regression test. So don't bug me.
PRInt32 i, ns = mDocument->GetNumberOfShells();
for (i = 0; i < ns; i++) {
nsCOMPtr<nsIPresShell> shell(dont_AddRef(mDocument->GetShellAt(i)));

Просмотреть файл

@ -1283,7 +1283,7 @@ nsHTMLDocument::Close()
nsAutoString emptyStr("</HTML>");
mWriteLevel++;
result = mParser->Parse(emptyStr, NS_GENERATE_PARSER_KEY(),
PR_TRUE, PR_FALSE, PR_TRUE);
"text/html", PR_FALSE, PR_TRUE);
mWriteLevel--;
mIsWriting = 0;
}
@ -1325,7 +1325,7 @@ nsHTMLDocument::WriteCommon(JSContext *cx,
mWriteLevel++;
result = mParser->Parse(str, NS_GENERATE_PARSER_KEY(),
PR_TRUE, PR_FALSE,
"text/html", PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
mWriteLevel--;
if (NS_OK != result) {

Просмотреть файл

@ -52,7 +52,6 @@ static NS_DEFINE_IID(kClassIID, NS_INAVHTML_DTD_IID);
//static const char* kNullFilename= "Error: Null filename given";
static const char* kNullToken = "Error: Null token given";
static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kHTMLTextContentType = "text/html";
static char* kVerificationDir = "c:/temp";
static const char* kViewSourceCommand= "view-source";
@ -130,12 +129,13 @@ public:
the DTD. Uses a factory pattern
***************************************************************/
class CTagHandlerRegister {
public:
CTagHandlerRegister() : mDeallocator(), mTagHandlerDeque(mDeallocator) {
}
~CTagHandlerRegister() {
}
void RegisterTagHandler(nsITagHandler *aTagHandler){
mTagHandlerDeque.Push(aTagHandler);
@ -162,7 +162,7 @@ public:
Note: This can also be attached to some object so it can be refcounted
and destroyed if you want this to go away when not imbedded.
************************************************************************/
CTagHandlerRegister gTagHandlerRegister;
//CTagHandlerRegister gTagHandlerRegister;
/************************************************************************
@ -357,6 +357,11 @@ CNavDTD::CNavDTD() : nsIDTD(){
mMapContext=0;
mTokenizer=0;
#ifndef NS_DEBUG
mComputedCRC32=0;
mExpectedCRC32=0;
#endif
// DebugDumpContainmentRules2(*this,"c:/temp/DTDRules.new","New CNavDTD Containment Rules");
}
@ -435,7 +440,9 @@ PRBool CNavDTD::Verify(nsString& aURLRef,nsIParser* aParser){
PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
PRBool result=PR_FALSE;
if(!aCommand.Equals(kViewSourceCommand)) {
result=aContentType.Equals(kHTMLTextContentType);
if(PR_TRUE==aContentType.Equals(kHTMLTextContentType) || PR_TRUE==aContentType.Equals(kPlainTextContentType)) {
result=PR_TRUE;
}
}
return result;
}
@ -448,8 +455,11 @@ PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVe
*/
eAutoDetectResult CNavDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
eAutoDetectResult result=eUnknownDetect;
if(PR_TRUE==aType.Equals(kHTMLTextContentType))
if(PR_TRUE==aType.Equals(kHTMLTextContentType) ||
PR_TRUE==aType.Equals(kPlainTextContentType)) {
result=eValidDetect;
}
else {
//otherwise, look into the buffer to see if you recognize anything...
if(BufferContainsHTML(aBuffer)){
@ -479,6 +489,12 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParse
if((aNotifySink) && (mSink)) {
result = mSink->WillBuildModel();
}
#ifdef NS_DEBUG
mComputedCRC32=0;
mExpectedCRC32=0;
#endif
}
return result;
}
@ -544,6 +560,15 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse
result = mSink->DidBuildModel(1);
#ifdef DEBUG
if(mComputedCRC32!=mExpectedCRC32) {
if(mExpectedCRC32!=0) {
printf("Expected CRC: %u,",mExpectedCRC32);
}
printf("Computed CRC: %u.\n",mComputedCRC32);
}
#endif
if(mDTDDebug) {
mDTDDebug->DumpVectorRecord();
}
@ -559,7 +584,6 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse
* moved over to the delegate. Ah, so much to do...
*
* @update gess 5/21/98
* @param aType
* @param aToken
* @param aParser
* @return
@ -899,6 +923,7 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI
* It's a generic hook to let us do pre processing.
* @param aToken contains the tag in question
* @param aChildTag is the tag itself.
* @param aNode is the node (tag) with associated attributes.
* @return TRUE if tag processing should continue; FALSE if the tag has been handled.
*/
nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode& aNode){
@ -910,6 +935,44 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode
result=CollectSkippedContent(aNode,theAttrCount);
}
//**********************************************************
//XXX Hack until I get the node observer API in place...
if(eHTMLTag_meta==aTag) {
PRInt32 theCount=aNode.GetAttributeCount();
if(1<theCount){
//<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-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);
theScanner->SetDocumentCharset(theValue);
} //if
}
}
#ifdef DEBUG
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
} //if
}//if
#endif
//XXX Hack until I get the node observer API in place...
//**********************************************************
if(NS_OK==result) {
result=!gHTMLElements[aTag].HasSpecialProperty(kDiscardTag);
}
@ -972,7 +1035,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
// ahead and close the tag out anyway, since its
// contents will be consumed.
if (NS_SUCCEEDED(result)) {
nsresult rv = CloseHead(attrNode);
nsresult rv=CloseHead(attrNode);
// XXX Only send along a failure. If the close
// succeeded we still may need to indicate that the
// parser has blocked (i.e. return the result of
@ -2192,6 +2255,7 @@ nsresult CNavDTD::CloseFrameset(const nsIParserNode& aNode){
}
/**
* This method does two things: 1st, help construct
* our own internal model of the content-stack; and
@ -2207,6 +2271,12 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){
nsresult result=NS_OK;
eHTMLTags nodeType=(eHTMLTags)aNode.GetNodeType();
#ifdef NS_DEBUG
#define K_OPENOP 100
CRCStruct theStruct(nodeType,K_OPENOP);
mComputedCRC32=AccumulateCRC(mComputedCRC32,(char*)&theStruct,sizeof(theStruct));
#endif
switch(nodeType) {
case eHTMLTag_html:
@ -2288,8 +2358,12 @@ CNavDTD::CloseContainer(const nsIParserNode& aNode,eHTMLTags aTag,
nsresult result=NS_OK;
eHTMLTags nodeType=(eHTMLTags)aNode.GetNodeType();
//XXX Hack! We know this is wrong, but it works
//for the general case until we get it right.
#ifdef NS_DEBUG
#define K_CLOSEOP 200
CRCStruct theStruct(nodeType,K_CLOSEOP);
mComputedCRC32=AccumulateCRC(mComputedCRC32,(char*)&theStruct,sizeof(theStruct));
#endif
switch(nodeType) {
case eHTMLTag_html:

Просмотреть файл

@ -538,6 +538,10 @@ protected:
PRInt32 mLineNumber;
nsParser* mParser;
nsITokenizer* mTokenizer;
#ifdef NS_DEBUG
PRUint32 mComputedCRC32;
PRUint32 mExpectedCRC32;
#endif
};
extern NS_HTMLPARS nsresult NS_NewNavHTMLDTD(nsIDTD** aInstancePtrResult);

Просмотреть файл

@ -63,7 +63,6 @@ static NS_DEFINE_IID(kBaseClassIID, NS_INAVHTML_DTD_IID);
//static const char* kNullTokenizer = "Error: Unable to construct tokenizer";
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
//static const char* kHTMLTextContentType = "text/html";
static nsAutoString gEmpty;

Просмотреть файл

@ -279,7 +279,10 @@ CTokenRecycler::~CTokenRecycler() {
//We're also deleting the cache-deques themselves.
int i;
for(i=0;i<eToken_last-1;i++) {
if(0!=mTokenCache[i]) {
delete mTokenCache[i];
mTokenCache[i]=0;
}
}
}
@ -383,3 +386,47 @@ void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char*
}
/*************************************************************************
* The table lookup technique was adapted from the algorithm described *
* by Avram Perez, Byte-wise CRC Calculations, IEEE Micro 3, 40 (1983). *
*************************************************************************/
#define POLYNOMIAL 0x04c11db7L
static PRUint32 crc_table[256];
void gen_crc_table() {
/* generate the table of CRC remainders for all possible bytes */
int i, j;
PRUint32 crc_accum;
for ( i = 0; i < 256; i++ ) {
crc_accum = ( (unsigned long) i << 24 );
for ( j = 0; j < 8; j++ ) {
if ( crc_accum & 0x80000000L )
crc_accum = ( crc_accum << 1 ) ^ POLYNOMIAL;
else crc_accum = ( crc_accum << 1 );
}
crc_table[i] = crc_accum;
}
return;
}
class CRCInitializer {
public:
CRCInitializer() {
gen_crc_table();
}
};
CRCInitializer gCRCInitializer;
PRUint32 AccumulateCRC(PRUint32 crc_accum, char *data_blk_ptr, int data_blk_size) {
/* update the CRC on the data block one byte at a time */
int i, j;
for ( j = 0; j < data_blk_size; j++ ) {
i = ( (int) ( crc_accum >> 24) ^ *data_blk_ptr++ ) & 0xff;
crc_accum = ( crc_accum << 8 ) ^ crc_table[i];
}
return crc_accum;
}

Просмотреть файл

@ -52,6 +52,7 @@
void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* aTitle);
void DebugDumpContainmentRules2(nsIDTD& theDTD,const char* aFilename,const char* aTitle);
PRUint32 AccumulateCRC(PRUint32 crc_accum, char *data_blk_ptr, int data_blk_size);
class nsTagStack {
@ -206,12 +207,26 @@ inline PRBool BufferContainsHTML(nsString& aBuffer){
nsString temp;
aBuffer.Left(temp,200);
temp.ToLowerCase();
if((-1<temp.Find("<html") || (-1<temp.Find("!doctype html public \"-//w3c//dtd html")))) {
if((-1<temp.Find("<html ") || (-1<temp.Find("!doctype html public")))) {
result=PR_TRUE;
}
return result;
}
#ifdef NS_DEBUG
/******************************************************************************
This little structure is used to compute CRC32 values for our debug validator
******************************************************************************/
struct CRCStruct {
CRCStruct(eHTMLTags aTag,PRInt32 anOp) {mTag=aTag; mOperation=anOp;}
eHTMLTags mTag;
PRInt32 mOperation; //usually open or close
};
#endif
#endif

Просмотреть файл

@ -218,6 +218,7 @@ CTagList gCaptionAutoClose(1,0,eHTMLTag_tbody);
CTagList gLIAutoClose(2,0,eHTMLTag_p,eHTMLTag_li);
CTagList gPAutoClose(2,0,eHTMLTag_p,eHTMLTag_li);
CTagList gOLAutoClose(3,0,eHTMLTag_p,eHTMLTag_ol,eHTMLTag_ul);
CTagList gDivAutoClose(1,0,eHTMLTag_p);
static eHTMLTags gHxList[]={eHTMLTag_h1,eHTMLTag_h2,eHTMLTag_h3,eHTMLTag_h4,eHTMLTag_h5,eHTMLTag_h6};
CTagList gHxAutoClose(sizeof(gHxList)/sizeof(eHTMLTag_unknown),gHxList);
@ -322,14 +323,14 @@ nsHTMLElement gHTMLElements[] = {
{ /*tag*/ eHTMLTag_big,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,
/*parent,incl,exclgroups*/ (kFontStyle|kPreformatted), (kFlow|kSelf), kNone,
/*parent,incl,exclgroups*/ kFontStyle, (kFlow|kSelf), kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_blink,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,
/*parent,incl,exclgroups*/ (kFontStyle|kPreformatted), (kFlow|kSelf), kNone,
/*parent,incl,exclgroups*/ kFontStyle, (kFlow|kSelf), kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
@ -433,7 +434,7 @@ nsHTMLElement gHTMLElements[] = {
{ /*tag*/ eHTMLTag_div,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,
/*autoclose starttags and endtags*/ &gDivAutoClose,0,0,
/*parent,incl,exclgroups*/ kBlock, (kSelf|kFlow), kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
@ -505,42 +506,42 @@ nsHTMLElement gHTMLElements[] = {
{ /*tag*/ eHTMLTag_h1,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_h2,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_h3,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_h4,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_h5,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_h6,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
@ -589,7 +590,7 @@ nsHTMLElement gHTMLElements[] = {
{ /*tag*/ eHTMLTag_img,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,
/*parent,incl,exclgroups*/ kSpecial, kNone, kNone,
/*parent,incl,exclgroups*/ kFlow, kNone, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
@ -764,7 +765,7 @@ nsHTMLElement gHTMLElements[] = {
{ /*tag*/ eHTMLTag_p,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,
/*parent,incl,exclgroups*/ kBlock, kInline, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,&gInP,eHTMLTag_unknown},

Просмотреть файл

@ -677,6 +677,7 @@ nsresult ConsumeStrictComment(PRUnichar aChar, nsScanner& aScanner,nsString& aSt
* @return
*/
nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) {
static nsAutoString gEdibles("!-");
static nsAutoString gMinus("-");
nsresult result=NS_OK;
@ -699,14 +700,16 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString)
PRBool done=PR_FALSE;
PRInt32 findpos=kNotFound;
result=aScanner.ReadWhile(aString,gMinus,PR_TRUE,PR_TRUE); //get all available '---'
findpos=aString.RFind("->");
findpos=aString.RFind("-->");
nsAutoString temp("");
while((kNotFound==findpos) && (NS_OK==result)) {
result=aScanner.ReadUntil(temp,kMinus,PR_TRUE);
if(NS_OK==result) {
result=aScanner.ReadWhile(temp,gMinus,PR_TRUE,PR_TRUE); //get all available '---'
result=aScanner.ReadWhile(temp,gEdibles,PR_TRUE,PR_TRUE); //get all available '---'
}
findpos=temp.RFind("->");
findpos=temp.RFind("-->");
if(kNotFound==findpos)
findpos=temp.RFind("!>");
aString+=temp;
temp="";
} //while
@ -964,7 +967,8 @@ nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScann
PRUnichar ch=aString.Last();
if(ch!=aChar)
aString+=aChar;
aString.StripChars("\r\n");
aString.ReplaceChar(PRUnichar('\n'),PRUnichar(' '));
aString.StripChars("\r"); //per the HTML spec, ignore linefeeds...
return result;
}

Просмотреть файл

@ -59,6 +59,12 @@ enum eParseMode {
eParseMode_autodetect
};
enum eCRCQuality {
eCRCGood = 0,
eCRCFair,
eCRCPoor
};
enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
/**
@ -128,7 +134,7 @@ class nsIParser : public nsISupports {
virtual PRBool EnableParser(PRBool aState) = 0;
virtual nsresult Parse(nsIURL* aURL,nsIStreamObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE) = 0;
virtual nsresult Parse(fstream& aStream,PRBool aEnableVerify=PR_FALSE) = 0;
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify,PRBool aLastCall) = 0;
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall) = 0;
/**
* This method gets called when the tokens have been consumed, and it's time
@ -167,6 +173,7 @@ class nsIParser : public nsISupports {
#define NS_ERROR_HTMLPARSER_INTERRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1007)
#define NS_ERROR_HTMLPARSER_BADTOKENIZER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1008)
#define NS_ERROR_HTMLPARSER_BADATTRIBUTE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1009)
#define NS_ERROR_HTMLPARSER_UNRESOLVEDDTD NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1010)
/**
* Return codes for parsing routines.
@ -221,4 +228,11 @@ const PRUint32 kLeftSquareBracket = '[';
const PRUint32 kRightSquareBracket = ']';
const PRUnichar kNullCh = '\0';
#define kHTMLTextContentType "text/html"
#define kXMLTextContentType "text/xml"
#define kXULTextContentType "text/xul"
#define kRDFTextContentType "text/rdf"
#define kXIFTextContentType "text/xif"
#define kPlainTextContentType "text/plain"
#endif

Просмотреть файл

@ -92,13 +92,12 @@ class CSharedParserObjects {
public:
CSharedParserObjects() : mDeallocator(), mDTDDeque(mDeallocator) {
/*
NS_NewWellFormed_DTD(&theDTD);
RegisterDTD(theDTD);
*/
nsIDTD* theDTD;
NS_NewWellFormed_DTD(&theDTD);
RegisterDTD(theDTD);
NS_NewNavHTMLDTD(&theDTD); //do this as the default HTML DTD...
mDTDDeque.Push(theDTD);
@ -608,7 +607,7 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){
CParserContext* pc=new CParserContext(new nsScanner(kUnknownFilename,aStream,PR_FALSE),&aStream,0);
if(pc) {
PushContext(*pc);
pc->mSourceType="text/html";
pc->mSourceType=kHTMLTextContentType;
pc->mStreamListenerState=eOnStart;
pc->mMultipart=PR_FALSE;
pc->mContextType=CParserContext::eCTStream;
@ -628,10 +627,10 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){
*
* @update gess5/11/98
* @param aSourceBuffer contains a string-full of real content
* @param anHTMLString tells us whether we should assume the content is HTML (usually true)
* @param aContentType tells us what type of content to expect in the given string
* @return error code -- 0 if ok, non-zero if error.
*/
nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify,PRBool aLastCall){
nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall){
#ifdef _rickgdebug
{
@ -659,10 +658,7 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,
PushContext(*pc);
pc->mStreamListenerState=eOnStart;
pc->mContextType=CParserContext::eCTString;
if(PR_TRUE==anHTMLString)
pc->mSourceType="text/html";
else
pc->mSourceType="text/xml"; // XXX rick is a fish
pc->mSourceType=aContentType;
}
else {
NS_RELEASE(me);
@ -702,7 +698,7 @@ nsresult nsParser::ResumeParse(nsIDTD* aDefaultDTD) {
nsresult result=NS_OK;
if(mParserContext->mParserEnabled) {
result=WillBuildModel(mParserContext->mScanner->GetFilename(),aDefaultDTD);
if (mParserContext->mDTD) {
if(mParserContext->mDTD) {
mParserContext->mDTD->WillResumeParse();
if(NS_OK==result) {
@ -725,6 +721,7 @@ nsresult nsParser::ResumeParse(nsIDTD* aDefaultDTD) {
}//if
}//if
}//if
else result=NS_ERROR_HTMLPARSER_UNRESOLVEDDTD;
}//if
return result;
}

Просмотреть файл

@ -166,7 +166,7 @@ friend class CTokenHandler;
* @param appendTokens tells us whether we should insert tokens inline, or append them.
* @return TRUE if all went well -- FALSE otherwise
*/
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE);
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE);
/**

Просмотреть файл

@ -119,7 +119,8 @@ void nsScanner::InitUnicodeDecoder()
nsAutoString defaultCharset("ISO-8859-1");
SetDocumentCharset(defaultCharset);
}
nsresult nsScanner::SetDocumentCharset(nsString& aCharset )
nsresult nsScanner::SetDocumentCharset(const nsString& aCharset )
{
nsresult res = NS_OK;
if(! mCharset.EqualsIgnoreCase(aCharset)) // see do we need to change a converter.
@ -372,7 +373,7 @@ nsresult nsScanner::PutBack(PRUnichar aChar) {
* @return error status
*/
nsresult nsScanner::SkipWhitespace(void) {
static nsAutoString chars(" \n\r\t");
static nsAutoString chars(" \n\r\t\b");
return SkipOver(chars);
}

Просмотреть файл

@ -269,7 +269,7 @@ class nsScanner {
/**
* Change the charset and the Unicode Decoder
*/
nsresult SetDocumentCharset(nsString& aCharset);
nsresult SetDocumentCharset(const nsString& aCharset);
protected:

Просмотреть файл

@ -60,7 +60,6 @@ static NS_DEFINE_IID(kClassIID, NS_VALID_DTD_IID);
//static const char* kNullTokenizer = "Error: Unable to construct tokenizer";
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kXMLTextContentType = "text/xml";
static nsAutoString gEmpty;

Просмотреть файл

@ -57,8 +57,6 @@ static NS_DEFINE_IID(kClassIID, NS_VIEWSOURCE_HTML_IID);
//static const char* kNullTokenizer = "Error: Unable to construct tokenizer";
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kHTMLTextContentType = "text/html";
static const char* kXMLTextContentType = "text/xml";
static const char* kViewSourceCommand= "view-source";
static nsAutoString gEmpty;
@ -230,9 +228,13 @@ nsresult CViewSourceHTML::CreateNewInstance(nsIDTD** aInstancePtrResult){
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
*/
PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
PRBool result=(aContentType.Equals(kHTMLTextContentType) && (aCommand.Equals(kViewSourceCommand)));
if(!result) {
result=(aContentType.Equals(kXMLTextContentType) && (aCommand.Equals(kViewSourceCommand)));
PRBool result=PR_FALSE;
if(aCommand.Equals(kViewSourceCommand)) {
result=(aContentType.Equals(kXMLTextContentType) ||
aContentType.Equals(kRDFTextContentType) ||
aContentType.Equals(kHTMLTextContentType) ||
aContentType.Equals(kPlainTextContentType) ||
aContentType.Equals(kXULTextContentType));
}
return result;
}
@ -240,24 +242,15 @@ PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRI
/**
* This is called to ask the DTD if it recognizes either the aType or data in the buffer.
* We intentionally say NO to autodetect types so that XML and HTML dtds can do the right thing.
* If either of those DTD's say YES, then we'll agree and render either.
*
* @update gess7/7/98
* @param
* @return detect result
*/
eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsString& aType){
eAutoDetectResult result=eUnknownDetect;
if(PR_TRUE==aType.Equals(kHTMLTextContentType))
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;
}

Просмотреть файл

@ -57,9 +57,6 @@ static NS_DEFINE_IID(kClassIID, NS_WELLFORMED_DTD_IID);
//static const char* kNullTokenizer = "Error: Unable to construct tokenizer";
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kXMLTextContentType = "text/xml";
static const char* kRDFTextContentType = "text/rdf";
static const char* kXULTextContentType = "text/xul";
static const char* kViewSourceCommand= "view-source";
static nsAutoString gEmpty;
@ -203,8 +200,15 @@ eAutoDetectResult CWellFormedDTD::AutoDetectContentType(nsString& aBuffer,nsStri
eAutoDetectResult result=eUnknownDetect;
if(PR_TRUE==aType.Equals(kXMLTextContentType) ||
PR_TRUE==aType.Equals(kRDFTextContentType) ||
PR_TRUE==aType.Equals(kXULTextContentType))
PR_TRUE==aType.Equals(kXULTextContentType)) {
result=eValidDetect;
}
else {
if(-1<aBuffer.Find("<?xml ")) {
aType = kXMLTextContentType;
result=eValidDetect;
}
}
return result;
}

Просмотреть файл

@ -42,7 +42,6 @@ static NS_DEFINE_IID(kClassIID, NS_XIF_DTD_IID);
static const char* kNullToken = "Error: Null token given";
static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kXIFTextContentType = "text/xif";
static const char* kXIFDocHeader= "<!DOCTYPE xif>";
static nsAutoString gEmpty;

Просмотреть файл

@ -1456,7 +1456,7 @@ HTMLContentSink::DidBuildModel(PRInt32 aQualityLevel)
mHTMLDocument->SetTitle("");
}
// XXX this is silly; who cares?
// XXX this is silly; who cares? RickG cares. It's part of the regression test. So don't bug me.
PRInt32 i, ns = mDocument->GetNumberOfShells();
for (i = 0; i < ns; i++) {
nsCOMPtr<nsIPresShell> shell(dont_AddRef(mDocument->GetShellAt(i)));

Просмотреть файл

@ -1283,7 +1283,7 @@ nsHTMLDocument::Close()
nsAutoString emptyStr("</HTML>");
mWriteLevel++;
result = mParser->Parse(emptyStr, NS_GENERATE_PARSER_KEY(),
PR_TRUE, PR_FALSE, PR_TRUE);
"text/html", PR_FALSE, PR_TRUE);
mWriteLevel--;
mIsWriting = 0;
}
@ -1325,7 +1325,7 @@ nsHTMLDocument::WriteCommon(JSContext *cx,
mWriteLevel++;
result = mParser->Parse(str, NS_GENERATE_PARSER_KEY(),
PR_TRUE, PR_FALSE,
"text/html", PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
mWriteLevel--;
if (NS_OK != result) {

Просмотреть файл

@ -52,7 +52,6 @@ static NS_DEFINE_IID(kClassIID, NS_INAVHTML_DTD_IID);
//static const char* kNullFilename= "Error: Null filename given";
static const char* kNullToken = "Error: Null token given";
static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kHTMLTextContentType = "text/html";
static char* kVerificationDir = "c:/temp";
static const char* kViewSourceCommand= "view-source";
@ -130,12 +129,13 @@ public:
the DTD. Uses a factory pattern
***************************************************************/
class CTagHandlerRegister {
public:
CTagHandlerRegister() : mDeallocator(), mTagHandlerDeque(mDeallocator) {
}
~CTagHandlerRegister() {
}
void RegisterTagHandler(nsITagHandler *aTagHandler){
mTagHandlerDeque.Push(aTagHandler);
@ -162,7 +162,7 @@ public:
Note: This can also be attached to some object so it can be refcounted
and destroyed if you want this to go away when not imbedded.
************************************************************************/
CTagHandlerRegister gTagHandlerRegister;
//CTagHandlerRegister gTagHandlerRegister;
/************************************************************************
@ -357,6 +357,11 @@ CNavDTD::CNavDTD() : nsIDTD(){
mMapContext=0;
mTokenizer=0;
#ifndef NS_DEBUG
mComputedCRC32=0;
mExpectedCRC32=0;
#endif
// DebugDumpContainmentRules2(*this,"c:/temp/DTDRules.new","New CNavDTD Containment Rules");
}
@ -435,7 +440,9 @@ PRBool CNavDTD::Verify(nsString& aURLRef,nsIParser* aParser){
PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
PRBool result=PR_FALSE;
if(!aCommand.Equals(kViewSourceCommand)) {
result=aContentType.Equals(kHTMLTextContentType);
if(PR_TRUE==aContentType.Equals(kHTMLTextContentType) || PR_TRUE==aContentType.Equals(kPlainTextContentType)) {
result=PR_TRUE;
}
}
return result;
}
@ -448,8 +455,11 @@ PRBool CNavDTD::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVe
*/
eAutoDetectResult CNavDTD::AutoDetectContentType(nsString& aBuffer,nsString& aType){
eAutoDetectResult result=eUnknownDetect;
if(PR_TRUE==aType.Equals(kHTMLTextContentType))
if(PR_TRUE==aType.Equals(kHTMLTextContentType) ||
PR_TRUE==aType.Equals(kPlainTextContentType)) {
result=eValidDetect;
}
else {
//otherwise, look into the buffer to see if you recognize anything...
if(BufferContainsHTML(aBuffer)){
@ -479,6 +489,12 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParse
if((aNotifySink) && (mSink)) {
result = mSink->WillBuildModel();
}
#ifdef NS_DEBUG
mComputedCRC32=0;
mExpectedCRC32=0;
#endif
}
return result;
}
@ -544,6 +560,15 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse
result = mSink->DidBuildModel(1);
#ifdef DEBUG
if(mComputedCRC32!=mExpectedCRC32) {
if(mExpectedCRC32!=0) {
printf("Expected CRC: %u,",mExpectedCRC32);
}
printf("Computed CRC: %u.\n",mComputedCRC32);
}
#endif
if(mDTDDebug) {
mDTDDebug->DumpVectorRecord();
}
@ -559,7 +584,6 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse
* moved over to the delegate. Ah, so much to do...
*
* @update gess 5/21/98
* @param aType
* @param aToken
* @param aParser
* @return
@ -899,6 +923,7 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI
* It's a generic hook to let us do pre processing.
* @param aToken contains the tag in question
* @param aChildTag is the tag itself.
* @param aNode is the node (tag) with associated attributes.
* @return TRUE if tag processing should continue; FALSE if the tag has been handled.
*/
nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode& aNode){
@ -910,6 +935,44 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode
result=CollectSkippedContent(aNode,theAttrCount);
}
//**********************************************************
//XXX Hack until I get the node observer API in place...
if(eHTMLTag_meta==aTag) {
PRInt32 theCount=aNode.GetAttributeCount();
if(1<theCount){
//<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-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);
theScanner->SetDocumentCharset(theValue);
} //if
}
}
#ifdef DEBUG
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
} //if
}//if
#endif
//XXX Hack until I get the node observer API in place...
//**********************************************************
if(NS_OK==result) {
result=!gHTMLElements[aTag].HasSpecialProperty(kDiscardTag);
}
@ -972,7 +1035,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
// ahead and close the tag out anyway, since its
// contents will be consumed.
if (NS_SUCCEEDED(result)) {
nsresult rv = CloseHead(attrNode);
nsresult rv=CloseHead(attrNode);
// XXX Only send along a failure. If the close
// succeeded we still may need to indicate that the
// parser has blocked (i.e. return the result of
@ -2192,6 +2255,7 @@ nsresult CNavDTD::CloseFrameset(const nsIParserNode& aNode){
}
/**
* This method does two things: 1st, help construct
* our own internal model of the content-stack; and
@ -2207,6 +2271,12 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){
nsresult result=NS_OK;
eHTMLTags nodeType=(eHTMLTags)aNode.GetNodeType();
#ifdef NS_DEBUG
#define K_OPENOP 100
CRCStruct theStruct(nodeType,K_OPENOP);
mComputedCRC32=AccumulateCRC(mComputedCRC32,(char*)&theStruct,sizeof(theStruct));
#endif
switch(nodeType) {
case eHTMLTag_html:
@ -2288,8 +2358,12 @@ CNavDTD::CloseContainer(const nsIParserNode& aNode,eHTMLTags aTag,
nsresult result=NS_OK;
eHTMLTags nodeType=(eHTMLTags)aNode.GetNodeType();
//XXX Hack! We know this is wrong, but it works
//for the general case until we get it right.
#ifdef NS_DEBUG
#define K_CLOSEOP 200
CRCStruct theStruct(nodeType,K_CLOSEOP);
mComputedCRC32=AccumulateCRC(mComputedCRC32,(char*)&theStruct,sizeof(theStruct));
#endif
switch(nodeType) {
case eHTMLTag_html:

Просмотреть файл

@ -538,6 +538,10 @@ protected:
PRInt32 mLineNumber;
nsParser* mParser;
nsITokenizer* mTokenizer;
#ifdef NS_DEBUG
PRUint32 mComputedCRC32;
PRUint32 mExpectedCRC32;
#endif
};
extern NS_HTMLPARS nsresult NS_NewNavHTMLDTD(nsIDTD** aInstancePtrResult);

Просмотреть файл

@ -63,7 +63,6 @@ static NS_DEFINE_IID(kBaseClassIID, NS_INAVHTML_DTD_IID);
//static const char* kNullTokenizer = "Error: Unable to construct tokenizer";
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
//static const char* kHTMLTextContentType = "text/html";
static nsAutoString gEmpty;

Просмотреть файл

@ -279,7 +279,10 @@ CTokenRecycler::~CTokenRecycler() {
//We're also deleting the cache-deques themselves.
int i;
for(i=0;i<eToken_last-1;i++) {
if(0!=mTokenCache[i]) {
delete mTokenCache[i];
mTokenCache[i]=0;
}
}
}
@ -383,3 +386,47 @@ void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char*
}
/*************************************************************************
* The table lookup technique was adapted from the algorithm described *
* by Avram Perez, Byte-wise CRC Calculations, IEEE Micro 3, 40 (1983). *
*************************************************************************/
#define POLYNOMIAL 0x04c11db7L
static PRUint32 crc_table[256];
void gen_crc_table() {
/* generate the table of CRC remainders for all possible bytes */
int i, j;
PRUint32 crc_accum;
for ( i = 0; i < 256; i++ ) {
crc_accum = ( (unsigned long) i << 24 );
for ( j = 0; j < 8; j++ ) {
if ( crc_accum & 0x80000000L )
crc_accum = ( crc_accum << 1 ) ^ POLYNOMIAL;
else crc_accum = ( crc_accum << 1 );
}
crc_table[i] = crc_accum;
}
return;
}
class CRCInitializer {
public:
CRCInitializer() {
gen_crc_table();
}
};
CRCInitializer gCRCInitializer;
PRUint32 AccumulateCRC(PRUint32 crc_accum, char *data_blk_ptr, int data_blk_size) {
/* update the CRC on the data block one byte at a time */
int i, j;
for ( j = 0; j < data_blk_size; j++ ) {
i = ( (int) ( crc_accum >> 24) ^ *data_blk_ptr++ ) & 0xff;
crc_accum = ( crc_accum << 8 ) ^ crc_table[i];
}
return crc_accum;
}

Просмотреть файл

@ -52,6 +52,7 @@
void DebugDumpContainmentRules(nsIDTD& theDTD,const char* aFilename,const char* aTitle);
void DebugDumpContainmentRules2(nsIDTD& theDTD,const char* aFilename,const char* aTitle);
PRUint32 AccumulateCRC(PRUint32 crc_accum, char *data_blk_ptr, int data_blk_size);
class nsTagStack {
@ -206,12 +207,26 @@ inline PRBool BufferContainsHTML(nsString& aBuffer){
nsString temp;
aBuffer.Left(temp,200);
temp.ToLowerCase();
if((-1<temp.Find("<html") || (-1<temp.Find("!doctype html public \"-//w3c//dtd html")))) {
if((-1<temp.Find("<html ") || (-1<temp.Find("!doctype html public")))) {
result=PR_TRUE;
}
return result;
}
#ifdef NS_DEBUG
/******************************************************************************
This little structure is used to compute CRC32 values for our debug validator
******************************************************************************/
struct CRCStruct {
CRCStruct(eHTMLTags aTag,PRInt32 anOp) {mTag=aTag; mOperation=anOp;}
eHTMLTags mTag;
PRInt32 mOperation; //usually open or close
};
#endif
#endif

Просмотреть файл

@ -218,6 +218,7 @@ CTagList gCaptionAutoClose(1,0,eHTMLTag_tbody);
CTagList gLIAutoClose(2,0,eHTMLTag_p,eHTMLTag_li);
CTagList gPAutoClose(2,0,eHTMLTag_p,eHTMLTag_li);
CTagList gOLAutoClose(3,0,eHTMLTag_p,eHTMLTag_ol,eHTMLTag_ul);
CTagList gDivAutoClose(1,0,eHTMLTag_p);
static eHTMLTags gHxList[]={eHTMLTag_h1,eHTMLTag_h2,eHTMLTag_h3,eHTMLTag_h4,eHTMLTag_h5,eHTMLTag_h6};
CTagList gHxAutoClose(sizeof(gHxList)/sizeof(eHTMLTag_unknown),gHxList);
@ -322,14 +323,14 @@ nsHTMLElement gHTMLElements[] = {
{ /*tag*/ eHTMLTag_big,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,
/*parent,incl,exclgroups*/ (kFontStyle|kPreformatted), (kFlow|kSelf), kNone,
/*parent,incl,exclgroups*/ kFontStyle, (kFlow|kSelf), kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_blink,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,
/*parent,incl,exclgroups*/ (kFontStyle|kPreformatted), (kFlow|kSelf), kNone,
/*parent,incl,exclgroups*/ kFontStyle, (kFlow|kSelf), kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
@ -433,7 +434,7 @@ nsHTMLElement gHTMLElements[] = {
{ /*tag*/ eHTMLTag_div,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,
/*autoclose starttags and endtags*/ &gDivAutoClose,0,0,
/*parent,incl,exclgroups*/ kBlock, (kSelf|kFlow), kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
@ -505,42 +506,42 @@ nsHTMLElement gHTMLElements[] = {
{ /*tag*/ eHTMLTag_h1,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_h2,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_h3,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_h4,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_h5,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
{ /*tag*/ eHTMLTag_h6,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ &gHxAutoClose, &gHxAutoClose, &gHxAutoClose,
/*parent,incl,exclgroups*/ kBlock, kBlock, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
@ -589,7 +590,7 @@ nsHTMLElement gHTMLElements[] = {
{ /*tag*/ eHTMLTag_img,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,
/*parent,incl,exclgroups*/ kSpecial, kNone, kNone,
/*parent,incl,exclgroups*/ kFlow, kNone, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown},
@ -764,7 +765,7 @@ nsHTMLElement gHTMLElements[] = {
{ /*tag*/ eHTMLTag_p,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,
/*parent,incl,exclgroups*/ kBlock, kInline, kNone,
/*parent,incl,exclgroups*/ kBlock, kFlow, kNone,
/*special properties*/ 0,
/*special parents,kids,skip*/ 0,&gInP,eHTMLTag_unknown},

Просмотреть файл

@ -677,6 +677,7 @@ nsresult ConsumeStrictComment(PRUnichar aChar, nsScanner& aScanner,nsString& aSt
* @return
*/
nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) {
static nsAutoString gEdibles("!-");
static nsAutoString gMinus("-");
nsresult result=NS_OK;
@ -699,14 +700,16 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString)
PRBool done=PR_FALSE;
PRInt32 findpos=kNotFound;
result=aScanner.ReadWhile(aString,gMinus,PR_TRUE,PR_TRUE); //get all available '---'
findpos=aString.RFind("->");
findpos=aString.RFind("-->");
nsAutoString temp("");
while((kNotFound==findpos) && (NS_OK==result)) {
result=aScanner.ReadUntil(temp,kMinus,PR_TRUE);
if(NS_OK==result) {
result=aScanner.ReadWhile(temp,gMinus,PR_TRUE,PR_TRUE); //get all available '---'
result=aScanner.ReadWhile(temp,gEdibles,PR_TRUE,PR_TRUE); //get all available '---'
}
findpos=temp.RFind("->");
findpos=temp.RFind("-->");
if(kNotFound==findpos)
findpos=temp.RFind("!>");
aString+=temp;
temp="";
} //while
@ -964,7 +967,8 @@ nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScann
PRUnichar ch=aString.Last();
if(ch!=aChar)
aString+=aChar;
aString.StripChars("\r\n");
aString.ReplaceChar(PRUnichar('\n'),PRUnichar(' '));
aString.StripChars("\r"); //per the HTML spec, ignore linefeeds...
return result;
}

Просмотреть файл

@ -59,6 +59,12 @@ enum eParseMode {
eParseMode_autodetect
};
enum eCRCQuality {
eCRCGood = 0,
eCRCFair,
eCRCPoor
};
enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
/**
@ -128,7 +134,7 @@ class nsIParser : public nsISupports {
virtual PRBool EnableParser(PRBool aState) = 0;
virtual nsresult Parse(nsIURL* aURL,nsIStreamObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE) = 0;
virtual nsresult Parse(fstream& aStream,PRBool aEnableVerify=PR_FALSE) = 0;
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify,PRBool aLastCall) = 0;
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall) = 0;
/**
* This method gets called when the tokens have been consumed, and it's time
@ -167,6 +173,7 @@ class nsIParser : public nsISupports {
#define NS_ERROR_HTMLPARSER_INTERRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1007)
#define NS_ERROR_HTMLPARSER_BADTOKENIZER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1008)
#define NS_ERROR_HTMLPARSER_BADATTRIBUTE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1009)
#define NS_ERROR_HTMLPARSER_UNRESOLVEDDTD NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1010)
/**
* Return codes for parsing routines.
@ -221,4 +228,11 @@ const PRUint32 kLeftSquareBracket = '[';
const PRUint32 kRightSquareBracket = ']';
const PRUnichar kNullCh = '\0';
#define kHTMLTextContentType "text/html"
#define kXMLTextContentType "text/xml"
#define kXULTextContentType "text/xul"
#define kRDFTextContentType "text/rdf"
#define kXIFTextContentType "text/xif"
#define kPlainTextContentType "text/plain"
#endif

Просмотреть файл

@ -92,13 +92,12 @@ class CSharedParserObjects {
public:
CSharedParserObjects() : mDeallocator(), mDTDDeque(mDeallocator) {
/*
NS_NewWellFormed_DTD(&theDTD);
RegisterDTD(theDTD);
*/
nsIDTD* theDTD;
NS_NewWellFormed_DTD(&theDTD);
RegisterDTD(theDTD);
NS_NewNavHTMLDTD(&theDTD); //do this as the default HTML DTD...
mDTDDeque.Push(theDTD);
@ -608,7 +607,7 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){
CParserContext* pc=new CParserContext(new nsScanner(kUnknownFilename,aStream,PR_FALSE),&aStream,0);
if(pc) {
PushContext(*pc);
pc->mSourceType="text/html";
pc->mSourceType=kHTMLTextContentType;
pc->mStreamListenerState=eOnStart;
pc->mMultipart=PR_FALSE;
pc->mContextType=CParserContext::eCTStream;
@ -628,10 +627,10 @@ nsresult nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){
*
* @update gess5/11/98
* @param aSourceBuffer contains a string-full of real content
* @param anHTMLString tells us whether we should assume the content is HTML (usually true)
* @param aContentType tells us what type of content to expect in the given string
* @return error code -- 0 if ok, non-zero if error.
*/
nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify,PRBool aLastCall){
nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall){
#ifdef _rickgdebug
{
@ -659,10 +658,7 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,
PushContext(*pc);
pc->mStreamListenerState=eOnStart;
pc->mContextType=CParserContext::eCTString;
if(PR_TRUE==anHTMLString)
pc->mSourceType="text/html";
else
pc->mSourceType="text/xml"; // XXX rick is a fish
pc->mSourceType=aContentType;
}
else {
NS_RELEASE(me);
@ -702,7 +698,7 @@ nsresult nsParser::ResumeParse(nsIDTD* aDefaultDTD) {
nsresult result=NS_OK;
if(mParserContext->mParserEnabled) {
result=WillBuildModel(mParserContext->mScanner->GetFilename(),aDefaultDTD);
if (mParserContext->mDTD) {
if(mParserContext->mDTD) {
mParserContext->mDTD->WillResumeParse();
if(NS_OK==result) {
@ -725,6 +721,7 @@ nsresult nsParser::ResumeParse(nsIDTD* aDefaultDTD) {
}//if
}//if
}//if
else result=NS_ERROR_HTMLPARSER_UNRESOLVEDDTD;
}//if
return result;
}

Просмотреть файл

@ -166,7 +166,7 @@ friend class CTokenHandler;
* @param appendTokens tells us whether we should insert tokens inline, or append them.
* @return TRUE if all went well -- FALSE otherwise
*/
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,PRBool anHTMLString,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE);
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE);
/**

Просмотреть файл

@ -119,7 +119,8 @@ void nsScanner::InitUnicodeDecoder()
nsAutoString defaultCharset("ISO-8859-1");
SetDocumentCharset(defaultCharset);
}
nsresult nsScanner::SetDocumentCharset(nsString& aCharset )
nsresult nsScanner::SetDocumentCharset(const nsString& aCharset )
{
nsresult res = NS_OK;
if(! mCharset.EqualsIgnoreCase(aCharset)) // see do we need to change a converter.
@ -372,7 +373,7 @@ nsresult nsScanner::PutBack(PRUnichar aChar) {
* @return error status
*/
nsresult nsScanner::SkipWhitespace(void) {
static nsAutoString chars(" \n\r\t");
static nsAutoString chars(" \n\r\t\b");
return SkipOver(chars);
}

Просмотреть файл

@ -269,7 +269,7 @@ class nsScanner {
/**
* Change the charset and the Unicode Decoder
*/
nsresult SetDocumentCharset(nsString& aCharset);
nsresult SetDocumentCharset(const nsString& aCharset);
protected:

Просмотреть файл

@ -60,7 +60,6 @@ static NS_DEFINE_IID(kClassIID, NS_VALID_DTD_IID);
//static const char* kNullTokenizer = "Error: Unable to construct tokenizer";
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kXMLTextContentType = "text/xml";
static nsAutoString gEmpty;

Просмотреть файл

@ -57,8 +57,6 @@ static NS_DEFINE_IID(kClassIID, NS_VIEWSOURCE_HTML_IID);
//static const char* kNullTokenizer = "Error: Unable to construct tokenizer";
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kHTMLTextContentType = "text/html";
static const char* kXMLTextContentType = "text/xml";
static const char* kViewSourceCommand= "view-source";
static nsAutoString gEmpty;
@ -230,9 +228,13 @@ nsresult CViewSourceHTML::CreateNewInstance(nsIDTD** aInstancePtrResult){
* @return TRUE if this DTD can satisfy the request; FALSE otherwise.
*/
PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRInt32 aVersion){
PRBool result=(aContentType.Equals(kHTMLTextContentType) && (aCommand.Equals(kViewSourceCommand)));
if(!result) {
result=(aContentType.Equals(kXMLTextContentType) && (aCommand.Equals(kViewSourceCommand)));
PRBool result=PR_FALSE;
if(aCommand.Equals(kViewSourceCommand)) {
result=(aContentType.Equals(kXMLTextContentType) ||
aContentType.Equals(kRDFTextContentType) ||
aContentType.Equals(kHTMLTextContentType) ||
aContentType.Equals(kPlainTextContentType) ||
aContentType.Equals(kXULTextContentType));
}
return result;
}
@ -240,24 +242,15 @@ PRBool CViewSourceHTML::CanParse(nsString& aContentType, nsString& aCommand, PRI
/**
* This is called to ask the DTD if it recognizes either the aType or data in the buffer.
* We intentionally say NO to autodetect types so that XML and HTML dtds can do the right thing.
* If either of those DTD's say YES, then we'll agree and render either.
*
* @update gess7/7/98
* @param
* @return detect result
*/
eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsString& aType){
eAutoDetectResult result=eUnknownDetect;
if(PR_TRUE==aType.Equals(kHTMLTextContentType))
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;
}

Просмотреть файл

@ -57,9 +57,6 @@ static NS_DEFINE_IID(kClassIID, NS_WELLFORMED_DTD_IID);
//static const char* kNullTokenizer = "Error: Unable to construct tokenizer";
//static const char* kNullToken = "Error: Null token given";
//static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kXMLTextContentType = "text/xml";
static const char* kRDFTextContentType = "text/rdf";
static const char* kXULTextContentType = "text/xul";
static const char* kViewSourceCommand= "view-source";
static nsAutoString gEmpty;
@ -203,8 +200,15 @@ eAutoDetectResult CWellFormedDTD::AutoDetectContentType(nsString& aBuffer,nsStri
eAutoDetectResult result=eUnknownDetect;
if(PR_TRUE==aType.Equals(kXMLTextContentType) ||
PR_TRUE==aType.Equals(kRDFTextContentType) ||
PR_TRUE==aType.Equals(kXULTextContentType))
PR_TRUE==aType.Equals(kXULTextContentType)) {
result=eValidDetect;
}
else {
if(-1<aBuffer.Find("<?xml ")) {
aType = kXMLTextContentType;
result=eValidDetect;
}
}
return result;
}

Просмотреть файл

@ -42,7 +42,6 @@ static NS_DEFINE_IID(kClassIID, NS_XIF_DTD_IID);
static const char* kNullToken = "Error: Null token given";
static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static const char* kXIFTextContentType = "text/xif";
static const char* kXIFDocHeader= "<!DOCTYPE xif>";
static nsAutoString gEmpty;

Просмотреть файл

@ -2219,7 +2219,7 @@ nsBrowserWindow::DoCopy()
parser->RegisterDTD(dtd);
//dtd->SetContentSink(sink);
//dtd->SetParser(parser);
parser->Parse(buffer, 0, PR_FALSE,PR_FALSE,PR_TRUE);
parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE);
}
NS_IF_RELEASE(dtd);
NS_IF_RELEASE(sink);
@ -2889,7 +2889,7 @@ nsBrowserWindow::DoDebugSave()
parser->RegisterDTD(dtd);
//dtd->SetContentSink(sink);
//dtd->SetParser(parser);
parser->Parse(buffer, 0, PR_FALSE,PR_FALSE,PR_TRUE);
parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE);
}
out.close();