diff options
author | sverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-03 22:09:50 +0000 |
---|---|---|
committer | sverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-03 22:09:50 +0000 |
commit | d81c1e5c40d61b2282a8c1f3b8ac0fb90ba0a8bc (patch) | |
tree | f8bf7eab7e0ca333255181e9b4c1c05757d24145 /chrome/renderer | |
parent | dd50e0777dc325f9179eb8732b7d1c4852467948 (diff) | |
download | chromium_src-d81c1e5c40d61b2282a8c1f3b8ac0fb90ba0a8bc.zip chromium_src-d81c1e5c40d61b2282a8c1f3b8ac0fb90ba0a8bc.tar.gz chromium_src-d81c1e5c40d61b2282a8c1f3b8ac0fb90ba0a8bc.tar.bz2 |
Resubmitting change r17491 that was reverted because of a memory leak.
Fixed the leak.
Review URL: http://codereview.chromium.org/118190
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17547 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/print_web_view_helper.cc | 281 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper.h | 93 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 233 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 13 | ||||
-rw-r--r-- | chrome/renderer/renderer.vcproj | 8 |
5 files changed, 390 insertions, 238 deletions
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc new file mode 100644 index 0000000..d8ba139 --- /dev/null +++ b/chrome/renderer/print_web_view_helper.cc @@ -0,0 +1,281 @@ +// Copyright (c) 2009 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/print_web_view_helper.h"
+
+#include "app/l10n_util.h"
+#include "base/logging.h"
+#include "base/gfx/size.h"
+#include "chrome/common/render_messages.h"
+#include "chrome/renderer/render_view.h"
+#include "grit/generated_resources.h"
+#include "printing/units.h"
+#include "webkit/api/public/WebScreenInfo.h"
+#include "webkit/api/public/WebSize.h"
+#include "webkit/glue/webframe.h"
+#include "webkit/glue/weburlrequest.h"
+
+#if defined(OS_WIN)
+#include "chrome/common/gfx/emf.h"
+#include "skia/ext/vector_canvas.h"
+#endif
+
+
+void PrintWebViewHelper::SyncPrint(WebFrame* frame) {
+#if defined(OS_WIN)
+ // Retrieve the default print settings to calculate the expected number of
+ // pages.
+ ViewMsg_Print_Params default_settings;
+
+ IPC::SyncMessage* msg =
+ new ViewHostMsg_GetDefaultPrintSettings(routing_id(), &default_settings);
+ if (Send(msg)) {
+ msg = NULL;
+ // Check if the printer returned any settings, if the settings is empty, we
+ // can safely assume there are no printer drivers configured. So we safely
+ // terminate.
+ if (default_settings.IsEmpty()) {
+ RunJavaScriptAlert(frame,
+ l10n_util::GetString(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING_TITLE));
+ return;
+ }
+
+ // Continue only if the settings are valid.
+ if (default_settings.dpi && default_settings.document_cookie) {
+ int expected_pages_count = 0;
+ gfx::Size canvas_size;
+ canvas_size.set_width(
+ printing::ConvertUnit(default_settings.printable_size.width(),
+ static_cast<int>(default_settings.dpi),
+ default_settings.desired_dpi));
+ canvas_size.set_height(
+ printing::ConvertUnit(default_settings.printable_size.height(),
+ static_cast<int>(default_settings.dpi),
+ default_settings.desired_dpi));
+ frame->BeginPrint(canvas_size, &expected_pages_count);
+ DCHECK(expected_pages_count);
+ frame->EndPrint();
+
+ // Ask the browser to show UI to retrieve the final print settings.
+ ViewMsg_PrintPages_Params print_settings;
+ // host_window_ may be NULL at this point if the current window is a popup
+ // and the print() command has been issued from the parent. The receiver
+ // of this message has to deal with this.
+ msg = new ViewHostMsg_ScriptedPrint(routing_id(),
+ render_view_->host_window(),
+ default_settings.document_cookie,
+ expected_pages_count,
+ &print_settings);
+ if (Send(msg)) {
+ msg = NULL;
+
+ // If the settings are invalid, early quit.
+ if (print_settings.params.dpi &&
+ print_settings.params.document_cookie) {
+ // Render the printed pages. It will implicitly revert the document to
+ // display CSS media type.
+ PrintPages(print_settings, frame);
+ // All went well.
+ return;
+ } else {
+ // The user cancelled.
+ }
+ } else {
+ // Send() failed.
+ NOTREACHED();
+ }
+ } else {
+ // The user cancelled.
+ }
+ } else {
+ // Send() failed.
+ NOTREACHED();
+ }
+ // TODO(maruel): bug 1123882 Alert the user that printing failed.
+#else // defined(OS_WIN)
+ // TODO(port): print not implemented
+ NOTIMPLEMENTED();
+#endif
+}
+
+void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params,
+ WebFrame* frame) {
+ int page_count = 0;
+ gfx::Size canvas_size;
+ canvas_size.set_width(
+ printing::ConvertUnit(params.params.printable_size.width(),
+ static_cast<int>(params.params.dpi),
+ params.params.desired_dpi));
+ canvas_size.set_height(
+ printing::ConvertUnit(params.params.printable_size.height(),
+ static_cast<int>(params.params.dpi),
+ params.params.desired_dpi));
+ frame->BeginPrint(canvas_size, &page_count);
+ Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id(),
+ params.params.document_cookie,
+ page_count));
+ if (page_count) {
+ ViewMsg_PrintPage_Params page_params;
+ page_params.params = params.params;
+ if (params.pages.empty()) {
+ for (int i = 0; i < page_count; ++i) {
+ page_params.page_number = i;
+ PrintPage(page_params, canvas_size, frame);
+ }
+ } else {
+ for (size_t i = 0; i < params.pages.size(); ++i) {
+ page_params.page_number = params.pages[i];
+ PrintPage(page_params, canvas_size, frame);
+ }
+ }
+ }
+ frame->EndPrint();
+}
+
+void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
+ const gfx::Size& canvas_size,
+ WebFrame* frame) {
+#if defined(OS_WIN)
+ // Generate a memory-based EMF file. The EMF will use the current screen's
+ // DPI.
+ gfx::Emf emf;
+
+ emf.CreateDc(NULL, NULL);
+ HDC hdc = emf.hdc();
+ DCHECK(hdc);
+ skia::PlatformDeviceWin::InitializeDC(hdc);
+ // Since WebKit extends the page width depending on the magical shrink
+ // factor we make sure the canvas covers the worst case scenario
+ // (x2.0 currently). PrintContext will then set the correct clipping region.
+ int size_x = static_cast<int>(canvas_size.width() * params.params.max_shrink);
+ int size_y = static_cast<int>(canvas_size.height() *
+ params.params.max_shrink);
+ // Calculate the dpi adjustment.
+ float shrink = static_cast<float>(canvas_size.width()) /
+ params.params.printable_size.width();
+#if 0
+ // TODO(maruel): This code is kept for testing until the 100% GDI drawing
+ // code is stable. maruels use this code's output as a reference when the
+ // GDI drawing code fails.
+
+ // Mix of Skia and GDI based.
+ skia::PlatformCanvasWin canvas(size_x, size_y, true);
+ canvas.drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode);
+ float webkit_shrink = frame->PrintPage(params.page_number, &canvas);
+ if (shrink <= 0) {
+ NOTREACHED() << "Printing page " << params.page_number << " failed.";
+ } else {
+ // Update the dpi adjustment with the "page shrink" calculated in webkit.
+ shrink /= webkit_shrink;
+ }
+
+ // Create a BMP v4 header that we can serialize.
+ BITMAPV4HEADER bitmap_header;
+ gfx::CreateBitmapV4Header(size_x, size_y, &bitmap_header);
+ const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true);
+ SkAutoLockPixels src_lock(src_bmp);
+ int retval = StretchDIBits(hdc,
+ 0,
+ 0,
+ size_x, size_y,
+ 0, 0,
+ size_x, size_y,
+ src_bmp.getPixels(),
+ reinterpret_cast<BITMAPINFO*>(&bitmap_header),
+ DIB_RGB_COLORS,
+ SRCCOPY);
+ DCHECK(retval != GDI_ERROR);
+#else
+ // 100% GDI based.
+ skia::VectorCanvas canvas(hdc, size_x, size_y);
+ float webkit_shrink = frame->PrintPage(params.page_number, &canvas);
+ if (shrink <= 0) {
+ NOTREACHED() << "Printing page " << params.page_number << " failed.";
+ } else {
+ // Update the dpi adjustment with the "page shrink" calculated in webkit.
+ shrink /= webkit_shrink;
+ }
+#endif
+
+ // Done printing. Close the device context to retrieve the compiled EMF.
+ if (!emf.CloseDc()) {
+ NOTREACHED() << "EMF failed";
+ }
+
+ // Get the size of the compiled EMF.
+ unsigned buf_size = emf.GetDataSize();
+ DCHECK_GT(buf_size, 128u);
+ ViewHostMsg_DidPrintPage_Params page_params;
+ page_params.data_size = 0;
+ page_params.emf_data_handle = NULL;
+ page_params.page_number = params.page_number;
+ page_params.document_cookie = params.params.document_cookie;
+ page_params.actual_shrink = shrink;
+ base::SharedMemory shared_buf;
+
+ // http://msdn2.microsoft.com/en-us/library/ms535522.aspx
+ // Windows 2000/XP: When a page in a spooled file exceeds approximately 350
+ // MB, it can fail to print and not send an error message.
+ if (buf_size < 350*1024*1024) {
+ // Allocate a shared memory buffer to hold the generated EMF data.
+ if (shared_buf.Create(L"", false, false, buf_size) &&
+ shared_buf.Map(buf_size)) {
+ // Copy the bits into shared memory.
+ if (emf.GetData(shared_buf.memory(), buf_size)) {
+ page_params.emf_data_handle = shared_buf.handle();
+ page_params.data_size = buf_size;
+ } else {
+ NOTREACHED() << "GetData() failed";
+ }
+ shared_buf.Unmap();
+ } else {
+ NOTREACHED() << "Buffer allocation failed";
+ }
+ } else {
+ NOTREACHED() << "Buffer too large: " << buf_size;
+ }
+ emf.CloseEmf();
+ if (Send(new ViewHostMsg_DuplicateSection(routing_id(),
+ page_params.emf_data_handle,
+ &page_params.emf_data_handle))) {
+ Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params));
+ }
+#else // defined(OS_WIN)
+ // TODO(port) implement printing
+ NOTIMPLEMENTED();
+#endif
+}
+
+bool PrintWebViewHelper::Send(IPC::Message* msg) {
+ return render_view_->Send(msg);
+}
+
+int32 PrintWebViewHelper::routing_id() {
+ return render_view_->routing_id();
+}
+
+void PrintWebViewHelper::GetWindowRect(WebWidget* webwidget,
+ WebKit::WebRect* rect) {
+ NOTREACHED();
+}
+
+void PrintWebViewHelper::DidStopLoading(WebView* webview) {
+ NOTREACHED();
+}
+
+WebKit::WebScreenInfo PrintWebViewHelper::GetScreenInfo(WebWidget* webwidget) {
+ WebKit::WebScreenInfo info;
+ NOTREACHED();
+ return info;
+}
+
+gfx::NativeViewId PrintWebViewHelper::GetContainingView(WebWidget* webwidget) {
+ NOTREACHED();
+ return gfx::NativeViewId();
+}
+
+bool PrintWebViewHelper::IsHidden(WebWidget* webwidget) {
+ NOTREACHED();
+ return true;
+}
diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h new file mode 100644 index 0000000..f9e3fa9 --- /dev/null +++ b/chrome/renderer/print_web_view_helper.h @@ -0,0 +1,93 @@ +// Copyright (c) 2009 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.
+
+#ifndef CHROME_RENDERER_PRINT_WEB_VIEW_DELEGATE_H_
+#define CHROME_RENDERER_PRINT_WEB_VIEW_DELEGATE_H_
+
+#include <vector>
+
+#include "base/scoped_ptr.h"
+#include "webkit/glue/webview_delegate.h"
+
+namespace gfx {
+class Size;
+}
+
+namespace IPC {
+class Message;
+}
+
+class RenderView;
+class WebView;
+struct ViewMsg_PrintPage_Params;
+struct ViewMsg_PrintPages_Params;
+
+
+// PrintWebViewHelper handles most of the printing grunt work for RenderView.
+// We plan on making print asynchronous and that will require copying the DOM
+// of the document and creating a new WebView with the contents.
+class PrintWebViewHelper : public WebViewDelegate {
+ public:
+ explicit PrintWebViewHelper(RenderView * render_view)
+ : render_view_(render_view) {}
+
+ virtual ~PrintWebViewHelper() {}
+
+ void SyncPrint(WebFrame* frame);
+
+ protected:
+
+ // Prints the page listed in |params|.
+ void PrintPage(const ViewMsg_PrintPage_Params& params,
+ const gfx::Size& canvas_size,
+ WebFrame* frame);
+
+ // Prints all the pages listed in |params|.
+ void PrintPages(const ViewMsg_PrintPages_Params& params, WebFrame* frame);
+
+ // IPC::Message::Sender
+ bool Send(IPC::Message* msg);
+
+ int32 routing_id();
+
+ // WebViewDeletegate
+ virtual void DidStartLoading(WebView* webview) {}
+ virtual void DidStopLoading(WebView* webview);
+ virtual gfx::NativeViewId GetContainingView(WebWidget* webwidget);
+ virtual void DidInvalidateRect(WebWidget* webwidget,
+ const WebKit::WebRect& rect) {}
+ virtual void DidScrollRect(WebWidget* webwidget, int dx, int dy,
+ const WebKit::WebRect& clip_rect) {}
+ virtual void Show(WebWidget* webwidget, WindowOpenDisposition disposition) {}
+ virtual void ShowAsPopupWithItems(WebWidget* webwidget,
+ const WebKit::WebRect& bounds,
+ int item_height,
+ int selected_index,
+ const std::vector<WebMenuItem>& items) {}
+ virtual void CloseWidgetSoon(WebWidget* webwidget) {}
+ virtual void Focus(WebWidget* webwidget) {}
+ virtual void Blur(WebWidget* webwidget) {}
+ virtual void SetCursor(WebWidget* webwidget, const WebCursor& cursor) {}
+ virtual void GetWindowRect(WebWidget* webwidget, WebKit::WebRect* rect);
+ virtual void SetWindowRect(WebWidget* webwidget,
+ const WebKit::WebRect& rect) {}
+ virtual void GetRootWindowRect(WebWidget* webwidget, WebKit::WebRect* rect) {}
+ virtual void GetRootWindowResizerRect(WebWidget* webwidget,
+ WebKit::WebRect* rect) {}
+ virtual void DidMove(WebWidget* webwidget, const WebPluginGeometry& move) {}
+ virtual void RunModal(WebWidget* webwidget) {}
+ virtual void AddRef() {}
+ virtual void Release() {}
+ virtual bool IsHidden(WebWidget* webwidget);
+ virtual WebKit::WebScreenInfo GetScreenInfo(WebWidget* webwidget);
+
+ private:
+ RenderView* render_view_;
+ scoped_ptr<WebView> print_web_view_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
+};
+
+#endif // CHROME_RENDERER_PRINT_WEB_VIEW_DELEGATE_H_
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index ea92604..6ad30d6 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -37,6 +37,7 @@ #include "chrome/renderer/extensions/extension_process_bindings.h" #include "chrome/renderer/localized_error.h" #include "chrome/renderer/media/audio_renderer_impl.h" +#include "chrome/renderer/print_web_view_helper.h" #include "chrome/renderer/render_process.h" #include "chrome/renderer/renderer_logging.h" #include "chrome/renderer/user_script_slave.h" @@ -49,7 +50,6 @@ #include "net/base/data_url.h" #include "net/base/escape.h" #include "net/base/net_errors.h" -#include "printing/units.h" #include "skia/ext/bitmap_platform_device.h" #include "skia/ext/image_operations.h" #include "webkit/api/public/WebDragData.h" @@ -80,15 +80,8 @@ #if defined(OS_WIN) // TODO(port): these files are currently Windows only because they concern: -// * logging -// * printing // * theming -// * views -#include "base/gfx/gdi_util.h" #include "base/gfx/native_theme.h" -#include "chrome/common/gfx/emf.h" -#include "skia/ext/vector_canvas.h" -#include "views/controls/message_box_view.h" #endif using base::Time; @@ -462,120 +455,6 @@ void RenderView::SendThumbnail() { Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail)); } -void RenderView::PrintPage(const ViewMsg_PrintPage_Params& params, - const gfx::Size& canvas_size, - WebFrame* frame) { -#if defined(OS_WIN) - // Generate a memory-based EMF file. The EMF will use the current screen's - // DPI. - gfx::Emf emf; - - emf.CreateDc(NULL, NULL); - HDC hdc = emf.hdc(); - DCHECK(hdc); - skia::PlatformDeviceWin::InitializeDC(hdc); - // Since WebKit extends the page width depending on the magical shrink - // factor we make sure the canvas covers the worst case scenario - // (x2.0 currently). PrintContext will then set the correct clipping region. - int size_x = static_cast<int>(canvas_size.width() * params.params.max_shrink); - int size_y = static_cast<int>(canvas_size.height() * - params.params.max_shrink); - // Calculate the dpi adjustment. - float shrink = static_cast<float>(canvas_size.width()) / - params.params.printable_size.width(); -#if 0 - // TODO(maruel): This code is kept for testing until the 100% GDI drawing - // code is stable. maruels use this code's output as a reference when the - // GDI drawing code fails. - - // Mix of Skia and GDI based. - skia::PlatformCanvasWin canvas(size_x, size_y, true); - canvas.drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode); - float webkit_shrink = frame->PrintPage(params.page_number, &canvas); - if (shrink <= 0) { - NOTREACHED() << "Printing page " << params.page_number << " failed."; - } else { - // Update the dpi adjustment with the "page shrink" calculated in webkit. - shrink /= webkit_shrink; - } - - // Create a BMP v4 header that we can serialize. - BITMAPV4HEADER bitmap_header; - gfx::CreateBitmapV4Header(size_x, size_y, &bitmap_header); - const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true); - SkAutoLockPixels src_lock(src_bmp); - int retval = StretchDIBits(hdc, - 0, - 0, - size_x, size_y, - 0, 0, - size_x, size_y, - src_bmp.getPixels(), - reinterpret_cast<BITMAPINFO*>(&bitmap_header), - DIB_RGB_COLORS, - SRCCOPY); - DCHECK(retval != GDI_ERROR); -#else - // 100% GDI based. - skia::VectorCanvas canvas(hdc, size_x, size_y); - float webkit_shrink = frame->PrintPage(params.page_number, &canvas); - if (shrink <= 0) { - NOTREACHED() << "Printing page " << params.page_number << " failed."; - } else { - // Update the dpi adjustment with the "page shrink" calculated in webkit. - shrink /= webkit_shrink; - } -#endif - - // Done printing. Close the device context to retrieve the compiled EMF. - if (!emf.CloseDc()) { - NOTREACHED() << "EMF failed"; - } - - // Get the size of the compiled EMF. - unsigned buf_size = emf.GetDataSize(); - DCHECK_GT(buf_size, 128u); - ViewHostMsg_DidPrintPage_Params page_params; - page_params.data_size = 0; - page_params.emf_data_handle = NULL; - page_params.page_number = params.page_number; - page_params.document_cookie = params.params.document_cookie; - page_params.actual_shrink = shrink; - base::SharedMemory shared_buf; - - // http://msdn2.microsoft.com/en-us/library/ms535522.aspx - // Windows 2000/XP: When a page in a spooled file exceeds approximately 350 - // MB, it can fail to print and not send an error message. - if (buf_size < 350*1024*1024) { - // Allocate a shared memory buffer to hold the generated EMF data. - if (shared_buf.Create(L"", false, false, buf_size) && - shared_buf.Map(buf_size)) { - // Copy the bits into shared memory. - if (emf.GetData(shared_buf.memory(), buf_size)) { - page_params.emf_data_handle = shared_buf.handle(); - page_params.data_size = buf_size; - } else { - NOTREACHED() << "GetData() failed"; - } - shared_buf.Unmap(); - } else { - NOTREACHED() << "Buffer allocation failed"; - } - } else { - NOTREACHED() << "Buffer too large: " << buf_size; - } - emf.CloseEmf(); - if (Send(new ViewHostMsg_DuplicateSection(routing_id_, - page_params.emf_data_handle, - &page_params.emf_data_handle))) { - Send(new ViewHostMsg_DidPrintPage(routing_id_, page_params)); - } -#else // defined(OS_WIN) - // TODO(port) implement printing - NOTIMPLEMENTED(); -#endif -} - void RenderView::OnPrintPages() { DCHECK(webview()); if (webview()) { @@ -584,40 +463,6 @@ void RenderView::OnPrintPages() { } } -void RenderView::PrintPages(const ViewMsg_PrintPages_Params& params, - WebFrame* frame) { - int page_count = 0; - gfx::Size canvas_size; - canvas_size.set_width( - printing::ConvertUnit(params.params.printable_size.width(), - static_cast<int>(params.params.dpi), - params.params.desired_dpi)); - canvas_size.set_height( - printing::ConvertUnit(params.params.printable_size.height(), - static_cast<int>(params.params.dpi), - params.params.desired_dpi)); - frame->BeginPrint(canvas_size, &page_count); - Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id_, - params.params.document_cookie, - page_count)); - if (page_count) { - ViewMsg_PrintPage_Params page_params; - page_params.params = params.params; - if (params.pages.empty()) { - for (int i = 0; i < page_count; ++i) { - page_params.page_number = i; - PrintPage(page_params, canvas_size, frame); - } - } else { - for (size_t i = 0; i < params.pages.size(); ++i) { - page_params.page_number = params.pages[i]; - PrintPage(page_params, canvas_size, frame); - } - } - } - frame->EndPrint(); -} - void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { if (load_id != page_id_) return; // this capture call is no longer relevant due to navigation @@ -2360,79 +2205,9 @@ void RenderView::SetInputMethodState(bool enabled) { } void RenderView::ScriptedPrint(WebFrame* frame) { -#if defined(OS_WIN) - // Retrieve the default print settings to calculate the expected number of - // pages. - ViewMsg_Print_Params default_settings; - IPC::SyncMessage* msg = - new ViewHostMsg_GetDefaultPrintSettings(routing_id_, &default_settings); - if (Send(msg)) { - msg = NULL; - // Check if the printer returned any settings, if the settings is empty, we - // can safely assume there are no printer drivers configured. So we safely - // terminate. - if (default_settings.IsEmpty()) { - RunJavaScriptAlert(frame, - l10n_util::GetString(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING_TITLE)); - return; - } - - // Continue only if the settings are valid. - if (default_settings.dpi && default_settings.document_cookie) { - int expected_pages_count = 0; - gfx::Size canvas_size; - canvas_size.set_width( - printing::ConvertUnit(default_settings.printable_size.width(), - static_cast<int>(default_settings.dpi), - default_settings.desired_dpi)); - canvas_size.set_height( - printing::ConvertUnit(default_settings.printable_size.height(), - static_cast<int>(default_settings.dpi), - default_settings.desired_dpi)); - frame->BeginPrint(canvas_size, &expected_pages_count); - DCHECK(expected_pages_count); - frame->EndPrint(); - - // Ask the browser to show UI to retrieve the final print settings. - ViewMsg_PrintPages_Params print_settings; - // host_window_ may be NULL at this point if the current window is a popup - // and the print() command has been issued from the parent. The receiver - // of this message has to deal with this. - msg = new ViewHostMsg_ScriptedPrint(routing_id_, - host_window_, - default_settings.document_cookie, - expected_pages_count, - &print_settings); - if (Send(msg)) { - msg = NULL; - - // If the settings are invalid, early quit. - if (print_settings.params.dpi && - print_settings.params.document_cookie) { - // Render the printed pages. It will implicitly revert the document to - // display CSS media type. - PrintPages(print_settings, frame); - // All went well. - return; - } else { - // The user cancelled. - } - } else { - // Send() failed. - NOTREACHED(); - } - } else { - // The user cancelled. - } - } else { - // Send() failed. - NOTREACHED(); - } - // TODO(maruel): bug 1123882 Alert the user that printing failed. -#else // defined(OS_WIN) - // TODO(port): print not implemented - NOTIMPLEMENTED(); -#endif + print_render_view_.reset(new PrintWebViewHelper(this)); + print_render_view_->SyncPrint(frame); + print_render_view_.reset(); } void RenderView::WebInspectorOpened(int num_resources) { diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 0702fbe..bd216ae 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -46,6 +46,7 @@ class DebugMessageHandler; class DevToolsAgent; class DevToolsClient; class FilePath; +class PrintWebViewHelper; class GURL; class RenderThread; class ResourceDispatcher; @@ -58,7 +59,6 @@ struct FindInPageRequest; struct ThumbnailScore; struct ViewMsg_Navigate_Params; struct ViewMsg_PrintPage_Params; -struct ViewMsg_PrintPages_Params; struct ViewMsg_Print_Params; struct ViewMsg_UploadFile_Params; struct WebDropData; @@ -588,14 +588,6 @@ class RenderView : public RenderWidget, // a custom background. void OnSetBackground(const SkBitmap& background); - // Prints the page listed in |params|. - void PrintPage(const ViewMsg_PrintPage_Params& params, - const gfx::Size& canvas_size, - WebFrame* frame); - - // Prints all the pages listed in |params|. - void PrintPages(const ViewMsg_PrintPages_Params& params, WebFrame* frame); - // Attempt to upload the file that we are trying to process if any. // Reset the pending file upload data if the form was successfully // posted. @@ -812,6 +804,9 @@ class RenderView : public RenderWidget, class NavigationState; scoped_ptr<NavigationState> pending_navigation_state_; + // Need for printing + scoped_ptr<PrintWebViewHelper> print_render_view_; + DISALLOW_COPY_AND_ASSIGN(RenderView); }; diff --git a/chrome/renderer/renderer.vcproj b/chrome/renderer/renderer.vcproj index b86fae6..55afb5b 100644 --- a/chrome/renderer/renderer.vcproj +++ b/chrome/renderer/renderer.vcproj @@ -342,6 +342,14 @@ > </File> <File + RelativePath=".\print_web_view_helper.cc" + > + </File> + <File + RelativePath=".\print_web_view_helper.h" + > + </File> + <File RelativePath=".\render_process.cc" > </File> |