Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8825)

Unified Diff: chrome/browser/ui/webui/print_preview_handler.cc

Issue 6759044: Prepopulating "Print To PDF" select file dialog with a suggested filename and path. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Getting print job title in a different way. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 08f506a787b480d3ee511441b2603387e2e32120..4a2e2555f9761a9689881c750b4e3babfaac78e7 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/native_metafile_factory.h"
#include "printing/native_metafile.h"
#include "printing/print_job_constants.h"
+#include "ui/base/l10n/l10n_util.h"
namespace {
@@ -202,11 +207,24 @@ 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;
+ bool ret = settings->GetString(printing::kPrintJobTitle, &print_job_title);
+ if (!ret || print_job_title.length() == 0)
kmadhusu 2011/04/11 17:34:26 If "ret" value is false, we need to return. Please
dpapad 2011/04/12 00:20:09 Why do we want to prevent the user from printing,
+ print_job_title = l10n_util::GetStringUTF8(IDS_PRINT_PREVIEW_TITLE);
kmadhusu 2011/04/11 17:34:26 We don't want to display the default file name as
dpapad 2011/04/12 00:20:09 Done.
+
+ file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_');
+ FilePath default_path;
+ PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_path);
+ FilePath default_filename(print_job_title);
+ default_filename =
+ default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf"));
+
+ SelectFile(default_path.Append(default_filename));
} else {
RenderViewHost* rvh = web_ui_->GetRenderViewHost();
rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings));
@@ -240,7 +258,7 @@ void PrintPreviewHandler::ProcessLandscapeSetting(
}
}
-void PrintPreviewHandler::SelectFile() {
+void PrintPreviewHandler::SelectFile(const FilePath& default_path) {
SelectFileDialog::FileTypeInfo file_type_info;
file_type_info.extensions.resize(1);
file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf"));
@@ -251,7 +269,7 @@ void PrintPreviewHandler::SelectFile() {
select_file_dialog_->SelectFile(
SelectFileDialog::SELECT_SAVEAS_FILE,
string16(),
- FilePath(),
+ default_path,
&file_type_info,
0,
FILE_PATH_LITERAL(""),

Powered by Google App Engine
This is Rietveld 408576698