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/. */
|
2017-12-05 00:09:15 +03:00
|
|
|
|
2014-02-27 01:36:35 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2017-06-17 05:54:40 +03:00
|
|
|
#include "mozilla/Encoding.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
const mozilla::Encoding* nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes) {
|
2009-06-29 02:44:22 +04:00
|
|
|
readable = bytes;
|
|
|
|
stateLoop(stateSave);
|
2012-07-30 18:20:58 +04:00
|
|
|
readable = nullptr;
|
2017-06-18 14:37:50 +03:00
|
|
|
return mEncoding;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
2017-03-20 15:45:15 +03:00
|
|
|
bool nsHtml5MetaScanner::tryCharset(nsHtml5String 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;
|
2017-03-20 15:45:15 +03:00
|
|
|
nsString charset16; // Not Auto, because using it to hold nsStringBuffer*
|
|
|
|
charset.ToString(charset16);
|
|
|
|
CopyUTF16toUTF8(charset16, label);
|
2017-12-05 00:09:15 +03:00
|
|
|
const mozilla::Encoding* encoding = Encoding::ForLabel(label);
|
2017-06-17 05:54:40 +03:00
|
|
|
if (!encoding) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2018-03-16 18:26:06 +03:00
|
|
|
if (encoding == UTF_16BE_ENCODING || encoding == UTF_16LE_ENCODING) {
|
2017-06-18 14:37:50 +03:00
|
|
|
mEncoding = UTF_8_ENCODING;
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2017-06-17 05:54:40 +03:00
|
|
|
if (encoding == X_USER_DEFINED_ENCODING) {
|
2014-01-02 11:18:19 +04:00
|
|
|
// WebKit/Blink hack for Indian and Armenian legacy sites
|
2017-06-18 14:37:50 +03:00
|
|
|
mEncoding = WINDOWS_1252_ENCODING;
|
2014-01-02 11:18:19 +04:00
|
|
|
return true;
|
|
|
|
}
|
2017-06-18 14:37:50 +03:00
|
|
|
mEncoding = encoding;
|
2013-11-25 12:06:56 +04:00
|
|
|
return true;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|