summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorarthurhsu@chromium.org <arthurhsu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-18 21:35:48 +0000
committerarthurhsu@chromium.org <arthurhsu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-18 21:35:48 +0000
commitff3ccc2f254ec879c4f7e2d2095a2b2aabeb57b4 (patch)
treec4db4a9a8190e24ae896c20e8276970531c0670e /printing
parent96aa01940bfdf48da820b5d25cbec3fed5039faf (diff)
downloadchromium_src-ff3ccc2f254ec879c4f7e2d2095a2b2aabeb57b4.zip
chromium_src-ff3ccc2f254ec879c4f7e2d2095a2b2aabeb57b4.tar.gz
chromium_src-ff3ccc2f254ec879c4f7e2d2095a2b2aabeb57b4.tar.bz2
Attempt to fetch first printer's settings to bootstrap the printing process if there are printers but none is set as default.
BUG=21265 TEST=attempt to print with no default printer set. Please refer to bug report about how to setup this. Review URL: http://codereview.chromium.org/6866001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r--printing/printing_context_win.cc44
1 files changed, 40 insertions, 4 deletions
diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc
index 1acdc6a..8d6252d 100644
--- a/printing/printing_context_win.cc
+++ b/printing/printing_context_win.cc
@@ -203,11 +203,47 @@ PrintingContext::Result PrintingContextWin::UseDefaultSettings() {
PRINTDLG dialog_options = { sizeof(PRINTDLG) };
dialog_options.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
- if (PrintDlg(&dialog_options) == 0) {
- ResetSettings();
- return FAILED;
+ if (PrintDlg(&dialog_options))
+ return ParseDialogResult(dialog_options);
+
+ // No default printer configured, do we have any printers at all?
+ DWORD bytes_needed = 0;
+ DWORD count_returned = 0;
+ (void)::EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS,
+ NULL, 2, NULL, 0, &bytes_needed, &count_returned);
+ if (bytes_needed) {
+ DCHECK(bytes_needed >= count_returned * sizeof(PRINTER_INFO_2));
+ scoped_array<BYTE> printer_info_buffer(new BYTE[bytes_needed]);
+ BOOL ret = ::EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS,
+ NULL, 2, printer_info_buffer.get(),
+ bytes_needed, &bytes_needed,
+ &count_returned);
+ if (ret && count_returned) { // have printers
+ // Open the first successfully found printer.
+ for (DWORD count = 0; count < count_returned; count++) {
+ PRINTER_INFO_2* info_2;
+ info_2 = reinterpret_cast<PRINTER_INFO_2*>(
+ printer_info_buffer.get() + count * sizeof(PRINTER_INFO_2));
+ std::wstring printer_name = info_2->pPrinterName;
+ if (info_2->pDevMode == NULL || printer_name.length() == 0)
+ continue;
+ if (!AllocateContext(printer_name, info_2->pDevMode, &context_))
+ break;
+ if (InitializeSettings(*info_2->pDevMode, printer_name,
+ NULL, 0, false))
+ break;
+ if (context_) {
+ ::DeleteDC(context_);
+ context_ = NULL;
+ }
+ }
+ if (context_)
+ return OK;
+ }
}
- return ParseDialogResult(dialog_options);
+
+ ResetSettings();
+ return FAILED;
}
PrintingContext::Result PrintingContextWin::UpdatePrintSettings(