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 9d233c40dcb29cf77d3368c869440c0f054c971b..f1641c52c9be435a60e316f3beae9f804f157d56 100644 |
| --- a/chrome/browser/ui/webui/print_preview_handler.cc |
| +++ b/chrome/browser/ui/webui/print_preview_handler.cc |
| @@ -608,9 +608,38 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
| args->GetString(1, &print_ticket); |
| SendCloudPrintJob(*settings, print_ticket); |
| } else if (print_to_pdf) { |
| + HandlePrintToPdf(*settings.get()); |
|
kmadhusu
2011/09/08 18:01:47
HandlePrintToPdf(*settings);
dpapad
2011/09/08 19:11:33
Done.
|
| + } else { |
| + ReportPrintSettingsStats(*settings); |
| + ReportUserActionHistogram(PRINT_TO_PRINTER); |
| + UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", |
| + GetPageCountFromSettingsDictionary(*settings)); |
| + |
| + // This tries to activate the initiator tab as well, so do not clear the |
| + // association with the initiator tab yet. |
| + HidePreviewTab(); |
| + |
| + // Do this so the initiator tab can open a new print preview tab. |
| + ClearInitiatorTabDetails(); |
| + |
| + // The PDF being printed contains only the pages that the user selected, |
| + // so ignore the page range and print all pages. |
| + settings->Remove(printing::kSettingPageRange, NULL); |
| + RenderViewHost* rvh = web_ui_->tab_contents()->render_view_host(); |
| + rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); |
| + } |
| +} |
| + |
| +void PrintPreviewHandler::HandlePrintToPdf( |
| + const base::DictionaryValue& settings) { |
| + if (print_to_pdf_path_.get()) { |
| + // User has already selected a path, no need to show the dialog again. |
| + PostPrintToPdfTask(); |
| + } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( |
| + platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { |
| ReportUserActionHistogram(PRINT_TO_PDF); |
| UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", |
| - GetPageCountFromSettingsDictionary(*settings)); |
| + GetPageCountFromSettingsDictionary(settings)); |
| // Pre-populating select file dialog with print job title. |
| string16 print_job_title_utf16 = |
| @@ -628,24 +657,6 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
| default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
| SelectFile(default_filename); |
| - } else { |
| - ReportPrintSettingsStats(*settings); |
| - ReportUserActionHistogram(PRINT_TO_PRINTER); |
| - UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", |
| - GetPageCountFromSettingsDictionary(*settings)); |
| - |
| - // This tries to activate the initiator tab as well, so do not clear the |
| - // association with the initiator tab yet. |
| - HidePreviewTab(); |
| - |
| - // Do this so the initiator tab can open a new print preview tab. |
| - ClearInitiatorTabDetails(); |
| - |
| - // The PDF being printed contains only the pages that the user selected, |
| - // so ignore the page range and print all pages. |
| - settings->Remove(printing::kSettingPageRange, NULL); |
| - RenderViewHost* rvh = web_ui_->tab_contents()->render_view_host(); |
| - rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); |
| } |
| } |
| @@ -960,24 +971,31 @@ 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->CallJavascriptFunction("fileSelectionCompleted"); |
| scoped_refptr<RefCountedBytes> data; |
| print_preview_ui->GetPrintPreviewDataForIndex( |
| printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| - if (!data.get()) { |
| - NOTREACHED(); |
| - return; |
| - } |
| + print_to_pdf_path_.reset(new FilePath(path)); |
| + if (data.get()) |
| + PostPrintToPdfTask(); |
| +} |
| +void PrintPreviewHandler::PostPrintToPdfTask() { |
| + PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| + scoped_refptr<RefCountedBytes> data; |
| + print_preview_ui->GetPrintPreviewDataForIndex( |
| + printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| + DCHECK(data.get()); |
| 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); |
| + PrintToPdfTask* task = new PrintToPdfTask(metafile, |
| + *print_to_pdf_path_.get()); |
|
kmadhusu
2011/09/08 18:01:47
"*print_to_pdf_path_" is sufficient. ".get()" is n
dpapad
2011/09/08 19:11:33
Done.
|
| BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
| - |
| + print_to_pdf_path_.reset(); |
| ActivateInitiatorTabAndClosePreviewTab(); |
| } |