| 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
rights reserved. | 3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All
rights reserved. |
| 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 // in the first place. | 410 // in the first place. |
| 411 // We also check if the text is encoded in UTF-8 in case the encoding has not | 411 // We also check if the text is encoded in UTF-8 in case the encoding has not |
| 412 // been determined by auto encoding detector (optional). Then |m_source| needs | 412 // been determined by auto encoding detector (optional). Then |m_source| needs |
| 413 // to be set to anything but DefaultEncoding to avoid further detection | 413 // to be set to anything but DefaultEncoding to avoid further detection |
| 414 // attempts. | 414 // attempts. |
| 415 void TextResourceDecoder::detectTextEncoding(const char* data, size_t len) | 415 void TextResourceDecoder::detectTextEncoding(const char* data, size_t len) |
| 416 { | 416 { |
| 417 if (!shouldDetectEncoding()) | 417 if (!shouldDetectEncoding()) |
| 418 return; | 418 return; |
| 419 | 419 |
| 420 if (m_encodingDetectionOption == UseAllAutoDetection) { | 420 if (true || m_encodingDetectionOption == UseAllAutoDetection) { |
| 421 WTF::TextEncoding detectedEncoding; | 421 WTF::TextEncoding detectedEncoding; |
| 422 if (detectTextEncodingUniversal(data, len, m_hintEncoding, &detectedEnco
ding)) { | 422 if (detectTextEncodingUniversal(data, len, m_hintEncoding, &detectedEnco
ding)) { |
| 423 setEncoding(detectedEncoding, EncodingFromContentSniffing); | 423 setEncoding(detectedEncoding, EncodingFromContentSniffing); |
| 424 return; | 424 return; |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 | 427 |
| 428 if (WTF::Unicode::isUTF8andNotASCII(data, len)) | 428 if (WTF::Unicode::isUTF8andNotASCII(data, len)) |
| 429 setEncoding(UTF8Encoding(), EncodingFromContentSniffing); | 429 setEncoding(UTF8Encoding(), EncodingFromContentSniffing); |
| 430 else | 430 else |
| 431 m_source = EncodingFromContentSniffing; | 431 m_source = EncodingFromContentSniffing; |
| 432 } | 432 } |
| 433 | 433 |
| 434 bool TextResourceDecoder::shouldDetectEncoding() const | 434 bool TextResourceDecoder::shouldDetectEncoding() const |
| 435 { | 435 { |
| 436 // Just checking m_hintEncoding suffices here because it's only set | 436 // Just checking m_hintEncoding suffices here because it's only set |
| 437 // in setHintEncoding when the source is AutoDetectedEncoding. | 437 // in setHintEncoding when the source is AutoDetectedEncoding. |
| 438 return m_source == DefaultEncoding || (m_source == EncodingFromParentFrame &
& m_hintEncoding); | 438 return true; // m_source == DefaultEncoding || (m_source == EncodingFromPare
ntFrame && m_hintEncoding); |
| 439 } | 439 } |
| 440 | 440 |
| 441 String TextResourceDecoder::flush() | 441 String TextResourceDecoder::flush() |
| 442 { | 442 { |
| 443 // If we can not identify the encoding even after a document is completely | 443 // If we can not identify the encoding even after a document is completely |
| 444 // loaded, we need to detect the encoding if other conditions for | 444 // loaded, we need to detect the encoding if other conditions for |
| 445 // autodetection is satisfied. | 445 // autodetection is satisfied. |
| 446 if (m_buffer.size() | 446 if (m_buffer.size() |
| 447 && ((!m_checkedForXMLCharset && (m_contentType == HTMLContent || m_conte
ntType == XMLContent)) || (!m_checkedForCSSCharset && (m_contentType == CSSConte
nt)))) { | 447 && ((!m_checkedForXMLCharset && (m_contentType == HTMLContent || m_conte
ntType == XMLContent)) || (!m_checkedForCSSCharset && (m_contentType == CSSConte
nt)))) { |
| 448 detectTextEncoding(m_buffer.data(), m_buffer.size()); | 448 detectTextEncoding(m_buffer.data(), m_buffer.size()); |
| 449 } | 449 } |
| 450 | 450 |
| 451 if (!m_codec) | 451 if (!m_codec) |
| 452 m_codec = newTextCodec(m_encoding); | 452 m_codec = newTextCodec(m_encoding); |
| 453 | 453 |
| 454 String result = m_codec->decode(m_buffer.data(), m_buffer.size(), FetchEOF,
m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); | 454 String result = m_codec->decode(m_buffer.data(), m_buffer.size(), FetchEOF,
m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); |
| 455 m_buffer.clear(); | 455 m_buffer.clear(); |
| 456 m_codec.clear(); | 456 m_codec.clear(); |
| 457 m_checkedForBOM = false; // Skip BOM again when re-decoding. | 457 m_checkedForBOM = false; // Skip BOM again when re-decoding. |
| 458 return result; | 458 return result; |
| 459 } | 459 } |
| 460 | 460 |
| 461 } // namespace blink | 461 } // namespace blink |
| OLD | NEW |