OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 24 matching lines...) Expand all Loading... | |
35 #include "core/frame/Settings.h" | 35 #include "core/frame/Settings.h" |
36 #include "platform/weborigin/SecurityOrigin.h" | 36 #include "platform/weborigin/SecurityOrigin.h" |
37 | 37 |
38 namespace blink { | 38 namespace blink { |
39 | 39 |
40 static inline bool canReferToParentFrameEncoding(const LocalFrame* frame, const LocalFrame* parentFrame) | 40 static inline bool canReferToParentFrameEncoding(const LocalFrame* frame, const LocalFrame* parentFrame) |
41 { | 41 { |
42 return parentFrame && parentFrame->document()->securityOrigin()->canAccess(f rame->document()->securityOrigin()); | 42 return parentFrame && parentFrame->document()->securityOrigin()->canAccess(f rame->document()->securityOrigin()); |
43 } | 43 } |
44 | 44 |
45 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
| |
46 "au", "windows-1252", | |
47 "az", "ISO-8859-9", | |
48 "bd", "windows-1252", | |
49 "bg", "windows-1251", | |
50 "br", "windows-1252", | |
51 "ca", "windows-1252", | |
52 "ch", "windows-1252", | |
53 "cn", "GBK", | |
54 "cz", "windows-1250", | |
55 "de", "windows-1252", | |
56 "dk", "windows-1252", | |
57 "ee", "windows-1256", | |
58 "eg", "windows-1257", | |
59 "et", "windows-1252", | |
60 "fi", "windows-1252", | |
61 "fr", "windows-1252", | |
62 "gb", "windows-1252", | |
63 "gr", "ISO-8859-7", | |
64 "hk", "Big5", | |
65 "hr", "windows-1250", | |
66 "hu", "ISO-8859-2", | |
67 "il", "windows-1255", | |
68 "ir", "windows-1257", | |
69 "is", "windows-1252", | |
70 "it", "windows-1252", | |
71 "jp", "Shift_JIS", | |
72 "kr", "windows-949", | |
73 "lt", "windows-1256", | |
74 "lv", "windows-1256", | |
75 "mk", "windows-1251", | |
76 "nl", "windows-1252", | |
77 "no", "windows-1252", | |
78 "pl", "ISO-8859-2", | |
79 "pt", "windows-1252", | |
80 "ro", "ISO-8859-2", | |
81 "rs", "windows-1251", | |
82 "ru", "windows-1251", | |
83 "se", "windows-1252", | |
84 "si", "ISO-8859-2", | |
85 "sk", "windows-1250", | |
86 "th", "windows-874", | |
87 "tr", "ISO-8859-9", | |
88 "tw", "Big5", | |
89 "tz", "windows-1252", | |
90 "ua", "windows-1251", | |
91 "us", "windows-1252", | |
92 "vn", "windows-1258", | |
93 "xa", "windows-1252", | |
94 "xb", "windows-1257" | |
95 }; | |
96 | |
97 static const WTF::TextEncoding getEncodingFromDomain(const KURL& url) | |
98 { | |
99 Vector<String> tokens; | |
100 url.host().split(".", tokens); | |
101 if (!tokens.isEmpty()) { | |
102 auto tld = tokens.last(); | |
103 for (size_t i = 0; i < WTF_ARRAY_LENGTH(legacyEncodings); i += 2) { | |
104 if (tld == legacyEncodings[i]) | |
105 return WTF::TextEncoding(legacyEncodings[i + 1]); | |
106 } | |
107 } | |
108 return WTF::TextEncoding(); | |
109 } | |
45 | 110 |
46 TextResourceDecoderBuilder::TextResourceDecoderBuilder(const AtomicString& mimeT ype, const AtomicString& encoding) | 111 TextResourceDecoderBuilder::TextResourceDecoderBuilder(const AtomicString& mimeT ype, const AtomicString& encoding) |
47 : m_mimeType(mimeType) | 112 : m_mimeType(mimeType) |
48 , m_encoding(encoding) | 113 , m_encoding(encoding) |
49 { | 114 { |
50 } | 115 } |
51 | 116 |
52 TextResourceDecoderBuilder::~TextResourceDecoderBuilder() | 117 TextResourceDecoderBuilder::~TextResourceDecoderBuilder() |
53 { | 118 { |
54 } | 119 } |
55 | 120 |
56 | 121 |
57 inline PassOwnPtr<TextResourceDecoder> TextResourceDecoderBuilder::createDecoder Instance(Document* document) | 122 inline PassOwnPtr<TextResourceDecoder> TextResourceDecoderBuilder::createDecoder Instance(Document* document) |
58 { | 123 { |
124 const WTF::TextEncoding encodingFromDomain = getEncodingFromDomain(document- >url()); | |
59 if (LocalFrame* frame = document->frame()) { | 125 if (LocalFrame* frame = document->frame()) { |
60 if (Settings* settings = frame->settings()) | 126 if (Settings* settings = frame->settings()) |
61 return TextResourceDecoder::create(m_mimeType, settings->defaultText EncodingName(), settings->usesEncodingDetector()); | 127 return TextResourceDecoder::create(m_mimeType, encodingFromDomain.is Valid() ? encodingFromDomain : settings->defaultTextEncodingName(), settings->us esEncodingDetector()); |
62 } | 128 } |
63 | 129 |
64 return TextResourceDecoder::create(m_mimeType, String()); | 130 return TextResourceDecoder::create(m_mimeType, encodingFromDomain); |
65 } | 131 } |
66 | 132 |
67 inline void TextResourceDecoderBuilder::setupEncoding(TextResourceDecoder* decod er, Document* document) | 133 inline void TextResourceDecoderBuilder::setupEncoding(TextResourceDecoder* decod er, Document* document) |
68 { | 134 { |
69 LocalFrame* frame = document->frame(); | 135 LocalFrame* frame = document->frame(); |
70 LocalFrame* parentFrame = 0; | 136 LocalFrame* parentFrame = 0; |
71 if (frame && frame->tree().parent() && frame->tree().parent()->isLocalFrame( )) | 137 if (frame && frame->tree().parent() && frame->tree().parent()->isLocalFrame( )) |
72 parentFrame = toLocalFrame(frame->tree().parent()); | 138 parentFrame = toLocalFrame(frame->tree().parent()); |
73 | 139 |
74 if (!m_encoding.isEmpty()) | 140 if (!m_encoding.isEmpty()) |
(...skipping 23 matching lines...) Expand all Loading... | |
98 setupEncoding(decoder.get(), document); | 164 setupEncoding(decoder.get(), document); |
99 return decoder.release(); | 165 return decoder.release(); |
100 } | 166 } |
101 | 167 |
102 void TextResourceDecoderBuilder::clear() | 168 void TextResourceDecoderBuilder::clear() |
103 { | 169 { |
104 m_encoding = nullAtom; | 170 m_encoding = nullAtom; |
105 } | 171 } |
106 | 172 |
107 } // namespace blink | 173 } // namespace blink |
OLD | NEW |