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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/TextResourceDecoder.h

Issue 2250263003: Move FuzzedDataProvider to //base and expose to blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ... also remove PLATFORM_EXPORT Created 4 years, 4 months 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) 3 Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
4 Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 4 Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 void setHintEncoding(const WTF::TextEncoding& encoding) 73 void setHintEncoding(const WTF::TextEncoding& encoding)
74 { 74 {
75 m_hintEncoding = encoding.name(); 75 m_hintEncoding = encoding.name();
76 } 76 }
77 77
78 void useLenientXMLDecoding() { m_useLenientXMLDecoding = true; } 78 void useLenientXMLDecoding() { m_useLenientXMLDecoding = true; }
79 bool sawError() const { return m_sawError; } 79 bool sawError() const { return m_sawError; }
80 size_t checkForBOM(const char*, size_t); 80 size_t checkForBOM(const char*, size_t);
81 81
82 private: 82 protected:
83
84 // TextResourceDecoder does three kind of encoding detection: 83 // TextResourceDecoder does three kind of encoding detection:
85 // 1. By BOM, 84 // 1. By BOM,
86 // 2. By Content if |m_contentType| is not |PlainTextContext| 85 // 2. By Content if |m_contentType| is not |PlainTextContext|
87 // (e.g. <meta> tag for HTML), and 86 // (e.g. <meta> tag for HTML), and
88 // 3. By detectTextEncoding(). 87 // 3. By detectTextEncoding().
89 enum EncodingDetectionOption { 88 enum EncodingDetectionOption {
90 // Use 1. + 2. + 3. 89 // Use 1. + 2. + 3.
91 UseAllAutoDetection, 90 UseAllAutoDetection,
92 91
93 // Use 1. + 2. 92 // Use 1. + 2.
94 UseContentAndBOMBasedDetection, 93 UseContentAndBOMBasedDetection,
95 94
96 // Use None of them. 95 // Use None of them.
97 // |m_contentType| must be |PlainTextContent| and 96 // |m_contentType| must be |PlainTextContent| and
98 // |m_encoding| must be UTF8Encoding. 97 // |m_encoding| must be UTF8Encoding.
99 // This doesn't change encoding based on BOMs, but still processes 98 // This doesn't change encoding based on BOMs, but still processes
100 // utf-8 BOMs so that utf-8 BOMs don't appear in the decoded result. 99 // utf-8 BOMs so that utf-8 BOMs don't appear in the decoded result.
101 AlwaysUseUTF8ForText 100 AlwaysUseUTF8ForText
102 }; 101 };
103 102
104 TextResourceDecoder(const String& mimeType, const WTF::TextEncoding& default Encoding, EncodingDetectionOption); 103 TextResourceDecoder(const String& mimeType, const WTF::TextEncoding& default Encoding, EncodingDetectionOption);
105 104
105 private:
106 enum ContentType { PlainTextContent, HTMLContent, XMLContent, CSSContent }; // PlainText only checks for BOM. 106 enum ContentType { PlainTextContent, HTMLContent, XMLContent, CSSContent }; // PlainText only checks for BOM.
107 static ContentType determineContentType(const String& mimeType); 107 static ContentType determineContentType(const String& mimeType);
108 static const WTF::TextEncoding& defaultEncoding(ContentType, const WTF::Text Encoding& defaultEncoding); 108 static const WTF::TextEncoding& defaultEncoding(ContentType, const WTF::Text Encoding& defaultEncoding);
109 109
110 bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer); 110 bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer);
111 bool checkForXMLCharset(const char*, size_t, bool& movedDataToBuffer); 111 bool checkForXMLCharset(const char*, size_t, bool& movedDataToBuffer);
112 void checkForMetaCharset(const char*, size_t); 112 void checkForMetaCharset(const char*, size_t);
113 bool shouldAutoDetect() const; 113 bool shouldAutoDetect() const;
114 114
115 ContentType m_contentType; 115 ContentType m_contentType;
116 WTF::TextEncoding m_encoding; 116 WTF::TextEncoding m_encoding;
117 std::unique_ptr<TextCodec> m_codec; 117 std::unique_ptr<TextCodec> m_codec;
118 EncodingSource m_source; 118 EncodingSource m_source;
119 const char* m_hintEncoding; 119 const char* m_hintEncoding;
120 Vector<char> m_buffer; 120 Vector<char> m_buffer;
121 bool m_checkedForBOM; 121 bool m_checkedForBOM;
122 bool m_checkedForCSSCharset; 122 bool m_checkedForCSSCharset;
123 bool m_checkedForXMLCharset; 123 bool m_checkedForXMLCharset;
124 bool m_checkedForMetaCharset; 124 bool m_checkedForMetaCharset;
125 bool m_useLenientXMLDecoding; // Don't stop on XML decoding errors. 125 bool m_useLenientXMLDecoding; // Don't stop on XML decoding errors.
126 bool m_sawError; 126 bool m_sawError;
127 EncodingDetectionOption m_encodingDetectionOption; 127 EncodingDetectionOption m_encodingDetectionOption;
128 128
129 std::unique_ptr<HTMLMetaCharsetParser> m_charsetParser; 129 std::unique_ptr<HTMLMetaCharsetParser> m_charsetParser;
130 }; 130 };
131 131
132 } // namespace blink 132 } // namespace blink
133 133
134 #endif 134 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/BUILD.gn ('k') | third_party/WebKit/Source/core/html/parser/TextResourceDecoderFuzzer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698