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 <ctype.h> | 7 #include <ctype.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 #include "printing/page_size_margins.h" | 50 #include "printing/page_size_margins.h" |
51 #include "printing/print_settings.h" | 51 #include "printing/print_settings.h" |
52 #include "unicode/ulocdata.h" | 52 #include "unicode/ulocdata.h" |
53 | 53 |
54 #if !defined(OS_CHROMEOS) | 54 #if !defined(OS_CHROMEOS) |
55 #include "base/command_line.h" | 55 #include "base/command_line.h" |
56 #include "chrome/common/chrome_switches.h" | 56 #include "chrome/common/chrome_switches.h" |
57 #endif | 57 #endif |
58 | 58 |
59 using content::BrowserThread; | 59 using content::BrowserThread; |
| 60 using printing::Metafile; |
60 | 61 |
61 namespace { | 62 namespace { |
62 | 63 |
63 enum UserActionBuckets { | 64 enum UserActionBuckets { |
64 PRINT_TO_PRINTER, | 65 PRINT_TO_PRINTER, |
65 PRINT_TO_PDF, | 66 PRINT_TO_PDF, |
66 CANCEL, | 67 CANCEL, |
67 FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, | 68 FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, |
68 PREVIEW_FAILED, | 69 PREVIEW_FAILED, |
69 PREVIEW_STARTED, | 70 PREVIEW_STARTED, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 if (settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode)) | 167 if (settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode)) |
167 ReportPrintSettingHistogram(duplex_mode ? DUPLEX : SIMPLEX); | 168 ReportPrintSettingHistogram(duplex_mode ? DUPLEX : SIMPLEX); |
168 | 169 |
169 int color_mode; | 170 int color_mode; |
170 if (settings.GetInteger(printing::kSettingColor, &color_mode)) { | 171 if (settings.GetInteger(printing::kSettingColor, &color_mode)) { |
171 ReportPrintSettingHistogram( | 172 ReportPrintSettingHistogram( |
172 printing::isColorModelSelected(color_mode) ? COLOR : BLACK_AND_WHITE); | 173 printing::isColorModelSelected(color_mode) ? COLOR : BLACK_AND_WHITE); |
173 } | 174 } |
174 } | 175 } |
175 | 176 |
| 177 // Callback that stores a PDF file on disk. |
| 178 void PrintToPdfCallback(Metafile* metafile, const FilePath& path) { |
| 179 metafile->SaveTo(path); |
| 180 // |metafile| must be deleted on the UI thread. |
| 181 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 182 base::Bind(&DeletePointer<Metafile>, metafile)); |
| 183 } |
| 184 |
176 } // namespace | 185 } // namespace |
177 | 186 |
178 // Callback that stores a PDF file on disk. | |
179 void PrintToPdfCallback(printing::Metafile* metafile, const FilePath& path) { | |
180 metafile->SaveTo(path); | |
181 } | |
182 | |
183 // static | 187 // static |
184 FilePath* PrintPreviewHandler::last_saved_path_ = NULL; | 188 FilePath* PrintPreviewHandler::last_saved_path_ = NULL; |
185 std::string* PrintPreviewHandler::last_used_printer_cloud_print_data_ = NULL; | 189 std::string* PrintPreviewHandler::last_used_printer_cloud_print_data_ = NULL; |
186 std::string* PrintPreviewHandler::last_used_printer_name_ = NULL; | 190 std::string* PrintPreviewHandler::last_used_printer_name_ = NULL; |
187 printing::ColorModels PrintPreviewHandler::last_used_color_model_ = | 191 printing::ColorModels PrintPreviewHandler::last_used_color_model_ = |
188 printing::UNKNOWN_COLOR_MODEL; | 192 printing::UNKNOWN_COLOR_MODEL; |
189 printing::MarginType PrintPreviewHandler::last_used_margins_type_ = | 193 printing::MarginType PrintPreviewHandler::last_used_margins_type_ = |
190 printing::DEFAULT_MARGINS; | 194 printing::DEFAULT_MARGINS; |
191 printing::PageSizeMargins* | 195 printing::PageSizeMargins* |
192 PrintPreviewHandler::last_used_page_size_margins_ = NULL; | 196 PrintPreviewHandler::last_used_page_size_margins_ = NULL; |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 } | 811 } |
808 | 812 |
809 void PrintPreviewHandler::PostPrintToPdfTask() { | 813 void PrintPreviewHandler::PostPrintToPdfTask() { |
810 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 814 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
811 scoped_refptr<RefCountedBytes> data; | 815 scoped_refptr<RefCountedBytes> data; |
812 print_preview_ui->GetPrintPreviewDataForIndex( | 816 print_preview_ui->GetPrintPreviewDataForIndex( |
813 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 817 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
814 DCHECK(data.get()); | 818 DCHECK(data.get()); |
815 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; | 819 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; |
816 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); | 820 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); |
| 821 // PrintToPdfCallback takes ownership of |metafile|. |
817 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 822 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
818 base::Bind(&PrintToPdfCallback, base::Owned(metafile), | 823 base::Bind(&PrintToPdfCallback, metafile, |
819 *print_to_pdf_path_)); | 824 *print_to_pdf_path_)); |
820 print_to_pdf_path_.reset(); | 825 print_to_pdf_path_.reset(); |
821 ActivateInitiatorTabAndClosePreviewTab(); | 826 ActivateInitiatorTabAndClosePreviewTab(); |
822 } | 827 } |
823 | 828 |
824 void PrintPreviewHandler::FileSelectionCanceled(void* params) { | 829 void PrintPreviewHandler::FileSelectionCanceled(void* params) { |
825 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 830 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
826 print_preview_ui->OnFileSelectionCancelled(); | 831 print_preview_ui->OnFileSelectionCancelled(); |
827 } | 832 } |
828 | 833 |
829 void PrintPreviewHandler::ClearInitiatorTabDetails() { | 834 void PrintPreviewHandler::ClearInitiatorTabDetails() { |
830 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 835 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
831 if (!initiator_tab) | 836 if (!initiator_tab) |
832 return; | 837 return; |
833 | 838 |
834 // We no longer require the initiator tab details. Remove those details | 839 // We no longer require the initiator tab details. Remove those details |
835 // associated with the preview tab to allow the initiator tab to create | 840 // associated with the preview tab to allow the initiator tab to create |
836 // another preview tab. | 841 // another preview tab. |
837 printing::PrintPreviewTabController* tab_controller = | 842 printing::PrintPreviewTabController* tab_controller = |
838 printing::PrintPreviewTabController::GetInstance(); | 843 printing::PrintPreviewTabController::GetInstance(); |
839 if (tab_controller) | 844 if (tab_controller) |
840 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 845 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
841 } | 846 } |
OLD | NEW |