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

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: Removed unneeded std::move calls that clang was complaining about. 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 std::vector<char> 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 std::vector<char>();
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 std::vector<char> output;
207 MHTMLArchive::generateMHTMLHeader(boundary, document->title(), 207 MHTMLArchive::generateMHTMLHeader(boundary, document->title(),
208 document->suggestedMIMEType(), *buffer); 208 document->suggestedMIMEType(), output);
209 return buffer.release(); 209 return output;
210 } 210 }
211 211
212 WebData WebFrameSerializer::generateMHTMLParts( 212 std::vector<char> WebFrameSerializer::generateMHTMLParts(
213 const WebString& boundary, 213 const WebString& boundary,
214 WebLocalFrame* webFrame, 214 WebLocalFrame* webFrame,
215 MHTMLPartsGenerationDelegate* webDelegate) { 215 MHTMLPartsGenerationDelegate* webDelegate) {
216 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLParts"); 216 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLParts");
217 DCHECK(webFrame); 217 DCHECK(webFrame);
218 DCHECK(webDelegate); 218 DCHECK(webDelegate);
219 219
220 if (!frameShouldBeSerializedAsMHTML(webFrame, 220 if (!frameShouldBeSerializedAsMHTML(webFrame,
221 webDelegate->cacheControlPolicy())) 221 webDelegate->cacheControlPolicy()))
222 return WebData(); 222 return std::vector<char>();
223 223
224 // Translate arguments from public to internal blink APIs. 224 // Translate arguments from public to internal blink APIs.
225 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); 225 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame();
226 MHTMLArchive::EncodingPolicy encodingPolicy = 226 MHTMLArchive::EncodingPolicy encodingPolicy =
227 webDelegate->useBinaryEncoding() 227 webDelegate->useBinaryEncoding()
228 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding 228 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding
229 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; 229 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding;
230 230
231 // Serialize. 231 // Serialize.
232 TRACE_EVENT_BEGIN0("page-serialization", 232 TRACE_EVENT_BEGIN0("page-serialization",
233 "WebFrameSerializer::generateMHTMLParts serializing"); 233 "WebFrameSerializer::generateMHTMLParts serializing");
234 Vector<SerializedResource> resources; 234 Vector<SerializedResource> resources;
235 { 235 {
236 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( 236 SCOPED_BLINK_UMA_HISTOGRAM_TIMER(
237 "PageSerialization.MhtmlGeneration.SerializationTime.SingleFrame"); 237 "PageSerialization.MhtmlGeneration.SerializationTime.SingleFrame");
238 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); 238 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate);
239 FrameSerializer serializer(resources, coreDelegate); 239 FrameSerializer serializer(resources, coreDelegate);
240 serializer.serializeFrame(*frame); 240 serializer.serializeFrame(*frame);
241 } 241 }
242 TRACE_EVENT_END1("page-serialization", 242 TRACE_EVENT_END1("page-serialization",
243 "WebFrameSerializer::generateMHTMLParts serializing", 243 "WebFrameSerializer::generateMHTMLParts serializing",
244 "resource count", 244 "resource count",
245 static_cast<unsigned long long>(resources.size())); 245 static_cast<unsigned long long>(resources.size()));
246 246
247 // Get Content-ID for the frame being serialized. 247 // Get Content-ID for the frame being serialized.
248 String frameContentID = webDelegate->getContentID(webFrame); 248 String frameContentID = webDelegate->getContentID(webFrame);
249 249
250 // Encode serializer's output as MHTML. 250 // Encode serializer's output as MHTML.
251 RefPtr<SharedBuffer> output = SharedBuffer::create(); 251 std::vector<char> output;
252 { 252 {
253 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( 253 SCOPED_BLINK_UMA_HISTOGRAM_TIMER(
254 "PageSerialization.MhtmlGeneration.EncodingTime.SingleFrame"); 254 "PageSerialization.MhtmlGeneration.EncodingTime.SingleFrame");
255 bool isFirstResource = true; 255 bool isFirstResource = true;
256 for (const SerializedResource& resource : resources) { 256 for (const SerializedResource& resource : resources) {
257 TRACE_EVENT0("page-serialization", 257 TRACE_EVENT0("page-serialization",
258 "WebFrameSerializer::generateMHTMLParts encoding"); 258 "WebFrameSerializer::generateMHTMLParts encoding");
259 // Frame is the 1st resource (see FrameSerializer::serializeFrame doc 259 // Frame is the 1st resource (see FrameSerializer::serializeFrame doc
260 // comment). Frames get a Content-ID header. 260 // comment). Frames get a Content-ID header.
261 String contentID = isFirstResource ? frameContentID : String(); 261 String contentID = isFirstResource ? frameContentID : String();
262 262
263 MHTMLArchive::generateMHTMLPart(boundary, contentID, encodingPolicy, 263 MHTMLArchive::generateMHTMLPart(boundary, contentID, encodingPolicy,
264 resource, *output); 264 resource, output);
265 265
266 isFirstResource = false; 266 isFirstResource = false;
267 } 267 }
268 } 268 }
269 return output.release(); 269 return output;
270 } 270 }
271 271
272 WebData WebFrameSerializer::generateMHTMLFooter(const WebString& boundary) { 272 std::vector<char> WebFrameSerializer::generateMHTMLFooter(
273 const WebString& boundary) {
273 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLFooter"); 274 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLFooter");
274 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); 275 std::vector<char> output;
275 MHTMLArchive::generateMHTMLFooter(boundary, *buffer); 276 MHTMLArchive::generateMHTMLFooter(boundary, output);
276 return buffer.release(); 277 return output;
277 } 278 }
278 279
279 bool WebFrameSerializer::serialize( 280 bool WebFrameSerializer::serialize(
280 WebLocalFrame* frame, 281 WebLocalFrame* frame,
281 WebFrameSerializerClient* client, 282 WebFrameSerializerClient* client,
282 WebFrameSerializer::LinkRewritingDelegate* delegate) { 283 WebFrameSerializer::LinkRewritingDelegate* delegate) {
283 WebFrameSerializerImpl serializerImpl(frame, client, delegate); 284 WebFrameSerializerImpl serializerImpl(frame, client, delegate);
284 return serializerImpl.serialize(); 285 return serializerImpl.serialize();
285 } 286 }
286 287
(...skipping 19 matching lines...) Expand all
306 const WebString& baseTarget) { 307 const WebString& baseTarget) {
307 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. 308 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|.
308 if (baseTarget.isEmpty()) 309 if (baseTarget.isEmpty())
309 return String("<base href=\".\">"); 310 return String("<base href=\".\">");
310 String baseString = "<base href=\".\" target=\"" + 311 String baseString = "<base href=\".\" target=\"" +
311 static_cast<const String&>(baseTarget) + "\">"; 312 static_cast<const String&>(baseTarget) + "\">";
312 return baseString; 313 return baseString;
313 } 314 }
314 315
315 } // namespace blink 316 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698