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 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 titleElement->setTextContent(correctlyDecodedTitle, IGNORE_EXCEPTION); | 78 titleElement->setTextContent(correctlyDecodedTitle, IGNORE_EXCEPTION); |
| 79 } | 79 } |
| 80 | 80 |
| 81 } | 81 } |
| 82 | 82 |
| 83 DecodedDataDocumentParser::DecodedDataDocumentParser(Document* document) | 83 DecodedDataDocumentParser::DecodedDataDocumentParser(Document* document) |
| 84 : DocumentParser(document) | 84 : DocumentParser(document) |
| 85 { | 85 { |
| 86 } | 86 } |
| 87 | 87 |
| 88 DecodedDataDocumentParser::~DecodedDataDocumentParser() | |
| 89 { | |
| 90 } | |
| 91 | |
| 92 void DecodedDataDocumentParser::setDecoder(PassRefPtr<TextResourceDecoder> decod er) | |
| 93 { | |
| 94 m_decoder = decoder; | |
| 95 } | |
| 96 | |
| 88 size_t DecodedDataDocumentParser::appendBytes(const char* data, size_t length) | 97 size_t DecodedDataDocumentParser::appendBytes(const char* data, size_t length) |
| 89 { | 98 { |
| 90 if (!length) | 99 if (!length) |
| 91 return 0; | 100 return 0; |
| 92 | 101 |
| 93 TitleEncodingFixer encodingFixer(document()); | 102 TitleEncodingFixer encodingFixer(document()); |
| 94 | 103 |
| 95 String decoded = document()->decoder()->decode(data, length); | 104 String decoded = m_decoder->decode(data, length); |
| 96 document()->setEncoding(document()->decoder()->encoding()); | 105 Document::DocumentEncodingData encodingData; |
| 106 encodingData.encoding = m_decoder->encoding(); | |
| 107 encodingData.wasDetectedHeuristically = m_decoder->encodingWasDetectedHeuris tically(); | |
| 108 encodingData.sawDecodingError = m_decoder->sawError(); | |
| 109 document()->setEncoding(encodingData); | |
|
abarth-chromium
2013/08/30 22:50:38
This happens for every call to appendBytes? We ca
| |
| 97 | 110 |
| 98 encodingFixer.fixTitleEncodingIfNeeded(); | 111 encodingFixer.fixTitleEncodingIfNeeded(); |
| 99 | 112 |
| 100 if (decoded.isEmpty()) | 113 if (decoded.isEmpty()) |
| 101 return 0; | 114 return 0; |
| 102 | 115 |
| 103 size_t consumedChars = decoded.length(); | 116 size_t consumedChars = decoded.length(); |
| 104 append(decoded.releaseImpl()); | 117 append(decoded.releaseImpl()); |
| 105 | 118 |
| 106 return consumedChars; | 119 return consumedChars; |
| 107 } | 120 } |
| 108 | 121 |
| 109 size_t DecodedDataDocumentParser::flush() | 122 size_t DecodedDataDocumentParser::flush() |
| 110 { | 123 { |
| 111 // null decoder indicates there is no data received. | 124 // null decoder indicates there is no data received. |
| 112 // We have nothing to do in that case. | 125 // We have nothing to do in that case. |
| 113 TextResourceDecoder* decoder = document()->decoder(); | 126 if (!m_decoder) |
| 114 if (!decoder) | |
| 115 return 0; | 127 return 0; |
| 116 String remainingData = decoder->flush(); | 128 String remainingData = m_decoder->flush(); |
| 117 document()->setEncoding(document()->decoder()->encoding()); | 129 Document::DocumentEncodingData encodingData; |
| 130 encodingData.encoding = m_decoder->encoding(); | |
| 131 encodingData.wasDetectedHeuristically = m_decoder->encodingWasDetectedHeuris tically(); | |
| 132 encodingData.sawDecodingError = m_decoder->sawError(); | |
| 133 document()->setEncoding(encodingData); | |
|
abarth-chromium
2013/08/30 22:50:38
Copy/paste code makes me a sad panda.
| |
| 134 | |
| 118 if (remainingData.isEmpty()) | 135 if (remainingData.isEmpty()) |
| 119 return 0; | 136 return 0; |
| 120 | 137 |
| 121 size_t consumedChars = remainingData.length(); | 138 size_t consumedChars = remainingData.length(); |
| 122 append(remainingData.releaseImpl()); | 139 append(remainingData.releaseImpl()); |
| 123 | 140 |
| 124 return consumedChars; | 141 return consumedChars; |
| 125 } | 142 } |
| 126 | 143 |
| 127 }; | 144 }; |
| OLD | NEW |