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 9811baf05001402a808f2ac6898a8fa00ca94682..a1c69513058d84f4f483f140bd30affcc9dde7ad 100644 |
| --- a/chrome/browser/ui/webui/print_preview_handler.cc |
| +++ b/chrome/browser/ui/webui/print_preview_handler.cc |
| @@ -6,21 +6,26 @@ |
| #include <string> |
| +#include "base/i18n/file_util_icu.h" |
| #include "base/json/json_reader.h" |
| +#include "base/path_service.h" |
| #include "base/threading/thread.h" |
| #include "base/values.h" |
| #include "chrome/browser/platform_util.h" |
| #include "chrome/browser/printing/print_preview_tab_controller.h" |
| #include "chrome/browser/ui/webui/print_preview_ui_html_source.h" |
| #include "chrome/browser/ui/webui/print_preview_ui.h" |
| +#include "chrome/common/chrome_paths.h" |
| #include "chrome/common/print_messages.h" |
| #include "content/browser/browser_thread.h" |
| #include "content/browser/renderer_host/render_view_host.h" |
| #include "content/browser/tab_contents/tab_contents.h" |
| +#include "grit/generated_resources.h" |
| #include "printing/backend/print_backend.h" |
| #include "printing/metafile.h" |
| #include "printing/metafile_impl.h" |
| #include "printing/print_job_constants.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| namespace { |
| @@ -140,11 +145,17 @@ class PrintToPdfTask : public Task { |
| FilePath path_; |
| }; |
| +FilePath* PrintPreviewHandler::last_saved_path_ = NULL; |
| + |
| PrintPreviewHandler::PrintPreviewHandler() |
| : print_backend_(printing::PrintBackend::CreateInstance(NULL)), |
| need_to_generate_preview_(true), |
| color_(kColorDefaultValue), |
| landscape_(kLandscapeDefaultValue) { |
| + if (!last_saved_path_) { |
| + last_saved_path_ = new FilePath(); |
| + PathService::Get(chrome::DIR_USER_DOCUMENTS, last_saved_path_); |
|
Lei Zhang
2011/04/14 00:15:45
BTW, you can't do this - file access on the UI thr
dpapad
2011/04/14 02:33:35
Added a scoped exception for the moment. Alternati
|
| + } |
| } |
| PrintPreviewHandler::~PrintPreviewHandler() { |
| @@ -202,11 +213,23 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
| if (!settings.get()) |
| return; |
| - bool print_to_pdf; |
| + bool print_to_pdf = false; |
| settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); |
| if (print_to_pdf) { |
| - SelectFile(); |
| + // Pre-populating select file dialog with print job title. |
| + FilePath::StringType print_job_title; |
|
Lei Zhang
2011/04/14 00:15:45
I think you can instead just do the following:
dpapad
2011/04/14 02:33:35
Done.
|
| + bool ret = settings->GetString(printing::kPrintJobTitle, &print_job_title); |
| + if (!ret || print_job_title.length() == 0) |
| + print_job_title = l10n_util::GetStringUTF8( |
| + IDS_DEFAULT_PRINT_DOCUMENT_TITLE); |
| + |
| + file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); |
| + FilePath default_filename(print_job_title); |
| + default_filename = |
| + default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
| + |
| + SelectFile(default_filename); |
| } else { |
| RenderViewHost* rvh = web_ui_->GetRenderViewHost(); |
| rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); |
| @@ -240,7 +263,7 @@ void PrintPreviewHandler::ProcessLandscapeSetting( |
| } |
| } |
| -void PrintPreviewHandler::SelectFile() { |
| +void PrintPreviewHandler::SelectFile(const FilePath& default_filename) { |
| SelectFileDialog::FileTypeInfo file_type_info; |
| file_type_info.extensions.resize(1); |
| file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf")); |
| @@ -251,7 +274,7 @@ void PrintPreviewHandler::SelectFile() { |
| select_file_dialog_->SelectFile( |
| SelectFileDialog::SELECT_SAVEAS_FILE, |
| string16(), |
| - FilePath(), |
| + last_saved_path_->Append(default_filename), |
| &file_type_info, |
| 0, |
| FILE_PATH_LITERAL(""), |
| @@ -271,6 +294,9 @@ void PrintPreviewHandler::FileSelected(const FilePath& path, |
| printing::PreviewMetafile* metafile = new printing::PreviewMetafile; |
| metafile->InitFromData(data.first->memory(), data.second); |
| + // 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); |
| } |