Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Side by Side Diff: printing/backend/print_backend_win.cc

Issue 9812002: Include driver infor into PrinterBasicInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <algorithm>
8 #include <objidl.h> 7 #include <objidl.h>
9 #include <winspool.h> 8 #include <winspool.h>
10 9
11 #include "base/file_path.h"
12 #include "base/file_version_info.h"
13 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
14 #include "base/string_piece.h" 11 #include "base/string_piece.h"
15 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
16 #include "base/win/scoped_bstr.h" 13 #include "base/win/scoped_bstr.h"
17 #include "base/win/scoped_comptr.h" 14 #include "base/win/scoped_comptr.h"
18 #include "base/win/scoped_hglobal.h" 15 #include "base/win/scoped_hglobal.h"
19 #include "printing/backend/print_backend_consts.h" 16 #include "printing/backend/print_backend_consts.h"
20 #include "printing/backend/win_helper.h" 17 #include "printing/backend/win_helper.h"
21 18
22 namespace { 19 namespace {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 &count_returned); 66 &count_returned);
70 DCHECK(ret); 67 DCHECK(ret);
71 if (!ret) 68 if (!ret)
72 return false; 69 return false;
73 70
74 std::string default_printer = GetDefaultPrinterName(); 71 std::string default_printer = GetDefaultPrinterName();
75 PRINTER_INFO_2* printer_info = 72 PRINTER_INFO_2* printer_info =
76 reinterpret_cast<PRINTER_INFO_2*>(printer_info_buffer.get()); 73 reinterpret_cast<PRINTER_INFO_2*>(printer_info_buffer.get());
77 for (DWORD index = 0; index < count_returned; index++) { 74 for (DWORD index = 0; index < count_returned; index++) {
78 PrinterBasicInfo info; 75 PrinterBasicInfo info;
79 info.printer_name = WideToUTF8(printer_info[index].pPrinterName); 76 ScopedPrinterHandle printer;
77 OpenPrinter(printer_info->pPrinterName, printer.Receive(), NULL);
78 scoped_array<BYTE> driver_info_buffer;
79 InitBasicPrinterInfo(&printer_info[index],
gene 2012/03/21 21:07:22 Can you make InitBasicPrinterInfo to take printer
Vitaly Buka (NO REVIEWS) 2012/03/21 21:23:01 need to talk about that On 2012/03/21 21:07:22, g
80 GetDriverInfo6(printer, &driver_info_buffer),
81 &info);
80 info.is_default = (info.printer_name == default_printer); 82 info.is_default = (info.printer_name == default_printer);
81 if (printer_info[index].pComment)
82 info.printer_description = WideToUTF8(printer_info[index].pComment);
83 info.printer_status = printer_info[index].Status;
84 if (printer_info[index].pLocation)
85 info.options[kLocationTagName] =
86 WideToUTF8(printer_info[index].pLocation);
87 if (printer_info[index].pDriverName)
88 info.options[kDriverNameTagName] =
89 WideToUTF8(printer_info[index].pDriverName);
90 printer_list->push_back(info); 83 printer_list->push_back(info);
91 } 84 }
92 return true; 85 return true;
93 } 86 }
94 87
95 std::string PrintBackendWin::GetDefaultPrinterName() { 88 std::string PrintBackendWin::GetDefaultPrinterName() {
96 DWORD size = MAX_PATH; 89 DWORD size = MAX_PATH;
97 TCHAR default_printer_name[MAX_PATH]; 90 TCHAR default_printer_name[MAX_PATH];
98 if (!::GetDefaultPrinter(default_printer_name, &size)) 91 if (!::GetDefaultPrinter(default_printer_name, &size))
99 return std::string(); 92 return std::string();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 165 }
173 } 166 }
174 XPSModule::CloseProvider(provider); 167 XPSModule::CloseProvider(provider);
175 } 168 }
176 return true; 169 return true;
177 } 170 }
178 171
179 // Gets the information about driver for a specific printer. 172 // Gets the information about driver for a specific printer.
180 std::string PrintBackendWin::GetPrinterDriverInfo( 173 std::string PrintBackendWin::GetPrinterDriverInfo(
181 const std::string& printer_name) { 174 const std::string& printer_name) {
182 std::string driver_info; 175 ScopedPrinterHandle printer;
183 ScopedPrinterHandle printer_handle;
184 if (!::OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()), 176 if (!::OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()),
185 printer_handle.Receive(), NULL)) { 177 printer.Receive(), NULL)) {
186 return driver_info; 178 return std::string();
187 } 179 }
188 DCHECK(printer_handle.IsValid()); 180 DCHECK(printer.IsValid());
189 DWORD bytes_needed = 0; 181 scoped_array<BYTE> driver_info_buffer;
190 ::GetPrinterDriver(printer_handle, NULL, 6, NULL, 0, &bytes_needed); 182 return GetDriverInfo(GetDriverInfo6(printer, &driver_info_buffer));
gene 2012/03/21 21:07:22 Let's make GetDriverInfo to take printer name?
191 scoped_array<BYTE> driver_info_buffer(new BYTE[bytes_needed]);
192 if (!bytes_needed || !driver_info_buffer.get())
193 return driver_info;
194 if (!::GetPrinterDriver(printer_handle, NULL, 6, driver_info_buffer.get(),
195 bytes_needed, &bytes_needed)) {
196 return driver_info;
197 }
198 if (!bytes_needed)
199 return driver_info;
200 const DRIVER_INFO_6* driver_info_6 =
201 reinterpret_cast<DRIVER_INFO_6*>(driver_info_buffer.get());
202
203 std::string info[4];
204
205 if (driver_info_6->pName)
206 info[0] = WideToUTF8(driver_info_6->pName);
207
208 if (driver_info_6->pDriverPath) {
209 scoped_ptr<FileVersionInfo> version_info(
210 FileVersionInfo::CreateFileVersionInfo(
211 FilePath(driver_info_6->pDriverPath)));
212 info[1] = WideToUTF8(version_info->file_version());
213 info[2] = WideToUTF8(version_info->product_name());
214 info[3] = WideToUTF8(version_info->product_version());
215 }
216
217 for (size_t i = 0; i < arraysize(info); ++i) {
218 std::replace(info[i].begin(), info[i].end(), ';', ',');
219 driver_info.append(info[i]);
220 driver_info.append(";");
221 }
222
223 return driver_info;
224 } 183 }
225 184
226 bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) { 185 bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) {
227 ScopedPrinterHandle printer_handle; 186 ScopedPrinterHandle printer_handle;
228 OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()), 187 OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()),
229 printer_handle.Receive(), NULL); 188 printer_handle.Receive(), NULL);
230 return printer_handle.IsValid(); 189 return printer_handle.IsValid();
231 } 190 }
232 191
233 scoped_refptr<PrintBackend> PrintBackend::CreateInstance( 192 scoped_refptr<PrintBackend> PrintBackend::CreateInstance(
234 const base::DictionaryValue* print_backend_settings) { 193 const base::DictionaryValue* print_backend_settings) {
235 return new PrintBackendWin; 194 return new PrintBackendWin;
236 } 195 }
237 196
238 } // namespace printing 197 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698