michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsEncoderDecoderUtils.h" michael@0: #include "nsISupportsImpl.h" michael@0: michael@0: #include "mozilla/dom/EncodingUtils.h" michael@0: michael@0: using mozilla::dom::EncodingUtils; michael@0: michael@0: void michael@0: nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes, nsACString& charset) michael@0: { michael@0: readable = bytes; michael@0: stateLoop(stateSave); michael@0: readable = nullptr; michael@0: charset.Assign(mCharset); michael@0: } michael@0: michael@0: bool michael@0: nsHtml5MetaScanner::tryCharset(nsString* charset) michael@0: { michael@0: // This code needs to stay in sync with michael@0: // nsHtml5StreamParser::internalEncodingDeclaration. Unfortunately, the michael@0: // trickery with member fields here leads to some copy-paste reuse. :-( michael@0: nsAutoCString label; michael@0: CopyUTF16toUTF8(*charset, label); michael@0: nsAutoCString encoding; michael@0: if (!EncodingUtils::FindEncodingForLabel(label, encoding)) { michael@0: return false; michael@0: } michael@0: if (encoding.EqualsLiteral("UTF-16BE") || michael@0: encoding.EqualsLiteral("UTF-16LE")) { michael@0: mCharset.Assign("UTF-8"); michael@0: return true; michael@0: } michael@0: if (encoding.EqualsLiteral("x-user-defined")) { michael@0: // WebKit/Blink hack for Indian and Armenian legacy sites michael@0: mCharset.Assign("windows-1252"); michael@0: return true; michael@0: } michael@0: mCharset.Assign(encoding); michael@0: return true; michael@0: }