Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: chrome/browser/resources/print_preview/data/destination_store.js

Issue 2516523002: Fix CrOS reverting to Save as PDF and random PDF preview fail (Closed)
Patch Set: Add helper Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/print_preview/data/app_state.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 649
650 /** 650 /**
651 * @return {boolean} Whether a search for cloud destinations is in progress. 651 * @return {boolean} Whether a search for cloud destinations is in progress.
652 */ 652 */
653 get isCloudDestinationSearchInProgress() { 653 get isCloudDestinationSearchInProgress() {
654 return !!this.cloudPrintInterface_ && 654 return !!this.cloudPrintInterface_ &&
655 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; 655 this.cloudPrintInterface_.isCloudDestinationSearchInProgress;
656 }, 656 },
657 657
658 /** 658 /**
659 * @return {boolean} Whether the selected destination is valid.
660 */
661 selectedDestinationValid_: function() {
662 return this.appState_.selectedDestination &&
dpapad 2016/11/21 18:08:56 Nit: This method only refers to |this.appState_| m
663 this.appState_.selectedDestination.id &&
664 this.appState_.selectedDestination.origin;
665 },
666
667 /*
659 * Initializes the destination store. Sets the initially selected 668 * Initializes the destination store. Sets the initially selected
660 * destination. If any inserted destinations match this ID, that destination 669 * destination. If any inserted destinations match this ID, that destination
661 * will be automatically selected. This method must be called after the 670 * will be automatically selected. This method must be called after the
662 * print_preview.AppState has been initialized. 671 * print_preview.AppState has been initialized.
663 * @param {boolean} isInAppKioskMode Whether the print preview is in App 672 * @param {boolean} isInAppKioskMode Whether the print preview is in App
664 * Kiosk mode. 673 * Kiosk mode.
665 * @param {?string} systemDefaultDestinationId ID of the system default 674 * @param {?string} systemDefaultDestinationId ID of the system default
666 * destination. 675 * destination.
667 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized 676 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
668 * default destination selection rules. 677 * default destination selection rules.
669 */ 678 */
670 init: function( 679 init: function(
671 isInAppKioskMode, 680 isInAppKioskMode,
672 systemDefaultDestinationId, 681 systemDefaultDestinationId,
673 serializedDefaultDestinationSelectionRulesStr) { 682 serializedDefaultDestinationSelectionRulesStr) {
674 this.pdfPrinterEnabled_ = !isInAppKioskMode; 683 this.pdfPrinterEnabled_ = !isInAppKioskMode;
675 this.systemDefaultDestinationId_ = systemDefaultDestinationId; 684 this.systemDefaultDestinationId_ = systemDefaultDestinationId;
676 this.createLocalPdfPrintDestination_(); 685 this.createLocalPdfPrintDestination_();
677 686
678 if (!this.appState_.selectedDestinationId || 687 if (!this.selectedDestinationValid_()) {
679 !this.appState_.selectedDestinationOrigin) {
680 var destinationMatch = this.convertToDestinationMatch_( 688 var destinationMatch = this.convertToDestinationMatch_(
681 serializedDefaultDestinationSelectionRulesStr); 689 serializedDefaultDestinationSelectionRulesStr);
682 if (destinationMatch) { 690 if (destinationMatch) {
683 this.fetchMatchingDestination_(destinationMatch); 691 this.fetchMatchingDestination_(destinationMatch);
684 return; 692 return;
685 } 693 }
686 } 694 }
687 695
688 if (!this.systemDefaultDestinationId_ && 696 if (!this.systemDefaultDestinationId_ &&
689 !(this.appState_.selectedDestinationId && 697 !this.selectedDestinationValid_()) {
690 this.appState_.selectedDestinationOrigin)) {
691 this.selectPdfDestination_(); 698 this.selectPdfDestination_();
692 return; 699 return;
693 } 700 }
694 701
695 var origin = print_preview.Destination.Origin.LOCAL; 702 var origin = print_preview.Destination.Origin.LOCAL;
696 var id = this.systemDefaultDestinationId_; 703 var id = this.systemDefaultDestinationId_;
697 var account = ''; 704 var account = '';
698 var name = ''; 705 var name = '';
699 var capabilities = null; 706 var capabilities = null;
700 var extensionId = ''; 707 var extensionId = '';
701 var extensionName = ''; 708 var extensionName = '';
702 var foundDestination = false; 709 var foundDestination = false;
703 if (this.appState_.recentDestinations) { 710 if (this.appState_.recentDestinations) {
704 // Run through the destinations backwards the most recently used is set 711 // Run through the destinations forward. As soon as we find a
705 // as the initially selected destination. 712 // destination, don't select any future destinations, just mark
706 for (var i = this.appState_.recentDestinations.length - 1; i >= 0; 713 // them recent. Otherwise, there is a race condition between selecting
707 i--) { 714 // destinations/updating the print ticket and this selecting a new
715 // destination that causes random print preview errors.
716 for (var i = 0; i < this.appState_.recentDestinations.length; i++) {
708 origin = this.appState_.recentDestinations[i].origin; 717 origin = this.appState_.recentDestinations[i].origin;
709 id = this.appState_.recentDestinations[i].id; 718 id = this.appState_.recentDestinations[i].id;
710 account = this.appState_.recentDestinations[i].account || ''; 719 account = this.appState_.recentDestinations[i].account || '';
711 name = this.appState_.recentDestinations[i].name || ''; 720 name = this.appState_.recentDestinations[i].name || '';
712 capabilities = this.appState_.recentDestinations[i].capabilities; 721 capabilities = this.appState_.recentDestinations[i].capabilities;
713 extensionId = this.appState_.recentDestinations[i].extensionId || 722 extensionId = this.appState_.recentDestinations[i].extensionId ||
714 ''; 723 '';
715 extensionName = 724 extensionName =
716 this.appState_.recentDestinations[i].extensionName || ''; 725 this.appState_.recentDestinations[i].extensionName || '';
717 var candidate = 726 var candidate =
718 this.destinationMap_[this.getDestinationKey_(origin, 727 this.destinationMap_[this.getDestinationKey_(origin,
719 id, account)]; 728 id, account)];
720 if (candidate != null) { 729 if (candidate != null) {
721 this.selectDestination(candidate); 730 if (!foundDestination)
731 this.selectDestination(candidate);
722 candidate.isRecent = true; 732 candidate.isRecent = true;
723 foundDestination = true; 733 foundDestination = true;
724 } else { 734 } else if (!foundDestination) {
725 foundDestination = this.fetchPreselectedDestination_( 735 foundDestination = this.fetchPreselectedDestination_(
726 origin, 736 origin,
727 id, 737 id,
728 account, 738 account,
729 name, 739 name,
730 capabilities, 740 capabilities,
731 extensionId, 741 extensionId,
732 extensionName); 742 extensionName);
733 } 743 }
734 } 744 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 displayNameRegExp, 942 displayNameRegExp,
933 true /*skipVirtualDestinations*/); 943 true /*skipVirtualDestinations*/);
934 }, 944 },
935 945
936 /** 946 /**
937 * @return {print_preview.DestinationMatch} Creates rules matching 947 * @return {print_preview.DestinationMatch} Creates rules matching
938 * previously selected destination. 948 * previously selected destination.
939 * @private 949 * @private
940 */ 950 */
941 convertPreselectedToDestinationMatch_: function() { 951 convertPreselectedToDestinationMatch_: function() {
942 if (this.appState_.selectedDestinationId && 952 if (this.selectedDestinationValid_()) {
943 this.appState_.selectedDestinationOrigin) {
944 return this.createExactDestinationMatch_( 953 return this.createExactDestinationMatch_(
945 this.appState_.selectedDestinationOrigin, 954 this.appState_.selectedDestination.origin,
946 this.appState_.selectedDestinationId); 955 this.appState_.selectedDestination.id);
947 } 956 }
948 if (this.systemDefaultDestinationId_) { 957 if (this.systemDefaultDestinationId_) {
949 return this.createExactDestinationMatch_( 958 return this.createExactDestinationMatch_(
950 print_preview.Destination.Origin.LOCAL, 959 print_preview.Destination.Origin.LOCAL,
951 this.systemDefaultDestinationId_); 960 this.systemDefaultDestinationId_);
952 } 961 }
953 return null; 962 return null;
954 }, 963 },
955 964
956 /** 965 /**
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 destination.capabilities_); 1346 destination.capabilities_);
1338 destination.capabilities_ = DestinationStore.sortMediaSizes_( 1347 destination.capabilities_ = DestinationStore.sortMediaSizes_(
1339 destination.capabilities_); 1348 destination.capabilities_);
1340 var existingDestination = this.destinationMap_[this.getKey_(destination)]; 1349 var existingDestination = this.destinationMap_[this.getKey_(destination)];
1341 if (existingDestination != null) { 1350 if (existingDestination != null) {
1342 existingDestination.capabilities = destination.capabilities; 1351 existingDestination.capabilities = destination.capabilities;
1343 } else { 1352 } else {
1344 this.insertDestination_(destination); 1353 this.insertDestination_(destination);
1345 } 1354 }
1346 1355
1347 if (existingDestination == this.selectedDestination_ || 1356 if (this.selectedDestination_ &&
1348 destination == this.selectedDestination_) { 1357 (existingDestination == this.selectedDestination_ ||
1358 destination == this.selectedDestination_)) {
1349 this.appState_.persistSelectedDestination(this.selectedDestination_); 1359 this.appState_.persistSelectedDestination(this.selectedDestination_);
1350 cr.dispatchSimpleEvent( 1360 cr.dispatchSimpleEvent(
1351 this, 1361 this,
1352 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); 1362 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY);
1353 } 1363 }
1354 }, 1364 },
1355 1365
1356 /** 1366 /**
1357 * Called when the search for Privet printers is done. 1367 * Called when the search for Privet printers is done.
1358 * @private 1368 * @private
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 return this.getDestinationKey_( 1754 return this.getDestinationKey_(
1745 destination.origin, destination.id, destination.account); 1755 destination.origin, destination.id, destination.account);
1746 } 1756 }
1747 }; 1757 };
1748 1758
1749 // Export 1759 // Export
1750 return { 1760 return {
1751 DestinationStore: DestinationStore 1761 DestinationStore: DestinationStore
1752 }; 1762 };
1753 }); 1763 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/data/app_state.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698