Allow nsIExpatSink implementations to control whether the expat driver logs
parse errors to the console. Bug 342164, patch by Alex Vincent <ajvincent@gmail.com>, r+sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@208410 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
ec9585116a
commit
b59b0dd36c
@ -204,27 +204,19 @@ nsXBLContentSink::FlushText(PRBool aCreateTextNode,
|
||||
NS_IMETHODIMP
|
||||
nsXBLContentSink::ReportError(const PRUnichar* aErrorText,
|
||||
const PRUnichar* aSourceText,
|
||||
PRInt32 aLineNumber,
|
||||
PRInt32 aColumnNumber)
|
||||
nsIScriptError *aError,
|
||||
PRBool *_retval)
|
||||
{
|
||||
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
||||
|
||||
// XXX FIXME This function overrides and calls on
|
||||
// nsXMLContentSink::ReportError, and probably should die. See bug 347826.
|
||||
|
||||
// XXX We should make sure the binding has no effect, but that it also
|
||||
// gets destroyed properly without leaking. Perhaps we should even
|
||||
// ensure that the content that was bound is displayed with no
|
||||
// binding.
|
||||
|
||||
// Report the error to the error console.
|
||||
nsCOMPtr<nsIConsoleService> consoleService =
|
||||
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
||||
if (consoleService) {
|
||||
// XXX It would be nice if the parser didn't pre-format it for us,
|
||||
// because then we could create a instance of nsIScriptError and the
|
||||
// error console would format this much more nicely for us.
|
||||
// However, that would require duplicating even more code between
|
||||
// the XML content sink and the XUL content sink.
|
||||
|
||||
consoleService->LogStringMessage(aErrorText);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Report the error to stderr.
|
||||
fprintf(stderr,
|
||||
@ -234,10 +226,11 @@ nsXBLContentSink::ReportError(const PRUnichar* aErrorText,
|
||||
#endif
|
||||
|
||||
// Most of what this does won't be too useful, but whatever...
|
||||
// nsXMLContentSink::ReportError will handle the console logging.
|
||||
return nsXMLContentSink::ReportError(aErrorText,
|
||||
aSourceText,
|
||||
aLineNumber,
|
||||
aColumnNumber);
|
||||
aError,
|
||||
_retval);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
||||
@ -147,8 +147,8 @@ protected:
|
||||
// nsIExpatSink overrides
|
||||
NS_IMETHOD ReportError(const PRUnichar* aErrorText,
|
||||
const PRUnichar* aSourceText,
|
||||
PRInt32 aLineNumber,
|
||||
PRInt32 aColumnNumber);
|
||||
nsIScriptError *aError,
|
||||
PRBool *_retval);
|
||||
|
||||
protected:
|
||||
nsresult ReportUnexpectedElement(nsIAtom* aElementName, PRUint32 aLineNumber);
|
||||
|
||||
@ -201,11 +201,16 @@ nsLoadSaveContentSink::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
NS_IMETHODIMP
|
||||
nsLoadSaveContentSink::ReportError(const PRUnichar* aErrorText,
|
||||
const PRUnichar* aSourceText,
|
||||
PRInt32 aLineNumber,
|
||||
PRInt32 aColumnNumber)
|
||||
nsIScriptError *aError,
|
||||
PRBool *_retval)
|
||||
{
|
||||
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
||||
|
||||
// XXX Do error reporting here. I see no reason to call ReportError
|
||||
// on the "base" sink; all we need to do is drop the document on the
|
||||
// floor...
|
||||
|
||||
// The expat driver should report the error.
|
||||
*_retval = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1279,10 +1279,14 @@ nsXMLContentSink::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
NS_IMETHODIMP
|
||||
nsXMLContentSink::ReportError(const PRUnichar* aErrorText,
|
||||
const PRUnichar* aSourceText,
|
||||
PRInt32 aLineNumber,
|
||||
PRInt32 aColumnNumber)
|
||||
nsIScriptError *aError,
|
||||
PRBool *_retval)
|
||||
{
|
||||
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// The expat driver should report the error. We're just cleaning up the mess.
|
||||
*_retval = PR_TRUE;
|
||||
|
||||
mPrettyPrintXML = PR_FALSE;
|
||||
|
||||
|
||||
@ -52,6 +52,7 @@
|
||||
#include "nsContentCreatorFunctions.h"
|
||||
#include "nsDOMError.h"
|
||||
#include "nsIConsoleService.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
@ -83,8 +84,8 @@ public:
|
||||
PRInt32 aStandalone);
|
||||
NS_IMETHOD ReportError(const PRUnichar* aErrorText,
|
||||
const PRUnichar* aSourceText,
|
||||
PRInt32 aLineNumber,
|
||||
PRInt32 aColumnNumber);
|
||||
nsIScriptError *aError,
|
||||
PRBool *_retval);
|
||||
|
||||
// nsIContentSink
|
||||
NS_IMETHOD WillBuildModel(void);
|
||||
@ -314,17 +315,15 @@ nsXMLFragmentContentSink::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
NS_IMETHODIMP
|
||||
nsXMLFragmentContentSink::ReportError(const PRUnichar* aErrorText,
|
||||
const PRUnichar* aSourceText,
|
||||
PRInt32 aLineNumber,
|
||||
PRInt32 aColumnNumber)
|
||||
nsIScriptError *aError,
|
||||
PRBool *_retval)
|
||||
{
|
||||
mParseError = PR_TRUE;
|
||||
// The following error reporting is copied from nsXBLContentSink::ReportError()
|
||||
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
||||
|
||||
nsCOMPtr<nsIConsoleService> consoleService =
|
||||
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
||||
if (consoleService) {
|
||||
consoleService->LogStringMessage(aErrorText);
|
||||
}
|
||||
// The expat driver should report the error.
|
||||
*_retval = PR_TRUE;
|
||||
|
||||
mParseError = PR_TRUE;
|
||||
|
||||
#ifdef DEBUG
|
||||
// Report the error to stderr.
|
||||
|
||||
@ -67,6 +67,7 @@
|
||||
#include "txStylesheetCompiler.h"
|
||||
#include "txXMLUtils.h"
|
||||
#include "nsAttrName.h"
|
||||
#include "nsIScriptError.h"
|
||||
|
||||
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
|
||||
|
||||
@ -233,9 +234,14 @@ txStylesheetSink::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
NS_IMETHODIMP
|
||||
txStylesheetSink::ReportError(const PRUnichar *aErrorText,
|
||||
const PRUnichar *aSourceText,
|
||||
PRInt32 aLineNumber,
|
||||
PRInt32 aColumnNumber)
|
||||
nsIScriptError *aError,
|
||||
PRBool *_retval)
|
||||
{
|
||||
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
||||
|
||||
// The expat driver should report the error.
|
||||
*_retval = PR_TRUE;
|
||||
|
||||
mCompiler->cancel(NS_ERROR_FAILURE, aErrorText, aSourceText);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
@ -108,6 +108,7 @@
|
||||
#include "nsXMLContentSink.h"
|
||||
#include "nsLayoutAtoms.h"
|
||||
#include "nsIConsoleService.h"
|
||||
#include "nsIScriptError.h"
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
static PRLogModuleInfo* gLog;
|
||||
@ -998,9 +999,14 @@ XULContentSinkImpl::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
NS_IMETHODIMP
|
||||
XULContentSinkImpl::ReportError(const PRUnichar* aErrorText,
|
||||
const PRUnichar* aSourceText,
|
||||
PRInt32 aLineNumber,
|
||||
PRInt32 aColumnNumber)
|
||||
nsIScriptError *aError,
|
||||
PRBool *_retval)
|
||||
{
|
||||
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
||||
|
||||
// The expat driver should report the error.
|
||||
*_retval = PR_TRUE;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// make sure to empty the context stack so that
|
||||
@ -1030,11 +1036,7 @@ XULContentSinkImpl::ReportError(const PRUnichar* aErrorText,
|
||||
|
||||
nsCOMPtr<nsIXULDocument> doc = do_QueryReferent(mDocument);
|
||||
if (doc && !doc->OnDocumentParserError()) {
|
||||
// Report the error to the error console.
|
||||
nsCOMPtr<nsIConsoleService> consoleService =
|
||||
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
||||
if (consoleService)
|
||||
consoleService->LogStringMessage(aErrorText);
|
||||
// The overlay was broken. Don't add a messy element to the master doc.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
interface nsIScriptError;
|
||||
|
||||
/**
|
||||
* This interface should be implemented by any content sink that wants
|
||||
@ -43,7 +44,7 @@
|
||||
* by any sink that handles some sort of XML dialect.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(34CB3B34-7F15-4971-B262-370CE61ADE4D)]
|
||||
[scriptable, uuid(f61c56b5-ea5b-42b4-ad3c-17416e72e238)]
|
||||
interface nsIExpatSink : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -129,8 +130,16 @@ interface nsIExpatSink : nsISupports
|
||||
in wstring aEncoding,
|
||||
in long aStandalone);
|
||||
|
||||
void ReportError(in wstring aErrorText,
|
||||
in wstring aSourceText,
|
||||
in long aLineNumber,
|
||||
in long aColumnNumber);
|
||||
/**
|
||||
* Ask the content sink if the expat driver should log an error to the console.
|
||||
*
|
||||
* @param aErrorText Error message to pass to content sink.
|
||||
* @param aSourceText Source text of the document we're parsing.
|
||||
* @param aError Script error object with line number & column number
|
||||
*
|
||||
* @retval True if the expat driver should report the error.
|
||||
*/
|
||||
boolean ReportError(in wstring aErrorText,
|
||||
in wstring aSourceText,
|
||||
in nsIScriptError aError);
|
||||
};
|
||||
|
||||
@ -911,27 +911,41 @@ nsExpatDriver::HandleError()
|
||||
CreateErrorText(description.get(), XML_GetBase(mExpatParser), lineNumber,
|
||||
colNumber, errorText);
|
||||
|
||||
nsCOMPtr<nsIConsoleService> cs
|
||||
(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
||||
nsCOMPtr<nsIScriptError> serr(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
||||
if (serr && cs) {
|
||||
if (NS_SUCCEEDED(serr->Init(description.get(),
|
||||
mURISpec.get(),
|
||||
mLastLine.get(),
|
||||
lineNumber, colNumber,
|
||||
nsIScriptError::errorFlag, "malformed-xml")))
|
||||
cs->LogMessage(serr);
|
||||
}
|
||||
NS_ASSERTION(mSink, "no sink?");
|
||||
|
||||
nsAutoString sourceText(mLastLine);
|
||||
AppendErrorPointer(colNumber, mLastLine.get(), sourceText);
|
||||
|
||||
NS_ASSERTION(mSink, "no sink?");
|
||||
if (mSink) {
|
||||
mSink->ReportError(errorText.get(),
|
||||
sourceText.get(),
|
||||
lineNumber,
|
||||
colNumber);
|
||||
// Try to create and initialize the script error.
|
||||
nsCOMPtr<nsIScriptError> serr(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (serr) {
|
||||
rv = serr->Init(description.get(),
|
||||
mURISpec.get(),
|
||||
mLastLine.get(),
|
||||
lineNumber, colNumber,
|
||||
nsIScriptError::errorFlag, "malformed-xml");
|
||||
}
|
||||
|
||||
// If it didn't initialize, we can't do any logging.
|
||||
PRBool shouldReportError = NS_SUCCEEDED(rv);
|
||||
|
||||
if (mSink && shouldReportError) {
|
||||
rv = mSink->ReportError(errorText.get(),
|
||||
sourceText.get(),
|
||||
serr,
|
||||
&shouldReportError);
|
||||
if (NS_FAILED(rv)) {
|
||||
shouldReportError = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldReportError) {
|
||||
nsCOMPtr<nsIConsoleService> cs
|
||||
(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
||||
if (cs) {
|
||||
cs->LogMessage(serr);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_HTMLPARSER_STOPPARSING;
|
||||
|
||||
@ -291,13 +291,22 @@ nsSAXXMLReader::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
NS_IMETHODIMP
|
||||
nsSAXXMLReader::ReportError(const PRUnichar* aErrorText,
|
||||
const PRUnichar* aSourceText,
|
||||
PRInt32 aLineNumber,
|
||||
PRInt32 aColumnNumber)
|
||||
nsIScriptError *aError,
|
||||
PRBool *_retval)
|
||||
{
|
||||
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
||||
// 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)
|
||||
return mErrorHandler->FatalError(nsnull, nsDependentString(aErrorText));
|
||||
if (mErrorHandler) {
|
||||
nsresult rv = mErrorHandler->FatalError(nsnull, nsDependentString(aErrorText));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// The error handler has handled the script error. Don't log to console.
|
||||
*_retval = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -52,6 +52,7 @@ REQUIRES = xpcom \
|
||||
necko \
|
||||
content \
|
||||
htmlparser \
|
||||
xpconnect \
|
||||
unicharutil \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@ -95,6 +95,7 @@
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsStaticAtom.h"
|
||||
#include "nsIScriptError.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// XPCOM IIDs
|
||||
@ -592,9 +593,13 @@ RDFContentSinkImpl::HandleXMLDeclaration(const PRUnichar *aVersion,
|
||||
NS_IMETHODIMP
|
||||
RDFContentSinkImpl::ReportError(const PRUnichar* aErrorText,
|
||||
const PRUnichar* aSourceText,
|
||||
PRInt32 aLineNumber,
|
||||
PRInt32 aColumnNumber)
|
||||
nsIScriptError *aError,
|
||||
PRBool *_retval)
|
||||
{
|
||||
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
||||
|
||||
// The expat driver should report the error.
|
||||
*_retval = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user