| 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/memory/ref_counted.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/platform_util.h" | 19 #include "chrome/browser/platform_util.h" |
| 19 #include "chrome/browser/printing/background_printing_manager.h" | 20 #include "chrome/browser/printing/background_printing_manager.h" |
| 20 #include "chrome/browser/printing/printer_manager_dialog.h" | 21 #include "chrome/browser/printing/printer_manager_dialog.h" |
| 21 #include "chrome/browser/printing/print_preview_tab_controller.h" | 22 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 22 #include "chrome/browser/tabs/tab_strip_model.h" | 23 #include "chrome/browser/tabs/tab_strip_model.h" |
| 23 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 25 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h" | |
| 26 #include "chrome/browser/ui/webui/print_preview_ui.h" | 26 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 27 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/print_messages.h" | 28 #include "chrome/common/print_messages.h" |
| 29 #include "content/browser/browser_thread.h" | 29 #include "content/browser/browser_thread.h" |
| 30 #include "content/browser/renderer_host/render_view_host.h" | 30 #include "content/browser/renderer_host/render_view_host.h" |
| 31 #include "content/browser/tab_contents/tab_contents.h" | 31 #include "content/browser/tab_contents/tab_contents.h" |
| 32 #include "printing/backend/print_backend.h" | 32 #include "printing/backend/print_backend.h" |
| 33 #include "printing/metafile.h" | 33 #include "printing/metafile.h" |
| 34 #include "printing/metafile_impl.h" | 34 #include "printing/metafile_impl.h" |
| 35 #include "printing/print_job_constants.h" | 35 #include "printing/print_job_constants.h" |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 &file_type_info, | 575 &file_type_info, |
| 576 0, | 576 0, |
| 577 FILE_PATH_LITERAL(""), | 577 FILE_PATH_LITERAL(""), |
| 578 preview_tab(), | 578 preview_tab(), |
| 579 platform_util::GetTopLevel(preview_tab()->GetNativeView()), | 579 platform_util::GetTopLevel(preview_tab()->GetNativeView()), |
| 580 NULL); | 580 NULL); |
| 581 } | 581 } |
| 582 | 582 |
| 583 void PrintPreviewHandler::FileSelected(const FilePath& path, | 583 void PrintPreviewHandler::FileSelected(const FilePath& path, |
| 584 int index, void* params) { | 584 int index, void* params) { |
| 585 PrintPreviewUIHTMLSource::PrintPreviewData data; | |
| 586 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 585 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| 587 print_preview_ui->html_source()->GetPrintPreviewData(&data); | 586 scoped_refptr<RefCountedBytes> data(new RefCountedBytes()); |
| 588 if (!data.first || !data.second) { | 587 print_preview_ui->GetPrintPreviewData(&data); |
| 588 if (!data->front() || !data->size()) { |
| 589 NOTREACHED(); | 589 NOTREACHED(); |
| 590 return; | 590 return; |
| 591 } | 591 } |
| 592 | 592 |
| 593 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; | 593 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; |
| 594 metafile->InitFromData(data.first->memory(), data.second); | 594 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); |
| 595 | 595 |
| 596 // Updating last_saved_path_ to the newly selected folder. | 596 // Updating last_saved_path_ to the newly selected folder. |
| 597 *last_saved_path_ = path.DirName(); | 597 *last_saved_path_ = path.DirName(); |
| 598 | 598 |
| 599 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); | 599 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); |
| 600 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); | 600 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
| 601 | 601 |
| 602 ActivateInitiatorTabAndClosePreviewTab(); | 602 ActivateInitiatorTabAndClosePreviewTab(); |
| 603 } | 603 } |
| OLD | NEW |