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 13 matching lines...) Expand all Loading... |
24 | 24 |
25 #include "core/HTMLNames.h" | 25 #include "core/HTMLNames.h" |
26 #include "core/dom/DOMImplementation.h" | 26 #include "core/dom/DOMImplementation.h" |
27 #include "core/html/parser/HTMLMetaCharsetParser.h" | 27 #include "core/html/parser/HTMLMetaCharsetParser.h" |
28 #include "platform/Language.h" | 28 #include "platform/Language.h" |
29 #include "platform/text/TextEncodingDetector.h" | 29 #include "platform/text/TextEncodingDetector.h" |
30 #include "wtf/StringExtras.h" | 30 #include "wtf/StringExtras.h" |
31 #include "wtf/text/TextCodec.h" | 31 #include "wtf/text/TextCodec.h" |
32 #include "wtf/text/TextEncodingRegistry.h" | 32 #include "wtf/text/TextEncodingRegistry.h" |
33 | 33 |
34 using namespace WTF; | |
35 | |
36 namespace blink { | 34 namespace blink { |
37 | 35 |
38 using namespace HTMLNames; | 36 using namespace HTMLNames; |
39 | 37 |
40 const int minimumLengthOfXMLDeclaration = 8; | 38 const int minimumLengthOfXMLDeclaration = 8; |
41 | 39 |
42 static inline bool bytesEqual(const char* p, | 40 static inline bool bytesEqual(const char* p, |
43 char b0, | 41 char b0, |
44 char b1, | 42 char b1, |
45 char b2, | 43 char b2, |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 m_hintLanguage, &detectedEncoding)) | 476 m_hintLanguage, &detectedEncoding)) |
479 setEncoding(detectedEncoding, EncodingFromContentSniffing); | 477 setEncoding(detectedEncoding, EncodingFromContentSniffing); |
480 } | 478 } |
481 | 479 |
482 ASSERT(m_encoding.isValid()); | 480 ASSERT(m_encoding.isValid()); |
483 | 481 |
484 if (!m_codec) | 482 if (!m_codec) |
485 m_codec = newTextCodec(m_encoding); | 483 m_codec = newTextCodec(m_encoding); |
486 | 484 |
487 String result = m_codec->decode( | 485 String result = m_codec->decode( |
488 dataForDecode, lengthForDecode, DoNotFlush, | 486 dataForDecode, lengthForDecode, WTF::DoNotFlush, |
489 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); | 487 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); |
490 | 488 |
491 m_buffer.clear(); | 489 m_buffer.clear(); |
492 return result; | 490 return result; |
493 } | 491 } |
494 | 492 |
495 String TextResourceDecoder::flush() { | 493 String TextResourceDecoder::flush() { |
496 // If we can not identify the encoding even after a document is completely | 494 // If we can not identify the encoding even after a document is completely |
497 // loaded, we need to detect the encoding if other conditions for | 495 // loaded, we need to detect the encoding if other conditions for |
498 // autodetection is satisfied. | 496 // autodetection is satisfied. |
499 if (m_buffer.size() && shouldAutoDetect() && | 497 if (m_buffer.size() && shouldAutoDetect() && |
500 ((!m_checkedForXMLCharset && | 498 ((!m_checkedForXMLCharset && |
501 (m_contentType == HTMLContent || m_contentType == XMLContent)) || | 499 (m_contentType == HTMLContent || m_contentType == XMLContent)) || |
502 (!m_checkedForCSSCharset && (m_contentType == CSSContent)))) { | 500 (!m_checkedForCSSCharset && (m_contentType == CSSContent)))) { |
503 WTF::TextEncoding detectedEncoding; | 501 WTF::TextEncoding detectedEncoding; |
504 if (detectTextEncoding(m_buffer.data(), m_buffer.size(), m_hintEncoding, | 502 if (detectTextEncoding(m_buffer.data(), m_buffer.size(), m_hintEncoding, |
505 m_hintUrl.data(), m_hintLanguage, &detectedEncoding)) | 503 m_hintUrl.data(), m_hintLanguage, &detectedEncoding)) |
506 setEncoding(detectedEncoding, EncodingFromContentSniffing); | 504 setEncoding(detectedEncoding, EncodingFromContentSniffing); |
507 } | 505 } |
508 | 506 |
509 if (!m_codec) | 507 if (!m_codec) |
510 m_codec = newTextCodec(m_encoding); | 508 m_codec = newTextCodec(m_encoding); |
511 | 509 |
512 String result = m_codec->decode( | 510 String result = m_codec->decode( |
513 m_buffer.data(), m_buffer.size(), FetchEOF, | 511 m_buffer.data(), m_buffer.size(), WTF::FetchEOF, |
514 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); | 512 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); |
515 m_buffer.clear(); | 513 m_buffer.clear(); |
516 m_codec.reset(); | 514 m_codec.reset(); |
517 m_checkedForBOM = false; // Skip BOM again when re-decoding. | 515 m_checkedForBOM = false; // Skip BOM again when re-decoding. |
518 return result; | 516 return result; |
519 } | 517 } |
520 | 518 |
521 } // namespace blink | 519 } // namespace blink |
OLD | NEW |