Index: third_party/WebKit/Source/core/loader/TextResourceDecoderBuilder.cpp |
diff --git a/third_party/WebKit/Source/core/loader/TextResourceDecoderBuilder.cpp b/third_party/WebKit/Source/core/loader/TextResourceDecoderBuilder.cpp |
index 077ad6d0f5013afd3cd332a3a30ec748e3eb6825..204a8ede7bba46ee6cc5b04da2d07f6a855c5bde 100644 |
--- a/third_party/WebKit/Source/core/loader/TextResourceDecoderBuilder.cpp |
+++ b/third_party/WebKit/Source/core/loader/TextResourceDecoderBuilder.cpp |
@@ -42,6 +42,71 @@ static inline bool canReferToParentFrameEncoding(const LocalFrame* frame, const |
return parentFrame && parentFrame->document()->securityOrigin()->canAccess(frame->document()->securityOrigin()); |
} |
+static const char* legacyEncodings[] = { |
esprehn
2016/03/21 22:56:25
I'd name this into an array of structs, so you cou
Jinsuk Kim
2016/03/22 21:51:52
Done. Also used anonymous namespace to limit the s
|
+ "au", "windows-1252", |
+ "az", "ISO-8859-9", |
+ "bd", "windows-1252", |
+ "bg", "windows-1251", |
+ "br", "windows-1252", |
+ "ca", "windows-1252", |
+ "ch", "windows-1252", |
+ "cn", "GBK", |
+ "cz", "windows-1250", |
+ "de", "windows-1252", |
+ "dk", "windows-1252", |
+ "ee", "windows-1256", |
+ "eg", "windows-1257", |
+ "et", "windows-1252", |
+ "fi", "windows-1252", |
+ "fr", "windows-1252", |
+ "gb", "windows-1252", |
+ "gr", "ISO-8859-7", |
+ "hk", "Big5", |
+ "hr", "windows-1250", |
+ "hu", "ISO-8859-2", |
+ "il", "windows-1255", |
+ "ir", "windows-1257", |
+ "is", "windows-1252", |
+ "it", "windows-1252", |
+ "jp", "Shift_JIS", |
+ "kr", "windows-949", |
+ "lt", "windows-1256", |
+ "lv", "windows-1256", |
+ "mk", "windows-1251", |
+ "nl", "windows-1252", |
+ "no", "windows-1252", |
+ "pl", "ISO-8859-2", |
+ "pt", "windows-1252", |
+ "ro", "ISO-8859-2", |
+ "rs", "windows-1251", |
+ "ru", "windows-1251", |
+ "se", "windows-1252", |
+ "si", "ISO-8859-2", |
+ "sk", "windows-1250", |
+ "th", "windows-874", |
+ "tr", "ISO-8859-9", |
+ "tw", "Big5", |
+ "tz", "windows-1252", |
+ "ua", "windows-1251", |
+ "us", "windows-1252", |
+ "vn", "windows-1258", |
+ "xa", "windows-1252", |
+ "xb", "windows-1257" |
+}; |
+ |
+static const WTF::TextEncoding getEncodingFromDomain(const KURL& url) |
+{ |
+ Vector<String> tokens; |
+ url.host().split(".", tokens); |
+ if (!tokens.isEmpty()) { |
+ auto tld = tokens.last(); |
+ for (size_t i = 0; i < WTF_ARRAY_LENGTH(legacyEncodings); i += 2) { |
+ if (tld == legacyEncodings[i]) |
+ return WTF::TextEncoding(legacyEncodings[i + 1]); |
+ } |
+ } |
+ return WTF::TextEncoding(); |
+} |
TextResourceDecoderBuilder::TextResourceDecoderBuilder(const AtomicString& mimeType, const AtomicString& encoding) |
: m_mimeType(mimeType) |
@@ -56,12 +121,13 @@ TextResourceDecoderBuilder::~TextResourceDecoderBuilder() |
inline PassOwnPtr<TextResourceDecoder> TextResourceDecoderBuilder::createDecoderInstance(Document* document) |
{ |
+ const WTF::TextEncoding encodingFromDomain = getEncodingFromDomain(document->url()); |
if (LocalFrame* frame = document->frame()) { |
if (Settings* settings = frame->settings()) |
- return TextResourceDecoder::create(m_mimeType, settings->defaultTextEncodingName(), settings->usesEncodingDetector()); |
+ return TextResourceDecoder::create(m_mimeType, encodingFromDomain.isValid() ? encodingFromDomain : settings->defaultTextEncodingName(), settings->usesEncodingDetector()); |
} |
- return TextResourceDecoder::create(m_mimeType, String()); |
+ return TextResourceDecoder::create(m_mimeType, encodingFromDomain); |
} |
inline void TextResourceDecoderBuilder::setupEncoding(TextResourceDecoder* decoder, Document* document) |