Chromium Code Reviews| 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 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #ifndef TextResourceDecoder_h | 23 #ifndef TextResourceDecoder_h |
| 24 #define TextResourceDecoder_h | 24 #define TextResourceDecoder_h |
| 25 | 25 |
| 26 #include "wtf/RefCounted.h" | 26 #include "wtf/RefCounted.h" |
| 27 #include "wtf/text/TextEncoding.h" | 27 #include "wtf/text/TextEncoding.h" |
| 28 | 28 |
| 29 namespace WebCore { | 29 namespace WebCore { |
| 30 | 30 |
| 31 struct DocumentEncodingData; | |
| 31 class HTMLMetaCharsetParser; | 32 class HTMLMetaCharsetParser; |
| 32 | 33 |
| 33 class TextResourceDecoder { | 34 class TextResourceDecoder { |
| 34 public: | 35 public: |
| 35 enum EncodingSource { | 36 enum EncodingSource { |
| 36 DefaultEncoding, | 37 DefaultEncoding, |
| 37 AutoDetectedEncoding, | 38 AutoDetectedEncoding, |
| 38 EncodingFromContentSniffing, | 39 EncodingFromContentSniffing, |
| 39 EncodingFromXMLHeader, | 40 EncodingFromXMLHeader, |
| 40 EncodingFromMetaTag, | 41 EncodingFromMetaTag, |
| 41 EncodingFromCSSCharset, | 42 EncodingFromCSSCharset, |
| 42 EncodingFromHTTPHeader, | 43 EncodingFromHTTPHeader, |
| 43 UserChosenEncoding, | 44 UserChosenEncoding, |
| 44 EncodingFromParentFrame | 45 EncodingFromParentFrame |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 static PassOwnPtr<TextResourceDecoder> create(const String& mimeType, const WTF::TextEncoding& defaultEncoding = WTF::TextEncoding(), bool usesEncodingDetec tor = false) | 48 static PassOwnPtr<TextResourceDecoder> create(const String& mimeType, const WTF::TextEncoding& defaultEncoding = WTF::TextEncoding(), bool usesEncodingDetec tor = false) |
| 48 { | 49 { |
| 49 return adoptPtr(new TextResourceDecoder(mimeType, defaultEncoding, usesE ncodingDetector)); | 50 return adoptPtr(new TextResourceDecoder(mimeType, defaultEncoding, usesE ncodingDetector)); |
| 50 } | 51 } |
| 51 ~TextResourceDecoder(); | 52 ~TextResourceDecoder(); |
| 52 | 53 |
| 53 void setEncoding(const WTF::TextEncoding&, EncodingSource); | 54 void setEncoding(const WTF::TextEncoding&, EncodingSource); |
| 54 const WTF::TextEncoding& encoding() const { return m_encoding; } | 55 const WTF::TextEncoding& encoding() const { return m_encoding; } |
| 55 bool encodingWasDetectedHeuristically() const | |
| 56 { | |
| 57 return m_source == AutoDetectedEncoding | |
| 58 || m_source == EncodingFromContentSniffing; | |
| 59 } | |
| 60 | 56 |
| 61 String decode(const char* data, size_t length); | 57 String decode(const char* data, size_t length); |
| 62 String flush(); | 58 String flush(); |
| 63 | 59 |
| 64 void setHintEncoding(const WTF::TextEncoding& encoding) | 60 void setHintEncoding(const WTF::TextEncoding& encoding) |
| 65 { | 61 { |
| 66 m_hintEncoding = encoding.name(); | 62 m_hintEncoding = encoding.name(); |
| 67 } | 63 } |
| 68 | 64 |
| 69 void useLenientXMLDecoding() { m_useLenientXMLDecoding = true; } | 65 void useLenientXMLDecoding() { m_useLenientXMLDecoding = true; } |
| 70 bool sawError() const { return m_sawError; } | 66 bool sawError() const { return m_sawError; } |
| 67 void getEncodingData(DocumentEncodingData&) const; | |
|
eseidel
2013/11/18 22:32:07
"get" methods are uncommon in Blink. Is there a r
oystein (OOO til 10th of July)
2013/11/18 22:36:46
It's copyable, it'd just add the need for the full
| |
| 71 | 68 |
| 72 private: | 69 private: |
| 73 TextResourceDecoder(const String& mimeType, const WTF::TextEncoding& default Encoding, bool usesEncodingDetector); | 70 TextResourceDecoder(const String& mimeType, const WTF::TextEncoding& default Encoding, bool usesEncodingDetector); |
| 74 | 71 |
| 75 enum ContentType { PlainText, HTML, XML, CSS }; // PlainText only checks for BOM. | 72 enum ContentType { PlainText, HTML, XML, CSS }; // PlainText only checks for BOM. |
| 76 static ContentType determineContentType(const String& mimeType); | 73 static ContentType determineContentType(const String& mimeType); |
| 77 static const WTF::TextEncoding& defaultEncoding(ContentType, const WTF::Text Encoding& defaultEncoding); | 74 static const WTF::TextEncoding& defaultEncoding(ContentType, const WTF::Text Encoding& defaultEncoding); |
| 78 | 75 |
| 79 size_t checkForBOM(const char*, size_t); | 76 size_t checkForBOM(const char*, size_t); |
| 80 bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer); | 77 bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer); |
| 81 bool checkForXMLCharset(const char*, size_t, bool& movedDataToBuffer); | 78 bool checkForXMLCharset(const char*, size_t, bool& movedDataToBuffer); |
| 82 void checkForMetaCharset(const char*, size_t); | 79 void checkForMetaCharset(const char*, size_t); |
| 83 void detectJapaneseEncoding(const char*, size_t); | 80 void detectJapaneseEncoding(const char*, size_t); |
| 84 bool shouldAutoDetect() const; | 81 bool shouldAutoDetect() const; |
| 85 | 82 |
| 83 bool encodingWasDetectedHeuristically() const | |
| 84 { | |
| 85 return m_source == AutoDetectedEncoding | |
| 86 || m_source == EncodingFromContentSniffing; | |
| 87 } | |
| 88 | |
| 89 | |
| 86 ContentType m_contentType; | 90 ContentType m_contentType; |
| 87 WTF::TextEncoding m_encoding; | 91 WTF::TextEncoding m_encoding; |
| 88 OwnPtr<TextCodec> m_codec; | 92 OwnPtr<TextCodec> m_codec; |
| 89 EncodingSource m_source; | 93 EncodingSource m_source; |
| 90 const char* m_hintEncoding; | 94 const char* m_hintEncoding; |
| 91 Vector<char> m_buffer; | 95 Vector<char> m_buffer; |
| 92 bool m_checkedForBOM; | 96 bool m_checkedForBOM; |
| 93 bool m_checkedForCSSCharset; | 97 bool m_checkedForCSSCharset; |
| 94 bool m_checkedForXMLCharset; | 98 bool m_checkedForXMLCharset; |
| 95 bool m_checkedForMetaCharset; | 99 bool m_checkedForMetaCharset; |
| 96 bool m_useLenientXMLDecoding; // Don't stop on XML decoding errors. | 100 bool m_useLenientXMLDecoding; // Don't stop on XML decoding errors. |
| 97 bool m_sawError; | 101 bool m_sawError; |
| 98 bool m_usesEncodingDetector; | 102 bool m_usesEncodingDetector; |
| 99 | 103 |
| 100 OwnPtr<HTMLMetaCharsetParser> m_charsetParser; | 104 OwnPtr<HTMLMetaCharsetParser> m_charsetParser; |
| 101 }; | 105 }; |
| 102 | 106 |
| 103 } | 107 } |
| 104 | 108 |
| 105 #endif | 109 #endif |
| OLD | NEW |