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/browser/ui/webui/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #if !defined(OS_CHROMEOS) | 10 #if !defined(OS_CHROMEOS) |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false); | 576 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false); |
| 577 | 577 |
| 578 TabContentsWrapper* preview_tab_wrapper = | 578 TabContentsWrapper* preview_tab_wrapper = |
| 579 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); | 579 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); |
| 580 | 580 |
| 581 bool print_to_cloud = settings->HasKey(printing::kSettingCloudPrintId); | 581 bool print_to_cloud = settings->HasKey(printing::kSettingCloudPrintId); |
| 582 if (print_to_cloud) { | 582 if (print_to_cloud) { |
| 583 std::string print_ticket; | 583 std::string print_ticket; |
| 584 args->GetString(1, &print_ticket); | 584 args->GetString(1, &print_ticket); |
| 585 SendCloudPrintJob(*settings, print_ticket); | 585 SendCloudPrintJob(*settings, print_ticket); |
| 586 } else if (print_to_pdf) { | 586 } else if (print_to_pdf) { |
|
dpapad
2011/09/02 18:36:33
I would prefer to move this big else if block to a
kmadhusu
2011/09/02 21:47:03
sounds good to me.
dpapad
2011/09/07 00:46:19
Done.
| |
| 587 ReportUserActionHistogram(PRINT_TO_PDF); | 587 ReportUserActionHistogram(PRINT_TO_PDF); |
| 588 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", | 588 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", |
| 589 GetPageCountFromSettingsDictionary(*settings)); | 589 GetPageCountFromSettingsDictionary(*settings)); |
| 590 | 590 |
| 591 // Pre-populating select file dialog with print job title. | 591 if (!pending_print_to_pdf_path_.empty()) { |
| 592 string16 print_job_title_utf16 = | 592 // User has already selected a path, no need to show the dialog again. |
| 593 preview_tab_wrapper->print_view_manager()->RenderSourceName(); | 593 FilePath& temp_path = pending_print_to_pdf_path_; |
|
kmadhusu
2011/09/02 21:47:03
Is this temp_path necessary?
dpapad
2011/09/07 00:46:19
Done. Changed pending_print_to_pdf_path_ to be a s
| |
| 594 PostPrintToPdfTask(temp_path, true); | |
| 595 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( | |
| 596 platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { | |
| 597 // Pre-populating select file dialog with print job title. | |
| 598 string16 print_job_title_utf16 = | |
| 599 preview_tab_wrapper->print_view_manager()->RenderSourceName(); | |
| 594 | 600 |
| 595 #if defined(OS_WIN) | 601 #if defined(OS_WIN) |
| 596 FilePath::StringType print_job_title(print_job_title_utf16); | 602 FilePath::StringType print_job_title(print_job_title_utf16); |
| 597 #elif defined(OS_POSIX) | 603 #elif defined(OS_POSIX) |
| 598 FilePath::StringType print_job_title = UTF16ToUTF8(print_job_title_utf16); | 604 FilePath::StringType print_job_title = UTF16ToUTF8(print_job_title_utf16); |
| 599 #endif | 605 #endif |
| 600 | 606 |
| 601 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); | 607 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); |
| 602 FilePath default_filename(print_job_title); | 608 FilePath default_filename(print_job_title); |
| 603 default_filename = | 609 default_filename = |
| 604 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); | 610 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
| 605 | 611 |
| 606 SelectFile(default_filename); | 612 SelectFile(default_filename); |
| 613 } | |
| 607 } else { | 614 } else { |
| 608 ReportPrintSettingsStats(*settings); | 615 ReportPrintSettingsStats(*settings); |
| 609 ReportUserActionHistogram(PRINT_TO_PRINTER); | 616 ReportUserActionHistogram(PRINT_TO_PRINTER); |
| 610 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", | 617 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", |
| 611 GetPageCountFromSettingsDictionary(*settings)); | 618 GetPageCountFromSettingsDictionary(*settings)); |
| 612 | 619 |
| 613 // This tries to activate the initiator tab as well, so do not clear the | 620 // This tries to activate the initiator tab as well, so do not clear the |
| 614 // association with the initiator tab yet. | 621 // association with the initiator tab yet. |
| 615 HidePreviewTab(); | 622 HidePreviewTab(); |
| 616 | 623 |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 922 reported_failed_preview_ = true; | 929 reported_failed_preview_ = true; |
| 923 ReportUserActionHistogram(PREVIEW_FAILED); | 930 ReportUserActionHistogram(PREVIEW_FAILED); |
| 924 } | 931 } |
| 925 | 932 |
| 926 void PrintPreviewHandler::ShowSystemDialog() { | 933 void PrintPreviewHandler::ShowSystemDialog() { |
| 927 HandleShowSystemDialog(NULL); | 934 HandleShowSystemDialog(NULL); |
| 928 } | 935 } |
| 929 | 936 |
| 930 void PrintPreviewHandler::FileSelected(const FilePath& path, | 937 void PrintPreviewHandler::FileSelected(const FilePath& path, |
| 931 int index, void* params) { | 938 int index, void* params) { |
| 939 // Updating last_saved_path_ to the newly selected folder. | |
| 940 *last_saved_path_ = path.DirName(); | |
| 941 | |
| 942 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | |
| 943 print_preview_ui->OnFileSelectionCompleted(); | |
| 944 scoped_refptr<RefCountedBytes> data; | |
| 945 print_preview_ui->GetPrintPreviewDataForIndex( | |
| 946 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | |
| 947 if (!data.get()) { | |
| 948 pending_print_to_pdf_path_ = path; | |
| 949 } else { | |
| 950 FilePath temp_path(path); | |
| 951 PostPrintToPdfTask(temp_path, false); | |
| 952 } | |
| 953 } | |
| 954 | |
| 955 void PrintPreviewHandler::PostPrintToPdfTask(FilePath& path, bool is_pending) { | |
| 932 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 956 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| 933 scoped_refptr<RefCountedBytes> data; | 957 scoped_refptr<RefCountedBytes> data; |
| 934 print_preview_ui->GetPrintPreviewDataForIndex( | 958 print_preview_ui->GetPrintPreviewDataForIndex( |
| 935 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 959 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| 936 if (!data.get()) { | |
| 937 NOTREACHED(); | |
| 938 return; | |
| 939 } | |
| 940 | |
| 941 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; | 960 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; |
| 942 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); | 961 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); |
| 943 | |
| 944 // Updating last_saved_path_ to the newly selected folder. | |
| 945 *last_saved_path_ = path.DirName(); | |
| 946 | |
| 947 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); | 962 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); |
| 948 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); | 963 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
| 949 | 964 pending_print_to_pdf_path_.clear(); |
| 950 ActivateInitiatorTabAndClosePreviewTab(); | 965 is_pending ? delete preview_tab_wrapper() : |
|
kmadhusu
2011/09/02 21:47:03
I prefer to have Y ? A : B in an assignment state
dpapad
2011/09/07 00:46:19
No need anymore, I am not hiding the preview tab,
| |
| 966 ActivateInitiatorTabAndClosePreviewTab(); | |
| 951 } | 967 } |
| 952 | 968 |
| 953 void PrintPreviewHandler::FileSelectionCanceled(void* params) { | 969 void PrintPreviewHandler::FileSelectionCanceled(void* params) { |
| 954 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 970 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| 955 print_preview_ui->OnFileSelectionCancelled(); | 971 print_preview_ui->OnFileSelectionCancelled(); |
| 956 } | 972 } |
| 957 | 973 |
| 958 void PrintPreviewHandler::HidePreviewTab() { | 974 void PrintPreviewHandler::HidePreviewTab() { |
| 959 TabContentsWrapper* preview_tab_wrapper = | 975 TabContentsWrapper* preview_tab_wrapper = |
| 960 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); | 976 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); |
| 961 if (GetBackgroundPrintingManager()->HasPrintPreviewTab(preview_tab_wrapper)) | 977 if (GetBackgroundPrintingManager()->HasPrintPreviewTab(preview_tab_wrapper)) |
| 962 return; | 978 return; |
| 963 GetBackgroundPrintingManager()->OwnPrintPreviewTab(preview_tab_wrapper); | 979 GetBackgroundPrintingManager()->OwnPrintPreviewTab(preview_tab_wrapper); |
| 964 } | 980 } |
| 965 | 981 |
| 966 void PrintPreviewHandler::ClearInitiatorTabDetails() { | 982 void PrintPreviewHandler::ClearInitiatorTabDetails() { |
| 967 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 983 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
| 968 if (!initiator_tab) | 984 if (!initiator_tab) |
| 969 return; | 985 return; |
| 970 | 986 |
| 971 // We no longer require the initiator tab details. Remove those details | 987 // We no longer require the initiator tab details. Remove those details |
| 972 // associated with the preview tab to allow the initiator tab to create | 988 // associated with the preview tab to allow the initiator tab to create |
| 973 // another preview tab. | 989 // another preview tab. |
| 974 printing::PrintPreviewTabController* tab_controller = | 990 printing::PrintPreviewTabController* tab_controller = |
| 975 printing::PrintPreviewTabController::GetInstance(); | 991 printing::PrintPreviewTabController::GetInstance(); |
| 976 if (tab_controller) | 992 if (tab_controller) |
| 977 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 993 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
| 978 } | 994 } |
| OLD | NEW |