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) |