Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/parser/TextResourceDecoder.h |
| diff --git a/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.h b/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.h |
| index 2539cc8a68577c5e20da2b757637e3e510931e27..d736de9aaf2b9fe151dce7c7d87b3a2d9c866927 100644 |
| --- a/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.h |
| +++ b/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.h |
| @@ -48,7 +48,13 @@ public: |
| static PassOwnPtr<TextResourceDecoder> create(const String& mimeType, const WTF::TextEncoding& defaultEncoding = WTF::TextEncoding(), bool usesEncodingDetector = false) |
|
kouhei (in TOK)
2015/12/14 02:00:22
Most of the create() methods use exactly same para
hiroshige
2015/12/14 05:44:02
I'd like to enforce mimeType == "plain/text" && de
|
| { |
| - return adoptPtr(new TextResourceDecoder(mimeType, defaultEncoding, usesEncodingDetector)); |
| + return adoptPtr(new TextResourceDecoder(mimeType, defaultEncoding, usesEncodingDetector ? UseAllAutoDetection : UseContentAndBOMBasedDetection)); |
| + } |
| + // Corresponds to utf-8 decode in Encoding spec: |
| + // https://encoding.spec.whatwg.org/#utf-8-decode. |
| + static PassOwnPtr<TextResourceDecoder> createAlwaysUseUTF8ForText() |
| + { |
| + return adoptPtr(new TextResourceDecoder("plain/text", UTF8Encoding(), AlwaysUseUTF8ForText)); |
| } |
| ~TextResourceDecoder(); |
| @@ -73,7 +79,28 @@ public: |
| size_t checkForBOM(const char*, size_t); |
| private: |
| - TextResourceDecoder(const String& mimeType, const WTF::TextEncoding& defaultEncoding, bool usesEncodingDetector); |
| + |
| + // TextResourceDecoder does three kind of encoding detection: |
| + // 1. By BOM, |
| + // 2. By Content if |m_contentType| is not |PlainTextContext| |
| + // (e.g. <meta> tag for HTML), and |
| + // 3. By detectTextEncoding(). |
| + enum EncodingDetectionOption { |
| + // Use 1. + 2. + 3. |
| + UseAllAutoDetection, |
| + |
| + // Use 1. + 2. |
| + UseContentAndBOMBasedDetection, |
| + |
| + // Use None of them. |
| + // |m_contentType| must be |PlainTextContent| and |
| + // |m_encoding| must be UTF8Encoding. |
| + // This doesn't change encoding based on BOMs, but still processes |
| + // utf-8 BOMs so that utf-8 BOMs don't appear in the decoded result. |
| + AlwaysUseUTF8ForText |
| + }; |
| + |
| + TextResourceDecoder(const String& mimeType, const WTF::TextEncoding& defaultEncoding, EncodingDetectionOption); |
| enum ContentType { PlainTextContent, HTMLContent, XMLContent, CSSContent }; // PlainText only checks for BOM. |
| static ContentType determineContentType(const String& mimeType); |
| @@ -96,7 +123,7 @@ private: |
| bool m_checkedForMetaCharset; |
| bool m_useLenientXMLDecoding; // Don't stop on XML decoding errors. |
| bool m_sawError; |
| - bool m_usesEncodingDetector; |
| + EncodingDetectionOption m_encodingDetectionOption; |
| OwnPtr<HTMLMetaCharsetParser> m_charsetParser; |
| }; |