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 "chrome/browser/plugins/chrome_plugin_service_filter.h" | 11 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
12 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 12 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
13 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 13 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
14 #include "chrome/common/chrome_content_client.h" | 14 #include "chrome/common/chrome_content_client.h" |
15 #include "components/printing/common/print_messages.h" | 15 #include "components/printing/common/print_messages.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/plugin_service.h" | 17 #include "content/public/browser/plugin_service.h" |
18 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
19 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/webplugininfo.h" | 21 #include "content/public/common/webplugininfo.h" |
| 22 #include "printing/features/features.h" |
22 | 23 |
23 using content::BrowserThread; | 24 using content::BrowserThread; |
24 | 25 |
25 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintViewManager); | 26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintViewManager); |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // Keeps track of pending scripted print preview closures. | 30 // Keeps track of pending scripted print preview closures. |
30 // No locking, only access on the UI thread. | 31 // No locking, only access on the UI thread. |
31 base::LazyInstance<std::map<content::RenderProcessHost*, base::Closure>> | 32 base::LazyInstance<std::map<content::RenderProcessHost*, base::Closure>> |
(...skipping 27 matching lines...) Expand all Loading... |
59 EnableInternalPDFPluginForContents( | 60 EnableInternalPDFPluginForContents( |
60 web_contents->GetRenderProcessHost()->GetID(), | 61 web_contents->GetRenderProcessHost()->GetID(), |
61 web_contents->GetMainFrame()->GetRoutingID()); | 62 web_contents->GetMainFrame()->GetRoutingID()); |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 PrintViewManager::~PrintViewManager() { | 66 PrintViewManager::~PrintViewManager() { |
66 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_); | 67 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_); |
67 } | 68 } |
68 | 69 |
69 #if defined(ENABLE_BASIC_PRINTING) | 70 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
70 bool PrintViewManager::PrintForSystemDialogNow( | 71 bool PrintViewManager::PrintForSystemDialogNow( |
71 const base::Closure& dialog_shown_callback) { | 72 const base::Closure& dialog_shown_callback) { |
72 DCHECK(!dialog_shown_callback.is_null()); | 73 DCHECK(!dialog_shown_callback.is_null()); |
73 DCHECK(on_print_dialog_shown_callback_.is_null()); | 74 DCHECK(on_print_dialog_shown_callback_.is_null()); |
74 on_print_dialog_shown_callback_ = dialog_shown_callback; | 75 on_print_dialog_shown_callback_ = dialog_shown_callback; |
75 return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id())); | 76 return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id())); |
76 } | 77 } |
77 | 78 |
78 bool PrintViewManager::BasicPrint() { | 79 bool PrintViewManager::BasicPrint() { |
79 PrintPreviewDialogController* dialog_controller = | 80 PrintPreviewDialogController* dialog_controller = |
80 PrintPreviewDialogController::GetInstance(); | 81 PrintPreviewDialogController::GetInstance(); |
81 if (!dialog_controller) | 82 if (!dialog_controller) |
82 return false; | 83 return false; |
83 | 84 |
84 content::WebContents* print_preview_dialog = | 85 content::WebContents* print_preview_dialog = |
85 dialog_controller->GetPrintPreviewForContents(web_contents()); | 86 dialog_controller->GetPrintPreviewForContents(web_contents()); |
86 if (!print_preview_dialog) | 87 if (!print_preview_dialog) |
87 return PrintNow(); | 88 return PrintNow(); |
88 | 89 |
89 if (!print_preview_dialog->GetWebUI()) | 90 if (!print_preview_dialog->GetWebUI()) |
90 return false; | 91 return false; |
91 | 92 |
92 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 93 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
93 print_preview_dialog->GetWebUI()->GetController()); | 94 print_preview_dialog->GetWebUI()->GetController()); |
94 print_preview_ui->OnShowSystemDialog(); | 95 print_preview_ui->OnShowSystemDialog(); |
95 return true; | 96 return true; |
96 } | 97 } |
97 #endif // defined(ENABLE_BASIC_PRINTING) | 98 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
98 | 99 |
99 bool PrintViewManager::PrintPreviewNow(bool selection_only) { | 100 bool PrintViewManager::PrintPreviewNow(bool selection_only) { |
100 // Users can send print commands all they want and it is beyond | 101 // Users can send print commands all they want and it is beyond |
101 // PrintViewManager's control. Just ignore the extra commands. | 102 // PrintViewManager's control. Just ignore the extra commands. |
102 // See http://crbug.com/136842 for example. | 103 // See http://crbug.com/136842 for example. |
103 if (print_preview_state_ != NOT_PREVIEWING) | 104 if (print_preview_state_ != NOT_PREVIEWING) |
104 return false; | 105 return false; |
105 | 106 |
106 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(), | 107 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(), |
107 selection_only))) { | 108 selection_only))) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 OnSetupScriptedPrintPreview) | 213 OnSetupScriptedPrintPreview) |
213 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, | 214 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, |
214 OnShowScriptedPrintPreview) | 215 OnShowScriptedPrintPreview) |
215 IPC_MESSAGE_UNHANDLED(handled = false) | 216 IPC_MESSAGE_UNHANDLED(handled = false) |
216 IPC_END_MESSAGE_MAP() | 217 IPC_END_MESSAGE_MAP() |
217 | 218 |
218 return handled || PrintViewManagerBase::OnMessageReceived(message); | 219 return handled || PrintViewManagerBase::OnMessageReceived(message); |
219 } | 220 } |
220 | 221 |
221 } // namespace printing | 222 } // namespace printing |
OLD | NEW |