Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/renderer/print_web_view_helper.cc

Issue 11367033: "Using" cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | chrome/renderer/print_web_view_helper_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 #if defined(OS_WIN) || defined(OS_MACOSX) 54 #if defined(OS_WIN) || defined(OS_MACOSX)
55 #define USE_RENDER_TEXT 55 #define USE_RENDER_TEXT
56 #endif 56 #endif
57 57
58 #if defined(USE_RENDER_TEXT) 58 #if defined(USE_RENDER_TEXT)
59 #include "ui/gfx/canvas.h" 59 #include "ui/gfx/canvas.h"
60 #include "ui/gfx/render_text.h" 60 #include "ui/gfx/render_text.h"
61 #endif 61 #endif
62 62
63 using printing::ConvertPixelsToPoint;
64 using printing::ConvertPixelsToPointDouble;
65 using printing::ConvertPointsToPixelDouble;
66 using printing::ConvertUnit; 63 using printing::ConvertUnit;
67 using printing::ConvertUnitDouble;
68 using printing::GetHeaderFooterSegmentWidth;
69 using printing::PageSizeMargins; 64 using printing::PageSizeMargins;
70 using WebKit::WebConsoleMessage; 65 using printing::kPixelsPerInch;
71 using WebKit::WebDocument; 66 using printing::kPointsPerInch;
72 using WebKit::WebElement;
73 using WebKit::WebFrame; 67 using WebKit::WebFrame;
74 using WebKit::WebNode; 68 using WebKit::WebNode;
75 using WebKit::WebPlugin;
76 using WebKit::WebPluginDocument;
77 using WebKit::WebPrintParams;
78 using WebKit::WebSize;
79 using WebKit::WebString;
80 using WebKit::WebURLRequest;
81 using WebKit::WebView;
82 69
83 namespace { 70 namespace {
84 71
85 #if defined(USE_RENDER_TEXT) 72 #if defined(USE_RENDER_TEXT)
86 typedef gfx::RenderText* HeaderFooterPaint; 73 typedef gfx::RenderText* HeaderFooterPaint;
87 #else 74 #else
88 typedef SkPaint HeaderFooterPaint; 75 typedef SkPaint HeaderFooterPaint;
89 #endif 76 #endif
90 77
91 const double kMinDpi = 1.0; 78 const double kMinDpi = 1.0;
92 79
93 int GetDPI(const PrintMsg_Print_Params* print_params) { 80 int GetDPI(const PrintMsg_Print_Params* print_params) {
94 #if defined(OS_MACOSX) 81 #if defined(OS_MACOSX)
95 // On the Mac, the printable area is in points, don't do any scaling based 82 // On the Mac, the printable area is in points, don't do any scaling based
96 // on dpi. 83 // on dpi.
97 return printing::kPointsPerInch; 84 return kPointsPerInch;
98 #else 85 #else
99 return static_cast<int>(print_params->dpi); 86 return static_cast<int>(print_params->dpi);
100 #endif // defined(OS_MACOSX) 87 #endif // defined(OS_MACOSX)
101 } 88 }
102 89
103 bool PrintMsg_Print_Params_IsValid(const PrintMsg_Print_Params& params) { 90 bool PrintMsg_Print_Params_IsValid(const PrintMsg_Print_Params& params) {
104 return !params.content_size.IsEmpty() && !params.page_size.IsEmpty() && 91 return !params.content_size.IsEmpty() && !params.page_size.IsEmpty() &&
105 !params.printable_area.IsEmpty() && params.document_cookie && 92 !params.printable_area.IsEmpty() && params.document_cookie &&
106 params.desired_dpi && params.max_shrink && params.min_shrink && 93 params.desired_dpi && params.max_shrink && params.min_shrink &&
107 params.dpi && (params.margin_top >= 0) && (params.margin_left >= 0); 94 params.dpi && (params.margin_top >= 0) && (params.margin_left >= 0);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 std::equal(oldParams.pages.begin(), oldParams.pages.end(), 126 std::equal(oldParams.pages.begin(), oldParams.pages.end(),
140 newParams.pages.begin()); 127 newParams.pages.begin());
141 } 128 }
142 129
143 PrintMsg_Print_Params GetCssPrintParams( 130 PrintMsg_Print_Params GetCssPrintParams(
144 WebFrame* frame, 131 WebFrame* frame,
145 int page_index, 132 int page_index,
146 const PrintMsg_Print_Params& page_params) { 133 const PrintMsg_Print_Params& page_params) {
147 PrintMsg_Print_Params page_css_params = page_params; 134 PrintMsg_Print_Params page_css_params = page_params;
148 int dpi = GetDPI(&page_params); 135 int dpi = GetDPI(&page_params);
149 WebSize page_size_in_pixels( 136 WebKit::WebSize page_size_in_pixels(
150 ConvertUnit(page_params.page_size.width(), 137 ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch),
151 dpi, printing::kPixelsPerInch), 138 ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch));
152 ConvertUnit(page_params.page_size.height(), 139 int margin_top_in_pixels =
153 dpi, printing::kPixelsPerInch)); 140 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch);
154 int margin_top_in_pixels = ConvertUnit(
155 page_params.margin_top,
156 dpi, printing::kPixelsPerInch);
157 int margin_right_in_pixels = ConvertUnit( 141 int margin_right_in_pixels = ConvertUnit(
158 page_params.page_size.width() - 142 page_params.page_size.width() -
159 page_params.content_size.width() - page_params.margin_left, 143 page_params.content_size.width() - page_params.margin_left,
160 dpi, printing::kPixelsPerInch); 144 dpi, kPixelsPerInch);
161 int margin_bottom_in_pixels = ConvertUnit( 145 int margin_bottom_in_pixels = ConvertUnit(
162 page_params.page_size.height() - 146 page_params.page_size.height() -
163 page_params.content_size.height() - page_params.margin_top, 147 page_params.content_size.height() - page_params.margin_top,
164 dpi, printing::kPixelsPerInch); 148 dpi, kPixelsPerInch);
165 int margin_left_in_pixels = ConvertUnit( 149 int margin_left_in_pixels = ConvertUnit(
166 page_params.margin_left, 150 page_params.margin_left,
167 dpi, printing::kPixelsPerInch); 151 dpi, kPixelsPerInch);
168 152
169 WebSize original_page_size_in_pixels = page_size_in_pixels; 153 WebKit::WebSize original_page_size_in_pixels = page_size_in_pixels;
170 154
171 if (frame) { 155 if (frame) {
172 frame->pageSizeAndMarginsInPixels(page_index, 156 frame->pageSizeAndMarginsInPixels(page_index,
173 page_size_in_pixels, 157 page_size_in_pixels,
174 margin_top_in_pixels, 158 margin_top_in_pixels,
175 margin_right_in_pixels, 159 margin_right_in_pixels,
176 margin_bottom_in_pixels, 160 margin_bottom_in_pixels,
177 margin_left_in_pixels); 161 margin_left_in_pixels);
178 } 162 }
179 163
180 int new_content_width = page_size_in_pixels.width - 164 int new_content_width = page_size_in_pixels.width -
181 margin_left_in_pixels - margin_right_in_pixels; 165 margin_left_in_pixels - margin_right_in_pixels;
182 int new_content_height = page_size_in_pixels.height - 166 int new_content_height = page_size_in_pixels.height -
183 margin_top_in_pixels - margin_bottom_in_pixels; 167 margin_top_in_pixels - margin_bottom_in_pixels;
184 168
185 // Invalid page size and/or margins. We just use the default setting. 169 // Invalid page size and/or margins. We just use the default setting.
186 if (new_content_width < 1 || new_content_height < 1) { 170 if (new_content_width < 1 || new_content_height < 1) {
187 CHECK(frame != NULL); 171 CHECK(frame != NULL);
188 page_css_params = GetCssPrintParams(NULL, page_index, page_params); 172 page_css_params = GetCssPrintParams(NULL, page_index, page_params);
189 return page_css_params; 173 return page_css_params;
190 } 174 }
191 175
192 page_css_params.content_size = gfx::Size( 176 page_css_params.content_size = gfx::Size(
193 static_cast<int>(ConvertUnit(new_content_width, 177 ConvertUnit(new_content_width, kPixelsPerInch, dpi),
194 printing::kPixelsPerInch, dpi)), 178 ConvertUnit(new_content_height, kPixelsPerInch, dpi));
195 static_cast<int>(ConvertUnit(new_content_height,
196 printing::kPixelsPerInch, dpi)));
197 179
198 if (original_page_size_in_pixels != page_size_in_pixels) { 180 if (original_page_size_in_pixels != page_size_in_pixels) {
199 page_css_params.page_size = gfx::Size( 181 page_css_params.page_size = gfx::Size(
200 static_cast<int>(ConvertUnit(page_size_in_pixels.width, 182 ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi),
201 printing::kPixelsPerInch, dpi)), 183 ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi));
202 static_cast<int>(ConvertUnit(page_size_in_pixels.height,
203 printing::kPixelsPerInch, dpi)));
204 } else { 184 } else {
205 // Printing frame doesn't have any page size css. Pixels to dpi conversion 185 // Printing frame doesn't have any page size css. Pixels to dpi conversion
206 // causes rounding off errors. Therefore use the default page size values 186 // causes rounding off errors. Therefore use the default page size values
207 // directly. 187 // directly.
208 page_css_params.page_size = page_params.page_size; 188 page_css_params.page_size = page_params.page_size;
209 } 189 }
210 190
211 page_css_params.margin_top = 191 page_css_params.margin_top =
212 static_cast<int>(ConvertUnit(margin_top_in_pixels, 192 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi);
213 printing::kPixelsPerInch, dpi));
214
215 page_css_params.margin_left = 193 page_css_params.margin_left =
216 static_cast<int>(ConvertUnit(margin_left_in_pixels, 194 ConvertUnit(margin_left_in_pixels, kPixelsPerInch, dpi);
217 printing::kPixelsPerInch, dpi));
218 return page_css_params; 195 return page_css_params;
219 } 196 }
220 197
221 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, 198 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params,
222 PrintMsg_Print_Params* params_to_fit) { 199 PrintMsg_Print_Params* params_to_fit) {
223 double content_width = 200 double content_width =
224 static_cast<double>(params_to_fit->content_size.width()); 201 static_cast<double>(params_to_fit->content_size.width());
225 double content_height = 202 double content_height =
226 static_cast<double>(params_to_fit->content_size.height()); 203 static_cast<double>(params_to_fit->content_size.height());
227 int default_page_size_height = page_params.page_size.height(); 204 int default_page_size_height = page_params.page_size.height();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 PageSizeMargins* page_layout_in_points) { 237 PageSizeMargins* page_layout_in_points) {
261 int dpi = GetDPI(&params); 238 int dpi = GetDPI(&params);
262 int content_width = params.content_size.width(); 239 int content_width = params.content_size.width();
263 int content_height = params.content_size.height(); 240 int content_height = params.content_size.height();
264 241
265 int margin_bottom = params.page_size.height() - 242 int margin_bottom = params.page_size.height() -
266 content_height - params.margin_top; 243 content_height - params.margin_top;
267 int margin_right = params.page_size.width() - 244 int margin_right = params.page_size.width() -
268 content_width - params.margin_left; 245 content_width - params.margin_left;
269 246
270 page_layout_in_points->content_width = ConvertUnit( 247 page_layout_in_points->content_width =
271 content_width, dpi, printing::kPointsPerInch); 248 ConvertUnit(content_width, dpi, kPointsPerInch);
272 page_layout_in_points->content_height = ConvertUnit( 249 page_layout_in_points->content_height =
273 content_height, dpi, printing::kPointsPerInch); 250 ConvertUnit(content_height, dpi, kPointsPerInch);
274 page_layout_in_points->margin_top = ConvertUnit( 251 page_layout_in_points->margin_top =
275 params.margin_top, dpi, printing::kPointsPerInch); 252 ConvertUnit(params.margin_top, dpi, kPointsPerInch);
276 page_layout_in_points->margin_right = ConvertUnit( 253 page_layout_in_points->margin_right =
277 margin_right, dpi, printing::kPointsPerInch); 254 ConvertUnit(margin_right, dpi, kPointsPerInch);
278 page_layout_in_points->margin_bottom = ConvertUnit( 255 page_layout_in_points->margin_bottom =
279 margin_bottom, dpi, printing::kPointsPerInch); 256 ConvertUnit(margin_bottom, dpi, kPointsPerInch);
280 page_layout_in_points->margin_left = ConvertUnit( 257 page_layout_in_points->margin_left =
281 params.margin_left, dpi, printing::kPointsPerInch); 258 ConvertUnit(params.margin_left, dpi, kPointsPerInch);
282 } 259 }
283 260
284 void EnsureOrientationMatches(const PrintMsg_Print_Params& css_params, 261 void EnsureOrientationMatches(const PrintMsg_Print_Params& css_params,
285 PrintMsg_Print_Params* page_params) { 262 PrintMsg_Print_Params* page_params) {
286 if ((page_params->page_size.width() > page_params->page_size.height()) == 263 if ((page_params->page_size.width() > page_params->page_size.height()) ==
287 (css_params.page_size.width() > css_params.page_size.height())) { 264 (css_params.page_size.width() > css_params.page_size.height())) {
288 return; 265 return;
289 } 266 }
290 267
291 // Swap the |width| and |height| values. 268 // Swap the |width| and |height| values.
292 page_params->page_size.SetSize(page_params->page_size.height(), 269 page_params->page_size.SetSize(page_params->page_size.height(),
293 page_params->page_size.width()); 270 page_params->page_size.width());
294 page_params->content_size.SetSize(page_params->content_size.height(), 271 page_params->content_size.SetSize(page_params->content_size.height(),
295 page_params->content_size.width()); 272 page_params->content_size.width());
296 page_params->printable_area.set_size( 273 page_params->printable_area.set_size(
297 gfx::Size(page_params->printable_area.height(), 274 gfx::Size(page_params->printable_area.height(),
298 page_params->printable_area.width())); 275 page_params->printable_area.width()));
299 } 276 }
300 277
301 void ComputeWebKitPrintParamsInDesiredDpi( 278 void ComputeWebKitPrintParamsInDesiredDpi(
302 const PrintMsg_Print_Params& print_params, 279 const PrintMsg_Print_Params& print_params,
303 WebPrintParams* webkit_print_params) { 280 WebKit::WebPrintParams* webkit_print_params) {
304 int dpi = GetDPI(&print_params); 281 int dpi = GetDPI(&print_params);
305 webkit_print_params->printerDPI = dpi; 282 webkit_print_params->printerDPI = dpi;
306 webkit_print_params->printScalingOption = print_params.print_scaling_option; 283 webkit_print_params->printScalingOption = print_params.print_scaling_option;
307 284
308 webkit_print_params->printContentArea.width = 285 webkit_print_params->printContentArea.width =
309 ConvertUnit(print_params.content_size.width(), dpi, 286 ConvertUnit(print_params.content_size.width(), dpi,
310 print_params.desired_dpi); 287 print_params.desired_dpi);
311 webkit_print_params->printContentArea.height = 288 webkit_print_params->printContentArea.height =
312 ConvertUnit(print_params.content_size.height(), dpi, 289 ConvertUnit(print_params.content_size.height(), dpi,
313 print_params.desired_dpi); 290 print_params.desired_dpi);
(...skipping 17 matching lines...) Expand all
331 webkit_print_params->paperSize.height = 308 webkit_print_params->paperSize.height =
332 ConvertUnit(print_params.page_size.height(), dpi, 309 ConvertUnit(print_params.page_size.height(), dpi,
333 print_params.desired_dpi); 310 print_params.desired_dpi);
334 } 311 }
335 312
336 bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) { 313 bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) {
337 if (!node.isNull()) 314 if (!node.isNull())
338 return true; 315 return true;
339 if (!frame->document().isPluginDocument()) 316 if (!frame->document().isPluginDocument())
340 return false; 317 return false;
341 WebPlugin* plugin = frame->document().to<WebPluginDocument>().plugin(); 318 WebKit::WebPlugin* plugin =
319 frame->document().to<WebKit::WebPluginDocument>().plugin();
342 return plugin && plugin->supportsPaginatedPrint(); 320 return plugin && plugin->supportsPaginatedPrint();
343 } 321 }
344 322
345 bool PrintingFrameHasPageSizeStyle(WebFrame* frame, int total_page_count) { 323 bool PrintingFrameHasPageSizeStyle(WebFrame* frame, int total_page_count) {
346 if (!frame) 324 if (!frame)
347 return false; 325 return false;
348 bool frame_has_custom_page_size_style = false; 326 bool frame_has_custom_page_size_style = false;
349 for (int i = 0; i < total_page_count; ++i) { 327 for (int i = 0; i < total_page_count; ++i) {
350 if (frame->hasCustomPageSizeStyle(i)) { 328 if (frame->hasCustomPageSizeStyle(i)) {
351 frame_has_custom_page_size_style = true; 329 frame_has_custom_page_size_style = true;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 case printing::LEFT: { 364 case printing::LEFT: {
387 x = printing::kSettingHeaderFooterInterstice - page_layout.margin_left; 365 x = printing::kSettingHeaderFooterInterstice - page_layout.margin_left;
388 break; 366 break;
389 } 367 }
390 case printing::RIGHT: { 368 case printing::RIGHT: {
391 x = page_layout.content_width + page_layout.margin_right - 369 x = page_layout.content_width + page_layout.margin_right -
392 printing::kSettingHeaderFooterInterstice - text_width_in_points; 370 printing::kSettingHeaderFooterInterstice - text_width_in_points;
393 break; 371 break;
394 } 372 }
395 case printing::CENTER: { 373 case printing::CENTER: {
396 SkScalar available_width = GetHeaderFooterSegmentWidth( 374 SkScalar available_width = printing::GetHeaderFooterSegmentWidth(
397 page_layout.margin_left + page_layout.margin_right + 375 page_layout.margin_left + page_layout.margin_right +
398 page_layout.content_width); 376 page_layout.content_width);
399 x = available_width - page_layout.margin_left + 377 x = available_width - page_layout.margin_left +
400 (available_width - text_width_in_points) / 2; 378 (available_width - text_width_in_points) / 2;
401 break; 379 break;
402 } 380 }
403 default: { 381 default: {
404 NOTREACHED(); 382 NOTREACHED();
405 } 383 }
406 } 384 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 512
535 } // namespace 513 } // namespace
536 514
537 // static - Not anonymous so that platform implementations can use it. 515 // static - Not anonymous so that platform implementations can use it.
538 void PrintWebViewHelper::PrintHeaderAndFooter( 516 void PrintWebViewHelper::PrintHeaderAndFooter(
539 WebKit::WebCanvas* canvas, 517 WebKit::WebCanvas* canvas,
540 int page_number, 518 int page_number,
541 int total_pages, 519 int total_pages,
542 float webkit_scale_factor, 520 float webkit_scale_factor,
543 const PageSizeMargins& page_layout, 521 const PageSizeMargins& page_layout,
544 const DictionaryValue& header_footer_info) { 522 const DictionaryValue& header_footer_info,
523 const PrintMsg_Print_Params& params) {
545 skia::VectorPlatformDeviceSkia* device = 524 skia::VectorPlatformDeviceSkia* device =
546 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); 525 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice());
547 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); 526 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea);
548 527
549 #if defined(USE_RENDER_TEXT) 528 #if defined(USE_RENDER_TEXT)
550 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); 529 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance());
551 // TODO(asvitkine): The below line is to workaround http://crbug.com/133548. 530 // TODO(asvitkine): The below line is to workaround http://crbug.com/133548.
552 // Remove it when the underlying Skia bug has been fixed. 531 // Remove it when the underlying Skia bug has been fixed.
553 render_text->set_clip_to_display_rect(false); 532 render_text->set_clip_to_display_rect(false);
554 gfx::FontList font_list( 533 gfx::FontList font_list(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 page_layout, printing::CENTER, printing::TOP, 580 page_layout, printing::CENTER, printing::TOP,
602 header_vertical_bounds.top()); 581 header_vertical_bounds.top());
603 } 582 }
604 583
605 // Prints the footers onto the |canvas| if there is enough space to print 584 // Prints the footers onto the |canvas| if there is enough space to print
606 // them. 585 // them.
607 string16 page_of_total_pages = base::IntToString16(page_number) + 586 string16 page_of_total_pages = base::IntToString16(page_number) +
608 UTF8ToUTF16("/") + 587 UTF8ToUTF16("/") +
609 base::IntToString16(total_pages); 588 base::IntToString16(total_pages);
610 string16 url; 589 string16 url;
611 if (!header_footer_info.GetString(printing::kSettingHeaderFooterURL, 590 if (!header_footer_info.GetString(printing::kSettingHeaderFooterURL, &url)) {
612 &url)) {
613 NOTREACHED(); 591 NOTREACHED();
614 } 592 }
615 string16 footer_text = page_of_total_pages + url; 593 string16 footer_text = page_of_total_pages + url;
616 594
617 // Used for height calculations. Note that the width may be undefined. 595 // Used for height calculations. Note that the width may be undefined.
618 SkRect footer_vertical_bounds; 596 SkRect footer_vertical_bounds;
619 #if defined(USE_RENDER_TEXT) 597 #if defined(USE_RENDER_TEXT)
620 paint->SetFontList(font_list); 598 paint->SetFontList(font_list);
621 paint->SetText(footer_text); 599 paint->SetText(footer_text);
622 { 600 {
(...skipping 23 matching lines...) Expand all
646 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( 624 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint(
647 const PrintMsg_Print_Params& print_params, 625 const PrintMsg_Print_Params& print_params,
648 WebFrame* frame, 626 WebFrame* frame,
649 const WebNode& node) 627 const WebNode& node)
650 : frame_(frame), 628 : frame_(frame),
651 node_to_print_(node), 629 node_to_print_(node),
652 web_view_(frame->view()), 630 web_view_(frame->view()),
653 expected_pages_count_(0), 631 expected_pages_count_(0),
654 use_browser_overlays_(true), 632 use_browser_overlays_(true),
655 finished_(false) { 633 finished_(false) {
656 WebPrintParams webkit_print_params; 634 WebKit::WebPrintParams webkit_print_params;
657 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); 635 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params);
658 636
659 if (WebFrame* web_frame = web_view_->mainFrame()) 637 if (WebFrame* web_frame = web_view_->mainFrame())
660 prev_scroll_offset_ = web_frame->scrollOffset(); 638 prev_scroll_offset_ = web_frame->scrollOffset();
661 prev_view_size_ = web_view_->size(); 639 prev_view_size_ = web_view_->size();
662 640
663 StartPrinting(webkit_print_params); 641 StartPrinting(webkit_print_params);
664 } 642 }
665 643
666 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { 644 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() {
667 FinishPrinting(); 645 FinishPrinting();
668 } 646 }
669 647
670 void PrepareFrameAndViewForPrint::UpdatePrintParams( 648 void PrepareFrameAndViewForPrint::UpdatePrintParams(
671 const PrintMsg_Print_Params& print_params) { 649 const PrintMsg_Print_Params& print_params) {
672 DCHECK(!finished_); 650 DCHECK(!finished_);
673 WebPrintParams webkit_print_params; 651 WebKit::WebPrintParams webkit_print_params;
674 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); 652 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params);
675 653
676 if (webkit_print_params.printContentArea == 654 if (webkit_print_params.printContentArea ==
677 web_print_params_.printContentArea && 655 web_print_params_.printContentArea &&
678 webkit_print_params.printableArea == web_print_params_.printableArea && 656 webkit_print_params.printableArea == web_print_params_.printableArea &&
679 webkit_print_params.paperSize == web_print_params_.paperSize && 657 webkit_print_params.paperSize == web_print_params_.paperSize &&
680 webkit_print_params.printScalingOption == 658 webkit_print_params.printScalingOption ==
681 web_print_params_.printScalingOption) { 659 web_print_params_.printScalingOption) {
682 return; 660 return;
683 } 661 }
684 662
685 frame_->printEnd(); 663 frame_->printEnd();
686 StartPrinting(webkit_print_params); 664 StartPrinting(webkit_print_params);
687 } 665 }
688 666
667 gfx::Size PrepareFrameAndViewForPrint::GetPrintCanvasSize() const {
668 return gfx::Size(web_print_params_.printContentArea.width,
669 web_print_params_.printContentArea.height);
670 }
671
689 void PrepareFrameAndViewForPrint::StartPrinting( 672 void PrepareFrameAndViewForPrint::StartPrinting(
690 const WebPrintParams& webkit_print_params) { 673 const WebKit::WebPrintParams& webkit_print_params) {
691 web_print_params_ = webkit_print_params; 674 web_print_params_ = webkit_print_params;
692 675
693 // Layout page according to printer page size. Since WebKit shrinks the 676 // Layout page according to printer page size. Since WebKit shrinks the
694 // size of the page automatically (from 125% to 200%) we trick it to 677 // size of the page automatically (from 125% to 200%) we trick it to
695 // think the page is 125% larger so the size of the page is correct for 678 // think the page is 125% larger so the size of the page is correct for
696 // minimum (default) scaling. 679 // minimum (default) scaling.
697 // This is important for sites that try to fill the page. 680 // This is important for sites that try to fill the page.
698 gfx::Size print_layout_size(web_print_params_.printContentArea.width, 681 gfx::Size print_layout_size(web_print_params_.printContentArea.width,
699 web_print_params_.printContentArea.height); 682 web_print_params_.printContentArea.height);
700 print_layout_size.set_height(static_cast<int>( 683 print_layout_size.set_height(static_cast<int>(
(...skipping 26 matching lines...) Expand all
727 ignore_css_margins_(false), 710 ignore_css_margins_(false),
728 user_cancelled_scripted_print_count_(0), 711 user_cancelled_scripted_print_count_(0),
729 is_scripted_printing_blocked_(false), 712 is_scripted_printing_blocked_(false),
730 notify_browser_of_print_failure_(true), 713 notify_browser_of_print_failure_(true),
731 print_for_preview_(false) { 714 print_for_preview_(false) {
732 } 715 }
733 716
734 PrintWebViewHelper::~PrintWebViewHelper() {} 717 PrintWebViewHelper::~PrintWebViewHelper() {}
735 718
736 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( 719 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(
737 WebKit::WebFrame* frame, bool user_initiated) { 720 WebFrame* frame, bool user_initiated) {
Lei Zhang 2012/11/01 19:21:42 If you don't mind, can we keep this one and the on
Vitaly Buka (NO REVIEWS) 2012/11/01 19:55:56 Then we don't need these usings, most of them inte
738 if (is_scripted_printing_blocked_) 721 if (is_scripted_printing_blocked_)
739 return false; 722 return false;
740 // If preview is enabled, then the print dialog is tab modal, and the user 723 // If preview is enabled, then the print dialog is tab modal, and the user
741 // can always close the tab on a mis-behaving page (the system print dialog 724 // can always close the tab on a mis-behaving page (the system print dialog
742 // is app modal). If the print was initiated through user action, don't 725 // is app modal). If the print was initiated through user action, don't
743 // throttle. Or, if the command line flag to skip throttling has been set. 726 // throttle. Or, if the command line flag to skip throttling has been set.
744 if (!is_scripted_print_throttling_disabled_ && 727 if (!is_scripted_print_throttling_disabled_ &&
745 !is_preview_enabled_ && 728 !is_preview_enabled_ &&
746 !user_initiated) 729 !user_initiated)
747 return !IsScriptInitiatedPrintTooFrequent(frame); 730 return !IsScriptInitiatedPrintTooFrequent(frame);
748 return true; 731 return true;
749 } 732 }
750 733
751 // Prints |frame| which called window.print(). 734 // Prints |frame| which called window.print().
752 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame, 735 void PrintWebViewHelper::PrintPage(WebFrame* frame,
753 bool user_initiated) { 736 bool user_initiated) {
754 DCHECK(frame); 737 DCHECK(frame);
755 738
756 // Allow Prerendering to cancel this print request if necessary. 739 // Allow Prerendering to cancel this print request if necessary.
757 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { 740 if (prerender::PrerenderHelper::IsPrerendering(render_view())) {
758 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); 741 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id()));
759 return; 742 return;
760 } 743 }
761 744
762 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) 745 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated))
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 // If still not finished with earlier print request simply ignore. 780 // If still not finished with earlier print request simply ignore.
798 if (print_web_view_) 781 if (print_web_view_)
799 return; 782 return;
800 783
801 if (!render_view()->GetWebView()) 784 if (!render_view()->GetWebView())
802 return; 785 return;
803 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); 786 WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
804 if (!main_frame) 787 if (!main_frame)
805 return; 788 return;
806 789
807 WebDocument document = main_frame->document(); 790 WebKit::WebDocument document = main_frame->document();
808 // <object> with id="pdf-viewer" is created in 791 // <object> with id="pdf-viewer" is created in
809 // chrome/browser/resources/print_preview/print_preview.js 792 // chrome/browser/resources/print_preview/print_preview.js
810 WebElement pdf_element = document.getElementById("pdf-viewer"); 793 WebKit::WebElement pdf_element = document.getElementById("pdf-viewer");
811 if (pdf_element.isNull()) { 794 if (pdf_element.isNull()) {
812 NOTREACHED(); 795 NOTREACHED();
813 return; 796 return;
814 } 797 }
815 798
816 // Set |print_for_preview_| flag and autoreset it to back to original 799 // Set |print_for_preview_| flag and autoreset it to back to original
817 // on return. 800 // on return.
818 AutoReset<bool> set_printing_flag(&print_for_preview_, true); 801 AutoReset<bool> set_printing_flag(&print_for_preview_, true);
819 802
820 WebFrame* pdf_frame = pdf_element.document().frame(); 803 WebFrame* pdf_frame = pdf_element.document().frame();
(...skipping 15 matching lines...) Expand all
836 PrintMsg_Print_Params& print_params = print_pages_params_->params; 819 PrintMsg_Print_Params& print_params = print_pages_params_->params;
837 print_params.printable_area = gfx::Rect(print_params.page_size); 820 print_params.printable_area = gfx::Rect(print_params.page_size);
838 821
839 // Render Pages for printing. 822 // Render Pages for printing.
840 if (!RenderPagesForPrint(pdf_frame, pdf_element)) { 823 if (!RenderPagesForPrint(pdf_frame, pdf_element)) {
841 LOG(ERROR) << "RenderPagesForPrint failed"; 824 LOG(ERROR) << "RenderPagesForPrint failed";
842 DidFinishPrinting(FAIL_PRINT); 825 DidFinishPrinting(FAIL_PRINT);
843 } 826 }
844 } 827 }
845 828
846 bool PrintWebViewHelper::GetPrintFrame(WebKit::WebFrame** frame) { 829 bool PrintWebViewHelper::GetPrintFrame(WebFrame** frame) {
847 DCHECK(frame); 830 DCHECK(frame);
848 DCHECK(render_view()->GetWebView()); 831 DCHECK(render_view()->GetWebView());
849 if (!render_view()->GetWebView()) 832 if (!render_view()->GetWebView())
850 return false; 833 return false;
851 834
852 // If the user has selected text in the currently focused frame we print 835 // If the user has selected text in the currently focused frame we print
853 // only that frame (this makes print selection work for multiple frames). 836 // only that frame (this makes print selection work for multiple frames).
854 *frame = render_view()->GetWebView()->focusedFrame()->hasSelection() ? 837 *frame = render_view()->GetWebView()->focusedFrame()->hasSelection() ?
855 render_view()->GetWebView()->focusedFrame() : 838 render_view()->GetWebView()->focusedFrame() :
856 render_view()->GetWebView()->mainFrame(); 839 render_view()->GetWebView()->mainFrame();
(...skipping 10 matching lines...) Expand all
867 WebFrame* frame = print_preview_context_.frame(); 850 WebFrame* frame = print_preview_context_.frame();
868 if (!frame) { 851 if (!frame) {
869 NOTREACHED(); 852 NOTREACHED();
870 return; 853 return;
871 } 854 }
872 855
873 Print(frame, print_preview_context_.node()); 856 Print(frame, print_preview_context_.node());
874 } 857 }
875 858
876 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( 859 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout(
877 const printing::PageSizeMargins& page_layout_in_points, 860 const PageSizeMargins& page_layout_in_points,
878 gfx::Size* page_size, 861 gfx::Size* page_size,
879 gfx::Rect* content_area) { 862 gfx::Rect* content_area) {
880 *page_size = gfx::Size( 863 *page_size = gfx::Size(
881 page_layout_in_points.content_width + 864 page_layout_in_points.content_width +
882 page_layout_in_points.margin_right + 865 page_layout_in_points.margin_right +
883 page_layout_in_points.margin_left, 866 page_layout_in_points.margin_left,
884 page_layout_in_points.content_height + 867 page_layout_in_points.content_height +
885 page_layout_in_points.margin_top + 868 page_layout_in_points.margin_top +
886 page_layout_in_points.margin_bottom); 869 page_layout_in_points.margin_bottom);
887 *content_area = gfx::Rect(page_layout_in_points.margin_left, 870 *content_area = gfx::Rect(page_layout_in_points.margin_left,
888 page_layout_in_points.margin_top, 871 page_layout_in_points.margin_top,
889 page_layout_in_points.content_width, 872 page_layout_in_points.content_width,
890 page_layout_in_points.content_height); 873 page_layout_in_points.content_height);
891 } 874 }
892 875
893 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( 876 void PrintWebViewHelper::UpdateFrameMarginsCssInfo(
894 const DictionaryValue& settings) { 877 const DictionaryValue& settings) {
895 int margins_type = 0; 878 int margins_type = 0;
896 if (!settings.GetInteger(printing::kSettingMarginsType, &margins_type)) 879 if (!settings.GetInteger(printing::kSettingMarginsType, &margins_type))
897 margins_type = printing::DEFAULT_MARGINS; 880 margins_type = printing::DEFAULT_MARGINS;
898 ignore_css_margins_ = margins_type != printing::DEFAULT_MARGINS; 881 ignore_css_margins_ = (margins_type != printing::DEFAULT_MARGINS);
899 } 882 }
900 883
901 bool PrintWebViewHelper::IsPrintToPdfRequested( 884 bool PrintWebViewHelper::IsPrintToPdfRequested(
902 const DictionaryValue& job_settings) { 885 const DictionaryValue& job_settings) {
903 bool print_to_pdf = false; 886 bool print_to_pdf = false;
904 if (!job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf)) 887 if (!job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf))
905 NOTREACHED(); 888 NOTREACHED();
906 return print_to_pdf; 889 return print_to_pdf;
907 } 890 }
908 891
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 if (CreatePreviewDocument()) { 972 if (CreatePreviewDocument()) {
990 DidFinishPrinting(OK); 973 DidFinishPrinting(OK);
991 } else { 974 } else {
992 if (notify_browser_of_print_failure_) 975 if (notify_browser_of_print_failure_)
993 LOG(ERROR) << "CreatePreviewDocument failed"; 976 LOG(ERROR) << "CreatePreviewDocument failed";
994 DidFinishPrinting(FAIL_PREVIEW); 977 DidFinishPrinting(FAIL_PREVIEW);
995 } 978 }
996 } 979 }
997 980
998 bool PrintWebViewHelper::CreatePreviewDocument() { 981 bool PrintWebViewHelper::CreatePreviewDocument() {
999 PrintMsg_Print_Params print_params = print_pages_params_->params; 982 const PrintMsg_Print_Params& print_params = print_pages_params_->params;
1000 const std::vector<int>& pages = print_pages_params_->pages; 983 const std::vector<int>& pages = print_pages_params_->pages;
1001 if (!print_preview_context_.CreatePreviewDocument(&print_params, pages, 984 if (!print_preview_context_.CreatePreviewDocument(print_params, pages,
1002 ignore_css_margins_)) { 985 ignore_css_margins_)) {
1003 return false; 986 return false;
1004 } 987 }
1005 988
1006 PageSizeMargins default_page_layout; 989 PageSizeMargins default_page_layout;
1007 ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0, 990 ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0,
1008 print_params, ignore_css_margins_, NULL, 991 print_params, ignore_css_margins_, NULL,
1009 &default_page_layout); 992 &default_page_layout);
1010 993
1011 if (!old_print_pages_params_.get() || 994 if (!old_print_pages_params_.get() ||
1012 !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) { 995 !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) {
1013 bool has_page_size_style = PrintingFrameHasPageSizeStyle( 996 bool has_page_size_style = PrintingFrameHasPageSizeStyle(
1014 print_preview_context_.frame(), 997 print_preview_context_.frame(),
1015 print_preview_context_.total_page_count()); 998 print_preview_context_.total_page_count());
1016 int dpi = GetDPI(&print_params); 999 int dpi = GetDPI(&print_params);
1017 gfx::Rect printable_area_in_points( 1000 gfx::Rect printable_area_in_points(
1018 ConvertUnit(print_pages_params_->params.printable_area.x(), 1001 ConvertUnit(print_params.printable_area.x(), dpi, kPointsPerInch),
1019 dpi, printing::kPointsPerInch), 1002 ConvertUnit(print_params.printable_area.y(), dpi, kPointsPerInch),
1020 ConvertUnit(print_pages_params_->params.printable_area.y(), 1003 ConvertUnit(print_params.printable_area.width(), dpi, kPointsPerInch),
1021 dpi, printing::kPointsPerInch), 1004 ConvertUnit(print_params.printable_area.height(), dpi, kPointsPerInch));
1022 ConvertUnit(print_pages_params_->params.printable_area.width(),
1023 dpi, printing::kPointsPerInch),
1024 ConvertUnit(print_pages_params_->params.printable_area.height(),
1025 dpi, printing::kPointsPerInch));
1026 1005
1027 // Margins: Send default page layout to browser process. 1006 // Margins: Send default page layout to browser process.
1028 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), 1007 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(),
1029 default_page_layout, 1008 default_page_layout,
1030 printable_area_in_points, 1009 printable_area_in_points,
1031 has_page_size_style)); 1010 has_page_size_style));
1032 } 1011 }
1033 1012
1034 PrintHostMsg_DidGetPreviewPageCount_Params params; 1013 PrintHostMsg_DidGetPreviewPageCount_Params params;
1035 params.page_count = print_preview_context_.total_page_count(); 1014 params.page_count = print_preview_context_.total_page_count();
1036 params.is_modifiable = print_preview_context_.IsModifiable(); 1015 params.is_modifiable = print_preview_context_.IsModifiable();
1037 params.document_cookie = print_pages_params_->params.document_cookie; 1016 params.document_cookie = print_params.document_cookie;
1038 params.preview_request_id = print_pages_params_->params.preview_request_id; 1017 params.preview_request_id = print_params.preview_request_id;
1039 params.clear_preview_data = print_preview_context_.generate_draft_pages(); 1018 params.clear_preview_data = print_preview_context_.generate_draft_pages();
1040 Send(new PrintHostMsg_DidGetPreviewPageCount(routing_id(), params)); 1019 Send(new PrintHostMsg_DidGetPreviewPageCount(routing_id(), params));
1041 if (CheckForCancel()) 1020 if (CheckForCancel())
1042 return false; 1021 return false;
1043 1022
1044 while (!print_preview_context_.IsFinalPageRendered()) { 1023 while (!print_preview_context_.IsFinalPageRendered()) {
1045 int page_number = print_preview_context_.GetNextPageNumber(); 1024 int page_number = print_preview_context_.GetNextPageNumber();
1046 DCHECK_GE(page_number, 0); 1025 DCHECK_GE(page_number, 0);
1047 if (!RenderPreviewPage(page_number)) 1026 if (!RenderPreviewPage(page_number, print_params))
1048 return false; 1027 return false;
1049 1028
1050 if (CheckForCancel()) 1029 if (CheckForCancel())
1051 return false; 1030 return false;
1052 1031
1053 // We must call PrepareFrameAndViewForPrint::FinishPrinting() (by way of 1032 // We must call PrepareFrameAndViewForPrint::FinishPrinting() (by way of
1054 // print_preview_context_.AllPagesRendered()) before calling 1033 // print_preview_context_.AllPagesRendered()) before calling
1055 // FinalizePrintReadyDocument() when printing a PDF because the plugin 1034 // FinalizePrintReadyDocument() when printing a PDF because the plugin
1056 // code does not generate output until we call FinishPrinting(). We do not 1035 // code does not generate output until we call FinishPrinting(). We do not
1057 // generate draft pages for PDFs, so IsFinalPageRendered() and 1036 // generate draft pages for PDFs, so IsFinalPageRendered() and
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 // its |context_menu_node_|. 1124 // its |context_menu_node_|.
1146 if (is_preview_enabled_) { 1125 if (is_preview_enabled_) {
1147 print_preview_context_.InitWithNode(node); 1126 print_preview_context_.InitWithNode(node);
1148 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); 1127 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE);
1149 } else { 1128 } else {
1150 WebNode duplicate_node(node); 1129 WebNode duplicate_node(node);
1151 Print(duplicate_node.document().frame(), duplicate_node); 1130 Print(duplicate_node.document().frame(), duplicate_node);
1152 } 1131 }
1153 } 1132 }
1154 1133
1155 void PrintWebViewHelper::Print(WebKit::WebFrame* frame, 1134 void PrintWebViewHelper::Print(WebFrame* frame,
1156 const WebKit::WebNode& node) { 1135 const WebNode& node) {
1157 // If still not finished with earlier print request simply ignore. 1136 // If still not finished with earlier print request simply ignore.
1158 if (print_web_view_) 1137 if (print_web_view_)
1159 return; 1138 return;
1160 1139
1161 // Initialize print settings. 1140 // Initialize print settings.
1162 scoped_ptr<PrepareFrameAndViewForPrint> prepare; 1141 scoped_ptr<PrepareFrameAndViewForPrint> prepare;
1163 if (!InitPrintSettingsAndPrepareFrame(frame, node, &prepare)) { 1142 if (!InitPrintSettingsAndPrepareFrame(frame, node, &prepare)) {
1164 DidFinishPrinting(FAIL_PRINT_INIT); 1143 DidFinishPrinting(FAIL_PRINT_INIT);
1165 return; // Failed to init print page settings. 1144 return; // Failed to init print page settings.
1166 } 1145 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 if (store_print_pages_params) { 1214 if (store_print_pages_params) {
1236 old_print_pages_params_.reset(print_pages_params_.release()); 1215 old_print_pages_params_.reset(print_pages_params_.release());
1237 } else { 1216 } else {
1238 print_pages_params_.reset(); 1217 print_pages_params_.reset();
1239 old_print_pages_params_.reset(); 1218 old_print_pages_params_.reset();
1240 } 1219 }
1241 1220
1242 notify_browser_of_print_failure_ = true; 1221 notify_browser_of_print_failure_ = true;
1243 } 1222 }
1244 1223
1245 bool PrintWebViewHelper::CopyAndPrint(WebKit::WebFrame* web_frame) { 1224 bool PrintWebViewHelper::CopyAndPrint(WebFrame* web_frame) {
1246 // Create a new WebView with the same settings as the current display one. 1225 // Create a new WebView with the same settings as the current display one.
1247 // Except that we disable javascript (don't want any active content running 1226 // Except that we disable javascript (don't want any active content running
1248 // on the page). 1227 // on the page).
1249 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); 1228 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences();
1250 prefs.javascript_enabled = false; 1229 prefs.javascript_enabled = false;
1251 prefs.java_enabled = false; 1230 prefs.java_enabled = false;
1252 1231
1253 print_web_view_ = WebView::create(this); 1232 print_web_view_ = WebKit::WebView::create(this);
1254 prefs.Apply(print_web_view_); 1233 prefs.Apply(print_web_view_);
1255 print_web_view_->initializeMainFrame(this); 1234 print_web_view_->initializeMainFrame(this);
1256 1235
1257 print_pages_params_->pages.clear(); // Print all pages of selection. 1236 print_pages_params_->pages.clear(); // Print all pages of selection.
1258 1237
1259 std::string html = web_frame->selectionAsMarkup().utf8(); 1238 std::string html = web_frame->selectionAsMarkup().utf8();
1260 std::string url_str = "data:text/html;charset=utf-8,"; 1239 std::string url_str = "data:text/html;charset=utf-8,";
1261 url_str.append(html); 1240 url_str.append(html);
1262 GURL url(url_str); 1241 GURL url(url_str);
1263 1242
1264 // When loading is done this will call didStopLoading() and that will do the 1243 // When loading is done this will call didStopLoading() and that will do the
1265 // actual printing. 1244 // actual printing.
1266 print_web_view_->mainFrame()->loadRequest(WebURLRequest(url)); 1245 print_web_view_->mainFrame()->loadRequest(WebKit::WebURLRequest(url));
1267 1246
1268 return true; 1247 return true;
1269 } 1248 }
1270 1249
1271 #if defined(OS_MACOSX) || defined(OS_WIN) 1250 #if defined(OS_MACOSX) || defined(OS_WIN)
1272 bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) { 1251 bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) {
1273 const PrintMsg_PrintPages_Params& params = *print_pages_params_; 1252 const PrintMsg_PrintPages_Params& params = *print_pages_params_;
1274 const PrintMsg_Print_Params& print_params = params.params; 1253 const PrintMsg_Print_Params& print_params = params.params;
1275 PrepareFrameAndViewForPrint prep_frame_view(print_params, frame, node); 1254 PrepareFrameAndViewForPrint prep_frame_view(print_params, frame, node);
1276 UpdateFrameAndViewFromCssPageLayout(frame, node, &prep_frame_view, 1255 UpdateFrameAndViewFromCssPageLayout(frame, node, &prep_frame_view,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 if (fit_to_paper_size) { 1346 if (fit_to_paper_size) {
1368 settings.params.print_scaling_option = 1347 settings.params.print_scaling_option =
1369 WebKit::WebPrintScalingOptionFitToPrintableArea; 1348 WebKit::WebPrintScalingOptionFitToPrintableArea;
1370 } 1349 }
1371 1350
1372 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 1351 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1373 return result; 1352 return result;
1374 } 1353 }
1375 1354
1376 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( 1355 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame(
1377 WebKit::WebFrame* frame, const WebKit::WebNode& node, 1356 WebFrame* frame, const WebNode& node,
1378 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { 1357 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) {
1379 DCHECK(frame); 1358 DCHECK(frame);
1380 1359
1381 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); 1360 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node));
1382 if (!InitPrintSettings(fit_to_paper_size)) { 1361 if (!InitPrintSettings(fit_to_paper_size)) {
1383 notify_browser_of_print_failure_ = false; 1362 notify_browser_of_print_failure_ = false;
1384 render_view()->RunModalAlertDialog( 1363 render_view()->RunModalAlertDialog(
1385 frame, 1364 frame,
1386 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); 1365 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
1387 return false; 1366 return false;
1388 } 1367 }
1389 1368
1390 DCHECK(!prepare->get()); 1369 DCHECK(!prepare->get());
1391 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, 1370 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params,
1392 frame, node)); 1371 frame, node));
1393 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare->get(), 1372 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare->get(),
1394 print_pages_params_->params, 1373 print_pages_params_->params,
1395 ignore_css_margins_); 1374 ignore_css_margins_);
1396 Send(new PrintHostMsg_DidGetDocumentCookie( 1375 Send(new PrintHostMsg_DidGetDocumentCookie(
1397 routing_id(), print_pages_params_->params.document_cookie)); 1376 routing_id(), print_pages_params_->params.document_cookie));
1398 return true; 1377 return true;
1399 } 1378 }
1400 1379
1401 bool PrintWebViewHelper::UpdatePrintSettings( 1380 bool PrintWebViewHelper::UpdatePrintSettings(
1402 WebKit::WebFrame* frame, const WebKit::WebNode& node, 1381 WebFrame* frame, const WebNode& node,
1403 const DictionaryValue& passed_job_settings) { 1382 const DictionaryValue& passed_job_settings) {
1404 DCHECK(is_preview_enabled_); 1383 DCHECK(is_preview_enabled_);
1405 const DictionaryValue* job_settings = &passed_job_settings; 1384 const DictionaryValue* job_settings = &passed_job_settings;
1406 DictionaryValue modified_job_settings; 1385 DictionaryValue modified_job_settings;
1407 if (job_settings->empty()) { 1386 if (job_settings->empty()) {
1408 if (!print_for_preview_) 1387 if (!print_for_preview_)
1409 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); 1388 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING);
1410 return false; 1389 return false;
1411 } 1390 }
1412 1391
(...skipping 23 matching lines...) Expand all
1436 PrintMsg_PrintPages_Params settings; 1415 PrintMsg_PrintPages_Params settings;
1437 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), 1416 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(),
1438 cookie, *job_settings, &settings)); 1417 cookie, *job_settings, &settings));
1439 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 1418 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1440 1419
1441 if (!PrintMsg_Print_Params_IsValid(settings.params)) { 1420 if (!PrintMsg_Print_Params_IsValid(settings.params)) {
1442 if (!print_for_preview_) { 1421 if (!print_for_preview_) {
1443 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); 1422 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
1444 } else { 1423 } else {
1445 // PrintForPrintPreview 1424 // PrintForPrintPreview
1446 WebKit::WebFrame* print_frame = NULL; 1425 WebFrame* print_frame = NULL;
1447 // This may not be the right frame, but the alert will be modal, 1426 // This may not be the right frame, but the alert will be modal,
1448 // therefore it works well enough. 1427 // therefore it works well enough.
1449 GetPrintFrame(&print_frame); 1428 GetPrintFrame(&print_frame);
1450 if (print_frame) { 1429 if (print_frame) {
1451 render_view()->RunModalAlertDialog( 1430 render_view()->RunModalAlertDialog(
1452 print_frame, 1431 print_frame,
1453 l10n_util::GetStringUTF16( 1432 l10n_util::GetStringUTF16(
1454 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); 1433 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
1455 } 1434 }
1456 } 1435 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 settings.params.title); 1470 settings.params.title);
1492 } 1471 }
1493 } 1472 }
1494 1473
1495 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 1474 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1496 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), 1475 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
1497 settings.params.document_cookie)); 1476 settings.params.document_cookie));
1498 return true; 1477 return true;
1499 } 1478 }
1500 1479
1501 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, 1480 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebFrame* frame,
1502 const WebKit::WebNode& node, 1481 const WebNode& node,
1503 int expected_pages_count, 1482 int expected_pages_count,
1504 bool use_browser_overlays) { 1483 bool use_browser_overlays) {
1505 PrintHostMsg_ScriptedPrint_Params params; 1484 PrintHostMsg_ScriptedPrint_Params params;
1506 PrintMsg_PrintPages_Params print_settings; 1485 PrintMsg_PrintPages_Params print_settings;
1507 1486
1508 params.cookie = print_pages_params_->params.document_cookie; 1487 params.cookie = print_pages_params_->params.document_cookie;
1509 params.has_selection = frame->hasSelection(); 1488 params.has_selection = frame->hasSelection();
1510 params.expected_pages_count = expected_pages_count; 1489 params.expected_pages_count = expected_pages_count;
1511 printing::MarginType margin_type = printing::DEFAULT_MARGINS; 1490 printing::MarginType margin_type = printing::DEFAULT_MARGINS;
1512 if (PrintingNodeOrPdfFrame(frame, node)) 1491 if (PrintingNodeOrPdfFrame(frame, node))
(...skipping 12 matching lines...) Expand all
1525 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings); 1504 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings);
1526 msg->EnableMessagePumping(); 1505 msg->EnableMessagePumping();
1527 Send(msg); 1506 Send(msg);
1528 print_pages_params_.reset(new PrintMsg_PrintPages_Params(print_settings)); 1507 print_pages_params_.reset(new PrintMsg_PrintPages_Params(print_settings));
1529 1508
1530 print_pages_params_->params.print_scaling_option = scaling_option; 1509 print_pages_params_->params.print_scaling_option = scaling_option;
1531 return (print_settings.params.dpi && print_settings.params.document_cookie); 1510 return (print_settings.params.dpi && print_settings.params.document_cookie);
1532 } 1511 }
1533 1512
1534 bool PrintWebViewHelper::RenderPagesForPrint( 1513 bool PrintWebViewHelper::RenderPagesForPrint(
1535 WebKit::WebFrame* frame, 1514 WebFrame* frame,
1536 const WebKit::WebNode& node) { 1515 const WebNode& node) {
1537 if (print_pages_params_->params.selection_only) 1516 if (print_pages_params_->params.selection_only)
1538 return CopyAndPrint(frame); 1517 return CopyAndPrint(frame);
1539 return PrintPages(frame, node); 1518 return PrintPages(frame, node);
1540 } 1519 }
1541 1520
1542 #if defined(OS_POSIX) 1521 #if defined(OS_POSIX)
1543 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( 1522 bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
1544 printing::Metafile* metafile, 1523 printing::Metafile* metafile,
1545 base::SharedMemoryHandle* shared_mem_handle) { 1524 base::SharedMemoryHandle* shared_mem_handle) {
1546 uint32 buf_size = metafile->GetDataSize(); 1525 uint32 buf_size = metafile->GetDataSize();
1547 base::SharedMemoryHandle mem_handle = 1526 base::SharedMemoryHandle mem_handle =
1548 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(buf_size); 1527 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(buf_size);
1549 if (base::SharedMemory::IsHandleValid(mem_handle)) { 1528 if (base::SharedMemory::IsHandleValid(mem_handle)) {
1550 base::SharedMemory shared_buf(mem_handle, false); 1529 base::SharedMemory shared_buf(mem_handle, false);
1551 if (shared_buf.Map(buf_size)) { 1530 if (shared_buf.Map(buf_size)) {
1552 metafile->GetData(shared_buf.memory(), buf_size); 1531 metafile->GetData(shared_buf.memory(), buf_size);
1553 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), 1532 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(),
1554 shared_mem_handle); 1533 shared_mem_handle);
1555 return true; 1534 return true;
1556 } 1535 }
1557 } 1536 }
1558 NOTREACHED(); 1537 NOTREACHED();
1559 return false; 1538 return false;
1560 } 1539 }
1561 #endif // defined(OS_POSIX) 1540 #endif // defined(OS_POSIX)
1562 1541
1563 bool PrintWebViewHelper::IsScriptInitiatedPrintTooFrequent( 1542 bool PrintWebViewHelper::IsScriptInitiatedPrintTooFrequent(
1564 WebKit::WebFrame* frame) { 1543 WebFrame* frame) {
1565 const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2; 1544 const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2;
1566 const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 32; 1545 const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 32;
1567 bool too_frequent = false; 1546 bool too_frequent = false;
1568 1547
1569 // Check if there is script repeatedly trying to print and ignore it if too 1548 // Check if there is script repeatedly trying to print and ignore it if too
1570 // frequent. The first 3 times, we use a constant wait time, but if this 1549 // frequent. The first 3 times, we use a constant wait time, but if this
1571 // gets excessive, we switch to exponential wait time. So for a page that 1550 // gets excessive, we switch to exponential wait time. So for a page that
1572 // calls print() in a loop the user will need to cancel the print dialog 1551 // calls print() in a loop the user will need to cancel the print dialog
1573 // after: [2, 2, 2, 4, 8, 16, 32, 32, ...] seconds. 1552 // after: [2, 2, 2, 4, 8, 16, 32, 32, ...] seconds.
1574 // This gives the user time to navigate from the page. 1553 // This gives the user time to navigate from the page.
1575 if (user_cancelled_scripted_print_count_ > 0) { 1554 if (user_cancelled_scripted_print_count_ > 0) {
1576 base::TimeDelta diff = base::Time::Now() - last_cancelled_script_print_; 1555 base::TimeDelta diff = base::Time::Now() - last_cancelled_script_print_;
1577 int min_wait_seconds = kMinSecondsToIgnoreJavascriptInitiatedPrint; 1556 int min_wait_seconds = kMinSecondsToIgnoreJavascriptInitiatedPrint;
1578 if (user_cancelled_scripted_print_count_ > 3) { 1557 if (user_cancelled_scripted_print_count_ > 3) {
1579 min_wait_seconds = std::min( 1558 min_wait_seconds = std::min(
1580 kMinSecondsToIgnoreJavascriptInitiatedPrint << 1559 kMinSecondsToIgnoreJavascriptInitiatedPrint <<
1581 (user_cancelled_scripted_print_count_ - 3), 1560 (user_cancelled_scripted_print_count_ - 3),
1582 kMaxSecondsToIgnoreJavascriptInitiatedPrint); 1561 kMaxSecondsToIgnoreJavascriptInitiatedPrint);
1583 } 1562 }
1584 if (diff.InSeconds() < min_wait_seconds) { 1563 if (diff.InSeconds() < min_wait_seconds) {
1585 too_frequent = true; 1564 too_frequent = true;
1586 } 1565 }
1587 } 1566 }
1588 1567
1589 if (!too_frequent) 1568 if (!too_frequent)
1590 return false; 1569 return false;
1591 1570
1592 WebString message(WebString::fromUTF8( 1571 WebKit::WebString message(
1593 "Ignoring too frequent calls to print().")); 1572 WebKit::WebString::fromUTF8("Ignoring too frequent calls to print()."));
1594 frame->addMessageToConsole(WebConsoleMessage(WebConsoleMessage::LevelWarning, 1573 frame->addMessageToConsole(
1595 message)); 1574 WebKit::WebConsoleMessage(
1575 WebKit::WebConsoleMessage::LevelWarning, message));
1596 return true; 1576 return true;
1597 } 1577 }
1598 1578
1599 void PrintWebViewHelper::ResetScriptedPrintCount() { 1579 void PrintWebViewHelper::ResetScriptedPrintCount() {
1600 // Reset cancel counter on successful print. 1580 // Reset cancel counter on successful print.
1601 user_cancelled_scripted_print_count_ = 0; 1581 user_cancelled_scripted_print_count_ = 0;
1602 } 1582 }
1603 1583
1604 void PrintWebViewHelper::IncrementScriptedPrintCount() { 1584 void PrintWebViewHelper::IncrementScriptedPrintCount() {
1605 ++user_cancelled_scripted_print_count_; 1585 ++user_cancelled_scripted_print_count_;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 generate_draft_pages_(true), 1672 generate_draft_pages_(true),
1693 print_ready_metafile_page_count_(0), 1673 print_ready_metafile_page_count_(0),
1694 error_(PREVIEW_ERROR_NONE), 1674 error_(PREVIEW_ERROR_NONE),
1695 state_(UNINITIALIZED) { 1675 state_(UNINITIALIZED) {
1696 } 1676 }
1697 1677
1698 PrintWebViewHelper::PrintPreviewContext::~PrintPreviewContext() { 1678 PrintWebViewHelper::PrintPreviewContext::~PrintPreviewContext() {
1699 } 1679 }
1700 1680
1701 void PrintWebViewHelper::PrintPreviewContext::InitWithFrame( 1681 void PrintWebViewHelper::PrintPreviewContext::InitWithFrame(
1702 WebKit::WebFrame* web_frame) { 1682 WebFrame* web_frame) {
1703 DCHECK(web_frame); 1683 DCHECK(web_frame);
1704 DCHECK(!IsRendering()); 1684 DCHECK(!IsRendering());
1705 state_ = INITIALIZED; 1685 state_ = INITIALIZED;
1706 frame_ = web_frame; 1686 frame_ = web_frame;
1707 node_.reset(); 1687 node_.reset();
1708 } 1688 }
1709 1689
1710 void PrintWebViewHelper::PrintPreviewContext::InitWithNode( 1690 void PrintWebViewHelper::PrintPreviewContext::InitWithNode(
1711 const WebKit::WebNode& web_node) { 1691 const WebNode& web_node) {
1712 DCHECK(!web_node.isNull()); 1692 DCHECK(!web_node.isNull());
1713 DCHECK(web_node.document().frame()); 1693 DCHECK(web_node.document().frame());
1714 DCHECK(!IsRendering()); 1694 DCHECK(!IsRendering());
1715 state_ = INITIALIZED; 1695 state_ = INITIALIZED;
1716 frame_ = web_node.document().frame(); 1696 frame_ = web_node.document().frame();
1717 node_ = web_node; 1697 node_ = web_node;
1718 } 1698 }
1719 1699
1720 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { 1700 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() {
1721 DCHECK_EQ(INITIALIZED, state_); 1701 DCHECK_EQ(INITIALIZED, state_);
1722 ClearContext(); 1702 ClearContext();
1723 } 1703 }
1724 1704
1725 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( 1705 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument(
1726 PrintMsg_Print_Params* print_params, 1706 const PrintMsg_Print_Params& print_params,
1727 const std::vector<int>& pages, 1707 const std::vector<int>& pages,
1728 bool ignore_css_margins) { 1708 bool ignore_css_margins) {
1729 DCHECK_EQ(INITIALIZED, state_); 1709 DCHECK_EQ(INITIALIZED, state_);
1730 state_ = RENDERING; 1710 state_ = RENDERING;
1731 1711
1732 metafile_.reset(new printing::PreviewMetafile); 1712 metafile_.reset(new printing::PreviewMetafile);
1733 if (!metafile_->Init()) { 1713 if (!metafile_->Init()) {
1734 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); 1714 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED);
1735 LOG(ERROR) << "PreviewMetafile Init failed"; 1715 LOG(ERROR) << "PreviewMetafile Init failed";
1736 return false; 1716 return false;
1737 } 1717 }
1738 1718
1739 // Need to make sure old object gets destroyed first. 1719 // Need to make sure old object gets destroyed first.
1740 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(*print_params, frame(), 1720 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(print_params, frame(),
1741 node())); 1721 node()));
1742 UpdateFrameAndViewFromCssPageLayout(frame_, node_, prep_frame_view_.get(), 1722 UpdateFrameAndViewFromCssPageLayout(frame_, node_, prep_frame_view_.get(),
1743 *print_params, ignore_css_margins); 1723 print_params, ignore_css_margins);
1744
1745 print_params_.reset(new PrintMsg_Print_Params(*print_params));
1746 1724
1747 total_page_count_ = prep_frame_view_->GetExpectedPageCount(); 1725 total_page_count_ = prep_frame_view_->GetExpectedPageCount();
1748 if (total_page_count_ == 0) { 1726 if (total_page_count_ == 0) {
1749 LOG(ERROR) << "CreatePreviewDocument got 0 page count"; 1727 LOG(ERROR) << "CreatePreviewDocument got 0 page count";
1750 set_error(PREVIEW_ERROR_ZERO_PAGES); 1728 set_error(PREVIEW_ERROR_ZERO_PAGES);
1751 return false; 1729 return false;
1752 } 1730 }
1753 1731
1754 int selected_page_count = pages.size(); 1732 int selected_page_count = pages.size();
1755 current_page_index_ = 0; 1733 current_page_index_ = 0;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 bool generate_draft_pages) { 1838 bool generate_draft_pages) {
1861 DCHECK_EQ(INITIALIZED, state_); 1839 DCHECK_EQ(INITIALIZED, state_);
1862 generate_draft_pages_ = generate_draft_pages; 1840 generate_draft_pages_ = generate_draft_pages;
1863 } 1841 }
1864 1842
1865 void PrintWebViewHelper::PrintPreviewContext::set_error( 1843 void PrintWebViewHelper::PrintPreviewContext::set_error(
1866 enum PrintPreviewErrorBuckets error) { 1844 enum PrintPreviewErrorBuckets error) {
1867 error_ = error; 1845 error_ = error;
1868 } 1846 }
1869 1847
1870 WebKit::WebFrame* PrintWebViewHelper::PrintPreviewContext::frame() { 1848 WebFrame* PrintWebViewHelper::PrintPreviewContext::frame() {
1871 // TODO(thestig) turn this back into a DCHECK when http://crbug.com/118303 is 1849 // TODO(thestig) turn this back into a DCHECK when http://crbug.com/118303 is
1872 // resolved. 1850 // resolved.
1873 CHECK(state_ != UNINITIALIZED); 1851 CHECK(state_ != UNINITIALIZED);
1874 return frame_; 1852 return frame_;
1875 } 1853 }
1876 1854
1877 const WebKit::WebNode& PrintWebViewHelper::PrintPreviewContext::node() const { 1855 const WebNode& PrintWebViewHelper::PrintPreviewContext::node() const {
1878 DCHECK(state_ != UNINITIALIZED); 1856 DCHECK(state_ != UNINITIALIZED);
1879 return node_; 1857 return node_;
1880 } 1858 }
1881 1859
1882 int PrintWebViewHelper::PrintPreviewContext::total_page_count() const { 1860 int PrintWebViewHelper::PrintPreviewContext::total_page_count() const {
1883 DCHECK(state_ != UNINITIALIZED); 1861 DCHECK(state_ != UNINITIALIZED);
1884 return total_page_count_; 1862 return total_page_count_;
1885 } 1863 }
1886 1864
1887 bool PrintWebViewHelper::PrintPreviewContext::generate_draft_pages() const { 1865 bool PrintWebViewHelper::PrintPreviewContext::generate_draft_pages() const {
1888 return generate_draft_pages_; 1866 return generate_draft_pages_;
1889 } 1867 }
1890 1868
1891 printing::PreviewMetafile* PrintWebViewHelper::PrintPreviewContext::metafile() { 1869 printing::PreviewMetafile* PrintWebViewHelper::PrintPreviewContext::metafile() {
1892 DCHECK(IsRendering()); 1870 DCHECK(IsRendering());
1893 return metafile_.get(); 1871 return metafile_.get();
1894 } 1872 }
1895 1873
1896 const PrintMsg_Print_Params&
1897 PrintWebViewHelper::PrintPreviewContext::print_params() const {
1898 DCHECK(state_ != UNINITIALIZED);
1899 return *print_params_;
1900 }
1901
1902 int PrintWebViewHelper::PrintPreviewContext::last_error() const { 1874 int PrintWebViewHelper::PrintPreviewContext::last_error() const {
1903 return error_; 1875 return error_;
1904 } 1876 }
1905 1877
1906 gfx::Size PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { 1878 gfx::Size PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const {
1907 DCHECK(IsRendering()); 1879 DCHECK(IsRendering());
1908 return prep_frame_view_->GetPrintCanvasSize(); 1880 return prep_frame_view_->GetPrintCanvasSize();
1909 } 1881 }
1910 1882
1911 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 1883 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
1912 prep_frame_view_.reset(); 1884 prep_frame_view_.reset();
1913 metafile_.reset(); 1885 metafile_.reset();
1914 pages_to_render_.clear(); 1886 pages_to_render_.clear();
1915 error_ = PREVIEW_ERROR_NONE; 1887 error_ = PREVIEW_ERROR_NONE;
1916 } 1888 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | chrome/renderer/print_web_view_helper_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698