diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-10 17:38:06 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-10 17:38:06 +0000 |
commit | ecdc9d4c11a997c23b2e8cbb588732ceea823047 (patch) | |
tree | 807f488f60df6249e1d1fa2b5af3e0661b166786 /printing | |
parent | 15a3ebf01a2e6ea982c1d952abfa60e14e7e0357 (diff) | |
download | chromium_src-ecdc9d4c11a997c23b2e8cbb588732ceea823047.zip chromium_src-ecdc9d4c11a997c23b2e8cbb588732ceea823047.tar.gz chromium_src-ecdc9d4c11a997c23b2e8cbb588732ceea823047.tar.bz2 |
Used GetProcAddress to load exported functions from prntvpt.dll instead of using DELAYLOAD.
BUG=62421
TEST=ui_tests on XP without the XPS Framework installed should run.
Review URL: http://codereview.chromium.org/4637004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65678 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/backend/print_backend_win.cc | 23 | ||||
-rw-r--r-- | printing/backend/win_helper.cc | 167 | ||||
-rw-r--r-- | printing/backend/win_helper.h | 49 |
3 files changed, 224 insertions, 15 deletions
diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc index 4cfd400..909904b 100644 --- a/printing/backend/print_backend_win.cc +++ b/printing/backend/print_backend_win.cc @@ -5,7 +5,6 @@ #include "printing/backend/print_backend.h" #include <objidl.h> -#include <prntvpt.h> #include <winspool.h> #include "base/scoped_ptr.h" @@ -17,8 +16,6 @@ #include "printing/backend/print_backend_consts.h" #include "printing/backend/win_helper.h" -#pragma comment(lib, "prntvpt.lib") - using base::win::ScopedBstr; using base::win::ScopedComPtr; using base::win::ScopedHGlobal; @@ -89,7 +86,7 @@ void PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) { bool PrintBackendWin::GetPrinterCapsAndDefaults( const std::string& printer_name, PrinterCapsAndDefaults* printer_info) { - if (!printing::InitXPSModule()) { + if (!XPSModule::Init()) { // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) return false; } @@ -99,7 +96,7 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults( DCHECK(printer_info); HPTPROVIDER provider = NULL; std::wstring printer_name_wide = UTF8ToWide(printer_name); - HRESULT hr = PTOpenProvider(printer_name_wide.c_str(), 1, &provider); + HRESULT hr = XPSModule::OpenProvider(printer_name_wide, 1, &provider); DCHECK(SUCCEEDED(hr)); if (provider) { ScopedComPtr<IStream> print_capabilities_stream; @@ -108,8 +105,10 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults( DCHECK(SUCCEEDED(hr)); if (print_capabilities_stream) { ScopedBstr error; - hr = PTGetPrintCapabilities(provider, NULL, print_capabilities_stream, - error.Receive()); + hr = XPSModule::GetPrintCapabilities(provider, + NULL, + print_capabilities_stream, + error.Receive()); DCHECK(SUCCEEDED(hr)); if (FAILED(hr)) { return false; @@ -140,9 +139,11 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults( printer_defaults_stream.Receive()); DCHECK(SUCCEEDED(hr)); if (printer_defaults_stream) { - hr = PTConvertDevModeToPrintTicket(provider, devmode_size, - devmode_out, kPTJobScope, - printer_defaults_stream); + hr = XPSModule::ConvertDevModeToPrintTicket(provider, + devmode_size, + devmode_out, + kPTJobScope, + printer_defaults_stream); DCHECK(SUCCEEDED(hr)); if (SUCCEEDED(hr)) { hr = StreamOnHGlobalToString(printer_defaults_stream.get(), @@ -153,7 +154,7 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults( } ClosePrinter(printer_handle); } - PTCloseProvider(provider); + XPSModule::CloseProvider(provider); } return true; } diff --git a/printing/backend/win_helper.cc b/printing/backend/win_helper.cc index a5f515f..72f2528 100644 --- a/printing/backend/win_helper.cc +++ b/printing/backend/win_helper.cc @@ -4,14 +4,175 @@ #include "printing/backend/win_helper.h" +#include "base/logging.h" -#include <windows.h> +namespace { +typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name, + DWORD version, + HPTPROVIDER *provider); +typedef HRESULT (WINAPI *PTGetPrintCapabilitiesProc)(HPTPROVIDER provider, + IStream *print_ticket, + IStream *capabilities, + BSTR* error_message); +typedef HRESULT (WINAPI *PTConvertDevModeToPrintTicketProc)( + HPTPROVIDER provider, + ULONG devmode_size_in_bytes, + PDEVMODE devmode, + EPrintTicketScope scope, + IStream* print_ticket); +typedef HRESULT (WINAPI *PTConvertPrintTicketToDevModeProc)( + HPTPROVIDER provider, + IStream* print_ticket, + EDefaultDevmodeType base_devmode_type, + EPrintTicketScope scope, + ULONG* devmode_byte_count, + PDEVMODE *devmode, + BSTR* error_message); +typedef HRESULT (WINAPI *PTMergeAndValidatePrintTicketProc)( + HPTPROVIDER provider, + IStream* base_ticket, + IStream* delta_ticket, + EPrintTicketScope scope, + IStream* result_ticket, + BSTR* error_message); +typedef HRESULT (WINAPI *PTReleaseMemoryProc)(PVOID buffer); +typedef HRESULT (WINAPI *PTCloseProviderProc)(HPTPROVIDER provider); + +PTOpenProviderProc g_open_provider_proc = NULL; +PTGetPrintCapabilitiesProc g_get_print_capabilities_proc = NULL; +PTConvertDevModeToPrintTicketProc g_convert_devmode_to_print_ticket_proc = NULL; +PTConvertPrintTicketToDevModeProc g_convert_print_ticket_to_devmode_proc = NULL; +PTMergeAndValidatePrintTicketProc g_merge_and_validate_print_ticket_proc = NULL; +PTReleaseMemoryProc g_release_memory_proc = NULL; +PTCloseProviderProc g_close_provider_proc = NULL; +} namespace printing { -bool InitXPSModule() { +bool XPSModule::Init() { + static bool initialized = InitImpl(); + return initialized; +} + +bool XPSModule::InitImpl() { HMODULE prntvpt_module = LoadLibrary(L"prntvpt.dll"); - return (NULL != prntvpt_module); + if (prntvpt_module == NULL) + return false; + g_open_provider_proc = reinterpret_cast<PTOpenProviderProc>( + GetProcAddress(prntvpt_module, "PTOpenProvider")); + if (!g_open_provider_proc) { + NOTREACHED(); + return false; + } + g_get_print_capabilities_proc = reinterpret_cast<PTGetPrintCapabilitiesProc>( + GetProcAddress(prntvpt_module, "PTGetPrintCapabilities")); + if (!g_get_print_capabilities_proc) { + NOTREACHED(); + return false; + } + g_convert_devmode_to_print_ticket_proc = + reinterpret_cast<PTConvertDevModeToPrintTicketProc>( + GetProcAddress(prntvpt_module, "PTConvertDevModeToPrintTicket")); + if (!g_convert_devmode_to_print_ticket_proc) { + NOTREACHED(); + return false; + } + g_convert_print_ticket_to_devmode_proc = + reinterpret_cast<PTConvertPrintTicketToDevModeProc>( + GetProcAddress(prntvpt_module, "PTConvertPrintTicketToDevMode")); + if (!g_convert_print_ticket_to_devmode_proc) { + NOTREACHED(); + return false; + } + g_merge_and_validate_print_ticket_proc = + reinterpret_cast<PTMergeAndValidatePrintTicketProc>( + GetProcAddress(prntvpt_module, "PTMergeAndValidatePrintTicket")); + if (!g_merge_and_validate_print_ticket_proc) { + NOTREACHED(); + return false; + } + g_release_memory_proc = + reinterpret_cast<PTReleaseMemoryProc>( + GetProcAddress(prntvpt_module, "PTReleaseMemory")); + if (!g_release_memory_proc) { + NOTREACHED(); + return false; + } + g_close_provider_proc = + reinterpret_cast<PTCloseProviderProc>( + GetProcAddress(prntvpt_module, "PTCloseProvider")); + if (!g_close_provider_proc) { + NOTREACHED(); + return false; + } + return true; +} + +HRESULT XPSModule::OpenProvider(const string16& printer_name, + DWORD version, + HPTPROVIDER *provider) { + return g_open_provider_proc(printer_name.c_str(), version, provider); +} + +HRESULT XPSModule::GetPrintCapabilities(HPTPROVIDER provider, + IStream *print_ticket, + IStream *capabilities, + BSTR* error_message) { + return g_get_print_capabilities_proc(provider, + print_ticket, + capabilities, + error_message); +} + +HRESULT XPSModule::ConvertDevModeToPrintTicket(HPTPROVIDER provider, + ULONG devmode_size_in_bytes, + PDEVMODE devmode, + EPrintTicketScope scope, + IStream* print_ticket) { + return g_convert_devmode_to_print_ticket_proc(provider, + devmode_size_in_bytes, + devmode, + scope, + print_ticket); +} + +HRESULT XPSModule::ConvertPrintTicketToDevMode( + HPTPROVIDER provider, + IStream* print_ticket, + EDefaultDevmodeType base_devmode_type, + EPrintTicketScope scope, + ULONG* devmode_byte_count, + PDEVMODE *devmode, + BSTR* error_message) { + return g_convert_print_ticket_to_devmode_proc(provider, + print_ticket, + base_devmode_type, + scope, + devmode_byte_count, + devmode, + error_message); +} + +HRESULT XPSModule::MergeAndValidatePrintTicket(HPTPROVIDER provider, + IStream* base_ticket, + IStream* delta_ticket, + EPrintTicketScope scope, + IStream* result_ticket, + BSTR* error_message) { + return g_merge_and_validate_print_ticket_proc(provider, + base_ticket, + delta_ticket, + scope, + result_ticket, + error_message); +} + +HRESULT XPSModule::ReleaseMemory(PVOID buffer) { + return g_release_memory_proc(buffer); +} + +HRESULT XPSModule::CloseProvider(HPTPROVIDER provider) { + return g_close_provider_proc(provider); } } // namespace printing diff --git a/printing/backend/win_helper.h b/printing/backend/win_helper.h index a779ad7..8b99a35 100644 --- a/printing/backend/win_helper.h +++ b/printing/backend/win_helper.h @@ -6,10 +6,57 @@ #define PRINTING_BACKEND_WIN_HELPER_H_ #pragma once +#include <objidl.h> +#include <winspool.h> +#include <prntvpt.h> + +#include "base/string16.h" + // These are helper functions for dealing with Windows Printing. namespace printing { -bool InitXPSModule(); +// Wrapper class to wrap the XPS APIs (PTxxx APIs). This is needed because these +// APIs are not available by default on XP. We could delayload prntvpt.dll but +// this would mean having to add that to every binary that links with +// printing.lib (which is a LOT of binaries). So choosing the GetProcAddress +// route instead). +class XPSModule { + public: + // All the other methods can ONLY be called after a successful call to Init. + // Init can be called many times and by multiple threads. + static bool Init(); + static HRESULT OpenProvider(const string16& printer_name, + DWORD version, + HPTPROVIDER *provider); + static HRESULT GetPrintCapabilities(HPTPROVIDER provider, + IStream *print_ticket, + IStream *capabilities, + BSTR* error_message); + static HRESULT ConvertDevModeToPrintTicket(HPTPROVIDER provider, + ULONG devmode_size_in_bytes, + PDEVMODE devmode, + EPrintTicketScope scope, + IStream* print_ticket); + static HRESULT ConvertPrintTicketToDevMode( + HPTPROVIDER provider, + IStream* print_ticket, + EDefaultDevmodeType base_devmode_type, + EPrintTicketScope scope, + ULONG* devmode_byte_count, + PDEVMODE *devmode, + BSTR* error_message); + static HRESULT MergeAndValidatePrintTicket(HPTPROVIDER provider, + IStream* base_ticket, + IStream* delta_ticket, + EPrintTicketScope scope, + IStream* result_ticket, + BSTR* error_message); + static HRESULT ReleaseMemory(PVOID buffer); + static HRESULT CloseProvider(HPTPROVIDER provider); + private: + XPSModule() { } + static bool InitImpl(); +}; } // namespace printing |