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

Unified Diff: chrome/renderer/mhtml_generator.cc

Issue 7044095: Hooking MHTML generation to the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fixes Created 9 years, 6 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: chrome/renderer/mhtml_generator.cc
diff --git a/chrome/renderer/mhtml_generator.cc b/chrome/renderer/mhtml_generator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c9b56884a19e15efc62589fd3f25d013a1f2e16b
--- /dev/null
+++ b/chrome/renderer/mhtml_generator.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/mhtml_generator.h"
+
+#include "base/platform_file.h"
+#include "content/common/view_messages.h"
+#include "content/renderer/render_view.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
+
+MHTMLGenerator::MHTMLGenerator(RenderView* render_view)
+ : RenderViewObserver(render_view),
+ file_(base::kInvalidPlatformFileValue) {
+}
+
+MHTMLGenerator::~MHTMLGenerator() {
+}
+
+// RenderViewObserver implementation:
+bool MHTMLGenerator::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(MHTMLGenerator, message)
+ IPC_MESSAGE_HANDLER(ViewMsg_SavePageAsMHTML, OnSavePageAsMHTML)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void MHTMLGenerator::OnSavePageAsMHTML(
+ int job_id, IPC::PlatformFileForTransit file_for_transit) {
+ base::PlatformFile file =
+ IPC::PlatformFileForTransitToPlatformFile(file_for_transit);
+ file_ = file;
+ bool success = GenerateMHTML();
+ NotifyBrowser(job_id, success);
+}
+
+void MHTMLGenerator::NotifyBrowser(int job_id, bool success) {
+ render_view()->Send(new ViewHostMsg_SavedPageAsMHTML(
+ render_view()->routing_id(), job_id, success));
+ file_ = base::kInvalidPlatformFileValue;
+}
+
+// TODO(jcivelli): write the chunks in deferred tasks to give a chance to the
+// message loop to process other events.
Randy Smith (Not in Mondays) 2011/06/10 18:45:38 Another area where I'm feeling my lack of competen
Jay Civelli 2011/06/10 22:38:22 I think it is OK too, but I'll try to find someone
+bool MHTMLGenerator::GenerateMHTML() {
+ WebKit::WebCString mhtml =
+ WebKit::WebPageSerializer::serializeToMHTML(render_view()->webview());
+ const size_t chunk_size = 1024;
+ const char* data = mhtml.data();
+ for (size_t i = 0; i < mhtml.length(); i += chunk_size) {
+ size_t copy_size = std::min(mhtml.length() - i, chunk_size);
+ if (base::WritePlatformFile(file_, i, data + i, copy_size) == -1)
Randy Smith (Not in Mondays) 2011/06/10 18:45:38 Shouldn't you handle the case where WritePlatformF
Jay Civelli 2011/06/10 22:38:22 Good point, now taking the returned number of byte
+ return false;
+ }
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698