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/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "chrome/common/print_messages.h" | 11 #include "chrome/common/print_messages.h" |
12 #include "content/public/renderer/render_thread.h" | 12 #include "content/public/renderer/render_thread.h" |
13 #include "printing/metafile.h" | 13 #include "printing/metafile.h" |
14 #include "printing/metafile_impl.h" | 14 #include "printing/metafile_impl.h" |
15 #include "printing/metafile_skia_wrapper.h" | 15 #include "printing/metafile_skia_wrapper.h" |
16 #include "printing/page_size_margins.h" | 16 #include "printing/page_size_margins.h" |
17 #include "skia/ext/platform_device.h" | 17 #include "skia/ext/platform_device.h" |
18 #include "skia/ext/vector_canvas.h" | 18 #include "skia/ext/vector_canvas.h" |
19 #include "third_party/skia/include/core/SkRefCnt.h" | |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
21 | 20 |
22 #if !defined(OS_CHROMEOS) | 21 #if !defined(OS_CHROMEOS) |
23 #include "base/process_util.h" | 22 #include "base/process_util.h" |
24 #endif // !defined(OS_CHROMEOS) | 23 #endif // !defined(OS_CHROMEOS) |
25 | 24 |
26 using WebKit::WebFrame; | 25 using WebKit::WebFrame; |
27 using WebKit::WebNode; | 26 using WebKit::WebNode; |
28 | 27 |
29 bool PrintWebViewHelper::RenderPreviewPage( | 28 bool PrintWebViewHelper::RenderPreviewPage( |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 gfx::Rect canvas_area = | 186 gfx::Rect canvas_area = |
188 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | 187 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; |
189 | 188 |
190 SkDevice* device = metafile->StartPageForVectorCanvas(page_size, canvas_area, | 189 SkDevice* device = metafile->StartPageForVectorCanvas(page_size, canvas_area, |
191 scale_factor); | 190 scale_factor); |
192 if (!device) | 191 if (!device) |
193 return; | 192 return; |
194 | 193 |
195 // The printPage method take a reference to the canvas we pass down, so it | 194 // The printPage method take a reference to the canvas we pass down, so it |
196 // can't be a stack object. | 195 // can't be a stack object. |
197 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 196 skia::RefPtr<skia::VectorCanvas> canvas = |
198 canvas->unref(); // SkRefPtr and new both took a reference. | 197 skia::AdoptRef(new skia::VectorCanvas(device)); |
199 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 198 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
200 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 199 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
201 | 200 |
202 if (params.params.display_header_footer) { | 201 if (params.params.display_header_footer) { |
203 // |page_number| is 0-based, so 1 is added. | 202 // |page_number| is 0-based, so 1 is added. |
204 // TODO(vitalybuka) : why does it work only with 1.25? | 203 // TODO(vitalybuka) : why does it work only with 1.25? |
205 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, | 204 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, |
206 print_preview_context_.total_page_count(), | 205 print_preview_context_.total_page_count(), |
207 scale_factor / 1.25, | 206 scale_factor / 1.25, |
208 page_layout_in_points, *header_footer_info_, | 207 page_layout_in_points, *header_footer_info_, |
209 params.params); | 208 params.params); |
210 } | 209 } |
211 RenderPageContent(frame, params.page_number, canvas_area, content_area, | 210 RenderPageContent(frame, params.page_number, canvas_area, content_area, |
212 scale_factor, canvas.get()); | 211 scale_factor, canvas.get()); |
213 | 212 |
214 // Done printing. Close the device context to retrieve the compiled metafile. | 213 // Done printing. Close the device context to retrieve the compiled metafile. |
215 if (!metafile->FinishPage()) | 214 if (!metafile->FinishPage()) |
216 NOTREACHED() << "metafile failed"; | 215 NOTREACHED() << "metafile failed"; |
217 } | 216 } |
OLD | NEW |