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, 2009, 2012 Apple Inc. All | 3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All |
4 rights reserved. | 4 rights reserved. |
5 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com) | 5 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com) |
6 | 6 |
7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 m_hintUrl(url.utf8()), | 150 m_hintUrl(url.utf8()), |
151 m_checkedForBOM(false), | 151 m_checkedForBOM(false), |
152 m_checkedForCSSCharset(false), | 152 m_checkedForCSSCharset(false), |
153 m_checkedForXMLCharset(false), | 153 m_checkedForXMLCharset(false), |
154 m_checkedForMetaCharset(false), | 154 m_checkedForMetaCharset(false), |
155 m_useLenientXMLDecoding(false), | 155 m_useLenientXMLDecoding(false), |
156 m_sawError(false), | 156 m_sawError(false), |
157 m_encodingDetectionOption(encodingDetectionOption) { | 157 m_encodingDetectionOption(encodingDetectionOption) { |
158 m_hintLanguage[0] = 0; | 158 m_hintLanguage[0] = 0; |
159 if (m_encodingDetectionOption == AlwaysUseUTF8ForText) { | 159 if (m_encodingDetectionOption == AlwaysUseUTF8ForText) { |
160 ASSERT(m_contentType == PlainTextContent && m_encoding == UTF8Encoding()); | 160 DCHECK(m_contentType == PlainTextContent && m_encoding == UTF8Encoding()); |
161 } else if (m_encodingDetectionOption == UseAllAutoDetection) { | 161 } else if (m_encodingDetectionOption == UseAllAutoDetection) { |
162 // Checking empty URL helps unit testing. Providing defaultLanguage() is | 162 // Checking empty URL helps unit testing. Providing defaultLanguage() is |
163 // sometimes difficult in tests. | 163 // sometimes difficult in tests. |
164 if (!url.isEmpty()) { | 164 if (!url.isEmpty()) { |
165 // This object is created in the main thread, but used in another thread. | 165 // This object is created in the main thread, but used in another thread. |
166 // We should not share an AtomicString. | 166 // We should not share an AtomicString. |
167 AtomicString locale = defaultLanguage(); | 167 AtomicString locale = defaultLanguage(); |
168 if (locale.length() >= 2) { | 168 if (locale.length() >= 2) { |
169 // defaultLanguage() is always an ASCII string. | 169 // defaultLanguage() is always an ASCII string. |
170 m_hintLanguage[0] = static_cast<char>(locale[0]); | 170 m_hintLanguage[0] = static_cast<char>(locale[0]); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (end >= len) | 234 if (end >= len) |
235 return -1; | 235 return -1; |
236 | 236 |
237 encodingLength = end - pos; | 237 encodingLength = end - pos; |
238 return pos; | 238 return pos; |
239 } | 239 } |
240 | 240 |
241 size_t TextResourceDecoder::checkForBOM(const char* data, size_t len) { | 241 size_t TextResourceDecoder::checkForBOM(const char* data, size_t len) { |
242 // Check for UTF-16/32 or UTF-8 BOM mark at the beginning, which is a sure | 242 // Check for UTF-16/32 or UTF-8 BOM mark at the beginning, which is a sure |
243 // sign of a Unicode encoding. We let it override even a user-chosen encoding. | 243 // sign of a Unicode encoding. We let it override even a user-chosen encoding. |
244 ASSERT(!m_checkedForBOM); | 244 DCHECK(!m_checkedForBOM); |
245 | 245 |
246 size_t lengthOfBOM = 0; | 246 size_t lengthOfBOM = 0; |
247 | 247 |
248 size_t bufferLength = m_buffer.size(); | 248 size_t bufferLength = m_buffer.size(); |
249 | 249 |
250 size_t buf1Len = bufferLength; | 250 size_t buf1Len = bufferLength; |
251 size_t buf2Len = len; | 251 size_t buf2Len = len; |
252 const unsigned char* buf1 = | 252 const unsigned char* buf1 = |
253 reinterpret_cast<const unsigned char*>(m_buffer.data()); | 253 reinterpret_cast<const unsigned char*>(m_buffer.data()); |
254 const unsigned char* buf2 = reinterpret_cast<const unsigned char*>(data); | 254 const unsigned char* buf2 = reinterpret_cast<const unsigned char*>(data); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 if (m_contentType == HTMLContent && !m_checkedForMetaCharset) | 470 if (m_contentType == HTMLContent && !m_checkedForMetaCharset) |
471 checkForMetaCharset(dataForDecode, lengthForDecode); | 471 checkForMetaCharset(dataForDecode, lengthForDecode); |
472 | 472 |
473 if (shouldAutoDetect()) { | 473 if (shouldAutoDetect()) { |
474 WTF::TextEncoding detectedEncoding; | 474 WTF::TextEncoding detectedEncoding; |
475 if (detectTextEncoding(data, len, m_hintEncoding, m_hintUrl.data(), | 475 if (detectTextEncoding(data, len, m_hintEncoding, m_hintUrl.data(), |
476 m_hintLanguage, &detectedEncoding)) | 476 m_hintLanguage, &detectedEncoding)) |
477 setEncoding(detectedEncoding, EncodingFromContentSniffing); | 477 setEncoding(detectedEncoding, EncodingFromContentSniffing); |
478 } | 478 } |
479 | 479 |
480 ASSERT(m_encoding.isValid()); | 480 DCHECK(m_encoding.isValid()); |
481 | 481 |
482 if (!m_codec) | 482 if (!m_codec) |
483 m_codec = newTextCodec(m_encoding); | 483 m_codec = newTextCodec(m_encoding); |
484 | 484 |
485 String result = m_codec->decode( | 485 String result = m_codec->decode( |
486 dataForDecode, lengthForDecode, WTF::DoNotFlush, | 486 dataForDecode, lengthForDecode, WTF::DoNotFlush, |
487 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); | 487 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); |
488 | 488 |
489 m_buffer.clear(); | 489 m_buffer.clear(); |
490 return result; | 490 return result; |
(...skipping 19 matching lines...) Expand all Loading... |
510 String result = m_codec->decode( | 510 String result = m_codec->decode( |
511 m_buffer.data(), m_buffer.size(), WTF::FetchEOF, | 511 m_buffer.data(), m_buffer.size(), WTF::FetchEOF, |
512 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); | 512 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); |
513 m_buffer.clear(); | 513 m_buffer.clear(); |
514 m_codec.reset(); | 514 m_codec.reset(); |
515 m_checkedForBOM = false; // Skip BOM again when re-decoding. | 515 m_checkedForBOM = false; // Skip BOM again when re-decoding. |
516 return result; | 516 return result; |
517 } | 517 } |
518 | 518 |
519 } // namespace blink | 519 } // namespace blink |
OLD | NEW |