Chromium Code Reviews| Index: content/renderer/render_frame_impl.cc |
| diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc |
| index 4a09e2253c41ddda7c3546282474515d521e3a9e..29eb8d71a42dbba6ccce531a84559a4758bb57de 100644 |
| --- a/content/renderer/render_frame_impl.cc |
| +++ b/content/renderer/render_frame_impl.cc |
| @@ -707,6 +707,13 @@ class MHTMLPartsGenerationDelegate |
| return WebString::fromUTF8(content_id); |
| } |
| + blink::WebFrameSerializerCacheControlPolicy cacheControlPolicy() override { |
| + return static_cast<blink::WebFrameSerializerCacheControlPolicy>( |
| + params_.mhtml_cache_control_policy); |
| + } |
| + |
| + bool useBinaryEncoding() override { return params_.mhtml_binary_encoding; } |
| + |
| private: |
| const FrameMsg_SerializeAsMHTML_Params& params_; |
| std::set<std::string>* digests_of_uris_of_serialized_resources_; |
| @@ -4948,27 +4955,35 @@ void RenderFrameImpl::OnSerializeAsMHTML( |
| DCHECK(!mhtml_boundary.isEmpty()); |
| WebData data; |
| - bool success = true; |
| std::set<std::string> digests_of_uris_of_serialized_resources; |
| MHTMLPartsGenerationDelegate delegate( |
| params, &digests_of_uris_of_serialized_resources); |
| + bool should_serialize_frame = |
| + WebFrameSerializer::frameShouldBeSerializedAsMHTML(GetWebFrame(), |
| + &delegate); |
| + bool success = true; |
| + |
| // Generate MHTML header if needed. |
| if (IsMainFrame()) { |
| - blink::WebFrameSerializerCacheControlPolicy policy = |
| - static_cast<blink::WebFrameSerializerCacheControlPolicy>( |
| - params.mhtml_cache_control_policy); |
| - success = WebFrameSerializer::generateMHTMLHeader(mhtml_boundary, policy, |
| - GetWebFrame(), &data); |
| - if (success && file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| + if (should_serialize_frame) { |
| + WebData data = WebFrameSerializer::generateMHTMLHeader( |
| + mhtml_boundary, GetWebFrame(), &delegate); |
| + if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |
| + success = false; |
| + } |
| + } else { |
| + // If we can't serialize the main frame, the whole archive is bad. |
| success = false; |
| } |
| } |
| - // Generate MHTML parts. |
| - if (success) { |
| - data = WebFrameSerializer::generateMHTMLParts( |
| - mhtml_boundary, GetWebFrame(), params.mhtml_binary_encoding, &delegate); |
| + // Generate MHTML parts. Note that if this is not the main frame, then even |
| + // skipping the whole parts generation step is not an error - it simply |
| + // results in an omitted resource in the final file. |
| + if (success && should_serialize_frame) { |
| + data = WebFrameSerializer::generateMHTMLParts(mhtml_boundary, GetWebFrame(), |
| + &delegate); |
|
Łukasz Anforowicz
2016/05/18 17:27:25
This skips generating the MHTML part for a subfram
dewittj
2016/05/19 04:13:17
I'd prefer to leave this as-is and address generat
Łukasz Anforowicz
2016/05/19 17:00:13
I am fine with that (given that MHTML saved by end
dewittj
2016/05/19 18:18:35
I am going to work on this :) Perhaps we can agre
Łukasz Anforowicz
2016/05/19 18:50:17
Sure - I'll be happy to help :-)
|
| // TODO(jcivelli): write the chunks in deferred tasks to give a chance to |
| // the message loop to process other events. |
| if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { |