Chromium Code Reviews| Index: chrome/browser/printing/print_view_manager.cc |
| diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc |
| index c09c632b0608ef9a95c485e372b74a829abbd6b6..1731efb37f33a045c351268f65868500eb26d010 100644 |
| --- a/chrome/browser/printing/print_view_manager.cc |
| +++ b/chrome/browser/printing/print_view_manager.cc |
| @@ -5,9 +5,11 @@ |
| #include "chrome/browser/printing/print_view_manager.h" |
| #include <map> |
| +#include <utility> |
| #include "base/bind.h" |
| #include "base/lazy_instance.h" |
| +#include "base/memory/ptr_util.h" |
| #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| @@ -54,6 +56,8 @@ namespace printing { |
| PrintViewManager::PrintViewManager(content::WebContents* web_contents) |
| : PrintViewManagerBase(web_contents), |
| print_preview_state_(NOT_PREVIEWING), |
| + print_preview_rfh_(nullptr), |
| + scripted_print_rfh_(nullptr), |
| scripted_print_preview_rph_(nullptr) { |
| if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents)) { |
| EnableInternalPDFPluginForContents( |
| @@ -72,10 +76,12 @@ bool PrintViewManager::PrintForSystemDialogNow( |
| DCHECK(!dialog_shown_callback.is_null()); |
| DCHECK(on_print_dialog_shown_callback_.is_null()); |
| on_print_dialog_shown_callback_ = dialog_shown_callback; |
| - return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id())); |
| + |
| + int32_t id = print_preview_rfh_->GetRoutingID(); |
| + return PrintNowInternal(base::MakeUnique<PrintMsg_PrintForSystemDialog>(id)); |
| } |
| -bool PrintViewManager::BasicPrint() { |
| +bool PrintViewManager::BasicPrint(content::RenderFrameHost* rfh) { |
| PrintPreviewDialogController* dialog_controller = |
| PrintPreviewDialogController::GetInstance(); |
| if (!dialog_controller) |
| @@ -84,7 +90,7 @@ bool PrintViewManager::BasicPrint() { |
| content::WebContents* print_preview_dialog = |
| dialog_controller->GetPrintPreviewForContents(web_contents()); |
| if (!print_preview_dialog) |
| - return PrintNow(); |
| + return PrintNow(rfh); |
| if (!print_preview_dialog->GetWebUI()) |
| return false; |
| @@ -96,18 +102,21 @@ bool PrintViewManager::BasicPrint() { |
| } |
| #endif // defined(ENABLE_BASIC_PRINTING) |
| -bool PrintViewManager::PrintPreviewNow(bool selection_only) { |
| +bool PrintViewManager::PrintPreviewNow(content::RenderFrameHost* rfh, |
| + bool has_selection) { |
| // Users can send print commands all they want and it is beyond |
| // PrintViewManager's control. Just ignore the extra commands. |
| // See http://crbug.com/136842 for example. |
| if (print_preview_state_ != NOT_PREVIEWING) |
| return false; |
| - if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(), |
| - selection_only))) { |
| + auto message = base::MakeUnique<PrintMsg_InitiatePrintPreview>( |
| + rfh->GetRoutingID(), has_selection); |
| + if (!PrintNowInternal(std::move(message))) |
| return false; |
| - } |
| + DCHECK(!print_preview_rfh_); |
| + print_preview_rfh_ = rfh; |
| print_preview_state_ = USER_INITIATED_PREVIEW; |
| return true; |
| } |
| @@ -131,6 +140,7 @@ void PrintViewManager::PrintPreviewDone() { |
| scripted_print_preview_rph_ = nullptr; |
| } |
| print_preview_state_ = NOT_PREVIEWING; |
| + print_preview_rfh_ = nullptr; |
| } |
| void PrintViewManager::RenderFrameCreated( |
| @@ -146,13 +156,23 @@ void PrintViewManager::RenderProcessGone(base::TerminationStatus status) { |
| PrintViewManagerBase::RenderProcessGone(status); |
|
nasko
2016/11/02 04:50:37
Isn't that gone from the base object?
Lei Zhang
2016/11/08 11:13:22
The inheritance tree is several levels deep.
nasko
2016/11/08 22:18:35
Acknowledged.
|
| } |
| -void PrintViewManager::OnDidShowPrintDialog() { |
| - if (!on_print_dialog_shown_callback_.is_null()) |
| - on_print_dialog_shown_callback_.Run(); |
| +void PrintViewManager::OnDidShowPrintDialog(content::RenderFrameHost* rfh) { |
| + bool has_callback = !on_print_dialog_shown_callback_.is_null(); |
| + if (!has_callback) |
| + return; |
| + |
| + if (rfh != print_preview_rfh_) |
| + return; |
| + |
| + on_print_dialog_shown_callback_.Run(); |
| on_print_dialog_shown_callback_.Reset(); |
| } |
| void PrintViewManager::OnSetupScriptedPrintPreview(IPC::Message* reply_msg) { |
| + DCHECK(scripted_print_rfh_); |
| + content::RenderFrameHost* rfh = scripted_print_rfh_; |
| + scripted_print_rfh_ = nullptr; |
| + |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| auto& map = g_scripted_print_preview_closure_map.Get(); |
| content::RenderProcessHost* rph = web_contents()->GetRenderProcessHost(); |
| @@ -178,13 +198,20 @@ void PrintViewManager::OnSetupScriptedPrintPreview(IPC::Message* reply_msg) { |
| return; |
| } |
| + DCHECK(!print_preview_rfh_); |
| + print_preview_rfh_ = rfh; |
| print_preview_state_ = SCRIPTED_PREVIEW; |
| map[rph] = base::Bind(&PrintViewManager::OnScriptedPrintPreviewReply, |
| base::Unretained(this), reply_msg); |
| scripted_print_preview_rph_ = rph; |
| } |
| -void PrintViewManager::OnShowScriptedPrintPreview(bool source_is_modifiable) { |
| +void PrintViewManager::OnShowScriptedPrintPreview(content::RenderFrameHost* rfh, |
| + bool source_is_modifiable) { |
| + DCHECK(print_preview_rfh_); |
| + if (rfh != print_preview_rfh_) |
| + return; |
| + |
| PrintPreviewDialogController* dialog_controller = |
| PrintPreviewDialogController::GetInstance(); |
| if (!dialog_controller) { |
| @@ -204,9 +231,16 @@ void PrintViewManager::OnScriptedPrintPreviewReply(IPC::Message* reply_msg) { |
| Send(reply_msg); |
| } |
| -bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { |
| +bool PrintViewManager::OnMessageReceived( |
| + const IPC::Message& message, |
| + content::RenderFrameHost* render_frame_host) { |
| + if (message.type() == PrintHostMsg_SetupScriptedPrintPreview::ID) { |
| + DCHECK(!scripted_print_rfh_); |
| + scripted_print_rfh_ = render_frame_host; |
|
nasko
2016/11/02 04:50:37
Is this just a hack to "pass" the RFH as parameter
Lei Zhang
2016/11/08 11:13:22
Yes. IPC_MESSAGE_HANDLER_DELAY_REPLY doesn't seem
nasko
2016/11/08 22:18:35
That macro is a wrapper for IPC_MESSAGE_FORWARD_DE
Lei Zhang
2016/11/11 21:06:48
I ventured into ipc/ land and came back with a new
|
| + } |
| + |
| bool handled = true; |
| - IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) |
| + IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(PrintViewManager, message, render_frame_host) |
| IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog) |
| IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_SetupScriptedPrintPreview, |
| OnSetupScriptedPrintPreview) |
| @@ -215,7 +249,8 @@ bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| - return handled || PrintViewManagerBase::OnMessageReceived(message); |
| + return handled || |
| + PrintViewManagerBase::OnMessageReceived(message, render_frame_host); |
| } |
| } // namespace printing |