| 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_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // so ignore the page range and print all pages. | 467 // so ignore the page range and print all pages. |
| 468 settings->Remove(printing::kSettingPageRange, NULL); | 468 settings->Remove(printing::kSettingPageRange, NULL); |
| 469 RenderViewHost* rvh = preview_web_contents()->GetRenderViewHost(); | 469 RenderViewHost* rvh = preview_web_contents()->GetRenderViewHost(); |
| 470 rvh->Send( | 470 rvh->Send( |
| 471 new PrintMsg_PrintForPrintPreview(rvh->GetRoutingID(), *settings)); | 471 new PrintMsg_PrintForPrintPreview(rvh->GetRoutingID(), *settings)); |
| 472 | 472 |
| 473 // For all other cases above, the tab will stay open until the printing has | 473 // For all other cases above, the tab will stay open until the printing has |
| 474 // finished. Then the tab closes and PrintPreviewDone() gets called. Here, | 474 // finished. Then the tab closes and PrintPreviewDone() gets called. Here, |
| 475 // since we are hiding the tab, and not closing it, we need to make this | 475 // since we are hiding the tab, and not closing it, we need to make this |
| 476 // call. | 476 // call. |
| 477 if (initiator_tab) | 477 if (initiator_tab) { |
| 478 initiator_tab->print_view_manager()->PrintPreviewDone(); | 478 printing::PrintViewManager* print_view_manager = |
| 479 printing::PrintViewManager::FromWebContents( |
| 480 initiator_tab->web_contents()); |
| 481 print_view_manager->PrintPreviewDone(); |
| 482 } |
| 479 } | 483 } |
| 480 } | 484 } |
| 481 | 485 |
| 482 void PrintPreviewHandler::HandlePrintToPdf( | 486 void PrintPreviewHandler::HandlePrintToPdf( |
| 483 const base::DictionaryValue& settings) { | 487 const base::DictionaryValue& settings) { |
| 484 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 488 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 485 web_ui()->GetController()); | 489 web_ui()->GetController()); |
| 486 if (print_to_pdf_path_.get()) { | 490 if (print_to_pdf_path_.get()) { |
| 487 // User has already selected a path, no need to show the dialog again. | 491 // User has already selected a path, no need to show the dialog again. |
| 488 scoped_refptr<base::RefCountedBytes> data; | 492 scoped_refptr<base::RefCountedBytes> data; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } | 627 } |
| 624 | 628 |
| 625 void PrintPreviewHandler::HandleShowSystemDialog(const ListValue* /*args*/) { | 629 void PrintPreviewHandler::HandleShowSystemDialog(const ListValue* /*args*/) { |
| 626 ReportStats(); | 630 ReportStats(); |
| 627 ReportUserActionHistogram(FALLBACK_TO_ADVANCED_SETTINGS_DIALOG); | 631 ReportUserActionHistogram(FALLBACK_TO_ADVANCED_SETTINGS_DIALOG); |
| 628 | 632 |
| 629 TabContents* initiator_tab = GetInitiatorTab(); | 633 TabContents* initiator_tab = GetInitiatorTab(); |
| 630 if (!initiator_tab) | 634 if (!initiator_tab) |
| 631 return; | 635 return; |
| 632 | 636 |
| 633 printing::PrintViewManager* manager = initiator_tab->print_view_manager(); | 637 printing::PrintViewManager* print_view_manager = |
| 634 manager->set_observer(this); | 638 printing::PrintViewManager::FromWebContents( |
| 635 manager->PrintForSystemDialogNow(); | 639 initiator_tab->web_contents()); |
| 640 print_view_manager->set_observer(this); |
| 641 print_view_manager->PrintForSystemDialogNow(); |
| 636 | 642 |
| 637 // Cancel the pending preview request if exists. | 643 // Cancel the pending preview request if exists. |
| 638 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 644 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 639 web_ui()->GetController()); | 645 web_ui()->GetController()); |
| 640 print_preview_ui->OnCancelPendingPreviewRequest(); | 646 print_preview_ui->OnCancelPendingPreviewRequest(); |
| 641 } | 647 } |
| 642 | 648 |
| 643 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { | 649 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { |
| 644 ++manage_printers_dialog_request_count_; | 650 ++manage_printers_dialog_request_count_; |
| 645 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); | 651 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 | 797 |
| 792 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, | 798 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, |
| 793 std::string print_ticket) { | 799 std::string print_ticket) { |
| 794 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); | 800 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); |
| 795 scoped_refptr<base::RefCountedBytes> data; | 801 scoped_refptr<base::RefCountedBytes> data; |
| 796 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 802 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 797 web_ui()->GetController()); | 803 web_ui()->GetController()); |
| 798 print_preview_ui->GetPrintPreviewDataForIndex( | 804 print_preview_ui->GetPrintPreviewDataForIndex( |
| 799 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 805 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| 800 if (data.get() && data->size() > 0U && data->front()) { | 806 if (data.get() && data->size() > 0U && data->front()) { |
| 801 string16 print_job_title_utf16 = | 807 printing::PrintViewManager* print_view_manager = |
| 802 preview_tab_contents()->print_view_manager()->RenderSourceName(); | 808 printing::PrintViewManager::FromWebContents( |
| 809 preview_tab_contents()->web_contents()); |
| 810 string16 print_job_title_utf16 = print_view_manager->RenderSourceName(); |
| 803 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16); | 811 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16); |
| 804 std::string printer_id; | 812 std::string printer_id; |
| 805 settings.GetString(printing::kSettingCloudPrintId, &printer_id); | 813 settings.GetString(printing::kSettingCloudPrintId, &printer_id); |
| 806 // BASE64 encode the job data. | 814 // BASE64 encode the job data. |
| 807 std::string raw_data(reinterpret_cast<const char*>(data->front()), | 815 std::string raw_data(reinterpret_cast<const char*>(data->front()), |
| 808 data->size()); | 816 data->size()); |
| 809 std::string base64_data; | 817 std::string base64_data; |
| 810 if (!base::Base64Encode(raw_data, &base64_data)) { | 818 if (!base::Base64Encode(raw_data, &base64_data)) { |
| 811 NOTREACHED() << "Base64 encoding PDF data."; | 819 NOTREACHED() << "Base64 encoding PDF data."; |
| 812 } | 820 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 FILE_PATH_LITERAL(""), | 899 FILE_PATH_LITERAL(""), |
| 892 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), | 900 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), |
| 893 NULL); | 901 NULL); |
| 894 } | 902 } |
| 895 | 903 |
| 896 void PrintPreviewHandler::OnTabDestroyed() { | 904 void PrintPreviewHandler::OnTabDestroyed() { |
| 897 TabContents* initiator_tab = GetInitiatorTab(); | 905 TabContents* initiator_tab = GetInitiatorTab(); |
| 898 if (!initiator_tab) | 906 if (!initiator_tab) |
| 899 return; | 907 return; |
| 900 | 908 |
| 901 initiator_tab->print_view_manager()->set_observer(NULL); | 909 printing::PrintViewManager* print_view_manager = |
| 910 printing::PrintViewManager::FromWebContents( |
| 911 initiator_tab->web_contents()); |
| 912 print_view_manager->set_observer(NULL); |
| 902 } | 913 } |
| 903 | 914 |
| 904 void PrintPreviewHandler::OnPrintPreviewFailed() { | 915 void PrintPreviewHandler::OnPrintPreviewFailed() { |
| 905 if (reported_failed_preview_) | 916 if (reported_failed_preview_) |
| 906 return; | 917 return; |
| 907 reported_failed_preview_ = true; | 918 reported_failed_preview_ = true; |
| 908 ReportUserActionHistogram(PREVIEW_FAILED); | 919 ReportUserActionHistogram(PREVIEW_FAILED); |
| 909 } | 920 } |
| 910 | 921 |
| 911 void PrintPreviewHandler::ShowSystemDialog() { | 922 void PrintPreviewHandler::ShowSystemDialog() { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 return; | 974 return; |
| 964 | 975 |
| 965 // We no longer require the initiator tab details. Remove those details | 976 // We no longer require the initiator tab details. Remove those details |
| 966 // associated with the preview tab to allow the initiator tab to create | 977 // associated with the preview tab to allow the initiator tab to create |
| 967 // another preview tab. | 978 // another preview tab. |
| 968 printing::PrintPreviewTabController* tab_controller = | 979 printing::PrintPreviewTabController* tab_controller = |
| 969 printing::PrintPreviewTabController::GetInstance(); | 980 printing::PrintPreviewTabController::GetInstance(); |
| 970 if (tab_controller) | 981 if (tab_controller) |
| 971 tab_controller->EraseInitiatorTabInfo(preview_tab_contents()); | 982 tab_controller->EraseInitiatorTabInfo(preview_tab_contents()); |
| 972 } | 983 } |
| OLD | NEW |