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/printing/print_view_manager_observer.h" |
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
16 #include "chrome/browser/ui/webui/print_preview_ui.h" | 16 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 17 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/print_messages.h" | 18 #include "chrome/common/print_messages.h" |
18 #include "content/browser/renderer_host/render_view_host.h" | 19 #include "content/browser/renderer_host/render_view_host.h" |
19 #include "content/browser/tab_contents/navigation_entry.h" | 20 #include "content/browser/tab_contents/navigation_entry.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "content/common/notification_details.h" | 22 #include "content/common/notification_details.h" |
22 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
23 #include "content/common/notification_source.h" | 24 #include "content/common/notification_source.h" |
24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
25 #include "printing/metafile.h" | 26 #include "printing/metafile.h" |
26 #include "printing/metafile_impl.h" | 27 #include "printing/metafile_impl.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 params.content_area, | 217 params.content_area, |
217 params.has_visible_overlays); | 218 params.has_visible_overlays); |
218 | 219 |
219 ShouldQuitFromInnerMessageLoop(); | 220 ShouldQuitFromInnerMessageLoop(); |
220 } | 221 } |
221 | 222 |
222 void PrintViewManager::OnPrintingFailed(int cookie) { | 223 void PrintViewManager::OnPrintingFailed(int cookie) { |
223 ReleasePrinterQuery(cookie); | 224 ReleasePrinterQuery(cookie); |
224 | 225 |
225 NotificationService::current()->Notify( | 226 NotificationService::current()->Notify( |
226 NotificationType::PRINT_JOB_RELEASED, | 227 chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
227 Source<TabContents>(tab_contents()), | 228 Source<TabContents>(tab_contents()), |
228 NotificationService::NoDetails()); | 229 NotificationService::NoDetails()); |
229 } | 230 } |
230 | 231 |
231 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { | 232 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { |
232 bool handled = true; | 233 bool handled = true; |
233 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) | 234 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) |
234 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, | 235 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, |
235 OnDidGetPrintedPagesCount) | 236 OnDidGetPrintedPagesCount) |
236 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie, | 237 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie, |
237 OnDidGetDocumentCookie) | 238 OnDidGetDocumentCookie) |
238 IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog) | 239 IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog) |
239 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) | 240 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) |
240 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) | 241 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) |
241 IPC_MESSAGE_UNHANDLED(handled = false) | 242 IPC_MESSAGE_UNHANDLED(handled = false) |
242 IPC_END_MESSAGE_MAP() | 243 IPC_END_MESSAGE_MAP() |
243 return handled; | 244 return handled; |
244 } | 245 } |
245 | 246 |
246 void PrintViewManager::Observe(NotificationType type, | 247 void PrintViewManager::Observe(int type, |
247 const NotificationSource& source, | 248 const NotificationSource& source, |
248 const NotificationDetails& details) { | 249 const NotificationDetails& details) { |
249 switch (type.value) { | 250 switch (type) { |
250 case NotificationType::PRINT_JOB_EVENT: { | 251 case chrome::NOTIFICATION_PRINT_JOB_EVENT: { |
251 OnNotifyPrintJobEvent(*Details<JobEventDetails>(details).ptr()); | 252 OnNotifyPrintJobEvent(*Details<JobEventDetails>(details).ptr()); |
252 break; | 253 break; |
253 } | 254 } |
254 default: { | 255 default: { |
255 NOTREACHED(); | 256 NOTREACHED(); |
256 break; | 257 break; |
257 } | 258 } |
258 } | 259 } |
259 } | 260 } |
260 | 261 |
261 void PrintViewManager::OnNotifyPrintJobEvent( | 262 void PrintViewManager::OnNotifyPrintJobEvent( |
262 const JobEventDetails& event_details) { | 263 const JobEventDetails& event_details) { |
263 switch (event_details.type()) { | 264 switch (event_details.type()) { |
264 case JobEventDetails::FAILED: { | 265 case JobEventDetails::FAILED: { |
265 TerminatePrintJob(true); | 266 TerminatePrintJob(true); |
266 | 267 |
267 NotificationService::current()->Notify( | 268 NotificationService::current()->Notify( |
268 NotificationType::PRINT_JOB_RELEASED, | 269 chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
269 Source<TabContentsWrapper>(tab_), | 270 Source<TabContentsWrapper>(tab_), |
270 NotificationService::NoDetails()); | 271 NotificationService::NoDetails()); |
271 break; | 272 break; |
272 } | 273 } |
273 case JobEventDetails::USER_INIT_DONE: | 274 case JobEventDetails::USER_INIT_DONE: |
274 case JobEventDetails::DEFAULT_INIT_DONE: | 275 case JobEventDetails::DEFAULT_INIT_DONE: |
275 case JobEventDetails::USER_INIT_CANCELED: { | 276 case JobEventDetails::USER_INIT_CANCELED: { |
276 NOTREACHED(); | 277 NOTREACHED(); |
277 break; | 278 break; |
278 } | 279 } |
279 case JobEventDetails::ALL_PAGES_REQUESTED: { | 280 case JobEventDetails::ALL_PAGES_REQUESTED: { |
280 ShouldQuitFromInnerMessageLoop(); | 281 ShouldQuitFromInnerMessageLoop(); |
281 break; | 282 break; |
282 } | 283 } |
283 case JobEventDetails::NEW_DOC: | 284 case JobEventDetails::NEW_DOC: |
284 case JobEventDetails::NEW_PAGE: | 285 case JobEventDetails::NEW_PAGE: |
285 case JobEventDetails::PAGE_DONE: | 286 case JobEventDetails::PAGE_DONE: |
286 case JobEventDetails::DOC_DONE: { | 287 case JobEventDetails::DOC_DONE: { |
287 // Don't care about the actual printing process. | 288 // Don't care about the actual printing process. |
288 break; | 289 break; |
289 } | 290 } |
290 case JobEventDetails::JOB_DONE: { | 291 case JobEventDetails::JOB_DONE: { |
291 // Printing is done, we don't need it anymore. | 292 // Printing is done, we don't need it anymore. |
292 // print_job_->is_job_pending() may still be true, depending on the order | 293 // print_job_->is_job_pending() may still be true, depending on the order |
293 // of object registration. | 294 // of object registration. |
294 printing_succeeded_ = true; | 295 printing_succeeded_ = true; |
295 ReleasePrintJob(); | 296 ReleasePrintJob(); |
296 | 297 |
297 NotificationService::current()->Notify( | 298 NotificationService::current()->Notify( |
298 NotificationType::PRINT_JOB_RELEASED, | 299 chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
299 Source<TabContentsWrapper>(tab_), | 300 Source<TabContentsWrapper>(tab_), |
300 NotificationService::NoDetails()); | 301 NotificationService::NoDetails()); |
301 break; | 302 break; |
302 } | 303 } |
303 default: { | 304 default: { |
304 NOTREACHED(); | 305 NOTREACHED(); |
305 break; | 306 break; |
306 } | 307 } |
307 } | 308 } |
308 } | 309 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 371 |
371 // Ask the renderer to generate the print preview, create the print preview | 372 // Ask the renderer to generate the print preview, create the print preview |
372 // view and switch to it, initialize the printer and show the print dialog. | 373 // view and switch to it, initialize the printer and show the print dialog. |
373 DCHECK(!print_job_.get()); | 374 DCHECK(!print_job_.get()); |
374 DCHECK(job); | 375 DCHECK(job); |
375 if (!job) | 376 if (!job) |
376 return false; | 377 return false; |
377 | 378 |
378 print_job_ = new PrintJob(); | 379 print_job_ = new PrintJob(); |
379 print_job_->Initialize(job, this, number_pages_); | 380 print_job_->Initialize(job, this, number_pages_); |
380 registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, | 381 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, |
381 Source<PrintJob>(print_job_.get())); | 382 Source<PrintJob>(print_job_.get())); |
382 printing_succeeded_ = false; | 383 printing_succeeded_ = false; |
383 return true; | 384 return true; |
384 } | 385 } |
385 | 386 |
386 void PrintViewManager::DisconnectFromCurrentPrintJob() { | 387 void PrintViewManager::DisconnectFromCurrentPrintJob() { |
387 // Make sure all the necessary rendered page are done. Don't bother with the | 388 // Make sure all the necessary rendered page are done. Don't bother with the |
388 // return value. | 389 // return value. |
389 bool result = RenderAllMissingPagesNow(); | 390 bool result = RenderAllMissingPagesNow(); |
390 | 391 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 } | 431 } |
431 ReleasePrintJob(); | 432 ReleasePrintJob(); |
432 } | 433 } |
433 | 434 |
434 void PrintViewManager::ReleasePrintJob() { | 435 void PrintViewManager::ReleasePrintJob() { |
435 if (!print_job_.get()) | 436 if (!print_job_.get()) |
436 return; | 437 return; |
437 | 438 |
438 PrintingDone(printing_succeeded_); | 439 PrintingDone(printing_succeeded_); |
439 | 440 |
440 registrar_.Remove(this, NotificationType::PRINT_JOB_EVENT, | 441 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, |
441 Source<PrintJob>(print_job_.get())); | 442 Source<PrintJob>(print_job_.get())); |
442 print_job_->DisconnectSource(); | 443 print_job_->DisconnectSource(); |
443 // Don't close the worker thread. | 444 // Don't close the worker thread. |
444 print_job_ = NULL; | 445 print_job_ = NULL; |
445 } | 446 } |
446 | 447 |
447 bool PrintViewManager::RunInnerMessageLoop() { | 448 bool PrintViewManager::RunInnerMessageLoop() { |
448 // This value may actually be too low: | 449 // This value may actually be too low: |
449 // | 450 // |
450 // - If we're looping because of printer settings initialization, the premise | 451 // - If we're looping because of printer settings initialization, the premise |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 return false; | 505 return false; |
505 } | 506 } |
506 | 507 |
507 // Settings are already loaded. Go ahead. This will set | 508 // Settings are already loaded. Go ahead. This will set |
508 // print_job_->is_job_pending() to true. | 509 // print_job_->is_job_pending() to true. |
509 print_job_->StartPrinting(); | 510 print_job_->StartPrinting(); |
510 return true; | 511 return true; |
511 } | 512 } |
512 | 513 |
513 } // namespace printing | 514 } // namespace printing |
OLD | NEW |