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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** Namespace that contains a method to parse local print destinations. */ | 8 /** Namespace that contains a method to parse local print destinations. */ |
9 function LocalDestinationParser() {}; | 9 function LocalDestinationParser() {}; |
10 | 10 |
11 /** | 11 /** |
12 * Parses a local print destination. | 12 * Parses a local print destination. |
13 * @param {!Object} destinationInfo Information describing a local print | 13 * @param {!Object} destinationInfo Information describing a local print |
14 * destination. | 14 * destination. |
15 * @return {!print_preview.Destination} Parsed local print destination. | 15 * @return {!print_preview.Destination} Parsed local print destination. |
16 */ | 16 */ |
17 LocalDestinationParser.parse = function(destinationInfo) { | 17 LocalDestinationParser.parse = function(destinationInfo) { |
| 18 var options = {'description': destinationInfo.printerDescription}; |
| 19 if (destinationInfo.printerOptions) { |
| 20 // Convert options into cloud print tags format. |
| 21 options.tags = Object.keys(destinationInfo.printerOptions).map( |
| 22 function(key) {return '__cp__' + key + '=' + this[key];}, |
| 23 destinationInfo.printerOptions); |
| 24 } |
18 return new print_preview.Destination( | 25 return new print_preview.Destination( |
19 destinationInfo.deviceName, | 26 destinationInfo.deviceName, |
20 print_preview.Destination.Type.LOCAL, | 27 print_preview.Destination.Type.LOCAL, |
21 print_preview.Destination.Origin.LOCAL, | 28 print_preview.Destination.Origin.LOCAL, |
22 destinationInfo.printerName, | 29 destinationInfo.printerName, |
23 false /*isRecent*/, | 30 false /*isRecent*/, |
24 print_preview.Destination.ConnectionStatus.ONLINE); | 31 print_preview.Destination.ConnectionStatus.ONLINE, |
| 32 options); |
25 }; | 33 }; |
26 | 34 |
27 /** Namespace that contains a method to parse local print capabilities. */ | 35 /** Namespace that contains a method to parse local print capabilities. */ |
28 function LocalCapabilitiesParser() {}; | 36 function LocalCapabilitiesParser() {}; |
29 | 37 |
30 /** | 38 /** |
31 * Parses local print capabilities. | 39 * Parses local print capabilities. |
32 * @param {!Object} settingsInfo Object that describes local print | 40 * @param {!Object} settingsInfo Object that describes local print |
33 * capabilities. | 41 * capabilities. |
34 * @return {!print_preview.Cdd} Parsed local print capabilities. | 42 * @return {!print_preview.Cdd} Parsed local print capabilities. |
35 */ | 43 */ |
36 LocalCapabilitiesParser.parse = function(settingsInfo) { | 44 LocalCapabilitiesParser.parse = function(settingsInfo) { |
37 var cdd = { | 45 var cdd = { |
38 version: '1.0', | 46 version: '1.0', |
39 printer: { | 47 printer: { |
40 collate: {default: true} | 48 collate: {'default': true} |
41 } | 49 } |
42 }; | 50 }; |
43 | 51 |
44 if (!settingsInfo['disableColorOption']) { | 52 if (!settingsInfo['disableColorOption']) { |
45 cdd.printer.color = { | 53 cdd.printer.color = { |
46 option: [ | 54 option: [ |
47 { | 55 { |
48 type: 'STANDARD_COLOR', | 56 type: 'STANDARD_COLOR', |
49 is_default: !!settingsInfo['setColorAsDefault'] | 57 is_default: !!settingsInfo['setColorAsDefault'] |
50 }, | 58 }, |
51 { | 59 { |
52 type: 'STANDARD_MONOCHROME', | 60 type: 'STANDARD_MONOCHROME', |
53 is_default: !settingsInfo['setColorAsDefault'] | 61 is_default: !settingsInfo['setColorAsDefault'] |
54 } | 62 } |
55 ] | 63 ] |
56 } | 64 }; |
57 } | 65 } |
58 | 66 |
59 if (!settingsInfo['disableCopiesOption']) { | 67 if (!settingsInfo['disableCopiesOption']) { |
60 cdd.printer.copies = {default: 1}; | 68 cdd.printer.copies = {'default': 1}; |
61 } | 69 } |
62 | 70 |
63 if (settingsInfo['printerDefaultDuplexValue'] != | 71 if (settingsInfo['printerDefaultDuplexValue'] != |
64 print_preview.NativeLayer.DuplexMode.UNKNOWN_DUPLEX_MODE) { | 72 print_preview.NativeLayer.DuplexMode.UNKNOWN_DUPLEX_MODE) { |
65 cdd.printer.duplex = { | 73 cdd.printer.duplex = { |
66 option: [ | 74 option: [ |
67 {type: 'NO_DUPLEX', is_default: !settingsInfo['setDuplexAsDefault']}, | 75 {type: 'NO_DUPLEX', is_default: !settingsInfo['setDuplexAsDefault']}, |
68 {type: 'LONG_EDGE', is_default: !!settingsInfo['setDuplexAsDefault']} | 76 {type: 'LONG_EDGE', is_default: !!settingsInfo['setDuplexAsDefault']} |
69 ] | 77 ] |
70 }; | 78 }; |
(...skipping 27 matching lines...) Expand all Loading... |
98 print_preview.Destination.Type.LOCAL, | 106 print_preview.Destination.Type.LOCAL, |
99 print_preview.Destination.Origin.PRIVET, | 107 print_preview.Destination.Origin.PRIVET, |
100 destinationInfo.name, | 108 destinationInfo.name, |
101 false /*isRecent*/, | 109 false /*isRecent*/, |
102 print_preview.Destination.ConnectionStatus.ONLINE, | 110 print_preview.Destination.ConnectionStatus.ONLINE, |
103 { cloudID: destinationInfo.cloudID })); | 111 { cloudID: destinationInfo.cloudID })); |
104 } | 112 } |
105 | 113 |
106 if (destinationInfo.isUnregistered) { | 114 if (destinationInfo.isUnregistered) { |
107 returnedPrinters.push(new print_preview.Destination( | 115 returnedPrinters.push(new print_preview.Destination( |
108 destinationInfo.serviceName, | 116 destinationInfo.serviceName, |
109 print_preview.Destination.Type.GOOGLE, | 117 print_preview.Destination.Type.GOOGLE, |
110 print_preview.Destination.Origin.PRIVET, | 118 print_preview.Destination.Origin.PRIVET, |
111 destinationInfo.name, | 119 destinationInfo.name, |
112 false /*isRecent*/, | 120 false /*isRecent*/, |
113 print_preview.Destination.ConnectionStatus.UNREGISTERED)); | 121 print_preview.Destination.ConnectionStatus.UNREGISTERED)); |
114 } | 122 } |
115 | 123 |
116 return returnedPrinters; | 124 return returnedPrinters; |
117 }; | 125 }; |
118 | 126 |
119 // Export | 127 // Export |
120 return { | 128 return { |
121 LocalCapabilitiesParser: LocalCapabilitiesParser, | 129 LocalCapabilitiesParser: LocalCapabilitiesParser, |
122 LocalDestinationParser: LocalDestinationParser, | 130 LocalDestinationParser: LocalDestinationParser, |
123 PrivetDestinationParser: PrivetDestinationParser | 131 PrivetDestinationParser: PrivetDestinationParser |
124 }; | 132 }; |
125 }); | 133 }); |
OLD | NEW |