| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include "base/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 10 #include "chrome/common/render_messages_params.h" | 10 #include "chrome/common/render_messages_params.h" |
| 11 #include "printing/native_metafile.h" | 11 #include "printing/native_metafile.h" |
| 12 #include "skia/ext/vector_canvas.h" | 12 #include "skia/ext/vector_canvas.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
| 15 | 15 |
| 16 using printing::NativeMetafile; | 16 using printing::NativeMetafile; |
| 17 using WebKit::WebFrame; | 17 using WebKit::WebFrame; |
| 18 using WebKit::WebNode; |
| 18 using WebKit::WebSize; | 19 using WebKit::WebSize; |
| 19 | 20 |
| 20 void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, | 21 void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, |
| 21 WebFrame* frame) { | 22 WebFrame* frame, |
| 23 WebNode* node) { |
| 22 // We only can use PDF in the renderer because Cairo needs to create a | 24 // We only can use PDF in the renderer because Cairo needs to create a |
| 23 // temporary file for a PostScript surface. | 25 // temporary file for a PostScript surface. |
| 24 printing::NativeMetafile metafile(printing::NativeMetafile::PDF); | 26 printing::NativeMetafile metafile(printing::NativeMetafile::PDF); |
| 25 int page_count; | 27 int page_count; |
| 26 skia::VectorCanvas* canvas = NULL; | 28 skia::VectorCanvas* canvas = NULL; |
| 27 | 29 |
| 28 { | 30 { |
| 29 // Hack - when |prep_frame_view| goes out of scope, PrintEnd() gets called. | 31 // Hack - when |prep_frame_view| goes out of scope, PrintEnd() gets called. |
| 30 // Doing this before closing |metafile| below ensures | 32 // Doing this before closing |metafile| below ensures |
| 31 // webkit::ppapi::PluginInstance::PrintEnd() has a valid canvas/metafile to | 33 // webkit::ppapi::PluginInstance::PrintEnd() has a valid canvas/metafile to |
| 32 // save the final output to. See pepper_plugin_instance.cc for the whole | 34 // save the final output to. See pepper_plugin_instance.cc for the whole |
| 33 // story. | 35 // story. |
| 34 PrepareFrameAndViewForPrint prep_frame_view(params.params, | 36 PrepareFrameAndViewForPrint prep_frame_view(params.params, |
| 35 frame, | 37 frame, |
| 38 node, |
| 36 frame->view()); | 39 frame->view()); |
| 37 page_count = prep_frame_view.GetExpectedPageCount(); | 40 page_count = prep_frame_view.GetExpectedPageCount(); |
| 38 | 41 |
| 39 // TODO(myhuang): Send ViewHostMsg_DidGetPrintedPagesCount. | 42 // TODO(myhuang): Send ViewHostMsg_DidGetPrintedPagesCount. |
| 40 | 43 |
| 41 if (page_count == 0) | 44 if (page_count == 0) |
| 42 return; | 45 return; |
| 43 | 46 |
| 44 metafile.Init(); | 47 metafile.Init(); |
| 45 | 48 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 canvas_size.height()); | 123 canvas_size.height()); |
| 121 frame->printPage(params.page_number, *canvas); | 124 frame->printPage(params.page_number, *canvas); |
| 122 | 125 |
| 123 // TODO(myhuang): We should handle transformation for paper margins. | 126 // TODO(myhuang): We should handle transformation for paper margins. |
| 124 // TODO(myhuang): We should render the header and the footer. | 127 // TODO(myhuang): We should render the header and the footer. |
| 125 | 128 |
| 126 // Done printing. Close the device context to retrieve the compiled metafile. | 129 // Done printing. Close the device context to retrieve the compiled metafile. |
| 127 if (!metafile->FinishPage()) | 130 if (!metafile->FinishPage()) |
| 128 NOTREACHED() << "metafile failed"; | 131 NOTREACHED() << "metafile failed"; |
| 129 } | 132 } |
| OLD | NEW |