Suppress spurious console errors for XHR response codes 201, 202, 204, 205 and 304.

Parse errors for XML data are already handled in 4d8f9a9add1805a5cb3b7fd1cc1ff8dd4b020fe4  -- this is a follow-up to suppress unnecessary console errors.
This commit is contained in:
Pale Moon
2017-04-29 00:20:27 +02:00
committed by roytam1
parent 09d736f1e6
commit bc0f3e14bc
5 changed files with 36 additions and 0 deletions
+3
View File
@@ -237,6 +237,9 @@ public:
virtual void SetSuppressParserErrorElement(bool aSuppress) {}
virtual bool SuppressParserErrorElement() { return false; }
virtual void SetSuppressParserErrorConsoleMessages(bool aSuppress) {}
virtual bool SuppressParserErrorConsoleMessages() { return false; }
/**
* Signal that the document title may have changed
* (see nsDocument::GetTitle).
+10
View File
@@ -2158,6 +2158,16 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
mResponseXML->SetChromeXHRDocURI(chromeXHRDocURI);
mResponseXML->SetChromeXHRDocBaseURI(chromeXHRDocBaseURI);
// suppress parsing failure messages to console for statuses which
// can have empty bodies (see bugs 884693 + 1329365).
uint32_t responseStatus;
if (NS_SUCCEEDED(GetStatus(&responseStatus)) &&
(responseStatus == 201 || responseStatus == 202 ||
responseStatus == 204 || responseStatus == 205 ||
responseStatus == 304)) {
mResponseXML->SetSuppressParserErrorConsoleMessages(true);
}
if (nsContentUtils::IsSystemPrincipal(mPrincipal)) {
mResponseXML->ForceEnableXULXBL();
}
+12
View File
@@ -524,6 +524,18 @@ XMLDocument::SuppressParserErrorElement()
return mSuppressParserErrorElement;
}
void
XMLDocument::SetSuppressParserErrorConsoleMessages(bool aSuppress)
{
mSuppressParserErrorConsoleMessages = aSuppress;
}
bool
XMLDocument::SuppressParserErrorConsoleMessages()
{
return mSuppressParserErrorConsoleMessages;
}
nsresult
XMLDocument::StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
+6
View File
@@ -33,6 +33,9 @@ public:
virtual void SetSuppressParserErrorElement(bool aSuppress) override;
virtual bool SuppressParserErrorElement() override;
virtual void SetSuppressParserErrorConsoleMessages(bool aSuppress) override;
virtual bool SuppressParserErrorConsoleMessages() override;
virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* channel,
nsILoadGroup* aLoadGroup,
nsISupports* aContainer,
@@ -93,6 +96,9 @@ protected:
// If true, do not output <parsererror> elements. Per spec, XMLHttpRequest
// shouldn't output them, whereas DOMParser/others should (see bug 918703).
bool mSuppressParserErrorElement;
// If true, do not log parsing errors to the web console (see bug 884693).
bool mSuppressParserErrorConsoleMessages;
};
} // namespace dom
+5
View File
@@ -988,6 +988,11 @@ nsExpatDriver::HandleError()
}
}
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mOriginalSink->GetTarget());
if (doc && doc->SuppressParserErrorConsoleMessages()) {
shouldReportError = false;
}
if (shouldReportError) {
nsCOMPtr<nsIConsoleService> cs
(do_GetService(NS_CONSOLESERVICE_CONTRACTID));