summaryrefslogtreecommitdiffstats
path: root/printing/printing_context_win.cc
diff options
context:
space:
mode:
authorarthurhsu@chromium.org <arthurhsu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-03 21:08:39 +0000
committerarthurhsu@chromium.org <arthurhsu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-03 21:08:39 +0000
commit30aaa81a9dce3070eaf510db99f16aec94f12a46 (patch)
tree89e6ef761417c5996cd61d8d11b1a0d6da15aeb1 /printing/printing_context_win.cc
parent95c528232f3f8f750f17ac8ddd806f15bc677be8 (diff)
downloadchromium_src-30aaa81a9dce3070eaf510db99f16aec94f12a46.zip
chromium_src-30aaa81a9dce3070eaf510db99f16aec94f12a46.tar.gz
chromium_src-30aaa81a9dce3070eaf510db99f16aec94f12a46.tar.bz2
Update set printer function to be local-only to avoid permission issues.
BUG=80760 TEST=none Review URL: http://codereview.chromium.org/6893149 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83964 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/printing_context_win.cc')
-rw-r--r--printing/printing_context_win.cc45
1 files changed, 35 insertions, 10 deletions
diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc
index 74de8ba..7a64df6 100644
--- a/printing/printing_context_win.cc
+++ b/printing/printing_context_win.cc
@@ -305,7 +305,7 @@ PrintingContext::Result PrintingContextWin::UpdatePrintSettings(
const PageRanges& ranges) {
DCHECK(!in_print_job_);
- bool is_landscape, is_collate, is_color;
+ bool is_landscape, is_collate, is_color, is_printToPDF;
string16 printer_name;
int copies, duplex_mode;
if (!job_settings.GetBoolean(kSettingLandscape, &is_landscape) ||
@@ -313,26 +313,45 @@ PrintingContext::Result PrintingContextWin::UpdatePrintSettings(
!job_settings.GetInteger(kSettingCopies, &copies) ||
!job_settings.GetBoolean(kSettingCollate, &is_collate) ||
!job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) ||
- !job_settings.GetBoolean(kSettingColor, &is_color)) {
+ !job_settings.GetBoolean(kSettingColor, &is_color) ||
+ !job_settings.GetBoolean(kSettingPrintToPDF, &is_printToPDF)) {
return OnError();
}
+ if (is_printToPDF) {
+ // Pseudo printer: handle orientation and ranges only.
+ settings_.SetOrientation(is_landscape);
+ settings_.ranges = ranges;
+ return OK;
+ }
+
// Underlying |settings_| do not have these attributes, so we need to
// operate on printer directly, which involves reloading settings.
// Therefore, reset the settings anyway.
ResetSettings();
HANDLE printer;
- if (!OpenPrinter(const_cast<wchar_t*>(printer_name.c_str()),
- &printer, NULL)) {
+ LPWSTR printer_name_wide = const_cast<wchar_t*>(printer_name.c_str());
+ if (!OpenPrinter(printer_name_wide, &printer, NULL))
return OnError();
- }
+ // Make printer changes local to Chrome.
+ // See MSDN documentation regarding DocumentProperties.
scoped_array<uint8> buffer;
- int level;
DEVMODE* dev_mode = NULL;
- if (!GetPrinterInfo(printer, printer_name, &level, &buffer, &dev_mode) ||
- dev_mode == NULL) {
+ LONG buffer_size = DocumentProperties(NULL, printer, printer_name_wide,
+ NULL, NULL, 0);
+ if (buffer_size) {
+ buffer.reset(new uint8[buffer_size]);
+ memset(buffer.get(), 0, buffer_size);
+ if (DocumentProperties(NULL, printer, printer_name_wide,
+ reinterpret_cast<PDEVMODE>(buffer.get()), NULL,
+ DM_OUT_BUFFER) == IDOK) {
+ dev_mode = reinterpret_cast<PDEVMODE>(buffer.get());
+ }
+ }
+ if (dev_mode == NULL) {
+ buffer.reset();
ClosePrinter(printer);
return OnError();
}
@@ -355,9 +374,15 @@ PrintingContext::Result PrintingContextWin::UpdatePrintSettings(
dev_mode->dmOrientation = is_landscape ? DMORIENT_LANDSCAPE :
DMORIENT_PORTRAIT;
+ // Update data using DocumentProperties.
+ if (DocumentProperties(NULL, printer, printer_name_wide, dev_mode, dev_mode,
+ DM_IN_BUFFER | DM_OUT_BUFFER) != IDOK) {
+ ClosePrinter(printer);
+ return OnError();
+ }
+
// Set printer then refresh printer settings.
- if (!SetPrinter(printer, level, buffer.get(), 0) ||
- !AllocateContext(printer_name, dev_mode, &context_)) {
+ if (!AllocateContext(printer_name, dev_mode, &context_)) {
ClosePrinter(printer);
return OnError();
}