Chromium Code Reviews| Index: chrome/browser/ui/webui/print_preview_handler.cc |
| diff --git a/chrome/browser/ui/webui/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview_handler.cc |
| index 53faf1ac950bb3e6c023c2973e89fd3cb4b5a47b..41e2d706059b6d47bc2c621cbd11405db511b490 100644 |
| --- a/chrome/browser/ui/webui/print_preview_handler.cc |
| +++ b/chrome/browser/ui/webui/print_preview_handler.cc |
| @@ -588,22 +588,29 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
| UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", |
| GetPageCountFromSettingsDictionary(*settings)); |
| - // Pre-populating select file dialog with print job title. |
| - string16 print_job_title_utf16 = |
| - preview_tab_wrapper->print_view_manager()->RenderSourceName(); |
| + if (!pending_print_to_pdf_path_.empty()) { |
| + // User has already selected a path, no need to show the dialog again. |
| + 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
|
| + PostPrintToPdfTask(temp_path, true); |
| + } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( |
| + platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { |
| + // Pre-populating select file dialog with print job title. |
| + string16 print_job_title_utf16 = |
| + preview_tab_wrapper->print_view_manager()->RenderSourceName(); |
| #if defined(OS_WIN) |
| - FilePath::StringType print_job_title(print_job_title_utf16); |
| + FilePath::StringType print_job_title(print_job_title_utf16); |
| #elif defined(OS_POSIX) |
| - FilePath::StringType print_job_title = UTF16ToUTF8(print_job_title_utf16); |
| + FilePath::StringType print_job_title = UTF16ToUTF8(print_job_title_utf16); |
| #endif |
| - file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); |
| - FilePath default_filename(print_job_title); |
| - default_filename = |
| - default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
| + file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); |
| + FilePath default_filename(print_job_title); |
| + default_filename = |
| + default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
| - SelectFile(default_filename); |
| + SelectFile(default_filename); |
| + } |
| } else { |
| ReportPrintSettingsStats(*settings); |
| ReportUserActionHistogram(PRINT_TO_PRINTER); |
| @@ -929,25 +936,34 @@ void PrintPreviewHandler::ShowSystemDialog() { |
| void PrintPreviewHandler::FileSelected(const FilePath& path, |
| int index, void* params) { |
| + // Updating last_saved_path_ to the newly selected folder. |
| + *last_saved_path_ = path.DirName(); |
| + |
| PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| + print_preview_ui->OnFileSelectionCompleted(); |
| scoped_refptr<RefCountedBytes> data; |
| print_preview_ui->GetPrintPreviewDataForIndex( |
| printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| if (!data.get()) { |
| - NOTREACHED(); |
| - return; |
| + pending_print_to_pdf_path_ = path; |
| + } else { |
| + FilePath temp_path(path); |
| + PostPrintToPdfTask(temp_path, false); |
| } |
| +} |
| +void PrintPreviewHandler::PostPrintToPdfTask(FilePath& path, bool is_pending) { |
| + PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| + scoped_refptr<RefCountedBytes> data; |
| + print_preview_ui->GetPrintPreviewDataForIndex( |
| + printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| printing::PreviewMetafile* metafile = new printing::PreviewMetafile; |
| metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); |
| - |
| - // Updating last_saved_path_ to the newly selected folder. |
| - *last_saved_path_ = path.DirName(); |
| - |
| PrintToPdfTask* task = new PrintToPdfTask(metafile, path); |
| BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
| - |
| - ActivateInitiatorTabAndClosePreviewTab(); |
| + pending_print_to_pdf_path_.clear(); |
| + 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,
|
| + ActivateInitiatorTabAndClosePreviewTab(); |
| } |
| void PrintPreviewHandler::FileSelectionCanceled(void* params) { |