From 468d83a18a7292a1583f905a379372d69e04625f Mon Sep 17 00:00:00 2001 From: "sayrer%gmail.com" Date: Wed, 13 Sep 2006 18:20:05 +0000 Subject: [PATCH] Bug 334302. Adjust SAXLocator reports in ReportError. Patch by Alex Vincent . r=sayrer, sr=bz git-svn-id: svn://10.0.0.236/trunk@210039 18797224-902f-48f8-a5cc-f745e15eee43 --- .../parser/htmlparser/src/nsParserModule.cpp | 8 +--- mozilla/parser/xml/src/Makefile.in | 1 + mozilla/parser/xml/src/nsSAXLocator.cpp | 37 ++++--------------- mozilla/parser/xml/src/nsSAXLocator.h | 10 ++--- mozilla/parser/xml/src/nsSAXXMLReader.cpp | 32 ++++++++++++++-- mozilla/parser/xml/src/nsSAXXMLReader.h | 2 + 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/mozilla/parser/htmlparser/src/nsParserModule.cpp b/mozilla/parser/htmlparser/src/nsParserModule.cpp index c774ea889c0..6f087a6492c 100644 --- a/mozilla/parser/htmlparser/src/nsParserModule.cpp +++ b/mozilla/parser/htmlparser/src/nsParserModule.cpp @@ -79,7 +79,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(CViewSourceHTML) #endif NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXAttributes) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXLocator) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXXMLReader) static const nsModuleComponentInfo gComponents[] = { @@ -99,18 +98,13 @@ static const nsModuleComponentInfo gComponents[] = { NS_PARSERSERVICE_CONTRACTID, nsParserServiceConstructor }, + { NS_SAXATTRIBUTES_CLASSNAME, NS_SAXATTRIBUTES_CID, NS_SAXATTRIBUTES_CONTRACTID, nsSAXAttributesConstructor }, - { - NS_SAXLOCATOR_CLASSNAME, - NS_SAXLOCATOR_CID, - NS_SAXLOCATOR_CONTRACTID, - nsSAXLocatorConstructor - }, { NS_SAXXMLREADER_CLASSNAME, diff --git a/mozilla/parser/xml/src/Makefile.in b/mozilla/parser/xml/src/Makefile.in index 78453cc626e..578224f6ed2 100644 --- a/mozilla/parser/xml/src/Makefile.in +++ b/mozilla/parser/xml/src/Makefile.in @@ -54,6 +54,7 @@ REQUIRES = \ htmlparser \ content \ uconv \ + xpconnect \ $(NULL) CPPSRCS = \ diff --git a/mozilla/parser/xml/src/nsSAXLocator.cpp b/mozilla/parser/xml/src/nsSAXLocator.cpp index 4cca3891c6a..a754d9c0efe 100644 --- a/mozilla/parser/xml/src/nsSAXLocator.cpp +++ b/mozilla/parser/xml/src/nsSAXLocator.cpp @@ -39,7 +39,14 @@ NS_IMPL_ISUPPORTS1(nsSAXLocator, nsISAXLocator) -nsSAXLocator::nsSAXLocator() : mLineNumber(0), mColumnNumber(0) +nsSAXLocator::nsSAXLocator(nsString& aPublicId, + nsString& aSystemId, + PRInt32 aLineNumber, + PRInt32 aColumnNumber) : + mPublicId(aPublicId), + mSystemId(aSystemId), + mLineNumber(aLineNumber), + mColumnNumber(aColumnNumber) { } @@ -70,31 +77,3 @@ nsSAXLocator::GetSystemId(nsAString &aSystemId) aSystemId = mSystemId; return NS_OK; } - -NS_IMETHODIMP -nsSAXLocator::SetColumnNumber(PRInt32 aColumnNumber) -{ - mColumnNumber = aColumnNumber; - return NS_OK; -} - -NS_IMETHODIMP -nsSAXLocator::SetLineNumber(PRInt32 aLineNumber) -{ - mLineNumber = aLineNumber; - return NS_OK; -} - -NS_IMETHODIMP -nsSAXLocator::SetSystemId(const nsAString &aSystemId) -{ - mSystemId = aSystemId; - return NS_OK; -} - -NS_IMETHODIMP -nsSAXLocator::SetPublicId(const nsAString &aPublicId) -{ - mPublicId = aPublicId; - return NS_OK; -} diff --git a/mozilla/parser/xml/src/nsSAXLocator.h b/mozilla/parser/xml/src/nsSAXLocator.h index cdb38400278..8e32cae9dec 100644 --- a/mozilla/parser/xml/src/nsSAXLocator.h +++ b/mozilla/parser/xml/src/nsSAXLocator.h @@ -54,12 +54,10 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSISAXLOCATOR - nsSAXLocator(); - - NS_IMETHOD SetColumnNumber(PRInt32 aColumnNumber); - NS_IMETHOD SetLineNumber(PRInt32 aLineNumber); - NS_IMETHOD SetSystemId(const nsAString & aSystemId); - NS_IMETHOD SetPublicId(const nsAString & aPublicId); + nsSAXLocator(nsString& aPublicId, + nsString& aSystemId, + PRInt32 aLineNumber, + PRInt32 aColumnNumber); private: nsString mPublicId; diff --git a/mozilla/parser/xml/src/nsSAXXMLReader.cpp b/mozilla/parser/xml/src/nsSAXXMLReader.cpp index 664b8fe92ea..6e713b8f061 100644 --- a/mozilla/parser/xml/src/nsSAXXMLReader.cpp +++ b/mozilla/parser/xml/src/nsSAXXMLReader.cpp @@ -43,7 +43,9 @@ #include "nsParserCIID.h" #include "nsStreamUtils.h" #include "nsStringStream.h" +#include "nsIScriptError.h" #include "nsSAXAttributes.h" +#include "nsSAXLocator.h" #include "nsSAXXMLReader.h" #define XMLNS_URI "http://www.w3.org/2000/xmlns/" @@ -163,6 +165,8 @@ nsSAXXMLReader::HandleStartDTD(const PRUnichar *aName, const PRUnichar *aSystemId, const PRUnichar *aPublicId) { + mSystemId = aSystemId; + mPublicId = aPublicId; if (mLexicalHandler) { return mLexicalHandler->StartDTD(nsDependentString(aName), nsDependentString(aSystemId), @@ -298,10 +302,23 @@ nsSAXXMLReader::ReportError(const PRUnichar* aErrorText, // Normally, the expat driver should report the error. *_retval = PR_TRUE; - /// XXX need to settle what to do about the input setup, so I have - /// coherent values for the nsISAXLocator here. nsnull for now. if (mErrorHandler) { - nsresult rv = mErrorHandler->FatalError(nsnull, nsDependentString(aErrorText)); + PRUint32 lineNumber; + nsresult rv = aError->GetLineNumber(&lineNumber); + NS_ENSURE_SUCCESS(rv, rv); + + PRUint32 columnNumber; + rv = aError->GetColumnNumber(&columnNumber); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr locator = new nsSAXLocator(mPublicId, + mSystemId, + lineNumber, + columnNumber); + if (!locator) + return NS_ERROR_OUT_OF_MEMORY; + + rv = mErrorHandler->FatalError(locator, nsDependentString(aErrorText)); if (NS_SUCCEEDED(rv)) { // The error handler has handled the script error. Don't log to console. *_retval = PR_FALSE; @@ -464,6 +481,15 @@ nsSAXXMLReader::ParseFromStream(nsIInputStream *aStream, rv = mListener->OnStartRequest(parserChannel, nsnull); if (NS_FAILED(rv)) parserChannel->Cancel(rv); + + /* When parsing a new document, we need to clear the XML identifiers. + HandleStartDTD will set these values from the DTD declaration tag. + We won't have them, of course, if there's a well-formedness error + before the DTD tag (such as a space before an XML declaration). + */ + mSystemId.Truncate(); + mPublicId.Truncate(); + nsresult status; parserChannel->GetStatus(&status); diff --git a/mozilla/parser/xml/src/nsSAXXMLReader.h b/mozilla/parser/xml/src/nsSAXXMLReader.h index a5b904fc1a9..3ce02636524 100644 --- a/mozilla/parser/xml/src/nsSAXXMLReader.h +++ b/mozilla/parser/xml/src/nsSAXXMLReader.h @@ -116,6 +116,8 @@ private: nsString &aURI, nsString &aLocalName, nsString &aQName); + nsString mPublicId; + nsString mSystemId; }; #endif // nsSAXXMLReader_h__