OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "chrome/common/print_messages.h" | 11 #include "chrome/common/print_messages.h" |
12 #include "printing/native_metafile_factory.h" | 12 #include "printing/native_metafile_factory.h" |
13 #include "printing/native_metafile.h" | 13 #include "printing/native_metafile.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
15 | 15 |
16 using WebKit::WebFrame; | 16 using WebKit::WebFrame; |
17 | 17 |
18 void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params, | 18 void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params, |
19 const gfx::Size& canvas_size, | 19 const gfx::Size& canvas_size, |
20 WebFrame* frame) { | 20 WebFrame* frame) { |
21 scoped_ptr<printing::NativeMetafile> metafile( | 21 scoped_ptr<printing::NativeMetafile> metafile( |
22 printing::NativeMetafileFactory::Create()); | 22 printing::NativeMetafileFactory::Create()); |
23 if (!metafile->Init()) | 23 if(!metafile.get()) |
24 return; | 24 return; |
25 | 25 |
26 float scale_factor = frame->getPrintPageShrink(params.page_number); | 26 float scale_factor = frame->getPrintPageShrink(params.page_number); |
27 int page_number = params.page_number; | 27 int page_number = params.page_number; |
28 | 28 |
29 // Render page for printing. | 29 // Render page for printing. |
30 gfx::Point origin(0.0f, 0.0f); | 30 gfx::Point origin(0.0f, 0.0f); |
31 RenderPage(params.params.printable_size, origin, scale_factor, page_number, | 31 RenderPage(params.params.printable_size, origin, scale_factor, page_number, |
32 frame, metafile.get()); | 32 frame, metafile.get()); |
33 metafile->FinishDocument(); | 33 metafile->FinishDocument(); |
(...skipping 26 matching lines...) Expand all Loading... |
60 | 60 |
61 PrepareFrameAndViewForPrint prep_frame_view(printParams, | 61 PrepareFrameAndViewForPrint prep_frame_view(printParams, |
62 frame, node, frame->view()); | 62 frame, node, frame->view()); |
63 int page_count = prep_frame_view.GetExpectedPageCount(); | 63 int page_count = prep_frame_view.GetExpectedPageCount(); |
64 | 64 |
65 if (!page_count) | 65 if (!page_count) |
66 return; | 66 return; |
67 | 67 |
68 scoped_ptr<printing::NativeMetafile> metafile( | 68 scoped_ptr<printing::NativeMetafile> metafile( |
69 printing::NativeMetafileFactory::Create()); | 69 printing::NativeMetafileFactory::Create()); |
70 if (!metafile->Init()) | 70 if(!metafile.get()) |
71 return; | 71 return; |
72 | 72 |
73 float scale_factor = frame->getPrintPageShrink(0); | 73 float scale_factor = frame->getPrintPageShrink(0); |
74 gfx::Point origin(printParams.margin_left, printParams.margin_top); | 74 gfx::Point origin(printParams.margin_left, printParams.margin_top); |
75 if (params.pages.empty()) { | 75 if (params.pages.empty()) { |
76 for (int i = 0; i < page_count; ++i) { | 76 for (int i = 0; i < page_count; ++i) { |
77 RenderPage(printParams.page_size, origin, scale_factor, i, frame, | 77 RenderPage(printParams.page_size, origin, scale_factor, i, frame, |
78 metafile.get()); | 78 metafile.get()); |
79 } | 79 } |
80 } else { | 80 } else { |
(...skipping 30 matching lines...) Expand all Loading... |
111 // printPage can create autoreleased references to |context|. PDF contexts | 111 // printPage can create autoreleased references to |context|. PDF contexts |
112 // don't write all their data until they are destroyed, so we need to make | 112 // don't write all their data until they are destroyed, so we need to make |
113 // certain that there are no lingering references. | 113 // certain that there are no lingering references. |
114 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | 114 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; |
115 frame->printPage(page_number, metafile->context()); | 115 frame->printPage(page_number, metafile->context()); |
116 [pool release]; | 116 [pool release]; |
117 | 117 |
118 // Done printing. Close the device context to retrieve the compiled metafile. | 118 // Done printing. Close the device context to retrieve the compiled metafile. |
119 metafile->FinishPage(); | 119 metafile->FinishPage(); |
120 } | 120 } |
OLD | NEW |