| 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 49897d7c3ac409bd860dbaf44bbc4786a39ad3b4..5e27ba9ba25127e309e0083ef6604eaf0ac442d4 100644
|
| --- a/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
|
| +++ b/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
|
| @@ -28,6 +28,7 @@
|
| #include "wtf/StringExtras.h"
|
| #include "wtf/text/TextCodec.h"
|
| #include "wtf/text/TextEncodingRegistry.h"
|
| +#include "wtf/text/UTF8.h"
|
|
|
| using namespace WTF;
|
|
|
| @@ -402,11 +403,7 @@ String TextResourceDecoder::decode(const char* data, size_t len)
|
| if (m_contentType == HTMLContent && !m_checkedForMetaCharset)
|
| 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());
|
|
|
| @@ -419,16 +416,28 @@ String TextResourceDecoder::decode(const char* data, size_t len)
|
| return result;
|
| }
|
|
|
| +void TextResourceDecoder::detectTextEncoding(const char* data, size_t len)
|
| +{
|
| + if (shouldAutoDetect()) {
|
| + WTF::TextEncoding detectedEncoding;
|
| + if (detectTextEncodingUniversal(data, len, m_hintEncoding, &detectedEncoding))
|
| + setEncoding(detectedEncoding, EncodingFromContentSniffing);
|
| + return;
|
| + }
|
| + if ((m_source == DefaultEncoding || (m_source == EncodingFromParentFrame && m_hintEncoding))) {
|
| + if (WTF::Unicode::isUTF8Encoded(data, len))
|
| + setEncoding(UTF8Encoding(), EncodingFromContentSniffing);
|
| + }
|
| +}
|
| +
|
| String TextResourceDecoder::flush()
|
| {
|
| // If we can not identify the encoding even after a document is completely
|
| // loaded, we need to detect the encoding if other conditions for
|
| // autodetection is satisfied.
|
| - if (m_buffer.size() && shouldAutoDetect()
|
| + if (m_buffer.size()
|
| && ((!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)
|
|
|