Commit a749d928 authored by Alan Screen's avatar Alan Screen Committed by Commit Bot

Add ability to detect support for OpenXPS

Windows printing path is being modernized from using the pre-WinXP
GDI print API to an XPS-based API.  This was first introduced
introduced Windows 7 and was deprecated in favor of OpenXPS in
Windows 8 and beyond.  Some Windows 7 installations may be capable of
OpenXPS if they have been sufficiently patched [1].

Need ability to determine the Windows XPS API version required for
interfacing with the print subsystem.

[1] https://docs.microsoft.com/en-us/windows/win32/printdocs/app-support-for-openxps-printing#sending-xps-data-to-the-print-system

Bug: 1008222
Change-Id: Ieb82ec5ef13ecff17c10b16284132bc45aa64dc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1826006Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Alan Screen <awscreen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702142}
parent 500a245e
......@@ -12,6 +12,7 @@
#include "base/debug/alias.h"
#include "base/file_version_info.h"
#include "base/file_version_info_win.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/memory/free_deleter.h"
......@@ -128,6 +129,19 @@ const char kXpsTicketTemplate[] =
const char kXpsTicketColor[] = "Color";
const char kXpsTicketMonochrome[] = "Monochrome";
bool IsOpenXpsCapableImpl() {
std::unique_ptr<FileVersionInfoWin> file_version_info =
FileVersionInfoWin::CreateFileVersionInfoWin(
base::FilePath(FILE_PATH_LITERAL("xpsprint.dll")));
if (!file_version_info)
return false; // Cannot support OpenXPS without system support.
// Need at least version 6.2.9200.16492 to support OpenXPS, per:
// https://support.microsoft.com/en-us/help/2670838/platform-update-for-windows-7-sp1-and-windows-server-2008-r2-sp1
const base::Version kOpenXpsMinVersion("6.2.9200.16492");
return file_version_info->GetFileVersion() >= kOpenXpsMinVersion;
}
} // namespace
namespace printing {
......@@ -152,6 +166,14 @@ bool ScopedPrinterHandle::OpenPrinterWithName(const wchar_t* printer) {
return IsValid();
}
// static
bool XPSModule::IsOpenXpsCapable() {
// TODO(awscreen): Can be removed once Chrome drops support for Windows 7,
// since everything from Windows 8 onward is all OpenXPS.
static const bool capable = IsOpenXpsCapableImpl();
return capable;
}
bool XPSModule::Init() {
static bool initialized = InitImpl();
return initialized;
......
......@@ -76,6 +76,9 @@ using ScopedPrinterChangeHandle =
// route instead).
class PRINTING_EXPORT XPSModule {
public:
// Returns true if OpenXPS printing is supported.
static bool IsOpenXpsCapable();
// 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();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment