| 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 "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 LAZY_INSTANCE_INITIALIZER; | 91 LAZY_INSTANCE_INITIALIZER; |
| 92 | 92 |
| 93 } // namespace | 93 } // namespace |
| 94 #endif // !defined(OS_MACOSX) | 94 #endif // !defined(OS_MACOSX) |
| 95 | 95 |
| 96 namespace printing { | 96 namespace printing { |
| 97 | 97 |
| 98 static const char kCUPSPrinterInfoOpt[] = "printer-info"; | 98 static const char kCUPSPrinterInfoOpt[] = "printer-info"; |
| 99 static const char kCUPSPrinterStateOpt[] = "printer-state"; | 99 static const char kCUPSPrinterStateOpt[] = "printer-state"; |
| 100 static const char kCUPSPrinterTypeOpt[] = "printer-type"; | 100 static const char kCUPSPrinterTypeOpt[] = "printer-type"; |
| 101 static const char kCUPSPrinterMakeModelOpt[] = "printer-make-and-model"; |
| 101 | 102 |
| 102 class PrintBackendCUPS : public PrintBackend { | 103 class PrintBackendCUPS : public PrintBackend { |
| 103 public: | 104 public: |
| 104 PrintBackendCUPS(const GURL& print_server_url, bool blocking); | 105 PrintBackendCUPS(const GURL& print_server_url, bool blocking); |
| 105 virtual ~PrintBackendCUPS() {} | 106 virtual ~PrintBackendCUPS() {} |
| 106 | 107 |
| 107 // PrintBackend implementation. | 108 // PrintBackend implementation. |
| 108 virtual bool EnumeratePrinters(PrinterList* printer_list) OVERRIDE; | 109 virtual bool EnumeratePrinters(PrinterList* printer_list) OVERRIDE; |
| 109 | 110 |
| 110 virtual std::string GetDefaultPrinterName() OVERRIDE; | 111 virtual std::string GetDefaultPrinterName() OVERRIDE; |
| 111 | 112 |
| 112 virtual bool GetPrinterCapsAndDefaults( | 113 virtual bool GetPrinterCapsAndDefaults( |
| 113 const std::string& printer_name, | 114 const std::string& printer_name, |
| 114 PrinterCapsAndDefaults* printer_info) OVERRIDE; | 115 PrinterCapsAndDefaults* printer_info) OVERRIDE; |
| 115 | 116 |
| 116 virtual bool GetPrinterDriverInfo(const std::string& printer_name, | 117 virtual std::string GetPrinterDriverInfo( |
| 117 std::string* driver_info) OVERRIDE; | 118 const std::string& printer_name) OVERRIDE; |
| 118 | 119 |
| 119 virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE; | 120 virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE; |
| 120 | 121 |
| 121 private: | 122 private: |
| 122 // Following functions are wrappers around corresponding CUPS functions. | 123 // Following functions are wrappers around corresponding CUPS functions. |
| 123 // <functions>2() are called when print server is specified, and plain | 124 // <functions>2() are called when print server is specified, and plain |
| 124 // version in another case. There is an issue specifing CUPS_HTTP_DEFAULT | 125 // version in another case. There is an issue specifing CUPS_HTTP_DEFAULT |
| 125 // in the <functions>2(), it does not work in CUPS prior to 1.4. | 126 // in the <functions>2(), it does not work in CUPS prior to 1.4. |
| 126 int GetDests(cups_dest_t** dests); | 127 int GetDests(cups_dest_t** dests); |
| 127 FilePath GetPPD(const char* name); | 128 FilePath GetPPD(const char* name); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 printer_info->printer_capabilities.swap(content); | 222 printer_info->printer_capabilities.swap(content); |
| 222 printer_info->caps_mime_type = "application/pagemaker"; | 223 printer_info->caps_mime_type = "application/pagemaker"; |
| 223 // In CUPS, printer defaults is a part of PPD file. Nothing to upload here. | 224 // In CUPS, printer defaults is a part of PPD file. Nothing to upload here. |
| 224 printer_info->printer_defaults.clear(); | 225 printer_info->printer_defaults.clear(); |
| 225 printer_info->defaults_mime_type.clear(); | 226 printer_info->defaults_mime_type.clear(); |
| 226 } | 227 } |
| 227 | 228 |
| 228 return res; | 229 return res; |
| 229 } | 230 } |
| 230 | 231 |
| 231 bool PrintBackendCUPS::GetPrinterDriverInfo(const std::string& printer_name, | 232 std::string PrintBackendCUPS::GetPrinterDriverInfo( |
| 232 std::string* driver_info) { | 233 const std::string& printer_name) { |
| 233 // TODO(vitalybuka): MAC implementation. http://crbug.com/108194 | 234 cups_dest_t* destinations = NULL; |
| 234 return false; | 235 int num_dests = GetDests(&destinations); |
| 236 std::string result; |
| 237 for (int printer_index = 0; printer_index < num_dests; printer_index++) { |
| 238 const cups_dest_t& printer = destinations[printer_index]; |
| 239 if (printer_name == printer.name) { |
| 240 const char* info = cupsGetOption(kCUPSPrinterMakeModelOpt, printer.num_opt
ions, |
| 241 printer.options); |
| 242 if (info) |
| 243 result = *info; |
| 244 } |
| 245 } |
| 246 |
| 247 cupsFreeDests(num_dests, destinations); |
| 248 return result; |
| 235 } | 249 } |
| 236 | 250 |
| 237 bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) { | 251 bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) { |
| 238 // This is not very efficient way to get specific printer info. CUPS 1.4 | 252 // This is not very efficient way to get specific printer info. CUPS 1.4 |
| 239 // supports cupsGetNamedDest() function. However, CUPS 1.4 is not available | 253 // supports cupsGetNamedDest() function. However, CUPS 1.4 is not available |
| 240 // everywhere (for example, it supported from Mac OS 10.6 only). | 254 // everywhere (for example, it supported from Mac OS 10.6 only). |
| 241 PrinterList printer_list; | 255 PrinterList printer_list; |
| 242 EnumeratePrinters(&printer_list); | 256 EnumeratePrinters(&printer_list); |
| 243 | 257 |
| 244 PrinterList::iterator it; | 258 PrinterList::iterator it; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 << ", HTTP error: " << http_error; | 333 << ", HTTP error: " << http_error; |
| 320 file_util::Delete(ppd_path, false); | 334 file_util::Delete(ppd_path, false); |
| 321 ppd_path.clear(); | 335 ppd_path.clear(); |
| 322 } | 336 } |
| 323 } | 337 } |
| 324 } | 338 } |
| 325 return ppd_path; | 339 return ppd_path; |
| 326 } | 340 } |
| 327 | 341 |
| 328 } // namespace printing | 342 } // namespace printing |
| OLD | NEW |