Bug 672453 - Whine to console about various character encoding declaration-related authoring errors. r=smaug.

This commit is contained in:
Henri Sivonen
2012-03-24 13:34:42 +02:00
parent b8bbb20e93
commit 71efda6e2b
117 changed files with 2477 additions and 73 deletions

View File

@@ -60,6 +60,7 @@
#include "mozilla/css/Loader.h"
#include "mozilla/Util.h" // DebugOnly
#include "sampler.h"
#include "nsIScriptError.h"
using namespace mozilla;
@@ -808,7 +809,8 @@ nsHtml5TreeOpExecutor::Start()
void
nsHtml5TreeOpExecutor::NeedsCharsetSwitchTo(const char* aEncoding,
PRInt32 aSource)
PRInt32 aSource,
PRUint32 aLineNumber)
{
EndDocUpdate();
@@ -831,14 +833,73 @@ nsHtml5TreeOpExecutor::NeedsCharsetSwitchTo(const char* aEncoding,
if (!mParser) {
// success
if (aSource == kCharsetFromMetaTag) {
MaybeComplainAboutCharset("EncLateMetaReload", false, aLineNumber);
}
return;
}
if (aSource == kCharsetFromMetaTag) {
MaybeComplainAboutCharset("EncLateMetaTooLate", true, aLineNumber);
}
GetParser()->ContinueAfterFailedCharsetSwitch();
BeginDocUpdate();
}
void
nsHtml5TreeOpExecutor::MaybeComplainAboutCharset(const char* aMsgId,
bool aError,
PRUint32 aLineNumber)
{
if (mAlreadyComplainedAboutCharset) {
return;
}
// The EncNoDeclaration case for advertising iframes is so common that it
// would result is way too many errors. The iframe case doesn't matter
// when the ad is an image or a Flash animation anyway. When the ad is
// textual, a misrendered ad probably isn't a huge loss for users.
// Let's suppress the message in this case.
// This means that errors about other different-origin iframes in mashups
// are lost as well, but generally, the site author isn't in control of
// the embedded different-origin pages anyway and can't fix problems even
// if alerted about them.
if (!strcmp(aMsgId, "EncNoDeclaration") && mDocShell) {
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(mDocShell);
nsCOMPtr<nsIDocShellTreeItem> parent;
treeItem->GetSameTypeParent(getter_AddRefs(parent));
if (parent) {
return;
}
}
mAlreadyComplainedAboutCharset = true;
nsContentUtils::ReportToConsole(aError ? nsIScriptError::errorFlag
: nsIScriptError::warningFlag,
"HTML parser",
mDocument,
nsContentUtils::eHTMLPARSER_PROPERTIES,
aMsgId,
nsnull,
0,
nsnull,
EmptyString(),
aLineNumber);
}
void
nsHtml5TreeOpExecutor::ComplainAboutBogusProtocolCharset(nsIDocument* aDoc)
{
NS_ASSERTION(!mAlreadyComplainedAboutCharset,
"How come we already managed to complain?");
mAlreadyComplainedAboutCharset = true;
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
"HTML parser",
aDoc,
nsContentUtils::eHTMLPARSER_PROPERTIES,
"EncProtocolUnsupported");
}
nsHtml5Parser*
nsHtml5TreeOpExecutor::GetParser()
{