Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp

Issue 2803563004: Avoid using language hint in encoding detection (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All 3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All
4 rights reserved. 4 rights reserved.
5 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com) 5 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com)
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 m_checkedForCSSCharset(false), 152 m_checkedForCSSCharset(false),
153 m_checkedForXMLCharset(false), 153 m_checkedForXMLCharset(false),
154 m_checkedForMetaCharset(false), 154 m_checkedForMetaCharset(false),
155 m_useLenientXMLDecoding(false), 155 m_useLenientXMLDecoding(false),
156 m_sawError(false), 156 m_sawError(false),
157 m_encodingDetectionOption(encodingDetectionOption) { 157 m_encodingDetectionOption(encodingDetectionOption) {
158 m_hintLanguage[0] = 0; 158 m_hintLanguage[0] = 0;
159 if (m_encodingDetectionOption == AlwaysUseUTF8ForText) { 159 if (m_encodingDetectionOption == AlwaysUseUTF8ForText) {
160 DCHECK(m_contentType == PlainTextContent && m_encoding == UTF8Encoding()); 160 DCHECK(m_contentType == PlainTextContent && m_encoding == UTF8Encoding());
161 } else if (m_encodingDetectionOption == UseAllAutoDetection) { 161 } else if (m_encodingDetectionOption == UseAllAutoDetection) {
162 // Checking empty URL helps unit testing. Providing defaultLanguage() is 162 // Obtain language hint from system locale:
163 // 1) In general, do not use language hint. This helps get more
164 // deterministic encoding detection results across devices. Note that local
165 // file resources can still benefit from the hint.
166 // 2) Checking empty URL helps unit testing. Providing defaultLanguage() is
163 // sometimes difficult in tests. 167 // sometimes difficult in tests.
164 if (!hintUrl.isEmpty()) { 168 if (hintUrl.protocol() == "file" || !hintUrl.isEmpty()) {
tkent 2017/04/06 07:29:13 The code is incorrect. http:// URLs are not isEmp
Jinsuk Kim 2017/04/06 08:10:25 My bad. Moved to TextEncodingDetector and updated
165 // This object is created in the main thread, but used in another thread. 169 // This object is created in the main thread, but used in another thread.
166 // We should not share an AtomicString. 170 // We should not share an AtomicString.
167 AtomicString locale = defaultLanguage(); 171 AtomicString locale = defaultLanguage();
168 if (locale.length() >= 2) { 172 if (locale.length() >= 2) {
169 // defaultLanguage() is always an ASCII string. 173 // defaultLanguage() is always an ASCII string.
170 m_hintLanguage[0] = static_cast<char>(locale[0]); 174 m_hintLanguage[0] = static_cast<char>(locale[0]);
171 m_hintLanguage[1] = static_cast<char>(locale[1]); 175 m_hintLanguage[1] = static_cast<char>(locale[1]);
172 m_hintLanguage[2] = 0; 176 m_hintLanguage[2] = 0;
173 } 177 }
174 } 178 }
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 String result = m_codec->decode( 514 String result = m_codec->decode(
511 m_buffer.data(), m_buffer.size(), WTF::FetchEOF, 515 m_buffer.data(), m_buffer.size(), WTF::FetchEOF,
512 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); 516 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError);
513 m_buffer.clear(); 517 m_buffer.clear();
514 m_codec.reset(); 518 m_codec.reset();
515 m_checkedForBOM = false; // Skip BOM again when re-decoding. 519 m_checkedForBOM = false; // Skip BOM again when re-decoding.
516 return result; 520 return result;
517 } 521 }
518 522
519 } // namespace blink 523 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698