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_observer.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 observer_(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() { |
(...skipping 12 matching lines...) Expand all Loading... |
73 return Send(new PrintMsg_InitiatePrintPreview(routing_id())); | 75 return Send(new PrintMsg_InitiatePrintPreview(routing_id())); |
74 } | 76 } |
75 | 77 |
76 void PrintViewManager::PreviewPrintingRequestCancelled() { | 78 void PrintViewManager::PreviewPrintingRequestCancelled() { |
77 if (!tab_contents()) | 79 if (!tab_contents()) |
78 return; | 80 return; |
79 RenderViewHost* rvh = tab_contents()->render_view_host(); | 81 RenderViewHost* rvh = tab_contents()->render_view_host(); |
80 rvh->Send(new PrintMsg_PreviewPrintingRequestCancelled(rvh->routing_id())); | 82 rvh->Send(new PrintMsg_PreviewPrintingRequestCancelled(rvh->routing_id())); |
81 } | 83 } |
82 | 84 |
| 85 void PrintViewManager::set_observer(PrintViewManagerObserver* observer) { |
| 86 DCHECK(!observer || !observer_); |
| 87 observer_ = observer; |
| 88 } |
| 89 |
83 void PrintViewManager::StopNavigation() { | 90 void PrintViewManager::StopNavigation() { |
84 // Cancel the current job, wait for the worker to finish. | 91 // Cancel the current job, wait for the worker to finish. |
85 TerminatePrintJob(true); | 92 TerminatePrintJob(true); |
86 } | 93 } |
87 | 94 |
88 void PrintViewManager::RenderViewGone() { | 95 void PrintViewManager::RenderViewGone() { |
89 if (!print_job_.get()) | 96 if (!print_job_.get()) |
90 return; | 97 return; |
91 | 98 |
92 scoped_refptr<PrintedDocument> document(print_job_->document()); | 99 scoped_refptr<PrintedDocument> document(print_job_->document()); |
(...skipping 23 matching lines...) Expand all Loading... |
116 return GURL(); | 123 return GURL(); |
117 } | 124 } |
118 | 125 |
119 void PrintViewManager::OnDidGetPrintedPagesCount(int cookie, int number_pages) { | 126 void PrintViewManager::OnDidGetPrintedPagesCount(int cookie, int number_pages) { |
120 DCHECK_GT(cookie, 0); | 127 DCHECK_GT(cookie, 0); |
121 DCHECK_GT(number_pages, 0); | 128 DCHECK_GT(number_pages, 0); |
122 number_pages_ = number_pages; | 129 number_pages_ = number_pages; |
123 OpportunisticallyCreatePrintJob(cookie); | 130 OpportunisticallyCreatePrintJob(cookie); |
124 } | 131 } |
125 | 132 |
| 133 void PrintViewManager::OnDidShowPrintDialog() { |
| 134 if (observer_) |
| 135 observer_->OnPrintDialogShown(); |
| 136 } |
| 137 |
126 void PrintViewManager::OnDidPrintPage( | 138 void PrintViewManager::OnDidPrintPage( |
127 const PrintHostMsg_DidPrintPage_Params& params) { | 139 const PrintHostMsg_DidPrintPage_Params& params) { |
128 if (!OpportunisticallyCreatePrintJob(params.document_cookie)) | 140 if (!OpportunisticallyCreatePrintJob(params.document_cookie)) |
129 return; | 141 return; |
130 | 142 |
131 PrintedDocument* document = print_job_->document(); | 143 PrintedDocument* document = print_job_->document(); |
132 if (!document || params.document_cookie != document->cookie()) { | 144 if (!document || params.document_cookie != document->cookie()) { |
133 // Out of sync. It may happen since we are completely asynchronous. Old | 145 // 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. | 146 // spurious messages can be received if one of the processes is overloaded. |
135 return; | 147 return; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 NotificationType::PRINT_JOB_RELEASED, | 210 NotificationType::PRINT_JOB_RELEASED, |
199 Source<TabContents>(tab_contents()), | 211 Source<TabContents>(tab_contents()), |
200 NotificationService::NoDetails()); | 212 NotificationService::NoDetails()); |
201 } | 213 } |
202 | 214 |
203 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { | 215 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { |
204 bool handled = true; | 216 bool handled = true; |
205 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) | 217 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) |
206 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, | 218 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, |
207 OnDidGetPrintedPagesCount) | 219 OnDidGetPrintedPagesCount) |
| 220 IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog) |
208 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) | 221 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) |
209 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) | 222 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) |
210 IPC_MESSAGE_UNHANDLED(handled = false) | 223 IPC_MESSAGE_UNHANDLED(handled = false) |
211 IPC_END_MESSAGE_MAP() | 224 IPC_END_MESSAGE_MAP() |
212 return handled; | 225 return handled; |
213 } | 226 } |
214 | 227 |
215 void PrintViewManager::Observe(NotificationType type, | 228 void PrintViewManager::Observe(NotificationType type, |
216 const NotificationSource& source, | 229 const NotificationSource& source, |
217 const NotificationDetails& details) { | 230 const NotificationDetails& details) { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 return false; | 486 return false; |
474 } | 487 } |
475 | 488 |
476 // Settings are already loaded. Go ahead. This will set | 489 // Settings are already loaded. Go ahead. This will set |
477 // print_job_->is_job_pending() to true. | 490 // print_job_->is_job_pending() to true. |
478 print_job_->StartPrinting(); | 491 print_job_->StartPrinting(); |
479 return true; | 492 return true; |
480 } | 493 } |
481 | 494 |
482 } // namespace printing | 495 } // namespace printing |
OLD | NEW |