OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/backend/print_backend.h" | 5 #include "printing/backend/print_backend.h" |
6 | 6 |
7 #include <objidl.h> | 7 #include <objidl.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <winspool.h> | 9 #include <winspool.h> |
10 | 10 |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 if (!IsValidPrinter(printer_name)) { | 315 if (!IsValidPrinter(printer_name)) { |
316 return false; | 316 return false; |
317 } | 317 } |
318 DCHECK(printer_info); | 318 DCHECK(printer_info); |
319 HPTPROVIDER provider = NULL; | 319 HPTPROVIDER provider = NULL; |
320 std::wstring printer_name_wide = base::UTF8ToWide(printer_name); | 320 std::wstring printer_name_wide = base::UTF8ToWide(printer_name); |
321 HRESULT hr = XPSModule::OpenProvider(printer_name_wide, 1, &provider); | 321 HRESULT hr = XPSModule::OpenProvider(printer_name_wide, 1, &provider); |
322 if (provider) { | 322 if (provider) { |
323 base::win::ScopedComPtr<IStream> print_capabilities_stream; | 323 base::win::ScopedComPtr<IStream> print_capabilities_stream; |
324 hr = CreateStreamOnHGlobal(NULL, TRUE, | 324 hr = CreateStreamOnHGlobal(NULL, TRUE, |
325 print_capabilities_stream.Receive()); | 325 print_capabilities_stream.GetAddressOf()); |
326 DCHECK(SUCCEEDED(hr)); | 326 DCHECK(SUCCEEDED(hr)); |
327 if (print_capabilities_stream.Get()) { | 327 if (print_capabilities_stream.Get()) { |
328 base::win::ScopedBstr error; | 328 base::win::ScopedBstr error; |
329 hr = XPSModule::GetPrintCapabilities( | 329 hr = XPSModule::GetPrintCapabilities( |
330 provider, NULL, print_capabilities_stream.Get(), error.Receive()); | 330 provider, NULL, print_capabilities_stream.Get(), error.Receive()); |
331 DCHECK(SUCCEEDED(hr)); | 331 DCHECK(SUCCEEDED(hr)); |
332 if (FAILED(hr)) { | 332 if (FAILED(hr)) { |
333 return false; | 333 return false; |
334 } | 334 } |
335 hr = StreamOnHGlobalToString(print_capabilities_stream.Get(), | 335 hr = StreamOnHGlobalToString(print_capabilities_stream.Get(), |
336 &printer_info->printer_capabilities); | 336 &printer_info->printer_capabilities); |
337 DCHECK(SUCCEEDED(hr)); | 337 DCHECK(SUCCEEDED(hr)); |
338 printer_info->caps_mime_type = "text/xml"; | 338 printer_info->caps_mime_type = "text/xml"; |
339 } | 339 } |
340 ScopedPrinterHandle printer_handle; | 340 ScopedPrinterHandle printer_handle; |
341 if (printer_handle.OpenPrinter(printer_name_wide.c_str())) { | 341 if (printer_handle.OpenPrinter(printer_name_wide.c_str())) { |
342 std::unique_ptr<DEVMODE, base::FreeDeleter> devmode_out( | 342 std::unique_ptr<DEVMODE, base::FreeDeleter> devmode_out( |
343 CreateDevMode(printer_handle.Get(), NULL)); | 343 CreateDevMode(printer_handle.Get(), NULL)); |
344 if (!devmode_out) | 344 if (!devmode_out) |
345 return false; | 345 return false; |
346 base::win::ScopedComPtr<IStream> printer_defaults_stream; | 346 base::win::ScopedComPtr<IStream> printer_defaults_stream; |
347 hr = CreateStreamOnHGlobal(NULL, TRUE, | 347 hr = CreateStreamOnHGlobal(NULL, TRUE, |
348 printer_defaults_stream.Receive()); | 348 printer_defaults_stream.GetAddressOf()); |
349 DCHECK(SUCCEEDED(hr)); | 349 DCHECK(SUCCEEDED(hr)); |
350 if (printer_defaults_stream.Get()) { | 350 if (printer_defaults_stream.Get()) { |
351 DWORD dm_size = devmode_out->dmSize + devmode_out->dmDriverExtra; | 351 DWORD dm_size = devmode_out->dmSize + devmode_out->dmDriverExtra; |
352 hr = XPSModule::ConvertDevModeToPrintTicket( | 352 hr = XPSModule::ConvertDevModeToPrintTicket( |
353 provider, dm_size, devmode_out.get(), kPTJobScope, | 353 provider, dm_size, devmode_out.get(), kPTJobScope, |
354 printer_defaults_stream.Get()); | 354 printer_defaults_stream.Get()); |
355 DCHECK(SUCCEEDED(hr)); | 355 DCHECK(SUCCEEDED(hr)); |
356 if (SUCCEEDED(hr)) { | 356 if (SUCCEEDED(hr)) { |
357 hr = StreamOnHGlobalToString(printer_defaults_stream.Get(), | 357 hr = StreamOnHGlobalToString(printer_defaults_stream.Get(), |
358 &printer_info->printer_defaults); | 358 &printer_info->printer_defaults); |
(...skipping 22 matching lines...) Expand all Loading... |
381 return printer_handle.OpenPrinter(base::UTF8ToWide(printer_name).c_str()); | 381 return printer_handle.OpenPrinter(base::UTF8ToWide(printer_name).c_str()); |
382 } | 382 } |
383 | 383 |
384 // static | 384 // static |
385 scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl( | 385 scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl( |
386 const base::DictionaryValue* print_backend_settings) { | 386 const base::DictionaryValue* print_backend_settings) { |
387 return new PrintBackendWin; | 387 return new PrintBackendWin; |
388 } | 388 } |
389 | 389 |
390 } // namespace printing | 390 } // namespace printing |
OLD | NEW |