Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/printing/print_job.h" | 10 #include "chrome/browser/printing/print_job.h" |
| 11 #include "chrome/browser/printing/print_job_manager.h" | 11 #include "chrome/browser/printing/print_job_manager.h" |
| 12 #include "chrome/browser/printing/print_preview_tab_controller.h" | 12 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 13 #include "chrome/browser/printing/printer_query.h" | 13 #include "chrome/browser/printing/printer_query.h" |
| 14 #include "chrome/browser/printing/print_view_manager_delegate.h" | |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 15 #include "chrome/browser/ui/webui/print_preview_ui.h" | 16 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 16 #include "chrome/common/print_messages.h" | 17 #include "chrome/common/print_messages.h" |
| 17 #include "content/browser/renderer_host/render_view_host.h" | 18 #include "content/browser/renderer_host/render_view_host.h" |
| 18 #include "content/browser/tab_contents/navigation_entry.h" | 19 #include "content/browser/tab_contents/navigation_entry.h" |
| 19 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
| 20 #include "content/common/notification_details.h" | 21 #include "content/common/notification_details.h" |
| 21 #include "content/common/notification_service.h" | 22 #include "content/common/notification_service.h" |
| 22 #include "content/common/notification_source.h" | 23 #include "content/common/notification_source.h" |
| 23 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 40 } // namespace | 41 } // namespace |
| 41 | 42 |
| 42 namespace printing { | 43 namespace printing { |
| 43 | 44 |
| 44 PrintViewManager::PrintViewManager(TabContentsWrapper* tab) | 45 PrintViewManager::PrintViewManager(TabContentsWrapper* tab) |
| 45 : TabContentsObserver(tab->tab_contents()), | 46 : TabContentsObserver(tab->tab_contents()), |
| 46 tab_(tab), | 47 tab_(tab), |
| 47 number_pages_(0), | 48 number_pages_(0), |
| 48 printing_succeeded_(false), | 49 printing_succeeded_(false), |
| 49 inside_inner_message_loop_(false), | 50 inside_inner_message_loop_(false), |
| 50 is_title_overridden_(false) { | 51 is_title_overridden_(false), |
| 52 delegate_(NULL) { | |
| 51 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 53 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 52 expecting_first_page_ = true; | 54 expecting_first_page_ = true; |
| 53 #endif | 55 #endif |
| 54 } | 56 } |
| 55 | 57 |
| 56 PrintViewManager::~PrintViewManager() { | 58 PrintViewManager::~PrintViewManager() { |
| 57 DisconnectFromCurrentPrintJob(); | 59 DisconnectFromCurrentPrintJob(); |
| 58 } | 60 } |
| 59 | 61 |
| 60 bool PrintViewManager::PrintNow() { | 62 bool PrintViewManager::PrintNow(PrintViewManagerDelegate* delegate) { |
| 63 delegate_ = delegate; | |
| 64 | |
| 61 // Don't print interstitials. | 65 // Don't print interstitials. |
| 62 if (tab_contents()->showing_interstitial_page()) | 66 if (tab_contents()->showing_interstitial_page()) |
| 63 return false; | 67 return false; |
| 64 | 68 |
| 65 return Send(new PrintMsg_PrintPages(routing_id())); | 69 return Send(new PrintMsg_PrintPages(routing_id())); |
| 66 } | 70 } |
| 67 | 71 |
| 68 bool PrintViewManager::PrintPreviewNow() { | 72 bool PrintViewManager::PrintPreviewNow() { |
| 69 // Don't print preview interstitials. | 73 // Don't print preview interstitials. |
| 70 if (tab_contents()->showing_interstitial_page()) | 74 if (tab_contents()->showing_interstitial_page()) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 return GURL(); | 120 return GURL(); |
| 117 } | 121 } |
| 118 | 122 |
| 119 void PrintViewManager::OnDidGetPrintedPagesCount(int cookie, int number_pages) { | 123 void PrintViewManager::OnDidGetPrintedPagesCount(int cookie, int number_pages) { |
| 120 DCHECK_GT(cookie, 0); | 124 DCHECK_GT(cookie, 0); |
| 121 DCHECK_GT(number_pages, 0); | 125 DCHECK_GT(number_pages, 0); |
| 122 number_pages_ = number_pages; | 126 number_pages_ = number_pages; |
| 123 OpportunisticallyCreatePrintJob(cookie); | 127 OpportunisticallyCreatePrintJob(cookie); |
| 124 } | 128 } |
| 125 | 129 |
| 130 void PrintViewManager::OnDidShowPrintDialog() { | |
| 131 if (delegate_) | |
| 132 delegate_->OnPrintDialogShown(); | |
|
Lei Zhang
2011/06/21 01:54:46
set |delegate_| to NULL here instead of below?
James Hawkins
2011/06/22 23:47:24
No, why would we remove the delegate here? That's
| |
| 133 } | |
| 134 | |
| 126 void PrintViewManager::OnDidPrintPage( | 135 void PrintViewManager::OnDidPrintPage( |
| 127 const PrintHostMsg_DidPrintPage_Params& params) { | 136 const PrintHostMsg_DidPrintPage_Params& params) { |
| 128 if (!OpportunisticallyCreatePrintJob(params.document_cookie)) | 137 if (!OpportunisticallyCreatePrintJob(params.document_cookie)) |
| 129 return; | 138 return; |
| 130 | 139 |
| 131 PrintedDocument* document = print_job_->document(); | 140 PrintedDocument* document = print_job_->document(); |
| 132 if (!document || params.document_cookie != document->cookie()) { | 141 if (!document || params.document_cookie != document->cookie()) { |
| 133 // Out of sync. It may happen since we are completely asynchronous. Old | 142 // Out of sync. It may happen since we are completely asynchronous. Old |
| 134 // spurious messages can be received if one of the processes is overloaded. | 143 // spurious messages can be received if one of the processes is overloaded. |
| 135 return; | 144 return; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 NotificationType::PRINT_JOB_RELEASED, | 207 NotificationType::PRINT_JOB_RELEASED, |
| 199 Source<TabContents>(tab_contents()), | 208 Source<TabContents>(tab_contents()), |
| 200 NotificationService::NoDetails()); | 209 NotificationService::NoDetails()); |
| 201 } | 210 } |
| 202 | 211 |
| 203 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { | 212 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { |
| 204 bool handled = true; | 213 bool handled = true; |
| 205 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) | 214 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) |
| 206 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, | 215 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, |
| 207 OnDidGetPrintedPagesCount) | 216 OnDidGetPrintedPagesCount) |
| 217 IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog) | |
| 208 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) | 218 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) |
| 209 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) | 219 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) |
| 210 IPC_MESSAGE_UNHANDLED(handled = false) | 220 IPC_MESSAGE_UNHANDLED(handled = false) |
| 211 IPC_END_MESSAGE_MAP() | 221 IPC_END_MESSAGE_MAP() |
| 212 return handled; | 222 return handled; |
| 213 } | 223 } |
| 214 | 224 |
| 215 void PrintViewManager::Observe(NotificationType type, | 225 void PrintViewManager::Observe(NotificationType type, |
| 216 const NotificationSource& source, | 226 const NotificationSource& source, |
| 217 const NotificationDetails& details) { | 227 const NotificationDetails& details) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 if (!print_job_.get() || !tab_contents()) | 387 if (!print_job_.get() || !tab_contents()) |
| 378 return; | 388 return; |
| 379 RenderViewHost* rvh = tab_contents()->render_view_host(); | 389 RenderViewHost* rvh = tab_contents()->render_view_host(); |
| 380 rvh->Send(new PrintMsg_PrintingDone(rvh->routing_id(), success)); | 390 rvh->Send(new PrintMsg_PrintingDone(rvh->routing_id(), success)); |
| 381 } | 391 } |
| 382 | 392 |
| 383 void PrintViewManager::TerminatePrintJob(bool cancel) { | 393 void PrintViewManager::TerminatePrintJob(bool cancel) { |
| 384 if (!print_job_.get()) | 394 if (!print_job_.get()) |
| 385 return; | 395 return; |
| 386 | 396 |
| 397 delegate_ = NULL; | |
| 398 | |
| 387 if (cancel) { | 399 if (cancel) { |
| 388 // We don't need the metafile data anymore because the printing is canceled. | 400 // We don't need the metafile data anymore because the printing is canceled. |
| 389 print_job_->Cancel(); | 401 print_job_->Cancel(); |
| 390 inside_inner_message_loop_ = false; | 402 inside_inner_message_loop_ = false; |
| 391 } else { | 403 } else { |
| 392 DCHECK(!inside_inner_message_loop_); | 404 DCHECK(!inside_inner_message_loop_); |
| 393 DCHECK(!print_job_->document() || print_job_->document()->IsComplete()); | 405 DCHECK(!print_job_->document() || print_job_->document()->IsComplete()); |
| 394 | 406 |
| 395 // TabContents is either dying or navigating elsewhere. We need to render | 407 // TabContents is either dying or navigating elsewhere. We need to render |
| 396 // all the pages in an hurry if a print job is still pending. This does the | 408 // all the pages in an hurry if a print job is still pending. This does the |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 return false; | 485 return false; |
| 474 } | 486 } |
| 475 | 487 |
| 476 // Settings are already loaded. Go ahead. This will set | 488 // Settings are already loaded. Go ahead. This will set |
| 477 // print_job_->is_job_pending() to true. | 489 // print_job_->is_job_pending() to true. |
| 478 print_job_->StartPrinting(); | 490 print_job_->StartPrinting(); |
| 479 return true; | 491 return true; |
| 480 } | 492 } |
| 481 | 493 |
| 482 } // namespace printing | 494 } // namespace printing |
| OLD | NEW |