parser/html/nsHtml5MetaScannerCppSupplement.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "nsEncoderDecoderUtils.h"
michael@0 6 #include "nsISupportsImpl.h"
michael@0 7
michael@0 8 #include "mozilla/dom/EncodingUtils.h"
michael@0 9
michael@0 10 using mozilla::dom::EncodingUtils;
michael@0 11
michael@0 12 void
michael@0 13 nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes, nsACString& charset)
michael@0 14 {
michael@0 15 readable = bytes;
michael@0 16 stateLoop(stateSave);
michael@0 17 readable = nullptr;
michael@0 18 charset.Assign(mCharset);
michael@0 19 }
michael@0 20
michael@0 21 bool
michael@0 22 nsHtml5MetaScanner::tryCharset(nsString* charset)
michael@0 23 {
michael@0 24 // This code needs to stay in sync with
michael@0 25 // nsHtml5StreamParser::internalEncodingDeclaration. Unfortunately, the
michael@0 26 // trickery with member fields here leads to some copy-paste reuse. :-(
michael@0 27 nsAutoCString label;
michael@0 28 CopyUTF16toUTF8(*charset, label);
michael@0 29 nsAutoCString encoding;
michael@0 30 if (!EncodingUtils::FindEncodingForLabel(label, encoding)) {
michael@0 31 return false;
michael@0 32 }
michael@0 33 if (encoding.EqualsLiteral("UTF-16BE") ||
michael@0 34 encoding.EqualsLiteral("UTF-16LE")) {
michael@0 35 mCharset.Assign("UTF-8");
michael@0 36 return true;
michael@0 37 }
michael@0 38 if (encoding.EqualsLiteral("x-user-defined")) {
michael@0 39 // WebKit/Blink hack for Indian and Armenian legacy sites
michael@0 40 mCharset.Assign("windows-1252");
michael@0 41 return true;
michael@0 42 }
michael@0 43 mCharset.Assign(encoding);
michael@0 44 return true;
michael@0 45 }

mercurial