OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 page_params.content_area = content_area_in_dpi; | 83 page_params.content_area = content_area_in_dpi; |
84 | 84 |
85 if (!CopyMetafileDataToSharedMem(metafile.get(), | 85 if (!CopyMetafileDataToSharedMem(metafile.get(), |
86 &(page_params.metafile_data_handle))) { | 86 &(page_params.metafile_data_handle))) { |
87 page_params.data_size = 0; | 87 page_params.data_size = 0; |
88 } | 88 } |
89 | 89 |
90 Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params)); | 90 Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params)); |
91 } | 91 } |
92 | 92 |
93 bool PrintWebViewHelper::RenderPreviewPage(int page_number) { | 93 bool PrintWebViewHelper::RenderPreviewPage( |
94 PrintMsg_Print_Params print_params = print_preview_context_.print_params(); | 94 int page_number, |
| 95 const PrintMsg_Print_Params& print_params) { |
95 // Calculate the dpi adjustment. | 96 // Calculate the dpi adjustment. |
96 double actual_shrink = static_cast<float>(print_params.desired_dpi / | 97 double actual_shrink = static_cast<float>(print_params.desired_dpi / |
97 print_params.dpi); | 98 print_params.dpi); |
98 scoped_ptr<Metafile> draft_metafile; | 99 scoped_ptr<Metafile> draft_metafile; |
99 printing::Metafile* initial_render_metafile = | 100 printing::Metafile* initial_render_metafile = |
100 print_preview_context_.metafile(); | 101 print_preview_context_.metafile(); |
101 | 102 |
102 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { | 103 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { |
103 draft_metafile.reset(new printing::PreviewMetafile); | 104 draft_metafile.reset(new printing::PreviewMetafile); |
104 initial_render_metafile = draft_metafile.get(); | 105 initial_render_metafile = draft_metafile.get(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 skia::SetIsPreviewMetafile(*canvas, is_preview); | 182 skia::SetIsPreviewMetafile(*canvas, is_preview); |
182 } | 183 } |
183 | 184 |
184 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); | 185 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); |
185 | 186 |
186 if (params.display_header_footer) { | 187 if (params.display_header_footer) { |
187 // |page_number| is 0-based, so 1 is added. | 188 // |page_number| is 0-based, so 1 is added. |
188 PrintHeaderAndFooter(canvas.get(), page_number + 1, | 189 PrintHeaderAndFooter(canvas.get(), page_number + 1, |
189 print_preview_context_.total_page_count(), | 190 print_preview_context_.total_page_count(), |
190 css_scale_factor * webkit_page_shrink_factor, | 191 css_scale_factor * webkit_page_shrink_factor, |
191 page_layout_in_points, | 192 page_layout_in_points, *header_footer_info_, params); |
192 *header_footer_info_); | |
193 } | 193 } |
194 | 194 |
195 if (*actual_shrink <= 0 || webkit_scale_factor <= 0) { | 195 if (*actual_shrink <= 0 || webkit_scale_factor <= 0) { |
196 NOTREACHED() << "Printing page " << page_number << " failed."; | 196 NOTREACHED() << "Printing page " << page_number << " failed."; |
197 } else { | 197 } else { |
198 // While rendering certain plugins (PDF) to metafile, we might need to | 198 // While rendering certain plugins (PDF) to metafile, we might need to |
199 // set custom scale factor. Update |actual_shrink| with custom scale | 199 // set custom scale factor. Update |actual_shrink| with custom scale |
200 // if it is set on canvas. | 200 // if it is set on canvas. |
201 // TODO(gene): We should revisit this solution for the next versions. | 201 // TODO(gene): We should revisit this solution for the next versions. |
202 // Consider creating metafile of the right size (or resizable) | 202 // Consider creating metafile of the right size (or resizable) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 shared_buf.Unmap(); | 234 shared_buf.Unmap(); |
235 return false; | 235 return false; |
236 } | 236 } |
237 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 237 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
238 shared_buf.Unmap(); | 238 shared_buf.Unmap(); |
239 | 239 |
240 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 240 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
241 shared_mem_handle)); | 241 shared_mem_handle)); |
242 return true; | 242 return true; |
243 } | 243 } |
OLD | NEW |