Added PrinterDriverInfo and PrintBackend::GetPrinterDriverInfo for windows.
BUG=108194 TEST=none Review URL: http://codereview.chromium.org/9516010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125020 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
@ -16,6 +16,10 @@ PrinterCapsAndDefaults::PrinterCapsAndDefaults() {}
|
|||||||
|
|
||||||
PrinterCapsAndDefaults::~PrinterCapsAndDefaults() {}
|
PrinterCapsAndDefaults::~PrinterCapsAndDefaults() {}
|
||||||
|
|
||||||
|
PrinterDriverInfo::PrinterDriverInfo() {}
|
||||||
|
|
||||||
|
PrinterDriverInfo::~PrinterDriverInfo() {}
|
||||||
|
|
||||||
PrintBackend::~PrintBackend() {}
|
PrintBackend::~PrintBackend() {}
|
||||||
|
|
||||||
} // namespace printing
|
} // namespace printing
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
@ -43,6 +43,16 @@ struct PRINTING_EXPORT PrinterCapsAndDefaults {
|
|||||||
std::string defaults_mime_type;
|
std::string defaults_mime_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PRINTING_EXPORT PrinterDriverInfo {
|
||||||
|
PrinterDriverInfo();
|
||||||
|
~PrinterDriverInfo();
|
||||||
|
|
||||||
|
std::string driver_name;
|
||||||
|
std::string driver_version;
|
||||||
|
std::string product_name;
|
||||||
|
std::string product_version;
|
||||||
|
};
|
||||||
|
|
||||||
// PrintBackend class will provide interface for different print backends
|
// PrintBackend class will provide interface for different print backends
|
||||||
// (Windows, CUPS) to implement. User will call CreateInstance() to
|
// (Windows, CUPS) to implement. User will call CreateInstance() to
|
||||||
// obtain available print backend.
|
// obtain available print backend.
|
||||||
@ -66,6 +76,11 @@ class PRINTING_EXPORT PrintBackend
|
|||||||
const std::string& printer_name,
|
const std::string& printer_name,
|
||||||
PrinterCapsAndDefaults* printer_info) = 0;
|
PrinterCapsAndDefaults* printer_info) = 0;
|
||||||
|
|
||||||
|
// Gets the information about driver for a specific printer.
|
||||||
|
virtual bool GetPrinterDriverInfo(
|
||||||
|
const std::string& printer_name,
|
||||||
|
PrinterDriverInfo* driver_info) = 0;
|
||||||
|
|
||||||
// Returns true if printer_name points to a valid printer.
|
// Returns true if printer_name points to a valid printer.
|
||||||
virtual bool IsValidPrinter(const std::string& printer_name) = 0;
|
virtual bool IsValidPrinter(const std::string& printer_name) = 0;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
@ -22,6 +22,9 @@ class PrintBackendChromeOS : public PrintBackend {
|
|||||||
virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name,
|
virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name,
|
||||||
PrinterCapsAndDefaults* printer_info);
|
PrinterCapsAndDefaults* printer_info);
|
||||||
|
|
||||||
|
virtual bool GetPrinterDriverInfo(const std::string& printer_name,
|
||||||
|
PrinterDriverInfo* driver_info);
|
||||||
|
|
||||||
virtual bool IsValidPrinter(const std::string& printer_name);
|
virtual bool IsValidPrinter(const std::string& printer_name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -42,6 +45,13 @@ bool PrintBackendChromeOS::GetPrinterCapsAndDefaults(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PrintBackendChromeOS::GetPrinterDriverInfo(
|
||||||
|
const std::string& printer_name,
|
||||||
|
PrinterDriverInfo* driver_info) {
|
||||||
|
NOTREACHED();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::string PrintBackendChromeOS::GetDefaultPrinterName() {
|
std::string PrintBackendChromeOS::GetDefaultPrinterName() {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,9 @@ class PrintBackendCUPS : public PrintBackend {
|
|||||||
const std::string& printer_name,
|
const std::string& printer_name,
|
||||||
PrinterCapsAndDefaults* printer_info) OVERRIDE;
|
PrinterCapsAndDefaults* printer_info) OVERRIDE;
|
||||||
|
|
||||||
|
virtual bool GetPrinterDriverInfo(const std::string& printer_name,
|
||||||
|
PrinterDriverInfo* driver_info) OVERRIDE;
|
||||||
|
|
||||||
virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE;
|
virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -225,6 +228,12 @@ bool PrintBackendCUPS::GetPrinterCapsAndDefaults(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PrintBackendCUPS::GetPrinterDriverInfo(const std::string& printer_name,
|
||||||
|
PrinterDriverInfo* driver_info) {
|
||||||
|
// TODO(vitalybuka): MAC implementation. http://crbug.com/108194
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) {
|
bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) {
|
||||||
// This is not very efficient way to get specific printer info. CUPS 1.4
|
// This is not very efficient way to get specific printer info. CUPS 1.4
|
||||||
// supports cupsGetNamedDest() function. However, CUPS 1.4 is not available
|
// supports cupsGetNamedDest() function. However, CUPS 1.4 is not available
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <objidl.h>
|
#include <objidl.h>
|
||||||
#include <winspool.h>
|
#include <winspool.h>
|
||||||
|
|
||||||
|
#include "base/file_path.h"
|
||||||
|
#include "base/file_version_info.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "base/string_piece.h"
|
#include "base/string_piece.h"
|
||||||
#include "base/utf_string_conversions.h"
|
#include "base/utf_string_conversions.h"
|
||||||
@ -47,6 +49,9 @@ class PrintBackendWin : public PrintBackend {
|
|||||||
virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name,
|
virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name,
|
||||||
PrinterCapsAndDefaults* printer_info);
|
PrinterCapsAndDefaults* printer_info);
|
||||||
|
|
||||||
|
virtual bool GetPrinterDriverInfo(const std::string& printer_name,
|
||||||
|
PrinterDriverInfo* driver_info);
|
||||||
|
|
||||||
virtual bool IsValidPrinter(const std::string& printer_name);
|
virtual bool IsValidPrinter(const std::string& printer_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -171,10 +176,48 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) {
|
// Gets the information about driver for a specific printer.
|
||||||
std::wstring printer_name_wide = UTF8ToWide(printer_name);
|
bool PrintBackendWin::GetPrinterDriverInfo(const std::string& printer_name,
|
||||||
|
PrinterDriverInfo* driver_info) {
|
||||||
|
DCHECK(driver_info);
|
||||||
ScopedPrinterHandle printer_handle;
|
ScopedPrinterHandle printer_handle;
|
||||||
OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()),
|
if (!::OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()),
|
||||||
|
printer_handle.Receive(), NULL)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
DCHECK(printer_handle.IsValid());
|
||||||
|
DWORD bytes_needed = 0;
|
||||||
|
::GetPrinterDriver(printer_handle, NULL, 6, NULL, 0, &bytes_needed);
|
||||||
|
scoped_array<BYTE> driver_info_buffer(new BYTE[bytes_needed]);
|
||||||
|
if (!bytes_needed || !driver_info_buffer.get())
|
||||||
|
return false;
|
||||||
|
if (!::GetPrinterDriver(printer_handle, NULL, 6, driver_info_buffer.get(),
|
||||||
|
bytes_needed, &bytes_needed)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!bytes_needed)
|
||||||
|
return false;
|
||||||
|
const DRIVER_INFO_6* driver_info_6 =
|
||||||
|
reinterpret_cast<DRIVER_INFO_6*>(driver_info_buffer.get());
|
||||||
|
|
||||||
|
if (driver_info_6->pName)
|
||||||
|
driver_info->driver_name = WideToUTF8(driver_info_6->pName);
|
||||||
|
|
||||||
|
if (driver_info_6->pDriverPath) {
|
||||||
|
scoped_ptr<FileVersionInfo> version_info(
|
||||||
|
FileVersionInfo::CreateFileVersionInfo(
|
||||||
|
FilePath(driver_info_6->pDriverPath)));
|
||||||
|
driver_info->driver_version = WideToUTF8(version_info->file_version());
|
||||||
|
driver_info->product_name = WideToUTF8(version_info->product_name());
|
||||||
|
driver_info->product_version = WideToUTF8(version_info->product_version());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) {
|
||||||
|
ScopedPrinterHandle printer_handle;
|
||||||
|
OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()),
|
||||||
printer_handle.Receive(), NULL);
|
printer_handle.Receive(), NULL);
|
||||||
return printer_handle.IsValid();
|
return printer_handle.IsValid();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user