summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorvitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-22 02:21:11 +0000
committervitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-22 02:21:11 +0000
commited05893e5bad87fb25ba8ce3b74426ad747e24bd (patch)
treeae497b532b3d8856ecba3f53ae46ddf1b6b16b40 /printing
parent421982855791701464fca867481c5d8193f5ec87 (diff)
downloadchromium_src-ed05893e5bad87fb25ba8ce3b74426ad747e24bd.zip
chromium_src-ed05893e5bad87fb25ba8ce3b74426ad747e24bd.tar.gz
chromium_src-ed05893e5bad87fb25ba8ce3b74426ad747e24bd.tar.bz2
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
Diffstat (limited to 'printing')
-rw-r--r--printing/backend/print_backend_consts.cc3
-rw-r--r--printing/backend/print_backend_consts.h3
-rw-r--r--printing/backend/print_backend_cups.cc6
-rw-r--r--printing/backend/print_backend_win.cc76
-rw-r--r--printing/backend/win_helper.cc114
-rw-r--r--printing/backend/win_helper.h10
6 files changed, 149 insertions, 63 deletions
diff --git a/printing/backend/print_backend_consts.cc b/printing/backend/print_backend_consts.cc
index 4891c23..43bd89f 100644
--- a/printing/backend/print_backend_consts.cc
+++ b/printing/backend/print_backend_consts.cc
@@ -1,4 +1,4 @@
-// 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
// found in the LICENSE file.
@@ -8,6 +8,7 @@
const char kLocationTagName[] = "location";
const char kDriverNameTagName[] = "drivername";
+const char kDriverInfoTagName[] = "system_driverinfo";
const char kCUPSPrintServerURL[] = "print_server_url";
const char kCUPSBlocking[] = "cups_blocking";
const char kValueTrue[] = "true";
diff --git a/printing/backend/print_backend_consts.h b/printing/backend/print_backend_consts.h
index 51210f6..88b01fb 100644
--- a/printing/backend/print_backend_consts.h
+++ b/printing/backend/print_backend_consts.h
@@ -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
// found in the LICENSE file.
@@ -10,6 +10,7 @@
PRINTING_EXPORT extern const char kLocationTagName[];
PRINTING_EXPORT extern const char kDriverNameTagName[];
+PRINTING_EXPORT extern const char kDriverInfoTagName[];
PRINTING_EXPORT extern const char kCUPSPrintServerURL[];
PRINTING_EXPORT extern const char kCUPSBlocking[];
PRINTING_EXPORT extern const char kValueTrue[];
diff --git a/printing/backend/print_backend_cups.cc b/printing/backend/print_backend_cups.cc
index c14af03..ae0c553 100644
--- a/printing/backend/print_backend_cups.cc
+++ b/printing/backend/print_backend_cups.cc
@@ -176,6 +176,12 @@ bool PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) {
if (state != NULL)
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.
for (int opt_index = 0; opt_index < printer.num_options; opt_index++) {
printer_info.options[printer.options[opt_index].name] =
diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc
index bed2c67..ae178c7 100644
--- a/printing/backend/print_backend_win.cc
+++ b/printing/backend/print_backend_win.cc
@@ -4,12 +4,9 @@
#include "printing/backend/print_backend.h"
-#include <algorithm>
#include <objidl.h>
#include <winspool.h>
-#include "base/file_path.h"
-#include "base/file_version_info.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_piece.h"
#include "base/utf_string_conversions.h"
@@ -59,12 +56,13 @@ bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) {
DCHECK(printer_list);
DWORD bytes_needed = 0;
DWORD count_returned = 0;
- BOOL ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2,
- NULL, 0, &bytes_needed, &count_returned);
+ const DWORD kLevel = 4;
+ BOOL ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL,
+ kLevel, NULL, 0, &bytes_needed, &count_returned);
if (!bytes_needed)
return false;
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,
&count_returned);
DCHECK(ret);
@@ -72,22 +70,16 @@ bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) {
return false;
std::string default_printer = GetDefaultPrinterName();
- PRINTER_INFO_2* printer_info =
- reinterpret_cast<PRINTER_INFO_2*>(printer_info_buffer.get());
+ PRINTER_INFO_4* printer_info =
+ reinterpret_cast<PRINTER_INFO_4*>(printer_info_buffer.get());
for (DWORD index = 0; index < count_returned; index++) {
+ ScopedPrinterHandle printer;
+ OpenPrinter(printer_info[index].pPrinterName, printer.Receive(), NULL);
PrinterBasicInfo info;
- info.printer_name = WideToUTF8(printer_info[index].pPrinterName);
- info.is_default = (info.printer_name == default_printer);
- if (printer_info[index].pComment)
- 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);
+ if (InitBasicPrinterInfo(printer, &info)) {
+ info.is_default = (info.printer_name == default_printer);
+ printer_list->push_back(info);
+ }
}
return true;
}
@@ -179,48 +171,12 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
// Gets the information about driver for a specific printer.
std::string PrintBackendWin::GetPrinterDriverInfo(
const std::string& printer_name) {
- std::string driver_info;
- ScopedPrinterHandle printer_handle;
+ ScopedPrinterHandle printer;
if (!::OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()),
- printer_handle.Receive(), NULL)) {
- return driver_info;
- }
- 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(";");
+ printer.Receive(), NULL)) {
+ return std::string();
}
-
- return driver_info;
+ return GetDriverInfo(printer);
}
bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) {
diff --git a/printing/backend/win_helper.cc b/printing/backend/win_helper.cc
index b163a65..eba284e 100644
--- a/printing/backend/win_helper.cc
+++ b/printing/backend/win_helper.cc
@@ -1,10 +1,17 @@
-// 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
// found in the LICENSE file.
#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/utf_string_conversions.h"
+#include "printing/backend/print_backend.h"
+#include "printing/backend/print_backend_consts.h"
namespace {
typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name,
@@ -57,6 +64,49 @@ PTMergeAndValidatePrintTicketProc g_merge_and_validate_print_ticket_proc = NULL;
PTReleaseMemoryProc g_release_memory_proc = NULL;
PTCloseProviderProc g_close_provider_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 {
@@ -260,4 +310,66 @@ HRESULT XPSPrintModule::StartXpsPrintJob(
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
diff --git a/printing/backend/win_helper.h b/printing/backend/win_helper.h
index 667609d..7c35cbe 100644
--- a/printing/backend/win_helper.h
+++ b/printing/backend/win_helper.h
@@ -11,6 +11,9 @@
#include <prntvpt.h>
#include <xpsprint.h>
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "base/win/scoped_handle.h"
#include "printing/printing_export.h"
@@ -18,6 +21,8 @@
// These are helper functions for dealing with Windows Printing.
namespace printing {
+struct PRINTING_EXPORT PrinterBasicInfo;
+
class PrinterHandleTraits {
public:
typedef HANDLE Handle;
@@ -120,6 +125,11 @@ class PRINTING_EXPORT XPSPrintModule {
static bool InitImpl();
};
+PRINTING_EXPORT bool InitBasicPrinterInfo(HANDLE printer,
+ PrinterBasicInfo* printer_info);
+
+PRINTING_EXPORT std::string GetDriverInfo(HANDLE printer);
+
} // namespace printing
#endif // PRINTING_BACKEND_WIN_HELPER_H_