Bug 548232 - Make meta charset not have an effect on document.open()ed documents in the HTML5 parser (reverting most of bug 539887). r=bzbarsky.

This commit is contained in:
Henri Sivonen
2010-04-16 13:52:06 +03:00
parent 9f1426c660
commit 4d410f2cc6
22 changed files with 24 additions and 135 deletions

View File

@@ -60,9 +60,6 @@
#include "nsHtml5TreeBuilder.h"
#include "nsHtml5Parser.h"
#include "nsHtml5AtomTable.h"
#include "nsICharsetAlias.h"
static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
NS_INTERFACE_TABLE_HEAD(nsHtml5Parser)
NS_INTERFACE_TABLE2(nsHtml5Parser, nsIParser, nsISupportsWeakReference)
@@ -147,7 +144,6 @@ nsHtml5Parser::SetDocumentCharset(const nsACString& aCharset,
mStreamParser->SetDocumentCharset(aCharset, aCharsetSource);
mExecutor->SetDocumentCharsetAndSource((nsACString&)aCharset,
aCharsetSource);
mCharsetSource = aCharsetSource; // used for the document.open() case only
}
NS_IMETHODIMP_(void)
@@ -256,7 +252,6 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer,
"Had stream parser but document.write started life cycle.");
// This is the first document.write() on a document.open()ed document
mExecutor->SetParser(this);
mTokenizer->setEncodingDeclarationHandler(this);
mTreeBuilder->setScriptingEnabled(mExecutor->IsScriptEnabled());
mTokenizer->start();
mExecutor->Start();
@@ -676,37 +671,3 @@ nsHtml5Parser::ContinueAfterFailedCharsetSwitch()
"Tried to continue after failed charset switch without a stream parser");
mStreamParser->ContinueAfterFailedCharsetSwitch();
}
void
nsHtml5Parser::internalEncodingDeclaration(nsString* aEncoding)
{
// Note: This handler is only installed when parsing a document.open()ed doc
// See bug 539887 and bug 255820.
// this threshold corresponds to "confident" in the HTML5 spec
if (mCharsetSource >= kCharsetFromMetaTag) {
return;
}
nsresult rv = NS_OK;
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID, &rv));
if (NS_FAILED(rv)) {
NS_NOTREACHED("Charset alias service not available.");
return;
}
nsCAutoString newEncoding;
CopyUTF16toUTF8(*aEncoding, newEncoding);
// XXX check HTML5 non-IANA aliases here
nsCAutoString preferred;
rv = calias->GetPreferred(newEncoding, preferred);
if (NS_FAILED(rv)) {
// the encoding name is bogus
return;
}
mCharsetSource = kCharsetFromMetaTag;
mTreeBuilder->SetDocumentCharset(preferred, mCharsetSource);
}