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