Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
5 #include "nsEncoderDecoderUtils.h"
6 #include "nsISupportsImpl.h"
8 #include "mozilla/dom/EncodingUtils.h"
10 using mozilla::dom::EncodingUtils;
12 void
13 nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes, nsACString& charset)
14 {
15 readable = bytes;
16 stateLoop(stateSave);
17 readable = nullptr;
18 charset.Assign(mCharset);
19 }
21 bool
22 nsHtml5MetaScanner::tryCharset(nsString* charset)
23 {
24 // This code needs to stay in sync with
25 // nsHtml5StreamParser::internalEncodingDeclaration. Unfortunately, the
26 // trickery with member fields here leads to some copy-paste reuse. :-(
27 nsAutoCString label;
28 CopyUTF16toUTF8(*charset, label);
29 nsAutoCString encoding;
30 if (!EncodingUtils::FindEncodingForLabel(label, encoding)) {
31 return false;
32 }
33 if (encoding.EqualsLiteral("UTF-16BE") ||
34 encoding.EqualsLiteral("UTF-16LE")) {
35 mCharset.Assign("UTF-8");
36 return true;
37 }
38 if (encoding.EqualsLiteral("x-user-defined")) {
39 // WebKit/Blink hack for Indian and Armenian legacy sites
40 mCharset.Assign("windows-1252");
41 return true;
42 }
43 mCharset.Assign(encoding);
44 return true;
45 }