2012-05-29 08:52:43 -07: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-28 15:44:22 -07:00
|
|
|
|
|
|
|
#include "nsEncoderDecoderUtils.h"
|
2014-02-26 13:36:35 -08:00
|
|
|
#include "nsISupportsImpl.h"
|
2009-06-28 15:44:22 -07:00
|
|
|
|
2012-11-07 15:04:22 -08:00
|
|
|
#include "mozilla/dom/EncodingUtils.h"
|
|
|
|
|
|
|
|
using mozilla::dom::EncodingUtils;
|
2009-06-28 15:44:22 -07:00
|
|
|
|
|
|
|
void
|
2013-11-25 00:06:56 -08:00
|
|
|
nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes, nsACString& charset)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
|
|
|
readable = bytes;
|
|
|
|
stateLoop(stateSave);
|
2012-07-30 07:20:58 -07:00
|
|
|
readable = nullptr;
|
2013-11-25 00:06:56 -08:00
|
|
|
charset.Assign(mCharset);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5MetaScanner::tryCharset(nsString* charset)
|
|
|
|
{
|
2010-07-30 03:03:54 -07: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 00:06:56 -08:00
|
|
|
nsAutoCString label;
|
|
|
|
CopyUTF16toUTF8(*charset, label);
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString encoding;
|
2013-11-25 00:06:56 -08:00
|
|
|
if (!EncodingUtils::FindEncodingForLabel(label, encoding)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
2013-11-25 00:06:56 -08:00
|
|
|
if (encoding.EqualsLiteral("UTF-16BE") ||
|
|
|
|
encoding.EqualsLiteral("UTF-16LE")) {
|
2014-05-21 20:48:51 -07:00
|
|
|
mCharset.AssignLiteral("UTF-8");
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
2014-01-01 23:18:19 -08:00
|
|
|
if (encoding.EqualsLiteral("x-user-defined")) {
|
|
|
|
// WebKit/Blink hack for Indian and Armenian legacy sites
|
2014-05-21 20:48:51 -07:00
|
|
|
mCharset.AssignLiteral("windows-1252");
|
2014-01-01 23:18:19 -08:00
|
|
|
return true;
|
|
|
|
}
|
2013-11-25 00:06:56 -08:00
|
|
|
mCharset.Assign(encoding);
|
|
|
|
return true;
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|