Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: chrome/browser/printing/print_view_manager.cc

Issue 2510753002: Revert of Make printing work better with OOPIF. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
9 8
10 #include "base/bind.h" 9 #include "base/bind.h"
11 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
12 #include "base/memory/ptr_util.h"
13 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 11 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
14 #include "chrome/browser/printing/print_preview_dialog_controller.h" 12 #include "chrome/browser/printing/print_preview_dialog_controller.h"
15 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" 13 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
16 #include "chrome/common/chrome_content_client.h" 14 #include "chrome/common/chrome_content_client.h"
17 #include "components/printing/common/print_messages.h" 15 #include "components/printing/common/print_messages.h"
18 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/plugin_service.h" 17 #include "content/public/browser/plugin_service.h"
20 #include "content/public/browser/render_frame_host.h" 18 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
(...skipping 27 matching lines...) Expand all
50 render_process_id, render_frame_id, GURL(), pdf_plugin); 48 render_process_id, render_frame_id, GURL(), pdf_plugin);
51 } 49 }
52 50
53 } // namespace 51 } // namespace
54 52
55 namespace printing { 53 namespace printing {
56 54
57 PrintViewManager::PrintViewManager(content::WebContents* web_contents) 55 PrintViewManager::PrintViewManager(content::WebContents* web_contents)
58 : PrintViewManagerBase(web_contents), 56 : PrintViewManagerBase(web_contents),
59 print_preview_state_(NOT_PREVIEWING), 57 print_preview_state_(NOT_PREVIEWING),
60 print_preview_rfh_(nullptr),
61 scripted_print_preview_rph_(nullptr) { 58 scripted_print_preview_rph_(nullptr) {
62 if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents)) { 59 if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents)) {
63 EnableInternalPDFPluginForContents( 60 EnableInternalPDFPluginForContents(
64 web_contents->GetRenderProcessHost()->GetID(), 61 web_contents->GetRenderProcessHost()->GetID(),
65 web_contents->GetMainFrame()->GetRoutingID()); 62 web_contents->GetMainFrame()->GetRoutingID());
66 } 63 }
67 } 64 }
68 65
69 PrintViewManager::~PrintViewManager() { 66 PrintViewManager::~PrintViewManager() {
70 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_); 67 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_);
71 } 68 }
72 69
73 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 70 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
74 bool PrintViewManager::PrintForSystemDialogNow( 71 bool PrintViewManager::PrintForSystemDialogNow(
75 const base::Closure& dialog_shown_callback) { 72 const base::Closure& dialog_shown_callback) {
76 DCHECK(!dialog_shown_callback.is_null()); 73 DCHECK(!dialog_shown_callback.is_null());
77 DCHECK(on_print_dialog_shown_callback_.is_null()); 74 DCHECK(on_print_dialog_shown_callback_.is_null());
78 on_print_dialog_shown_callback_ = dialog_shown_callback; 75 on_print_dialog_shown_callback_ = dialog_shown_callback;
79 76 return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id()));
80 SetPrintingRFH(print_preview_rfh_);
81 int32_t id = print_preview_rfh_->GetRoutingID();
82 return PrintNowInternal(print_preview_rfh_,
83 base::MakeUnique<PrintMsg_PrintForSystemDialog>(id));
84 } 77 }
85 78
86 bool PrintViewManager::BasicPrint(content::RenderFrameHost* rfh) { 79 bool PrintViewManager::BasicPrint() {
87 PrintPreviewDialogController* dialog_controller = 80 PrintPreviewDialogController* dialog_controller =
88 PrintPreviewDialogController::GetInstance(); 81 PrintPreviewDialogController::GetInstance();
89 if (!dialog_controller) 82 if (!dialog_controller)
90 return false; 83 return false;
91 84
92 content::WebContents* print_preview_dialog = 85 content::WebContents* print_preview_dialog =
93 dialog_controller->GetPrintPreviewForContents(web_contents()); 86 dialog_controller->GetPrintPreviewForContents(web_contents());
94 if (!print_preview_dialog) 87 if (!print_preview_dialog)
95 return PrintNow(rfh); 88 return PrintNow();
96 89
97 if (!print_preview_dialog->GetWebUI()) 90 if (!print_preview_dialog->GetWebUI())
98 return false; 91 return false;
99 92
100 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 93 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
101 print_preview_dialog->GetWebUI()->GetController()); 94 print_preview_dialog->GetWebUI()->GetController());
102 print_preview_ui->OnShowSystemDialog(); 95 print_preview_ui->OnShowSystemDialog();
103 return true; 96 return true;
104 } 97 }
105 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) 98 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
106 99
107 bool PrintViewManager::PrintPreviewNow(content::RenderFrameHost* rfh, 100 bool PrintViewManager::PrintPreviewNow(bool selection_only) {
108 bool has_selection) {
109 // 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
110 // PrintViewManager's control. Just ignore the extra commands. 102 // PrintViewManager's control. Just ignore the extra commands.
111 // See http://crbug.com/136842 for example. 103 // See http://crbug.com/136842 for example.
112 if (print_preview_state_ != NOT_PREVIEWING) 104 if (print_preview_state_ != NOT_PREVIEWING)
113 return false; 105 return false;
114 106
115 auto message = base::MakeUnique<PrintMsg_InitiatePrintPreview>( 107 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(),
116 rfh->GetRoutingID(), has_selection); 108 selection_only))) {
117 if (!PrintNowInternal(rfh, std::move(message)))
118 return false; 109 return false;
110 }
119 111
120 DCHECK(!print_preview_rfh_);
121 print_preview_rfh_ = rfh;
122 print_preview_state_ = USER_INITIATED_PREVIEW; 112 print_preview_state_ = USER_INITIATED_PREVIEW;
123 return true; 113 return true;
124 } 114 }
125 115
126 void PrintViewManager::PrintPreviewForWebNode() { 116 void PrintViewManager::PrintPreviewForWebNode() {
127 if (print_preview_state_ != NOT_PREVIEWING) 117 if (print_preview_state_ != NOT_PREVIEWING)
128 return; 118 return;
129 print_preview_state_ = USER_INITIATED_PREVIEW; 119 print_preview_state_ = USER_INITIATED_PREVIEW;
130 } 120 }
131 121
132 void PrintViewManager::PrintPreviewDone() { 122 void PrintViewManager::PrintPreviewDone() {
133 DCHECK_CURRENTLY_ON(BrowserThread::UI); 123 DCHECK_CURRENTLY_ON(BrowserThread::UI);
134 DCHECK_NE(NOT_PREVIEWING, print_preview_state_); 124 DCHECK_NE(NOT_PREVIEWING, print_preview_state_);
135 125
136 if (print_preview_state_ == SCRIPTED_PREVIEW) { 126 if (print_preview_state_ == SCRIPTED_PREVIEW) {
137 auto& map = g_scripted_print_preview_closure_map.Get(); 127 auto& map = g_scripted_print_preview_closure_map.Get();
138 auto it = map.find(scripted_print_preview_rph_); 128 auto it = map.find(scripted_print_preview_rph_);
139 CHECK(it != map.end()); 129 CHECK(it != map.end());
140 it->second.Run(); 130 it->second.Run();
141 map.erase(it); 131 map.erase(it);
142 scripted_print_preview_rph_ = nullptr; 132 scripted_print_preview_rph_ = nullptr;
143 } 133 }
144 print_preview_state_ = NOT_PREVIEWING; 134 print_preview_state_ = NOT_PREVIEWING;
145 print_preview_rfh_ = nullptr;
146 } 135 }
147 136
148 void PrintViewManager::RenderFrameCreated( 137 void PrintViewManager::RenderFrameCreated(
149 content::RenderFrameHost* render_frame_host) { 138 content::RenderFrameHost* render_frame_host) {
150 if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents())) { 139 if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents())) {
151 EnableInternalPDFPluginForContents(render_frame_host->GetProcess()->GetID(), 140 EnableInternalPDFPluginForContents(render_frame_host->GetProcess()->GetID(),
152 render_frame_host->GetRoutingID()); 141 render_frame_host->GetRoutingID());
153 } 142 }
154 } 143 }
155 144
156 void PrintViewManager::RenderFrameDeleted( 145 void PrintViewManager::RenderProcessGone(base::TerminationStatus status) {
157 content::RenderFrameHost* render_frame_host) { 146 print_preview_state_ = NOT_PREVIEWING;
158 if (render_frame_host == print_preview_rfh_) 147 PrintViewManagerBase::RenderProcessGone(status);
159 print_preview_state_ = NOT_PREVIEWING;
160 PrintViewManagerBase::RenderFrameDeleted(render_frame_host);
161 } 148 }
162 149
163 void PrintViewManager::OnDidShowPrintDialog(content::RenderFrameHost* rfh) { 150 void PrintViewManager::OnDidShowPrintDialog() {
164 if (rfh != print_preview_rfh_) 151 if (!on_print_dialog_shown_callback_.is_null())
165 return; 152 on_print_dialog_shown_callback_.Run();
166
167 if (on_print_dialog_shown_callback_.is_null())
168 return;
169
170 on_print_dialog_shown_callback_.Run();
171 on_print_dialog_shown_callback_.Reset(); 153 on_print_dialog_shown_callback_.Reset();
172 } 154 }
173 155
174 void PrintViewManager::OnSetupScriptedPrintPreview( 156 void PrintViewManager::OnSetupScriptedPrintPreview(IPC::Message* reply_msg) {
175 content::RenderFrameHost* rfh,
176 IPC::Message* reply_msg) {
177 DCHECK_CURRENTLY_ON(BrowserThread::UI); 157 DCHECK_CURRENTLY_ON(BrowserThread::UI);
178 auto& map = g_scripted_print_preview_closure_map.Get(); 158 auto& map = g_scripted_print_preview_closure_map.Get();
179 content::RenderProcessHost* rph = rfh->GetProcess(); 159 content::RenderProcessHost* rph = web_contents()->GetRenderProcessHost();
180 160
181 if (base::ContainsKey(map, rph)) { 161 if (base::ContainsKey(map, rph)) {
182 // Renderer already handling window.print(). Abort this attempt to prevent 162 // Renderer already handling window.print() in another View.
183 // the renderer from having multiple nested loops. If multiple nested loops 163 Send(reply_msg);
184 // existed, then they have to exit in the right order and that is messy.
185 rfh->Send(reply_msg);
186 return; 164 return;
187 } 165 }
188 166
189 if (print_preview_state_ != NOT_PREVIEWING) { 167 if (print_preview_state_ != NOT_PREVIEWING) {
190 // If a print dialog is already open for this tab, ignore the scripted print 168 // If a user initiated print dialog is already open, ignore the scripted
191 // message. 169 // print message.
192 rfh->Send(reply_msg); 170 DCHECK_EQ(USER_INITIATED_PREVIEW, print_preview_state_);
171 Send(reply_msg);
193 return; 172 return;
194 } 173 }
195 174
196 PrintPreviewDialogController* dialog_controller = 175 PrintPreviewDialogController* dialog_controller =
197 PrintPreviewDialogController::GetInstance(); 176 PrintPreviewDialogController::GetInstance();
198 if (!dialog_controller) { 177 if (!dialog_controller) {
199 rfh->Send(reply_msg); 178 Send(reply_msg);
200 return; 179 return;
201 } 180 }
202 181
203 DCHECK(!print_preview_rfh_);
204 print_preview_rfh_ = rfh;
205 print_preview_state_ = SCRIPTED_PREVIEW; 182 print_preview_state_ = SCRIPTED_PREVIEW;
206 map[rph] = base::Bind(&PrintViewManager::OnScriptedPrintPreviewReply, 183 map[rph] = base::Bind(&PrintViewManager::OnScriptedPrintPreviewReply,
207 base::Unretained(this), reply_msg); 184 base::Unretained(this), reply_msg);
208 scripted_print_preview_rph_ = rph; 185 scripted_print_preview_rph_ = rph;
209 } 186 }
210 187
211 void PrintViewManager::OnShowScriptedPrintPreview(content::RenderFrameHost* rfh, 188 void PrintViewManager::OnShowScriptedPrintPreview(bool source_is_modifiable) {
212 bool source_is_modifiable) {
213 DCHECK(print_preview_rfh_);
214 if (rfh != print_preview_rfh_)
215 return;
216
217 PrintPreviewDialogController* dialog_controller = 189 PrintPreviewDialogController* dialog_controller =
218 PrintPreviewDialogController::GetInstance(); 190 PrintPreviewDialogController::GetInstance();
219 if (!dialog_controller) { 191 if (!dialog_controller) {
220 PrintPreviewDone(); 192 PrintPreviewDone();
221 return; 193 return;
222 } 194 }
223 195
224 dialog_controller->PrintPreview(web_contents()); 196 dialog_controller->PrintPreview(web_contents());
225 PrintHostMsg_RequestPrintPreview_Params params; 197 PrintHostMsg_RequestPrintPreview_Params params;
226 params.is_modifiable = source_is_modifiable; 198 params.is_modifiable = source_is_modifiable;
227 PrintPreviewUI::SetInitialParams( 199 PrintPreviewUI::SetInitialParams(
228 dialog_controller->GetPrintPreviewForContents(web_contents()), params); 200 dialog_controller->GetPrintPreviewForContents(web_contents()), params);
229 } 201 }
230 202
231 void PrintViewManager::OnScriptedPrintPreviewReply(IPC::Message* reply_msg) { 203 void PrintViewManager::OnScriptedPrintPreviewReply(IPC::Message* reply_msg) {
232 DCHECK_CURRENTLY_ON(BrowserThread::UI); 204 DCHECK_CURRENTLY_ON(BrowserThread::UI);
233 print_preview_rfh_->Send(reply_msg); 205 Send(reply_msg);
234 } 206 }
235 207
236 bool PrintViewManager::OnMessageReceived( 208 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) {
237 const IPC::Message& message,
238 content::RenderFrameHost* render_frame_host) {
239 bool handled = true; 209 bool handled = true;
240 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(PrintViewManager, message, render_frame_host) 210 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message)
241 IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog) 211 IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog)
242 IPC_MESSAGE_HANDLER_WITH_PARAM_DELAY_REPLY( 212 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_SetupScriptedPrintPreview,
243 PrintHostMsg_SetupScriptedPrintPreview, OnSetupScriptedPrintPreview) 213 OnSetupScriptedPrintPreview)
244 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, 214 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview,
245 OnShowScriptedPrintPreview) 215 OnShowScriptedPrintPreview)
246 IPC_MESSAGE_UNHANDLED(handled = false) 216 IPC_MESSAGE_UNHANDLED(handled = false)
247 IPC_END_MESSAGE_MAP() 217 IPC_END_MESSAGE_MAP()
248 218
249 return handled || 219 return handled || PrintViewManagerBase::OnMessageReceived(message);
250 PrintViewManagerBase::OnMessageReceived(message, render_frame_host);
251 } 220 }
252 221
253 } // namespace printing 222 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_view_manager.h ('k') | chrome/browser/printing/print_view_manager_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698