Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/dom/DecodedDataDocumentParser.h" | 27 #include "core/dom/DecodedDataDocumentParser.h" |
| 28 | 28 |
| 29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
| 30 #include "core/dom/DocumentEncodingData.h" | |
| 30 #include "core/fetch/TextResourceDecoder.h" | 31 #include "core/fetch/TextResourceDecoder.h" |
| 31 | 32 |
| 32 namespace WebCore { | 33 namespace WebCore { |
| 33 | 34 |
| 34 DecodedDataDocumentParser::DecodedDataDocumentParser(Document* document) | 35 DecodedDataDocumentParser::DecodedDataDocumentParser(Document* document) |
| 35 : DocumentParser(document) | 36 : DocumentParser(document) |
| 36 { | 37 { |
| 37 } | 38 } |
| 38 | 39 |
| 40 DecodedDataDocumentParser::~DecodedDataDocumentParser() | |
| 41 { | |
| 42 } | |
| 43 | |
| 44 void DecodedDataDocumentParser::setDecoder(PassRefPtr<TextResourceDecoder> decod er) | |
| 45 { | |
| 46 m_decoder = decoder; | |
| 47 } | |
| 48 | |
| 39 size_t DecodedDataDocumentParser::appendBytes(const char* data, size_t length) | 49 size_t DecodedDataDocumentParser::appendBytes(const char* data, size_t length) |
| 40 { | 50 { |
| 41 if (!length) | 51 if (!length) |
| 42 return 0; | 52 return 0; |
| 43 | 53 |
| 44 // This should be checking isStopped(), but XMLDocumentParser prematurely | 54 // This should be checking isStopped(), but XMLDocumentParser prematurely |
| 45 // stops parsing when handling an XSLT processing instruction and still | 55 // stops parsing when handling an XSLT processing instruction and still |
| 46 // needs to receive decoded bytes. | 56 // needs to receive decoded bytes. |
| 47 if (isDetached()) | 57 if (isDetached()) |
| 48 return 0; | 58 return 0; |
| 49 | 59 |
| 50 String decoded = document()->decoder()->decode(data, length); | 60 String decoded = m_decoder->decode(data, length); |
| 51 document()->setEncoding(document()->decoder()->encoding()); | 61 updateDocumentEncoding(); |
| 52 | 62 |
| 53 if (decoded.isEmpty()) | 63 if (decoded.isEmpty()) |
| 54 return 0; | 64 return 0; |
| 55 | 65 |
| 56 size_t consumedChars = decoded.length(); | 66 size_t consumedChars = decoded.length(); |
| 57 append(decoded.releaseImpl()); | 67 append(decoded.releaseImpl()); |
| 58 | 68 |
| 59 return consumedChars; | 69 return consumedChars; |
| 60 } | 70 } |
| 61 | 71 |
| 62 size_t DecodedDataDocumentParser::flush() | 72 size_t DecodedDataDocumentParser::flush() |
| 63 { | 73 { |
| 64 // This should be checking isStopped(), but XMLDocumentParser prematurely | 74 // This should be checking isStopped(), but XMLDocumentParser prematurely |
| 65 // stops parsing when handling an XSLT processing instruction and still | 75 // stops parsing when handling an XSLT processing instruction and still |
| 66 // needs to receive decoded bytes. | 76 // needs to receive decoded bytes. |
| 67 if (isDetached()) | 77 if (isDetached()) |
| 68 return 0; | 78 return 0; |
| 69 | 79 |
| 70 // null decoder indicates there is no data received. | 80 // null decoder indicates there is no data received. |
| 71 // We have nothing to do in that case. | 81 // We have nothing to do in that case. |
| 72 TextResourceDecoder* decoder = document()->decoder(); | 82 if (!m_decoder) |
| 73 if (!decoder) | |
| 74 return 0; | 83 return 0; |
| 75 String remainingData = decoder->flush(); | 84 String remainingData = m_decoder->flush(); |
| 76 document()->setEncoding(document()->decoder()->encoding()); | 85 updateDocumentEncoding(); |
| 86 | |
| 77 if (remainingData.isEmpty()) | 87 if (remainingData.isEmpty()) |
| 78 return 0; | 88 return 0; |
| 79 | 89 |
| 80 size_t consumedChars = remainingData.length(); | 90 size_t consumedChars = remainingData.length(); |
| 81 append(remainingData.releaseImpl()); | 91 append(remainingData.releaseImpl()); |
| 82 | 92 |
| 83 return consumedChars; | 93 return consumedChars; |
| 84 } | 94 } |
| 85 | 95 |
| 96 void DecodedDataDocumentParser::updateDocumentEncoding() | |
| 97 { | |
| 98 DocumentEncodingData encodingData; | |
| 99 encodingData.encoding = m_decoder->encoding(); | |
| 100 encodingData.wasDetectedHeuristically = m_decoder->encodingWasDetectedHeuris tically(); | |
| 101 encodingData.sawDecodingError = m_decoder->sawError(); | |
| 102 document()->setEncodingData(encodingData); | |
|
abarth-chromium
2013/11/14 07:04:33
Looks like we call this unconditionally every time
oystein (OOO til 10th of July)
2013/11/14 19:02:29
We could check, but I don't think it would really
| |
| 103 } | |
| 104 | |
| 86 }; | 105 }; |
| OLD | NEW |