Chromium Code Reviews| 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..a4b137cf24d224af0613f76212e95119214e089c 100644 |
| --- a/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp |
| +++ b/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp |
| @@ -402,11 +402,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); |
| - } |
| + tryDetectingTextEncoding(data, len); |
| ASSERT(m_encoding.isValid()); |
| @@ -419,16 +415,25 @@ String TextResourceDecoder::decode(const char* data, size_t len) |
| return result; |
| } |
| +void TextResourceDecoder::tryDetectingTextEncoding(const char* data, size_t len) |
| +{ |
| + if (shouldAutoDetect()) { |
|
esprehn
2016/02/26 09:37:25
Can we use early return instead?
put a return at
Jinsuk Kim
2016/03/02 00:08:32
Done. (I suppose you meant 'if' not 'return' state
|
| + WTF::TextEncoding detectedEncoding; |
| + if (detectTextEncoding(data, len, m_hintEncoding, &detectedEncoding)) |
| + setEncoding(detectedEncoding, EncodingFromContentSniffing); |
| + } else if ((m_source == DefaultEncoding || (m_source == EncodingFromParentFrame && m_hintEncoding)) && 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); |
| + tryDetectingTextEncoding(m_buffer.data(), m_buffer.size()); |
| } |
| if (!m_codec) |