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 "printing/backend/print_backend.h" | 5 #include "printing/backend/print_backend.h" |
6 | 6 |
7 #include <objidl.h> | 7 #include <objidl.h> |
8 #include <winspool.h> | 8 #include <winspool.h> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 } | 89 } |
90 return true; | 90 return true; |
91 } | 91 } |
92 | 92 |
93 std::string PrintBackendWin::GetDefaultPrinterName() { | 93 std::string PrintBackendWin::GetDefaultPrinterName() { |
94 DWORD size = MAX_PATH; | 94 DWORD size = MAX_PATH; |
95 TCHAR default_printer_name[MAX_PATH]; | 95 TCHAR default_printer_name[MAX_PATH]; |
96 if (!::GetDefaultPrinter(default_printer_name, &size)) | 96 if (!::GetDefaultPrinter(default_printer_name, &size)) |
97 return std::string(); | 97 return std::string(); |
98 return WideToUTF8(default_printer_name); | 98 return base::WideToUTF8(default_printer_name); |
99 } | 99 } |
100 | 100 |
101 bool PrintBackendWin::GetPrinterSemanticCapsAndDefaults( | 101 bool PrintBackendWin::GetPrinterSemanticCapsAndDefaults( |
102 const std::string& printer_name, | 102 const std::string& printer_name, |
103 PrinterSemanticCapsAndDefaults* printer_info) { | 103 PrinterSemanticCapsAndDefaults* printer_info) { |
104 ScopedPrinterHandle printer_handle; | 104 ScopedPrinterHandle printer_handle; |
105 if (!printer_handle.OpenPrinter(UTF8ToWide(printer_name).c_str())) { | 105 if (!printer_handle.OpenPrinter(base::UTF8ToWide(printer_name).c_str())) { |
106 LOG(WARNING) << "Failed to open printer, error = " << GetLastError(); | 106 LOG(WARNING) << "Failed to open printer, error = " << GetLastError(); |
107 return false; | 107 return false; |
108 } | 108 } |
109 | 109 |
110 PrinterInfo5 info_5; | 110 PrinterInfo5 info_5; |
111 if (!info_5.Init(printer_handle)) { | 111 if (!info_5.Init(printer_handle)) { |
112 return false; | 112 return false; |
113 } | 113 } |
114 DCHECK_EQ(info_5.get()->pPrinterName, UTF8ToUTF16(printer_name)); | 114 DCHECK_EQ(info_5.get()->pPrinterName, base::UTF8ToUTF16(printer_name)); |
115 | 115 |
116 PrinterSemanticCapsAndDefaults caps; | 116 PrinterSemanticCapsAndDefaults caps; |
117 | 117 |
118 // Get printer capabilities. For more info see here: | 118 // Get printer capabilities. For more info see here: |
119 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd183552(v=vs.85).a
spx | 119 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd183552(v=vs.85).a
spx |
120 caps.color_changeable = (::DeviceCapabilities(info_5.get()->pPrinterName, | 120 caps.color_changeable = (::DeviceCapabilities(info_5.get()->pPrinterName, |
121 info_5.get()->pPortName, | 121 info_5.get()->pPortName, |
122 DC_COLORDEVICE, | 122 DC_COLORDEVICE, |
123 NULL, | 123 NULL, |
124 NULL) == 1); | 124 NULL) == 1); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 ScopedXPSInitializer xps_initializer; | 166 ScopedXPSInitializer xps_initializer; |
167 if (!xps_initializer.initialized()) { | 167 if (!xps_initializer.initialized()) { |
168 // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) | 168 // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) |
169 return false; | 169 return false; |
170 } | 170 } |
171 if (!IsValidPrinter(printer_name)) { | 171 if (!IsValidPrinter(printer_name)) { |
172 return false; | 172 return false; |
173 } | 173 } |
174 DCHECK(printer_info); | 174 DCHECK(printer_info); |
175 HPTPROVIDER provider = NULL; | 175 HPTPROVIDER provider = NULL; |
176 std::wstring printer_name_wide = UTF8ToWide(printer_name); | 176 std::wstring printer_name_wide = base::UTF8ToWide(printer_name); |
177 HRESULT hr = XPSModule::OpenProvider(printer_name_wide, 1, &provider); | 177 HRESULT hr = XPSModule::OpenProvider(printer_name_wide, 1, &provider); |
178 if (provider) { | 178 if (provider) { |
179 base::win::ScopedComPtr<IStream> print_capabilities_stream; | 179 base::win::ScopedComPtr<IStream> print_capabilities_stream; |
180 hr = CreateStreamOnHGlobal(NULL, TRUE, | 180 hr = CreateStreamOnHGlobal(NULL, TRUE, |
181 print_capabilities_stream.Receive()); | 181 print_capabilities_stream.Receive()); |
182 DCHECK(SUCCEEDED(hr)); | 182 DCHECK(SUCCEEDED(hr)); |
183 if (print_capabilities_stream) { | 183 if (print_capabilities_stream) { |
184 base::win::ScopedBstr error; | 184 base::win::ScopedBstr error; |
185 hr = XPSModule::GetPrintCapabilities(provider, | 185 hr = XPSModule::GetPrintCapabilities(provider, |
186 NULL, | 186 NULL, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 229 } |
230 XPSModule::CloseProvider(provider); | 230 XPSModule::CloseProvider(provider); |
231 } | 231 } |
232 return true; | 232 return true; |
233 } | 233 } |
234 | 234 |
235 // Gets the information about driver for a specific printer. | 235 // Gets the information about driver for a specific printer. |
236 std::string PrintBackendWin::GetPrinterDriverInfo( | 236 std::string PrintBackendWin::GetPrinterDriverInfo( |
237 const std::string& printer_name) { | 237 const std::string& printer_name) { |
238 ScopedPrinterHandle printer; | 238 ScopedPrinterHandle printer; |
239 if (!printer.OpenPrinter(UTF8ToWide(printer_name).c_str())) { | 239 if (!printer.OpenPrinter(base::UTF8ToWide(printer_name).c_str())) { |
240 return std::string(); | 240 return std::string(); |
241 } | 241 } |
242 return GetDriverInfo(printer); | 242 return GetDriverInfo(printer); |
243 } | 243 } |
244 | 244 |
245 bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) { | 245 bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) { |
246 ScopedPrinterHandle printer_handle; | 246 ScopedPrinterHandle printer_handle; |
247 return printer_handle.OpenPrinter(UTF8ToWide(printer_name).c_str()); | 247 return printer_handle.OpenPrinter(base::UTF8ToWide(printer_name).c_str()); |
248 } | 248 } |
249 | 249 |
250 scoped_refptr<PrintBackend> PrintBackend::CreateInstance( | 250 scoped_refptr<PrintBackend> PrintBackend::CreateInstance( |
251 const base::DictionaryValue* print_backend_settings) { | 251 const base::DictionaryValue* print_backend_settings) { |
252 return new PrintBackendWin; | 252 return new PrintBackendWin; |
253 } | 253 } |
254 | 254 |
255 } // namespace printing | 255 } // namespace printing |
OLD | NEW |