OLD | NEW |
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const char* const base64 = "base64"; | 50 const char* const base64 = "base64"; |
51 const char* const binary = "binary"; | 51 const char* const binary = "binary"; |
52 | 52 |
53 static String generateRandomBoundary() | 53 static String generateRandomBoundary() |
54 { | 54 { |
55 // Trying to generate random boundaries similar to IE/UnMHT (ex: ----=_NextP
art_000_001B_01CC157B.96F808A0). | 55 // Trying to generate random boundaries similar to IE/UnMHT (ex: ----=_NextP
art_000_001B_01CC157B.96F808A0). |
56 const size_t randomValuesLength = 10; | 56 const size_t randomValuesLength = 10; |
57 char randomValues[randomValuesLength]; | 57 char randomValues[randomValuesLength]; |
58 cryptographicallyRandomValues(&randomValues, randomValuesLength); | 58 cryptographicallyRandomValues(&randomValues, randomValuesLength); |
59 StringBuilder stringBuilder; | 59 StringBuilder stringBuilder; |
60 stringBuilder.append("----=_NextPart_000_"); | 60 stringBuilder.appendLiteral("----=_NextPart_000_"); |
61 for (size_t i = 0; i < randomValuesLength; ++i) { | 61 for (size_t i = 0; i < randomValuesLength; ++i) { |
62 if (i == 2) | 62 if (i == 2) |
63 stringBuilder.append('_'); | 63 stringBuilder.append('_'); |
64 else if (i == 6) | 64 else if (i == 6) |
65 stringBuilder.append('.'); | 65 stringBuilder.append('.'); |
66 stringBuilder.append(lowerNibbleToASCIIHexDigit(randomValues[i])); | 66 stringBuilder.append(lowerNibbleToASCIIHexDigit(randomValues[i])); |
67 stringBuilder.append(upperNibbleToASCIIHexDigit(randomValues[i])); | 67 stringBuilder.append(upperNibbleToASCIIHexDigit(randomValues[i])); |
68 } | 68 } |
69 return stringBuilder.toString(); | 69 return stringBuilder.toString(); |
70 } | 70 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 PassRefPtr<SharedBuffer> MHTMLArchive::generateMHTMLData(const Vector<Serialized
Resource>& resources, EncodingPolicy encodingPolicy, const String& title, const
String& mimeType) | 125 PassRefPtr<SharedBuffer> MHTMLArchive::generateMHTMLData(const Vector<Serialized
Resource>& resources, EncodingPolicy encodingPolicy, const String& title, const
String& mimeType) |
126 { | 126 { |
127 String boundary = generateRandomBoundary(); | 127 String boundary = generateRandomBoundary(); |
128 String endOfResourceBoundary = "--" + boundary + "\r\n"; | 128 String endOfResourceBoundary = "--" + boundary + "\r\n"; |
129 | 129 |
130 DateComponents now; | 130 DateComponents now; |
131 now.setMillisecondsSinceEpochForDateTime(currentTimeMS()); | 131 now.setMillisecondsSinceEpochForDateTime(currentTimeMS()); |
132 String dateString = makeRFC2822DateString(now.weekDay(), now.monthDay(), now
.month(), now.fullYear(), now.hour(), now.minute(), now.second(), 0); | 132 String dateString = makeRFC2822DateString(now.weekDay(), now.monthDay(), now
.month(), now.fullYear(), now.hour(), now.minute(), now.second(), 0); |
133 | 133 |
134 StringBuilder stringBuilder; | 134 StringBuilder stringBuilder; |
135 stringBuilder.append("From: <Saved by WebKit>\r\n"); | 135 stringBuilder.appendLiteral("From: <Saved by WebKit>\r\n"); |
136 stringBuilder.append("Subject: "); | 136 stringBuilder.appendLiteral("Subject: "); |
137 // We replace non ASCII characters with '?' characters to match IE's behavio
r. | 137 // We replace non ASCII characters with '?' characters to match IE's behavio
r. |
138 stringBuilder.append(replaceNonPrintableCharacters(title)); | 138 stringBuilder.append(replaceNonPrintableCharacters(title)); |
139 stringBuilder.append("\r\nDate: "); | 139 stringBuilder.appendLiteral("\r\nDate: "); |
140 stringBuilder.append(dateString); | 140 stringBuilder.append(dateString); |
141 stringBuilder.append("\r\nMIME-Version: 1.0\r\n"); | 141 stringBuilder.appendLiteral("\r\nMIME-Version: 1.0\r\n"); |
142 stringBuilder.append("Content-Type: multipart/related;\r\n"); | 142 stringBuilder.appendLiteral("Content-Type: multipart/related;\r\n"); |
143 stringBuilder.append("\ttype=\""); | 143 stringBuilder.appendLiteral("\ttype=\""); |
144 stringBuilder.append(mimeType); | 144 stringBuilder.append(mimeType); |
145 stringBuilder.append("\";\r\n"); | 145 stringBuilder.appendLiteral("\";\r\n"); |
146 stringBuilder.append("\tboundary=\""); | 146 stringBuilder.appendLiteral("\tboundary=\""); |
147 stringBuilder.append(boundary); | 147 stringBuilder.append(boundary); |
148 stringBuilder.append("\"\r\n\r\n"); | 148 stringBuilder.appendLiteral("\"\r\n\r\n"); |
149 | 149 |
150 // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ??
(we still only have put ASCII characters in it). | 150 // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ??
(we still only have put ASCII characters in it). |
151 ASSERT(stringBuilder.toString().containsOnlyASCII()); | 151 ASSERT(stringBuilder.toString().containsOnlyASCII()); |
152 CString asciiString = stringBuilder.toString().utf8(); | 152 CString asciiString = stringBuilder.toString().utf8(); |
153 RefPtr<SharedBuffer> mhtmlData = SharedBuffer::create(); | 153 RefPtr<SharedBuffer> mhtmlData = SharedBuffer::create(); |
154 mhtmlData->append(asciiString.data(), asciiString.length()); | 154 mhtmlData->append(asciiString.data(), asciiString.length()); |
155 | 155 |
156 for (size_t i = 0; i < resources.size(); ++i) { | 156 for (size_t i = 0; i < resources.size(); ++i) { |
157 const SerializedResource& resource = resources[i]; | 157 const SerializedResource& resource = resources[i]; |
158 | 158 |
159 stringBuilder.clear(); | 159 stringBuilder.clear(); |
160 stringBuilder.append(endOfResourceBoundary); | 160 stringBuilder.append(endOfResourceBoundary); |
161 stringBuilder.append("Content-Type: "); | 161 stringBuilder.appendLiteral("Content-Type: "); |
162 stringBuilder.append(resource.mimeType); | 162 stringBuilder.append(resource.mimeType); |
163 | 163 |
164 const char* contentEncoding = 0; | 164 const char* contentEncoding = 0; |
165 if (encodingPolicy == UseBinaryEncoding) | 165 if (encodingPolicy == UseBinaryEncoding) |
166 contentEncoding = binary; | 166 contentEncoding = binary; |
167 else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeTy
pe) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType)) | 167 else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeTy
pe) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType)) |
168 contentEncoding = quotedPrintable; | 168 contentEncoding = quotedPrintable; |
169 else | 169 else |
170 contentEncoding = base64; | 170 contentEncoding = base64; |
171 | 171 |
172 stringBuilder.append("\r\nContent-Transfer-Encoding: "); | 172 stringBuilder.appendLiteral("\r\nContent-Transfer-Encoding: "); |
173 stringBuilder.append(contentEncoding); | 173 stringBuilder.append(contentEncoding); |
174 stringBuilder.append("\r\nContent-Location: "); | 174 stringBuilder.appendLiteral("\r\nContent-Location: "); |
175 stringBuilder.append(resource.url); | 175 stringBuilder.append(resource.url); |
176 stringBuilder.append("\r\n\r\n"); | 176 stringBuilder.appendLiteral("\r\n\r\n"); |
177 | 177 |
178 asciiString = stringBuilder.toString().utf8(); | 178 asciiString = stringBuilder.toString().utf8(); |
179 mhtmlData->append(asciiString.data(), asciiString.length()); | 179 mhtmlData->append(asciiString.data(), asciiString.length()); |
180 | 180 |
181 if (!strcmp(contentEncoding, binary)) { | 181 if (!strcmp(contentEncoding, binary)) { |
182 const char* data; | 182 const char* data; |
183 size_t position = 0; | 183 size_t position = 0; |
184 while (size_t length = resource.data->getSomeData(data, position)) { | 184 while (size_t length = resource.data->getSomeData(data, position)) { |
185 mhtmlData->append(data, length); | 185 mhtmlData->append(data, length); |
186 position += length; | 186 position += length; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 252 } |
253 | 253 |
254 void MHTMLArchive::trace(Visitor* visitor) | 254 void MHTMLArchive::trace(Visitor* visitor) |
255 { | 255 { |
256 visitor->trace(m_mainResource); | 256 visitor->trace(m_mainResource); |
257 visitor->trace(m_subresources); | 257 visitor->trace(m_subresources); |
258 visitor->trace(m_subframeArchives); | 258 visitor->trace(m_subframeArchives); |
259 } | 259 } |
260 | 260 |
261 } | 261 } |
OLD | NEW |