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) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reser
ved. | 3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reser
ved. |
4 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com) | 4 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com) |
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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 324 } |
325 | 325 |
326 TextResourceDecoder::TextResourceDecoder(const String& mimeType, const TextEncod
ing& specifiedDefaultEncoding, bool usesEncodingDetector, const TextResourceDeco
der* hintDecoder) | 326 TextResourceDecoder::TextResourceDecoder(const String& mimeType, const TextEncod
ing& specifiedDefaultEncoding, bool usesEncodingDetector, const TextResourceDeco
der* hintDecoder) |
327 : m_contentType(determineContentType(mimeType)) | 327 : m_contentType(determineContentType(mimeType)) |
328 , m_decoder(defaultEncoding(m_contentType, specifiedDefaultEncoding)) | 328 , m_decoder(defaultEncoding(m_contentType, specifiedDefaultEncoding)) |
329 , m_hintDecoder(hintDecoder) | 329 , m_hintDecoder(hintDecoder) |
330 , m_source(DefaultEncoding) | 330 , m_source(DefaultEncoding) |
331 , m_checkedForBOM(false) | 331 , m_checkedForBOM(false) |
332 , m_checkedForCSSCharset(false) | 332 , m_checkedForCSSCharset(false) |
333 , m_checkedForHeadCharset(false) | 333 , m_checkedForHeadCharset(false) |
| 334 , m_useLenientXMLDecoding(false) |
334 , m_sawError(false) | 335 , m_sawError(false) |
335 , m_usesEncodingDetector(usesEncodingDetector) | 336 , m_usesEncodingDetector(usesEncodingDetector) |
336 { | 337 { |
337 } | 338 } |
338 | 339 |
339 TextResourceDecoder::~TextResourceDecoder() | 340 TextResourceDecoder::~TextResourceDecoder() |
340 { | 341 { |
341 } | 342 } |
342 | 343 |
343 void TextResourceDecoder::setEncoding(const TextEncoding& encoding, EncodingSour
ce source) | 344 void TextResourceDecoder::setEncoding(const TextEncoding& encoding, EncodingSour
ce source) |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 | 868 |
868 if (m_buffer.isEmpty()) | 869 if (m_buffer.isEmpty()) |
869 return m_decoder.decode(data, len, false, m_contentType == XML, m_sawErr
or); | 870 return m_decoder.decode(data, len, false, m_contentType == XML, m_sawErr
or); |
870 | 871 |
871 if (!movedDataToBuffer) { | 872 if (!movedDataToBuffer) { |
872 size_t oldSize = m_buffer.size(); | 873 size_t oldSize = m_buffer.size(); |
873 m_buffer.grow(oldSize + len); | 874 m_buffer.grow(oldSize + len); |
874 memcpy(m_buffer.data() + oldSize, data, len); | 875 memcpy(m_buffer.data() + oldSize, data, len); |
875 } | 876 } |
876 | 877 |
877 String result = m_decoder.decode(m_buffer.data(), m_buffer.size(), false, m_
contentType == XML, m_sawError); | 878 String result = m_decoder.decode(m_buffer.data(), m_buffer.size(), false, m_
contentType == XML && !m_useLenientXMLDecoding, m_sawError); |
878 m_buffer.clear(); | 879 m_buffer.clear(); |
879 return result; | 880 return result; |
880 } | 881 } |
881 | 882 |
882 String TextResourceDecoder::flush() | 883 String TextResourceDecoder::flush() |
883 { | 884 { |
884 // For HTML and XML document, if we can not find proper encoding even | 885 String result = m_decoder.decode(m_buffer.data(), m_buffer.size(), true, m_c
ontentType == XML && !m_useLenientXMLDecoding, m_sawError); |
885 // document is completely loaded, we need to use automatically detect | 886 // document is completely loaded, we need to use automatically detect |
886 // the encoding of document if user has enabled this option. | 887 // the encoding of document if user has enabled this option. |
887 if (m_buffer.size() && !m_checkedForHeadCharset && | 888 if (m_buffer.size() && !m_checkedForHeadCharset && |
888 (m_contentType == HTML || m_contentType == XML) && | 889 (m_contentType == HTML || m_contentType == XML) && |
889 ((m_usesEncodingDetector && m_source == DefaultEncoding) || | 890 ((m_usesEncodingDetector && m_source == DefaultEncoding) || |
890 (m_source == EncodingFromParentFrame && m_hintDecoder && | 891 (m_source == EncodingFromParentFrame && m_hintDecoder && |
891 m_hintDecoder->source() == AutoDetectedEncoding))) | 892 m_hintDecoder->source() == AutoDetectedEncoding))) |
892 detectEncoding(m_buffer.data(), m_buffer.size()); | 893 detectEncoding(m_buffer.data(), m_buffer.size()); |
893 | 894 |
894 String result = m_decoder.decode(m_buffer.data(), m_buffer.size(), true, m_c
ontentType == XML, m_sawError); | |
895 m_buffer.clear(); | 895 m_buffer.clear(); |
896 m_decoder.reset(m_decoder.encoding()); | 896 m_decoder.reset(m_decoder.encoding()); |
897 return result; | 897 return result; |
898 } | 898 } |
899 | 899 |
900 } | 900 } |
901 | 901 |
OLD | NEW |