• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef PRINTING_BACKEND_PRINT_BACKEND_H_
6 #define PRINTING_BACKEND_PRINT_BACKEND_H_
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 #include "base/memory/ref_counted.h"
13 #include "printing/print_job_constants.h"
14 #include "printing/printing_export.h"
15 
16 namespace base {
17 class DictionaryValue;
18 }
19 
20 // This is the interface for platform-specific code for a print backend
21 namespace printing {
22 
23 struct PRINTING_EXPORT PrinterBasicInfo {
24   PrinterBasicInfo();
25   ~PrinterBasicInfo();
26 
27   std::string printer_name;
28   std::string printer_description;
29   int printer_status;
30   int is_default;
31   std::map<std::string, std::string> options;
32 };
33 
34 typedef std::vector<PrinterBasicInfo> PrinterList;
35 
36 struct PRINTING_EXPORT PrinterSemanticCapsAndDefaults {
37   PrinterSemanticCapsAndDefaults();
38   ~PrinterSemanticCapsAndDefaults();
39 
40   // Capabilities.
41   bool color_changeable;
42   bool duplex_capable;
43 
44 #if defined(USE_CUPS)
45   ColorModel color_model;
46   ColorModel bw_model;
47 #endif
48 
49   // Current defaults.
50   bool color_default;
51   DuplexMode duplex_default;
52 };
53 
54 struct PRINTING_EXPORT PrinterCapsAndDefaults {
55   PrinterCapsAndDefaults();
56   ~PrinterCapsAndDefaults();
57 
58   std::string printer_capabilities;
59   std::string caps_mime_type;
60   std::string printer_defaults;
61   std::string defaults_mime_type;
62 };
63 
64 // PrintBackend class will provide interface for different print backends
65 // (Windows, CUPS) to implement. User will call CreateInstance() to
66 // obtain available print backend.
67 // Please note, that PrintBackend is not platform specific, but rather
68 // print system specific. For example, CUPS is available on both Linux and Mac,
69 // but not available on ChromeOS, etc. This design allows us to add more
70 // functionality on some platforms, while reusing core (CUPS) functions.
71 class PRINTING_EXPORT PrintBackend
72     : public base::RefCountedThreadSafe<PrintBackend> {
73  public:
74   // Enumerates the list of installed local and network printers.
75   virtual bool EnumeratePrinters(PrinterList* printer_list) = 0;
76 
77   // Get the default printer name. Empty string if no default printer.
78   virtual std::string GetDefaultPrinterName() = 0;
79 
80   // Gets the semantic capabilities and defaults for a specific printer.
81   // This is usually a lighter implementation than GetPrinterCapsAndDefaults().
82   // NOTE: on some old platforms (WinXP without XPS pack)
83   // GetPrinterCapsAndDefaults() will fail, while this function will succeed.
84   virtual bool GetPrinterSemanticCapsAndDefaults(
85       const std::string& printer_name,
86       PrinterSemanticCapsAndDefaults* printer_info) = 0;
87 
88   // Gets the capabilities and defaults for a specific printer.
89   virtual bool GetPrinterCapsAndDefaults(
90       const std::string& printer_name,
91       PrinterCapsAndDefaults* printer_info) = 0;
92 
93   // Gets the information about driver for a specific printer.
94   virtual std::string GetPrinterDriverInfo(
95       const std::string& printer_name) = 0;
96 
97   // Returns true if printer_name points to a valid printer.
98   virtual bool IsValidPrinter(const std::string& printer_name) = 0;
99 
100   // Allocate a print backend. If |print_backend_settings| is NULL, default
101   // settings will be used.
102   // Return NULL if no print backend available.
103   static scoped_refptr<PrintBackend> CreateInstance(
104       const base::DictionaryValue* print_backend_settings);
105 
106  protected:
107   friend class base::RefCountedThreadSafe<PrintBackend>;
108   virtual ~PrintBackend();
109 };
110 
111 }  // namespace printing
112 
113 #endif  // PRINTING_BACKEND_PRINT_BACKEND_H_
114