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

Side by Side 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: Rebasing 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/print_preview_handler.h ('k') | printing/print_job_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/print_preview_handler.h" 5 #include "chrome/browser/ui/webui/print_preview_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/i18n/file_util_icu.h"
9 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/path_service.h"
10 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
11 #include "base/values.h" 13 #include "base/values.h"
12 #include "chrome/browser/platform_util.h" 14 #include "chrome/browser/platform_util.h"
13 #include "chrome/browser/printing/print_preview_tab_controller.h" 15 #include "chrome/browser/printing/print_preview_tab_controller.h"
14 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h" 16 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h"
15 #include "chrome/browser/ui/webui/print_preview_ui.h" 17 #include "chrome/browser/ui/webui/print_preview_ui.h"
18 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/print_messages.h" 19 #include "chrome/common/print_messages.h"
17 #include "content/browser/browser_thread.h" 20 #include "content/browser/browser_thread.h"
18 #include "content/browser/renderer_host/render_view_host.h" 21 #include "content/browser/renderer_host/render_view_host.h"
19 #include "content/browser/tab_contents/tab_contents.h" 22 #include "content/browser/tab_contents/tab_contents.h"
20 #include "printing/backend/print_backend.h" 23 #include "printing/backend/print_backend.h"
21 #include "printing/native_metafile_factory.h" 24 #include "printing/native_metafile_factory.h"
22 #include "printing/native_metafile.h" 25 #include "printing/native_metafile.h"
23 #include "printing/print_job_constants.h" 26 #include "printing/print_job_constants.h"
24 27
25 namespace { 28 namespace {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 TabContents* initiator_tab = GetInitiatorTab(web_ui_->tab_contents()); 198 TabContents* initiator_tab = GetInitiatorTab(web_ui_->tab_contents());
196 if (initiator_tab) { 199 if (initiator_tab) {
197 RenderViewHost* rvh = initiator_tab->render_view_host(); 200 RenderViewHost* rvh = initiator_tab->render_view_host();
198 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->routing_id())); 201 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->routing_id()));
199 } 202 }
200 203
201 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); 204 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args));
202 if (!settings.get()) 205 if (!settings.get())
203 return; 206 return;
204 207
205 bool print_to_pdf; 208 bool print_to_pdf = false;
206 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); 209 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf);
207 210
208 if (print_to_pdf) { 211 if (print_to_pdf) {
209 SelectFile(); 212 // Pre-populating select file dialog with print job title.
213 FilePath::StringType print_job_title;
214 bool ret = settings->GetString(printing::kPrintJobTitle, &print_job_title);
215 if (!ret || print_job_title.length() == 0)
kmadhusu 2011/04/05 20:57:48 If the "print_job_title" is empty, I think its bet
dpapad 2011/04/09 01:38:06 Done.
216 return;
217
218 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_');
219 FilePath default_path;
220 PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_path);
221 FilePath default_filename(print_job_title);
222 default_filename =
223 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf"));
224
225 SelectFile(default_path.Append(default_filename));
210 } else { 226 } else {
211 RenderViewHost* rvh = web_ui_->GetRenderViewHost(); 227 RenderViewHost* rvh = web_ui_->GetRenderViewHost();
212 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); 228 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings));
213 } 229 }
214 } 230 }
215 231
216 void PrintPreviewHandler::SendPrinterList( 232 void PrintPreviewHandler::SendPrinterList(
217 const ListValue& printers, 233 const ListValue& printers,
218 const FundamentalValue& default_printer_index) { 234 const FundamentalValue& default_printer_index) {
219 web_ui_->CallJavascriptFunction("setPrinters", printers, 235 web_ui_->CallJavascriptFunction("setPrinters", printers,
(...skipping 13 matching lines...) Expand all
233 void PrintPreviewHandler::ProcessLandscapeSetting( 249 void PrintPreviewHandler::ProcessLandscapeSetting(
234 const DictionaryValue& settings) { 250 const DictionaryValue& settings) {
235 bool landscape = kLandscapeDefaultValue; 251 bool landscape = kLandscapeDefaultValue;
236 settings.GetBoolean(printing::kSettingLandscape, &landscape); 252 settings.GetBoolean(printing::kSettingLandscape, &landscape);
237 if (landscape != landscape_) { 253 if (landscape != landscape_) {
238 landscape_ = landscape; 254 landscape_ = landscape;
239 need_to_generate_preview_ = true; 255 need_to_generate_preview_ = true;
240 } 256 }
241 } 257 }
242 258
243 void PrintPreviewHandler::SelectFile() { 259 void PrintPreviewHandler::SelectFile(const FilePath& default_path) {
244 SelectFileDialog::FileTypeInfo file_type_info; 260 SelectFileDialog::FileTypeInfo file_type_info;
245 file_type_info.extensions.resize(1); 261 file_type_info.extensions.resize(1);
246 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf")); 262 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf"));
247 263
248 if (!select_file_dialog_.get()) 264 if (!select_file_dialog_.get())
249 select_file_dialog_ = SelectFileDialog::Create(this); 265 select_file_dialog_ = SelectFileDialog::Create(this);
250 266
251 select_file_dialog_->SelectFile( 267 select_file_dialog_->SelectFile(
252 SelectFileDialog::SELECT_SAVEAS_FILE, 268 SelectFileDialog::SELECT_SAVEAS_FILE,
253 string16(), 269 string16(),
254 FilePath(), 270 default_path,
255 &file_type_info, 271 &file_type_info,
256 0, 272 0,
257 FILE_PATH_LITERAL(""), 273 FILE_PATH_LITERAL(""),
258 platform_util::GetTopLevel( 274 platform_util::GetTopLevel(
259 web_ui_->tab_contents()->GetNativeView()), 275 web_ui_->tab_contents()->GetNativeView()),
260 NULL); 276 NULL);
261 } 277 }
262 278
263 void PrintPreviewHandler::FileSelected(const FilePath& path, 279 void PrintPreviewHandler::FileSelected(const FilePath& path,
264 int index, void* params) { 280 int index, void* params) {
265 #if defined(OS_POSIX) 281 #if defined(OS_POSIX)
266 PrintPreviewUIHTMLSource::PrintPreviewData data; 282 PrintPreviewUIHTMLSource::PrintPreviewData data;
267 PrintPreviewUI* pp_ui = reinterpret_cast<PrintPreviewUI*>(web_ui_); 283 PrintPreviewUI* pp_ui = reinterpret_cast<PrintPreviewUI*>(web_ui_);
268 pp_ui->html_source()->GetPrintPreviewData(&data); 284 pp_ui->html_source()->GetPrintPreviewData(&data);
269 DCHECK(data.first != NULL); 285 DCHECK(data.first != NULL);
270 DCHECK(data.second > 0); 286 DCHECK(data.second > 0);
271 287
272 printing::NativeMetafile* metafile = 288 printing::NativeMetafile* metafile =
273 printing::NativeMetafileFactory::CreateFromData(data.first->memory(), 289 printing::NativeMetafileFactory::CreateFromData(data.first->memory(),
274 data.second); 290 data.second);
275 metafile->FinishDocument(); 291 metafile->FinishDocument();
276 292
277 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); 293 PrintToPdfTask* task = new PrintToPdfTask(metafile, path);
278 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); 294 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task);
279 #else 295 #else
280 NOTIMPLEMENTED(); 296 NOTIMPLEMENTED();
281 #endif 297 #endif
282 } 298 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview_handler.h ('k') | printing/print_job_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698