| OLD | NEW |
| 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 |
| 11 This library is distributed in the hope that it will be useful, | 11 This library is distributed in the hope that it will be useful, |
| 12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 Library General Public License for more details. | 14 Library General Public License for more details. |
| 15 | 15 |
| 16 You should have received a copy of the GNU Library General Public License | 16 You should have received a copy of the GNU Library General Public License |
| 17 along with this library; see the file COPYING.LIB. If not, write to | 17 along with this library; see the file COPYING.LIB. If not, write to |
| 18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 Boston, MA 02110-1301, USA. | 19 Boston, MA 02110-1301, USA. |
| 20 | 20 |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #ifndef TextResourceDecoder_h | 23 #ifndef TextResourceDecoder_h |
| 24 #define TextResourceDecoder_h | 24 #define TextResourceDecoder_h |
| 25 | 25 |
| 26 #include "core/CoreExport.h" | 26 #include "core/CoreExport.h" |
| 27 #include "wtf/PtrUtil.h" | |
| 28 #include "wtf/text/TextEncoding.h" | 27 #include "wtf/text/TextEncoding.h" |
| 29 #include <memory> | |
| 30 | 28 |
| 31 namespace blink { | 29 namespace blink { |
| 32 | 30 |
| 33 class HTMLMetaCharsetParser; | 31 class HTMLMetaCharsetParser; |
| 34 | 32 |
| 35 class CORE_EXPORT TextResourceDecoder { | 33 class CORE_EXPORT TextResourceDecoder { |
| 36 USING_FAST_MALLOC(TextResourceDecoder); | 34 USING_FAST_MALLOC(TextResourceDecoder); |
| 37 WTF_MAKE_NONCOPYABLE(TextResourceDecoder); | 35 WTF_MAKE_NONCOPYABLE(TextResourceDecoder); |
| 38 public: | 36 public: |
| 39 enum EncodingSource { | 37 enum EncodingSource { |
| 40 DefaultEncoding, | 38 DefaultEncoding, |
| 41 AutoDetectedEncoding, | 39 AutoDetectedEncoding, |
| 42 EncodingFromContentSniffing, | 40 EncodingFromContentSniffing, |
| 43 EncodingFromXMLHeader, | 41 EncodingFromXMLHeader, |
| 44 EncodingFromMetaTag, | 42 EncodingFromMetaTag, |
| 45 EncodingFromCSSCharset, | 43 EncodingFromCSSCharset, |
| 46 EncodingFromHTTPHeader, | 44 EncodingFromHTTPHeader, |
| 47 EncodingFromParentFrame | 45 EncodingFromParentFrame |
| 48 }; | 46 }; |
| 49 | 47 |
| 50 static std::unique_ptr<TextResourceDecoder> create(const String& mimeType, c
onst WTF::TextEncoding& defaultEncoding = WTF::TextEncoding(), bool usesEncoding
Detector = false) | 48 static PassOwnPtr<TextResourceDecoder> create(const String& mimeType, const
WTF::TextEncoding& defaultEncoding = WTF::TextEncoding(), bool usesEncodingDetec
tor = false) |
| 51 { | 49 { |
| 52 return wrapUnique(new TextResourceDecoder(mimeType, defaultEncoding, use
sEncodingDetector ? UseAllAutoDetection : UseContentAndBOMBasedDetection)); | 50 return adoptPtr(new TextResourceDecoder(mimeType, defaultEncoding, usesE
ncodingDetector ? UseAllAutoDetection : UseContentAndBOMBasedDetection)); |
| 53 } | 51 } |
| 54 // Corresponds to utf-8 decode in Encoding spec: | 52 // Corresponds to utf-8 decode in Encoding spec: |
| 55 // https://encoding.spec.whatwg.org/#utf-8-decode. | 53 // https://encoding.spec.whatwg.org/#utf-8-decode. |
| 56 static std::unique_ptr<TextResourceDecoder> createAlwaysUseUTF8ForText() | 54 static PassOwnPtr<TextResourceDecoder> createAlwaysUseUTF8ForText() |
| 57 { | 55 { |
| 58 return wrapUnique(new TextResourceDecoder("plain/text", UTF8Encoding(),
AlwaysUseUTF8ForText)); | 56 return adoptPtr(new TextResourceDecoder("plain/text", UTF8Encoding(), Al
waysUseUTF8ForText)); |
| 59 } | 57 } |
| 60 ~TextResourceDecoder(); | 58 ~TextResourceDecoder(); |
| 61 | 59 |
| 62 void setEncoding(const WTF::TextEncoding&, EncodingSource); | 60 void setEncoding(const WTF::TextEncoding&, EncodingSource); |
| 63 const WTF::TextEncoding& encoding() const { return m_encoding; } | 61 const WTF::TextEncoding& encoding() const { return m_encoding; } |
| 64 bool encodingWasDetectedHeuristically() const | 62 bool encodingWasDetectedHeuristically() const |
| 65 { | 63 { |
| 66 return m_source == AutoDetectedEncoding | 64 return m_source == AutoDetectedEncoding |
| 67 || m_source == EncodingFromContentSniffing; | 65 || m_source == EncodingFromContentSniffing; |
| 68 } | 66 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 static ContentType determineContentType(const String& mimeType); | 105 static ContentType determineContentType(const String& mimeType); |
| 108 static const WTF::TextEncoding& defaultEncoding(ContentType, const WTF::Text
Encoding& defaultEncoding); | 106 static const WTF::TextEncoding& defaultEncoding(ContentType, const WTF::Text
Encoding& defaultEncoding); |
| 109 | 107 |
| 110 bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer); | 108 bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer); |
| 111 bool checkForXMLCharset(const char*, size_t, bool& movedDataToBuffer); | 109 bool checkForXMLCharset(const char*, size_t, bool& movedDataToBuffer); |
| 112 void checkForMetaCharset(const char*, size_t); | 110 void checkForMetaCharset(const char*, size_t); |
| 113 bool shouldAutoDetect() const; | 111 bool shouldAutoDetect() const; |
| 114 | 112 |
| 115 ContentType m_contentType; | 113 ContentType m_contentType; |
| 116 WTF::TextEncoding m_encoding; | 114 WTF::TextEncoding m_encoding; |
| 117 std::unique_ptr<TextCodec> m_codec; | 115 OwnPtr<TextCodec> m_codec; |
| 118 EncodingSource m_source; | 116 EncodingSource m_source; |
| 119 const char* m_hintEncoding; | 117 const char* m_hintEncoding; |
| 120 Vector<char> m_buffer; | 118 Vector<char> m_buffer; |
| 121 bool m_checkedForBOM; | 119 bool m_checkedForBOM; |
| 122 bool m_checkedForCSSCharset; | 120 bool m_checkedForCSSCharset; |
| 123 bool m_checkedForXMLCharset; | 121 bool m_checkedForXMLCharset; |
| 124 bool m_checkedForMetaCharset; | 122 bool m_checkedForMetaCharset; |
| 125 bool m_useLenientXMLDecoding; // Don't stop on XML decoding errors. | 123 bool m_useLenientXMLDecoding; // Don't stop on XML decoding errors. |
| 126 bool m_sawError; | 124 bool m_sawError; |
| 127 EncodingDetectionOption m_encodingDetectionOption; | 125 EncodingDetectionOption m_encodingDetectionOption; |
| 128 | 126 |
| 129 std::unique_ptr<HTMLMetaCharsetParser> m_charsetParser; | 127 OwnPtr<HTMLMetaCharsetParser> m_charsetParser; |
| 130 }; | 128 }; |
| 131 | 129 |
| 132 } // namespace blink | 130 } // namespace blink |
| 133 | 131 |
| 134 #endif | 132 #endif |
| OLD | NEW |