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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/scoped_nsautorelease_pool.h" | 10 #include "base/mac/scoped_nsautorelease_pool.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "components/printing/common/print_messages.h" | 12 #include "components/printing/common/print_messages.h" |
| 13 #include "printing/features/features.h" |
13 #include "printing/metafile_skia_wrapper.h" | 14 #include "printing/metafile_skia_wrapper.h" |
14 #include "printing/page_size_margins.h" | 15 #include "printing/page_size_margins.h" |
15 #include "third_party/WebKit/public/platform/WebCanvas.h" | 16 #include "third_party/WebKit/public/platform/WebCanvas.h" |
16 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 17 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
17 #include "third_party/skia/include/core/SkCanvas.h" | 18 #include "third_party/skia/include/core/SkCanvas.h" |
18 | 19 |
19 namespace printing { | 20 namespace printing { |
20 | 21 |
21 #if defined(ENABLE_BASIC_PRINTING) | 22 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
22 bool PrintWebViewHelper::PrintPagesNative(blink::WebLocalFrame* frame, | 23 bool PrintWebViewHelper::PrintPagesNative(blink::WebLocalFrame* frame, |
23 int page_count) { | 24 int page_count) { |
24 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 25 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
25 const PrintMsg_Print_Params& print_params = params.params; | 26 const PrintMsg_Print_Params& print_params = params.params; |
26 | 27 |
27 std::vector<int> printed_pages = GetPrintedPages(params, page_count); | 28 std::vector<int> printed_pages = GetPrintedPages(params, page_count); |
28 if (printed_pages.empty()) | 29 if (printed_pages.empty()) |
29 return false; | 30 return false; |
30 | 31 |
31 PrintMsg_PrintPage_Params page_params; | 32 PrintMsg_PrintPage_Params page_params; |
32 page_params.params = print_params; | 33 page_params.params = print_params; |
33 for (int page_number : printed_pages) { | 34 for (int page_number : printed_pages) { |
34 page_params.page_number = page_number; | 35 page_params.page_number = page_number; |
35 PrintPageInternal(page_params, frame); | 36 PrintPageInternal(page_params, frame); |
36 } | 37 } |
37 return true; | 38 return true; |
38 } | 39 } |
39 #endif // defined(ENABLE_BASIC_PRINTING) | 40 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
40 | 41 |
41 void PrintWebViewHelper::PrintPageInternal( | 42 void PrintWebViewHelper::PrintPageInternal( |
42 const PrintMsg_PrintPage_Params& params, | 43 const PrintMsg_PrintPage_Params& params, |
43 blink::WebLocalFrame* frame) { | 44 blink::WebLocalFrame* frame) { |
44 PdfMetafileSkia metafile(PDF_SKIA_DOCUMENT_TYPE); | 45 PdfMetafileSkia metafile(PDF_SKIA_DOCUMENT_TYPE); |
45 CHECK(metafile.Init()); | 46 CHECK(metafile.Init()); |
46 | 47 |
47 int page_number = params.page_number; | 48 int page_number = params.page_number; |
48 gfx::Size page_size_in_dpi; | 49 gfx::Size page_size_in_dpi; |
49 gfx::Rect content_area_in_dpi; | 50 gfx::Rect content_area_in_dpi; |
(...skipping 11 matching lines...) Expand all Loading... |
61 // Ask the browser to create the shared memory for us. | 62 // Ask the browser to create the shared memory for us. |
62 if (!CopyMetafileDataToSharedMem(metafile, | 63 if (!CopyMetafileDataToSharedMem(metafile, |
63 &(page_params.metafile_data_handle))) { | 64 &(page_params.metafile_data_handle))) { |
64 // TODO(thestig): Fail and return false instead. | 65 // TODO(thestig): Fail and return false instead. |
65 page_params.data_size = 0; | 66 page_params.data_size = 0; |
66 } | 67 } |
67 | 68 |
68 Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params)); | 69 Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params)); |
69 } | 70 } |
70 | 71 |
71 #if defined(ENABLE_PRINT_PREVIEW) | 72 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
72 bool PrintWebViewHelper::RenderPreviewPage( | 73 bool PrintWebViewHelper::RenderPreviewPage( |
73 int page_number, | 74 int page_number, |
74 const PrintMsg_Print_Params& print_params) { | 75 const PrintMsg_Print_Params& print_params) { |
75 PrintMsg_Print_Params printParams = print_params; | 76 PrintMsg_Print_Params printParams = print_params; |
76 std::unique_ptr<PdfMetafileSkia> draft_metafile; | 77 std::unique_ptr<PdfMetafileSkia> draft_metafile; |
77 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); | 78 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); |
78 | 79 |
79 bool render_to_draft = print_preview_context_.IsModifiable() && | 80 bool render_to_draft = print_preview_context_.IsModifiable() && |
80 is_print_ready_metafile_sent_; | 81 is_print_ready_metafile_sent_; |
81 | 82 |
(...skipping 16 matching lines...) Expand all Loading... |
98 if (print_preview_context_.IsModifiable() && | 99 if (print_preview_context_.IsModifiable() && |
99 print_preview_context_.generate_draft_pages()) { | 100 print_preview_context_.generate_draft_pages()) { |
100 DCHECK(!draft_metafile.get()); | 101 DCHECK(!draft_metafile.get()); |
101 draft_metafile = | 102 draft_metafile = |
102 print_preview_context_.metafile()->GetMetafileForCurrentPage( | 103 print_preview_context_.metafile()->GetMetafileForCurrentPage( |
103 PDF_SKIA_DOCUMENT_TYPE); | 104 PDF_SKIA_DOCUMENT_TYPE); |
104 } | 105 } |
105 } | 106 } |
106 return PreviewPageRendered(page_number, draft_metafile.get()); | 107 return PreviewPageRendered(page_number, draft_metafile.get()); |
107 } | 108 } |
108 #endif // defined(ENABLE_PRINT_PREVIEW) | 109 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
109 | 110 |
110 void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params, | 111 void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params, |
111 int page_number, | 112 int page_number, |
112 blink::WebLocalFrame* frame, | 113 blink::WebLocalFrame* frame, |
113 bool is_preview, | 114 bool is_preview, |
114 PdfMetafileSkia* metafile, | 115 PdfMetafileSkia* metafile, |
115 gfx::Size* page_size, | 116 gfx::Size* page_size, |
116 gfx::Rect* content_rect) { | 117 gfx::Rect* content_rect) { |
117 double scale_factor = | 118 double scale_factor = |
118 params.scale_factor >= kEpsilon ? params.scale_factor : 1.0f; | 119 params.scale_factor >= kEpsilon ? params.scale_factor : 1.0f; |
(...skipping 15 matching lines...) Expand all Loading... |
134 params.display_header_footer ? gfx::Rect(*page_size) : content_area; | 135 params.display_header_footer ? gfx::Rect(*page_size) : content_area; |
135 | 136 |
136 { | 137 { |
137 SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( | 138 SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( |
138 *page_size, canvas_area, scale_factor); | 139 *page_size, canvas_area, scale_factor); |
139 if (!canvas) | 140 if (!canvas) |
140 return; | 141 return; |
141 | 142 |
142 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 143 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
143 skia::SetIsPreviewMetafile(*canvas, is_preview); | 144 skia::SetIsPreviewMetafile(*canvas, is_preview); |
144 #if defined(ENABLE_PRINT_PREVIEW) | 145 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
145 if (params.display_header_footer) { | 146 if (params.display_header_footer) { |
146 PrintHeaderAndFooter(static_cast<blink::WebCanvas*>(canvas), | 147 PrintHeaderAndFooter(static_cast<blink::WebCanvas*>(canvas), |
147 page_number + 1, | 148 page_number + 1, |
148 print_preview_context_.total_page_count(), *frame, | 149 print_preview_context_.total_page_count(), *frame, |
149 scale_factor, page_layout_in_points, params); | 150 scale_factor, page_layout_in_points, params); |
150 } | 151 } |
151 #endif // defined(ENABLE_PRINT_PREVIEW) | 152 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
152 RenderPageContent(frame, page_number, canvas_area, content_area, | 153 RenderPageContent(frame, page_number, canvas_area, content_area, |
153 scale_factor, static_cast<blink::WebCanvas*>(canvas)); | 154 scale_factor, static_cast<blink::WebCanvas*>(canvas)); |
154 } | 155 } |
155 | 156 |
156 // Done printing. Close the device context to retrieve the compiled metafile. | 157 // Done printing. Close the device context to retrieve the compiled metafile. |
157 metafile->FinishPage(); | 158 metafile->FinishPage(); |
158 } | 159 } |
159 | 160 |
160 } // namespace printing | 161 } // namespace printing |
OLD | NEW |