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 #if defined(USE_SKIA) | |
8 #include <algorithm> | |
9 #include <cmath> | |
10 #endif | |
7 #include <string> | 11 #include <string> |
8 | 12 |
9 #include "base/command_line.h" | 13 #include "base/command_line.h" |
10 #include "base/logging.h" | 14 #include "base/logging.h" |
11 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
12 #include "base/process_util.h" | 16 #include "base/process_util.h" |
13 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
14 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/print_messages.h" | 19 #include "chrome/common/print_messages.h" |
16 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
33 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
34 | 38 |
35 #if defined(OS_POSIX) | 39 #if defined(OS_POSIX) |
36 #include "content/common/view_messages.h" | 40 #include "content/common/view_messages.h" |
37 #endif | 41 #endif |
38 | 42 |
43 #if defined(USE_SKIA) | |
44 #include "base/i18n/time_formatting.h" | |
45 #include "base/string_number_conversions.h" | |
46 #include "base/time.h" | |
47 #include "skia/ext/vector_canvas.h" | |
48 #include "skia/ext/vector_platform_device_skia.h" | |
49 #include "third_party/skia/include/core/SkTypeface.h" | |
50 #include "ui/base/text/text_elider.h" | |
51 #endif // USE_SKIA | |
52 | |
53 using base::Time; | |
39 using printing::ConvertPixelsToPoint; | 54 using printing::ConvertPixelsToPoint; |
40 using printing::ConvertPixelsToPointDouble; | 55 using printing::ConvertPixelsToPointDouble; |
56 using printing::ConvertPointsToPixelDouble; | |
41 using printing::ConvertUnit; | 57 using printing::ConvertUnit; |
42 using printing::ConvertUnitDouble; | 58 using printing::ConvertUnitDouble; |
43 using WebKit::WebConsoleMessage; | 59 using WebKit::WebConsoleMessage; |
44 using WebKit::WebDocument; | 60 using WebKit::WebDocument; |
45 using WebKit::WebElement; | 61 using WebKit::WebElement; |
46 using WebKit::WebFrame; | 62 using WebKit::WebFrame; |
47 using WebKit::WebNode; | 63 using WebKit::WebNode; |
48 using WebKit::WebSize; | 64 using WebKit::WebSize; |
49 using WebKit::WebString; | 65 using WebKit::WebString; |
50 using WebKit::WebURLRequest; | 66 using WebKit::WebURLRequest; |
(...skipping 29 matching lines...) Expand all Loading... | |
80 oldParams.params.min_shrink == newParams.params.min_shrink && | 96 oldParams.params.min_shrink == newParams.params.min_shrink && |
81 oldParams.params.dpi == newParams.params.dpi && | 97 oldParams.params.dpi == newParams.params.dpi && |
82 oldParams.params.printable_size == newParams.params.printable_size && | 98 oldParams.params.printable_size == newParams.params.printable_size && |
83 oldParams.params.selection_only == newParams.params.selection_only && | 99 oldParams.params.selection_only == newParams.params.selection_only && |
84 oldParams.params.page_size == newParams.params.page_size && | 100 oldParams.params.page_size == newParams.params.page_size && |
85 oldParams.params.margin_top == newParams.params.margin_top && | 101 oldParams.params.margin_top == newParams.params.margin_top && |
86 oldParams.params.margin_left == newParams.params.margin_left && | 102 oldParams.params.margin_left == newParams.params.margin_left && |
87 oldParams.params.supports_alpha_blend == | 103 oldParams.params.supports_alpha_blend == |
88 newParams.params.supports_alpha_blend && | 104 newParams.params.supports_alpha_blend && |
89 oldParams.pages.size() == newParams.pages.size() && | 105 oldParams.pages.size() == newParams.pages.size() && |
106 oldParams.params.display_header_footer == | |
107 newParams.params.display_header_footer && | |
90 std::equal(oldParams.pages.begin(), oldParams.pages.end(), | 108 std::equal(oldParams.pages.begin(), oldParams.pages.end(), |
91 newParams.pages.begin()); | 109 newParams.pages.begin()); |
92 } | 110 } |
93 | 111 |
94 void CalculatePrintCanvasSize(const PrintMsg_Print_Params& print_params, | 112 void CalculatePrintCanvasSize(const PrintMsg_Print_Params& print_params, |
95 gfx::Size* result) { | 113 gfx::Size* result) { |
96 int dpi = GetDPI(&print_params); | 114 int dpi = GetDPI(&print_params); |
97 result->set_width(ConvertUnit(print_params.printable_size.width(), dpi, | 115 result->set_width(ConvertUnit(print_params.printable_size.width(), dpi, |
98 print_params.desired_dpi)); | 116 print_params.desired_dpi)); |
99 | 117 |
100 result->set_height(ConvertUnit(print_params.printable_size.height(), dpi, | 118 result->set_height(ConvertUnit(print_params.printable_size.height(), dpi, |
101 print_params.desired_dpi)); | 119 print_params.desired_dpi)); |
102 } | 120 } |
103 | 121 |
122 #if defined(USE_SKIA) | |
123 // Splits the horizontal width equally into segments with an interstice | |
124 // between each segment. Returns the width of this segment. | |
125 SkScalar GetSegmentWidth(const PageSizeMargins& page_layout) { | |
126 SkScalar page_width = page_layout.margin_left + | |
127 page_layout.content_width + | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
nit: indent should be 4.
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
128 page_layout.margin_right; | |
129 // Interstice is left at both ends of the page as well as between | |
130 // each region, so 1 is added. | |
131 SkScalar total_interstice_width = | |
132 (printing::kSettingHeaderFooterHorizontalRegions + 1) * | |
133 printing::kSettingHeaderFooterInterstice; | |
134 return (page_width - total_interstice_width) / | |
135 printing::kSettingHeaderFooterHorizontalRegions; | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
nit: indent should be 4.
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
136 } | |
137 | |
138 // Given a text, the positions, and the paint object, this method gets the | |
139 // coordinates and prints the text at those coordinates on the canvas. | |
140 void PrintHeaderFooterText( | |
141 string16 text, | |
142 SkPaint paint, | |
143 skia::VectorCanvas* canvas, | |
144 printing::HorizontalHeaderFooterPosition horizontal_position, | |
145 printing::VerticalHeaderFooterPosition vertical_position, | |
146 float webkit_scale_factor, | |
147 const PageSizeMargins& page_layout, | |
148 const SkScalar& max_text_width, | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
POD should be passed in directly... i.e. SkScalar
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
149 const gfx::Font& font, | |
150 const SkScalar& space_for_descenders) { | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
and here
vandebo (ex-Chrome)
2011/08/03 19:00:05
I guess I misunderstood before... this isn't the s
Aayush Kumar
2011/08/04 18:25:04
Done.
Aayush Kumar
2011/08/04 18:25:04
Renamed back to "height_to_baseline"
vandebo (ex-Chrome)
2011/08/04 20:46:21
nit: hmm, maybe offset_to_baseline would be better
Aayush Kumar
2011/08/04 23:00:30
Done.
| |
151 text = ui::ElideText(text, font, ConvertPointsToPixelDouble(max_text_width), | |
152 false); | |
153 | |
154 size_t text_byte_length = text.length() * sizeof(char16); | |
155 // Get the (x, y) coordinate from where printing of the current text should | |
156 // start depending on the horizontal alignment (LEFT, RIGHT, CENTER) and | |
157 // vertical alignment (TOP, BOTTOM). | |
158 SkScalar text_width_in_points = paint.measureText(text.c_str(), | |
159 text_byte_length); | |
160 SkScalar x = 0; | |
161 switch (horizontal_position) { | |
162 case printing::LEFT: { | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
{}'s are not needed on the cases statements in thi
Aayush Kumar
2011/08/04 18:25:04
According to the google C++ style guide, braces se
vandebo (ex-Chrome)
2011/08/04 20:46:21
Indeed, but the overriding rule is to follow exist
Aayush Kumar
2011/08/04 23:00:30
Done.
| |
163 x = printing::kSettingHeaderFooterInterstice - page_layout.margin_left; | |
164 break; | |
165 } | |
166 case printing::RIGHT: { | |
167 x = page_layout.content_width + page_layout.margin_right - | |
168 printing::kSettingHeaderFooterInterstice - text_width_in_points; | |
169 break; | |
170 } | |
171 case printing::CENTER: { | |
172 SkScalar available_width = GetSegmentWidth(page_layout); | |
173 x = available_width - page_layout.margin_left + | |
174 (available_width - text_width_in_points) / 2; | |
175 break; | |
176 } | |
177 default: { | |
178 NOTREACHED(); | |
179 } | |
180 } | |
181 | |
182 SkScalar y = 0; | |
183 switch (vertical_position) { | |
184 case printing::TOP: { | |
185 y = printing::kSettingHeaderFooterInterstice - | |
186 page_layout.margin_top - space_for_descenders; | |
187 break; | |
188 } | |
189 case printing::BOTTOM: { | |
190 y = page_layout.margin_bottom + page_layout.content_height - | |
191 printing::kSettingHeaderFooterInterstice - space_for_descenders; | |
192 break; | |
193 } | |
194 default: { | |
195 NOTREACHED(); | |
196 } | |
197 } | |
198 | |
199 x = x / webkit_scale_factor; | |
200 y = y / webkit_scale_factor; | |
201 paint.setTextSize(paint.getTextSize() / webkit_scale_factor); | |
202 canvas->drawText(text.c_str(), text_byte_length, x, y, paint); | |
203 } | |
204 #endif // USE_SKIA | |
205 | |
104 } // namespace | 206 } // namespace |
105 | 207 |
208 #if defined(USE_SKIA) | |
209 // static - Not anonymous so that platform implementations can use it. | |
210 void PrintWebViewHelper::PrintHeaderAndFooter( | |
211 SkDevice* device, | |
212 skia::VectorCanvas* canvas, | |
213 int page_number, | |
214 int total_pages, | |
215 float webkit_scale_factor, | |
216 const PageSizeMargins& page_layout, | |
217 const DictionaryValue& header_footer_info) { | |
218 // Set the drawing area to draw in the margins. | |
219 static_cast<skia::VectorPlatformDeviceSkia*>(device)->setDrawingArea( | |
220 SkPDFDevice::kMargin_DrawingArea); | |
221 | |
222 // Setting up styles for the headers and footers text. | |
223 SkPaint paint; | |
224 paint.setColor(SK_ColorBLACK); | |
225 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); | |
226 paint.setTextSize(printing::kSettingHeaderFooterFontSize); | |
227 gfx::Font font(UTF8ToUTF16(printing::kSettingHeaderFooterFontName), | |
228 ceil(ConvertPointsToPixelDouble( | |
229 printing::kSettingHeaderFooterFontSize))); | |
230 paint.setTypeface(SkTypeface::CreateFromName( | |
231 UTF16ToUTF8(font.GetFontName()).c_str(), SkTypeface::kNormal)); | |
232 | |
233 // Ensure we have enough space to print above and below the page to print | |
234 // headers. | |
235 string16 date = base::TimeFormatShortDateNumeric(Time::Now()); | |
236 string16 title; | |
237 if (!header_footer_info.GetString(printing::kSettingHeaderFooterTitle, | |
238 &title)) { | |
239 NOTREACHED(); | |
240 } | |
241 | |
242 SkRect header_bounds; | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
Put header_bounds below header_text
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
243 string16 header_text = date + title; | |
244 paint.measureText(header_text.c_str(), header_text.length() * sizeof(char16), | |
245 &header_bounds, 0); | |
246 | |
247 SkScalar text_height = | |
248 printing::kSettingHeaderFooterInterstice + header_bounds.height(); | |
249 | |
250 if (text_height > page_layout.margin_top) | |
251 return; | |
252 | |
253 // Ensure we have enough space to print above and below the page to print | |
254 // footers. | |
255 string16 page_of_total_pages = base::IntToString16(page_number) + | |
256 UTF8ToUTF16("/") + | |
257 base::IntToString16(total_pages); | |
258 std::string url; | |
259 if (!header_footer_info.GetString(printing::kSettingHeaderFooterURL, | |
260 &url)) { | |
261 NOTREACHED(); | |
262 } | |
263 | |
264 SkRect footer_bounds; | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
Put footer_bounds below footer_text
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
265 string16 footer_text = page_of_total_pages + UTF8ToUTF16(url); | |
266 paint.measureText(footer_text.c_str(), footer_text.length() * sizeof(char16), | |
267 &footer_bounds, 0); | |
268 | |
269 text_height = | |
270 printing::kSettingHeaderFooterInterstice + footer_bounds.height(); | |
271 | |
272 if (text_height > page_layout.margin_bottom) | |
273 return; | |
274 | |
275 SkScalar segment_width = GetSegmentWidth(page_layout); | |
276 // Print the Date. | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
Redundant comment.
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
277 PrintHeaderFooterText(date, paint, canvas, printing::LEFT, printing::TOP, | |
278 webkit_scale_factor, page_layout, segment_width, font, | |
279 header_bounds.top()); | |
280 | |
281 // Print the title. | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
Redundant comment.
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
282 SkScalar date_width = paint.measureText(date.c_str(), | |
283 date.length() * sizeof(char16)); | |
284 // Calculate the available title width. If the date string is not long | |
285 // enough, then, we increase the available space we have for the title. | |
286 // Assumes there is no header text to RIGHT of title. | |
287 SkScalar max_title_width = std::min(2 * segment_width, | |
288 2 * (segment_width - date_width) + | |
289 segment_width); | |
290 PrintHeaderFooterText(title, paint, canvas, printing::CENTER, | |
291 printing::TOP, webkit_scale_factor, page_layout, | |
292 max_title_width, font, header_bounds.top()); | |
293 | |
294 // Print the page numbers at the bottom right corner of page. | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
Redundant comment.
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
295 PrintHeaderFooterText(page_of_total_pages, paint, canvas, printing::RIGHT, | |
296 printing::BOTTOM, webkit_scale_factor, page_layout, | |
297 segment_width, font, footer_bounds.bottom()); | |
298 | |
299 // Print the URL. | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
Redundant comment.
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
300 GURL gurl(url); | |
301 SkScalar page_width = paint.measureText( | |
302 page_of_total_pages.c_str(), | |
303 page_of_total_pages.length() * sizeof(char16)); | |
304 | |
305 // Calculate the available URL width. We increase the available URL width | |
306 // if the |page_of_total_pages| string isn't long enough. | |
307 // Assumes no footer text being printed in the CENTER. | |
308 SkScalar max_url_width = | |
309 (page_layout.content_width + page_layout.margin_left + | |
310 page_layout.margin_right) * 3 / 4; | |
311 max_url_width = std::min(max_url_width, | |
312 2 * (segment_width - page_width) + segment_width); | |
313 string16 url_elided = ui::ElideUrl(gurl, font, | |
314 ConvertPointsToPixelDouble(max_url_width), | |
315 std::string()); | |
316 PrintHeaderFooterText(url_elided, paint, canvas, printing::LEFT, | |
317 printing::BOTTOM, webkit_scale_factor, page_layout, | |
318 max_url_width, font, footer_bounds.bottom()); | |
319 | |
320 // Restore the drawing area to draw in the content area. | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
Redundant comment.
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
321 static_cast<skia::VectorPlatformDeviceSkia*>(device)->setDrawingArea( | |
322 SkPDFDevice::kContent_DrawingArea); | |
323 } | |
324 #endif // USE_SKIA | |
325 | |
106 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 326 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
107 const PrintMsg_Print_Params& print_params, | 327 const PrintMsg_Print_Params& print_params, |
108 WebFrame* frame, | 328 WebFrame* frame, |
109 WebNode* node) | 329 WebNode* node) |
110 : frame_(frame), | 330 : frame_(frame), |
111 web_view_(frame->view()), | 331 web_view_(frame->view()), |
112 dpi_(static_cast<int>(print_params.dpi)), | 332 dpi_(static_cast<int>(print_params.dpi)), |
113 expected_pages_count_(0), | 333 expected_pages_count_(0), |
114 use_browser_overlays_(true), | 334 use_browser_overlays_(true), |
115 finished_(false) { | 335 finished_(false) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 return; | 469 return; |
250 } | 470 } |
251 | 471 |
252 WebFrame* pdf_frame = pdf_element.document().frame(); | 472 WebFrame* pdf_frame = pdf_element.document().frame(); |
253 scoped_ptr<PrepareFrameAndViewForPrint> prepare; | 473 scoped_ptr<PrepareFrameAndViewForPrint> prepare; |
254 if (!InitPrintSettingsAndPrepareFrame(pdf_frame, &pdf_element, &prepare)) { | 474 if (!InitPrintSettingsAndPrepareFrame(pdf_frame, &pdf_element, &prepare)) { |
255 NOTREACHED() << "Failed to initialize print page settings"; | 475 NOTREACHED() << "Failed to initialize print page settings"; |
256 return; | 476 return; |
257 } | 477 } |
258 | 478 |
259 if (!UpdatePrintSettings(job_settings)) { | 479 if (!UpdatePrintSettings(const_cast<DictionaryValue*>(&job_settings))) { |
260 DidFinishPrinting(FAIL_PRINT); | 480 DidFinishPrinting(FAIL_PRINT); |
261 return; | 481 return; |
262 } | 482 } |
263 | 483 |
264 // Render Pages for printing. | 484 // Render Pages for printing. |
265 if (!RenderPagesForPrint(pdf_frame, &pdf_element, prepare.get())) | 485 if (!RenderPagesForPrint(pdf_frame, &pdf_element, prepare.get())) |
266 DidFinishPrinting(FAIL_PRINT); | 486 DidFinishPrinting(FAIL_PRINT); |
267 } | 487 } |
268 | 488 |
269 bool PrintWebViewHelper::GetPrintFrame(WebKit::WebFrame** frame) { | 489 bool PrintWebViewHelper::GetPrintFrame(WebKit::WebFrame** frame) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { | 527 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { |
308 DCHECK(is_preview_); | 528 DCHECK(is_preview_); |
309 print_preview_context_.OnPrintPreview(); | 529 print_preview_context_.OnPrintPreview(); |
310 | 530 |
311 if (!InitPrintSettings(print_preview_context_.frame(), | 531 if (!InitPrintSettings(print_preview_context_.frame(), |
312 print_preview_context_.node())) { | 532 print_preview_context_.node())) { |
313 NOTREACHED(); | 533 NOTREACHED(); |
314 return; | 534 return; |
315 } | 535 } |
316 | 536 |
317 if (!UpdatePrintSettings(settings)) { | 537 if (!UpdatePrintSettings(const_cast<DictionaryValue*>(&settings))) { |
318 DidFinishPrinting(FAIL_PREVIEW); | 538 DidFinishPrinting(FAIL_PREVIEW); |
319 return; | 539 return; |
320 } | 540 } |
321 | 541 |
322 if (print_pages_params_->params.preview_request_id != 0 && | 542 if (print_pages_params_->params.preview_request_id != 0 && |
323 old_print_pages_params_.get() && | 543 old_print_pages_params_.get() && |
324 PrintMsg_Print_Params_IsEqual(*old_print_pages_params_, | 544 PrintMsg_Print_Params_IsEqual(*old_print_pages_params_, |
325 *print_pages_params_)) { | 545 *print_pages_params_)) { |
326 PrintHostMsg_DidPreviewDocument_Params preview_params; | 546 PrintHostMsg_DidPreviewDocument_Params preview_params; |
327 preview_params.reuse_existing_data = true; | 547 preview_params.reuse_existing_data = true; |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 const DictionaryValue& job_settings, | 973 const DictionaryValue& job_settings, |
754 PrintMsg_Print_Params* params) { | 974 PrintMsg_Print_Params* params) { |
755 if (!job_settings.GetInteger(printing::kPreviewRequestID, | 975 if (!job_settings.GetInteger(printing::kPreviewRequestID, |
756 &(params->preview_request_id))) { | 976 &(params->preview_request_id))) { |
757 NOTREACHED(); | 977 NOTREACHED(); |
758 return false; | 978 return false; |
759 } | 979 } |
760 return true; | 980 return true; |
761 } | 981 } |
762 | 982 |
763 bool PrintWebViewHelper::UpdatePrintSettings( | 983 bool PrintWebViewHelper::UpdatePrintSettings(DictionaryValue* job_settings) { |
764 const DictionaryValue& job_settings) { | |
765 PrintMsg_PrintPages_Params settings; | 984 PrintMsg_PrintPages_Params settings; |
766 | 985 |
767 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), | 986 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), |
768 print_pages_params_->params.document_cookie, job_settings, &settings)); | 987 print_pages_params_->params.document_cookie, *job_settings, &settings)); |
769 | 988 |
770 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) | 989 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) |
771 return false; | 990 return false; |
772 | 991 |
773 if (!UpdatePrintSettingsRequestId(job_settings, &(settings.params))) | 992 if (!UpdatePrintSettingsRequestId(*job_settings, &(settings.params))) |
774 return false; | 993 return false; |
775 | 994 |
776 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 995 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
996 // Getting Header and Footer settings. | |
997 bool display_header_footer = false; | |
998 if (!job_settings->GetBoolean(printing::kSettingHeaderFooter, | |
999 &display_header_footer)) { | |
1000 NOTREACHED(); | |
1001 } | |
1002 if (!job_settings->Remove(printing::kSettingHeaderFooter, NULL)) | |
vandebo (ex-Chrome)
2011/08/03 19:00:05
I don't think it's worth the effort to remove thes
Aayush Kumar
2011/08/04 18:25:04
Done.
| |
1003 NOTREACHED(); | |
1004 print_pages_params_->params.display_header_footer = display_header_footer; | |
1005 | |
1006 if (display_header_footer) { | |
1007 string16 title; | |
1008 std::string url; | |
1009 if (!job_settings->GetString(printing::kSettingHeaderFooterTitle, &title) || | |
1010 !job_settings->GetString(printing::kSettingHeaderFooterURL, &url)) { | |
1011 NOTREACHED(); | |
1012 } | |
1013 header_footer_info_.reset(new DictionaryValue()); | |
1014 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, url); | |
1015 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, title); | |
1016 | |
1017 if (!job_settings->Remove(printing::kSettingHeaderFooterTitle, NULL) || | |
1018 !job_settings->Remove(printing::kSettingHeaderFooterURL, NULL)) { | |
1019 NOTREACHED(); | |
1020 } | |
1021 } | |
1022 | |
777 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 1023 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
778 settings.params.document_cookie)); | 1024 settings.params.document_cookie)); |
779 return true; | 1025 return true; |
780 } | 1026 } |
781 | 1027 |
782 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 1028 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
783 int expected_pages_count, | 1029 int expected_pages_count, |
784 bool use_browser_overlays) { | 1030 bool use_browser_overlays) { |
785 PrintHostMsg_ScriptedPrint_Params params; | 1031 PrintHostMsg_ScriptedPrint_Params params; |
786 PrintMsg_PrintPages_Params print_settings; | 1032 PrintMsg_PrintPages_Params print_settings; |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1116 const gfx::Size& | 1362 const gfx::Size& |
1117 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { | 1363 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { |
1118 return prep_frame_view_->GetPrintCanvasSize(); | 1364 return prep_frame_view_->GetPrintCanvasSize(); |
1119 } | 1365 } |
1120 | 1366 |
1121 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1367 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
1122 prep_frame_view_.reset(); | 1368 prep_frame_view_.reset(); |
1123 metafile_.reset(); | 1369 metafile_.reset(); |
1124 rendered_pages_.clear(); | 1370 rendered_pages_.clear(); |
1125 } | 1371 } |
OLD | NEW |