1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "printing/backend/printing_info_win.h" 6 7 #include "base/logging.h" 8 9 namespace printing { 10 11 namespace internal { 12 13 uint8* GetDriverInfo(HANDLE printer, int level) { 14 DWORD size = 0; 15 ::GetPrinterDriver(printer, NULL, level, NULL, 0, &size); 16 if (size == 0) { 17 return NULL; 18 } 19 scoped_ptr<uint8[]> buffer(new uint8[size]); 20 memset(buffer.get(), 0, size); 21 if (!::GetPrinterDriver(printer, NULL, level, buffer.get(), size, &size)) { 22 return NULL; 23 } 24 return buffer.release(); 25 } 26 27 uint8* GetPrinterInfo(HANDLE printer, int level) { 28 DWORD size = 0; 29 ::GetPrinter(printer, level, NULL, 0, &size); 30 if (size == 0) { 31 LOG(WARNING) << "Failed to get size of PRINTER_INFO_" << level << 32 ", error = " << GetLastError(); 33 return NULL; 34 } 35 scoped_ptr<uint8[]> buffer(new uint8[size]); 36 memset(buffer.get(), 0, size); 37 if (!::GetPrinter(printer, level, buffer.get(), size, &size)) { 38 LOG(WARNING) << "Failed to get PRINTER_INFO_" << level << 39 ", error = " << GetLastError(); 40 return NULL; 41 } 42 return buffer.release(); 43 } 44 45 } // namespace internal 46 47 UserDefaultDevMode::UserDefaultDevMode() : dev_mode_(NULL) { 48 } 49 50 bool UserDefaultDevMode::Init(HANDLE printer) { 51 if (info_9_.Init(printer)) 52 dev_mode_ = info_9_.get()->pDevMode; 53 54 if (!dev_mode_ && info_8_.Init(printer)) 55 dev_mode_ = info_8_.get()->pDevMode; 56 57 if (!dev_mode_ && info_2_.Init(printer)) 58 dev_mode_ = info_2_.get()->pDevMode; 59 60 return dev_mode_ != NULL; 61 } 62 63 UserDefaultDevMode::~UserDefaultDevMode() { 64 } 65 66 } // namespace printing 67