2012-05-29 19:52:43 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-06-29 02:44:22 +04:00
|
|
|
|
|
|
|
#include "nsEncoderDecoderUtils.h"
|
2014-02-27 01:36:35 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2012-11-08 03:04:22 +04:00
|
|
|
#include "mozilla/dom/EncodingUtils.h"
|
|
|
|
|
|
|
|
using mozilla::dom::EncodingUtils;
|
2009-06-29 02:44:22 +04:00
|
|
|
|
|
|
|
void
|
2013-11-25 12:06:56 +04:00
|
|
|
nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes, nsACString& charset)
|
2009-06-29 02:44:22 +04:00
|
|
|
{
|
|
|
|
readable = bytes;
|
|
|
|
stateLoop(stateSave);
|
2012-07-30 18:20:58 +04:00
|
|
|
readable = nullptr;
|
2013-11-25 12:06:56 +04:00
|
|
|
charset.Assign(mCharset);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5MetaScanner::tryCharset(nsString* charset)
|
|
|
|
{
|
2010-07-30 14:03:54 +04:00
|
|
|
// This code needs to stay in sync with
|
|
|
|
// nsHtml5StreamParser::internalEncodingDeclaration. Unfortunately, the
|
|
|
|
// trickery with member fields here leads to some copy-paste reuse. :-(
|
2013-11-25 12:06:56 +04:00
|
|
|
nsAutoCString label;
|
|
|
|
CopyUTF16toUTF8(*charset, label);
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString encoding;
|
2013-11-25 12:06:56 +04:00
|
|
|
if (!EncodingUtils::FindEncodingForLabel(label, encoding)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2013-11-25 12:06:56 +04:00
|
|
|
if (encoding.EqualsLiteral("UTF-16BE") ||
|
|
|
|
encoding.EqualsLiteral("UTF-16LE")) {
|
2014-05-22 07:48:51 +04:00
|
|
|
mCharset.AssignLiteral("UTF-8");
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2014-01-02 11:18:19 +04:00
|
|
|
if (encoding.EqualsLiteral("x-user-defined")) {
|
|
|
|
// WebKit/Blink hack for Indian and Armenian legacy sites
|
2014-05-22 07:48:51 +04:00
|
|
|
mCharset.AssignLiteral("windows-1252");
|
2014-01-02 11:18:19 +04:00
|
|
|
return true;
|
|
|
|
}
|
2013-11-25 12:06:56 +04:00
|
|
|
mCharset.Assign(encoding);
|
|
|
|
return true;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|