Chromium Code Reviews| 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)) | |
|
raymes
2015/03/19 02:14:33
nit: add {}
Lei Zhang
2015/03/19 02:20:08
Done.
| |
| 49 return; | |
| 50 | |
| 51 ChromePluginServiceFilter::GetInstance()->OverridePluginForFrame( | |
| 52 render_process_id, render_frame_id, GURL(), pdf_plugin); | |
| 53 } | |
| 54 | |
| 34 } // namespace | 55 } // namespace |
| 35 | 56 |
| 36 namespace printing { | 57 namespace printing { |
| 37 | 58 |
| 38 PrintViewManager::PrintViewManager(content::WebContents* web_contents) | 59 PrintViewManager::PrintViewManager(content::WebContents* web_contents) |
| 39 : PrintViewManagerBase(web_contents), | 60 : PrintViewManagerBase(web_contents), |
| 40 observer_(NULL), | 61 observer_(NULL), |
| 41 print_preview_state_(NOT_PREVIEWING), | 62 print_preview_state_(NOT_PREVIEWING), |
| 42 scripted_print_preview_rph_(NULL) { | 63 scripted_print_preview_rph_(NULL) { |
| 64 if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents)) { | |
| 65 EnableInternalPDFPluginForContents( | |
| 66 web_contents->GetRenderProcessHost()->GetID(), | |
| 67 web_contents->GetMainFrame()->GetRoutingID()); | |
| 68 } | |
| 43 } | 69 } |
| 44 | 70 |
| 45 PrintViewManager::~PrintViewManager() { | 71 PrintViewManager::~PrintViewManager() { |
| 46 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_); | 72 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_); |
| 47 } | 73 } |
| 48 | 74 |
| 49 #if defined(ENABLE_BASIC_PRINTING) | 75 #if defined(ENABLE_BASIC_PRINTING) |
| 50 bool PrintViewManager::PrintForSystemDialogNow() { | 76 bool PrintViewManager::PrintForSystemDialogNow() { |
| 51 return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id())); | 77 return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id())); |
| 52 } | 78 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 63 return false; | 89 return false; |
| 64 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 90 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 65 print_preview_dialog->GetWebUI()->GetController()); | 91 print_preview_dialog->GetWebUI()->GetController()); |
| 66 print_preview_ui->OnShowSystemDialog(); | 92 print_preview_ui->OnShowSystemDialog(); |
| 67 return true; | 93 return true; |
| 68 } else { | 94 } else { |
| 69 return PrintNow(); | 95 return PrintNow(); |
| 70 } | 96 } |
| 71 } | 97 } |
| 72 #endif // ENABLE_BASIC_PRINTING | 98 #endif // ENABLE_BASIC_PRINTING |
| 99 | |
| 73 bool PrintViewManager::PrintPreviewNow(bool selection_only) { | 100 bool PrintViewManager::PrintPreviewNow(bool selection_only) { |
| 74 // 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 |
| 75 // PrintViewManager's control. Just ignore the extra commands. | 102 // PrintViewManager's control. Just ignore the extra commands. |
| 76 // See http://crbug.com/136842 for example. | 103 // See http://crbug.com/136842 for example. |
| 77 if (print_preview_state_ != NOT_PREVIEWING) | 104 if (print_preview_state_ != NOT_PREVIEWING) |
| 78 return false; | 105 return false; |
| 79 | 106 |
| 80 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(), | 107 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(), |
| 81 selection_only))) { | 108 selection_only))) { |
| 82 return false; | 109 return false; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 107 scripted_print_preview_rph_ = NULL; | 134 scripted_print_preview_rph_ = NULL; |
| 108 } | 135 } |
| 109 print_preview_state_ = NOT_PREVIEWING; | 136 print_preview_state_ = NOT_PREVIEWING; |
| 110 } | 137 } |
| 111 | 138 |
| 112 void PrintViewManager::set_observer(PrintViewManagerObserver* observer) { | 139 void PrintViewManager::set_observer(PrintViewManagerObserver* observer) { |
| 113 DCHECK(!observer || !observer_); | 140 DCHECK(!observer || !observer_); |
| 114 observer_ = observer; | 141 observer_ = observer; |
| 115 } | 142 } |
| 116 | 143 |
| 144 void PrintViewManager::RenderFrameCreated( | |
| 145 content::RenderFrameHost* render_frame_host) { | |
| 146 if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents())) { | |
| 147 EnableInternalPDFPluginForContents(render_frame_host->GetProcess()->GetID(), | |
| 148 render_frame_host->GetRoutingID()); | |
| 149 } | |
| 150 } | |
| 151 | |
| 117 void PrintViewManager::RenderProcessGone(base::TerminationStatus status) { | 152 void PrintViewManager::RenderProcessGone(base::TerminationStatus status) { |
| 118 print_preview_state_ = NOT_PREVIEWING; | 153 print_preview_state_ = NOT_PREVIEWING; |
| 119 PrintViewManagerBase::RenderProcessGone(status); | 154 PrintViewManagerBase::RenderProcessGone(status); |
| 120 } | 155 } |
| 121 | 156 |
| 122 void PrintViewManager::OnDidShowPrintDialog() { | 157 void PrintViewManager::OnDidShowPrintDialog() { |
| 123 if (observer_) | 158 if (observer_) |
| 124 observer_->OnPrintDialogShown(); | 159 observer_->OnPrintDialogShown(); |
| 125 } | 160 } |
| 126 | 161 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 OnSetupScriptedPrintPreview) | 222 OnSetupScriptedPrintPreview) |
| 188 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, | 223 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, |
| 189 OnShowScriptedPrintPreview) | 224 OnShowScriptedPrintPreview) |
| 190 IPC_MESSAGE_UNHANDLED(handled = false) | 225 IPC_MESSAGE_UNHANDLED(handled = false) |
| 191 IPC_END_MESSAGE_MAP() | 226 IPC_END_MESSAGE_MAP() |
| 192 | 227 |
| 193 return handled ? true : PrintViewManagerBase::OnMessageReceived(message); | 228 return handled ? true : PrintViewManagerBase::OnMessageReceived(message); |
| 194 } | 229 } |
| 195 | 230 |
| 196 } // namespace printing | 231 } // namespace printing |
| OLD | NEW |