Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 #include "public/platform/WebVector.h" | 58 #include "public/platform/WebVector.h" |
| 59 #include "public/web/WebDataSource.h" | 59 #include "public/web/WebDataSource.h" |
| 60 #include "public/web/WebDocument.h" | 60 #include "public/web/WebDocument.h" |
| 61 #include "public/web/WebFrame.h" | 61 #include "public/web/WebFrame.h" |
| 62 #include "public/web/WebFrameSerializerCacheControlPolicy.h" | 62 #include "public/web/WebFrameSerializerCacheControlPolicy.h" |
| 63 #include "public/web/WebFrameSerializerClient.h" | 63 #include "public/web/WebFrameSerializerClient.h" |
| 64 #include "web/WebFrameSerializerImpl.h" | 64 #include "web/WebFrameSerializerImpl.h" |
| 65 #include "web/WebLocalFrameImpl.h" | 65 #include "web/WebLocalFrameImpl.h" |
| 66 #include "web/WebRemoteFrameImpl.h" | 66 #include "web/WebRemoteFrameImpl.h" |
| 67 #include "wtf/Assertions.h" | 67 #include "wtf/Assertions.h" |
| 68 #include "wtf/Deque.h" | |
| 68 #include "wtf/HashMap.h" | 69 #include "wtf/HashMap.h" |
| 69 #include "wtf/HashSet.h" | 70 #include "wtf/HashSet.h" |
| 70 #include "wtf/Noncopyable.h" | 71 #include "wtf/Noncopyable.h" |
| 71 #include "wtf/Vector.h" | 72 #include "wtf/Vector.h" |
| 72 #include "wtf/text/StringConcatenate.h" | 73 #include "wtf/text/StringConcatenate.h" |
| 73 | 74 |
| 74 namespace blink { | 75 namespace blink { |
| 75 | 76 |
| 76 namespace { | 77 namespace { |
| 77 | 78 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 // Translate arguments from public to internal blink APIs. | 279 // Translate arguments from public to internal blink APIs. |
| 279 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); | 280 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); |
| 280 MHTMLArchive::EncodingPolicy encodingPolicy = | 281 MHTMLArchive::EncodingPolicy encodingPolicy = |
| 281 webDelegate->useBinaryEncoding() | 282 webDelegate->useBinaryEncoding() |
| 282 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding | 283 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding |
| 283 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; | 284 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; |
| 284 | 285 |
| 285 // Serialize. | 286 // Serialize. |
| 286 TRACE_EVENT_BEGIN0("page-serialization", | 287 TRACE_EVENT_BEGIN0("page-serialization", |
| 287 "WebFrameSerializer::generateMHTMLParts serializing"); | 288 "WebFrameSerializer::generateMHTMLParts serializing"); |
| 288 Vector<SerializedResource> resources; | 289 Deque<SerializedResource> resources; |
| 289 { | 290 { |
| 290 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( | 291 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
| 291 "PageSerialization.MhtmlGeneration.SerializationTime.SingleFrame"); | 292 "PageSerialization.MhtmlGeneration.SerializationTime.SingleFrame"); |
| 292 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); | 293 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); |
| 293 FrameSerializer serializer(resources, coreDelegate); | 294 FrameSerializer serializer(resources, coreDelegate); |
| 294 serializer.serializeFrame(*frame); | 295 serializer.serializeFrame(*frame); |
| 295 } | 296 } |
| 296 TRACE_EVENT_END1("page-serialization", | 297 TRACE_EVENT_END1("page-serialization", |
| 297 "WebFrameSerializer::generateMHTMLParts serializing", | 298 "WebFrameSerializer::generateMHTMLParts serializing", |
| 298 "resource count", | 299 "resource count", |
| 299 static_cast<unsigned long long>(resources.size())); | 300 static_cast<unsigned long long>(resources.size())); |
| 300 | 301 |
| 301 // Get Content-ID for the frame being serialized. | 302 // Encode serialized resources as MHTML. |
| 302 String frameContentID = webDelegate->getContentID(webFrame); | |
| 303 | |
| 304 // Encode serializer's output as MHTML. | |
| 305 RefPtr<RawData> output = RawData::create(); | 303 RefPtr<RawData> output = RawData::create(); |
| 306 { | 304 { |
| 305 DCHECK(!resources.isEmpty()); | |
| 307 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( | 306 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
| 308 "PageSerialization.MhtmlGeneration.EncodingTime.SingleFrame"); | 307 "PageSerialization.MhtmlGeneration.EncodingTime.SingleFrame"); |
| 309 bool isFirstResource = true; | 308 // Frame is the 1st resource (see FrameSerializer::serializeFrame doc |
| 310 for (const SerializedResource& resource : resources) { | 309 // comment). Frames get a Content-ID header. |
| 310 MHTMLArchive::generateMHTMLPart( | |
| 311 boundary, webDelegate->getContentID(webFrame), encodingPolicy, | |
| 312 resources.takeFirst(), *output->mutableData()); | |
|
carlosk
2016/12/30 03:08:47
To make this clear: my assumption is that these 2
Łukasz Anforowicz
2016/12/30 17:39:16
I think that because SerializedResource doesn't de
dcheng
2017/01/03 22:31:16
SerializedResource will probably have a compiler g
carlosk
2017/01/05 01:34:57
I also think it should have an auto-generated move
| |
| 313 while (!resources.isEmpty()) { | |
| 311 TRACE_EVENT0("page-serialization", | 314 TRACE_EVENT0("page-serialization", |
| 312 "WebFrameSerializer::generateMHTMLParts encoding"); | 315 "WebFrameSerializer::generateMHTMLParts encoding"); |
| 313 // Frame is the 1st resource (see FrameSerializer::serializeFrame doc | 316 MHTMLArchive::generateMHTMLPart(boundary, String(), encodingPolicy, |
| 314 // comment). Frames get a Content-ID header. | 317 resources.takeFirst(), |
| 315 String contentID = isFirstResource ? frameContentID : String(); | 318 *output->mutableData()); |
| 316 | |
| 317 MHTMLArchive::generateMHTMLPart(boundary, contentID, encodingPolicy, | |
| 318 resource, *output->mutableData()); | |
| 319 | |
| 320 isFirstResource = false; | |
| 321 } | 319 } |
| 322 } | 320 } |
| 323 return output.release(); | 321 return output.release(); |
| 324 } | 322 } |
| 325 | 323 |
| 326 WebThreadSafeData WebFrameSerializer::generateMHTMLFooter( | 324 WebThreadSafeData WebFrameSerializer::generateMHTMLFooter( |
| 327 const WebString& boundary) { | 325 const WebString& boundary) { |
| 328 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLFooter"); | 326 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLFooter"); |
| 329 RefPtr<RawData> buffer = RawData::create(); | 327 RefPtr<RawData> buffer = RawData::create(); |
| 330 MHTMLArchive::generateMHTMLFooter(boundary, *buffer->mutableData()); | 328 MHTMLArchive::generateMHTMLFooter(boundary, *buffer->mutableData()); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 361 const WebString& baseTarget) { | 359 const WebString& baseTarget) { |
| 362 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. | 360 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. |
| 363 if (baseTarget.isEmpty()) | 361 if (baseTarget.isEmpty()) |
| 364 return String("<base href=\".\">"); | 362 return String("<base href=\".\">"); |
| 365 String baseString = "<base href=\".\" target=\"" + | 363 String baseString = "<base href=\".\" target=\"" + |
| 366 static_cast<const String&>(baseTarget) + "\">"; | 364 static_cast<const String&>(baseTarget) + "\">"; |
| 367 return baseString; | 365 return baseString; |
| 368 } | 366 } |
| 369 | 367 |
| 370 } // namespace blink | 368 } // namespace blink |
| OLD | NEW |