Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / printing / backend / win_helper.h
blobdb66bf89c4822c94aab94a7c41dd4501d7f0e4ab
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.
5 #ifndef PRINTING_BACKEND_WIN_HELPER_H_
6 #define PRINTING_BACKEND_WIN_HELPER_H_
8 #include <objidl.h>
9 #include <winspool.h>
10 #include <prntvpt.h>
11 #include <xpsprint.h>
13 #include <string>
15 #include "base/strings/string16.h"
16 #include "base/win/scoped_handle.h"
17 #include "printing/printing_export.h"
19 // These are helper functions for dealing with Windows Printing.
20 namespace printing {
22 struct PRINTING_EXPORT PrinterBasicInfo;
24 class PrinterHandleTraits {
25 public:
26 typedef HANDLE Handle;
28 static bool CloseHandle(HANDLE handle) {
29 return ::ClosePrinter(handle) != FALSE;
32 static bool IsHandleValid(HANDLE handle) {
33 return handle != NULL;
36 static HANDLE NullHandle() {
37 return NULL;
40 private:
41 DISALLOW_IMPLICIT_CONSTRUCTORS(PrinterHandleTraits);
44 class ScopedPrinterHandle
45 : public base::win::GenericScopedHandle<PrinterHandleTraits,
46 base::win::VerifierTraits> {
47 public:
48 bool OpenPrinter(const wchar_t* printer) {
49 HANDLE temp_handle;
50 // ::OpenPrinter may return error but assign some value into handle.
51 if (::OpenPrinter(const_cast<LPTSTR>(printer), &temp_handle, NULL)) {
52 Set(temp_handle);
54 return IsValid();
57 private:
58 typedef base::win::GenericScopedHandle<PrinterHandleTraits,
59 base::win::VerifierTraits> Base;
62 class PrinterChangeHandleTraits {
63 public:
64 typedef HANDLE Handle;
66 static bool CloseHandle(HANDLE handle) {
67 ::FindClosePrinterChangeNotification(handle);
68 return true;
71 static bool IsHandleValid(HANDLE handle) {
72 return handle != NULL;
75 static HANDLE NullHandle() {
76 return NULL;
79 private:
80 DISALLOW_IMPLICIT_CONSTRUCTORS(PrinterChangeHandleTraits);
83 typedef base::win::GenericScopedHandle<PrinterChangeHandleTraits,
84 base::win::DummyVerifierTraits>
85 ScopedPrinterChangeHandle;
87 // Wrapper class to wrap the XPS APIs (PTxxx APIs). This is needed because these
88 // APIs are not available by default on XP. We could delayload prntvpt.dll but
89 // this would mean having to add that to every binary that links with
90 // printing.lib (which is a LOT of binaries). So choosing the GetProcAddress
91 // route instead).
92 class PRINTING_EXPORT XPSModule {
93 public:
94 // All the other methods can ONLY be called after a successful call to Init.
95 // Init can be called many times and by multiple threads.
96 static bool Init();
97 static HRESULT OpenProvider(const base::string16& printer_name,
98 DWORD version,
99 HPTPROVIDER* provider);
100 static HRESULT GetPrintCapabilities(HPTPROVIDER provider,
101 IStream* print_ticket,
102 IStream* capabilities,
103 BSTR* error_message);
104 static HRESULT ConvertDevModeToPrintTicket(HPTPROVIDER provider,
105 ULONG devmode_size_in_bytes,
106 PDEVMODE devmode,
107 EPrintTicketScope scope,
108 IStream* print_ticket);
109 static HRESULT ConvertPrintTicketToDevMode(
110 HPTPROVIDER provider,
111 IStream* print_ticket,
112 EDefaultDevmodeType base_devmode_type,
113 EPrintTicketScope scope,
114 ULONG* devmode_byte_count,
115 PDEVMODE* devmode,
116 BSTR* error_message);
117 static HRESULT MergeAndValidatePrintTicket(HPTPROVIDER provider,
118 IStream* base_ticket,
119 IStream* delta_ticket,
120 EPrintTicketScope scope,
121 IStream* result_ticket,
122 BSTR* error_message);
123 static HRESULT ReleaseMemory(PVOID buffer);
124 static HRESULT CloseProvider(HPTPROVIDER provider);
126 private:
127 XPSModule() { }
128 static bool InitImpl();
131 // See comments in cc file explaining why we need this.
132 class PRINTING_EXPORT ScopedXPSInitializer {
133 public:
134 ScopedXPSInitializer();
135 ~ScopedXPSInitializer();
137 bool initialized() const { return initialized_; }
139 private:
140 bool initialized_;
143 // Wrapper class to wrap the XPS Print APIs (these are different from the PTxxx
144 // which deal with the XML Print Schema). This is needed because these
145 // APIs are only available on Windows 7 and higher.
146 class PRINTING_EXPORT XPSPrintModule {
147 public:
148 // All the other methods can ONLY be called after a successful call to Init.
149 // Init can be called many times and by multiple threads.
150 static bool Init();
151 static HRESULT StartXpsPrintJob(
152 const LPCWSTR printer_name,
153 const LPCWSTR job_name,
154 const LPCWSTR output_file_name,
155 HANDLE progress_event,
156 HANDLE completion_event,
157 UINT8* printable_pages_on,
158 UINT32 printable_pages_on_count,
159 IXpsPrintJob **xps_print_job,
160 IXpsPrintJobStream **document_stream,
161 IXpsPrintJobStream **print_ticket_stream);
162 private:
163 XPSPrintModule() { }
164 static bool InitImpl();
167 PRINTING_EXPORT bool InitBasicPrinterInfo(HANDLE printer,
168 PrinterBasicInfo* printer_info);
170 PRINTING_EXPORT std::string GetDriverInfo(HANDLE printer);
172 } // namespace printing
174 #endif // PRINTING_BACKEND_WIN_HELPER_H_