OLD | NEW |
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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/common/print_messages.h" | 24 #include "chrome/common/print_messages.h" |
25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
28 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "content/public/browser/web_contents_view.h" | 30 #include "content/public/browser/web_contents_view.h" |
31 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
32 #include "printing/metafile.h" | 32 #include "printing/metafile.h" |
33 #include "printing/metafile_impl.h" | 33 #include "printing/metafile_impl.h" |
34 #include "printing/printed_document.h" | |
35 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
36 | 35 |
37 using base::TimeDelta; | 36 using base::TimeDelta; |
38 using content::BrowserThread; | 37 using content::BrowserThread; |
39 using content::RenderViewHost; | 38 using content::RenderViewHost; |
40 | 39 |
41 namespace { | 40 namespace { |
42 | 41 |
43 // Keeps track of pending scripted print preview closures. | 42 // Keeps track of pending scripted print preview closures. |
44 // No locking, only access on the UI thread. | 43 // No locking, only access on the UI thread. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 return false; | 93 return false; |
95 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 94 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
96 print_preview_tab->web_contents()->GetWebUI()->GetController()); | 95 print_preview_tab->web_contents()->GetWebUI()->GetController()); |
97 print_preview_ui->OnShowSystemDialog(); | 96 print_preview_ui->OnShowSystemDialog(); |
98 return true; | 97 return true; |
99 } else { | 98 } else { |
100 return PrintNow(); | 99 return PrintNow(); |
101 } | 100 } |
102 } | 101 } |
103 | 102 |
| 103 bool PrintViewManager::PrintToDelegate( |
| 104 PrintedDocument::Delegate* printed_document_delegate) { |
| 105 printed_document_delegate_ = printed_document_delegate; |
| 106 return PrintNowInternal(new PrintMsg_PrintForFile(routing_id())); |
| 107 } |
| 108 |
104 bool PrintViewManager::PrintPreviewNow() { | 109 bool PrintViewManager::PrintPreviewNow() { |
105 if (print_preview_state_ != NOT_PREVIEWING) { | 110 if (print_preview_state_ != NOT_PREVIEWING) { |
106 NOTREACHED(); | 111 NOTREACHED(); |
107 return false; | 112 return false; |
108 } | 113 } |
109 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id()))) | 114 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id()))) |
110 return false; | 115 return false; |
111 | 116 |
112 print_preview_state_ = USER_INITIATED_PREVIEW; | 117 print_preview_state_ = USER_INITIATED_PREVIEW; |
113 return true; | 118 return true; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 463 } |
459 | 464 |
460 // Ask the renderer to generate the print preview, create the print preview | 465 // Ask the renderer to generate the print preview, create the print preview |
461 // view and switch to it, initialize the printer and show the print dialog. | 466 // view and switch to it, initialize the printer and show the print dialog. |
462 DCHECK(!print_job_.get()); | 467 DCHECK(!print_job_.get()); |
463 DCHECK(job); | 468 DCHECK(job); |
464 if (!job) | 469 if (!job) |
465 return false; | 470 return false; |
466 | 471 |
467 print_job_ = new PrintJob(); | 472 print_job_ = new PrintJob(); |
468 print_job_->Initialize(job, this, number_pages_); | 473 print_job_->Initialize( |
| 474 job, this, printed_document_delegate_.get(), number_pages_); |
469 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, | 475 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, |
470 content::Source<PrintJob>(print_job_.get())); | 476 content::Source<PrintJob>(print_job_.get())); |
471 printing_succeeded_ = false; | 477 printing_succeeded_ = false; |
472 return true; | 478 return true; |
473 } | 479 } |
474 | 480 |
475 void PrintViewManager::DisconnectFromCurrentPrintJob() { | 481 void PrintViewManager::DisconnectFromCurrentPrintJob() { |
476 // Make sure all the necessary rendered page are done. Don't bother with the | 482 // Make sure all the necessary rendered page are done. Don't bother with the |
477 // return value. | 483 // return value. |
478 bool result = RenderAllMissingPagesNow(); | 484 bool result = RenderAllMissingPagesNow(); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 } | 612 } |
607 return Send(message); | 613 return Send(message); |
608 } | 614 } |
609 | 615 |
610 void PrintViewManager::ReleasePrinterQuery() { | 616 void PrintViewManager::ReleasePrinterQuery() { |
611 if (!cookie_) | 617 if (!cookie_) |
612 return; | 618 return; |
613 | 619 |
614 int cookie = cookie_; | 620 int cookie = cookie_; |
615 cookie_ = 0; | 621 cookie_ = 0; |
| 622 printed_document_delegate_ = NULL; |
616 | 623 |
617 printing::PrintJobManager* print_job_manager = | 624 printing::PrintJobManager* print_job_manager = |
618 g_browser_process->print_job_manager(); | 625 g_browser_process->print_job_manager(); |
619 // May be NULL in tests. | 626 // May be NULL in tests. |
620 if (!print_job_manager) | 627 if (!print_job_manager) |
621 return; | 628 return; |
622 | 629 |
623 scoped_refptr<printing::PrinterQuery> printer_query; | 630 scoped_refptr<printing::PrinterQuery> printer_query; |
624 print_job_manager->PopPrinterQuery(cookie, &printer_query); | 631 print_job_manager->PopPrinterQuery(cookie, &printer_query); |
625 if (!printer_query.get()) | 632 if (!printer_query.get()) |
626 return; | 633 return; |
627 BrowserThread::PostTask( | 634 BrowserThread::PostTask( |
628 BrowserThread::IO, FROM_HERE, | 635 BrowserThread::IO, FROM_HERE, |
629 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); | 636 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); |
630 } | 637 } |
631 | 638 |
632 } // namespace printing | 639 } // namespace printing |
OLD | NEW |