Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 oldParams.pages.size() == newParams.pages.size() && | 102 oldParams.pages.size() == newParams.pages.size() && |
| 103 oldParams.params.print_to_pdf == newParams.params.print_to_pdf && | 103 oldParams.params.print_to_pdf == newParams.params.print_to_pdf && |
| 104 oldParams.params.print_scaling_option == | 104 oldParams.params.print_scaling_option == |
| 105 newParams.params.print_scaling_option && | 105 newParams.params.print_scaling_option && |
| 106 oldParams.params.display_header_footer == | 106 oldParams.params.display_header_footer == |
| 107 newParams.params.display_header_footer && | 107 newParams.params.display_header_footer && |
| 108 oldParams.params.date == newParams.params.date && | 108 oldParams.params.date == newParams.params.date && |
| 109 oldParams.params.title == newParams.params.title && | 109 oldParams.params.title == newParams.params.title && |
| 110 oldParams.params.url == newParams.params.url && | 110 oldParams.params.url == newParams.params.url && |
| 111 std::equal(oldParams.pages.begin(), oldParams.pages.end(), | 111 std::equal(oldParams.pages.begin(), oldParams.pages.end(), |
| 112 newParams.pages.begin()); | 112 newParams.pages.begin()) && |
| 113 oldParams.params.should_print_backgrounds == | |
| 114 newParams.params.should_print_backgrounds; | |
| 113 } | 115 } |
| 114 | 116 |
| 115 PrintMsg_Print_Params GetCssPrintParams( | 117 PrintMsg_Print_Params GetCssPrintParams( |
| 116 WebKit::WebFrame* frame, | 118 WebKit::WebFrame* frame, |
| 117 int page_index, | 119 int page_index, |
| 118 const PrintMsg_Print_Params& page_params) { | 120 const PrintMsg_Print_Params& page_params) { |
| 119 PrintMsg_Print_Params page_css_params = page_params; | 121 PrintMsg_Print_Params page_css_params = page_params; |
| 120 int dpi = GetDPI(&page_params); | 122 int dpi = GetDPI(&page_params); |
| 121 | 123 |
| 122 using printing::ConvertUnit; | 124 using printing::ConvertUnit; |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 expected_pages_count_(0), | 489 expected_pages_count_(0), |
| 488 use_browser_overlays_(true), | 490 use_browser_overlays_(true), |
| 489 finished_(false) { | 491 finished_(false) { |
| 490 WebKit::WebPrintParams webkit_print_params; | 492 WebKit::WebPrintParams webkit_print_params; |
| 491 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); | 493 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); |
| 492 | 494 |
| 493 if (WebKit::WebFrame* web_frame = web_view_->mainFrame()) | 495 if (WebKit::WebFrame* web_frame = web_view_->mainFrame()) |
| 494 prev_scroll_offset_ = web_frame->scrollOffset(); | 496 prev_scroll_offset_ = web_frame->scrollOffset(); |
| 495 prev_view_size_ = web_view_->size(); | 497 prev_view_size_ = web_view_->size(); |
| 496 | 498 |
| 499 should_print_backgrounds_ = print_params.should_print_backgrounds; | |
|
Lei Zhang
2013/01/11 00:30:04
You can just put this in the initializer list.
Toscano
2013/01/11 01:41:05
Done.
| |
| 500 | |
| 497 StartPrinting(webkit_print_params); | 501 StartPrinting(webkit_print_params); |
| 498 } | 502 } |
| 499 | 503 |
| 500 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 504 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
| 501 FinishPrinting(); | 505 FinishPrinting(); |
| 502 } | 506 } |
| 503 | 507 |
| 504 void PrepareFrameAndViewForPrint::UpdatePrintParams( | 508 void PrepareFrameAndViewForPrint::UpdatePrintParams( |
| 505 const PrintMsg_Print_Params& print_params) { | 509 const PrintMsg_Print_Params& print_params) { |
| 506 DCHECK(!finished_); | 510 DCHECK(!finished_); |
| 507 WebKit::WebPrintParams webkit_print_params; | 511 WebKit::WebPrintParams webkit_print_params; |
| 508 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); | 512 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); |
| 509 | 513 |
| 514 should_print_backgrounds_ = print_params.should_print_backgrounds; | |
| 515 | |
| 510 if (webkit_print_params.printContentArea == | 516 if (webkit_print_params.printContentArea == |
| 511 web_print_params_.printContentArea && | 517 web_print_params_.printContentArea && |
| 512 webkit_print_params.printableArea == web_print_params_.printableArea && | 518 webkit_print_params.printableArea == web_print_params_.printableArea && |
| 513 webkit_print_params.paperSize == web_print_params_.paperSize && | 519 webkit_print_params.paperSize == web_print_params_.paperSize && |
| 514 webkit_print_params.printScalingOption == | 520 webkit_print_params.printScalingOption == |
| 515 web_print_params_.printScalingOption) { | 521 web_print_params_.printScalingOption) { |
| 516 return; | 522 return; |
| 517 } | 523 } |
| 518 | 524 |
| 519 frame_->printEnd(); | 525 frame_->printEnd(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 537 gfx::Size print_layout_size(web_print_params_.printContentArea.width, | 543 gfx::Size print_layout_size(web_print_params_.printContentArea.width, |
| 538 web_print_params_.printContentArea.height); | 544 web_print_params_.printContentArea.height); |
| 539 print_layout_size.set_height(static_cast<int>( | 545 print_layout_size.set_height(static_cast<int>( |
| 540 static_cast<double>(print_layout_size.height()) * 1.25)); | 546 static_cast<double>(print_layout_size.height()) * 1.25)); |
| 541 | 547 |
| 542 web_view_->resize(print_layout_size); | 548 web_view_->resize(print_layout_size); |
| 543 | 549 |
| 544 expected_pages_count_ = frame_->printBegin(web_print_params_, | 550 expected_pages_count_ = frame_->printBegin(web_print_params_, |
| 545 node_to_print_, | 551 node_to_print_, |
| 546 &use_browser_overlays_); | 552 &use_browser_overlays_); |
| 553 | |
| 554 web_view_->settings()->setShouldPrintBackgrounds(should_print_backgrounds_); | |
| 547 } | 555 } |
| 548 | 556 |
| 549 void PrepareFrameAndViewForPrint::FinishPrinting() { | 557 void PrepareFrameAndViewForPrint::FinishPrinting() { |
| 550 if (!finished_) { | 558 if (!finished_) { |
| 551 finished_ = true; | 559 finished_ = true; |
| 552 frame_->printEnd(); | 560 frame_->printEnd(); |
| 553 web_view_->resize(prev_view_size_); | 561 web_view_->resize(prev_view_size_); |
| 554 if (WebKit::WebFrame* web_frame = web_view_->mainFrame()) | 562 if (WebKit::WebFrame* web_frame = web_view_->mainFrame()) |
| 555 web_frame->setScrollOffset(prev_scroll_offset_); | 563 web_frame->setScrollOffset(prev_scroll_offset_); |
| 564 web_view_->settings()->setShouldPrintBackgrounds(false); | |
| 556 } | 565 } |
| 557 } | 566 } |
| 558 | 567 |
| 559 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) | 568 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) |
| 560 : content::RenderViewObserver(render_view), | 569 : content::RenderViewObserver(render_view), |
| 561 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), | 570 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), |
| 562 print_web_view_(NULL), | 571 print_web_view_(NULL), |
| 563 is_preview_enabled_(IsPrintPreviewEnabled()), | 572 is_preview_enabled_(IsPrintPreviewEnabled()), |
| 564 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()), | 573 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()), |
| 565 is_print_ready_metafile_sent_(false), | 574 is_print_ready_metafile_sent_(false), |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1342 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, | 1351 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, |
| 1343 settings.params.url); | 1352 settings.params.url); |
| 1344 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, | 1353 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, |
| 1345 settings.params.title); | 1354 settings.params.title); |
| 1346 } | 1355 } |
| 1347 } | 1356 } |
| 1348 | 1357 |
| 1349 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1358 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1350 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 1359 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 1351 settings.params.document_cookie)); | 1360 settings.params.document_cookie)); |
| 1361 | |
| 1352 return true; | 1362 return true; |
| 1353 } | 1363 } |
| 1354 | 1364 |
| 1355 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 1365 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
| 1356 const WebKit::WebNode& node, | 1366 const WebKit::WebNode& node, |
| 1357 int expected_pages_count, | 1367 int expected_pages_count, |
| 1358 bool use_browser_overlays) { | 1368 bool use_browser_overlays) { |
| 1359 PrintHostMsg_ScriptedPrint_Params params; | 1369 PrintHostMsg_ScriptedPrint_Params params; |
| 1360 PrintMsg_PrintPages_Params print_settings; | 1370 PrintMsg_PrintPages_Params print_settings; |
| 1361 | 1371 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1755 DCHECK(IsRendering()); | 1765 DCHECK(IsRendering()); |
| 1756 return prep_frame_view_->GetPrintCanvasSize(); | 1766 return prep_frame_view_->GetPrintCanvasSize(); |
| 1757 } | 1767 } |
| 1758 | 1768 |
| 1759 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1769 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1760 prep_frame_view_.reset(); | 1770 prep_frame_view_.reset(); |
| 1761 metafile_.reset(); | 1771 metafile_.reset(); |
| 1762 pages_to_render_.clear(); | 1772 pages_to_render_.clear(); |
| 1763 error_ = PREVIEW_ERROR_NONE; | 1773 error_ = PREVIEW_ERROR_NONE; |
| 1764 } | 1774 } |
| OLD | NEW |