Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: Source/core/loader/archive/MHTMLParser.cpp

Issue 23464015: Default to binary encoding when loading MHTML files. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added layout test Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « LayoutTests/mhtml/content_transfer_encoding_none-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 RefPtr<MHTMLArchive> subframe = MHTMLArchive::create(); 133 RefPtr<MHTMLArchive> subframe = MHTMLArchive::create();
134 subframe->setMainResource(resource); 134 subframe->setMainResource(resource);
135 m_frames.append(subframe); 135 m_frames.append(subframe);
136 } 136 }
137 137
138 PassRefPtr<ArchiveResource> MHTMLParser::parseNextPart(const MIMEHeader& mimeHea der, const String& endOfPartBoundary, const String& endOfDocumentBoundary, bool& endOfArchiveReached) 138 PassRefPtr<ArchiveResource> MHTMLParser::parseNextPart(const MIMEHeader& mimeHea der, const String& endOfPartBoundary, const String& endOfDocumentBoundary, bool& endOfArchiveReached)
139 { 139 {
140 ASSERT(endOfPartBoundary.isEmpty() == endOfDocumentBoundary.isEmpty()); 140 ASSERT(endOfPartBoundary.isEmpty() == endOfDocumentBoundary.isEmpty());
141 141
142 // If no content transfer encoding is specified, default to binary encoding.
143 MIMEHeader::Encoding contentTransferEncoding = mimeHeader.contentTransferEnc oding();
144 if (contentTransferEncoding == MIMEHeader::Unknown)
145 contentTransferEncoding = MIMEHeader::Binary;
146
142 RefPtr<SharedBuffer> content = SharedBuffer::create(); 147 RefPtr<SharedBuffer> content = SharedBuffer::create();
143 const bool checkBoundary = !endOfPartBoundary.isEmpty(); 148 const bool checkBoundary = !endOfPartBoundary.isEmpty();
144 bool endOfPartReached = false; 149 bool endOfPartReached = false;
145 if (mimeHeader.contentTransferEncoding() == MIMEHeader::Binary) { 150 if (contentTransferEncoding == MIMEHeader::Binary) {
146 if (!checkBoundary) { 151 if (!checkBoundary) {
147 LOG_ERROR("Binary contents requires end of part"); 152 LOG_ERROR("Binary contents requires end of part");
148 return 0; 153 return 0;
149 } 154 }
150 m_lineReader.setSeparator(endOfPartBoundary.utf8().data()); 155 m_lineReader.setSeparator(endOfPartBoundary.utf8().data());
151 Vector<char> part; 156 Vector<char> part;
152 if (!m_lineReader.nextChunk(part)) { 157 if (!m_lineReader.nextChunk(part)) {
153 LOG_ERROR("Binary contents requires end of part"); 158 LOG_ERROR("Binary contents requires end of part");
154 return 0; 159 return 0;
155 } 160 }
(...skipping 17 matching lines...) Expand all
173 } else { 178 } else {
174 String line; 179 String line;
175 while (!(line = m_lineReader.nextChunkAsUTF8StringWithLatin1Fallback()). isNull()) { 180 while (!(line = m_lineReader.nextChunkAsUTF8StringWithLatin1Fallback()). isNull()) {
176 endOfArchiveReached = (line == endOfDocumentBoundary); 181 endOfArchiveReached = (line == endOfDocumentBoundary);
177 if (checkBoundary && (line == endOfPartBoundary || endOfArchiveReach ed)) { 182 if (checkBoundary && (line == endOfPartBoundary || endOfArchiveReach ed)) {
178 endOfPartReached = true; 183 endOfPartReached = true;
179 break; 184 break;
180 } 185 }
181 // Note that we use line.utf8() and not line.ascii() as ascii turns special characters (such as tab, line-feed...) into '?'. 186 // Note that we use line.utf8() and not line.ascii() as ascii turns special characters (such as tab, line-feed...) into '?'.
182 content->append(line.utf8().data(), line.length()); 187 content->append(line.utf8().data(), line.length());
183 if (mimeHeader.contentTransferEncoding() == MIMEHeader::QuotedPrinta ble) { 188 if (contentTransferEncoding == MIMEHeader::QuotedPrintable) {
184 // The line reader removes the \r\n, but we need them for the co ntent in this case as the QuotedPrintable decoder expects CR-LF terminated lines . 189 // The line reader removes the \r\n, but we need them for the co ntent in this case as the QuotedPrintable decoder expects CR-LF terminated lines .
185 content->append("\r\n", 2); 190 content->append("\r\n", 2);
186 } 191 }
187 } 192 }
188 } 193 }
189 if (!endOfPartReached && checkBoundary) { 194 if (!endOfPartReached && checkBoundary) {
190 LOG_ERROR("No bounday found for MHTML part."); 195 LOG_ERROR("No bounday found for MHTML part.");
191 return 0; 196 return 0;
192 } 197 }
193 198
194 Vector<char> data; 199 Vector<char> data;
195 switch (mimeHeader.contentTransferEncoding()) { 200 switch (contentTransferEncoding) {
196 case MIMEHeader::Base64: 201 case MIMEHeader::Base64:
197 if (!base64Decode(content->data(), content->size(), data)) { 202 if (!base64Decode(content->data(), content->size(), data)) {
198 LOG_ERROR("Invalid base64 content for MHTML part."); 203 LOG_ERROR("Invalid base64 content for MHTML part.");
199 return 0; 204 return 0;
200 } 205 }
201 break; 206 break;
202 case MIMEHeader::QuotedPrintable: 207 case MIMEHeader::QuotedPrintable:
203 quotedPrintableDecode(content->data(), content->size(), data); 208 quotedPrintableDecode(content->data(), content->size(), data);
204 break; 209 break;
205 case MIMEHeader::EightBit: 210 case MIMEHeader::EightBit:
(...skipping 27 matching lines...) Expand all
233 { 238 {
234 return m_resources.size(); 239 return m_resources.size();
235 } 240 }
236 241
237 ArchiveResource* MHTMLParser::subResourceAt(size_t index) const 242 ArchiveResource* MHTMLParser::subResourceAt(size_t index) const
238 { 243 {
239 return m_resources[index].get(); 244 return m_resources[index].get();
240 } 245 }
241 246
242 } 247 }
OLDNEW
« no previous file with comments | « LayoutTests/mhtml/content_transfer_encoding_none-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698