| 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/print_destination_interface.h" |
| 34 #include "printing/printed_document.h" | 35 #include "printing/printed_document.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 36 | 37 |
| 37 using base::TimeDelta; | 38 using base::TimeDelta; |
| 38 using content::BrowserThread; | 39 using content::BrowserThread; |
| 39 using content::RenderViewHost; | 40 using content::RenderViewHost; |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 // Keeps track of pending scripted print preview closures. | 44 // Keeps track of pending scripted print preview closures. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return false; | 95 return false; |
| 95 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 96 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 96 print_preview_tab->web_contents()->GetWebUI()->GetController()); | 97 print_preview_tab->web_contents()->GetWebUI()->GetController()); |
| 97 print_preview_ui->OnShowSystemDialog(); | 98 print_preview_ui->OnShowSystemDialog(); |
| 98 return true; | 99 return true; |
| 99 } else { | 100 } else { |
| 100 return PrintNow(); | 101 return PrintNow(); |
| 101 } | 102 } |
| 102 } | 103 } |
| 103 | 104 |
| 105 bool PrintViewManager::PrintToDestination() { |
| 106 // TODO(mad): Use a passed in destination interface instead. |
| 107 g_browser_process->print_job_manager()->SetPrintDestination( |
| 108 printing::CreatePrintDestination()); |
| 109 return PrintNowInternal(new PrintMsg_PrintPages(routing_id())); |
| 110 } |
| 111 |
| 104 bool PrintViewManager::PrintPreviewNow() { | 112 bool PrintViewManager::PrintPreviewNow() { |
| 105 if (print_preview_state_ != NOT_PREVIEWING) { | 113 if (print_preview_state_ != NOT_PREVIEWING) { |
| 106 NOTREACHED(); | 114 NOTREACHED(); |
| 107 return false; | 115 return false; |
| 108 } | 116 } |
| 109 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id()))) | 117 if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id()))) |
| 110 return false; | 118 return false; |
| 111 | 119 |
| 112 print_preview_state_ = USER_INITIATED_PREVIEW; | 120 print_preview_state_ = USER_INITIATED_PREVIEW; |
| 113 return true; | 121 return true; |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 } | 614 } |
| 607 return Send(message); | 615 return Send(message); |
| 608 } | 616 } |
| 609 | 617 |
| 610 void PrintViewManager::ReleasePrinterQuery() { | 618 void PrintViewManager::ReleasePrinterQuery() { |
| 611 if (!cookie_) | 619 if (!cookie_) |
| 612 return; | 620 return; |
| 613 | 621 |
| 614 int cookie = cookie_; | 622 int cookie = cookie_; |
| 615 cookie_ = 0; | 623 cookie_ = 0; |
| 624 g_browser_process->print_job_manager()->SetPrintDestination(NULL); |
| 625 |
| 616 | 626 |
| 617 printing::PrintJobManager* print_job_manager = | 627 printing::PrintJobManager* print_job_manager = |
| 618 g_browser_process->print_job_manager(); | 628 g_browser_process->print_job_manager(); |
| 619 // May be NULL in tests. | 629 // May be NULL in tests. |
| 620 if (!print_job_manager) | 630 if (!print_job_manager) |
| 621 return; | 631 return; |
| 622 | 632 |
| 623 scoped_refptr<printing::PrinterQuery> printer_query; | 633 scoped_refptr<printing::PrinterQuery> printer_query; |
| 624 print_job_manager->PopPrinterQuery(cookie, &printer_query); | 634 print_job_manager->PopPrinterQuery(cookie, &printer_query); |
| 625 if (!printer_query.get()) | 635 if (!printer_query.get()) |
| 626 return; | 636 return; |
| 627 BrowserThread::PostTask( | 637 BrowserThread::PostTask( |
| 628 BrowserThread::IO, FROM_HERE, | 638 BrowserThread::IO, FROM_HERE, |
| 629 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); | 639 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); |
| 630 } | 640 } |
| 631 | 641 |
| 632 } // namespace printing | 642 } // namespace printing |
| OLD | NEW |