| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 177       this.initialDestinationId_ = initialDestinationId; | 177       this.initialDestinationId_ = initialDestinationId; | 
| 178       this.isInAutoSelectMode_ = true; | 178       this.isInAutoSelectMode_ = true; | 
| 179       if (this.initialDestinationId_ == null) { | 179       if (this.initialDestinationId_ == null) { | 
| 180         assert(this.destinations_.length > 0, | 180         assert(this.destinations_.length > 0, | 
| 181                'No destinations available to select'); | 181                'No destinations available to select'); | 
| 182         this.selectDestination(this.destinations_[0]); | 182         this.selectDestination(this.destinations_[0]); | 
| 183       } else { | 183       } else { | 
| 184         var candidate = this.destinationMap_[this.initialDestinationId_]; | 184         var candidate = this.destinationMap_[this.initialDestinationId_]; | 
| 185         if (candidate != null) { | 185         if (candidate != null) { | 
| 186           this.selectDestination(candidate); | 186           this.selectDestination(candidate); | 
|  | 187         } else { | 
|  | 188           // Try and fetch the destination | 
|  | 189           // TODO(rltoscano): Since we don't know if the initialDestinationId is | 
|  | 190           // a local printer or a cloud printer, we are going to assume based on | 
|  | 191           // platform. The C++ layer should be modified to return more | 
|  | 192           // information about the initially selected printer so this assumption | 
|  | 193           // does not have to be made. See http://crbug.com/132831. | 
|  | 194           if (!cr.isChromeOS) { | 
|  | 195             this.nativeLayer_.startGetLocalDestinationCapabilities( | 
|  | 196                 initialDestinationId); | 
|  | 197           } | 
| 187         } | 198         } | 
| 188       } | 199       } | 
| 189     }, | 200     }, | 
| 190 | 201 | 
| 191     /** | 202     /** | 
| 192      * Sets the destination store's Google Cloud Print interface. | 203      * Sets the destination store's Google Cloud Print interface. | 
| 193      * @param {!print_preview.CloudPrintInterface} cloudPrintInterface Interface | 204      * @param {!print_preview.CloudPrintInterface} cloudPrintInterface Interface | 
| 194      *     to set. | 205      *     to set. | 
| 195      */ | 206      */ | 
| 196     setCloudPrintInterface: function(cloudPrintInterface) { | 207     setCloudPrintInterface: function(cloudPrintInterface) { | 
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 385      */ | 396      */ | 
| 386     onLocalDestinationsSet_: function(event) { | 397     onLocalDestinationsSet_: function(event) { | 
| 387       var localDestinations = event.destinationInfos.map(function(destInfo) { | 398       var localDestinations = event.destinationInfos.map(function(destInfo) { | 
| 388         return print_preview.LocalDestinationParser.parse(destInfo); | 399         return print_preview.LocalDestinationParser.parse(destInfo); | 
| 389       }); | 400       }); | 
| 390       this.insertDestinations(localDestinations); | 401       this.insertDestinations(localDestinations); | 
| 391     }, | 402     }, | 
| 392 | 403 | 
| 393     /** | 404     /** | 
| 394      * Called when the native layer retrieves the capabilities for the selected | 405      * Called when the native layer retrieves the capabilities for the selected | 
| 395      * local destination. | 406      * local destination. Updates the destination with new capabilities if the | 
|  | 407      * destination already exists, otherwise it creates a new destination and | 
|  | 408      * then updates its capabilities. | 
| 396      * @param {cr.Event} event Contains the capabilities of the local print | 409      * @param {cr.Event} event Contains the capabilities of the local print | 
| 397      *     destination. | 410      *     destination. | 
| 398      * @private | 411      * @private | 
| 399      */ | 412      */ | 
| 400     onLocalDestinationCapabilitiesSet_: function(event) { | 413     onLocalDestinationCapabilitiesSet_: function(event) { | 
| 401       // TODO(rltoscano): There may be a race condition here. This method is | 414       var destinationId = event.settingsInfo['printerId']; | 
| 402       // assumed to return capabilities for the currently selected printer. But | 415       var destination = this.destinationMap_[destinationId]; | 
| 403       // between the time the local printer was selected and the capabilities | 416       var capabilities = print_preview.LocalCapabilitiesParser.parse( | 
| 404       // were retrieved, the selected printer can change. One way to address |  | 
| 405       // this is to include the destination ID in the event.settingsInfo |  | 
| 406       // parameter. |  | 
| 407       if (this.selectedDestination_ && this.selectedDestination_.isLocal) { |  | 
| 408         var capabilities = print_preview.LocalCapabilitiesParser.parse( |  | 
| 409             event.settingsInfo); | 417             event.settingsInfo); | 
| 410         this.selectedDestination_.capabilities = capabilities; | 418       if (destination) { | 
| 411         cr.dispatchSimpleEvent( | 419         destination.capabilities = capabilities; | 
| 412             this, | 420         if (this.selectedDestination_ && | 
| 413             DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); | 421             this.selectedDestination_.id == destinationId) { | 
|  | 422           cr.dispatchSimpleEvent(this, | 
|  | 423                                  DestinationStore.EventType. | 
|  | 424                                      SELECTED_DESTINATION_CAPABILITIES_READY); | 
|  | 425         } | 
|  | 426       } else { | 
|  | 427         // TODO(rltoscano): This makes the assumption that the "deviceName" is | 
|  | 428         // the same as "printerName". We should include the "printerName" in the | 
|  | 429         // response. See http://crbug.com/132831. | 
|  | 430         destination = print_preview.LocalDestinationParser.parse( | 
|  | 431             {deviceName: destinationId, printerName: destinationId}); | 
|  | 432         destination.capabilities = capabilities; | 
|  | 433         this.insertDestination(destination); | 
| 414       } | 434       } | 
| 415     }, | 435     }, | 
| 416 | 436 | 
| 417     /** | 437     /** | 
| 418      * Called when the /search call completes. Adds the fetched printers to the | 438      * Called when the /search call completes. Adds the fetched printers to the | 
| 419      * destination store. | 439      * destination store. | 
| 420      * @param {cr.Event} event Contains the fetched printers. | 440      * @param {cr.Event} event Contains the fetched printers. | 
| 421      * @private | 441      * @private | 
| 422      */ | 442      */ | 
| 423     onCloudPrintSearchDone_: function(event) { | 443     onCloudPrintSearchDone_: function(event) { | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 464              'No destinations were loaded before auto-select timeout expired'); | 484              'No destinations were loaded before auto-select timeout expired'); | 
| 465       this.selectDestination(this.destinations_[0]); | 485       this.selectDestination(this.destinations_[0]); | 
| 466     } | 486     } | 
| 467   }; | 487   }; | 
| 468 | 488 | 
| 469   // Export | 489   // Export | 
| 470   return { | 490   return { | 
| 471     DestinationStore: DestinationStore | 491     DestinationStore: DestinationStore | 
| 472   }; | 492   }; | 
| 473 }); | 493 }); | 
| OLD | NEW | 
|---|