diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index 2289165198b..9183908bafc 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -1425,7 +1425,9 @@ nsXMLContentSink::HandleComment(const PRUnichar *aName) return result; } -NS_IMETHODIMP nsXMLContentSink::HandleCDataSection(const PRUnichar *aData, PRUint32 aLength) +NS_IMETHODIMP +nsXMLContentSink::HandleCDataSection(const PRUnichar *aData, + PRUint32 aLength) { FlushText(); @@ -1456,7 +1458,8 @@ NS_IMETHODIMP nsXMLContentSink::HandleCDataSection(const PRUnichar *aData, PRUin } NS_IMETHODIMP -nsXMLContentSink::HandleDoctypeDecl(const PRUnichar *aDoctype) +nsXMLContentSink::HandleDoctypeDecl(const PRUnichar *aDoctype, + PRUint32 aLength) { nsresult rv = NS_OK; @@ -1464,12 +1467,8 @@ nsXMLContentSink::HandleDoctypeDecl(const PRUnichar *aDoctype) if (!doc) return NS_OK; - nsAutoString docTypeStr(aDoctype); - nsAutoString str, name, publicId, systemId; - - if (Substring(docTypeStr, 0, 9).Equals(NS_LITERAL_STRING(") - str.Truncate(str.Length()-1); // Delete the trailing > + // The rest is the internal subset (minus whitespace) str.Trim(kWhitespace); nsCOMPtr oldDocType; diff --git a/content/xul/document/src/nsXULContentSink.cpp b/content/xul/document/src/nsXULContentSink.cpp index 8d643376be1..aec6bc8438f 100644 --- a/content/xul/document/src/nsXULContentSink.cpp +++ b/content/xul/document/src/nsXULContentSink.cpp @@ -1025,7 +1025,7 @@ XULContentSinkImpl::HandleCDataSection(const PRUnichar *aData, PRUint32 aLength) } NS_IMETHODIMP -XULContentSinkImpl::HandleDoctypeDecl(const PRUnichar *aDoctype) +XULContentSinkImpl::HandleDoctypeDecl(const PRUnichar *aDoctype, PRUint32 aLength) { return NS_OK; } diff --git a/htmlparser/public/nsIExpatSink.idl b/htmlparser/public/nsIExpatSink.idl index 8d1b24360ac..2a0e1043e37 100644 --- a/htmlparser/public/nsIExpatSink.idl +++ b/htmlparser/public/nsIExpatSink.idl @@ -54,7 +54,8 @@ interface nsIExpatSink : nsISupports void HandleCDataSection(in wstring aData, in unsigned long aLength); - void HandleDoctypeDecl(in wstring aDoctype); + void HandleDoctypeDecl(in wstring aDoctype, + in unsigned long aLength); void HandleCharacterData(in wstring aData, in unsigned long aLength); diff --git a/htmlparser/src/nsExpatDriver.cpp b/htmlparser/src/nsExpatDriver.cpp index cd38716a98a..e36ea919eec 100644 --- a/htmlparser/src/nsExpatDriver.cpp +++ b/htmlparser/src/nsExpatDriver.cpp @@ -51,6 +51,7 @@ #include "prmem.h" #include "nsTextFormatter.h" +static const PRUint32 kNotInDoctype = PRUint32(-1); static const char* kDTDDirectory = "dtd/"; /***************************** EXPAT CALL BACKS *******************************/ @@ -235,11 +236,12 @@ NS_NewExpatDriver(nsIDTD** aResult) { nsExpatDriver::nsExpatDriver() :mExpatParser(0), mSink(0), - mInDoctype(0), + mBuffer(0), mInCData(0), mBytesParsed(0), mBytePosition(0), - mInternalState(NS_OK) + mInternalState(NS_OK), + mDoctypePos(-1) { NS_INIT_REFCNT(); } @@ -305,13 +307,7 @@ nsExpatDriver::HandleComment(const PRUnichar *aValue) { NS_ASSERTION(mSink, "content sink not found!"); - if (mInDoctype) { - // We do not want comments popping out of the doctype... - mDoctypeText.Append(NS_LITERAL_STRING("")); - } - else if (mSink){ + if (mSink && mDoctypePos == kNotInDoctype){ mInternalState = mSink->HandleComment(aValue); } @@ -341,10 +337,7 @@ nsExpatDriver::HandleDefault(const PRUnichar *aValue, { NS_ASSERTION(mSink, "content sink not found!"); - if (mInDoctype) { - mDoctypeText.Append(aValue, aLength); - } - else if (mSink) { + if (mSink && mDoctypePos == kNotInDoctype) { static const PRUnichar newline[] = {'\n','\0'}; for (PRUint32 i = 0; i < aLength && NS_SUCCEEDED(mInternalState); i++) { if (aValue[i] == '\n' || aValue[i] == '\r') { @@ -380,8 +373,7 @@ nsExpatDriver::HandleEndCdataSection() nsresult nsExpatDriver::HandleStartDoctypeDecl() { - mInDoctype = PR_TRUE; - mDoctypeText.Assign(NS_LITERAL_STRING("')); - + const PRUnichar* doctypeStart = mBuffer + ( mDoctypePos - mBytesParsed ) / 2; + const PRUnichar* doctypeEnd = mBuffer + ( XML_GetCurrentByteIndex(mExpatParser) - mBytesParsed ) / 2; + if(mSink) { - mInternalState = mSink->HandleDoctypeDecl(mDoctypeText.get()); + mInternalState = mSink->HandleDoctypeDecl(doctypeStart, doctypeEnd - doctypeStart); } - mDoctypeText.Truncate(); + mDoctypePos = kNotInDoctype; + return NS_OK; } @@ -730,9 +723,9 @@ nsExpatDriver::ConsumeToken(nsScanner& aScanner, while (start != end) { PRUint32 fragLength = PRUint32(start.size_forward()); - const PRUnichar* expatBuffer = start.get(); + mBuffer = start.get(); - mInternalState = ParseBuffer((const char *)expatBuffer, + mInternalState = ParseBuffer((const char *)mBuffer, fragLength * sizeof(PRUnichar), aFlushTokens); diff --git a/htmlparser/src/nsExpatDriver.h b/htmlparser/src/nsExpatDriver.h index 753b9b32d8c..46fa652c445 100644 --- a/htmlparser/src/nsExpatDriver.h +++ b/htmlparser/src/nsExpatDriver.h @@ -82,16 +82,19 @@ protected: nsresult HandleError(const char *aBuffer, PRUint32 aLength, PRBool aIsFinal); void GetLine(const char* aSourceBuffer, PRUint32 aLength, PRUint32 aOffset, nsString& aLine); - XML_Parser mExpatParser; - nsIExpatSink* mSink; - nsString mLastLine; - nsString mDoctypeText; - nsString mCDataText; - PRPackedBool mInDoctype; - PRPackedBool mInCData; - PRUint32 mBytesParsed; - PRInt32 mBytePosition; - nsresult mInternalState; + XML_Parser mExpatParser; + nsIExpatSink* mSink; + const PRUnichar* mBuffer; // weak + + nsString mLastLine; + nsString mCDataText; + PRPackedBool mInCData; + PRInt32 mBytePosition; + nsresult mInternalState; + PRUint32 mBytesParsed; + PRUint32 mDoctypePos; + + }; nsresult NS_NewExpatDriver(nsIDTD** aDriver); diff --git a/htmlparser/src/nsParser.cpp b/htmlparser/src/nsParser.cpp index 4fb006b922a..41977e5cf4f 100644 --- a/htmlparser/src/nsParser.cpp +++ b/htmlparser/src/nsParser.cpp @@ -1877,7 +1877,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo DidBuildModel(mStreamStatus); mInternalState = result; } - break; + return NS_OK; } else if(((NS_OK==result) && (theTokenizerResult==kEOF)) || (result==NS_ERROR_HTMLPARSER_INTERRUPTED)){ diff --git a/parser/htmlparser/public/nsIExpatSink.idl b/parser/htmlparser/public/nsIExpatSink.idl index 8d1b24360ac..2a0e1043e37 100644 --- a/parser/htmlparser/public/nsIExpatSink.idl +++ b/parser/htmlparser/public/nsIExpatSink.idl @@ -54,7 +54,8 @@ interface nsIExpatSink : nsISupports void HandleCDataSection(in wstring aData, in unsigned long aLength); - void HandleDoctypeDecl(in wstring aDoctype); + void HandleDoctypeDecl(in wstring aDoctype, + in unsigned long aLength); void HandleCharacterData(in wstring aData, in unsigned long aLength); diff --git a/parser/htmlparser/src/nsExpatDriver.cpp b/parser/htmlparser/src/nsExpatDriver.cpp index cd38716a98a..e36ea919eec 100644 --- a/parser/htmlparser/src/nsExpatDriver.cpp +++ b/parser/htmlparser/src/nsExpatDriver.cpp @@ -51,6 +51,7 @@ #include "prmem.h" #include "nsTextFormatter.h" +static const PRUint32 kNotInDoctype = PRUint32(-1); static const char* kDTDDirectory = "dtd/"; /***************************** EXPAT CALL BACKS *******************************/ @@ -235,11 +236,12 @@ NS_NewExpatDriver(nsIDTD** aResult) { nsExpatDriver::nsExpatDriver() :mExpatParser(0), mSink(0), - mInDoctype(0), + mBuffer(0), mInCData(0), mBytesParsed(0), mBytePosition(0), - mInternalState(NS_OK) + mInternalState(NS_OK), + mDoctypePos(-1) { NS_INIT_REFCNT(); } @@ -305,13 +307,7 @@ nsExpatDriver::HandleComment(const PRUnichar *aValue) { NS_ASSERTION(mSink, "content sink not found!"); - if (mInDoctype) { - // We do not want comments popping out of the doctype... - mDoctypeText.Append(NS_LITERAL_STRING("")); - } - else if (mSink){ + if (mSink && mDoctypePos == kNotInDoctype){ mInternalState = mSink->HandleComment(aValue); } @@ -341,10 +337,7 @@ nsExpatDriver::HandleDefault(const PRUnichar *aValue, { NS_ASSERTION(mSink, "content sink not found!"); - if (mInDoctype) { - mDoctypeText.Append(aValue, aLength); - } - else if (mSink) { + if (mSink && mDoctypePos == kNotInDoctype) { static const PRUnichar newline[] = {'\n','\0'}; for (PRUint32 i = 0; i < aLength && NS_SUCCEEDED(mInternalState); i++) { if (aValue[i] == '\n' || aValue[i] == '\r') { @@ -380,8 +373,7 @@ nsExpatDriver::HandleEndCdataSection() nsresult nsExpatDriver::HandleStartDoctypeDecl() { - mInDoctype = PR_TRUE; - mDoctypeText.Assign(NS_LITERAL_STRING("')); - + const PRUnichar* doctypeStart = mBuffer + ( mDoctypePos - mBytesParsed ) / 2; + const PRUnichar* doctypeEnd = mBuffer + ( XML_GetCurrentByteIndex(mExpatParser) - mBytesParsed ) / 2; + if(mSink) { - mInternalState = mSink->HandleDoctypeDecl(mDoctypeText.get()); + mInternalState = mSink->HandleDoctypeDecl(doctypeStart, doctypeEnd - doctypeStart); } - mDoctypeText.Truncate(); + mDoctypePos = kNotInDoctype; + return NS_OK; } @@ -730,9 +723,9 @@ nsExpatDriver::ConsumeToken(nsScanner& aScanner, while (start != end) { PRUint32 fragLength = PRUint32(start.size_forward()); - const PRUnichar* expatBuffer = start.get(); + mBuffer = start.get(); - mInternalState = ParseBuffer((const char *)expatBuffer, + mInternalState = ParseBuffer((const char *)mBuffer, fragLength * sizeof(PRUnichar), aFlushTokens); diff --git a/parser/htmlparser/src/nsExpatDriver.h b/parser/htmlparser/src/nsExpatDriver.h index 753b9b32d8c..46fa652c445 100644 --- a/parser/htmlparser/src/nsExpatDriver.h +++ b/parser/htmlparser/src/nsExpatDriver.h @@ -82,16 +82,19 @@ protected: nsresult HandleError(const char *aBuffer, PRUint32 aLength, PRBool aIsFinal); void GetLine(const char* aSourceBuffer, PRUint32 aLength, PRUint32 aOffset, nsString& aLine); - XML_Parser mExpatParser; - nsIExpatSink* mSink; - nsString mLastLine; - nsString mDoctypeText; - nsString mCDataText; - PRPackedBool mInDoctype; - PRPackedBool mInCData; - PRUint32 mBytesParsed; - PRInt32 mBytePosition; - nsresult mInternalState; + XML_Parser mExpatParser; + nsIExpatSink* mSink; + const PRUnichar* mBuffer; // weak + + nsString mLastLine; + nsString mCDataText; + PRPackedBool mInCData; + PRInt32 mBytePosition; + nsresult mInternalState; + PRUint32 mBytesParsed; + PRUint32 mDoctypePos; + + }; nsresult NS_NewExpatDriver(nsIDTD** aDriver); diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp index 4fb006b922a..41977e5cf4f 100644 --- a/parser/htmlparser/src/nsParser.cpp +++ b/parser/htmlparser/src/nsParser.cpp @@ -1877,7 +1877,7 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk, PRBo DidBuildModel(mStreamStatus); mInternalState = result; } - break; + return NS_OK; } else if(((NS_OK==result) && (theTokenizerResult==kEOF)) || (result==NS_ERROR_HTMLPARSER_INTERRUPTED)){ diff --git a/rdf/base/src/nsRDFContentSink.cpp b/rdf/base/src/nsRDFContentSink.cpp index ba3c02c3a43..61346ce6671 100644 --- a/rdf/base/src/nsRDFContentSink.cpp +++ b/rdf/base/src/nsRDFContentSink.cpp @@ -603,7 +603,7 @@ RDFContentSinkImpl::HandleCDataSection(const PRUnichar *aData, } NS_IMETHODIMP -RDFContentSinkImpl::HandleDoctypeDecl(const PRUnichar *aDoctype) +RDFContentSinkImpl::HandleDoctypeDecl(const PRUnichar *aDoctype, PRUint32 aLength) { return NS_OK; }