Driver related info would be included into PrinterBasicInfo::options so it...

Driver related info would be included into PrinterBasicInfo::options so it would be uploaded to cloud print backend.


BUG=118797
TEST=none

Review URL: http://codereview.chromium.org/9812002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128141 0039d316-1c4b-4281-b951-d872f2087c98
parent 42198285
...@@ -225,33 +225,7 @@ class PrintSystemWatcherWin : public base::win::ObjectWatcher::Delegate { ...@@ -225,33 +225,7 @@ class PrintSystemWatcherWin : public base::win::ObjectWatcher::Delegate {
bool GetCurrentPrinterInfo(printing::PrinterBasicInfo* printer_info) { bool GetCurrentPrinterInfo(printing::PrinterBasicInfo* printer_info) {
DCHECK(printer_info); DCHECK(printer_info);
if (!printer_.IsValid()) return InitBasicPrinterInfo(printer_, printer_info);
return false;
DWORD bytes_needed = 0;
bool ret = false;
GetPrinter(printer_, 2, NULL, 0, &bytes_needed);
if (0 != bytes_needed) {
scoped_array<BYTE> printer_info_buffer(new BYTE[bytes_needed]);
if (GetPrinter(printer_, 2, printer_info_buffer.get(),
bytes_needed, &bytes_needed)) {
PRINTER_INFO_2* printer_info_win =
reinterpret_cast<PRINTER_INFO_2*>(printer_info_buffer.get());
printer_info->printer_name = WideToUTF8(printer_info_win->pPrinterName);
if (printer_info_win->pComment)
printer_info->printer_description =
WideToUTF8(printer_info_win->pComment);
if (printer_info_win->pLocation)
printer_info->options[kLocationTagName] =
WideToUTF8(printer_info_win->pLocation);
if (printer_info_win->pDriverName)
printer_info->options[kDriverNameTagName] =
WideToUTF8(printer_info_win->pDriverName);
printer_info->printer_status = printer_info_win->Status;
ret = true;
}
}
return ret;
} }
private: private:
......
// Copyright (c) 2010 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.
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
const char kLocationTagName[] = "location"; const char kLocationTagName[] = "location";
const char kDriverNameTagName[] = "drivername"; const char kDriverNameTagName[] = "drivername";
const char kDriverInfoTagName[] = "system_driverinfo";
const char kCUPSPrintServerURL[] = "print_server_url"; const char kCUPSPrintServerURL[] = "print_server_url";
const char kCUPSBlocking[] = "cups_blocking"; const char kCUPSBlocking[] = "cups_blocking";
const char kValueTrue[] = "true"; const char kValueTrue[] = "true";
......
// 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.
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
PRINTING_EXPORT extern const char kLocationTagName[]; PRINTING_EXPORT extern const char kLocationTagName[];
PRINTING_EXPORT extern const char kDriverNameTagName[]; PRINTING_EXPORT extern const char kDriverNameTagName[];
PRINTING_EXPORT extern const char kDriverInfoTagName[];
PRINTING_EXPORT extern const char kCUPSPrintServerURL[]; PRINTING_EXPORT extern const char kCUPSPrintServerURL[];
PRINTING_EXPORT extern const char kCUPSBlocking[]; PRINTING_EXPORT extern const char kCUPSBlocking[];
PRINTING_EXPORT extern const char kValueTrue[]; PRINTING_EXPORT extern const char kValueTrue[];
......
...@@ -176,6 +176,12 @@ bool PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) { ...@@ -176,6 +176,12 @@ bool PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) {
if (state != NULL) if (state != NULL)
base::StringToInt(state, &printer_info.printer_status); base::StringToInt(state, &printer_info.printer_status);
const char* drv_info = cupsGetOption(kCUPSPrinterMakeModelOpt,
printer.num_options,
printer.options);
if (drv_info)
printer_info.options[kDriverInfoTagName] = *drv_info;
// Store printer options. // Store printer options.
for (int opt_index = 0; opt_index < printer.num_options; opt_index++) { for (int opt_index = 0; opt_index < printer.num_options; opt_index++) {
printer_info.options[printer.options[opt_index].name] = printer_info.options[printer.options[opt_index].name] =
......
...@@ -4,12 +4,9 @@ ...@@ -4,12 +4,9 @@
#include "printing/backend/print_backend.h" #include "printing/backend/print_backend.h"
#include <algorithm>
#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"
...@@ -59,12 +56,13 @@ bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) { ...@@ -59,12 +56,13 @@ bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) {
DCHECK(printer_list); DCHECK(printer_list);
DWORD bytes_needed = 0; DWORD bytes_needed = 0;
DWORD count_returned = 0; DWORD count_returned = 0;
BOOL ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, const DWORD kLevel = 4;
NULL, 0, &bytes_needed, &count_returned); BOOL ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL,
kLevel, NULL, 0, &bytes_needed, &count_returned);
if (!bytes_needed) if (!bytes_needed)
return false; return false;
scoped_array<BYTE> printer_info_buffer(new BYTE[bytes_needed]); scoped_array<BYTE> printer_info_buffer(new BYTE[bytes_needed]);
ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, kLevel,
printer_info_buffer.get(), bytes_needed, &bytes_needed, printer_info_buffer.get(), bytes_needed, &bytes_needed,
&count_returned); &count_returned);
DCHECK(ret); DCHECK(ret);
...@@ -72,22 +70,16 @@ bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) { ...@@ -72,22 +70,16 @@ bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) {
return false; return false;
std::string default_printer = GetDefaultPrinterName(); std::string default_printer = GetDefaultPrinterName();
PRINTER_INFO_2* printer_info = PRINTER_INFO_4* printer_info =
reinterpret_cast<PRINTER_INFO_2*>(printer_info_buffer.get()); reinterpret_cast<PRINTER_INFO_4*>(printer_info_buffer.get());
for (DWORD index = 0; index < count_returned; index++) { for (DWORD index = 0; index < count_returned; index++) {
ScopedPrinterHandle printer;
OpenPrinter(printer_info[index].pPrinterName, printer.Receive(), NULL);
PrinterBasicInfo info; PrinterBasicInfo info;
info.printer_name = WideToUTF8(printer_info[index].pPrinterName); if (InitBasicPrinterInfo(printer, &info)) {
info.is_default = (info.printer_name == default_printer); info.is_default = (info.printer_name == default_printer);
if (printer_info[index].pComment) printer_list->push_back(info);
info.printer_description = WideToUTF8(printer_info[index].pComment); }
info.printer_status = printer_info[index].Status;
if (printer_info[index].pLocation)
info.options[kLocationTagName] =
WideToUTF8(printer_info[index].pLocation);
if (printer_info[index].pDriverName)
info.options[kDriverNameTagName] =
WideToUTF8(printer_info[index].pDriverName);
printer_list->push_back(info);
} }
return true; return true;
} }
...@@ -179,48 +171,12 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults( ...@@ -179,48 +171,12 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
// Gets the information about driver for a specific printer. // Gets the information about driver for a specific printer.
std::string PrintBackendWin::GetPrinterDriverInfo( std::string PrintBackendWin::GetPrinterDriverInfo(
const std::string& printer_name) { const std::string& printer_name) {
std::string driver_info; ScopedPrinterHandle printer;
ScopedPrinterHandle printer_handle;
if (!::OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()), if (!::OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()),
printer_handle.Receive(), NULL)) { printer.Receive(), NULL)) {
return driver_info; return std::string();
}
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 driver_info;
if (!::GetPrinterDriver(printer_handle, NULL, 6, driver_info_buffer.get(),
bytes_needed, &bytes_needed)) {
return driver_info;
}
if (!bytes_needed)
return driver_info;
const DRIVER_INFO_6* driver_info_6 =
reinterpret_cast<DRIVER_INFO_6*>(driver_info_buffer.get());
std::string info[4];
if (driver_info_6->pName)
info[0] = WideToUTF8(driver_info_6->pName);
if (driver_info_6->pDriverPath) {
scoped_ptr<FileVersionInfo> version_info(
FileVersionInfo::CreateFileVersionInfo(
FilePath(driver_info_6->pDriverPath)));
info[1] = WideToUTF8(version_info->file_version());
info[2] = WideToUTF8(version_info->product_name());
info[3] = WideToUTF8(version_info->product_version());
}
for (size_t i = 0; i < arraysize(info); ++i) {
std::replace(info[i].begin(), info[i].end(), ';', ',');
driver_info.append(info[i]);
driver_info.append(";");
} }
return GetDriverInfo(printer);
return driver_info;
} }
bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) { bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) {
......
// Copyright (c) 2010 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.
#include "printing/backend/win_helper.h" #include "printing/backend/win_helper.h"
#include <algorithm>
#include "base/file_path.h"
#include "base/file_version_info.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "printing/backend/print_backend.h"
#include "printing/backend/print_backend_consts.h"
namespace { namespace {
typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name, typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name,
...@@ -57,6 +64,49 @@ PTMergeAndValidatePrintTicketProc g_merge_and_validate_print_ticket_proc = NULL; ...@@ -57,6 +64,49 @@ PTMergeAndValidatePrintTicketProc g_merge_and_validate_print_ticket_proc = NULL;
PTReleaseMemoryProc g_release_memory_proc = NULL; PTReleaseMemoryProc g_release_memory_proc = NULL;
PTCloseProviderProc g_close_provider_proc = NULL; PTCloseProviderProc g_close_provider_proc = NULL;
StartXpsPrintJobProc g_start_xps_print_job_proc = NULL; StartXpsPrintJobProc g_start_xps_print_job_proc = NULL;
// Returns pointer to structure allocated in |buffer|. So pointer is only valide
// until |buffer| is destroyed.
const PRINTER_INFO_2* GetPrinterInfo2(HANDLE printer,
scoped_array<BYTE>* buffer) {
DCHECK(printer);
DCHECK(buffer);
DWORD bytes_needed = 0;
const DWORD kLevel = 2;
::GetPrinter(printer, kLevel, NULL, 0, &bytes_needed);
if (!bytes_needed)
return NULL;
buffer->reset(new BYTE[bytes_needed]);
if (!buffer->get())
return NULL;
if (!::GetPrinter(printer, kLevel, buffer->get(), bytes_needed,
&bytes_needed)) {
return NULL;
}
return reinterpret_cast<const PRINTER_INFO_2*>(buffer->get());
}
// Returns pointer to structure allocated in |buffer|. So pointer is only valide
// until |buffer| is destroyed.
const DRIVER_INFO_6* GetDriverInfo6(HANDLE printer,
scoped_array<BYTE>* buffer) {
DCHECK(printer);
DCHECK(buffer);
DWORD bytes_needed = 0;
const DWORD kLevel = 6;
::GetPrinterDriver(printer, NULL, kLevel, NULL, 0, &bytes_needed);
if (!bytes_needed)
return NULL;
buffer->reset(new BYTE[bytes_needed]);
if (!buffer->get())
return NULL;
if (!::GetPrinterDriver(printer, NULL, kLevel, buffer->get(), bytes_needed,
&bytes_needed)) {
return NULL;
}
return reinterpret_cast<const DRIVER_INFO_6*>(buffer->get());
}
} }
namespace printing { namespace printing {
...@@ -260,4 +310,66 @@ HRESULT XPSPrintModule::StartXpsPrintJob( ...@@ -260,4 +310,66 @@ HRESULT XPSPrintModule::StartXpsPrintJob(
print_ticket_stream); print_ticket_stream);
} }
bool InitBasicPrinterInfo(HANDLE printer, PrinterBasicInfo* printer_info) {
DCHECK(printer);
DCHECK(printer_info);
if (!printer)
return false;
scoped_array<BYTE> printer_info_buffer;
const PRINTER_INFO_2* info2 = GetPrinterInfo2(printer, &printer_info_buffer);
if (!info2)
return false;
printer_info->printer_name = WideToUTF8(info2->pPrinterName);
if (info2->pComment)
printer_info->printer_description =
WideToUTF8(info2->pComment);
if (info2->pLocation)
printer_info->options[kLocationTagName] =
WideToUTF8(info2->pLocation);
if (info2->pDriverName)
printer_info->options[kDriverNameTagName] =
WideToUTF8(info2->pDriverName);
printer_info->printer_status = info2->Status;
std::string driver_info = GetDriverInfo(printer);
if (!driver_info.empty())
printer_info->options[kDriverInfoTagName] = driver_info;
return true;
}
std::string GetDriverInfo(HANDLE printer) {
DCHECK(printer);
std::string driver_info;
if (!printer)
return driver_info;
scoped_array<BYTE> driver_info_buffer;
const DRIVER_INFO_6* driver = GetDriverInfo6(printer, &driver_info_buffer);
if (!driver)
return driver_info;
std::string info[4];
if (driver->pName)
info[0] = WideToUTF8(driver->pName);
if (driver->pDriverPath) {
scoped_ptr<FileVersionInfo> version_info(
FileVersionInfo::CreateFileVersionInfo(
FilePath(driver->pDriverPath)));
info[1] = WideToUTF8(version_info->file_version());
info[2] = WideToUTF8(version_info->product_name());
info[3] = WideToUTF8(version_info->product_version());
}
for (size_t i = 0; i < arraysize(info); ++i) {
std::replace(info[i].begin(), info[i].end(), ';', ',');
driver_info.append(info[i]);
driver_info.append(";");
}
return driver_info;
}
} // namespace printing } // namespace printing
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include <prntvpt.h> #include <prntvpt.h>
#include <xpsprint.h> #include <xpsprint.h>
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/string16.h" #include "base/string16.h"
#include "base/win/scoped_handle.h" #include "base/win/scoped_handle.h"
#include "printing/printing_export.h" #include "printing/printing_export.h"
...@@ -18,6 +21,8 @@ ...@@ -18,6 +21,8 @@
// These are helper functions for dealing with Windows Printing. // These are helper functions for dealing with Windows Printing.
namespace printing { namespace printing {
struct PRINTING_EXPORT PrinterBasicInfo;
class PrinterHandleTraits { class PrinterHandleTraits {
public: public:
typedef HANDLE Handle; typedef HANDLE Handle;
...@@ -120,6 +125,11 @@ class PRINTING_EXPORT XPSPrintModule { ...@@ -120,6 +125,11 @@ class PRINTING_EXPORT XPSPrintModule {
static bool InitImpl(); static bool InitImpl();
}; };
PRINTING_EXPORT bool InitBasicPrinterInfo(HANDLE printer,
PrinterBasicInfo* printer_info);
PRINTING_EXPORT std::string GetDriverInfo(HANDLE printer);
} // namespace printing } // namespace printing
#endif // PRINTING_BACKEND_WIN_HELPER_H_ #endif // PRINTING_BACKEND_WIN_HELPER_H_
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