| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/printing/print_view_manager.h" | 5 #include "chrome/browser/printing/print_view_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/printing/print_job_manager.h" | 13 #include "chrome/browser/printing/print_job_manager.h" |
| 14 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 14 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| 15 #include "chrome/browser/printing/print_view_manager_observer.h" | 15 #include "chrome/browser/printing/print_view_manager_observer.h" |
| 16 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 16 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 17 #include "chrome/common/print_messages.h" | 17 #include "chrome/common/print_messages.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "printing/print_destination_interface.h" | |
| 21 | 20 |
| 22 using content::BrowserThread; | 21 using content::BrowserThread; |
| 23 | 22 |
| 24 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintViewManager); | 23 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintViewManager); |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| 27 | 26 |
| 28 // Keeps track of pending scripted print preview closures. | 27 // Keeps track of pending scripted print preview closures. |
| 29 // No locking, only access on the UI thread. | 28 // No locking, only access on the UI thread. |
| 30 typedef std::map<content::RenderProcessHost*, base::Closure> | 29 typedef std::map<content::RenderProcessHost*, base::Closure> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 return false; | 65 return false; |
| 67 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 66 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 68 print_preview_dialog->GetWebUI()->GetController()); | 67 print_preview_dialog->GetWebUI()->GetController()); |
| 69 print_preview_ui->OnShowSystemDialog(); | 68 print_preview_ui->OnShowSystemDialog(); |
| 70 return true; | 69 return true; |
| 71 } else { | 70 } else { |
| 72 return PrintNow(); | 71 return PrintNow(); |
| 73 } | 72 } |
| 74 } | 73 } |
| 75 | 74 |
| 76 bool PrintViewManager::PrintToDestination() { | |
| 77 // TODO(mad): Remove this once we can send user metrics from the metro driver. | |
| 78 // crbug.com/142330 | |
| 79 UMA_HISTOGRAM_ENUMERATION("Metro.Print", 0, 2); | |
| 80 // TODO(mad): Use a passed in destination interface instead. | |
| 81 g_browser_process->print_job_manager()->queue()->SetDestination( | |
| 82 printing::CreatePrintDestination()); | |
| 83 return PrintNowInternal(new PrintMsg_PrintPages(routing_id())); | |
| 84 } | |
| 85 | |
| 86 bool PrintViewManager::PrintPreviewNow(bool selection_only) { | 75 bool PrintViewManager::PrintPreviewNow(bool selection_only) { |
| 87 // Users can send print commands all they want and it is beyond | 76 // Users can send print commands all they want and it is beyond |
| 88 // PrintViewManager's control. Just ignore the extra commands. | 77 // PrintViewManager's control. Just ignore the extra commands. |
| 89 // See http://crbug.com/136842 for example. | 78 // See http://crbug.com/136842 for example. |
| 90 if (print_preview_state_ != NOT_PREVIEWING) | 79 if (print_preview_state_ != NOT_PREVIEWING) |
| 91 return false; | 80 return false; |
| 92 | 81 |
| 93 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(), | 82 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(), |
| 94 selection_only))) { | 83 selection_only))) { |
| 95 return false; | 84 return false; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 OnSetupScriptedPrintPreview) | 189 OnSetupScriptedPrintPreview) |
| 201 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, | 190 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, |
| 202 OnShowScriptedPrintPreview) | 191 OnShowScriptedPrintPreview) |
| 203 IPC_MESSAGE_UNHANDLED(handled = false) | 192 IPC_MESSAGE_UNHANDLED(handled = false) |
| 204 IPC_END_MESSAGE_MAP() | 193 IPC_END_MESSAGE_MAP() |
| 205 | 194 |
| 206 return handled ? true : PrintViewManagerBase::OnMessageReceived(message); | 195 return handled ? true : PrintViewManagerBase::OnMessageReceived(message); |
| 207 } | 196 } |
| 208 | 197 |
| 209 } // namespace printing | 198 } // namespace printing |
| OLD | NEW |