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

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

Issue 1456843002: Finch experiment: auto-detect text encoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp b/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
index 7c483538ae2e3bf7f81ee0808da03883f4b568d9..7b74f86b64e4e7c192faaa86dd82ed94154c943d 100644
--- a/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
+++ b/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
@@ -19,7 +19,6 @@
Boston, MA 02110-1301, USA.
*/
-
#include "config.h"
#include "core/html/parser/TextResourceDecoder.h"
@@ -401,9 +400,7 @@ String TextResourceDecoder::decode(const char* data, size_t len)
checkForMetaCharset(dataForDecode, lengthForDecode);
if (shouldAutoDetect()) {
- WTF::TextEncoding detectedEncoding;
- if (detectTextEncoding(data, len, m_hintEncoding, &detectedEncoding))
- setEncoding(detectedEncoding, EncodingFromContentSniffing);
+ detectTextEncoding(data, len);
}
ASSERT(m_encoding.isValid());
@@ -417,6 +414,16 @@ String TextResourceDecoder::decode(const char* data, size_t len)
return result;
}
+void TextResourceDecoder::detectTextEncoding(const char* data, size_t len)
+{
+ WTF::TextEncoding detectedEncoding;
+ bool detected = blink::detectTextEncoding(data, len, m_hintEncoding, &detectedEncoding);
+ if (detected && detectedEncoding != encoding())
+ setEncoding(detectedEncoding, EncodingFromContentSniffing);
+ else
+ setEncoding(detectedEncoding, DefaultEncodingAttemptedSniffing);
+}
+
String TextResourceDecoder::flush()
{
// If we can not identify the encoding even after a document is completely
@@ -424,9 +431,7 @@ String TextResourceDecoder::flush()
// autodetection is satisfied.
if (m_buffer.size() && shouldAutoDetect()
&& ((!m_checkedForXMLCharset && (m_contentType == HTMLContent || m_contentType == XMLContent)) || (!m_checkedForCSSCharset && (m_contentType == CSSContent)))) {
- WTF::TextEncoding detectedEncoding;
- if (detectTextEncoding(m_buffer.data(), m_buffer.size(), m_hintEncoding, &detectedEncoding))
- setEncoding(detectedEncoding, EncodingFromContentSniffing);
+ detectTextEncoding(m_buffer.data(), m_buffer.size());
}
if (!m_codec)

Powered by Google App Engine
This is Rietveld 408576698