| 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/plugins/chrome_plugin_service_filter.h" |
| 13 #include "chrome/browser/printing/print_job_manager.h" | 14 #include "chrome/browser/printing/print_job_manager.h" |
| 14 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 15 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| 15 #include "chrome/browser/printing/print_view_manager_observer.h" | 16 #include "chrome/browser/printing/print_view_manager_observer.h" |
| 16 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 17 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 18 #include "chrome/common/chrome_content_client.h" |
| 17 #include "components/printing/common/print_messages.h" | 19 #include "components/printing/common/print_messages.h" |
| 18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/plugin_service.h" |
| 22 #include "content/public/browser/render_frame_host.h" |
| 23 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/common/webplugininfo.h" |
| 20 | 26 |
| 21 using content::BrowserThread; | 27 using content::BrowserThread; |
| 22 | 28 |
| 23 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintViewManager); | 29 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintViewManager); |
| 24 | 30 |
| 25 namespace { | 31 namespace { |
| 26 | 32 |
| 27 // Keeps track of pending scripted print preview closures. | 33 // Keeps track of pending scripted print preview closures. |
| 28 // No locking, only access on the UI thread. | 34 // No locking, only access on the UI thread. |
| 29 typedef std::map<content::RenderProcessHost*, base::Closure> | 35 typedef std::map<content::RenderProcessHost*, base::Closure> |
| 30 ScriptedPrintPreviewClosureMap; | 36 ScriptedPrintPreviewClosureMap; |
| 31 static base::LazyInstance<ScriptedPrintPreviewClosureMap> | 37 static base::LazyInstance<ScriptedPrintPreviewClosureMap> |
| 32 g_scripted_print_preview_closure_map = LAZY_INSTANCE_INITIALIZER; | 38 g_scripted_print_preview_closure_map = LAZY_INSTANCE_INITIALIZER; |
| 33 | 39 |
| 40 void EnableInternalPDFPluginForContents(int render_process_id, |
| 41 int render_frame_id) { |
| 42 // Always enable the internal PDF plugin for the print preview page. |
| 43 base::FilePath pdf_plugin_path = base::FilePath::FromUTF8Unsafe( |
| 44 ChromeContentClient::kPDFPluginPath); |
| 45 |
| 46 content::WebPluginInfo pdf_plugin; |
| 47 if (!content::PluginService::GetInstance()->GetPluginInfoByPath( |
| 48 pdf_plugin_path, &pdf_plugin)) { |
| 49 return; |
| 50 } |
| 51 |
| 52 ChromePluginServiceFilter::GetInstance()->OverridePluginForFrame( |
| 53 render_process_id, render_frame_id, GURL(), pdf_plugin); |
| 54 } |
| 55 |
| 34 } // namespace | 56 } // namespace |
| 35 | 57 |
| 36 namespace printing { | 58 namespace printing { |
| 37 | 59 |
| 38 PrintViewManager::PrintViewManager(content::WebContents* web_contents) | 60 PrintViewManager::PrintViewManager(content::WebContents* web_contents) |
| 39 : PrintViewManagerBase(web_contents), | 61 : PrintViewManagerBase(web_contents), |
| 40 observer_(NULL), | 62 observer_(NULL), |
| 41 print_preview_state_(NOT_PREVIEWING), | 63 print_preview_state_(NOT_PREVIEWING), |
| 42 scripted_print_preview_rph_(NULL) { | 64 scripted_print_preview_rph_(NULL) { |
| 65 if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents)) { |
| 66 EnableInternalPDFPluginForContents( |
| 67 web_contents->GetRenderProcessHost()->GetID(), |
| 68 web_contents->GetMainFrame()->GetRoutingID()); |
| 69 } |
| 43 } | 70 } |
| 44 | 71 |
| 45 PrintViewManager::~PrintViewManager() { | 72 PrintViewManager::~PrintViewManager() { |
| 46 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_); | 73 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_); |
| 47 } | 74 } |
| 48 | 75 |
| 49 #if defined(ENABLE_BASIC_PRINTING) | 76 #if defined(ENABLE_BASIC_PRINTING) |
| 50 bool PrintViewManager::PrintForSystemDialogNow() { | 77 bool PrintViewManager::PrintForSystemDialogNow() { |
| 51 return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id())); | 78 return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id())); |
| 52 } | 79 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 63 return false; | 90 return false; |
| 64 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 91 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 65 print_preview_dialog->GetWebUI()->GetController()); | 92 print_preview_dialog->GetWebUI()->GetController()); |
| 66 print_preview_ui->OnShowSystemDialog(); | 93 print_preview_ui->OnShowSystemDialog(); |
| 67 return true; | 94 return true; |
| 68 } else { | 95 } else { |
| 69 return PrintNow(); | 96 return PrintNow(); |
| 70 } | 97 } |
| 71 } | 98 } |
| 72 #endif // ENABLE_BASIC_PRINTING | 99 #endif // ENABLE_BASIC_PRINTING |
| 100 |
| 73 bool PrintViewManager::PrintPreviewNow(bool selection_only) { | 101 bool PrintViewManager::PrintPreviewNow(bool selection_only) { |
| 74 // Users can send print commands all they want and it is beyond | 102 // Users can send print commands all they want and it is beyond |
| 75 // PrintViewManager's control. Just ignore the extra commands. | 103 // PrintViewManager's control. Just ignore the extra commands. |
| 76 // See http://crbug.com/136842 for example. | 104 // See http://crbug.com/136842 for example. |
| 77 if (print_preview_state_ != NOT_PREVIEWING) | 105 if (print_preview_state_ != NOT_PREVIEWING) |
| 78 return false; | 106 return false; |
| 79 | 107 |
| 80 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(), | 108 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(), |
| 81 selection_only))) { | 109 selection_only))) { |
| 82 return false; | 110 return false; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 107 scripted_print_preview_rph_ = NULL; | 135 scripted_print_preview_rph_ = NULL; |
| 108 } | 136 } |
| 109 print_preview_state_ = NOT_PREVIEWING; | 137 print_preview_state_ = NOT_PREVIEWING; |
| 110 } | 138 } |
| 111 | 139 |
| 112 void PrintViewManager::set_observer(PrintViewManagerObserver* observer) { | 140 void PrintViewManager::set_observer(PrintViewManagerObserver* observer) { |
| 113 DCHECK(!observer || !observer_); | 141 DCHECK(!observer || !observer_); |
| 114 observer_ = observer; | 142 observer_ = observer; |
| 115 } | 143 } |
| 116 | 144 |
| 145 void PrintViewManager::RenderFrameCreated( |
| 146 content::RenderFrameHost* render_frame_host) { |
| 147 if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents())) { |
| 148 EnableInternalPDFPluginForContents(render_frame_host->GetProcess()->GetID(), |
| 149 render_frame_host->GetRoutingID()); |
| 150 } |
| 151 } |
| 152 |
| 117 void PrintViewManager::RenderProcessGone(base::TerminationStatus status) { | 153 void PrintViewManager::RenderProcessGone(base::TerminationStatus status) { |
| 118 print_preview_state_ = NOT_PREVIEWING; | 154 print_preview_state_ = NOT_PREVIEWING; |
| 119 PrintViewManagerBase::RenderProcessGone(status); | 155 PrintViewManagerBase::RenderProcessGone(status); |
| 120 } | 156 } |
| 121 | 157 |
| 122 void PrintViewManager::OnDidShowPrintDialog() { | 158 void PrintViewManager::OnDidShowPrintDialog() { |
| 123 if (observer_) | 159 if (observer_) |
| 124 observer_->OnPrintDialogShown(); | 160 observer_->OnPrintDialogShown(); |
| 125 } | 161 } |
| 126 | 162 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 OnSetupScriptedPrintPreview) | 223 OnSetupScriptedPrintPreview) |
| 188 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, | 224 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, |
| 189 OnShowScriptedPrintPreview) | 225 OnShowScriptedPrintPreview) |
| 190 IPC_MESSAGE_UNHANDLED(handled = false) | 226 IPC_MESSAGE_UNHANDLED(handled = false) |
| 191 IPC_END_MESSAGE_MAP() | 227 IPC_END_MESSAGE_MAP() |
| 192 | 228 |
| 193 return handled ? true : PrintViewManagerBase::OnMessageReceived(message); | 229 return handled ? true : PrintViewManagerBase::OnMessageReceived(message); |
| 194 } | 230 } |
| 195 | 231 |
| 196 } // namespace printing | 232 } // namespace printing |
| OLD | NEW |