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/browser/ui/webui/print_preview/print_preview_ui.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 base::TimeTicks::Now() - initial_preview_start_time_); | 552 base::TimeTicks::Now() - initial_preview_start_time_); |
553 } | 553 } |
554 g_print_preview_request_id_map.Get().Set(id_, request_id); | 554 g_print_preview_request_id_map.Get().Set(id_, request_id); |
555 } | 555 } |
556 | 556 |
557 void PrintPreviewUI::OnDidGetPreviewPageCount( | 557 void PrintPreviewUI::OnDidGetPreviewPageCount( |
558 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { | 558 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { |
559 DCHECK_GT(params.page_count, 0); | 559 DCHECK_GT(params.page_count, 0); |
560 if (g_testing_delegate) | 560 if (g_testing_delegate) |
561 g_testing_delegate->DidGetPreviewPageCount(params.page_count); | 561 g_testing_delegate->DidGetPreviewPageCount(params.page_count); |
562 base::Value count(params.page_count); | 562 handler_->SendPageCountReady(params.page_count, params.preview_request_id, |
563 base::Value request_id(params.preview_request_id); | 563 params.fit_to_page_scaling); |
564 base::Value fit_to_page_scaling(params.fit_to_page_scaling); | |
565 web_ui()->CallJavascriptFunctionUnsafe("onDidGetPreviewPageCount", count, | |
566 request_id, fit_to_page_scaling); | |
567 } | 564 } |
568 | 565 |
569 void PrintPreviewUI::OnDidGetDefaultPageLayout( | 566 void PrintPreviewUI::OnDidGetDefaultPageLayout( |
570 const PageSizeMargins& page_layout, const gfx::Rect& printable_area, | 567 const PageSizeMargins& page_layout, const gfx::Rect& printable_area, |
571 bool has_custom_page_size_style) { | 568 bool has_custom_page_size_style) { |
572 if (page_layout.margin_top < 0 || page_layout.margin_left < 0 || | 569 if (page_layout.margin_top < 0 || page_layout.margin_left < 0 || |
573 page_layout.margin_bottom < 0 || page_layout.margin_right < 0 || | 570 page_layout.margin_bottom < 0 || page_layout.margin_right < 0 || |
574 page_layout.content_width < 0 || page_layout.content_height < 0 || | 571 page_layout.content_width < 0 || page_layout.content_height < 0 || |
575 printable_area.width() <= 0 || printable_area.height() <= 0) { | 572 printable_area.width() <= 0 || printable_area.height() <= 0) { |
576 NOTREACHED(); | 573 NOTREACHED(); |
577 return; | 574 return; |
578 } | 575 } |
579 | 576 |
580 base::DictionaryValue layout; | 577 base::DictionaryValue layout; |
581 layout.SetDouble(printing::kSettingMarginTop, page_layout.margin_top); | 578 layout.SetDouble(printing::kSettingMarginTop, page_layout.margin_top); |
582 layout.SetDouble(printing::kSettingMarginLeft, page_layout.margin_left); | 579 layout.SetDouble(printing::kSettingMarginLeft, page_layout.margin_left); |
583 layout.SetDouble(printing::kSettingMarginBottom, page_layout.margin_bottom); | 580 layout.SetDouble(printing::kSettingMarginBottom, page_layout.margin_bottom); |
584 layout.SetDouble(printing::kSettingMarginRight, page_layout.margin_right); | 581 layout.SetDouble(printing::kSettingMarginRight, page_layout.margin_right); |
585 layout.SetDouble(printing::kSettingContentWidth, page_layout.content_width); | 582 layout.SetDouble(printing::kSettingContentWidth, page_layout.content_width); |
586 layout.SetDouble(printing::kSettingContentHeight, page_layout.content_height); | 583 layout.SetDouble(printing::kSettingContentHeight, page_layout.content_height); |
587 layout.SetInteger(printing::kSettingPrintableAreaX, printable_area.x()); | 584 layout.SetInteger(printing::kSettingPrintableAreaX, printable_area.x()); |
588 layout.SetInteger(printing::kSettingPrintableAreaY, printable_area.y()); | 585 layout.SetInteger(printing::kSettingPrintableAreaY, printable_area.y()); |
589 layout.SetInteger(printing::kSettingPrintableAreaWidth, | 586 layout.SetInteger(printing::kSettingPrintableAreaWidth, |
590 printable_area.width()); | 587 printable_area.width()); |
591 layout.SetInteger(printing::kSettingPrintableAreaHeight, | 588 layout.SetInteger(printing::kSettingPrintableAreaHeight, |
592 printable_area.height()); | 589 printable_area.height()); |
593 | 590 handler_->SendPageLayoutReady(layout, has_custom_page_size_style); |
594 base::Value has_page_size_style(has_custom_page_size_style); | |
595 web_ui()->CallJavascriptFunctionUnsafe("onDidGetDefaultPageLayout", layout, | |
596 has_page_size_style); | |
597 } | 591 } |
598 | 592 |
599 void PrintPreviewUI::OnDidPreviewPage(int page_number, | 593 void PrintPreviewUI::OnDidPreviewPage(int page_number, |
600 int preview_request_id) { | 594 int preview_request_id) { |
601 DCHECK_GE(page_number, 0); | 595 DCHECK_GE(page_number, 0); |
602 base::Value number(page_number); | |
603 base::Value ui_identifier(id_); | |
604 base::Value request_id(preview_request_id); | |
605 if (g_testing_delegate) | 596 if (g_testing_delegate) |
606 g_testing_delegate->DidRenderPreviewPage(web_ui()->GetWebContents()); | 597 g_testing_delegate->DidRenderPreviewPage(web_ui()->GetWebContents()); |
607 web_ui()->CallJavascriptFunctionUnsafe("onDidPreviewPage", number, | 598 handler_->SendPagePreviewReady(page_number, id_, preview_request_id); |
608 ui_identifier, request_id); | |
609 } | 599 } |
610 | 600 |
611 void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count, | 601 void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count, |
612 int preview_request_id) { | 602 int preview_request_id) { |
613 VLOG(1) << "Print preview request finished with " | 603 VLOG(1) << "Print preview request finished with " |
614 << expected_pages_count << " pages"; | 604 << expected_pages_count << " pages"; |
615 | 605 |
616 if (!initial_preview_start_time_.is_null()) { | 606 if (!initial_preview_start_time_.is_null()) { |
617 UMA_HISTOGRAM_TIMES("PrintPreview.InitialDisplayTime", | 607 UMA_HISTOGRAM_TIMES("PrintPreview.InitialDisplayTime", |
618 base::TimeTicks::Now() - initial_preview_start_time_); | 608 base::TimeTicks::Now() - initial_preview_start_time_); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 if (dialog_closed_) | 650 if (dialog_closed_) |
661 return; | 651 return; |
662 dialog_closed_ = true; | 652 dialog_closed_ = true; |
663 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); | 653 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); |
664 if (!delegate) | 654 if (!delegate) |
665 return; | 655 return; |
666 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); | 656 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); |
667 delegate->OnDialogCloseFromWebUI(); | 657 delegate->OnDialogCloseFromWebUI(); |
668 } | 658 } |
669 | 659 |
670 void PrintPreviewUI::OnReloadPrintersList() { | |
671 web_ui()->CallJavascriptFunctionUnsafe("reloadPrintersList"); | |
672 } | |
673 | |
674 void PrintPreviewUI::OnSetOptionsFromDocument( | 660 void PrintPreviewUI::OnSetOptionsFromDocument( |
675 const PrintHostMsg_SetOptionsFromDocument_Params& params) { | 661 const PrintHostMsg_SetOptionsFromDocument_Params& params) { |
676 base::DictionaryValue options; | 662 handler_->SendPrintPresetOptions(params.is_scaling_disabled, params.copies, |
677 options.SetBoolean(printing::kSettingDisableScaling, | 663 params.duplex); |
678 params.is_scaling_disabled); | |
679 options.SetInteger(printing::kSettingCopies, params.copies); | |
680 options.SetInteger(printing::kSettingDuplexMode, params.duplex); | |
681 web_ui()->CallJavascriptFunctionUnsafe("printPresetOptionsFromDocument", | |
682 options); | |
683 } | 664 } |
684 | 665 |
685 // static | 666 // static |
686 void PrintPreviewUI::SetDelegateForTesting(TestingDelegate* delegate) { | 667 void PrintPreviewUI::SetDelegateForTesting(TestingDelegate* delegate) { |
687 g_testing_delegate = delegate; | 668 g_testing_delegate = delegate; |
688 } | 669 } |
689 | 670 |
690 void PrintPreviewUI::SetSelectedFileForTesting(const base::FilePath& path) { | 671 void PrintPreviewUI::SetSelectedFileForTesting(const base::FilePath& path) { |
691 handler_->FileSelected(path, 0, NULL); | 672 handler_->FileSelected(path, 0, NULL); |
692 } | 673 } |
693 | 674 |
694 void PrintPreviewUI::SetPdfSavedClosureForTesting( | 675 void PrintPreviewUI::SetPdfSavedClosureForTesting( |
695 const base::Closure& closure) { | 676 const base::Closure& closure) { |
696 handler_->SetPdfSavedClosureForTesting(closure); | 677 handler_->SetPdfSavedClosureForTesting(closure); |
697 } | 678 } |
OLD | NEW |