| OLD | NEW |
| 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/i18n/file_util_icu.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/platform_util.h" | 17 #include "chrome/browser/platform_util.h" |
| 18 #include "chrome/browser/printing/background_printing_manager.h" |
| 17 #include "chrome/browser/printing/printer_manager_dialog.h" | 19 #include "chrome/browser/printing/printer_manager_dialog.h" |
| 18 #include "chrome/browser/printing/print_preview_tab_controller.h" | 20 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 19 #include "chrome/browser/ui/browser_list.h" | 21 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 21 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h" | 23 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h" |
| 22 #include "chrome/browser/ui/webui/print_preview_ui.h" | 24 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 23 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/print_messages.h" | 26 #include "chrome/common/print_messages.h" |
| 25 #include "content/browser/browser_thread.h" | 27 #include "content/browser/browser_thread.h" |
| 26 #include "content/browser/renderer_host/render_view_host.h" | 28 #include "content/browser/renderer_host/render_view_host.h" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->routing_id())); | 273 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->routing_id())); |
| 272 } | 274 } |
| 273 | 275 |
| 274 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); | 276 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); |
| 275 if (!settings.get()) | 277 if (!settings.get()) |
| 276 return; | 278 return; |
| 277 | 279 |
| 278 bool print_to_pdf = false; | 280 bool print_to_pdf = false; |
| 279 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); | 281 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); |
| 280 | 282 |
| 283 TabContentsWrapper* preview_tab_wrapper = |
| 284 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); |
| 285 |
| 281 if (print_to_pdf) { | 286 if (print_to_pdf) { |
| 282 // Pre-populating select file dialog with print job title. | 287 // Pre-populating select file dialog with print job title. |
| 283 TabContentsWrapper* wrapper = | |
| 284 TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); | |
| 285 | |
| 286 string16 print_job_title_utf16 = | 288 string16 print_job_title_utf16 = |
| 287 wrapper->print_view_manager()->RenderSourceName(); | 289 preview_tab_wrapper->print_view_manager()->RenderSourceName(); |
| 288 | 290 |
| 289 #if defined(OS_WIN) | 291 #if defined(OS_WIN) |
| 290 FilePath::StringType print_job_title(print_job_title_utf16); | 292 FilePath::StringType print_job_title(print_job_title_utf16); |
| 291 #elif defined(OS_POSIX) | 293 #elif defined(OS_POSIX) |
| 292 FilePath::StringType print_job_title = UTF16ToUTF8(print_job_title_utf16); | 294 FilePath::StringType print_job_title = UTF16ToUTF8(print_job_title_utf16); |
| 293 #endif | 295 #endif |
| 294 | 296 |
| 295 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); | 297 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); |
| 296 FilePath default_filename(print_job_title); | 298 FilePath default_filename(print_job_title); |
| 297 default_filename = | 299 default_filename = |
| 298 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); | 300 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
| 299 | 301 |
| 300 SelectFile(default_filename); | 302 SelectFile(default_filename); |
| 301 } else { | 303 } else { |
| 304 g_browser_process->background_printing_manager()->OwnTabContents( |
| 305 preview_tab_wrapper); |
| 306 |
| 302 // The PDF being printed contains only the pages that the user selected, | 307 // The PDF being printed contains only the pages that the user selected, |
| 303 // so ignore the page range and print all pages. | 308 // so ignore the page range and print all pages. |
| 304 settings->Remove(printing::kSettingPageRange, NULL); | 309 settings->Remove(printing::kSettingPageRange, NULL); |
| 305 RenderViewHost* rvh = web_ui_->GetRenderViewHost(); | 310 RenderViewHost* rvh = web_ui_->GetRenderViewHost(); |
| 306 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); | 311 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); |
| 307 } | 312 } |
| 308 } | 313 } |
| 309 | 314 |
| 310 void PrintPreviewHandler::HandleGetPrinterCapabilities( | 315 void PrintPreviewHandler::HandleGetPrinterCapabilities( |
| 311 const ListValue* args) { | 316 const ListValue* args) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 metafile->InitFromData(data.first->memory(), data.second); | 415 metafile->InitFromData(data.first->memory(), data.second); |
| 411 | 416 |
| 412 // Updating last_saved_path_ to the newly selected folder. | 417 // Updating last_saved_path_ to the newly selected folder. |
| 413 *last_saved_path_ = path.DirName(); | 418 *last_saved_path_ = path.DirName(); |
| 414 | 419 |
| 415 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); | 420 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); |
| 416 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); | 421 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
| 417 | 422 |
| 418 ClosePrintPreviewTab(); | 423 ClosePrintPreviewTab(); |
| 419 } | 424 } |
| OLD | NEW |