| 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/service/cloud_print/print_system.h" | 5 #include "chrome/service/cloud_print/print_system.h" |
| 6 | 6 |
| 7 #include <objidl.h> | 7 #include <objidl.h> |
| 8 #include <winspool.h> | 8 #include <winspool.h> |
| 9 #include <xpsprint.h> | 9 #include <xpsprint.h> |
| 10 | 10 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) | 112 // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) |
| 113 return E_FAIL; | 113 return E_FAIL; |
| 114 } | 114 } |
| 115 | 115 |
| 116 base::win::ScopedComPtr<IStream> pt_stream; | 116 base::win::ScopedComPtr<IStream> pt_stream; |
| 117 HRESULT hr = StreamFromPrintTicket(print_ticket, pt_stream.Receive()); | 117 HRESULT hr = StreamFromPrintTicket(print_ticket, pt_stream.Receive()); |
| 118 if (FAILED(hr)) | 118 if (FAILED(hr)) |
| 119 return hr; | 119 return hr; |
| 120 | 120 |
| 121 HPTPROVIDER provider = NULL; | 121 HPTPROVIDER provider = NULL; |
| 122 hr = printing::XPSModule::OpenProvider(UTF8ToWide(printer_name), | 122 hr = printing::XPSModule::OpenProvider(base::UTF8ToWide(printer_name), |
| 123 1, | 123 1, |
| 124 &provider); | 124 &provider); |
| 125 if (SUCCEEDED(hr)) { | 125 if (SUCCEEDED(hr)) { |
| 126 ULONG size = 0; | 126 ULONG size = 0; |
| 127 DEVMODE* dm = NULL; | 127 DEVMODE* dm = NULL; |
| 128 // Use kPTJobScope, because kPTDocumentScope breaks duplex. | 128 // Use kPTJobScope, because kPTDocumentScope breaks duplex. |
| 129 hr = printing::XPSModule::ConvertPrintTicketToDevMode(provider, | 129 hr = printing::XPSModule::ConvertPrintTicketToDevMode(provider, |
| 130 pt_stream, | 130 pt_stream, |
| 131 kUserDefaultDevmode, | 131 kUserDefaultDevmode, |
| 132 kPTJobScope, | 132 kPTJobScope, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 printing::PrintBackend::CreateInstance(NULL)); | 171 printing::PrintBackend::CreateInstance(NULL)); |
| 172 printer_info_ = print_backend->GetPrinterDriverInfo(printer_name); | 172 printer_info_ = print_backend->GetPrinterDriverInfo(printer_name); |
| 173 child_process_logging::ScopedPrinterInfoSetter prn_info(printer_info_); | 173 child_process_logging::ScopedPrinterInfoSetter prn_info(printer_info_); |
| 174 | 174 |
| 175 delegate_ = delegate; | 175 delegate_ = delegate; |
| 176 // An empty printer name means watch the current server, we need to pass | 176 // An empty printer name means watch the current server, we need to pass |
| 177 // NULL to OpenPrinter. | 177 // NULL to OpenPrinter. |
| 178 LPTSTR printer_name_to_use = NULL; | 178 LPTSTR printer_name_to_use = NULL; |
| 179 std::wstring printer_name_wide; | 179 std::wstring printer_name_wide; |
| 180 if (!printer_name.empty()) { | 180 if (!printer_name.empty()) { |
| 181 printer_name_wide = UTF8ToWide(printer_name); | 181 printer_name_wide = base::UTF8ToWide(printer_name); |
| 182 printer_name_to_use = const_cast<LPTSTR>(printer_name_wide.c_str()); | 182 printer_name_to_use = const_cast<LPTSTR>(printer_name_wide.c_str()); |
| 183 } | 183 } |
| 184 bool ret = false; | 184 bool ret = false; |
| 185 OpenPrinter(printer_name_to_use, printer_.Receive(), NULL); | 185 OpenPrinter(printer_name_to_use, printer_.Receive(), NULL); |
| 186 if (printer_.IsValid()) { | 186 if (printer_.IsValid()) { |
| 187 printer_change_.Set(FindFirstPrinterChangeNotification( | 187 printer_change_.Set(FindFirstPrinterChangeNotification( |
| 188 printer_, PRINTER_CHANGE_PRINTER|PRINTER_CHANGE_JOB, 0, NULL)); | 188 printer_, PRINTER_CHANGE_PRINTER|PRINTER_CHANGE_JOB, 0, NULL)); |
| 189 if (printer_change_.IsValid()) { | 189 if (printer_change_.IsValid()) { |
| 190 ret = watcher_.StartWatching(printer_change_, this); | 190 ret = watcher_.StartWatching(printer_change_, this); |
| 191 } | 191 } |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 // We only support PDF and XPS documents for now. | 415 // We only support PDF and XPS documents for now. |
| 416 if (print_data_mime_type == "application/pdf") { | 416 if (print_data_mime_type == "application/pdf") { |
| 417 DevMode pt_dev_mode; | 417 DevMode pt_dev_mode; |
| 418 HRESULT hr = PrintTicketToDevMode(printer_name, print_ticket, | 418 HRESULT hr = PrintTicketToDevMode(printer_name, print_ticket, |
| 419 &pt_dev_mode); | 419 &pt_dev_mode); |
| 420 if (FAILED(hr)) { | 420 if (FAILED(hr)) { |
| 421 NOTREACHED(); | 421 NOTREACHED(); |
| 422 return false; | 422 return false; |
| 423 } | 423 } |
| 424 | 424 |
| 425 HDC dc = CreateDC(L"WINSPOOL", UTF8ToWide(printer_name).c_str(), | 425 HDC dc = CreateDC(L"WINSPOOL", base::UTF8ToWide(printer_name).c_str(), |
| 426 NULL, pt_dev_mode.dm_); | 426 NULL, pt_dev_mode.dm_); |
| 427 if (!dc) { | 427 if (!dc) { |
| 428 NOTREACHED(); | 428 NOTREACHED(); |
| 429 return false; | 429 return false; |
| 430 } | 430 } |
| 431 hr = E_FAIL; | 431 hr = E_FAIL; |
| 432 DOCINFO di = {0}; | 432 DOCINFO di = {0}; |
| 433 di.cbSize = sizeof(DOCINFO); | 433 di.cbSize = sizeof(DOCINFO); |
| 434 string16 doc_name = UTF8ToUTF16(job_title); | 434 string16 doc_name = UTF8ToUTF16(job_title); |
| 435 DCHECK(printing::PrintBackend::SimplifyDocumentTitle(doc_name) == | 435 DCHECK(printing::PrintBackend::SimplifyDocumentTitle(doc_name) == |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 if (!job_progress_event_.Get()) | 595 if (!job_progress_event_.Get()) |
| 596 return false; | 596 return false; |
| 597 scoped_ptr<base::win::ScopedCOMInitializer> com_initializer( | 597 scoped_ptr<base::win::ScopedCOMInitializer> com_initializer( |
| 598 new base::win::ScopedCOMInitializer( | 598 new base::win::ScopedCOMInitializer( |
| 599 base::win::ScopedCOMInitializer::kMTA)); | 599 base::win::ScopedCOMInitializer::kMTA)); |
| 600 base::win::ScopedComPtr<IXpsPrintJobStream> doc_stream; | 600 base::win::ScopedComPtr<IXpsPrintJobStream> doc_stream; |
| 601 base::win::ScopedComPtr<IXpsPrintJobStream> print_ticket_stream; | 601 base::win::ScopedComPtr<IXpsPrintJobStream> print_ticket_stream; |
| 602 bool ret = false; | 602 bool ret = false; |
| 603 // Use nested SUCCEEDED checks because we want a common return point. | 603 // Use nested SUCCEEDED checks because we want a common return point. |
| 604 if (SUCCEEDED(printing::XPSPrintModule::StartXpsPrintJob( | 604 if (SUCCEEDED(printing::XPSPrintModule::StartXpsPrintJob( |
| 605 UTF8ToWide(printer_name).c_str(), | 605 base::UTF8ToWide(printer_name).c_str(), |
| 606 UTF8ToWide(job_title).c_str(), | 606 base::UTF8ToWide(job_title).c_str(), |
| 607 NULL, | 607 NULL, |
| 608 job_progress_event_.Get(), | 608 job_progress_event_.Get(), |
| 609 NULL, | 609 NULL, |
| 610 NULL, | 610 NULL, |
| 611 NULL, | 611 NULL, |
| 612 xps_print_job_.Receive(), | 612 xps_print_job_.Receive(), |
| 613 doc_stream.Receive(), | 613 doc_stream.Receive(), |
| 614 print_ticket_stream.Receive()))) { | 614 print_ticket_stream.Receive()))) { |
| 615 ULONG bytes_written = 0; | 615 ULONG bytes_written = 0; |
| 616 if (SUCCEEDED(print_ticket_stream->Write(print_ticket.c_str(), | 616 if (SUCCEEDED(print_ticket_stream->Write(print_ticket.c_str(), |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 const std::string& print_ticket_data) { | 782 const std::string& print_ticket_data) { |
| 783 child_process_logging::ScopedPrinterInfoSetter prn_info( | 783 child_process_logging::ScopedPrinterInfoSetter prn_info( |
| 784 print_backend_->GetPrinterDriverInfo(printer_name)); | 784 print_backend_->GetPrinterDriverInfo(printer_name)); |
| 785 printing::ScopedXPSInitializer xps_initializer; | 785 printing::ScopedXPSInitializer xps_initializer; |
| 786 if (!xps_initializer.initialized()) { | 786 if (!xps_initializer.initialized()) { |
| 787 // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) | 787 // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) |
| 788 return false; | 788 return false; |
| 789 } | 789 } |
| 790 bool ret = false; | 790 bool ret = false; |
| 791 HPTPROVIDER provider = NULL; | 791 HPTPROVIDER provider = NULL; |
| 792 printing::XPSModule::OpenProvider(UTF8ToWide(printer_name.c_str()), | 792 printing::XPSModule::OpenProvider(base::UTF8ToWide(printer_name.c_str()), |
| 793 1, | 793 1, |
| 794 &provider); | 794 &provider); |
| 795 if (provider) { | 795 if (provider) { |
| 796 base::win::ScopedComPtr<IStream> print_ticket_stream; | 796 base::win::ScopedComPtr<IStream> print_ticket_stream; |
| 797 CreateStreamOnHGlobal(NULL, TRUE, print_ticket_stream.Receive()); | 797 CreateStreamOnHGlobal(NULL, TRUE, print_ticket_stream.Receive()); |
| 798 ULONG bytes_written = 0; | 798 ULONG bytes_written = 0; |
| 799 print_ticket_stream->Write(print_ticket_data.c_str(), | 799 print_ticket_stream->Write(print_ticket_data.c_str(), |
| 800 print_ticket_data.length(), | 800 print_ticket_data.length(), |
| 801 &bytes_written); | 801 &bytes_written); |
| 802 DCHECK(bytes_written == print_ticket_data.length()); | 802 DCHECK(bytes_written == print_ticket_data.length()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 818 return ret; | 818 return ret; |
| 819 } | 819 } |
| 820 | 820 |
| 821 bool PrintSystemWin::GetJobDetails(const std::string& printer_name, | 821 bool PrintSystemWin::GetJobDetails(const std::string& printer_name, |
| 822 PlatformJobId job_id, | 822 PlatformJobId job_id, |
| 823 PrintJobDetails *job_details) { | 823 PrintJobDetails *job_details) { |
| 824 child_process_logging::ScopedPrinterInfoSetter prn_info( | 824 child_process_logging::ScopedPrinterInfoSetter prn_info( |
| 825 print_backend_->GetPrinterDriverInfo(printer_name)); | 825 print_backend_->GetPrinterDriverInfo(printer_name)); |
| 826 DCHECK(job_details); | 826 DCHECK(job_details); |
| 827 printing::ScopedPrinterHandle printer_handle; | 827 printing::ScopedPrinterHandle printer_handle; |
| 828 std::wstring printer_name_wide = UTF8ToWide(printer_name); | 828 std::wstring printer_name_wide = base::UTF8ToWide(printer_name); |
| 829 OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()), | 829 OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()), |
| 830 printer_handle.Receive(), NULL); | 830 printer_handle.Receive(), NULL); |
| 831 DCHECK(printer_handle.IsValid()); | 831 DCHECK(printer_handle.IsValid()); |
| 832 bool ret = false; | 832 bool ret = false; |
| 833 if (printer_handle.IsValid()) { | 833 if (printer_handle.IsValid()) { |
| 834 DWORD bytes_needed = 0; | 834 DWORD bytes_needed = 0; |
| 835 GetJob(printer_handle, job_id, 1, NULL, 0, &bytes_needed); | 835 GetJob(printer_handle, job_id, 1, NULL, 0, &bytes_needed); |
| 836 DWORD last_error = GetLastError(); | 836 DWORD last_error = GetLastError(); |
| 837 if (ERROR_INVALID_PARAMETER != last_error) { | 837 if (ERROR_INVALID_PARAMETER != last_error) { |
| 838 // ERROR_INVALID_PARAMETER normally means that the job id is not valid. | 838 // ERROR_INVALID_PARAMETER normally means that the job id is not valid. |
| 839 DCHECK(last_error == ERROR_INSUFFICIENT_BUFFER); | 839 DCHECK(last_error == ERROR_INSUFFICIENT_BUFFER); |
| 840 scoped_array<BYTE> job_info_buffer(new BYTE[bytes_needed]); | 840 scoped_array<BYTE> job_info_buffer(new BYTE[bytes_needed]); |
| 841 if (GetJob(printer_handle, job_id, 1, job_info_buffer.get(), bytes_needed, | 841 if (GetJob(printer_handle, job_id, 1, job_info_buffer.get(), bytes_needed, |
| 842 &bytes_needed)) { | 842 &bytes_needed)) { |
| 843 JOB_INFO_1 *job_info = | 843 JOB_INFO_1 *job_info = |
| 844 reinterpret_cast<JOB_INFO_1 *>(job_info_buffer.get()); | 844 reinterpret_cast<JOB_INFO_1 *>(job_info_buffer.get()); |
| 845 if (job_info->pStatus) { | 845 if (job_info->pStatus) { |
| 846 WideToUTF8(job_info->pStatus, wcslen(job_info->pStatus), | 846 base::WideToUTF8(job_info->pStatus, wcslen(job_info->pStatus), |
| 847 &job_details->status_message); | 847 &job_details->status_message); |
| 848 } | 848 } |
| 849 job_details->platform_status_flags = job_info->Status; | 849 job_details->platform_status_flags = job_info->Status; |
| 850 if ((job_info->Status & JOB_STATUS_COMPLETE) || | 850 if ((job_info->Status & JOB_STATUS_COMPLETE) || |
| 851 (job_info->Status & JOB_STATUS_PRINTED)) { | 851 (job_info->Status & JOB_STATUS_PRINTED)) { |
| 852 job_details->status = PRINT_JOB_STATUS_COMPLETED; | 852 job_details->status = PRINT_JOB_STATUS_COMPLETED; |
| 853 } else if (job_info->Status & JOB_STATUS_ERROR) { | 853 } else if (job_info->Status & JOB_STATUS_ERROR) { |
| 854 job_details->status = PRINT_JOB_STATUS_ERROR; | 854 job_details->status = PRINT_JOB_STATUS_ERROR; |
| 855 } else { | 855 } else { |
| 856 job_details->status = PRINT_JOB_STATUS_IN_PROGRESS; | 856 job_details->status = PRINT_JOB_STATUS_IN_PROGRESS; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 886 return "application/pdf"; | 886 return "application/pdf"; |
| 887 } | 887 } |
| 888 | 888 |
| 889 | 889 |
| 890 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( | 890 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( |
| 891 const base::DictionaryValue* print_system_settings) { | 891 const base::DictionaryValue* print_system_settings) { |
| 892 return new PrintSystemWin; | 892 return new PrintSystemWin; |
| 893 } | 893 } |
| 894 | 894 |
| 895 } // namespace cloud_print | 895 } // namespace cloud_print |
| OLD | NEW |