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

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

Issue 2514303002: M56: Fix CrOS reverting to Save as PDF and random PDF preview fail (Closed)
Patch Set: Created 4 years 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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 643
644 /** 644 /**
645 * @return {boolean} Whether a search for cloud destinations is in progress. 645 * @return {boolean} Whether a search for cloud destinations is in progress.
646 */ 646 */
647 get isCloudDestinationSearchInProgress() { 647 get isCloudDestinationSearchInProgress() {
648 return !!this.cloudPrintInterface_ && 648 return !!this.cloudPrintInterface_ &&
649 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; 649 this.cloudPrintInterface_.isCloudDestinationSearchInProgress;
650 }, 650 },
651 651
652 /** 652 /**
653 * @return {boolean} Whether the selected destination is valid.
654 */
655 selectedDestinationValid_: function() {
656 return this.appState_.selectedDestination &&
657 this.appState_.selectedDestination.id &&
658 this.appState_.selectedDestination.origin;
659 },
660
661 /*
653 * Initializes the destination store. Sets the initially selected 662 * Initializes the destination store. Sets the initially selected
654 * destination. If any inserted destinations match this ID, that destination 663 * destination. If any inserted destinations match this ID, that destination
655 * will be automatically selected. This method must be called after the 664 * will be automatically selected. This method must be called after the
656 * print_preview.AppState has been initialized. 665 * print_preview.AppState has been initialized.
657 * @param {boolean} isInAppKioskMode Whether the print preview is in App 666 * @param {boolean} isInAppKioskMode Whether the print preview is in App
658 * Kiosk mode. 667 * Kiosk mode.
659 * @param {?string} systemDefaultDestinationId ID of the system default 668 * @param {?string} systemDefaultDestinationId ID of the system default
660 * destination. 669 * destination.
661 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized 670 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
662 * default destination selection rules. 671 * default destination selection rules.
663 */ 672 */
664 init: function( 673 init: function(
665 isInAppKioskMode, 674 isInAppKioskMode,
666 systemDefaultDestinationId, 675 systemDefaultDestinationId,
667 serializedDefaultDestinationSelectionRulesStr) { 676 serializedDefaultDestinationSelectionRulesStr) {
668 this.pdfPrinterEnabled_ = !isInAppKioskMode; 677 this.pdfPrinterEnabled_ = !isInAppKioskMode;
669 this.systemDefaultDestinationId_ = systemDefaultDestinationId; 678 this.systemDefaultDestinationId_ = systemDefaultDestinationId;
670 this.createLocalPdfPrintDestination_(); 679 this.createLocalPdfPrintDestination_();
671 680
672 if (!this.appState_.selectedDestinationId || 681 if (!this.selectedDestinationValid_()) {
673 !this.appState_.selectedDestinationOrigin) {
674 var destinationMatch = this.convertToDestinationMatch_( 682 var destinationMatch = this.convertToDestinationMatch_(
675 serializedDefaultDestinationSelectionRulesStr); 683 serializedDefaultDestinationSelectionRulesStr);
676 if (destinationMatch) { 684 if (destinationMatch) {
677 this.fetchMatchingDestination_(destinationMatch); 685 this.fetchMatchingDestination_(destinationMatch);
678 return; 686 return;
679 } 687 }
680 } 688 }
681 689
682 if (!this.systemDefaultDestinationId_ && 690 if (!this.systemDefaultDestinationId_ &&
683 !(this.appState_.selectedDestinationId && 691 !this.selectedDestinationValid_()) {
684 this.appState_.selectedDestinationOrigin)) {
685 this.selectPdfDestination_(); 692 this.selectPdfDestination_();
686 return; 693 return;
687 } 694 }
688 695
689 var origin = print_preview.Destination.Origin.LOCAL; 696 var origin = print_preview.Destination.Origin.LOCAL;
690 var id = this.systemDefaultDestinationId_; 697 var id = this.systemDefaultDestinationId_;
691 var account = ''; 698 var account = '';
692 var name = ''; 699 var name = '';
693 var capabilities = null; 700 var capabilities = null;
694 var extensionId = ''; 701 var extensionId = '';
695 var extensionName = ''; 702 var extensionName = '';
696 var foundDestination = false; 703 var foundDestination = false;
697 if (this.appState_.recentDestinations) { 704 if (this.appState_.recentDestinations) {
698 // Run through the destinations backwards the most recently used is set 705 // Run through the destinations forward. As soon as we find a
699 // as the initially selected destination. 706 // destination, don't select any future destinations, just mark
700 for (var i = this.appState_.recentDestinations.length - 1; i >= 0; 707 // them recent. Otherwise, there is a race condition between selecting
701 i--) { 708 // destinations/updating the print ticket and this selecting a new
709 // destination that causes random print preview errors.
710 for (var i = 0; i < this.appState_.recentDestinations.length; i++) {
702 origin = this.appState_.recentDestinations[i].origin; 711 origin = this.appState_.recentDestinations[i].origin;
703 id = this.appState_.recentDestinations[i].id; 712 id = this.appState_.recentDestinations[i].id;
704 account = this.appState_.recentDestinations[i].account || ''; 713 account = this.appState_.recentDestinations[i].account || '';
705 name = this.appState_.recentDestinations[i].name || ''; 714 name = this.appState_.recentDestinations[i].name || '';
706 capabilities = this.appState_.recentDestinations[i].capabilities; 715 capabilities = this.appState_.recentDestinations[i].capabilities;
707 extensionId = this.appState_.recentDestinations[i].extensionId || 716 extensionId = this.appState_.recentDestinations[i].extensionId ||
708 ''; 717 '';
709 extensionName = 718 extensionName =
710 this.appState_.recentDestinations[i].extensionName || ''; 719 this.appState_.recentDestinations[i].extensionName || '';
711 var candidate = 720 var candidate =
712 this.destinationMap_[this.getDestinationKey_(origin, 721 this.destinationMap_[this.getDestinationKey_(origin,
713 id, account)]; 722 id, account)];
714 if (candidate != null) { 723 if (candidate != null) {
715 this.selectDestination(candidate); 724 if (!foundDestination)
725 this.selectDestination(candidate);
716 candidate.isRecent = true; 726 candidate.isRecent = true;
717 foundDestination = true; 727 foundDestination = true;
718 } else { 728 } else if (!foundDestination) {
719 foundDestination = this.fetchPreselectedDestination_( 729 foundDestination = this.fetchPreselectedDestination_(
720 origin, 730 origin,
721 id, 731 id,
722 account, 732 account,
723 name, 733 name,
724 capabilities, 734 capabilities,
725 extensionId, 735 extensionId,
726 extensionName); 736 extensionName);
727 } 737 }
728 } 738 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 displayNameRegExp, 936 displayNameRegExp,
927 true /*skipVirtualDestinations*/); 937 true /*skipVirtualDestinations*/);
928 }, 938 },
929 939
930 /** 940 /**
931 * @return {print_preview.DestinationMatch} Creates rules matching 941 * @return {print_preview.DestinationMatch} Creates rules matching
932 * previously selected destination. 942 * previously selected destination.
933 * @private 943 * @private
934 */ 944 */
935 convertPreselectedToDestinationMatch_: function() { 945 convertPreselectedToDestinationMatch_: function() {
936 if (this.appState_.selectedDestinationId && 946 if (this.selectedDestinationValid_()) {
937 this.appState_.selectedDestinationOrigin) {
938 return this.createExactDestinationMatch_( 947 return this.createExactDestinationMatch_(
939 this.appState_.selectedDestinationOrigin, 948 this.appState_.selectedDestination.origin,
940 this.appState_.selectedDestinationId); 949 this.appState_.selectedDestination.id);
941 } 950 }
942 if (this.systemDefaultDestinationId_) { 951 if (this.systemDefaultDestinationId_) {
943 return this.createExactDestinationMatch_( 952 return this.createExactDestinationMatch_(
944 print_preview.Destination.Origin.LOCAL, 953 print_preview.Destination.Origin.LOCAL,
945 this.systemDefaultDestinationId_); 954 this.systemDefaultDestinationId_);
946 } 955 }
947 return null; 956 return null;
948 }, 957 },
949 958
950 /** 959 /**
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 destination.capabilities_); 1340 destination.capabilities_);
1332 destination.capabilities_ = DestinationStore.sortMediaSizes_( 1341 destination.capabilities_ = DestinationStore.sortMediaSizes_(
1333 destination.capabilities_); 1342 destination.capabilities_);
1334 var existingDestination = this.destinationMap_[this.getKey_(destination)]; 1343 var existingDestination = this.destinationMap_[this.getKey_(destination)];
1335 if (existingDestination != null) { 1344 if (existingDestination != null) {
1336 existingDestination.capabilities = destination.capabilities; 1345 existingDestination.capabilities = destination.capabilities;
1337 } else { 1346 } else {
1338 this.insertDestination_(destination); 1347 this.insertDestination_(destination);
1339 } 1348 }
1340 1349
1341 if (existingDestination == this.selectedDestination_ || 1350 if (this.selectedDestination_ &&
1342 destination == this.selectedDestination_) { 1351 (existingDestination == this.selectedDestination_ ||
1352 destination == this.selectedDestination_)) {
1343 this.appState_.persistSelectedDestination(this.selectedDestination_); 1353 this.appState_.persistSelectedDestination(this.selectedDestination_);
1344 cr.dispatchSimpleEvent( 1354 cr.dispatchSimpleEvent(
1345 this, 1355 this,
1346 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); 1356 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY);
1347 } 1357 }
1348 }, 1358 },
1349 1359
1350 /** 1360 /**
1351 * Called when the search for Privet printers is done. 1361 * Called when the search for Privet printers is done.
1352 * @private 1362 * @private
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 return this.getDestinationKey_( 1748 return this.getDestinationKey_(
1739 destination.origin, destination.id, destination.account); 1749 destination.origin, destination.id, destination.account);
1740 } 1750 }
1741 }; 1751 };
1742 1752
1743 // Export 1753 // Export
1744 return { 1754 return {
1745 DestinationStore: DestinationStore 1755 DestinationStore: DestinationStore
1746 }; 1756 };
1747 }); 1757 });
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