| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
| 30 #include "core/fetch/TextResourceDecoder.h" | 30 #include "core/fetch/TextResourceDecoder.h" |
| 31 | 31 |
| 32 namespace WebCore { | 32 namespace WebCore { |
| 33 | 33 |
| 34 DecodedDataDocumentParser::DecodedDataDocumentParser(Document* document) | 34 DecodedDataDocumentParser::DecodedDataDocumentParser(Document* document) |
| 35 : DocumentParser(document) | 35 : DocumentParser(document) |
| 36 { | 36 { |
| 37 } | 37 } |
| 38 | 38 |
| 39 DecodedDataDocumentParser::~DecodedDataDocumentParser() |
| 40 { |
| 41 } |
| 42 |
| 43 void DecodedDataDocumentParser::setDecoder(PassRefPtr<TextResourceDecoder> decod
er) |
| 44 { |
| 45 m_decoder = decoder; |
| 46 } |
| 47 |
| 39 size_t DecodedDataDocumentParser::appendBytes(const char* data, size_t length) | 48 size_t DecodedDataDocumentParser::appendBytes(const char* data, size_t length) |
| 40 { | 49 { |
| 41 if (!length) | 50 if (!length) |
| 42 return 0; | 51 return 0; |
| 43 | 52 |
| 44 // This should be checking isStopped(), but XMLDocumentParser prematurely | 53 // This should be checking isStopped(), but XMLDocumentParser prematurely |
| 45 // stops parsing when handling an XSLT processing instruction and still | 54 // stops parsing when handling an XSLT processing instruction and still |
| 46 // needs to receive decoded bytes. | 55 // needs to receive decoded bytes. |
| 47 if (isDetached()) | 56 if (isDetached()) |
| 48 return 0; | 57 return 0; |
| 49 | 58 |
| 50 String decoded = document()->decoder()->decode(data, length); | 59 String decoded = m_decoder->decode(data, length); |
| 51 document()->setEncoding(document()->decoder()->encoding()); | 60 Document::DocumentEncodingData encodingData; |
| 61 encodingData.encoding = m_decoder->encoding(); |
| 62 encodingData.wasDetectedHeuristically = m_decoder->encodingWasDetectedHeuris
tically(); |
| 63 encodingData.sawDecodingError = m_decoder->sawError(); |
| 64 document()->setEncoding(encodingData); |
| 52 | 65 |
| 53 if (decoded.isEmpty()) | 66 if (decoded.isEmpty()) |
| 54 return 0; | 67 return 0; |
| 55 | 68 |
| 56 size_t consumedChars = decoded.length(); | 69 size_t consumedChars = decoded.length(); |
| 57 append(decoded.releaseImpl()); | 70 append(decoded.releaseImpl()); |
| 58 | 71 |
| 59 return consumedChars; | 72 return consumedChars; |
| 60 } | 73 } |
| 61 | 74 |
| 62 size_t DecodedDataDocumentParser::flush() | 75 size_t DecodedDataDocumentParser::flush() |
| 63 { | 76 { |
| 64 // This should be checking isStopped(), but XMLDocumentParser prematurely | 77 // This should be checking isStopped(), but XMLDocumentParser prematurely |
| 65 // stops parsing when handling an XSLT processing instruction and still | 78 // stops parsing when handling an XSLT processing instruction and still |
| 66 // needs to receive decoded bytes. | 79 // needs to receive decoded bytes. |
| 67 if (isDetached()) | 80 if (isDetached()) |
| 68 return 0; | 81 return 0; |
| 69 | 82 |
| 70 // null decoder indicates there is no data received. | 83 // null decoder indicates there is no data received. |
| 71 // We have nothing to do in that case. | 84 // We have nothing to do in that case. |
| 72 TextResourceDecoder* decoder = document()->decoder(); | 85 if (!m_decoder) |
| 73 if (!decoder) | |
| 74 return 0; | 86 return 0; |
| 75 String remainingData = decoder->flush(); | 87 String remainingData = m_decoder->flush(); |
| 76 document()->setEncoding(document()->decoder()->encoding()); | 88 Document::DocumentEncodingData encodingData; |
| 89 encodingData.encoding = m_decoder->encoding(); |
| 90 encodingData.wasDetectedHeuristically = m_decoder->encodingWasDetectedHeuris
tically(); |
| 91 encodingData.sawDecodingError = m_decoder->sawError(); |
| 92 document()->setEncoding(encodingData); |
| 93 |
| 77 if (remainingData.isEmpty()) | 94 if (remainingData.isEmpty()) |
| 78 return 0; | 95 return 0; |
| 79 | 96 |
| 80 size_t consumedChars = remainingData.length(); | 97 size_t consumedChars = remainingData.length(); |
| 81 append(remainingData.releaseImpl()); | 98 append(remainingData.releaseImpl()); |
| 82 | 99 |
| 83 return consumedChars; | 100 return consumedChars; |
| 84 } | 101 } |
| 85 | 102 |
| 86 }; | 103 }; |
| OLD | NEW |