Avoid double-InitCache() in SimpleDoomBetween test, leak
[chromium-blink-merge.git] / printing / backend / win_helper.h
blob04014336c79d8fc66b4b97431f27f9761326d518
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/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 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
51 // route instead).
52 class PRINTING_EXPORT XPSModule {
53 public:
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.
56 static bool Init();
57 static HRESULT OpenProvider(const string16& printer_name,
58 DWORD version,
59 HPTPROVIDER* provider);
60 static HRESULT GetPrintCapabilities(HPTPROVIDER provider,
61 IStream* print_ticket,
62 IStream* capabilities,
63 BSTR* error_message);
64 static HRESULT ConvertDevModeToPrintTicket(HPTPROVIDER provider,
65 ULONG devmode_size_in_bytes,
66 PDEVMODE devmode,
67 EPrintTicketScope scope,
68 IStream* print_ticket);
69 static HRESULT ConvertPrintTicketToDevMode(
70 HPTPROVIDER provider,
71 IStream* print_ticket,
72 EDefaultDevmodeType base_devmode_type,
73 EPrintTicketScope scope,
74 ULONG* devmode_byte_count,
75 PDEVMODE* devmode,
76 BSTR* error_message);
77 static HRESULT MergeAndValidatePrintTicket(HPTPROVIDER provider,
78 IStream* base_ticket,
79 IStream* delta_ticket,
80 EPrintTicketScope scope,
81 IStream* result_ticket,
82 BSTR* error_message);
83 static HRESULT ReleaseMemory(PVOID buffer);
84 static HRESULT CloseProvider(HPTPROVIDER provider);
86 private:
87 XPSModule() { }
88 static bool InitImpl();
91 // See comments in cc file explaining why we need this.
92 class PRINTING_EXPORT ScopedXPSInitializer {
93 public:
94 ScopedXPSInitializer();
95 ~ScopedXPSInitializer();
97 bool initialized() const { return initialized_; }
99 private:
100 bool 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 {
107 public:
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.
110 static bool Init();
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);
122 private:
123 XPSPrintModule() { }
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_