| 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 3df0e3fa2276bd620a5083200228128883e5c037..f6da814abf27e0b314af4f76eac20b93e90a00cf 100644
|
| --- a/chrome/browser/ui/webui/print_preview_handler.cc
|
| +++ b/chrome/browser/ui/webui/print_preview_handler.cc
|
| @@ -629,9 +629,38 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) {
|
| args->GetString(1, &print_ticket);
|
| SendCloudPrintJob(*settings, print_ticket);
|
| } else if (print_to_pdf) {
|
| + HandlePrintToPdf(*settings);
|
| + } 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 =
|
| @@ -649,24 +678,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));
|
| }
|
| }
|
|
|
| @@ -981,24 +992,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_);
|
| BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task);
|
| -
|
| + print_to_pdf_path_.reset();
|
| ActivateInitiatorTabAndClosePreviewTab();
|
| }
|
|
|
|
|