OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/gfx/jpeg_codec.h" | 8 #include "base/gfx/jpeg_codec.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 using WebKit::WebRect; | 22 using WebKit::WebRect; |
23 using WebKit::WebScreenInfo; | 23 using WebKit::WebScreenInfo; |
24 using WebKit::WebString; | 24 using WebKit::WebString; |
25 using WebKit::WebURLRequest; | 25 using WebKit::WebURLRequest; |
26 | 26 |
27 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 27 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
28 const ViewMsg_Print_Params& print_params, | 28 const ViewMsg_Print_Params& print_params, |
29 WebFrame* frame, | 29 WebFrame* frame, |
30 WebView* web_view) | 30 WebView* web_view) |
31 : frame_(frame), web_view_(web_view), expected_pages_count_(0) { | 31 : frame_(frame), web_view_(web_view), expected_pages_count_(0) { |
32 | |
33 print_canvas_size_.set_width( | 32 print_canvas_size_.set_width( |
34 printing::ConvertUnit(print_params.printable_size.width(), | 33 printing::ConvertUnit(print_params.printable_size.width(), |
35 static_cast<int>(print_params.dpi), | 34 static_cast<int>(print_params.dpi), |
36 print_params.desired_dpi)); | 35 print_params.desired_dpi)); |
37 | 36 |
38 print_canvas_size_.set_height( | 37 print_canvas_size_.set_height( |
39 printing::ConvertUnit(print_params.printable_size.height(), | 38 printing::ConvertUnit(print_params.printable_size.height(), |
40 static_cast<int>(print_params.dpi), | 39 static_cast<int>(print_params.dpi), |
41 print_params.desired_dpi)); | 40 print_params.desired_dpi)); |
42 | 41 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 url_str.append(html); | 106 url_str.append(html); |
108 GURL url(url_str); | 107 GURL url(url_str); |
109 | 108 |
110 // When loading is done this will call DidStopLoading that will do the | 109 // When loading is done this will call DidStopLoading that will do the |
111 // actual printing. | 110 // actual printing. |
112 print_web_view_->GetMainFrame()->loadRequest(WebURLRequest(url)); | 111 print_web_view_->GetMainFrame()->loadRequest(WebURLRequest(url)); |
113 | 112 |
114 return true; | 113 return true; |
115 } | 114 } |
116 | 115 |
117 void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, | |
118 WebFrame* frame) { | |
119 PrepareFrameAndViewForPrint prep_frame_view(params.params, | |
120 frame, | |
121 frame->view()); | |
122 int page_count = prep_frame_view.GetExpectedPageCount(); | |
123 | |
124 Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id(), | |
125 params.params.document_cookie, | |
126 page_count)); | |
127 if (page_count) { | |
128 ViewMsg_PrintPage_Params page_params; | |
129 page_params.params = params.params; | |
130 if (params.pages.empty()) { | |
131 for (int i = 0; i < page_count; ++i) { | |
132 page_params.page_number = i; | |
133 PrintPage(page_params, prep_frame_view.GetPrintCanvasSize(), frame); | |
134 } | |
135 } else { | |
136 for (size_t i = 0; i < params.pages.size(); ++i) { | |
137 page_params.page_number = params.pages[i]; | |
138 PrintPage(page_params, prep_frame_view.GetPrintCanvasSize(), frame); | |
139 } | |
140 } | |
141 } | |
142 } | |
143 | |
144 void PrintWebViewHelper::PrintPageAsJPEG( | 116 void PrintWebViewHelper::PrintPageAsJPEG( |
145 const ViewMsg_PrintPage_Params& params, | 117 const ViewMsg_PrintPage_Params& params, |
146 WebFrame* frame, | 118 WebFrame* frame, |
147 float zoom_factor, | 119 float zoom_factor, |
148 std::vector<unsigned char>* image_data) { | 120 std::vector<unsigned char>* image_data) { |
149 PrepareFrameAndViewForPrint prep_frame_view(params.params, | 121 PrepareFrameAndViewForPrint prep_frame_view(params.params, |
150 frame, | 122 frame, |
151 frame->view()); | 123 frame->view()); |
152 const gfx::Size& canvas_size(prep_frame_view.GetPrintCanvasSize()); | 124 const gfx::Size& canvas_size(prep_frame_view.GetPrintCanvasSize()); |
153 | 125 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 WebScreenInfo PrintWebViewHelper::screenInfo() { | 174 WebScreenInfo PrintWebViewHelper::screenInfo() { |
203 NOTREACHED(); | 175 NOTREACHED(); |
204 return WebScreenInfo(); | 176 return WebScreenInfo(); |
205 } | 177 } |
206 | 178 |
207 void PrintWebViewHelper::DidStopLoading(WebView* webview) { | 179 void PrintWebViewHelper::DidStopLoading(WebView* webview) { |
208 DCHECK(print_pages_params_.get() != NULL); | 180 DCHECK(print_pages_params_.get() != NULL); |
209 DCHECK_EQ(webview, print_web_view_.get()); | 181 DCHECK_EQ(webview, print_web_view_.get()); |
210 PrintPages(*print_pages_params_.get(), print_web_view_->GetMainFrame()); | 182 PrintPages(*print_pages_params_.get(), print_web_view_->GetMainFrame()); |
211 } | 183 } |
OLD | NEW |