| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 13 #include "chrome/browser/plugins/chrome_plugin_service_filter.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/ui/webui/print_preview/print_preview_ui.h" | 15 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 16 #include "chrome/common/chrome_content_client.h" | 16 #include "chrome/common/chrome_content_client.h" |
| 17 #include "components/guest_view/browser/guest_view_base.h" |
| 17 #include "components/printing/common/print_messages.h" | 18 #include "components/printing/common/print_messages.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/plugin_service.h" | 20 #include "content/public/browser/plugin_service.h" |
| 20 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/common/webplugininfo.h" | 24 #include "content/public/common/webplugininfo.h" |
| 25 #include "extensions/common/constants.h" |
| 24 #include "printing/features/features.h" | 26 #include "printing/features/features.h" |
| 25 | 27 |
| 26 using content::BrowserThread; | 28 using content::BrowserThread; |
| 27 | 29 |
| 28 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintViewManager); | 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintViewManager); |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 // Keeps track of pending scripted print preview closures. | 34 // Keeps track of pending scripted print preview closures. |
| 33 // No locking, only access on the UI thread. | 35 // No locking, only access on the UI thread. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 DCHECK(!print_preview_rfh_); | 122 DCHECK(!print_preview_rfh_); |
| 121 print_preview_rfh_ = rfh; | 123 print_preview_rfh_ = rfh; |
| 122 print_preview_state_ = USER_INITIATED_PREVIEW; | 124 print_preview_state_ = USER_INITIATED_PREVIEW; |
| 123 return true; | 125 return true; |
| 124 } | 126 } |
| 125 | 127 |
| 126 void PrintViewManager::PrintPreviewForWebNode() { | 128 void PrintViewManager::PrintPreviewForWebNode() { |
| 127 if (print_preview_state_ != NOT_PREVIEWING) | 129 if (print_preview_state_ != NOT_PREVIEWING) |
| 128 return; | 130 return; |
| 129 print_preview_state_ = USER_INITIATED_PREVIEW; | 131 print_preview_state_ = USER_INITIATED_PREVIEW; |
| 132 // If this is a PDF extension loaded inside a MimeHandlerViewGuest then we are |
| 133 // here due to clicking on print button inside the PDF extension. We should |
| 134 // use the main frame of the WebContents for print preview. |
| 135 if (guest_view::GuestViewBase::FromWebContents(web_contents()) && |
| 136 web_contents()->GetLastCommittedURL().host() == |
| 137 extension_misc::kPdfExtensionId) { |
| 138 print_preview_rfh_ = web_contents()->GetMainFrame(); |
| 139 } |
| 130 } | 140 } |
| 131 | 141 |
| 132 void PrintViewManager::PrintPreviewDone() { | 142 void PrintViewManager::PrintPreviewDone() { |
| 133 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 143 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 134 DCHECK_NE(NOT_PREVIEWING, print_preview_state_); | 144 DCHECK_NE(NOT_PREVIEWING, print_preview_state_); |
| 135 | 145 |
| 136 if (print_preview_state_ == SCRIPTED_PREVIEW) { | 146 if (print_preview_state_ == SCRIPTED_PREVIEW) { |
| 137 auto& map = g_scripted_print_preview_closure_map.Get(); | 147 auto& map = g_scripted_print_preview_closure_map.Get(); |
| 138 auto it = map.find(scripted_print_preview_rph_); | 148 auto it = map.find(scripted_print_preview_rph_); |
| 139 CHECK(it != map.end()); | 149 CHECK(it != map.end()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, | 254 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, |
| 245 OnShowScriptedPrintPreview) | 255 OnShowScriptedPrintPreview) |
| 246 IPC_MESSAGE_UNHANDLED(handled = false) | 256 IPC_MESSAGE_UNHANDLED(handled = false) |
| 247 IPC_END_MESSAGE_MAP() | 257 IPC_END_MESSAGE_MAP() |
| 248 | 258 |
| 249 return handled || | 259 return handled || |
| 250 PrintViewManagerBase::OnMessageReceived(message, render_frame_host); | 260 PrintViewManagerBase::OnMessageReceived(message, render_frame_host); |
| 251 } | 261 } |
| 252 | 262 |
| 253 } // namespace printing | 263 } // namespace printing |
| OLD | NEW |