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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 187 |
188 /** | 188 /** |
189 * Amount of time spent searching for privet destination, in milliseconds. | 189 * Amount of time spent searching for privet destination, in milliseconds. |
190 * @type {number} | 190 * @type {number} |
191 * @const | 191 * @const |
192 * @private | 192 * @private |
193 */ | 193 */ |
194 DestinationStore.PRIVET_SEARCH_DURATION_ = 2000; | 194 DestinationStore.PRIVET_SEARCH_DURATION_ = 2000; |
195 | 195 |
196 /** | 196 /** |
197 * Creates a local PDF print destination. | 197 * Localizes printer capabilities. |
198 * @return {!print_preview.Destination} Created print destination. | 198 * @param {!Object} capabilities Printer capabilities to localize. |
| 199 * @return {!Object} Localized capabilities. |
199 * @private | 200 * @private |
200 */ | 201 */ |
201 DestinationStore.createLocalPdfPrintDestination_ = function() { | 202 DestinationStore.localizeCapabilities_ = function(capabilities) { |
202 var dest = new print_preview.Destination( | 203 var mediaSize = capabilities.printer.media_size; |
203 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, | 204 var mediaDisplayNames = { |
204 print_preview.Destination.Type.LOCAL, | 205 'ISO_A4': 'A4', |
205 print_preview.Destination.Origin.LOCAL, | 206 'ISO_A3': 'A3', |
206 localStrings.getString('printToPDF'), | 207 'NA_LETTER': 'Letter', |
207 false /*isRecent*/, | 208 'NA_LEGAL': 'Legal', |
208 print_preview.Destination.ConnectionStatus.ONLINE); | 209 'NA_LEDGER': 'Tabloid' |
209 dest.capabilities = { | |
210 version: '1.0', | |
211 printer: { | |
212 page_orientation: { | |
213 option: [ | |
214 {type: 'AUTO', is_default: true}, | |
215 {type: 'PORTRAIT'}, | |
216 {type: 'LANDSCAPE'} | |
217 ] | |
218 }, | |
219 color: { option: [{type: 'STANDARD_COLOR', is_default: true}] } | |
220 } | |
221 }; | 210 }; |
222 return dest; | 211 for (var i = 0, media; media = mediaSize.option[i]; i++) { |
| 212 media.custom_display_name = mediaDisplayNames[media.name] || media.name; |
| 213 } |
| 214 return capabilities; |
223 }; | 215 }; |
224 | 216 |
225 DestinationStore.prototype = { | 217 DestinationStore.prototype = { |
226 __proto__: cr.EventTarget.prototype, | 218 __proto__: cr.EventTarget.prototype, |
227 | 219 |
228 /** | 220 /** |
229 * @param {string=} opt_account Account to filter destinations by. When | 221 * @param {string=} opt_account Account to filter destinations by. When |
230 * omitted, all destinations are returned. | 222 * omitted, all destinations are returned. |
231 * @return {!Array.<!print_preview.Destination>} List of destinations | 223 * @return {!Array.<!print_preview.Destination>} List of destinations |
232 * accessible by the {@code account}. | 224 * accessible by the {@code account}. |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 this.nativeLayer_, | 641 this.nativeLayer_, |
650 print_preview.NativeLayer.EventType.PRIVET_PRINTER_CHANGED, | 642 print_preview.NativeLayer.EventType.PRIVET_PRINTER_CHANGED, |
651 this.onPrivetPrinterAdded_.bind(this)); | 643 this.onPrivetPrinterAdded_.bind(this)); |
652 this.tracker_.add( | 644 this.tracker_.add( |
653 this.nativeLayer_, | 645 this.nativeLayer_, |
654 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, | 646 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, |
655 this.onPrivetCapabilitiesSet_.bind(this)); | 647 this.onPrivetCapabilitiesSet_.bind(this)); |
656 }, | 648 }, |
657 | 649 |
658 /** | 650 /** |
| 651 * Creates a local PDF print destination. |
| 652 * @return {!print_preview.Destination} Created print destination. |
| 653 * @private |
| 654 */ |
| 655 createLocalPdfPrintDestination_: function() { |
| 656 return new print_preview.Destination( |
| 657 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
| 658 print_preview.Destination.Type.LOCAL, |
| 659 print_preview.Destination.Origin.LOCAL, |
| 660 localStrings.getString('printToPDF'), |
| 661 false /*isRecent*/, |
| 662 print_preview.Destination.ConnectionStatus.ONLINE); |
| 663 }, |
| 664 |
| 665 /** |
659 * Resets the state of the destination store to its initial state. | 666 * Resets the state of the destination store to its initial state. |
660 * @private | 667 * @private |
661 */ | 668 */ |
662 reset_: function() { | 669 reset_: function() { |
663 this.destinations_ = []; | 670 this.destinations_ = []; |
664 this.destinationMap_ = {}; | 671 this.destinationMap_ = {}; |
665 this.selectDestination(null); | 672 this.selectDestination(null); |
666 this.loadedCloudOrigins_ = {}; | 673 this.loadedCloudOrigins_ = {}; |
667 this.hasLoadedAllLocalDestinations_ = false; | 674 this.hasLoadedAllLocalDestinations_ = false; |
668 this.insertDestination_( | 675 // TODO(alekseys): Create PDF printer in the native code and send its |
669 DestinationStore.createLocalPdfPrintDestination_()); | 676 // capabilities back with other local printers. |
| 677 this.insertDestination_(this.createLocalPdfPrintDestination_()); |
670 this.resetAutoSelectTimeout_(); | 678 this.resetAutoSelectTimeout_(); |
671 }, | 679 }, |
672 | 680 |
673 /** | 681 /** |
674 * Resets destination auto selection timeout. | 682 * Resets destination auto selection timeout. |
675 * @private | 683 * @private |
676 */ | 684 */ |
677 resetAutoSelectTimeout_: function() { | 685 resetAutoSelectTimeout_: function() { |
678 this.cancelAutoSelectTimeout_(); | 686 this.cancelAutoSelectTimeout_(); |
679 this.autoSelectTimeout_ = | 687 this.autoSelectTimeout_ = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 * destination. | 724 * destination. |
717 * @private | 725 * @private |
718 */ | 726 */ |
719 onLocalDestinationCapabilitiesSet_: function(event) { | 727 onLocalDestinationCapabilitiesSet_: function(event) { |
720 var destinationId = event.settingsInfo['printerId']; | 728 var destinationId = event.settingsInfo['printerId']; |
721 var key = this.getDestinationKey_( | 729 var key = this.getDestinationKey_( |
722 print_preview.Destination.Origin.LOCAL, | 730 print_preview.Destination.Origin.LOCAL, |
723 destinationId, | 731 destinationId, |
724 ''); | 732 ''); |
725 var destination = this.destinationMap_[key]; | 733 var destination = this.destinationMap_[key]; |
726 var capabilities = print_preview.LocalCapabilitiesParser.parse( | 734 // Special case for PDF printer (until local printers capabilities are |
| 735 // reported in CDD format too). |
| 736 if (destinationId == |
| 737 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
| 738 if (destination) { |
| 739 destination.capabilities = DestinationStore.localizeCapabilities_( |
| 740 event.settingsInfo.capabilities); |
| 741 } |
| 742 } else { |
| 743 var capabilities = print_preview.LocalCapabilitiesParser.parse( |
727 event.settingsInfo); | 744 event.settingsInfo); |
728 if (destination) { | 745 if (destination) { |
729 // In case there were multiple capabilities request for this local | 746 // In case there were multiple capabilities request for this local |
730 // destination, just ignore the later ones. | 747 // destination, just ignore the later ones. |
731 if (destination.capabilities != null) { | 748 if (destination.capabilities != null) { |
732 return; | 749 return; |
| 750 } |
| 751 destination.capabilities = capabilities; |
| 752 } else { |
| 753 // TODO(rltoscano): This makes the assumption that the "deviceName" is |
| 754 // the same as "printerName". We should include the "printerName" in |
| 755 // the response. See http://crbug.com/132831. |
| 756 destination = print_preview.LocalDestinationParser.parse( |
| 757 {deviceName: destinationId, printerName: destinationId}); |
| 758 destination.capabilities = capabilities; |
| 759 this.insertDestination_(destination); |
733 } | 760 } |
734 destination.capabilities = capabilities; | |
735 } else { | |
736 // TODO(rltoscano): This makes the assumption that the "deviceName" is | |
737 // the same as "printerName". We should include the "printerName" in the | |
738 // response. See http://crbug.com/132831. | |
739 destination = print_preview.LocalDestinationParser.parse( | |
740 {deviceName: destinationId, printerName: destinationId}); | |
741 destination.capabilities = capabilities; | |
742 this.insertDestination_(destination); | |
743 } | 761 } |
744 if (this.selectedDestination_ && | 762 if (this.selectedDestination_ && |
745 this.selectedDestination_.id == destinationId) { | 763 this.selectedDestination_.id == destinationId) { |
746 cr.dispatchSimpleEvent(this, | 764 cr.dispatchSimpleEvent(this, |
747 DestinationStore.EventType. | 765 DestinationStore.EventType. |
748 SELECTED_DESTINATION_CAPABILITIES_READY); | 766 SELECTED_DESTINATION_CAPABILITIES_READY); |
749 } | 767 } |
750 }, | 768 }, |
751 | 769 |
752 /** | 770 /** |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 return id == this.appState_.selectedDestinationId && | 932 return id == this.appState_.selectedDestinationId && |
915 origin == this.appState_.selectedDestinationOrigin; | 933 origin == this.appState_.selectedDestinationOrigin; |
916 } | 934 } |
917 }; | 935 }; |
918 | 936 |
919 // Export | 937 // Export |
920 return { | 938 return { |
921 DestinationStore: DestinationStore | 939 DestinationStore: DestinationStore |
922 }; | 940 }; |
923 }); | 941 }); |
OLD | NEW |