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