Chromium Code Reviews| 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 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 print_params.desired_dpi)); | 145 print_params.desired_dpi)); |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) { | 148 bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) { |
| 149 if (!node.isNull()) | 149 if (!node.isNull()) |
| 150 return true; | 150 return true; |
| 151 std::string mime(frame->dataSource()->response().mimeType().utf8()); | 151 std::string mime(frame->dataSource()->response().mimeType().utf8()); |
| 152 return mime == "application/pdf"; | 152 return mime == "application/pdf"; |
| 153 } | 153 } |
| 154 | 154 |
| 155 void SetMarginsForPdf(DictionaryValue* job_settings, bool force_no_margins) { | 155 printing::MarginType GetMarginsForPdf(WebFrame* frame, const WebNode& node) { |
| 156 // TODO(vandebo) When it's plumbed through, check if the plugin wants us to | 156 if (frame->isPrintScalingDisabledForPlugin(node)) |
| 157 // scale or not. For now, assume the answer is yes. | 157 return printing::NO_MARGINS; |
| 158 if (force_no_margins) { | 158 else |
| 159 job_settings->SetInteger(printing::kSettingMarginsType, | 159 return printing::PRINTABLE_AREA_MARGINS; |
| 160 printing::NO_MARGINS); | |
| 161 } else { | |
| 162 job_settings->SetInteger(printing::kSettingMarginsType, | |
| 163 printing::PRINTABLE_AREA_MARGINS); | |
| 164 } | |
| 165 | |
| 166 } | 160 } |
| 167 | 161 |
| 168 // Get the (x, y) coordinate from where printing of the current text should | 162 // Get the (x, y) coordinate from where printing of the current text should |
| 169 // start depending on the horizontal alignment (LEFT, RIGHT, CENTER) and | 163 // start depending on the horizontal alignment (LEFT, RIGHT, CENTER) and |
| 170 // vertical alignment (TOP, BOTTOM). | 164 // vertical alignment (TOP, BOTTOM). |
| 171 SkPoint GetHeaderFooterPosition( | 165 SkPoint GetHeaderFooterPosition( |
| 172 float webkit_scale_factor, | 166 float webkit_scale_factor, |
| 173 const PageSizeMargins& page_layout, | 167 const PageSizeMargins& page_layout, |
| 174 printing::HorizontalHeaderFooterPosition horizontal_position, | 168 printing::HorizontalHeaderFooterPosition horizontal_position, |
| 175 printing::VerticalHeaderFooterPosition vertical_position, | 169 printing::VerticalHeaderFooterPosition vertical_position, |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 web_view_->resize(prev_view_size_); | 431 web_view_->resize(prev_view_size_); |
| 438 if (WebFrame* web_frame = web_view_->mainFrame()) | 432 if (WebFrame* web_frame = web_view_->mainFrame()) |
| 439 web_frame->setScrollOffset(prev_scroll_offset_); | 433 web_frame->setScrollOffset(prev_scroll_offset_); |
| 440 } | 434 } |
| 441 } | 435 } |
| 442 | 436 |
| 443 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) | 437 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) |
| 444 : content::RenderViewObserver(render_view), | 438 : content::RenderViewObserver(render_view), |
| 445 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), | 439 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), |
| 446 print_web_view_(NULL), | 440 print_web_view_(NULL), |
| 447 is_preview_(switches::IsPrintPreviewEnabled()), | 441 is_preview_enabled_(switches::IsPrintPreviewEnabled()), |
| 448 is_print_ready_metafile_sent_(false), | 442 is_print_ready_metafile_sent_(false), |
| 449 user_cancelled_scripted_print_count_(0), | 443 user_cancelled_scripted_print_count_(0), |
| 450 notify_browser_of_print_failure_(true) { | 444 notify_browser_of_print_failure_(true) { |
| 451 } | 445 } |
| 452 | 446 |
| 453 PrintWebViewHelper::~PrintWebViewHelper() {} | 447 PrintWebViewHelper::~PrintWebViewHelper() {} |
| 454 | 448 |
| 455 // Prints |frame| which called window.print(). | 449 // Prints |frame| which called window.print(). |
| 456 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame) { | 450 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame) { |
| 457 DCHECK(frame); | 451 DCHECK(frame); |
| 458 | 452 |
| 459 // Allow Prerendering to cancel this print request if necessary. | 453 // Allow Prerendering to cancel this print request if necessary. |
| 460 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { | 454 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { |
| 461 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); | 455 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); |
| 462 return; | 456 return; |
| 463 } | 457 } |
| 464 | 458 |
| 465 if (IsScriptInitiatedPrintTooFrequent(frame)) | 459 if (IsScriptInitiatedPrintTooFrequent(frame)) |
| 466 return; | 460 return; |
| 467 IncrementScriptedPrintCount(); | 461 IncrementScriptedPrintCount(); |
| 468 | 462 |
| 469 if (is_preview_) { | 463 if (is_preview_enabled_) { |
| 470 print_preview_context_.InitWithFrame(frame); | 464 print_preview_context_.InitWithFrame(frame); |
| 471 RequestPrintPreview(); | 465 RequestPrintPreview(); |
| 472 } else { | 466 } else { |
| 473 Print(frame, WebNode()); | 467 Print(frame, WebNode()); |
| 474 } | 468 } |
| 475 } | 469 } |
| 476 | 470 |
| 477 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 471 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
| 478 bool handled = true; | 472 bool handled = true; |
| 479 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 473 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
| 480 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) | 474 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) |
| 481 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) | 475 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) |
| 482 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) | 476 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) |
| 483 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, | 477 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, |
| 484 OnPrintNodeUnderContextMenu) | 478 OnPrintNodeUnderContextMenu) |
| 485 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) | 479 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) |
| 486 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) | 480 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) |
| 487 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) | 481 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) |
| 488 IPC_MESSAGE_HANDLER(PrintMsg_ResetScriptedPrintCount, | 482 IPC_MESSAGE_HANDLER(PrintMsg_ResetScriptedPrintCount, |
| 489 ResetScriptedPrintCount) | 483 ResetScriptedPrintCount) |
| 490 IPC_MESSAGE_HANDLER(PrintMsg_PreviewPrintingRequestCancelled, | 484 IPC_MESSAGE_HANDLER(PrintMsg_PreviewPrintingRequestCancelled, |
| 491 DisplayPrintJobError) | 485 DisplayPrintJobError) |
| 492 IPC_MESSAGE_UNHANDLED(handled = false) | 486 IPC_MESSAGE_UNHANDLED(handled = false) |
| 493 IPC_END_MESSAGE_MAP() | 487 IPC_END_MESSAGE_MAP() |
| 494 return handled; | 488 return handled; |
| 495 } | 489 } |
| 496 | 490 |
| 497 void PrintWebViewHelper::OnPrintForPrintPreview( | 491 void PrintWebViewHelper::OnPrintForPrintPreview( |
| 498 const DictionaryValue& job_settings) { | 492 const DictionaryValue& job_settings) { |
| 499 DCHECK(is_preview_); | 493 DCHECK(is_preview_enabled_); |
| 500 // If still not finished with earlier print request simply ignore. | 494 // If still not finished with earlier print request simply ignore. |
| 501 if (print_web_view_) | 495 if (print_web_view_) |
| 502 return; | 496 return; |
| 503 | 497 |
| 504 if (!render_view()->GetWebView()) | 498 if (!render_view()->GetWebView()) |
| 505 return; | 499 return; |
| 506 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 500 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 507 if (!main_frame) | 501 if (!main_frame) |
| 508 return; | 502 return; |
| 509 | 503 |
| 510 WebDocument document = main_frame->document(); | 504 WebDocument document = main_frame->document(); |
| 511 // <object> with id="pdf-viewer" is created in | 505 // <object> with id="pdf-viewer" is created in |
| 512 // chrome/browser/resources/print_preview/print_preview.js | 506 // chrome/browser/resources/print_preview/print_preview.js |
| 513 WebElement pdf_element = document.getElementById("pdf-viewer"); | 507 WebElement pdf_element = document.getElementById("pdf-viewer"); |
| 514 if (pdf_element.isNull()) { | 508 if (pdf_element.isNull()) { |
| 515 NOTREACHED(); | 509 NOTREACHED(); |
| 516 return; | 510 return; |
| 517 } | 511 } |
| 518 | 512 |
| 519 WebFrame* pdf_frame = pdf_element.document().frame(); | 513 WebFrame* pdf_frame = pdf_element.document().frame(); |
| 520 if (!UpdatePrintSettings(pdf_frame, pdf_element, job_settings, false)) { | 514 if (!UpdatePrintSettings(pdf_frame, pdf_element, job_settings, true)) { |
| 521 LOG(ERROR) << "UpdatePrintSettings failed"; | 515 LOG(ERROR) << "UpdatePrintSettings failed"; |
| 522 DidFinishPrinting(FAIL_PRINT); | 516 DidFinishPrinting(FAIL_PRINT); |
| 523 return; | 517 return; |
| 524 } | 518 } |
| 525 | 519 |
| 526 scoped_ptr<PrepareFrameAndViewForPrint> prepare; | 520 scoped_ptr<PrepareFrameAndViewForPrint> prepare; |
| 527 prepare.reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, | 521 prepare.reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, |
| 528 pdf_frame, pdf_element)); | 522 pdf_frame, pdf_element)); |
| 529 UpdatePrintableSizeInPrintParameters(pdf_frame, pdf_element, prepare.get(), | 523 UpdatePrintableSizeInPrintParameters(pdf_frame, pdf_element, prepare.get(), |
| 530 &print_pages_params_->params); | 524 &print_pages_params_->params); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 560 WebFrame* frame = print_preview_context_.frame(); | 554 WebFrame* frame = print_preview_context_.frame(); |
| 561 if (!frame) { | 555 if (!frame) { |
| 562 NOTREACHED(); | 556 NOTREACHED(); |
| 563 return; | 557 return; |
| 564 } | 558 } |
| 565 | 559 |
| 566 Print(frame, print_preview_context_.node()); | 560 Print(frame, print_preview_context_.node()); |
| 567 } | 561 } |
| 568 | 562 |
| 569 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { | 563 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { |
| 570 DCHECK(is_preview_); | 564 DCHECK(is_preview_enabled_); |
| 571 print_preview_context_.OnPrintPreview(); | 565 print_preview_context_.OnPrintPreview(); |
| 572 | 566 |
| 573 if (!UpdatePrintSettings(print_preview_context_.frame(), | 567 if (!UpdatePrintSettings(print_preview_context_.frame(), |
| 574 print_preview_context_.node(), settings, true)) { | 568 print_preview_context_.node(), settings, false)) { |
| 575 if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) { | 569 if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) { |
| 576 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( | 570 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( |
| 577 routing_id(), print_pages_params_->params.document_cookie)); | 571 routing_id(), print_pages_params_->params.document_cookie)); |
| 578 notify_browser_of_print_failure_ = false; // Already sent. | 572 notify_browser_of_print_failure_ = false; // Already sent. |
| 579 } | 573 } |
| 580 DidFinishPrinting(FAIL_PREVIEW); | 574 DidFinishPrinting(FAIL_PREVIEW); |
| 581 return; | 575 return; |
| 582 } | 576 } |
| 583 | 577 |
| 584 if (!print_pages_params_->params.is_first_request && | 578 if (!print_pages_params_->params.is_first_request && |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 | 703 |
| 710 void PrintWebViewHelper::OnPrintNodeUnderContextMenu() { | 704 void PrintWebViewHelper::OnPrintNodeUnderContextMenu() { |
| 711 const WebNode& context_menu_node = render_view()->GetContextMenuNode(); | 705 const WebNode& context_menu_node = render_view()->GetContextMenuNode(); |
| 712 if (context_menu_node.isNull()) { | 706 if (context_menu_node.isNull()) { |
| 713 NOTREACHED(); | 707 NOTREACHED(); |
| 714 return; | 708 return; |
| 715 } | 709 } |
| 716 | 710 |
| 717 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets | 711 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets |
| 718 // its |context_menu_node_|. | 712 // its |context_menu_node_|. |
| 719 if (is_preview_) { | 713 if (is_preview_enabled_) { |
| 720 print_preview_context_.InitWithNode(context_menu_node); | 714 print_preview_context_.InitWithNode(context_menu_node); |
| 721 RequestPrintPreview(); | 715 RequestPrintPreview(); |
| 722 } else { | 716 } else { |
| 723 WebNode duplicate_node(context_menu_node); | 717 WebNode duplicate_node(context_menu_node); |
| 724 Print(duplicate_node.document().frame(), duplicate_node); | 718 Print(duplicate_node.document().frame(), duplicate_node); |
| 725 } | 719 } |
| 726 } | 720 } |
| 727 | 721 |
| 728 void PrintWebViewHelper::OnInitiatePrintPreview() { | 722 void PrintWebViewHelper::OnInitiatePrintPreview() { |
| 729 DCHECK(is_preview_); | 723 DCHECK(is_preview_enabled_); |
| 730 WebFrame* frame; | 724 WebFrame* frame; |
| 731 if (GetPrintFrame(&frame)) { | 725 if (GetPrintFrame(&frame)) { |
| 732 print_preview_context_.InitWithFrame(frame); | 726 print_preview_context_.InitWithFrame(frame); |
| 733 RequestPrintPreview(); | 727 RequestPrintPreview(); |
| 734 } | 728 } |
| 735 } | 729 } |
| 736 | 730 |
| 737 void PrintWebViewHelper::Print(WebKit::WebFrame* frame, | 731 void PrintWebViewHelper::Print(WebKit::WebFrame* frame, |
| 738 const WebKit::WebNode& node) { | 732 const WebKit::WebNode& node) { |
| 739 // If still not finished with earlier print request simply ignore. | 733 // If still not finished with earlier print request simply ignore. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 758 // show UI and wait for the user. | 752 // show UI and wait for the user. |
| 759 prepare.reset(); | 753 prepare.reset(); |
| 760 | 754 |
| 761 // Some full screen plugins can say they don't want to print. | 755 // Some full screen plugins can say they don't want to print. |
| 762 if (!expected_page_count) { | 756 if (!expected_page_count) { |
| 763 DidFinishPrinting(OK); // Release resources and fail silently. | 757 DidFinishPrinting(OK); // Release resources and fail silently. |
| 764 return; | 758 return; |
| 765 } | 759 } |
| 766 | 760 |
| 767 // Ask the browser to show UI to retrieve the final print settings. | 761 // Ask the browser to show UI to retrieve the final print settings. |
| 768 if (!GetPrintSettingsFromUser(frame, expected_page_count, | 762 if (!GetPrintSettingsFromUser(frame, node, expected_page_count, |
| 769 use_browser_overlays)) { | 763 use_browser_overlays)) { |
| 770 DidFinishPrinting(OK); // Release resources and fail silently. | 764 DidFinishPrinting(OK); // Release resources and fail silently. |
| 771 return; | 765 return; |
| 772 } | 766 } |
| 773 | 767 |
| 774 // Render Pages for printing. | 768 // Render Pages for printing. |
| 775 if (!RenderPagesForPrint(frame, node, NULL)) { | 769 if (!RenderPagesForPrint(frame, node, NULL)) { |
| 776 LOG(ERROR) << "RenderPagesForPrint failed"; | 770 LOG(ERROR) << "RenderPagesForPrint failed"; |
| 777 DidFinishPrinting(FAIL_PRINT); | 771 DidFinishPrinting(FAIL_PRINT); |
| 778 } | 772 } |
| 779 ResetScriptedPrintCount(); | 773 ResetScriptedPrintCount(); |
| 780 } | 774 } |
| 781 | 775 |
| 782 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 776 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
| 783 bool store_print_pages_params = true; | 777 bool store_print_pages_params = true; |
| 784 if (result == FAIL_PRINT) { | 778 if (result == FAIL_PRINT) { |
| 785 DisplayPrintJobError(); | 779 DisplayPrintJobError(); |
| 786 | 780 |
| 787 if (notify_browser_of_print_failure_ && print_pages_params_.get()) { | 781 if (notify_browser_of_print_failure_ && print_pages_params_.get()) { |
| 788 int cookie = print_pages_params_->params.document_cookie; | 782 int cookie = print_pages_params_->params.document_cookie; |
| 789 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); | 783 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); |
| 790 } | 784 } |
| 791 } else if (result == FAIL_PREVIEW) { | 785 } else if (result == FAIL_PREVIEW) { |
| 792 DCHECK(is_preview_); | 786 DCHECK(is_preview_enabled_); |
| 793 store_print_pages_params = false; | 787 store_print_pages_params = false; |
| 794 int cookie = print_pages_params_.get() ? | 788 int cookie = print_pages_params_.get() ? |
| 795 print_pages_params_->params.document_cookie : 0; | 789 print_pages_params_->params.document_cookie : 0; |
| 796 if (notify_browser_of_print_failure_) | 790 if (notify_browser_of_print_failure_) |
| 797 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 791 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
| 798 else | 792 else |
| 799 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 793 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
| 800 print_preview_context_.Failed(notify_browser_of_print_failure_); | 794 print_preview_context_.Failed(notify_browser_of_print_failure_); |
| 801 } | 795 } |
| 802 | 796 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1038 frame, node)); | 1032 frame, node)); |
| 1039 UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(), | 1033 UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(), |
| 1040 &print_pages_params_->params); | 1034 &print_pages_params_->params); |
| 1041 Send(new PrintHostMsg_DidGetDocumentCookie( | 1035 Send(new PrintHostMsg_DidGetDocumentCookie( |
| 1042 routing_id(), print_pages_params_->params.document_cookie)); | 1036 routing_id(), print_pages_params_->params.document_cookie)); |
| 1043 return true; | 1037 return true; |
| 1044 } | 1038 } |
| 1045 | 1039 |
| 1046 bool PrintWebViewHelper::UpdatePrintSettings( | 1040 bool PrintWebViewHelper::UpdatePrintSettings( |
| 1047 WebKit::WebFrame* frame, const WebKit::WebNode& node, | 1041 WebKit::WebFrame* frame, const WebKit::WebNode& node, |
| 1048 const DictionaryValue& passed_job_settings, bool generating_preview) { | 1042 const DictionaryValue& passed_job_settings, bool print_for_preview) { |
| 1049 DCHECK(is_preview_); | 1043 DCHECK(is_preview_enabled_); |
| 1050 const DictionaryValue* job_settings = &passed_job_settings; | 1044 const DictionaryValue* job_settings = &passed_job_settings; |
| 1051 DictionaryValue modified_job_settings; | 1045 DictionaryValue modified_job_settings; |
| 1052 if (job_settings->empty()) { | 1046 if (job_settings->empty()) { |
| 1053 if (generating_preview) | 1047 if (!print_for_preview) |
| 1054 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); | 1048 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); |
| 1055 return false; | 1049 return false; |
| 1056 } | 1050 } |
| 1057 | 1051 |
| 1058 bool is_pdf = PrintingNodeOrPdfFrame(frame, node); | 1052 bool source_is_html; |
|
Lei Zhang
2011/10/17 05:27:02
I'd initialize this to true in the unlikely event
vandebo (ex-Chrome)
2011/10/17 17:03:33
Done.
| |
| 1059 if (is_pdf || !generating_preview) { | 1053 if (print_for_preview) { |
| 1054 if (!job_settings->GetBoolean(printing::kSettingPreviewModifiable, | |
| 1055 &source_is_html)) { | |
| 1056 NOTREACHED(); | |
| 1057 } | |
| 1058 } else { | |
| 1059 source_is_html = !PrintingNodeOrPdfFrame(frame, node); | |
| 1060 } | |
| 1061 | |
| 1062 // When the source is a PDF: | |
|
Lei Zhang
2011/10/17 05:27:02
you can move this comment + #if block inside the i
vandebo (ex-Chrome)
2011/10/17 17:03:33
Done.
| |
| 1063 // - On Windows, we don't add a margin until we turn it into an EMF when | |
| 1064 // printing for print preview (We could add it in the plugin). | |
| 1065 // - On Mac with Skia, we don't add a margin until we send it to the printer | |
| 1066 // using the CG PDF class (We could add it in the plugin). | |
| 1067 // - On Mac with CG, we can add a margin when generating the preview. | |
| 1068 // - On Linux, we never add a margin (We Could add it in the plugin). | |
| 1069 | |
| 1070 #if defined(OS_MACOSX) && !defined(USE_SKIA) | |
| 1071 bool get_margins_from_pdf = !source_is_html && !print_for_preview; | |
| 1072 #elif defined (OS_WIN) || defined(OS_MACOSX) | |
| 1073 bool get_margins_from_pdf = !source_is_html && print_for_preview; | |
| 1074 #else | |
| 1075 bool get_margins_from_pdf = false; | |
| 1076 #endif | |
| 1077 | |
| 1078 if (print_for_preview || !source_is_html) { | |
| 1060 modified_job_settings.MergeDictionary(job_settings); | 1079 modified_job_settings.MergeDictionary(job_settings); |
| 1061 SetMarginsForPdf(&modified_job_settings, !generating_preview); | 1080 modified_job_settings.SetBoolean(printing::kSettingHeaderFooterEnabled, |
| 1062 if (is_pdf) { | 1081 false); |
| 1063 modified_job_settings.SetBoolean(printing::kSettingHeaderFooterEnabled, | 1082 |
| 1064 false); | 1083 printing::MarginType margin_type = printing::NO_MARGINS; |
| 1065 } | 1084 if (get_margins_from_pdf) |
| 1085 margin_type = GetMarginsForPdf(frame, node); | |
| 1086 modified_job_settings.SetInteger(printing::kSettingMarginsType, | |
| 1087 margin_type); | |
| 1066 job_settings = &modified_job_settings; | 1088 job_settings = &modified_job_settings; |
| 1067 } | 1089 } |
| 1068 | 1090 |
| 1069 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when | 1091 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when |
| 1070 // possible. | 1092 // possible. |
| 1071 int cookie = print_pages_params_.get() ? | 1093 int cookie = print_pages_params_.get() ? |
| 1072 print_pages_params_->params.document_cookie : 0; | 1094 print_pages_params_->params.document_cookie : 0; |
| 1073 PrintMsg_PrintPages_Params settings; | 1095 PrintMsg_PrintPages_Params settings; |
| 1074 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), | 1096 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), |
| 1075 cookie, *job_settings, &settings)); | 1097 cookie, *job_settings, &settings)); |
| 1076 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1098 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1077 | 1099 |
| 1078 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { | 1100 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { |
| 1079 if (generating_preview) { | 1101 if (!print_for_preview) { |
| 1080 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); | 1102 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); |
| 1081 } else { | 1103 } else { |
| 1082 WebKit::WebFrame* frame = print_preview_context_.frame(); | 1104 WebKit::WebFrame* frame = print_preview_context_.frame(); |
| 1083 if (!frame) { | 1105 if (!frame) { |
| 1084 GetPrintFrame(&frame); | 1106 GetPrintFrame(&frame); |
| 1085 } | 1107 } |
| 1086 if (frame) { | 1108 if (frame) { |
| 1087 render_view()->RunModalAlertDialog( | 1109 render_view()->RunModalAlertDialog( |
| 1088 frame, | 1110 frame, |
| 1089 l10n_util::GetStringUTF16( | 1111 l10n_util::GetStringUTF16( |
| 1090 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1112 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
| 1091 } | 1113 } |
| 1092 } | 1114 } |
| 1093 return false; | 1115 return false; |
| 1094 } | 1116 } |
| 1095 | 1117 |
| 1096 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) { | 1118 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) { |
| 1097 print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS); | 1119 print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS); |
| 1098 return false; | 1120 return false; |
| 1099 } | 1121 } |
| 1100 | 1122 |
| 1101 if (generating_preview) { | 1123 if (!print_for_preview) { |
| 1102 // Validate expected print preview settings. | 1124 // Validate expected print preview settings. |
| 1103 if (!job_settings->GetString(printing::kPreviewUIAddr, | 1125 if (!job_settings->GetString(printing::kPreviewUIAddr, |
| 1104 &(settings.params.preview_ui_addr)) || | 1126 &(settings.params.preview_ui_addr)) || |
| 1105 !job_settings->GetInteger(printing::kPreviewRequestID, | 1127 !job_settings->GetInteger(printing::kPreviewRequestID, |
| 1106 &(settings.params.preview_request_id)) || | 1128 &(settings.params.preview_request_id)) || |
| 1107 !job_settings->GetBoolean(printing::kIsFirstRequest, | 1129 !job_settings->GetBoolean(printing::kIsFirstRequest, |
| 1108 &(settings.params.is_first_request))) { | 1130 &(settings.params.is_first_request))) { |
| 1109 NOTREACHED(); | 1131 NOTREACHED(); |
| 1110 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); | 1132 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); |
| 1111 return false; | 1133 return false; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1133 } | 1155 } |
| 1134 } | 1156 } |
| 1135 | 1157 |
| 1136 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1158 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1137 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 1159 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 1138 settings.params.document_cookie)); | 1160 settings.params.document_cookie)); |
| 1139 return true; | 1161 return true; |
| 1140 } | 1162 } |
| 1141 | 1163 |
| 1142 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 1164 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
| 1165 const WebKit::WebNode& node, | |
| 1143 int expected_pages_count, | 1166 int expected_pages_count, |
| 1144 bool use_browser_overlays) { | 1167 bool use_browser_overlays) { |
| 1145 PrintHostMsg_ScriptedPrint_Params params; | 1168 PrintHostMsg_ScriptedPrint_Params params; |
| 1146 PrintMsg_PrintPages_Params print_settings; | 1169 PrintMsg_PrintPages_Params print_settings; |
| 1147 | 1170 |
| 1148 // The routing id is sent across as it is needed to look up the | 1171 // The routing id is sent across as it is needed to look up the |
| 1149 // corresponding RenderViewHost instance to signal and reset the | 1172 // corresponding RenderViewHost instance to signal and reset the |
| 1150 // pump messages event. | 1173 // pump messages event. |
| 1151 params.routing_id = render_view()->GetRoutingId(); | 1174 params.routing_id = render_view()->GetRoutingId(); |
| 1152 // host_window_ may be NULL at this point if the current window is a | 1175 // host_window_ may be NULL at this point if the current window is a |
| 1153 // popup and the print() command has been issued from the parent. The | 1176 // popup and the print() command has been issued from the parent. The |
| 1154 // receiver of this message has to deal with this. | 1177 // receiver of this message has to deal with this. |
| 1155 params.host_window_id = render_view()->GetHostWindow(); | 1178 params.host_window_id = render_view()->GetHostWindow(); |
| 1156 params.cookie = print_pages_params_->params.document_cookie; | 1179 params.cookie = print_pages_params_->params.document_cookie; |
| 1157 params.has_selection = frame->hasSelection(); | 1180 params.has_selection = frame->hasSelection(); |
| 1158 params.expected_pages_count = expected_pages_count; | 1181 params.expected_pages_count = expected_pages_count; |
| 1159 params.margin_type = printing::DEFAULT_MARGINS; | 1182 printing::MarginType margin_type = printing::DEFAULT_MARGINS; |
| 1183 if (PrintingNodeOrPdfFrame(frame, node)) | |
| 1184 margin_type = GetMarginsForPdf(frame, node); | |
| 1185 params.margin_type = margin_type; | |
| 1160 | 1186 |
| 1161 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); | 1187 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); |
| 1162 | 1188 |
| 1163 print_pages_params_.reset(); | 1189 print_pages_params_.reset(); |
| 1164 IPC::SyncMessage* msg = | 1190 IPC::SyncMessage* msg = |
| 1165 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings); | 1191 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings); |
| 1166 msg->EnableMessagePumping(); | 1192 msg->EnableMessagePumping(); |
| 1167 Send(msg); | 1193 Send(msg); |
| 1168 print_pages_params_.reset(new PrintMsg_PrintPages_Params(print_settings)); | 1194 print_pages_params_.reset(new PrintMsg_PrintPages_Params(print_settings)); |
| 1169 return (print_settings.params.dpi && print_settings.params.document_cookie); | 1195 return (print_settings.params.dpi && print_settings.params.document_cookie); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1324 error_(PREVIEW_ERROR_NONE), | 1350 error_(PREVIEW_ERROR_NONE), |
| 1325 state_(UNINITIALIZED) { | 1351 state_(UNINITIALIZED) { |
| 1326 } | 1352 } |
| 1327 | 1353 |
| 1328 PrintWebViewHelper::PrintPreviewContext::~PrintPreviewContext() { | 1354 PrintWebViewHelper::PrintPreviewContext::~PrintPreviewContext() { |
| 1329 } | 1355 } |
| 1330 | 1356 |
| 1331 void PrintWebViewHelper::PrintPreviewContext::InitWithFrame( | 1357 void PrintWebViewHelper::PrintPreviewContext::InitWithFrame( |
| 1332 WebKit::WebFrame* web_frame) { | 1358 WebKit::WebFrame* web_frame) { |
| 1333 DCHECK(web_frame); | 1359 DCHECK(web_frame); |
| 1360 DCHECK(state_ == UNINITIALIZED || state_ == INITIALIZED); | |
|
Lei Zhang
2011/10/17 05:27:02
Isn't this the same as !IsRendering() ?
vandebo (ex-Chrome)
2011/10/17 17:03:33
Done.
| |
| 1334 state_ = INITIALIZED; | 1361 state_ = INITIALIZED; |
| 1335 frame_ = web_frame; | 1362 frame_ = web_frame; |
| 1336 node_.reset(); | 1363 node_.reset(); |
| 1337 } | 1364 } |
| 1338 | 1365 |
| 1339 void PrintWebViewHelper::PrintPreviewContext::InitWithNode( | 1366 void PrintWebViewHelper::PrintPreviewContext::InitWithNode( |
| 1340 const WebKit::WebNode& web_node) { | 1367 const WebKit::WebNode& web_node) { |
| 1341 DCHECK(!web_node.isNull()); | 1368 DCHECK(!web_node.isNull()); |
| 1369 DCHECK(state_ == UNINITIALIZED || state_ == INITIALIZED); | |
| 1342 state_ = INITIALIZED; | 1370 state_ = INITIALIZED; |
| 1343 frame_ = web_node.document().frame(); | 1371 frame_ = web_node.document().frame(); |
| 1344 node_ = web_node; | 1372 node_ = web_node; |
| 1345 } | 1373 } |
| 1346 | 1374 |
| 1347 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { | 1375 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { |
| 1348 DCHECK(IsReadyToRender()); | 1376 DCHECK_EQ(INITIALIZED, state_); |
| 1349 ClearContext(); | 1377 ClearContext(); |
| 1350 } | 1378 } |
| 1351 | 1379 |
| 1352 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( | 1380 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( |
| 1353 PrintMsg_Print_Params* print_params, | 1381 PrintMsg_Print_Params* print_params, |
| 1354 const std::vector<int>& pages) { | 1382 const std::vector<int>& pages) { |
| 1355 DCHECK(IsReadyToRender()); | 1383 DCHECK_EQ(INITIALIZED, state_); |
| 1356 state_ = RENDERING; | 1384 state_ = RENDERING; |
| 1357 | 1385 |
| 1358 print_params_.reset(new PrintMsg_Print_Params(*print_params)); | 1386 print_params_.reset(new PrintMsg_Print_Params(*print_params)); |
| 1359 | 1387 |
| 1360 metafile_.reset(new printing::PreviewMetafile); | 1388 metafile_.reset(new printing::PreviewMetafile); |
| 1361 if (!metafile_->Init()) { | 1389 if (!metafile_->Init()) { |
| 1362 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); | 1390 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); |
| 1363 LOG(ERROR) << "PreviewMetafile Init failed"; | 1391 LOG(ERROR) << "PreviewMetafile Init failed"; |
| 1364 return false; | 1392 return false; |
| 1365 } | 1393 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1411 UMA_HISTOGRAM_TIMES("PrintPreview.RenderPDFPageTime", page_time); | 1439 UMA_HISTOGRAM_TIMES("PrintPreview.RenderPDFPageTime", page_time); |
| 1412 } | 1440 } |
| 1413 | 1441 |
| 1414 void PrintWebViewHelper::PrintPreviewContext::AllPagesRendered() { | 1442 void PrintWebViewHelper::PrintPreviewContext::AllPagesRendered() { |
| 1415 DCHECK_EQ(RENDERING, state_); | 1443 DCHECK_EQ(RENDERING, state_); |
| 1416 state_ = DONE; | 1444 state_ = DONE; |
| 1417 prep_frame_view_->FinishPrinting(); | 1445 prep_frame_view_->FinishPrinting(); |
| 1418 } | 1446 } |
| 1419 | 1447 |
| 1420 void PrintWebViewHelper::PrintPreviewContext::FinalizePrintReadyDocument() { | 1448 void PrintWebViewHelper::PrintPreviewContext::FinalizePrintReadyDocument() { |
| 1421 if (state_ != DONE && state_ != RENDERING) | 1449 DCHECK(state_ == RENDERING || state_ == DONE); |
|
Lei Zhang
2011/10/17 05:27:02
isn't this the same as IsRendering() ?
vandebo (ex-Chrome)
2011/10/17 17:03:33
Done.
| |
| 1422 NOTREACHED(); | |
| 1423 | 1450 |
| 1424 base::TimeTicks begin_time = base::TimeTicks::Now(); | 1451 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 1425 metafile_->FinishDocument(); | 1452 metafile_->FinishDocument(); |
| 1426 | 1453 |
| 1427 if (print_ready_metafile_page_count_ <= 0) { | 1454 if (print_ready_metafile_page_count_ <= 0) { |
| 1428 NOTREACHED(); | 1455 NOTREACHED(); |
| 1429 return; | 1456 return; |
| 1430 } | 1457 } |
| 1431 | 1458 |
| 1432 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderToPDFTime", | 1459 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderToPDFTime", |
| 1433 document_render_time_); | 1460 document_render_time_); |
| 1434 base::TimeDelta total_time = (base::TimeTicks::Now() - begin_time) + | 1461 base::TimeDelta total_time = (base::TimeTicks::Now() - begin_time) + |
| 1435 document_render_time_; | 1462 document_render_time_; |
| 1436 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderAndGeneratePDFTime", | 1463 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderAndGeneratePDFTime", |
| 1437 total_time); | 1464 total_time); |
| 1438 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderAndGeneratePDFTimeAvgPerPage", | 1465 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderAndGeneratePDFTimeAvgPerPage", |
| 1439 total_time / pages_to_render_.size()); | 1466 total_time / pages_to_render_.size()); |
| 1440 } | 1467 } |
| 1441 | 1468 |
| 1442 void PrintWebViewHelper::PrintPreviewContext::Finished() { | 1469 void PrintWebViewHelper::PrintPreviewContext::Finished() { |
| 1443 DCHECK_EQ(DONE, state_); | 1470 DCHECK_EQ(DONE, state_); |
| 1471 state_ = INITIALIZED; | |
| 1444 ClearContext(); | 1472 ClearContext(); |
| 1445 } | 1473 } |
| 1446 | 1474 |
| 1447 void PrintWebViewHelper::PrintPreviewContext::Failed(bool report_error) { | 1475 void PrintWebViewHelper::PrintPreviewContext::Failed(bool report_error) { |
| 1448 DCHECK(state_ == INITIALIZED || state_ == RENDERING); | 1476 DCHECK(state_ == INITIALIZED || state_ == RENDERING); |
| 1449 state_ = INITIALIZED; | 1477 state_ = INITIALIZED; |
| 1450 if (report_error) { | 1478 if (report_error) { |
| 1451 DCHECK_NE(PREVIEW_ERROR_NONE, error_); | 1479 DCHECK_NE(PREVIEW_ERROR_NONE, error_); |
| 1452 UMA_HISTOGRAM_ENUMERATION("PrintPreview.RendererError", error_, | 1480 UMA_HISTOGRAM_ENUMERATION("PrintPreview.RendererError", error_, |
| 1453 PREVIEW_ERROR_LAST_ENUM); | 1481 PREVIEW_ERROR_LAST_ENUM); |
| 1454 } | 1482 } |
| 1455 ClearContext(); | 1483 ClearContext(); |
| 1456 } | 1484 } |
| 1457 | 1485 |
| 1458 int PrintWebViewHelper::PrintPreviewContext::GetNextPageNumber() { | 1486 int PrintWebViewHelper::PrintPreviewContext::GetNextPageNumber() { |
| 1459 DCHECK_EQ(RENDERING, state_); | 1487 DCHECK_EQ(RENDERING, state_); |
| 1460 if (IsFinalPageRendered()) | 1488 if (IsFinalPageRendered()) |
| 1461 return -1; | 1489 return -1; |
| 1462 return pages_to_render_[current_page_index_++]; | 1490 return pages_to_render_[current_page_index_++]; |
| 1463 } | 1491 } |
| 1464 | 1492 |
| 1465 bool PrintWebViewHelper::PrintPreviewContext::IsReadyToRender() const { | 1493 bool PrintWebViewHelper::PrintPreviewContext::IsRendering() const { |
| 1466 return state_ != UNINITIALIZED; | 1494 return state_ == RENDERING || state_ == DONE; |
| 1467 } | 1495 } |
| 1468 | 1496 |
| 1469 bool PrintWebViewHelper::PrintPreviewContext::IsModifiable() const { | 1497 bool PrintWebViewHelper::PrintPreviewContext::IsModifiable() const { |
| 1470 // The only kind of node we can print right now is a PDF node. | 1498 // The only kind of node we can print right now is a PDF node. |
| 1471 return !PrintingNodeOrPdfFrame(frame(), node()); | 1499 return !PrintingNodeOrPdfFrame(frame(), node()); |
| 1472 } | 1500 } |
| 1473 | 1501 |
| 1474 bool PrintWebViewHelper::PrintPreviewContext::IsLastPageOfPrintReadyMetafile() | 1502 bool PrintWebViewHelper::PrintPreviewContext::IsLastPageOfPrintReadyMetafile() |
| 1475 const { | 1503 const { |
| 1504 DCHECK(IsRendering()); | |
| 1476 return current_page_index_ == print_ready_metafile_page_count_; | 1505 return current_page_index_ == print_ready_metafile_page_count_; |
| 1477 } | 1506 } |
| 1478 | 1507 |
| 1479 bool PrintWebViewHelper::PrintPreviewContext::IsFinalPageRendered() const { | 1508 bool PrintWebViewHelper::PrintPreviewContext::IsFinalPageRendered() const { |
| 1509 DCHECK(IsRendering()); | |
| 1480 return static_cast<size_t>(current_page_index_) == pages_to_render_.size(); | 1510 return static_cast<size_t>(current_page_index_) == pages_to_render_.size(); |
| 1481 } | 1511 } |
| 1482 | 1512 |
| 1483 void PrintWebViewHelper::PrintPreviewContext::set_generate_draft_pages( | 1513 void PrintWebViewHelper::PrintPreviewContext::set_generate_draft_pages( |
| 1484 bool generate_draft_pages) { | 1514 bool generate_draft_pages) { |
| 1515 DCHECK_EQ(INITIALIZED, state_); | |
| 1485 generate_draft_pages_ = generate_draft_pages; | 1516 generate_draft_pages_ = generate_draft_pages; |
| 1486 } | 1517 } |
| 1487 | 1518 |
| 1488 void PrintWebViewHelper::PrintPreviewContext::set_error( | 1519 void PrintWebViewHelper::PrintPreviewContext::set_error( |
| 1489 enum PrintPreviewErrorBuckets error) { | 1520 enum PrintPreviewErrorBuckets error) { |
| 1490 error_ = error; | 1521 error_ = error; |
| 1491 } | 1522 } |
| 1492 | 1523 |
| 1493 WebKit::WebFrame* PrintWebViewHelper::PrintPreviewContext::frame() const { | 1524 WebKit::WebFrame* PrintWebViewHelper::PrintPreviewContext::frame() const { |
|
Lei Zhang
2011/10/17 05:27:02
Add the same DCHECK as node() ?
vandebo (ex-Chrome)
2011/10/17 17:03:33
Currently, this triggers a DCHECK in one of the te
| |
| 1494 return frame_; | 1525 return frame_; |
| 1495 } | 1526 } |
| 1496 | 1527 |
| 1497 const WebKit::WebNode& PrintWebViewHelper::PrintPreviewContext::node() const { | 1528 const WebKit::WebNode& PrintWebViewHelper::PrintPreviewContext::node() const { |
| 1529 DCHECK(state_ != UNINITIALIZED); | |
| 1498 return node_; | 1530 return node_; |
| 1499 } | 1531 } |
| 1500 | 1532 |
| 1501 int PrintWebViewHelper::PrintPreviewContext::total_page_count() const { | 1533 int PrintWebViewHelper::PrintPreviewContext::total_page_count() const { |
| 1502 DCHECK(IsReadyToRender()); | 1534 DCHECK(IsRendering()); |
| 1503 return total_page_count_; | 1535 return total_page_count_; |
| 1504 } | 1536 } |
| 1505 | 1537 |
| 1506 bool PrintWebViewHelper::PrintPreviewContext::generate_draft_pages() { | 1538 bool PrintWebViewHelper::PrintPreviewContext::generate_draft_pages() { |
| 1507 return generate_draft_pages_; | 1539 return generate_draft_pages_; |
| 1508 } | 1540 } |
| 1509 | 1541 |
| 1510 printing::PreviewMetafile* | 1542 printing::PreviewMetafile* |
| 1511 PrintWebViewHelper::PrintPreviewContext::metafile() const { | 1543 PrintWebViewHelper::PrintPreviewContext::metafile() const { |
| 1544 DCHECK(IsRendering()); | |
| 1512 return metafile_.get(); | 1545 return metafile_.get(); |
| 1513 } | 1546 } |
| 1514 | 1547 |
| 1515 const PrintMsg_Print_Params& | 1548 const PrintMsg_Print_Params& |
| 1516 PrintWebViewHelper::PrintPreviewContext::print_params() const { | 1549 PrintWebViewHelper::PrintPreviewContext::print_params() const { |
| 1550 DCHECK(state_ != UNINITIALIZED); | |
| 1517 return *print_params_; | 1551 return *print_params_; |
| 1518 } | 1552 } |
| 1519 | 1553 |
| 1520 int PrintWebViewHelper::PrintPreviewContext::last_error() const { | 1554 int PrintWebViewHelper::PrintPreviewContext::last_error() const { |
| 1521 return error_; | 1555 return error_; |
| 1522 } | 1556 } |
| 1523 | 1557 |
| 1524 const gfx::Size& | 1558 const gfx::Size& |
| 1525 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { | 1559 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { |
| 1560 DCHECK(IsRendering()); | |
| 1526 return prep_frame_view_->GetPrintCanvasSize(); | 1561 return prep_frame_view_->GetPrintCanvasSize(); |
| 1527 } | 1562 } |
| 1528 | 1563 |
| 1529 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1564 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1530 prep_frame_view_.reset(); | 1565 prep_frame_view_.reset(); |
| 1531 metafile_.reset(); | 1566 metafile_.reset(); |
| 1532 pages_to_render_.clear(); | 1567 pages_to_render_.clear(); |
| 1533 error_ = PREVIEW_ERROR_NONE; | 1568 error_ = PREVIEW_ERROR_NONE; |
| 1534 } | 1569 } |
| OLD | NEW |