Chromium Code Reviews| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 /** | 193 /** |
| 194 * Local destinations are CROS destinations on ChromeOS because they require | 194 * Local destinations are CROS destinations on ChromeOS because they require |
| 195 * extra setup. | 195 * extra setup. |
| 196 * @type {!print_preview.DestinationOrigin} | 196 * @type {!print_preview.DestinationOrigin} |
| 197 * @private | 197 * @private |
| 198 */ | 198 */ |
| 199 this.platformOrigin_ = cr.isChromeOS ? | 199 this.platformOrigin_ = cr.isChromeOS ? |
| 200 print_preview.DestinationOrigin.CROS : | 200 print_preview.DestinationOrigin.CROS : |
| 201 print_preview.DestinationOrigin.LOCAL; | 201 print_preview.DestinationOrigin.LOCAL; |
| 202 | 202 |
| 203 /** | |
| 204 * Whether to default to the system default printer instead of the most | |
| 205 * recent destination. | |
| 206 * @type {boolean} | |
| 207 * @private | |
| 208 */ | |
| 209 this.useSystemDefaultAsDefault_ = | |
| 210 loadTimeData.getBoolean('useSystemDefaultPrinter'); | |
| 211 | |
| 203 this.addEventListeners_(); | 212 this.addEventListeners_(); |
| 204 this.reset_(); | 213 this.reset_(); |
| 205 } | 214 } |
| 206 | 215 |
| 207 /** | 216 /** |
| 208 * Event types dispatched by the data store. | 217 * Event types dispatched by the data store. |
| 209 * @enum {string} | 218 * @enum {string} |
| 210 */ | 219 */ |
| 211 DestinationStore.EventType = { | 220 DestinationStore.EventType = { |
| 212 DESTINATION_SEARCH_DONE: | 221 DESTINATION_SEARCH_DONE: |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 } | 621 } |
| 613 | 622 |
| 614 var origin = null; | 623 var origin = null; |
| 615 var id = ''; | 624 var id = ''; |
| 616 var account = ''; | 625 var account = ''; |
| 617 var name = ''; | 626 var name = ''; |
| 618 var capabilities = null; | 627 var capabilities = null; |
| 619 var extensionId = ''; | 628 var extensionId = ''; |
| 620 var extensionName = ''; | 629 var extensionName = ''; |
| 621 var foundDestination = false; | 630 var foundDestination = false; |
| 622 if (this.appState_.recentDestinations) { | 631 if (this.appState_.recentDestinations) { |
|
skau
2017/06/15 19:41:31
Can !this.useSystemDefaultAsDefault_ be moved here
rbpotter
2017/06/16 02:21:46
Think we still want to mark the recent destination
| |
| 623 // Run through the destinations forward. As soon as we find a | 632 // Run through the destinations forward. As soon as we find a |
| 624 // destination, don't select any future destinations, just mark | 633 // destination, don't select any future destinations, just mark |
| 625 // them recent. Otherwise, there is a race condition between selecting | 634 // them recent. Otherwise, there is a race condition between selecting |
| 626 // destinations/updating the print ticket and this selecting a new | 635 // destinations/updating the print ticket and this selecting a new |
| 627 // destination that causes random print preview errors. | 636 // destination that causes random print preview errors. |
| 628 for (var i = 0; i < this.appState_.recentDestinations.length; i++) { | 637 for (var i = 0; i < this.appState_.recentDestinations.length; i++) { |
| 629 origin = this.appState_.recentDestinations[i].origin; | 638 origin = this.appState_.recentDestinations[i].origin; |
| 630 id = this.appState_.recentDestinations[i].id; | 639 id = this.appState_.recentDestinations[i].id; |
| 631 account = this.appState_.recentDestinations[i].account || ''; | 640 account = this.appState_.recentDestinations[i].account || ''; |
| 632 name = this.appState_.recentDestinations[i].name || ''; | 641 name = this.appState_.recentDestinations[i].name || ''; |
| 633 capabilities = this.appState_.recentDestinations[i].capabilities; | 642 capabilities = this.appState_.recentDestinations[i].capabilities; |
| 634 extensionId = this.appState_.recentDestinations[i].extensionId || | 643 extensionId = this.appState_.recentDestinations[i].extensionId || |
| 635 ''; | 644 ''; |
| 636 extensionName = | 645 extensionName = |
| 637 this.appState_.recentDestinations[i].extensionName || ''; | 646 this.appState_.recentDestinations[i].extensionName || ''; |
| 638 var candidate = | 647 var candidate = |
| 639 this.destinationMap_[this.getDestinationKey_(origin, | 648 this.destinationMap_[this.getDestinationKey_(origin, |
| 640 id, account)]; | 649 id, account)]; |
| 641 if (candidate != null) { | 650 if (candidate != null) { |
| 642 if (!foundDestination) | 651 if (!foundDestination && !this.useSystemDefaultAsDefault_) |
| 643 this.selectDestination(candidate); | 652 this.selectDestination(candidate); |
| 644 candidate.isRecent = true; | 653 candidate.isRecent = true; |
| 645 foundDestination = true; | 654 foundDestination = true; |
| 646 } else if (!foundDestination) { | 655 } else if (!foundDestination && !this.useSystemDefaultAsDefault_) { |
| 647 foundDestination = this.fetchPreselectedDestination_( | 656 foundDestination = this.fetchPreselectedDestination_( |
| 648 origin, | 657 origin, |
| 649 id, | 658 id, |
| 650 account, | 659 account, |
| 651 name, | 660 name, |
| 652 capabilities, | 661 capabilities, |
| 653 extensionId, | 662 extensionId, |
| 654 extensionName); | 663 extensionName); |
| 655 } | 664 } |
| 656 } | 665 } |
| 657 } | 666 } |
| 658 if (foundDestination) return; | 667 if (foundDestination && !this.useSystemDefaultAsDefault_) return; |
| 659 | 668 |
| 660 // Try the system default | 669 // Try the system default |
| 661 id = this.systemDefaultDestinationId_ || ''; | 670 id = this.systemDefaultDestinationId_ || ''; |
| 662 origin = id == print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ? | 671 origin = id == print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ? |
| 663 print_preview.DestinationOrigin.LOCAL : | 672 print_preview.DestinationOrigin.LOCAL : |
| 664 this.platformOrigin_; | 673 this.platformOrigin_; |
| 665 account = ''; | 674 account = ''; |
| 666 var candidate = | 675 var candidate = |
| 667 this.destinationMap_[this.getDestinationKey_(origin, id, account)]; | 676 this.destinationMap_[this.getDestinationKey_(origin, id, account)]; |
| 668 if (candidate != null) { | 677 if (candidate != null) { |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1695 return this.getDestinationKey_( | 1704 return this.getDestinationKey_( |
| 1696 destination.origin, destination.id, destination.account); | 1705 destination.origin, destination.id, destination.account); |
| 1697 } | 1706 } |
| 1698 }; | 1707 }; |
| 1699 | 1708 |
| 1700 // Export | 1709 // Export |
| 1701 return { | 1710 return { |
| 1702 DestinationStore: DestinationStore | 1711 DestinationStore: DestinationStore |
| 1703 }; | 1712 }; |
| 1704 }); | 1713 }); |
| OLD | NEW |