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:
bzbarsky%mit.edu
2006-08-25 16:34:57 +00:00
parent ec9585116a
commit b59b0dd36c
12 changed files with 118 additions and 71 deletions

View File

@@ -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;