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

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

Issue 2617663002: WIP: run clang-format-js on lots of things (Closed)
Patch Set: merge Created 3 years, 11 months 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
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.
11 * @param {!Array<!print_preview.Destination.Origin>} origins Match 11 * @param {!Array<!print_preview.Destination.Origin>} origins Match
12 * destinations from these origins. 12 * destinations from these origins.
13 * @param {RegExp} idRegExp Match destination's id. 13 * @param {RegExp} idRegExp Match destination's id.
14 * @param {RegExp} displayNameRegExp Match destination's displayName. 14 * @param {RegExp} displayNameRegExp Match destination's displayName.
15 * @param {boolean} skipVirtualDestinations Whether to ignore virtual 15 * @param {boolean} skipVirtualDestinations Whether to ignore virtual
16 * destinations, for example, Save as PDF. 16 * destinations, for example, Save as PDF.
17 * @constructor 17 * @constructor
18 */ 18 */
19 function DestinationMatch( 19 function DestinationMatch(
20 origins, idRegExp, displayNameRegExp, skipVirtualDestinations) { 20 origins, idRegExp, displayNameRegExp, skipVirtualDestinations) {
21
22 /** @private {!Array<!print_preview.Destination.Origin>} */ 21 /** @private {!Array<!print_preview.Destination.Origin>} */
23 this.origins_ = origins; 22 this.origins_ = origins;
24 23
25 /** @private {RegExp} */ 24 /** @private {RegExp} */
26 this.idRegExp_ = idRegExp; 25 this.idRegExp_ = idRegExp;
27 26
28 /** @private {RegExp} */ 27 /** @private {RegExp} */
29 this.displayNameRegExp_ = displayNameRegExp; 28 this.displayNameRegExp_ = displayNameRegExp;
30 29
31 /** @private {boolean} */ 30 /** @private {boolean} */
32 this.skipVirtualDestinations_ = skipVirtualDestinations; 31 this.skipVirtualDestinations_ = skipVirtualDestinations;
33 }; 32 };
34 33
35 DestinationMatch.prototype = { 34 DestinationMatch.prototype = {
36 35
37 /** 36 /**
38 * @param {!print_preview.Destination.Origin} origin Origin to match. 37 * @param {!print_preview.Destination.Origin} origin Origin to match.
39 * @return {boolean} Whether the origin is one of the {@code origins_}. 38 * @return {boolean} Whether the origin is one of the {@code origins_}.
40 */ 39 */
41 matchOrigin: function(origin) { 40 matchOrigin: function(origin) {
42 return arrayContains(this.origins_, origin); 41 return arrayContains(this.origins_, origin);
43 }, 42 },
44 43
45 /** 44 /**
46 * @param {string} id Id of the destination. 45 * @param {string} id Id of the destination.
47 * @param {string} origin Origin of the destination. 46 * @param {string} origin Origin of the destination.
48 * @return {boolean} Whether destination is the same as initial. 47 * @return {boolean} Whether destination is the same as initial.
49 */ 48 */
50 matchIdAndOrigin: function(id, origin) { 49 matchIdAndOrigin: function(id, origin) {
51 return this.matchOrigin(origin) && 50 return this.matchOrigin(origin) && this.idRegExp_ &&
52 this.idRegExp_ && 51 this.idRegExp_.test(id);
53 this.idRegExp_.test(id);
54 }, 52 },
55 53
56 /** 54 /**
57 * @param {!print_preview.Destination} destination Destination to match. 55 * @param {!print_preview.Destination} destination Destination to match.
58 * @return {boolean} Whether {@code destination} matches the last user 56 * @return {boolean} Whether {@code destination} matches the last user
59 * selected one. 57 * selected one.
60 */ 58 */
61 match: function(destination) { 59 match: function(destination) {
62 if (!this.matchOrigin(destination.origin)) { 60 if (!this.matchOrigin(destination.origin)) {
63 return false; 61 return false;
(...skipping 18 matching lines...) Expand all
82 * destination selection. 80 * destination selection.
83 * @private 81 * @private
84 */ 82 */
85 isVirtualDestination_: function(destination) { 83 isVirtualDestination_: function(destination) {
86 if (destination.origin == print_preview.Destination.Origin.LOCAL) { 84 if (destination.origin == print_preview.Destination.Origin.LOCAL) {
87 return arrayContains( 85 return arrayContains(
88 [print_preview.Destination.GooglePromotedId.SAVE_AS_PDF], 86 [print_preview.Destination.GooglePromotedId.SAVE_AS_PDF],
89 destination.id); 87 destination.id);
90 } 88 }
91 return arrayContains( 89 return arrayContains(
92 [print_preview.Destination.GooglePromotedId.DOCS, 90 [
93 print_preview.Destination.GooglePromotedId.FEDEX], 91 print_preview.Destination.GooglePromotedId.DOCS,
92 print_preview.Destination.GooglePromotedId.FEDEX
93 ],
94 destination.id); 94 destination.id);
95 } 95 }
96 }; 96 };
97 97
98 /** 98 /**
99 * A data store that stores destinations and dispatches events when the data 99 * A data store that stores destinations and dispatches events when the data
100 * store changes. 100 * store changes.
101 * @param {!print_preview.NativeLayer} nativeLayer Used to fetch local print 101 * @param {!print_preview.NativeLayer} nativeLayer Used to fetch local print
102 * destinations. 102 * destinations.
103 * @param {!print_preview.UserInfo} userInfo User information repository. 103 * @param {!print_preview.UserInfo} userInfo User information repository.
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 if (!capabilities.printer) 512 if (!capabilities.printer)
513 return capabilities; 513 return capabilities;
514 514
515 var mediaSize = capabilities.printer.media_size; 515 var mediaSize = capabilities.printer.media_size;
516 if (!mediaSize) 516 if (!mediaSize)
517 return capabilities; 517 return capabilities;
518 518
519 for (var i = 0, media; media = mediaSize.option[i]; i++) { 519 for (var i = 0, media; media = mediaSize.option[i]; i++) {
520 // No need to patch capabilities with localized names provided. 520 // No need to patch capabilities with localized names provided.
521 if (!media.custom_display_name_localized) { 521 if (!media.custom_display_name_localized) {
522 media.custom_display_name = 522 media.custom_display_name = media.custom_display_name ||
523 media.custom_display_name || 523 DestinationStore.MEDIA_DISPLAY_NAMES_[media.name] || media.name;
524 DestinationStore.MEDIA_DISPLAY_NAMES_[media.name] ||
525 media.name;
526 } 524 }
527 } 525 }
528 return capabilities; 526 return capabilities;
529 }; 527 };
530 528
531 /** 529 /**
532 * Compare two media sizes by their names. 530 * Compare two media sizes by their names.
533 * @param {!Object} a Media to compare. 531 * @param {!Object} a Media to compare.
534 * @param {!Object} b Media to compare. 532 * @param {!Object} b Media to compare.
535 * @return {number} 1 if a > b, -1 if a < b, or 0 if a == b. 533 * @return {number} 1 if a > b, -1 if a < b, or 0 if a == b.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 var categoryStandardCN = []; 565 var categoryStandardCN = [];
568 var categoryStandardISO = []; 566 var categoryStandardISO = [];
569 var categoryStandardJP = []; 567 var categoryStandardJP = [];
570 var categoryStandardMisc = []; 568 var categoryStandardMisc = [];
571 var categoryCustom = []; 569 var categoryCustom = [];
572 for (var i = 0, media; media = mediaSize.option[i]; i++) { 570 for (var i = 0, media; media = mediaSize.option[i]; i++) {
573 var name = media.name || 'CUSTOM'; 571 var name = media.name || 'CUSTOM';
574 var category; 572 var category;
575 if (name.startsWith('NA_')) { 573 if (name.startsWith('NA_')) {
576 category = categoryStandardNA; 574 category = categoryStandardNA;
577 } else if (name.startsWith('PRC_') || name.startsWith('ROC_') || 575 } else if (
578 name == 'OM_DAI_PA_KAI' || name == 'OM_JUURO_KU_KAI' || 576 name.startsWith('PRC_') || name.startsWith('ROC_') ||
579 name == 'OM_PA_KAI') { 577 name == 'OM_DAI_PA_KAI' || name == 'OM_JUURO_KU_KAI' ||
578 name == 'OM_PA_KAI') {
580 category = categoryStandardCN; 579 category = categoryStandardCN;
581 } else if (name.startsWith('ISO_')) { 580 } else if (name.startsWith('ISO_')) {
582 category = categoryStandardISO; 581 category = categoryStandardISO;
583 } else if (name.startsWith('JIS_') || name.startsWith('JPN_')) { 582 } else if (name.startsWith('JIS_') || name.startsWith('JPN_')) {
584 category = categoryStandardJP; 583 category = categoryStandardJP;
585 } else if (name.startsWith('OM_')) { 584 } else if (name.startsWith('OM_')) {
586 category = categoryStandardMisc; 585 category = categoryStandardMisc;
587 } else { 586 } else {
588 assert(name == 'CUSTOM', 'Unknown media size. Assuming custom'); 587 assert(name == 'CUSTOM', 'Unknown media size. Assuming custom');
589 category = categoryCustom; 588 category = categoryCustom;
590 } 589 }
591 category.push(media); 590 category.push(media);
592 } 591 }
593 592
594 // For each category, sort by name. 593 // For each category, sort by name.
595 categoryStandardNA.sort(DestinationStore.compareMediaNames_); 594 categoryStandardNA.sort(DestinationStore.compareMediaNames_);
596 categoryStandardCN.sort(DestinationStore.compareMediaNames_); 595 categoryStandardCN.sort(DestinationStore.compareMediaNames_);
597 categoryStandardISO.sort(DestinationStore.compareMediaNames_); 596 categoryStandardISO.sort(DestinationStore.compareMediaNames_);
598 categoryStandardJP.sort(DestinationStore.compareMediaNames_); 597 categoryStandardJP.sort(DestinationStore.compareMediaNames_);
599 categoryStandardMisc.sort(DestinationStore.compareMediaNames_); 598 categoryStandardMisc.sort(DestinationStore.compareMediaNames_);
600 categoryCustom.sort(DestinationStore.compareMediaNames_); 599 categoryCustom.sort(DestinationStore.compareMediaNames_);
601 600
602 // Then put it all back together. 601 // Then put it all back together.
603 mediaSize.option = categoryStandardNA; 602 mediaSize.option = categoryStandardNA;
604 mediaSize.option.push(...categoryStandardCN, ...categoryStandardISO, 603 mediaSize.option.push(
605 ...categoryStandardJP, ...categoryStandardMisc, ...categoryCustom); 604 ...categoryStandardCN, ...categoryStandardISO, ...categoryStandardJP,
605 ...categoryStandardMisc, ...categoryCustom);
606 return capabilities; 606 return capabilities;
607 }; 607 };
608 608
609 DestinationStore.prototype = { 609 DestinationStore.prototype = {
610 __proto__: cr.EventTarget.prototype, 610 __proto__: cr.EventTarget.prototype,
611 611
612 /** 612 /**
613 * @param {string=} opt_account Account to filter destinations by. When 613 * @param {string=} opt_account Account to filter destinations by. When
614 * omitted, all destinations are returned. 614 * omitted, all destinations are returned.
615 * @return {!Array<!print_preview.Destination>} List of destinations 615 * @return {!Array<!print_preview.Destination>} List of destinations
(...skipping 20 matching lines...) Expand all
636 get isAutoSelectDestinationInProgress() { 636 get isAutoSelectDestinationInProgress() {
637 return this.selectedDestination_ == null && 637 return this.selectedDestination_ == null &&
638 this.autoSelectTimeout_ != null; 638 this.autoSelectTimeout_ != null;
639 }, 639 },
640 640
641 /** 641 /**
642 * @return {boolean} Whether a search for local destinations is in progress. 642 * @return {boolean} Whether a search for local destinations is in progress.
643 */ 643 */
644 get isLocalDestinationSearchInProgress() { 644 get isLocalDestinationSearchInProgress() {
645 return this.isLocalDestinationSearchInProgress_ || 645 return this.isLocalDestinationSearchInProgress_ ||
646 this.isPrivetDestinationSearchInProgress_ || 646 this.isPrivetDestinationSearchInProgress_ ||
647 this.isExtensionDestinationSearchInProgress_; 647 this.isExtensionDestinationSearchInProgress_;
648 }, 648 },
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 * Initializes the destination store. Sets the initially selected 659 * Initializes the destination store. Sets the initially selected
660 * destination. If any inserted destinations match this ID, that destination 660 * destination. If any inserted destinations match this ID, that destination
661 * will be automatically selected. This method must be called after the 661 * will be automatically selected. This method must be called after the
662 * print_preview.AppState has been initialized. 662 * print_preview.AppState has been initialized.
663 * @param {boolean} isInAppKioskMode Whether the print preview is in App 663 * @param {boolean} isInAppKioskMode Whether the print preview is in App
664 * Kiosk mode. 664 * Kiosk mode.
665 * @param {?string} systemDefaultDestinationId ID of the system default 665 * @param {?string} systemDefaultDestinationId ID of the system default
666 * destination. 666 * destination.
667 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized 667 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
668 * default destination selection rules. 668 * default destination selection rules.
669 */ 669 */
670 init: function( 670 init: function(
671 isInAppKioskMode, 671 isInAppKioskMode, systemDefaultDestinationId,
672 systemDefaultDestinationId,
673 serializedDefaultDestinationSelectionRulesStr) { 672 serializedDefaultDestinationSelectionRulesStr) {
674 this.pdfPrinterEnabled_ = !isInAppKioskMode; 673 this.pdfPrinterEnabled_ = !isInAppKioskMode;
675 this.systemDefaultDestinationId_ = systemDefaultDestinationId; 674 this.systemDefaultDestinationId_ = systemDefaultDestinationId;
676 this.createLocalPdfPrintDestination_(); 675 this.createLocalPdfPrintDestination_();
677 676
678 if (!this.appState_.isSelectedDestinationValid()) { 677 if (!this.appState_.isSelectedDestinationValid()) {
679 var destinationMatch = this.convertToDestinationMatch_( 678 var destinationMatch = this.convertToDestinationMatch_(
680 serializedDefaultDestinationSelectionRulesStr); 679 serializedDefaultDestinationSelectionRulesStr);
681 if (destinationMatch) { 680 if (destinationMatch) {
682 this.fetchMatchingDestination_(destinationMatch); 681 this.fetchMatchingDestination_(destinationMatch);
(...skipping 20 matching lines...) Expand all
703 // destination, don't select any future destinations, just mark 702 // destination, don't select any future destinations, just mark
704 // them recent. Otherwise, there is a race condition between selecting 703 // them recent. Otherwise, there is a race condition between selecting
705 // destinations/updating the print ticket and this selecting a new 704 // destinations/updating the print ticket and this selecting a new
706 // destination that causes random print preview errors. 705 // destination that causes random print preview errors.
707 for (var i = 0; i < this.appState_.recentDestinations.length; i++) { 706 for (var i = 0; i < this.appState_.recentDestinations.length; i++) {
708 origin = this.appState_.recentDestinations[i].origin; 707 origin = this.appState_.recentDestinations[i].origin;
709 id = this.appState_.recentDestinations[i].id; 708 id = this.appState_.recentDestinations[i].id;
710 account = this.appState_.recentDestinations[i].account || ''; 709 account = this.appState_.recentDestinations[i].account || '';
711 name = this.appState_.recentDestinations[i].name || ''; 710 name = this.appState_.recentDestinations[i].name || '';
712 capabilities = this.appState_.recentDestinations[i].capabilities; 711 capabilities = this.appState_.recentDestinations[i].capabilities;
713 extensionId = this.appState_.recentDestinations[i].extensionId || 712 extensionId = this.appState_.recentDestinations[i].extensionId || '';
714 '';
715 extensionName = 713 extensionName =
716 this.appState_.recentDestinations[i].extensionName || ''; 714 this.appState_.recentDestinations[i].extensionName || '';
717 var candidate = 715 var candidate = this.destinationMap_[this.getDestinationKey_(
718 this.destinationMap_[this.getDestinationKey_(origin, 716 origin, id, account)];
719 id, account)];
720 if (candidate != null) { 717 if (candidate != null) {
721 if (!foundDestination) 718 if (!foundDestination)
722 this.selectDestination(candidate); 719 this.selectDestination(candidate);
723 candidate.isRecent = true; 720 candidate.isRecent = true;
724 foundDestination = true; 721 foundDestination = true;
725 } else if (!foundDestination) { 722 } else if (!foundDestination) {
726 foundDestination = this.fetchPreselectedDestination_( 723 foundDestination = this.fetchPreselectedDestination_(
727 origin, 724 origin, id, account, name, capabilities, extensionId,
728 id, 725 extensionName);
729 account,
730 name,
731 capabilities,
732 extensionId,
733 extensionName);
734 } 726 }
735 } 727 }
736 } 728 }
737 if (foundDestination) return; 729 if (foundDestination)
730 return;
738 // Try the system default 731 // Try the system default
739 var candidate = 732 var candidate =
740 this.destinationMap_[this.getDestinationKey_(origin, id, account)]; 733 this.destinationMap_[this.getDestinationKey_(origin, id, account)];
741 if (candidate != null) { 734 if (candidate != null) {
742 this.selectDestination(candidate); 735 this.selectDestination(candidate);
743 return; 736 return;
744 } 737 }
745 738
746 if (this.fetchPreselectedDestination_( 739 if (this.fetchPreselectedDestination_(
747 origin, 740 origin, id, account, name, capabilities, extensionId,
748 id,
749 account,
750 name,
751 capabilities,
752 extensionId,
753 extensionName)) { 741 extensionName)) {
754 return; 742 return;
755 } 743 }
756 744
757 this.selectPdfDestination_(); 745 this.selectPdfDestination_();
758 }, 746 },
759 747
760 /** 748 /**
761 * Attempts to fetch capabilities of the destination identified by the 749 * Attempts to fetch capabilities of the destination identified by the
762 * provided origin, id and account. 750 * provided origin, id and account.
(...skipping 27 matching lines...) Expand all
790 778
791 if (origin == print_preview.Destination.Origin.PRIVET) { 779 if (origin == print_preview.Destination.Origin.PRIVET) {
792 // TODO(noamsml): Resolve a specific printer instead of listing all 780 // TODO(noamsml): Resolve a specific printer instead of listing all
793 // privet printers in this case. 781 // privet printers in this case.
794 this.nativeLayer_.startGetPrivetDestinations(); 782 this.nativeLayer_.startGetPrivetDestinations();
795 783
796 // Create a fake selectedDestination_ that is not actually in the 784 // Create a fake selectedDestination_ that is not actually in the
797 // destination store. When the real destination is created, this 785 // destination store. When the real destination is created, this
798 // destination will be overwritten. 786 // destination will be overwritten.
799 this.selectedDestination_ = new print_preview.Destination( 787 this.selectedDestination_ = new print_preview.Destination(
800 id, 788 id, print_preview.Destination.Type.LOCAL,
801 print_preview.Destination.Type.LOCAL, 789 print_preview.Destination.Origin.PRIVET, name, false /*isRecent*/,
802 print_preview.Destination.Origin.PRIVET,
803 name,
804 false /*isRecent*/,
805 print_preview.Destination.ConnectionStatus.ONLINE); 790 print_preview.Destination.ConnectionStatus.ONLINE);
806 this.selectedDestination_.capabilities = capabilities; 791 this.selectedDestination_.capabilities = capabilities;
807 792
808 cr.dispatchSimpleEvent( 793 cr.dispatchSimpleEvent(
809 this, 794 this,
810 DestinationStore.EventType.CACHED_SELECTED_DESTINATION_INFO_READY); 795 DestinationStore.EventType.CACHED_SELECTED_DESTINATION_INFO_READY);
811 return true; 796 return true;
812 } 797 }
813 798
814 if (origin == print_preview.Destination.Origin.EXTENSION) { 799 if (origin == print_preview.Destination.Origin.EXTENSION) {
815 // TODO(tbarzic): Add support for requesting a single extension's 800 // TODO(tbarzic): Add support for requesting a single extension's
816 // printer list. 801 // printer list.
817 this.startLoadExtensionDestinations(); 802 this.startLoadExtensionDestinations();
818 803
819 this.selectedDestination_ = 804 this.selectedDestination_ =
820 print_preview.ExtensionDestinationParser.parse({ 805 print_preview.ExtensionDestinationParser.parse({
821 extensionId: extensionId, 806 extensionId: extensionId,
822 extensionName: extensionName, 807 extensionName: extensionName,
823 id: id, 808 id: id,
824 name: name 809 name: name
825 }); 810 });
826 811
827 if (capabilities) { 812 if (capabilities) {
828 this.selectedDestination_.capabilities = capabilities; 813 this.selectedDestination_.capabilities = capabilities;
829 814
830 cr.dispatchSimpleEvent( 815 cr.dispatchSimpleEvent(
831 this, 816 this, DestinationStore.EventType
832 DestinationStore.EventType 817 .CACHED_SELECTED_DESTINATION_INFO_READY);
833 .CACHED_SELECTED_DESTINATION_INFO_READY);
834 } 818 }
835 return true; 819 return true;
836 } 820 }
837 821
838 return false; 822 return false;
839 }, 823 },
840 824
841 /** 825 /**
842 * Attempts to find a destination matching the provided rules. 826 * Attempts to find a destination matching the provided rules.
843 * @param {!print_preview.DestinationMatch} destinationMatch Rules to match. 827 * @param {!print_preview.DestinationMatch} destinationMatch Rules to match.
844 * @private 828 * @private
845 */ 829 */
846 fetchMatchingDestination_: function(destinationMatch) { 830 fetchMatchingDestination_: function(destinationMatch) {
847 this.autoSelectMatchingDestination_ = destinationMatch; 831 this.autoSelectMatchingDestination_ = destinationMatch;
848 832
849 if (destinationMatch.matchOrigin( 833 if (destinationMatch.matchOrigin(
850 print_preview.Destination.Origin.LOCAL)) { 834 print_preview.Destination.Origin.LOCAL)) {
851 this.startLoadLocalDestinations(); 835 this.startLoadLocalDestinations();
852 } 836 }
853 if (destinationMatch.matchOrigin( 837 if (destinationMatch.matchOrigin(
854 print_preview.Destination.Origin.PRIVET)) { 838 print_preview.Destination.Origin.PRIVET)) {
855 this.startLoadPrivetDestinations(); 839 this.startLoadPrivetDestinations();
856 } 840 }
857 if (destinationMatch.matchOrigin( 841 if (destinationMatch.matchOrigin(
858 print_preview.Destination.Origin.EXTENSION)) { 842 print_preview.Destination.Origin.EXTENSION)) {
859 this.startLoadExtensionDestinations(); 843 this.startLoadExtensionDestinations();
860 } 844 }
861 if (destinationMatch.matchOrigin( 845 if (destinationMatch.matchOrigin(
862 print_preview.Destination.Origin.COOKIES) || 846 print_preview.Destination.Origin.COOKIES) ||
863 destinationMatch.matchOrigin( 847 destinationMatch.matchOrigin(
864 print_preview.Destination.Origin.DEVICE) || 848 print_preview.Destination.Origin.DEVICE) ||
865 destinationMatch.matchOrigin( 849 destinationMatch.matchOrigin(
866 print_preview.Destination.Origin.PROFILE)) { 850 print_preview.Destination.Origin.PROFILE)) {
867 this.startLoadCloudDestinations(); 851 this.startLoadCloudDestinations();
868 } 852 }
869 }, 853 },
870 854
871 /** 855 /**
872 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized 856 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
873 * default destination selection rules. 857 * default destination selection rules.
874 * @return {!print_preview.DestinationMatch} Creates rules matching 858 * @return {!print_preview.DestinationMatch} Creates rules matching
875 * previously selected destination. 859 * previously selected destination.
876 * @private 860 * @private
877 */ 861 */
878 convertToDestinationMatch_: function( 862 convertToDestinationMatch_: function(
879 serializedDefaultDestinationSelectionRulesStr) { 863 serializedDefaultDestinationSelectionRulesStr) {
880 var matchRules = null; 864 var matchRules = null;
881 try { 865 try {
882 if (serializedDefaultDestinationSelectionRulesStr) { 866 if (serializedDefaultDestinationSelectionRulesStr) {
883 matchRules = 867 matchRules =
884 JSON.parse(serializedDefaultDestinationSelectionRulesStr); 868 JSON.parse(serializedDefaultDestinationSelectionRulesStr);
885 } 869 }
886 } catch(e) { 870 } catch (e) {
887 console.error( 871 console.error('Failed to parse defaultDestinationSelectionRules: ' + e);
888 'Failed to parse defaultDestinationSelectionRules: ' + e);
889 } 872 }
890 if (!matchRules) 873 if (!matchRules)
891 return; 874 return;
892 875
893 var isLocal = !matchRules.kind || matchRules.kind == 'local'; 876 var isLocal = !matchRules.kind || matchRules.kind == 'local';
894 var isCloud = !matchRules.kind || matchRules.kind == 'cloud'; 877 var isCloud = !matchRules.kind || matchRules.kind == 'cloud';
895 if (!isLocal && !isCloud) { 878 if (!isLocal && !isCloud) {
896 console.error('Unsupported type: "' + matchRules.kind + '"'); 879 console.error('Unsupported type: "' + matchRules.kind + '"');
897 return null; 880 return null;
898 } 881 }
(...skipping 22 matching lines...) Expand all
921 var displayNameRegExp = null; 904 var displayNameRegExp = null;
922 try { 905 try {
923 if (matchRules.namePattern) { 906 if (matchRules.namePattern) {
924 displayNameRegExp = new RegExp(matchRules.namePattern || '.*'); 907 displayNameRegExp = new RegExp(matchRules.namePattern || '.*');
925 } 908 }
926 } catch (e) { 909 } catch (e) {
927 console.error('Failed to parse regexp for "name": ' + e); 910 console.error('Failed to parse regexp for "name": ' + e);
928 } 911 }
929 912
930 return new DestinationMatch( 913 return new DestinationMatch(
931 origins, 914 origins, idRegExp, displayNameRegExp,
932 idRegExp,
933 displayNameRegExp,
934 true /*skipVirtualDestinations*/); 915 true /*skipVirtualDestinations*/);
935 }, 916 },
936 917
937 /** 918 /**
938 * @return {print_preview.DestinationMatch} Creates rules matching 919 * @return {print_preview.DestinationMatch} Creates rules matching
939 * previously selected destination. 920 * previously selected destination.
940 * @private 921 * @private
941 */ 922 */
942 convertPreselectedToDestinationMatch_: function() { 923 convertPreselectedToDestinationMatch_: function() {
943 if (this.appState_.isSelectedDestinationValid()) { 924 if (this.appState_.isSelectedDestinationValid()) {
(...skipping 13 matching lines...) Expand all
957 * @param {!print_preview.Destination.Origin} origin Destination origin. 938 * @param {!print_preview.Destination.Origin} origin Destination origin.
958 * @param {string} id Destination id. 939 * @param {string} id Destination id.
959 * @return {!print_preview.DestinationMatch} Creates rules matching 940 * @return {!print_preview.DestinationMatch} Creates rules matching
960 * provided destination. 941 * provided destination.
961 * @private 942 * @private
962 */ 943 */
963 createExactDestinationMatch_: function(origin, id) { 944 createExactDestinationMatch_: function(origin, id) {
964 return new DestinationMatch( 945 return new DestinationMatch(
965 [origin], 946 [origin],
966 new RegExp('^' + id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$'), 947 new RegExp('^' + id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$'),
967 null /*displayNameRegExp*/, 948 null /*displayNameRegExp*/, false /*skipVirtualDestinations*/);
968 false /*skipVirtualDestinations*/);
969 }, 949 },
970 950
971 /** 951 /**
972 * Sets the destination store's Google Cloud Print interface. 952 * Sets the destination store's Google Cloud Print interface.
973 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface 953 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface
974 * to set. 954 * to set.
975 */ 955 */
976 setCloudPrintInterface: function(cloudPrintInterface) { 956 setCloudPrintInterface: function(cloudPrintInterface) {
977 this.cloudPrintInterface_ = cloudPrintInterface; 957 this.cloudPrintInterface_ = cloudPrintInterface;
978 this.tracker_.add( 958 this.tracker_.add(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 } else if (destination == this.selectedDestination_) { 1003 } else if (destination == this.selectedDestination_) {
1024 return; 1004 return;
1025 } 1005 }
1026 if (destination == null) { 1006 if (destination == null) {
1027 this.selectedDestination_ = null; 1007 this.selectedDestination_ = null;
1028 cr.dispatchSimpleEvent( 1008 cr.dispatchSimpleEvent(
1029 this, DestinationStore.EventType.DESTINATION_SELECT); 1009 this, DestinationStore.EventType.DESTINATION_SELECT);
1030 return; 1010 return;
1031 } 1011 }
1032 1012
1033 assert(!destination.isProvisional, 1013 assert(
1034 'Unable to select provisonal destinations'); 1014 !destination.isProvisional,
1015 'Unable to select provisonal destinations');
1035 1016
1036 // Update and persist selected destination. 1017 // Update and persist selected destination.
1037 this.selectedDestination_ = destination; 1018 this.selectedDestination_ = destination;
1038 this.selectedDestination_.isRecent = true; 1019 this.selectedDestination_.isRecent = true;
1039 if (destination.id == print_preview.Destination.GooglePromotedId.FEDEX && 1020 if (destination.id == print_preview.Destination.GooglePromotedId.FEDEX &&
1040 !destination.isTosAccepted) { 1021 !destination.isTosAccepted) {
1041 assert(this.cloudPrintInterface_ != null, 1022 assert(
1042 'Selected FedEx destination, but GCP API is not available'); 1023 this.cloudPrintInterface_ != null,
1024 'Selected FedEx destination, but GCP API is not available');
1043 destination.isTosAccepted = true; 1025 destination.isTosAccepted = true;
1044 this.cloudPrintInterface_.updatePrinterTosAcceptance(destination, true); 1026 this.cloudPrintInterface_.updatePrinterTosAcceptance(destination, true);
1045 } 1027 }
1046 this.appState_.persistSelectedDestination(this.selectedDestination_); 1028 this.appState_.persistSelectedDestination(this.selectedDestination_);
1047 // Adjust metrics. 1029 // Adjust metrics.
1048 if (destination.cloudID && 1030 if (destination.cloudID &&
1049 this.destinations_.some(function(otherDestination) { 1031 this.destinations_.some(function(otherDestination) {
1050 return otherDestination.cloudID == destination.cloudID && 1032 return otherDestination.cloudID == destination.cloudID &&
1051 otherDestination != destination; 1033 otherDestination != destination;
1052 })) { 1034 })) {
1053 this.metrics_.record(destination.isPrivet ? 1035 this.metrics_.record(
1054 print_preview.Metrics.DestinationSearchBucket. 1036 destination.isPrivet ?
1055 PRIVET_DUPLICATE_SELECTED : 1037 print_preview.Metrics.DestinationSearchBucket
1056 print_preview.Metrics.DestinationSearchBucket. 1038 .PRIVET_DUPLICATE_SELECTED :
1057 CLOUD_DUPLICATE_SELECTED); 1039 print_preview.Metrics.DestinationSearchBucket
1040 .CLOUD_DUPLICATE_SELECTED);
1058 } 1041 }
1059 // Notify about selected destination change. 1042 // Notify about selected destination change.
1060 cr.dispatchSimpleEvent( 1043 cr.dispatchSimpleEvent(
1061 this, DestinationStore.EventType.DESTINATION_SELECT); 1044 this, DestinationStore.EventType.DESTINATION_SELECT);
1062 // Request destination capabilities, of not known yet. 1045 // Request destination capabilities, of not known yet.
1063 if (destination.capabilities == null) { 1046 if (destination.capabilities == null) {
1064 if (destination.isPrivet) { 1047 if (destination.isPrivet) {
1065 this.nativeLayer_.startGetPrivetDestinationCapabilities( 1048 this.nativeLayer_.startGetPrivetDestinationCapabilities(
1066 destination.id); 1049 destination.id);
1067 } else if (destination.isExtension) { 1050 } else if (destination.isExtension) {
1068 this.nativeLayer_.startGetExtensionDestinationCapabilities( 1051 this.nativeLayer_.startGetExtensionDestinationCapabilities(
1069 destination.id); 1052 destination.id);
1070 } else if (destination.isLocal) { 1053 } else if (destination.isLocal) {
1071 this.nativeLayer_.startGetLocalDestinationCapabilities( 1054 this.nativeLayer_.startGetLocalDestinationCapabilities(
1072 destination.id); 1055 destination.id);
1073 } else { 1056 } else {
1074 assert(this.cloudPrintInterface_ != null, 1057 assert(
1075 'Cloud destination selected, but GCP is not enabled'); 1058 this.cloudPrintInterface_ != null,
1059 'Cloud destination selected, but GCP is not enabled');
1076 this.cloudPrintInterface_.printer( 1060 this.cloudPrintInterface_.printer(
1077 destination.id, destination.origin, destination.account); 1061 destination.id, destination.origin, destination.account);
1078 } 1062 }
1079 } else { 1063 } else {
1080 cr.dispatchSimpleEvent( 1064 cr.dispatchSimpleEvent(
1081 this, 1065 this,
1082 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); 1066 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY);
1083 } 1067 }
1084 }, 1068 },
1085 1069
(...skipping 10 matching lines...) Expand all
1096 this.nativeLayer_.grantExtensionPrinterAccess(destination.id); 1080 this.nativeLayer_.grantExtensionPrinterAccess(destination.id);
1097 }, 1081 },
1098 1082
1099 /** 1083 /**
1100 * Selects 'Save to PDF' destination (since it always exists). 1084 * Selects 'Save to PDF' destination (since it always exists).
1101 * @private 1085 * @private
1102 */ 1086 */
1103 selectPdfDestination_: function() { 1087 selectPdfDestination_: function() {
1104 var saveToPdfKey = this.getDestinationKey_( 1088 var saveToPdfKey = this.getDestinationKey_(
1105 print_preview.Destination.Origin.LOCAL, 1089 print_preview.Destination.Origin.LOCAL,
1106 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, 1090 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, '');
1107 '');
1108 this.selectDestination( 1091 this.selectDestination(
1109 this.destinationMap_[saveToPdfKey] || this.destinations_[0] || null); 1092 this.destinationMap_[saveToPdfKey] || this.destinations_[0] || null);
1110 }, 1093 },
1111 1094
1112 /** 1095 /**
1113 * Attempts to select system default destination with a fallback to 1096 * Attempts to select system default destination with a fallback to
1114 * 'Save to PDF' destination. 1097 * 'Save to PDF' destination.
1115 * @private 1098 * @private
1116 */ 1099 */
1117 selectDefaultDestination_: function() { 1100 selectDefaultDestination_: function() {
1118 if (this.systemDefaultDestinationId_) { 1101 if (this.systemDefaultDestinationId_) {
1119 if (this.autoSelectMatchingDestination_ && 1102 if (this.autoSelectMatchingDestination_ &&
1120 !this.autoSelectMatchingDestination_.matchIdAndOrigin( 1103 !this.autoSelectMatchingDestination_.matchIdAndOrigin(
1121 this.systemDefaultDestinationId_, 1104 this.systemDefaultDestinationId_,
1122 print_preview.Destination.Origin.LOCAL)) { 1105 print_preview.Destination.Origin.LOCAL)) {
1123 if (this.fetchPreselectedDestination_( 1106 if (this.fetchPreselectedDestination_(
1124 print_preview.Destination.Origin.LOCAL, 1107 print_preview.Destination.Origin.LOCAL,
1125 this.systemDefaultDestinationId_, 1108 this.systemDefaultDestinationId_, '' /*account*/, '' /*name*/,
1126 '' /*account*/, 1109 null /*capabilities*/, '' /*extensionId*/,
1127 '' /*name*/, 1110 '' /*extensionName*/)) {
1128 null /*capabilities*/,
1129 '' /*extensionId*/,
1130 '' /*extensionName*/)) {
1131 return; 1111 return;
1132 } 1112 }
1133 } 1113 }
1134 } 1114 }
1135 this.selectPdfDestination_(); 1115 this.selectPdfDestination_();
1136 }, 1116 },
1137 1117
1138 /** Initiates loading of local print destinations. */ 1118 /** Initiates loading of local print destinations. */
1139 startLoadLocalDestinations: function() { 1119 startLoadLocalDestinations: function() {
1140 if (!this.hasLoadedAllLocalDestinations_) { 1120 if (!this.hasLoadedAllLocalDestinations_) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 }, 1306 },
1327 1307
1328 /** 1308 /**
1329 * Updates an existing print destination with capabilities and display name 1309 * Updates an existing print destination with capabilities and display name
1330 * information. If the destination doesn't already exist, it will be added. 1310 * information. If the destination doesn't already exist, it will be added.
1331 * @param {!print_preview.Destination} destination Destination to update. 1311 * @param {!print_preview.Destination} destination Destination to update.
1332 * @private 1312 * @private
1333 */ 1313 */
1334 updateDestination_: function(destination) { 1314 updateDestination_: function(destination) {
1335 assert(destination.constructor !== Array, 'Single printer expected'); 1315 assert(destination.constructor !== Array, 'Single printer expected');
1336 destination.capabilities_ = DestinationStore.localizeCapabilities_( 1316 destination.capabilities_ =
1337 destination.capabilities_); 1317 DestinationStore.localizeCapabilities_(destination.capabilities_);
1338 destination.capabilities_ = DestinationStore.sortMediaSizes_( 1318 destination.capabilities_ =
1339 destination.capabilities_); 1319 DestinationStore.sortMediaSizes_(destination.capabilities_);
1340 var existingDestination = this.destinationMap_[this.getKey_(destination)]; 1320 var existingDestination = this.destinationMap_[this.getKey_(destination)];
1341 if (existingDestination != null) { 1321 if (existingDestination != null) {
1342 existingDestination.capabilities = destination.capabilities; 1322 existingDestination.capabilities = destination.capabilities;
1343 } else { 1323 } else {
1344 this.insertDestination_(destination); 1324 this.insertDestination_(destination);
1345 } 1325 }
1346 1326
1347 if (this.selectedDestination_ && 1327 if (this.selectedDestination_ &&
1348 (existingDestination == this.selectedDestination_ || 1328 (existingDestination == this.selectedDestination_ ||
1349 destination == this.selectedDestination_)) { 1329 destination == this.selectedDestination_)) {
(...skipping 23 matching lines...) Expand all
1373 endExtensionPrinterSearch_: function() { 1353 endExtensionPrinterSearch_: function() {
1374 this.isExtensionDestinationSearchInProgress_ = false; 1354 this.isExtensionDestinationSearchInProgress_ = false;
1375 this.hasLoadedAllExtensionDestinations_ = true; 1355 this.hasLoadedAllExtensionDestinations_ = true;
1376 cr.dispatchSimpleEvent( 1356 cr.dispatchSimpleEvent(
1377 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); 1357 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE);
1378 // Clear initially selected (cached) extension destination if it hasn't 1358 // Clear initially selected (cached) extension destination if it hasn't
1379 // been found among reported extension destinations. 1359 // been found among reported extension destinations.
1380 if (this.autoSelectMatchingDestination_ && 1360 if (this.autoSelectMatchingDestination_ &&
1381 this.autoSelectMatchingDestination_.matchOrigin( 1361 this.autoSelectMatchingDestination_.matchOrigin(
1382 print_preview.Destination.Origin.EXTENSION) && 1362 print_preview.Destination.Origin.EXTENSION) &&
1383 this.selectedDestination_ && 1363 this.selectedDestination_ && this.selectedDestination_.isExtension) {
1384 this.selectedDestination_.isExtension) {
1385 this.selectDefaultDestination_(); 1364 this.selectDefaultDestination_();
1386 } 1365 }
1387 }, 1366 },
1388 1367
1389 /** 1368 /**
1390 * Inserts a destination into the store without dispatching any events. 1369 * Inserts a destination into the store without dispatching any events.
1391 * @return {boolean} Whether the inserted destination was not already in the 1370 * @return {boolean} Whether the inserted destination was not already in the
1392 * store. 1371 * store.
1393 * @private 1372 * @private
1394 */ 1373 */
1395 insertIntoStore_: function(destination) { 1374 insertIntoStore_: function(destination) {
1396 var key = this.getKey_(destination); 1375 var key = this.getKey_(destination);
1397 var existingDestination = this.destinationMap_[key]; 1376 var existingDestination = this.destinationMap_[key];
1398 if (existingDestination == null) { 1377 if (existingDestination == null) {
1399 destination.isRecent |= this.appState_.recentDestinations.some( 1378 destination.isRecent |=
1400 function(recent) { 1379 this.appState_.recentDestinations.some(function(recent) {
1401 return (destination.id == recent.id && 1380 return (
1402 destination.origin == recent.origin); 1381 destination.id == recent.id &&
1382 destination.origin == recent.origin);
1403 }, this); 1383 }, this);
1404 this.destinations_.push(destination); 1384 this.destinations_.push(destination);
1405 this.destinationMap_[key] = destination; 1385 this.destinationMap_[key] = destination;
1406 return true; 1386 return true;
1407 } else if (existingDestination.connectionStatus == 1387 } else if (
1408 print_preview.Destination.ConnectionStatus.UNKNOWN && 1388 existingDestination.connectionStatus ==
1409 destination.connectionStatus != 1389 print_preview.Destination.ConnectionStatus.UNKNOWN &&
1410 print_preview.Destination.ConnectionStatus.UNKNOWN) { 1390 destination.connectionStatus !=
1391 print_preview.Destination.ConnectionStatus.UNKNOWN) {
1411 existingDestination.connectionStatus = destination.connectionStatus; 1392 existingDestination.connectionStatus = destination.connectionStatus;
1412 return true; 1393 return true;
1413 } else { 1394 } else {
1414 return false; 1395 return false;
1415 } 1396 }
1416 }, 1397 },
1417 1398
1418 /** 1399 /**
1419 * Binds handlers to events. 1400 * Binds handlers to events.
1420 * @private 1401 * @private
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 * @private 1445 * @private
1465 */ 1446 */
1466 createLocalPdfPrintDestination_: function() { 1447 createLocalPdfPrintDestination_: function() {
1467 // TODO(alekseys): Create PDF printer in the native code and send its 1448 // TODO(alekseys): Create PDF printer in the native code and send its
1468 // capabilities back with other local printers. 1449 // capabilities back with other local printers.
1469 if (this.pdfPrinterEnabled_) { 1450 if (this.pdfPrinterEnabled_) {
1470 this.insertDestination_(new print_preview.Destination( 1451 this.insertDestination_(new print_preview.Destination(
1471 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, 1452 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
1472 print_preview.Destination.Type.LOCAL, 1453 print_preview.Destination.Type.LOCAL,
1473 print_preview.Destination.Origin.LOCAL, 1454 print_preview.Destination.Origin.LOCAL,
1474 loadTimeData.getString('printToPDF'), 1455 loadTimeData.getString('printToPDF'), false /*isRecent*/,
1475 false /*isRecent*/,
1476 print_preview.Destination.ConnectionStatus.ONLINE)); 1456 print_preview.Destination.ConnectionStatus.ONLINE));
1477 } 1457 }
1478 }, 1458 },
1479 1459
1480 /** 1460 /**
1481 * Resets the state of the destination store to its initial state. 1461 * Resets the state of the destination store to its initial state.
1482 * @private 1462 * @private
1483 */ 1463 */
1484 reset_: function() { 1464 reset_: function() {
1485 this.destinations_ = []; 1465 this.destinations_ = [];
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 * then updates its capabilities. 1498 * then updates its capabilities.
1519 * @param {Event} event Contains the capabilities of the local print 1499 * @param {Event} event Contains the capabilities of the local print
1520 * destination. 1500 * destination.
1521 * @private 1501 * @private
1522 */ 1502 */
1523 onLocalDestinationCapabilitiesSet_: function(event) { 1503 onLocalDestinationCapabilitiesSet_: function(event) {
1524 var destinationId = event.settingsInfo['printerId']; 1504 var destinationId = event.settingsInfo['printerId'];
1525 var printerName = event.settingsInfo['printerName']; 1505 var printerName = event.settingsInfo['printerName'];
1526 var printerDescription = event.settingsInfo['printerDescription']; 1506 var printerDescription = event.settingsInfo['printerDescription'];
1527 var key = this.getDestinationKey_( 1507 var key = this.getDestinationKey_(
1528 print_preview.Destination.Origin.LOCAL, 1508 print_preview.Destination.Origin.LOCAL, destinationId, '');
1529 destinationId,
1530 '');
1531 var destination = this.destinationMap_[key]; 1509 var destination = this.destinationMap_[key];
1532 var capabilities = DestinationStore.localizeCapabilities_( 1510 var capabilities = DestinationStore.localizeCapabilities_(
1533 event.settingsInfo.capabilities); 1511 event.settingsInfo.capabilities);
1534 // Special case for PDF printer (until local printers capabilities are 1512 // Special case for PDF printer (until local printers capabilities are
1535 // reported in CDD format too). 1513 // reported in CDD format too).
1536 if (destinationId == 1514 if (destinationId ==
1537 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { 1515 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) {
1538 if (destination) { 1516 if (destination) {
1539 destination.capabilities = capabilities; 1517 destination.capabilities = capabilities;
1540 } 1518 }
1541 } else { 1519 } else {
1542 if (destination) { 1520 if (destination) {
1543 // In case there were multiple capabilities request for this local 1521 // In case there were multiple capabilities request for this local
1544 // destination, just ignore the later ones. 1522 // destination, just ignore the later ones.
1545 if (destination.capabilities != null) { 1523 if (destination.capabilities != null) {
1546 return; 1524 return;
1547 } 1525 }
1548 destination.capabilities = capabilities; 1526 destination.capabilities = capabilities;
1549 } else { 1527 } else {
1550 destination = print_preview.LocalDestinationParser.parse( 1528 destination = print_preview.LocalDestinationParser.parse({
1551 {deviceName: destinationId, 1529 deviceName: destinationId,
1552 printerName: printerName, 1530 printerName: printerName,
1553 printerDescription: printerDescription}); 1531 printerDescription: printerDescription
1532 });
1554 destination.capabilities = capabilities; 1533 destination.capabilities = capabilities;
1555 this.insertDestination_(destination); 1534 this.insertDestination_(destination);
1556 } 1535 }
1557 } 1536 }
1558 if (this.selectedDestination_ && 1537 if (this.selectedDestination_ &&
1559 this.selectedDestination_.id == destinationId) { 1538 this.selectedDestination_.id == destinationId) {
1560 cr.dispatchSimpleEvent( 1539 cr.dispatchSimpleEvent(
1561 this, 1540 this,
1562 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); 1541 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY);
1563 } 1542 }
1564 }, 1543 },
1565 1544
1566 /** 1545 /**
1567 * Called when a request to get a local destination's print capabilities 1546 * Called when a request to get a local destination's print capabilities
1568 * fails. If the destination is the initial destination, auto-select another 1547 * fails. If the destination is the initial destination, auto-select another
1569 * destination instead. 1548 * destination instead.
1570 * @param {Event} event Contains the destination ID that failed. 1549 * @param {Event} event Contains the destination ID that failed.
1571 * @private 1550 * @private
1572 */ 1551 */
1573 onGetCapabilitiesFail_: function(event) { 1552 onGetCapabilitiesFail_: function(event) {
1574 console.error('Failed to get print capabilities for printer ' + 1553 console.error(
1575 event.destinationId); 1554 'Failed to get print capabilities for printer ' +
1555 event.destinationId);
1576 if (this.autoSelectMatchingDestination_ && 1556 if (this.autoSelectMatchingDestination_ &&
1577 this.autoSelectMatchingDestination_.matchIdAndOrigin( 1557 this.autoSelectMatchingDestination_.matchIdAndOrigin(
1578 event.destinationId, event.destinationOrigin)) { 1558 event.destinationId, event.destinationOrigin)) {
1579 this.selectDefaultDestination_(); 1559 this.selectDefaultDestination_();
1580 } 1560 }
1581 }, 1561 },
1582 1562
1583 /** 1563 /**
1584 * Called when the /search call completes, either successfully or not. 1564 * Called when the /search call completes, either successfully or not.
1585 * In case of success, stores fetched destinations. 1565 * In case of success, stores fetched destinations.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 } 1673 }
1694 }, 1674 },
1695 1675
1696 /** 1676 /**
1697 * Called when capabilities for an extension managed printer are set. 1677 * Called when capabilities for an extension managed printer are set.
1698 * @param {Object} event Contains the printer's capabilities and ID. 1678 * @param {Object} event Contains the printer's capabilities and ID.
1699 * @private 1679 * @private
1700 */ 1680 */
1701 onExtensionCapabilitiesSet_: function(event) { 1681 onExtensionCapabilitiesSet_: function(event) {
1702 var destinationKey = this.getDestinationKey_( 1682 var destinationKey = this.getDestinationKey_(
1703 print_preview.Destination.Origin.EXTENSION, 1683 print_preview.Destination.Origin.EXTENSION, event.printerId,
1704 event.printerId,
1705 '' /* account */); 1684 '' /* account */);
1706 var destination = this.destinationMap_[destinationKey]; 1685 var destination = this.destinationMap_[destinationKey];
1707 if (!destination) 1686 if (!destination)
1708 return; 1687 return;
1709 destination.capabilities = event.capabilities; 1688 destination.capabilities = event.capabilities;
1710 this.updateDestination_(destination); 1689 this.updateDestination_(destination);
1711 }, 1690 },
1712 1691
1713 /** 1692 /**
1714 * Called from native layer after the user was requested to sign in, and did 1693 * Called from native layer after the user was requested to sign in, and did
(...skipping 26 matching lines...) Expand all
1741 * @param {!print_preview.Destination} destination Destination. 1720 * @param {!print_preview.Destination} destination Destination.
1742 * @private 1721 * @private
1743 */ 1722 */
1744 getKey_: function(destination) { 1723 getKey_: function(destination) {
1745 return this.getDestinationKey_( 1724 return this.getDestinationKey_(
1746 destination.origin, destination.id, destination.account); 1725 destination.origin, destination.id, destination.account);
1747 } 1726 }
1748 }; 1727 };
1749 1728
1750 // Export 1729 // Export
1751 return { 1730 return {DestinationStore: DestinationStore};
1752 DestinationStore: DestinationStore
1753 };
1754 }); 1731 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698