OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/service/cloud_print/cdd_conversion_win.h" | 5 #include "chrome/service/cloud_print/cdd_conversion_win.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "components/cloud_devices/common/printer_description.h" | 10 #include "components/cloud_devices/common/printer_description.h" |
11 #include "printing/backend/win_helper.h" | 11 #include "printing/backend/win_helper.h" |
12 | 12 |
13 namespace cloud_print { | 13 namespace cloud_print { |
14 | 14 |
15 bool IsValidCjt(const std::string& print_ticket_data) { | 15 bool IsValidCjt(const std::string& print_ticket_data) { |
16 cloud_devices::CloudDeviceDescription description; | 16 cloud_devices::CloudDeviceDescription description; |
17 return description.InitFromString(print_ticket_data); | 17 return description.InitFromString(print_ticket_data); |
18 } | 18 } |
19 | 19 |
20 scoped_ptr<DEVMODE, base::FreeDeleter> CjtToDevMode( | 20 scoped_ptr<DEVMODE, base::FreeDeleter> CjtToDevMode( |
21 const base::string16& printer_name, | 21 const base::string16& printer_name, |
22 const std::string& print_ticket) { | 22 const std::string& print_ticket) { |
23 scoped_ptr<DEVMODE, base::FreeDeleter> dev_mode; | 23 scoped_ptr<DEVMODE, base::FreeDeleter> dev_mode; |
24 | 24 |
25 cloud_devices::CloudDeviceDescription description; | 25 cloud_devices::CloudDeviceDescription description; |
26 if (!description.InitFromString(print_ticket)) | 26 if (!description.InitFromString(print_ticket)) |
27 return dev_mode.Pass(); | 27 return dev_mode; |
28 | 28 |
29 using namespace cloud_devices::printer; | 29 using namespace cloud_devices::printer; |
30 printing::ScopedPrinterHandle printer; | 30 printing::ScopedPrinterHandle printer; |
31 if (!printer.OpenPrinter(printer_name.c_str())) | 31 if (!printer.OpenPrinter(printer_name.c_str())) |
32 return dev_mode.Pass(); | 32 return dev_mode; |
33 | 33 |
34 { | 34 { |
35 ColorTicketItem color; | 35 ColorTicketItem color; |
36 if (color.LoadFrom(description)) { | 36 if (color.LoadFrom(description)) { |
37 bool is_color = color.value().type == STANDARD_COLOR; | 37 bool is_color = color.value().type == STANDARD_COLOR; |
38 dev_mode = printing::CreateDevModeWithColor(printer.Get(), printer_name, | 38 dev_mode = printing::CreateDevModeWithColor(printer.Get(), printer_name, |
39 is_color); | 39 is_color); |
40 } else { | 40 } else { |
41 dev_mode = printing::CreateDevMode(printer.Get(), NULL); | 41 dev_mode = printing::CreateDevMode(printer.Get(), NULL); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 if (!dev_mode) | 45 if (!dev_mode) |
46 return dev_mode.Pass(); | 46 return dev_mode; |
47 | 47 |
48 ColorTicketItem color; | 48 ColorTicketItem color; |
49 DuplexTicketItem duplex; | 49 DuplexTicketItem duplex; |
50 OrientationTicketItem orientation; | 50 OrientationTicketItem orientation; |
51 MarginsTicketItem margins; | 51 MarginsTicketItem margins; |
52 DpiTicketItem dpi; | 52 DpiTicketItem dpi; |
53 FitToPageTicketItem fit_to_page; | 53 FitToPageTicketItem fit_to_page; |
54 MediaTicketItem media; | 54 MediaTicketItem media; |
55 CopiesTicketItem copies; | 55 CopiesTicketItem copies; |
56 PageRangeTicketItem page_range; | 56 PageRangeTicketItem page_range; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 dev_mode->dmPaperWidth = width; | 124 dev_mode->dmPaperWidth = width; |
125 dev_mode->dmFields |= DM_PAPERLENGTH; | 125 dev_mode->dmFields |= DM_PAPERLENGTH; |
126 dev_mode->dmPaperLength = height; | 126 dev_mode->dmPaperLength = height; |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 return printing::CreateDevMode(printer.Get(), dev_mode.get()); | 130 return printing::CreateDevMode(printer.Get(), dev_mode.get()); |
131 } | 131 } |
132 | 132 |
133 } // namespace cloud_print | 133 } // namespace cloud_print |
OLD | NEW |