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

Side by Side Diff: third_party/WebKit/Source/web/WebFrameSerializer.cpp

Issue 2379823003: Move MHTML file writing out of the renderer main thread. (Closed)
Patch Set: Address reviewer comments. Created 4 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 WebFrameSerializerCacheControlPolicy::FailForNoStoreMainFrame); 180 WebFrameSerializerCacheControlPolicy::FailForNoStoreMainFrame);
181 181
182 if (!needToCheckNoStore) 182 if (!needToCheckNoStore)
183 return true; 183 return true;
184 184
185 return !cacheControlNoStoreHeaderPresent(*webLocalFrameImpl); 185 return !cacheControlNoStoreHeaderPresent(*webLocalFrameImpl);
186 } 186 }
187 187
188 } // namespace 188 } // namespace
189 189
190 WebData WebFrameSerializer::generateMHTMLHeader( 190 WebThreadSafeData WebFrameSerializer::generateMHTMLHeader(
191 const WebString& boundary, 191 const WebString& boundary,
192 WebLocalFrame* frame, 192 WebLocalFrame* frame,
193 MHTMLPartsGenerationDelegate* delegate) { 193 MHTMLPartsGenerationDelegate* delegate) {
194 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLHeader"); 194 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLHeader");
195 DCHECK(frame); 195 DCHECK(frame);
196 DCHECK(delegate); 196 DCHECK(delegate);
197 197
198 if (!frameShouldBeSerializedAsMHTML(frame, delegate->cacheControlPolicy())) 198 if (!frameShouldBeSerializedAsMHTML(frame, delegate->cacheControlPolicy()))
199 return WebData(); 199 return WebThreadSafeData();
200 200
201 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame); 201 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame);
202 DCHECK(webLocalFrameImpl); 202 DCHECK(webLocalFrameImpl);
203 203
204 Document* document = webLocalFrameImpl->frame()->document(); 204 Document* document = webLocalFrameImpl->frame()->document();
205 205
206 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); 206 RefPtr<RawData> buffer = RawData::create();
207 MHTMLArchive::generateMHTMLHeader(boundary, document->title(), 207 MHTMLArchive::generateMHTMLHeader(boundary, document->title(),
208 document->suggestedMIMEType(), *buffer); 208 document->suggestedMIMEType(),
209 *buffer->mutableData());
209 return buffer.release(); 210 return buffer.release();
210 } 211 }
211 212
212 WebData WebFrameSerializer::generateMHTMLParts( 213 WebThreadSafeData WebFrameSerializer::generateMHTMLParts(
213 const WebString& boundary, 214 const WebString& boundary,
214 WebLocalFrame* webFrame, 215 WebLocalFrame* webFrame,
215 MHTMLPartsGenerationDelegate* webDelegate) { 216 MHTMLPartsGenerationDelegate* webDelegate) {
216 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLParts"); 217 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLParts");
217 DCHECK(webFrame); 218 DCHECK(webFrame);
218 DCHECK(webDelegate); 219 DCHECK(webDelegate);
219 220
220 if (!frameShouldBeSerializedAsMHTML(webFrame, 221 if (!frameShouldBeSerializedAsMHTML(webFrame,
221 webDelegate->cacheControlPolicy())) 222 webDelegate->cacheControlPolicy()))
222 return WebData(); 223 return WebThreadSafeData();
223 224
224 // Translate arguments from public to internal blink APIs. 225 // Translate arguments from public to internal blink APIs.
225 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); 226 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame();
226 MHTMLArchive::EncodingPolicy encodingPolicy = 227 MHTMLArchive::EncodingPolicy encodingPolicy =
227 webDelegate->useBinaryEncoding() 228 webDelegate->useBinaryEncoding()
228 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding 229 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding
229 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; 230 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding;
230 231
231 // Serialize. 232 // Serialize.
232 TRACE_EVENT_BEGIN0("page-serialization", 233 TRACE_EVENT_BEGIN0("page-serialization",
233 "WebFrameSerializer::generateMHTMLParts serializing"); 234 "WebFrameSerializer::generateMHTMLParts serializing");
234 Vector<SerializedResource> resources; 235 Vector<SerializedResource> resources;
235 { 236 {
236 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( 237 SCOPED_BLINK_UMA_HISTOGRAM_TIMER(
237 "PageSerialization.MhtmlGeneration.SerializationTime.SingleFrame"); 238 "PageSerialization.MhtmlGeneration.SerializationTime.SingleFrame");
238 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); 239 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate);
239 FrameSerializer serializer(resources, coreDelegate); 240 FrameSerializer serializer(resources, coreDelegate);
240 serializer.serializeFrame(*frame); 241 serializer.serializeFrame(*frame);
241 } 242 }
242 TRACE_EVENT_END1("page-serialization", 243 TRACE_EVENT_END1("page-serialization",
243 "WebFrameSerializer::generateMHTMLParts serializing", 244 "WebFrameSerializer::generateMHTMLParts serializing",
244 "resource count", 245 "resource count",
245 static_cast<unsigned long long>(resources.size())); 246 static_cast<unsigned long long>(resources.size()));
246 247
247 // Get Content-ID for the frame being serialized. 248 // Get Content-ID for the frame being serialized.
248 String frameContentID = webDelegate->getContentID(webFrame); 249 String frameContentID = webDelegate->getContentID(webFrame);
249 250
250 // Encode serializer's output as MHTML. 251 // Encode serializer's output as MHTML.
251 RefPtr<SharedBuffer> output = SharedBuffer::create(); 252 RefPtr<RawData> output = RawData::create();
252 { 253 {
253 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( 254 SCOPED_BLINK_UMA_HISTOGRAM_TIMER(
254 "PageSerialization.MhtmlGeneration.EncodingTime.SingleFrame"); 255 "PageSerialization.MhtmlGeneration.EncodingTime.SingleFrame");
255 bool isFirstResource = true; 256 bool isFirstResource = true;
256 for (const SerializedResource& resource : resources) { 257 for (const SerializedResource& resource : resources) {
257 TRACE_EVENT0("page-serialization", 258 TRACE_EVENT0("page-serialization",
258 "WebFrameSerializer::generateMHTMLParts encoding"); 259 "WebFrameSerializer::generateMHTMLParts encoding");
259 // Frame is the 1st resource (see FrameSerializer::serializeFrame doc 260 // Frame is the 1st resource (see FrameSerializer::serializeFrame doc
260 // comment). Frames get a Content-ID header. 261 // comment). Frames get a Content-ID header.
261 String contentID = isFirstResource ? frameContentID : String(); 262 String contentID = isFirstResource ? frameContentID : String();
262 263
263 MHTMLArchive::generateMHTMLPart(boundary, contentID, encodingPolicy, 264 MHTMLArchive::generateMHTMLPart(boundary, contentID, encodingPolicy,
264 resource, *output); 265 resource, *output->mutableData());
265 266
266 isFirstResource = false; 267 isFirstResource = false;
267 } 268 }
268 } 269 }
269 return output.release(); 270 return output.release();
270 } 271 }
271 272
272 WebData WebFrameSerializer::generateMHTMLFooter(const WebString& boundary) { 273 WebThreadSafeData WebFrameSerializer::generateMHTMLFooter(
274 const WebString& boundary) {
273 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLFooter"); 275 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLFooter");
274 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); 276 RefPtr<RawData> buffer = RawData::create();
275 MHTMLArchive::generateMHTMLFooter(boundary, *buffer); 277 MHTMLArchive::generateMHTMLFooter(boundary, *buffer->mutableData());
276 return buffer.release(); 278 return buffer.release();
277 } 279 }
278 280
279 bool WebFrameSerializer::serialize( 281 bool WebFrameSerializer::serialize(
280 WebLocalFrame* frame, 282 WebLocalFrame* frame,
281 WebFrameSerializerClient* client, 283 WebFrameSerializerClient* client,
282 WebFrameSerializer::LinkRewritingDelegate* delegate) { 284 WebFrameSerializer::LinkRewritingDelegate* delegate) {
283 WebFrameSerializerImpl serializerImpl(frame, client, delegate); 285 WebFrameSerializerImpl serializerImpl(frame, client, delegate);
284 return serializerImpl.serialize(); 286 return serializerImpl.serialize();
285 } 287 }
(...skipping 20 matching lines...) Expand all
306 const WebString& baseTarget) { 308 const WebString& baseTarget) {
307 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. 309 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|.
308 if (baseTarget.isEmpty()) 310 if (baseTarget.isEmpty())
309 return String("<base href=\".\">"); 311 return String("<base href=\".\">");
310 String baseString = "<base href=\".\" target=\"" + 312 String baseString = "<base href=\".\" target=\"" +
311 static_cast<const String&>(baseTarget) + "\">"; 313 static_cast<const String&>(baseTarget) + "\">";
312 return baseString; 314 return baseString;
313 } 315 }
314 316
315 } // namespace blink 317 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/mhtml/MHTMLArchive.cpp ('k') | third_party/WebKit/Source/web/tests/MHTMLTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698