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

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

Issue 2496203003: Add printing tests to ensure window.print() works for subframes.
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> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 ChromePluginServiceFilter::GetInstance()->OverridePluginForFrame( 49 ChromePluginServiceFilter::GetInstance()->OverridePluginForFrame(
50 render_process_id, render_frame_id, GURL(), pdf_plugin); 50 render_process_id, render_frame_id, GURL(), pdf_plugin);
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 namespace printing { 55 namespace printing {
56 56
57 bool PrintViewManager::TestDelegate::ScriptedPrint(
58 const content::RenderFrameHost* render_frame_host) {
59 return true;
60 }
61
57 PrintViewManager::PrintViewManager(content::WebContents* web_contents) 62 PrintViewManager::PrintViewManager(content::WebContents* web_contents)
58 : PrintViewManagerBase(web_contents), 63 : PrintViewManagerBase(web_contents) {
59 print_preview_state_(NOT_PREVIEWING),
60 print_preview_rfh_(nullptr),
61 scripted_print_preview_rph_(nullptr) {
62 if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents)) { 64 if (PrintPreviewDialogController::IsPrintPreviewDialog(web_contents)) {
63 EnableInternalPDFPluginForContents( 65 EnableInternalPDFPluginForContents(
64 web_contents->GetRenderProcessHost()->GetID(), 66 web_contents->GetRenderProcessHost()->GetID(),
65 web_contents->GetMainFrame()->GetRoutingID()); 67 web_contents->GetMainFrame()->GetRoutingID());
66 } 68 }
67 } 69 }
68 70
69 PrintViewManager::~PrintViewManager() { 71 PrintViewManager::~PrintViewManager() {
70 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_); 72 DCHECK_EQ(NOT_PREVIEWING, print_preview_state_);
71 } 73 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return; 195 return;
194 } 196 }
195 197
196 PrintPreviewDialogController* dialog_controller = 198 PrintPreviewDialogController* dialog_controller =
197 PrintPreviewDialogController::GetInstance(); 199 PrintPreviewDialogController::GetInstance();
198 if (!dialog_controller) { 200 if (!dialog_controller) {
199 rfh->Send(reply_msg); 201 rfh->Send(reply_msg);
200 return; 202 return;
201 } 203 }
202 204
205 if (test_delegate_ && !test_delegate_->ScriptedPrint(rfh)) {
206 rfh->Send(reply_msg);
207 return;
208 }
209
203 DCHECK(!print_preview_rfh_); 210 DCHECK(!print_preview_rfh_);
204 print_preview_rfh_ = rfh; 211 print_preview_rfh_ = rfh;
205 print_preview_state_ = SCRIPTED_PREVIEW; 212 print_preview_state_ = SCRIPTED_PREVIEW;
206 map[rph] = base::Bind(&PrintViewManager::OnScriptedPrintPreviewReply, 213 map[rph] = base::Bind(&PrintViewManager::OnScriptedPrintPreviewReply,
207 base::Unretained(this), reply_msg); 214 base::Unretained(this), reply_msg);
208 scripted_print_preview_rph_ = rph; 215 scripted_print_preview_rph_ = rph;
209 } 216 }
210 217
211 void PrintViewManager::OnShowScriptedPrintPreview(content::RenderFrameHost* rfh, 218 void PrintViewManager::OnShowScriptedPrintPreview(content::RenderFrameHost* rfh,
212 bool source_is_modifiable) { 219 bool source_is_modifiable) {
213 DCHECK(print_preview_rfh_);
214 if (rfh != print_preview_rfh_) 220 if (rfh != print_preview_rfh_)
215 return; 221 return;
216 222
217 PrintPreviewDialogController* dialog_controller = 223 PrintPreviewDialogController* dialog_controller =
218 PrintPreviewDialogController::GetInstance(); 224 PrintPreviewDialogController::GetInstance();
219 if (!dialog_controller) { 225 if (!dialog_controller) {
220 PrintPreviewDone(); 226 PrintPreviewDone();
221 return; 227 return;
222 } 228 }
223 229
(...skipping 19 matching lines...) Expand all
243 PrintHostMsg_SetupScriptedPrintPreview, OnSetupScriptedPrintPreview) 249 PrintHostMsg_SetupScriptedPrintPreview, OnSetupScriptedPrintPreview)
244 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview, 250 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowScriptedPrintPreview,
245 OnShowScriptedPrintPreview) 251 OnShowScriptedPrintPreview)
246 IPC_MESSAGE_UNHANDLED(handled = false) 252 IPC_MESSAGE_UNHANDLED(handled = false)
247 IPC_END_MESSAGE_MAP() 253 IPC_END_MESSAGE_MAP()
248 254
249 return handled || 255 return handled ||
250 PrintViewManagerBase::OnMessageReceived(message, render_frame_host); 256 PrintViewManagerBase::OnMessageReceived(message, render_frame_host);
251 } 257 }
252 258
259 void PrintViewManager::SetTestDelegate(TestDelegate* delegate) {
260 test_delegate_ = delegate;
261 }
262
253 } // namespace printing 263 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698