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

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

Issue 1470893002: [Fetch] Always use utf-8 for decoding in text() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove numerical enum value comparison. Created 5 years 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..ea5b826736f8aeb5fe57674f16b616f125bfac2f 100644
--- a/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
+++ b/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
@@ -112,7 +112,7 @@ const WTF::TextEncoding& TextResourceDecoder::defaultEncoding(ContentType conten
return specifiedDefaultEncoding;
}
-TextResourceDecoder::TextResourceDecoder(const String& mimeType, const WTF::TextEncoding& specifiedDefaultEncoding, bool usesEncodingDetector)
+TextResourceDecoder::TextResourceDecoder(const String& mimeType, const WTF::TextEncoding& specifiedDefaultEncoding, EncodingDetectionOption encodingDetectionOption)
: m_contentType(determineContentType(mimeType))
, m_encoding(defaultEncoding(m_contentType, specifiedDefaultEncoding))
, m_source(DefaultEncoding)
@@ -123,8 +123,9 @@ TextResourceDecoder::TextResourceDecoder(const String& mimeType, const WTF::Text
, m_checkedForMetaCharset(false)
, m_useLenientXMLDecoding(false)
, m_sawError(false)
- , m_usesEncodingDetector(usesEncodingDetector)
+ , m_encodingDetectionOption(encodingDetectionOption)
{
+ ASSERT(!(m_encodingDetectionOption == AlwaysUseUTF8ForText && (m_contentType != PlainTextContent || m_encoding != UTF8Encoding())));
kouhei (in TOK) 2015/12/14 02:00:22 Optional nit: Would you split this ASSERT stmt? if
hiroshige 2015/12/14 05:44:02 Done.
}
TextResourceDecoder::~TextResourceDecoder()
@@ -210,7 +211,7 @@ size_t TextResourceDecoder::checkForBOM(const char* data, size_t len)
unsigned char c4 = buf2Len ? (--buf2Len, *buf2++) : 0;
// Check for the BOM.
- if (c1 == 0xFF && c2 == 0xFE) {
+ if (m_encodingDetectionOption != AlwaysUseUTF8ForText && c1 == 0xFF && c2 == 0xFE) {
kouhei (in TOK) 2015/12/14 02:00:22 Can we reorder the if stmts here? if (c1 == 0xEF
hiroshige 2015/12/14 05:44:02 Done.
if (c3 || c4) {
setEncoding(UTF16LittleEndianEncoding(), AutoDetectedEncoding);
lengthOfBOM = 2;
@@ -221,10 +222,10 @@ size_t TextResourceDecoder::checkForBOM(const char* data, size_t len)
} else if (c1 == 0xEF && c2 == 0xBB && c3 == 0xBF) {
setEncoding(UTF8Encoding(), AutoDetectedEncoding);
lengthOfBOM = 3;
- } else if (c1 == 0xFE && c2 == 0xFF) {
+ } else if (m_encodingDetectionOption != AlwaysUseUTF8ForText && c1 == 0xFE && c2 == 0xFF) {
setEncoding(UTF16BigEndianEncoding(), AutoDetectedEncoding);
lengthOfBOM = 2;
- } else if (!c1 && !c2 && c3 == 0xFE && c4 == 0xFF) {
+ } else if (m_encodingDetectionOption != AlwaysUseUTF8ForText && !c1 && !c2 && c3 == 0xFE && c4 == 0xFF) {
setEncoding(UTF32BigEndianEncoding(), AutoDetectedEncoding);
lengthOfBOM = 4;
}
@@ -360,7 +361,7 @@ bool TextResourceDecoder::shouldAutoDetect() const
{
// Just checking m_hintEncoding suffices here because it's only set
// in setHintEncoding when the source is AutoDetectedEncoding.
- return m_usesEncodingDetector
+ return m_encodingDetectionOption == UseAllAutoDetection
&& (m_source == DefaultEncoding || (m_source == EncodingFromParentFrame && m_hintEncoding));
}

Powered by Google App Engine
This is Rietveld 408576698