1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "nsISupportsImpl.h" 6 7 #include "mozilla/Encoding.h" 8 sniff(nsHtml5ByteReadable * bytes)9const mozilla::Encoding* nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes) { 10 readable = bytes; 11 stateLoop(stateSave); 12 readable = nullptr; 13 return mEncoding; 14 } 15 tryCharset(nsHtml5String charset)16bool nsHtml5MetaScanner::tryCharset(nsHtml5String charset) { 17 // This code needs to stay in sync with 18 // nsHtml5StreamParser::internalEncodingDeclaration. Unfortunately, the 19 // trickery with member fields here leads to some copy-paste reuse. :-( 20 nsAutoCString label; 21 nsString charset16; // Not Auto, because using it to hold nsStringBuffer* 22 charset.ToString(charset16); 23 CopyUTF16toUTF8(charset16, label); 24 const mozilla::Encoding* encoding = Encoding::ForLabel(label); 25 if (!encoding) { 26 return false; 27 } 28 if (encoding == UTF_16BE_ENCODING || encoding == UTF_16LE_ENCODING) { 29 mEncoding = UTF_8_ENCODING; 30 return true; 31 } 32 if (encoding == X_USER_DEFINED_ENCODING) { 33 // WebKit/Blink hack for Indian and Armenian legacy sites 34 mEncoding = WINDOWS_1252_ENCODING; 35 return true; 36 } 37 mEncoding = encoding; 38 return true; 39 } 40