| 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 /** | 8 /** |
| 9 * A data store that stores destinations and dispatches events when the data | 9 * A data store that stores destinations and dispatches events when the data |
| 10 * store changes. | 10 * store changes. |
| (...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 * Called when the native layer retrieves the capabilities for the selected | 1242 * Called when the native layer retrieves the capabilities for the selected |
| 1243 * local destination. Updates the destination with new capabilities if the | 1243 * local destination. Updates the destination with new capabilities if the |
| 1244 * destination already exists, otherwise it creates a new destination and | 1244 * destination already exists, otherwise it creates a new destination and |
| 1245 * then updates its capabilities. | 1245 * then updates its capabilities. |
| 1246 * @param {Event} event Contains the capabilities of the local print | 1246 * @param {Event} event Contains the capabilities of the local print |
| 1247 * destination. | 1247 * destination. |
| 1248 * @private | 1248 * @private |
| 1249 */ | 1249 */ |
| 1250 onLocalDestinationCapabilitiesSet_: function(event) { | 1250 onLocalDestinationCapabilitiesSet_: function(event) { |
| 1251 var destinationId = event.settingsInfo['printerId']; | 1251 var destinationId = event.settingsInfo['printerId']; |
| 1252 var printerName = event.settingsInfo['printerName']; |
| 1253 var printerDescription = event.settingsInfo['printerDescription']; |
| 1252 var key = this.getDestinationKey_( | 1254 var key = this.getDestinationKey_( |
| 1253 print_preview.Destination.Origin.LOCAL, | 1255 print_preview.Destination.Origin.LOCAL, |
| 1254 destinationId, | 1256 destinationId, |
| 1255 ''); | 1257 ''); |
| 1256 var destination = this.destinationMap_[key]; | 1258 var destination = this.destinationMap_[key]; |
| 1257 var capabilities = DestinationStore.localizeCapabilities_( | 1259 var capabilities = DestinationStore.localizeCapabilities_( |
| 1258 event.settingsInfo.capabilities); | 1260 event.settingsInfo.capabilities); |
| 1259 // Special case for PDF printer (until local printers capabilities are | 1261 // Special case for PDF printer (until local printers capabilities are |
| 1260 // reported in CDD format too). | 1262 // reported in CDD format too). |
| 1261 if (destinationId == | 1263 if (destinationId == |
| 1262 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { | 1264 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
| 1263 if (destination) { | 1265 if (destination) { |
| 1264 destination.capabilities = capabilities; | 1266 destination.capabilities = capabilities; |
| 1265 } | 1267 } |
| 1266 } else { | 1268 } else { |
| 1267 if (destination) { | 1269 if (destination) { |
| 1268 // In case there were multiple capabilities request for this local | 1270 // In case there were multiple capabilities request for this local |
| 1269 // destination, just ignore the later ones. | 1271 // destination, just ignore the later ones. |
| 1270 if (destination.capabilities != null) { | 1272 if (destination.capabilities != null) { |
| 1271 return; | 1273 return; |
| 1272 } | 1274 } |
| 1273 destination.capabilities = capabilities; | 1275 destination.capabilities = capabilities; |
| 1274 } else { | 1276 } else { |
| 1275 // TODO(rltoscano): This makes the assumption that the "deviceName" is | |
| 1276 // the same as "printerName". We should include the "printerName" in | |
| 1277 // the response. See http://crbug.com/132831. | |
| 1278 destination = print_preview.LocalDestinationParser.parse( | 1277 destination = print_preview.LocalDestinationParser.parse( |
| 1279 {deviceName: destinationId, printerName: destinationId}); | 1278 {deviceName: destinationId, |
| 1279 printerName: printerName, |
| 1280 printerDescription: printerDescription}); |
| 1280 destination.capabilities = capabilities; | 1281 destination.capabilities = capabilities; |
| 1281 this.insertDestination_(destination); | 1282 this.insertDestination_(destination); |
| 1282 } | 1283 } |
| 1283 } | 1284 } |
| 1284 if (this.selectedDestination_ && | 1285 if (this.selectedDestination_ && |
| 1285 this.selectedDestination_.id == destinationId) { | 1286 this.selectedDestination_.id == destinationId) { |
| 1286 cr.dispatchSimpleEvent(this, | 1287 cr.dispatchSimpleEvent( |
| 1287 DestinationStore.EventType. | 1288 this, |
| 1288 SELECTED_DESTINATION_CAPABILITIES_READY); | 1289 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); |
| 1289 } | 1290 } |
| 1290 }, | 1291 }, |
| 1291 | 1292 |
| 1292 /** | 1293 /** |
| 1293 * Called when a request to get a local destination's print capabilities | 1294 * Called when a request to get a local destination's print capabilities |
| 1294 * fails. If the destination is the initial destination, auto-select another | 1295 * fails. If the destination is the initial destination, auto-select another |
| 1295 * destination instead. | 1296 * destination instead. |
| 1296 * @param {Event} event Contains the destination ID that failed. | 1297 * @param {Event} event Contains the destination ID that failed. |
| 1297 * @private | 1298 * @private |
| 1298 */ | 1299 */ |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 return this.getDestinationKey_( | 1472 return this.getDestinationKey_( |
| 1472 destination.origin, destination.id, destination.account); | 1473 destination.origin, destination.id, destination.account); |
| 1473 } | 1474 } |
| 1474 }; | 1475 }; |
| 1475 | 1476 |
| 1476 // Export | 1477 // Export |
| 1477 return { | 1478 return { |
| 1478 DestinationStore: DestinationStore | 1479 DestinationStore: DestinationStore |
| 1479 }; | 1480 }; |
| 1480 }); | 1481 }); |
| OLD | NEW |