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_
15 #include "base/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.
22 struct PRINTING_EXPORT PrinterBasicInfo
;
24 class PrinterHandleTraits
{
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() {
41 DISALLOW_IMPLICIT_CONSTRUCTORS(PrinterHandleTraits
);
44 typedef base::win::GenericScopedHandle
<
45 PrinterHandleTraits
, base::win::VerifierTraits
> ScopedPrinterHandle
;
47 // Wrapper class to wrap the XPS APIs (PTxxx APIs). This is needed because these
48 // APIs are not available by default on XP. We could delayload prntvpt.dll but
49 // this would mean having to add that to every binary that links with
50 // printing.lib (which is a LOT of binaries). So choosing the GetProcAddress
52 class PRINTING_EXPORT XPSModule
{
54 // All the other methods can ONLY be called after a successful call to Init.
55 // Init can be called many times and by multiple threads.
57 static HRESULT
OpenProvider(const string16
& printer_name
,
59 HPTPROVIDER
* provider
);
60 static HRESULT
GetPrintCapabilities(HPTPROVIDER provider
,
61 IStream
* print_ticket
,
62 IStream
* capabilities
,
64 static HRESULT
ConvertDevModeToPrintTicket(HPTPROVIDER provider
,
65 ULONG devmode_size_in_bytes
,
67 EPrintTicketScope scope
,
68 IStream
* print_ticket
);
69 static HRESULT
ConvertPrintTicketToDevMode(
71 IStream
* print_ticket
,
72 EDefaultDevmodeType base_devmode_type
,
73 EPrintTicketScope scope
,
74 ULONG
* devmode_byte_count
,
77 static HRESULT
MergeAndValidatePrintTicket(HPTPROVIDER provider
,
79 IStream
* delta_ticket
,
80 EPrintTicketScope scope
,
81 IStream
* result_ticket
,
83 static HRESULT
ReleaseMemory(PVOID buffer
);
84 static HRESULT
CloseProvider(HPTPROVIDER provider
);
88 static bool InitImpl();
91 // See comments in cc file explaining why we need this.
92 class PRINTING_EXPORT ScopedXPSInitializer
{
94 ScopedXPSInitializer();
95 ~ScopedXPSInitializer();
97 bool initialized() const { return initialized_
; }
103 // Wrapper class to wrap the XPS Print APIs (these are different from the PTxxx
104 // which deal with the XML Print Schema). This is needed because these
105 // APIs are only available on Windows 7 and higher.
106 class PRINTING_EXPORT XPSPrintModule
{
108 // All the other methods can ONLY be called after a successful call to Init.
109 // Init can be called many times and by multiple threads.
111 static HRESULT
StartXpsPrintJob(
112 const LPCWSTR printer_name
,
113 const LPCWSTR job_name
,
114 const LPCWSTR output_file_name
,
115 HANDLE progress_event
,
116 HANDLE completion_event
,
117 UINT8
* printable_pages_on
,
118 UINT32 printable_pages_on_count
,
119 IXpsPrintJob
**xps_print_job
,
120 IXpsPrintJobStream
**document_stream
,
121 IXpsPrintJobStream
**print_ticket_stream
);
124 static bool InitImpl();
127 PRINTING_EXPORT
bool InitBasicPrinterInfo(HANDLE printer
,
128 PrinterBasicInfo
* printer_info
);
130 PRINTING_EXPORT
std::string
GetDriverInfo(HANDLE printer
);
132 } // namespace printing
134 #endif // PRINTING_BACKEND_WIN_HELPER_H_