| 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 * Component used for searching for a print destination. | 9 * Component used for searching for a print destination. |
| 10 * This is a modal dialog that allows the user to search and select a | 10 * This is a modal dialog that allows the user to search and select a |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 }, | 576 }, |
| 577 | 577 |
| 578 /** | 578 /** |
| 579 * Called when a destination is selected. Clears the search and hides the | 579 * Called when a destination is selected. Clears the search and hides the |
| 580 * widget. If The destination is provisional, it runs provisional | 580 * widget. If The destination is provisional, it runs provisional |
| 581 * destination resolver first. | 581 * destination resolver first. |
| 582 * @param {!print_preview.Destination} destination The selected destination. | 582 * @param {!print_preview.Destination} destination The selected destination. |
| 583 * @private | 583 * @private |
| 584 */ | 584 */ |
| 585 handleOnDestinationSelect_: function(destination) { | 585 handleOnDestinationSelect_: function(destination) { |
| 586 if (destination.origin == print_preview.Destination.Origin.CROS && |
| 587 !destination.capabilities) { |
| 588 // local printers on CrOS require setup. |
| 589 assert(!this.printerConfigurer_); |
| 590 this.printerConfigurer_ = new print_preview.CrosDestinationResolver( |
| 591 this.destinationStore_, destination); |
| 592 this.addChild(this.printerConfigurer_); |
| 593 this.printerConfigurer_.run(this.getElement()) |
| 594 .then( |
| 595 /** |
| 596 * @param {Object} result |
| 597 * An object containing the printerId and capabilities. |
| 598 */ |
| 599 function(result) { |
| 600 assert(result.printerId == destination.id); |
| 601 destination.capabilities = result.capabilities; |
| 602 this.handleOnDestinationSelect_(destination); |
| 603 }.bind(this)) |
| 604 .catch( |
| 605 function() { |
| 606 console.log('Failed to setup destination: ' + destination.id); |
| 607 }) |
| 608 .then( |
| 609 function() { |
| 610 this.removeChild(this.printerConfigurer_); |
| 611 this.printerConfigurer_ = null; |
| 612 }.bind(this)); |
| 613 return; |
| 614 } |
| 615 |
| 586 if (destination.isProvisional) { | 616 if (destination.isProvisional) { |
| 587 assert(!this.provisionalDestinationResolver_, | 617 assert(!this.provisionalDestinationResolver_, |
| 588 'Provisional destination resolver already exists.'); | 618 'Provisional destination resolver already exists.'); |
| 589 this.provisionalDestinationResolver_ = | 619 this.provisionalDestinationResolver_ = |
| 590 print_preview.ProvisionalDestinationResolver.create( | 620 print_preview.ProvisionalDestinationResolver.create( |
| 591 this.destinationStore_, destination); | 621 this.destinationStore_, destination); |
| 592 assert(!!this.provisionalDestinationResolver_, | 622 assert(!!this.provisionalDestinationResolver_, |
| 593 'Unable to create provisional destination resolver'); | 623 'Unable to create provisional destination resolver'); |
| 594 | 624 |
| 595 var lastFocusedElement = document.activeElement; | 625 var lastFocusedElement = document.activeElement; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 onWindowResize_: function() { | 794 onWindowResize_: function() { |
| 765 this.reflowLists_(); | 795 this.reflowLists_(); |
| 766 } | 796 } |
| 767 }; | 797 }; |
| 768 | 798 |
| 769 // Export | 799 // Export |
| 770 return { | 800 return { |
| 771 DestinationSearch: DestinationSearch | 801 DestinationSearch: DestinationSearch |
| 772 }; | 802 }; |
| 773 }); | 803 }); |
| OLD | NEW |