Changeset 89869 in webkit
- Timestamp:
- Jun 27, 2011 3:18:15 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r89864 r89869 1 2011-06-27 Jay Civelli <jcivelli@chromium.org> 2 3 Reviewed by Darin Fisher. 4 5 Adding binary part support to MHTML. 6 https://bugs.webkit.org/show_bug.cgi?id=63310 7 8 * mhtml/multi_frames_binary.mht: Added. 9 * platform/chromium/mhtml/multi_frames_binary-expected.txt: Added. 10 1 11 2011-06-27 Levi Weintraub <leviw@chromium.org> 2 12 -
trunk/Source/WebCore/ChangeLog
r89864 r89869 1 2011-06-27 Jay Civelli <jcivelli@chromium.org> 2 3 Reviewed by Darin Fisher. 4 5 Adding binary part support to MHTML. 6 https://bugs.webkit.org/show_bug.cgi?id=63310 7 8 * loader/archive/mhtml/MHTMLArchive.cpp: 9 (WebCore::MHTMLArchive::generateMHTMLData): 10 (WebCore::MHTMLArchive::generateMHTMLDataUsingBinaryEncoding): 11 * loader/archive/mhtml/MHTMLArchive.h: 12 * loader/archive/mhtml/MHTMLParser.cpp: 13 (WebCore::MHTMLParser::parseNextPart): 14 * platform/SharedBuffer.cpp: 15 (WebCore::SharedBuffer::append): 16 * platform/SharedBuffer.h: 17 * platform/network/MIMEHeader.cpp: 18 (WebCore::MIMEHeader::parseContentTransferEncoding): 19 * platform/network/MIMEHeader.h: 20 1 21 2011-06-27 Levi Weintraub <leviw@chromium.org> 2 22 -
trunk/Source/WebCore/loader/archive/mhtml/MHTMLArchive.cpp
r87958 r89869 58 58 const char* const quotedPrintable = "quoted-printable"; 59 59 const char* const base64 = "base64"; 60 const char* const binary = "binary"; 60 61 61 62 static String generateRandomBoundary() … … 124 125 125 126 PassRefPtr<SharedBuffer> MHTMLArchive::generateMHTMLData(Page* page) 127 { 128 return generateMHTMLData(page, false); 129 } 130 131 PassRefPtr<SharedBuffer> MHTMLArchive::generateMHTMLDataUsingBinaryEncoding(Page* page) 132 { 133 return generateMHTMLData(page, true); 134 } 135 136 PassRefPtr<SharedBuffer> MHTMLArchive::generateMHTMLData(Page* page, bool useBinaryEncoding) 126 137 { 127 138 Vector<PageSerializer::Resource> resources; … … 168 179 stringBuilder.append(resource.mimeType); 169 180 170 const char* contentEncoding = MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeType) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType) ? quotedPrintable: base64;181 const char* contentEncoding = useBinaryEncoding ? binary : base64; 171 182 stringBuilder.append("\r\nContent-Transfer-Encoding: "); 172 183 stringBuilder.append(contentEncoding); … … 178 189 mhtmlData->append(asciiString.data(), asciiString.length()); 179 190 180 // FIXME: ideally we would encode the content as a stream without having to fetch it all. 181 const char* data = resource.data->data(); 182 size_t dataLength = resource.data->size(); 183 Vector<char> encodedData; 184 if (!strcmp(contentEncoding, quotedPrintable)) { 185 quotedPrintableEncode(data, dataLength, encodedData); 186 mhtmlData->append(encodedData.data(), encodedData.size()); 187 mhtmlData->append("\r\n", 2); 191 if (!strcmp(contentEncoding, binary)) { 192 const char* data; 193 size_t position = 0; 194 while (size_t length = resource.data->getSomeData(data, position)) { 195 mhtmlData->append(data, length); 196 position += length; 197 } 188 198 } else { 189 ASSERT(!strcmp(contentEncoding, base64)); 190 // We are not specifying insertLFs = true below as it would cut the lines with LFs and MHTML requires CRLFs. 191 base64Encode(data, dataLength, encodedData); 192 const size_t maximumLineLength = 76; 193 size_t index = 0; 194 size_t encodedDataLength = encodedData.size(); 195 do { 196 size_t lineLength = std::min(encodedDataLength - index, maximumLineLength); 197 mhtmlData->append(encodedData.data() + index, lineLength); 199 // FIXME: ideally we would encode the content as a stream without having to fetch it all. 200 const char* data = resource.data->data(); 201 size_t dataLength = resource.data->size(); 202 Vector<char> encodedData; 203 if (!strcmp(contentEncoding, quotedPrintable)) { 204 quotedPrintableEncode(data, dataLength, encodedData); 205 mhtmlData->append(encodedData.data(), encodedData.size()); 198 206 mhtmlData->append("\r\n", 2); 199 index += maximumLineLength; 200 } while (index < encodedDataLength); 207 } else { 208 ASSERT(!strcmp(contentEncoding, base64)); 209 // We are not specifying insertLFs = true below as it would cut the lines with LFs and MHTML requires CRLFs. 210 base64Encode(data, dataLength, encodedData); 211 const size_t maximumLineLength = 76; 212 size_t index = 0; 213 size_t encodedDataLength = encodedData.size(); 214 do { 215 size_t lineLength = std::min(encodedDataLength - index, maximumLineLength); 216 mhtmlData->append(encodedData.data() + index, lineLength); 217 mhtmlData->append("\r\n", 2); 218 index += maximumLineLength; 219 } while (index < encodedDataLength); 220 } 201 221 } 202 222 } -
trunk/Source/WebCore/loader/archive/mhtml/MHTMLArchive.h
r87958 r89869 50 50 51 51 static PassRefPtr<SharedBuffer> generateMHTMLData(Page*); 52 // Binary encoding results in smaller MHTML files but they might not work in other browsers. 53 static PassRefPtr<SharedBuffer> generateMHTMLDataUsingBinaryEncoding(Page*); 52 54 53 55 private: 56 static PassRefPtr<SharedBuffer> generateMHTMLData(Page*, bool useBinaryEncoding); 57 54 58 friend class MHTMLParser; 55 59 MHTMLArchive(); -
trunk/Source/WebCore/loader/archive/mhtml/MHTMLParser.cpp
r89599 r89869 147 147 const bool checkBoundary = !endOfPartBoundary.isEmpty(); 148 148 bool endOfPartReached = false; 149 String line; 150 while (!(line = m_lineReader.nextChunkAsUTF8StringWithLatin1Fallback()).isNull()) { 151 if (checkBoundary && (line == endOfPartBoundary || line == endOfDocumentBoundary)) { 149 if (mimeHeader.contentTransferEncoding() == MIMEHeader::Binary) { 150 if (!checkBoundary) { 151 LOG_ERROR("Binary contents requires end of part"); 152 return 0; 153 } 154 m_lineReader.setSeparator(endOfPartBoundary.utf8().data()); 155 Vector<char> part; 156 if (!m_lineReader.nextChunk(part)) { 157 LOG_ERROR("Binary contents requires end of part"); 158 return 0; 159 } 160 content->append(part); 161 m_lineReader.setSeparator("\r\n"); 162 Vector<char> nextChars; 163 if (m_lineReader.peek(nextChars, 2) != 2) { 164 LOG_ERROR("Invalid seperator."); 165 return 0; 166 } 167 endOfPartReached = true; 168 ASSERT(nextChars.size() == 2); 169 endOfArchiveReached = (nextChars[0] == '-' && nextChars[1] == '-'); 170 if (!endOfArchiveReached) { 171 String line = m_lineReader.nextChunkAsUTF8StringWithLatin1Fallback(); 172 if (!line.isEmpty()) { 173 LOG_ERROR("No CRLF at end of binary section."); 174 return 0; 175 } 176 } 177 } else { 178 String line; 179 while (!(line = m_lineReader.nextChunkAsUTF8StringWithLatin1Fallback()).isNull()) { 152 180 endOfArchiveReached = (line == endOfDocumentBoundary); 153 endOfPartReached = true; 154 break; 155 } 156 // Note that we use line.utf8() and not line.ascii() as ascii turns special characters (such as tab, line-feed...) into '?'. 157 content->append(line.utf8().data(), line.length()); 158 if (mimeHeader.contentTransferEncoding() == MIMEHeader::QuotedPrintable) { 159 // The line reader removes the \r\n, but we need them for the content in this case as the QuotedPrintable decoder expects CR-LF terminated lines. 160 content->append("\r\n", 2); 181 if (checkBoundary && (line == endOfPartBoundary || endOfArchiveReached)) { 182 endOfPartReached = true; 183 break; 184 } 185 // Note that we use line.utf8() and not line.ascii() as ascii turns special characters (such as tab, line-feed...) into '?'. 186 content->append(line.utf8().data(), line.length()); 187 if (mimeHeader.contentTransferEncoding() == MIMEHeader::QuotedPrintable) { 188 // The line reader removes the \r\n, but we need them for the content in this case as the QuotedPrintable decoder expects CR-LF terminated lines. 189 content->append("\r\n", 2); 190 } 161 191 } 162 192 } … … 178 208 break; 179 209 case MIMEHeader::SevenBit: 210 case MIMEHeader::Binary: 180 211 data.append(content->data(), content->size()); 181 212 break; -
trunk/Source/WebCore/platform/SharedBuffer.cpp
r87958 r89869 166 166 } 167 167 168 void SharedBuffer::append(const Vector<char>& data) 169 { 170 append(data.data(), data.size()); 171 } 172 168 173 void SharedBuffer::clear() 169 174 { -
trunk/Source/WebCore/platform/SharedBuffer.h
r87958 r89869 87 87 void append(SharedBuffer*); 88 88 void append(const char*, unsigned); 89 void append(const Vector<char>&); 90 89 91 void clear(); 90 92 const char* platformData() const; -
trunk/Source/WebCore/platform/network/MIMEHeader.cpp
r89599 r89869 124 124 if (encoding == "7bit") 125 125 return SevenBit; 126 if (encoding == "binary") 127 return Binary; 126 128 LOG_ERROR("Unknown encoding '%s' found in MIME header.", text.ascii().data()); 127 129 return Unknown; -
trunk/Source/WebCore/platform/network/MIMEHeader.h
r89321 r89869 47 47 Base64, 48 48 SevenBit, 49 Binary, 49 50 Unknown 50 51 }; -
trunk/Source/WebKit/chromium/ChangeLog
r89837 r89869 1 2011-06-27 Jay Civelli <jcivelli@chromium.org> 2 3 Reviewed by Darin Fisher. 4 5 Adding binary part support to MHTML. 6 https://bugs.webkit.org/show_bug.cgi?id=63310 7 8 * public/WebPageSerializer.h: 9 * src/WebPageSerializer.cpp: 10 (WebKit::WebPageSerializer::serializeToMHTML): 11 (WebKit::WebPageSerializer::serializeToMHTMLUsingBinaryEncoding): 12 1 13 2011-05-17 Nat Duca <nduca@chromium.org> 2 14 -
trunk/Source/WebKit/chromium/public/WebPageSerializer.h
r88495 r89869 62 62 WEBKIT_API static WebCString serializeToMHTML(WebView*); 63 63 64 // Similar to serializeToMHTML but uses binary encoding for the MHTML parts. 65 // This results in a smaller MHTML file but it might not be supported by other browsers. 66 WEBKIT_API static WebCString serializeToMHTMLUsingBinaryEncoding(WebView*); 67 64 68 // IMPORTANT: 65 69 // The API below is an older implementation of a pageserialization that -
trunk/Source/WebKit/chromium/src/WebPageSerializer.cpp
r88495 r89869 209 209 } 210 210 211 WebCString WebPageSerializer::serializeToMHTMLUsingBinaryEncoding(WebView* view) 212 { 213 RefPtr<SharedBuffer> mhtml = MHTMLArchive::generateMHTMLDataUsingBinaryEncoding(static_cast<WebViewImpl*>(view)->page()); 214 // FIXME: we are copying all the data here. Idealy we would have a WebSharedData(). 215 return WebCString(mhtml->data(), mhtml->size()); 216 } 217 211 218 bool WebPageSerializer::serialize(WebFrame* frame, 212 219 bool recursive,
Note: See TracChangeset
for help on using the changeset viewer.