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

Unified Diff: content/renderer/render_frame_impl.cc

Issue 1977303003: Adds a feature to MHTML serialization that omits subframes and subresources marked no-store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no-store
Patch Set: Address Łukasz comments. Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
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..e89c24e3943c57a922333682d3e222abce637791 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,32 @@ 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 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) {
+ // |data| can be empty if the main frame should be skipped. If the main
+ // frame is
+ // skipped, then the whole archive is bad, so bail to the error condition.
+ WebData data = WebFrameSerializer::generateMHTMLHeader(
+ mhtml_boundary, GetWebFrame(), &delegate);
+ if (data.size() == 0 ||
+ file.WriteAtCurrentPos(data.data(), data.size()) < 0) {
success = false;
}
}
- // Generate MHTML parts.
+ // 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) {
- data = WebFrameSerializer::generateMHTMLParts(
- mhtml_boundary, GetWebFrame(), params.mhtml_binary_encoding, &delegate);
+ // |data| can be empty if the frame should be skipped, but this is OK.
+ data = WebFrameSerializer::generateMHTMLParts(mhtml_boundary, GetWebFrame(),
+ &delegate);
// 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) {
Łukasz Anforowicz 2016/05/19 18:50:17 I think we also need the |data.size() == 0| check
dewittj 2016/05/19 19:44:55 No, we don't want to fail if any non-main-frame re
Łukasz Anforowicz 2016/05/19 19:51:24 I see. We might need to revisit if generating bot

Powered by Google App Engine
This is Rietveld 408576698