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

Side by Side Diff: third_party/WebKit/Source/platform/mhtml/MHTMLArchive.cpp

Issue 1441553002: Generating CIDs in Blink during MHTML serialization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mhtml-per-frame-page-serializer-only
Patch Set: Using references for out parameters in Blink. Created 5 years 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
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 21 matching lines...) Expand all
32 #include "platform/mhtml/MHTMLArchive.h" 32 #include "platform/mhtml/MHTMLArchive.h"
33 33
34 #include "platform/DateComponents.h" 34 #include "platform/DateComponents.h"
35 #include "platform/MIMETypeRegistry.h" 35 #include "platform/MIMETypeRegistry.h"
36 #include "platform/SerializedResource.h" 36 #include "platform/SerializedResource.h"
37 #include "platform/SharedBuffer.h" 37 #include "platform/SharedBuffer.h"
38 #include "platform/mhtml/ArchiveResource.h" 38 #include "platform/mhtml/ArchiveResource.h"
39 #include "platform/mhtml/MHTMLParser.h" 39 #include "platform/mhtml/MHTMLParser.h"
40 #include "platform/text/QuotedPrintable.h" 40 #include "platform/text/QuotedPrintable.h"
41 #include "platform/weborigin/SchemeRegistry.h" 41 #include "platform/weborigin/SchemeRegistry.h"
42 #include "wtf/Assertions.h"
42 #include "wtf/CryptographicallyRandomNumber.h" 43 #include "wtf/CryptographicallyRandomNumber.h"
43 #include "wtf/DateMath.h" 44 #include "wtf/DateMath.h"
44 #include "wtf/text/Base64.h" 45 #include "wtf/text/Base64.h"
45 #include "wtf/text/StringBuilder.h" 46 #include "wtf/text/StringBuilder.h"
46 47
47 namespace blink { 48 namespace blink {
48 49
49 const char* const quotedPrintable = "quoted-printable"; 50 const char* const quotedPrintable = "quoted-printable";
50 const char* const base64 = "base64"; 51 const char* const base64 = "base64";
51 const char* const binary = "binary"; 52 const char* const binary = "binary";
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 for (size_t j = 0; j < parser.subResourceCount(); ++j) 121 for (size_t j = 0; j < parser.subResourceCount(); ++j)
121 archive->addSubresource(parser.subResourceAt(j)); 122 archive->addSubresource(parser.subResourceAt(j));
122 } 123 }
123 return mainArchive.release(); 124 return mainArchive.release();
124 } 125 }
125 126
126 void MHTMLArchive::generateMHTMLHeader( 127 void MHTMLArchive::generateMHTMLHeader(
127 const String& boundary, const String& title, const String& mimeType, 128 const String& boundary, const String& title, const String& mimeType,
128 SharedBuffer& outputBuffer) 129 SharedBuffer& outputBuffer)
129 { 130 {
131 ASSERT(!boundary.isEmpty());
132 ASSERT(!mimeType.isEmpty());
133
130 DateComponents now; 134 DateComponents now;
131 now.setMillisecondsSinceEpochForDateTime(currentTimeMS()); 135 now.setMillisecondsSinceEpochForDateTime(currentTimeMS());
132 // TODO(lukasza): Passing individual date/time components seems fragile. 136 // TODO(lukasza): Passing individual date/time components seems fragile.
133 String dateString = makeRFC2822DateString( 137 String dateString = makeRFC2822DateString(
134 now.weekDay(), now.monthDay(), now.month(), now.fullYear(), 138 now.weekDay(), now.monthDay(), now.month(), now.fullYear(),
135 now.hour(), now.minute(), now.second(), 0); 139 now.hour(), now.minute(), now.second(), 0);
136 140
137 StringBuilder stringBuilder; 141 StringBuilder stringBuilder;
138 stringBuilder.appendLiteral("From: <Saved by Blink>\r\n"); 142 stringBuilder.appendLiteral("From: <Saved by Blink>\r\n");
139 stringBuilder.appendLiteral("Subject: "); 143 stringBuilder.appendLiteral("Subject: ");
(...skipping 13 matching lines...) Expand all
153 // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ?? 157 // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ??
154 // (we still only have put ASCII characters in it). 158 // (we still only have put ASCII characters in it).
155 ASSERT(stringBuilder.toString().containsOnlyASCII()); 159 ASSERT(stringBuilder.toString().containsOnlyASCII());
156 CString asciiString = stringBuilder.toString().utf8(); 160 CString asciiString = stringBuilder.toString().utf8();
157 161
158 outputBuffer.append(asciiString.data(), asciiString.length()); 162 outputBuffer.append(asciiString.data(), asciiString.length());
159 } 163 }
160 164
161 void MHTMLArchive::generateMHTMLPart( 165 void MHTMLArchive::generateMHTMLPart(
162 const String& boundary, 166 const String& boundary,
167 const String& contentID,
163 EncodingPolicy encodingPolicy, 168 EncodingPolicy encodingPolicy,
164 const SerializedResource& resource, 169 const SerializedResource& resource,
165 SharedBuffer& outputBuffer) 170 SharedBuffer& outputBuffer)
166 { 171 {
172 ASSERT(!boundary.isEmpty());
173 ASSERT(contentID.isEmpty() || contentID[0] == '<');
174
167 StringBuilder stringBuilder; 175 StringBuilder stringBuilder;
168 stringBuilder.append("--" + boundary + "\r\n"); 176 stringBuilder.append("--" + boundary + "\r\n");
177
169 stringBuilder.appendLiteral("Content-Type: "); 178 stringBuilder.appendLiteral("Content-Type: ");
170 stringBuilder.append(resource.mimeType); 179 stringBuilder.append(resource.mimeType);
180 stringBuilder.appendLiteral("\r\n");
181
182 if (!contentID.isEmpty()) {
183 stringBuilder.appendLiteral("Content-ID: ");
184 stringBuilder.append(contentID);
185 stringBuilder.appendLiteral("\r\n");
186 }
171 187
172 const char* contentEncoding = 0; 188 const char* contentEncoding = 0;
173 if (encodingPolicy == UseBinaryEncoding) 189 if (encodingPolicy == UseBinaryEncoding)
174 contentEncoding = binary; 190 contentEncoding = binary;
175 else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeType) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType)) 191 else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeType) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType))
176 contentEncoding = quotedPrintable; 192 contentEncoding = quotedPrintable;
177 else 193 else
178 contentEncoding = base64; 194 contentEncoding = base64;
179 195
180 stringBuilder.appendLiteral("\r\nContent-Transfer-Encoding: "); 196 stringBuilder.appendLiteral("Content-Transfer-Encoding: ");
181 stringBuilder.append(contentEncoding); 197 stringBuilder.append(contentEncoding);
182 stringBuilder.appendLiteral("\r\nContent-Location: "); 198 stringBuilder.appendLiteral("\r\n");
183 stringBuilder.append(resource.url); 199
184 stringBuilder.appendLiteral("\r\n\r\n"); 200 if (!resource.url.protocolIsAbout()) {
201 stringBuilder.appendLiteral("Content-Location: ");
202 stringBuilder.append(resource.url);
203 stringBuilder.appendLiteral("\r\n");
204 }
205
206 stringBuilder.appendLiteral("\r\n");
185 207
186 CString asciiString = stringBuilder.toString().utf8(); 208 CString asciiString = stringBuilder.toString().utf8();
187 outputBuffer.append(asciiString.data(), asciiString.length()); 209 outputBuffer.append(asciiString.data(), asciiString.length());
188 210
189 if (!strcmp(contentEncoding, binary)) { 211 if (!strcmp(contentEncoding, binary)) {
190 const char* data; 212 const char* data;
191 size_t position = 0; 213 size_t position = 0;
192 while (size_t length = resource.data->getSomeData(data, position)) { 214 while (size_t length = resource.data->getSomeData(data, position)) {
193 outputBuffer.append(data, length); 215 outputBuffer.append(data, length);
194 position += length; 216 position += length;
(...skipping 21 matching lines...) Expand all
216 index += maximumLineLength; 238 index += maximumLineLength;
217 } while (index < encodedDataLength); 239 } while (index < encodedDataLength);
218 } 240 }
219 } 241 }
220 } 242 }
221 243
222 void MHTMLArchive::generateMHTMLFooter( 244 void MHTMLArchive::generateMHTMLFooter(
223 const String& boundary, 245 const String& boundary,
224 SharedBuffer& outputBuffer) 246 SharedBuffer& outputBuffer)
225 { 247 {
248 ASSERT(!boundary.isEmpty());
226 CString asciiString = String("--" + boundary + "--\r\n").utf8(); 249 CString asciiString = String("--" + boundary + "--\r\n").utf8();
227 outputBuffer.append(asciiString.data(), asciiString.length()); 250 outputBuffer.append(asciiString.data(), asciiString.length());
228 } 251 }
229 252
230 #if !ENABLE(OILPAN) 253 #if !ENABLE(OILPAN)
231 void MHTMLArchive::clearAllSubframeArchives() 254 void MHTMLArchive::clearAllSubframeArchives()
232 { 255 {
233 SubFrameArchives clearedArchives; 256 SubFrameArchives clearedArchives;
234 clearAllSubframeArchivesImpl(&clearedArchives); 257 clearAllSubframeArchivesImpl(&clearedArchives);
235 } 258 }
(...skipping 26 matching lines...) Expand all
262 } 285 }
263 286
264 DEFINE_TRACE(MHTMLArchive) 287 DEFINE_TRACE(MHTMLArchive)
265 { 288 {
266 visitor->trace(m_mainResource); 289 visitor->trace(m_mainResource);
267 visitor->trace(m_subresources); 290 visitor->trace(m_subresources);
268 visitor->trace(m_subframeArchives); 291 visitor->trace(m_subframeArchives);
269 } 292 }
270 293
271 } 294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698