OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/printing/print_web_view_helper.h" | 5 #include "chrome/renderer/printing/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/process/process_handle.h" | 9 #include "base/process/process_handle.h" |
10 #include "chrome/common/print_messages.h" | 10 #include "chrome/common/print_messages.h" |
11 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
12 #include "printing/metafile.h" | |
13 #include "printing/metafile_skia_wrapper.h" | 12 #include "printing/metafile_skia_wrapper.h" |
14 #include "printing/page_size_margins.h" | 13 #include "printing/page_size_margins.h" |
15 #include "printing/pdf_metafile_skia.h" | 14 #include "printing/pdf_metafile_skia.h" |
16 #include "printing/units.h" | 15 #include "printing/units.h" |
17 #include "skia/ext/platform_device.h" | 16 #include "skia/ext/platform_device.h" |
18 #include "skia/ext/vector_canvas.h" | 17 #include "skia/ext/vector_canvas.h" |
19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
20 | 19 |
21 | 20 |
22 namespace printing { | 21 namespace printing { |
23 | 22 |
24 using blink::WebFrame; | 23 using blink::WebFrame; |
25 | 24 |
26 bool PrintWebViewHelper::RenderPreviewPage( | 25 bool PrintWebViewHelper::RenderPreviewPage( |
27 int page_number, | 26 int page_number, |
28 const PrintMsg_Print_Params& print_params) { | 27 const PrintMsg_Print_Params& print_params) { |
29 PrintMsg_PrintPage_Params page_params; | 28 PrintMsg_PrintPage_Params page_params; |
30 page_params.params = print_params; | 29 page_params.params = print_params; |
31 page_params.page_number = page_number; | 30 page_params.page_number = page_number; |
32 scoped_ptr<Metafile> draft_metafile; | 31 scoped_ptr<PdfMetafileSkia> draft_metafile; |
33 Metafile* initial_render_metafile = print_preview_context_.metafile(); | 32 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); |
34 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { | 33 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { |
35 draft_metafile.reset(new PdfMetafileSkia); | 34 draft_metafile.reset(new PdfMetafileSkia); |
36 initial_render_metafile = draft_metafile.get(); | 35 initial_render_metafile = draft_metafile.get(); |
37 } | 36 } |
38 | 37 |
39 base::TimeTicks begin_time = base::TimeTicks::Now(); | 38 base::TimeTicks begin_time = base::TimeTicks::Now(); |
40 PrintPageInternal(page_params, | 39 PrintPageInternal(page_params, |
41 print_preview_context_.GetPrintCanvasSize(), | 40 print_preview_context_.GetPrintCanvasSize(), |
42 print_preview_context_.prepared_frame(), | 41 print_preview_context_.prepared_frame(), |
43 initial_render_metafile, | 42 initial_render_metafile, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 Send(new PrintHostMsg_DidPrintPage(routing_id(), printed_page_params)); | 141 Send(new PrintHostMsg_DidPrintPage(routing_id(), printed_page_params)); |
143 printed_page_params.metafile_data_handle = INVALID_HANDLE_VALUE; | 142 printed_page_params.metafile_data_handle = INVALID_HANDLE_VALUE; |
144 } | 143 } |
145 return true; | 144 return true; |
146 } | 145 } |
147 | 146 |
148 void PrintWebViewHelper::PrintPageInternal( | 147 void PrintWebViewHelper::PrintPageInternal( |
149 const PrintMsg_PrintPage_Params& params, | 148 const PrintMsg_PrintPage_Params& params, |
150 const gfx::Size& canvas_size, | 149 const gfx::Size& canvas_size, |
151 WebFrame* frame, | 150 WebFrame* frame, |
152 Metafile* metafile, | 151 PdfMetafileSkia* metafile, |
153 gfx::Size* page_size_in_dpi, | 152 gfx::Size* page_size_in_dpi, |
154 gfx::Rect* content_area_in_dpi) { | 153 gfx::Rect* content_area_in_dpi) { |
155 PageSizeMargins page_layout_in_points; | 154 PageSizeMargins page_layout_in_points; |
156 double css_scale_factor = 1.0f; | 155 double css_scale_factor = 1.0f; |
157 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 156 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
158 ignore_css_margins_, &css_scale_factor, | 157 ignore_css_margins_, &css_scale_factor, |
159 &page_layout_in_points); | 158 &page_layout_in_points); |
160 gfx::Size page_size; | 159 gfx::Size page_size; |
161 gfx::Rect content_area; | 160 gfx::Rect content_area; |
162 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 161 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 content_area, | 213 content_area, |
215 scale_factor, | 214 scale_factor, |
216 canvas.get()); | 215 canvas.get()); |
217 DCHECK_GT(webkit_scale_factor, 0.0f); | 216 DCHECK_GT(webkit_scale_factor, 0.0f); |
218 // Done printing. Close the device context to retrieve the compiled metafile. | 217 // Done printing. Close the device context to retrieve the compiled metafile. |
219 if (!metafile->FinishPage()) | 218 if (!metafile->FinishPage()) |
220 NOTREACHED() << "metafile failed"; | 219 NOTREACHED() << "metafile failed"; |
221 } | 220 } |
222 | 221 |
223 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( | 222 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( |
224 Metafile* metafile, base::SharedMemoryHandle* shared_mem_handle) { | 223 PdfMetafileSkia* metafile, |
| 224 base::SharedMemoryHandle* shared_mem_handle) { |
225 uint32 buf_size = metafile->GetDataSize(); | 225 uint32 buf_size = metafile->GetDataSize(); |
226 base::SharedMemory shared_buf; | 226 base::SharedMemory shared_buf; |
227 // Allocate a shared memory buffer to hold the generated metafile data. | 227 // Allocate a shared memory buffer to hold the generated metafile data. |
228 if (!shared_buf.CreateAndMapAnonymous(buf_size)) { | 228 if (!shared_buf.CreateAndMapAnonymous(buf_size)) { |
229 NOTREACHED() << "Buffer allocation failed"; | 229 NOTREACHED() << "Buffer allocation failed"; |
230 return false; | 230 return false; |
231 } | 231 } |
232 | 232 |
233 // Copy the bits into shared memory. | 233 // Copy the bits into shared memory. |
234 if (!metafile->GetData(shared_buf.memory(), buf_size)) { | 234 if (!metafile->GetData(shared_buf.memory(), buf_size)) { |
235 NOTREACHED() << "GetData() failed"; | 235 NOTREACHED() << "GetData() failed"; |
236 shared_buf.Unmap(); | 236 shared_buf.Unmap(); |
237 return false; | 237 return false; |
238 } | 238 } |
239 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 239 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
240 shared_buf.Unmap(); | 240 shared_buf.Unmap(); |
241 | 241 |
242 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 242 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
243 shared_mem_handle)); | 243 shared_mem_handle)); |
244 return true; | 244 return true; |
245 } | 245 } |
246 | 246 |
247 } // namespace printing | 247 } // namespace printing |
OLD | NEW |