| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Internal backing store for the data store. | 50 * Internal backing store for the data store. |
| 51 * @type {!Array.<!print_preview.Destination>} | 51 * @type {!Array.<!print_preview.Destination>} |
| 52 * @private | 52 * @private |
| 53 */ | 53 */ |
| 54 this.destinations_ = []; | 54 this.destinations_ = []; |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * Cache used for constant lookup of destinations by origin and id. | 57 * Cache used for constant lookup of destinations by origin and id. |
| 58 * @type {object.<string, !print_preview.Destination>} | 58 * @type {Object.<string, !print_preview.Destination>} |
| 59 * @private | 59 * @private |
| 60 */ | 60 */ |
| 61 this.destinationMap_ = {}; | 61 this.destinationMap_ = {}; |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * Currently selected destination. | 64 * Currently selected destination. |
| 65 * @type {print_preview.Destination} | 65 * @type {print_preview.Destination} |
| 66 * @private | 66 * @private |
| 67 */ | 67 */ |
| 68 this.selectedDestination_ = null; | 68 this.selectedDestination_ = null; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 /** | 85 /** |
| 86 * Whether PDF printer is enabled. It's disabled, for example, in App Kiosk | 86 * Whether PDF printer is enabled. It's disabled, for example, in App Kiosk |
| 87 * mode. | 87 * mode. |
| 88 * @type {boolean} | 88 * @type {boolean} |
| 89 * @private | 89 * @private |
| 90 */ | 90 */ |
| 91 this.pdfPrinterEnabled_ = false; | 91 this.pdfPrinterEnabled_ = false; |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * Used to fetch cloud-based print destinations. | 94 * Used to fetch cloud-based print destinations. |
| 95 * @type {print_preview.CloudPrintInterface} | 95 * @type {cloudprint.CloudPrintInterface} |
| 96 * @private | 96 * @private |
| 97 */ | 97 */ |
| 98 this.cloudPrintInterface_ = null; | 98 this.cloudPrintInterface_ = null; |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * Maps user account to the list of origins for which destinations are | 101 * Maps user account to the list of origins for which destinations are |
| 102 * already loaded. | 102 * already loaded. |
| 103 * @type {!Object.<string, Array.<print_preview.Destination.Origin>>} | 103 * @type {!Object.<string, Array.<print_preview.Destination.Origin>>} |
| 104 * @private | 104 * @private |
| 105 */ | 105 */ |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 */ | 264 */ |
| 265 get isLocalDestinationSearchInProgress() { | 265 get isLocalDestinationSearchInProgress() { |
| 266 return this.isLocalDestinationSearchInProgress_ || | 266 return this.isLocalDestinationSearchInProgress_ || |
| 267 this.isPrivetDestinationSearchInProgress_; | 267 this.isPrivetDestinationSearchInProgress_; |
| 268 }, | 268 }, |
| 269 | 269 |
| 270 /** | 270 /** |
| 271 * @return {boolean} Whether a search for cloud destinations is in progress. | 271 * @return {boolean} Whether a search for cloud destinations is in progress. |
| 272 */ | 272 */ |
| 273 get isCloudDestinationSearchInProgress() { | 273 get isCloudDestinationSearchInProgress() { |
| 274 return this.cloudPrintInterface_ && | 274 return !!this.cloudPrintInterface_ && |
| 275 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; | 275 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; |
| 276 }, | 276 }, |
| 277 | 277 |
| 278 /** | 278 /** |
| 279 * Initializes the destination store. Sets the initially selected | 279 * Initializes the destination store. Sets the initially selected |
| 280 * destination. If any inserted destinations match this ID, that destination | 280 * destination. If any inserted destinations match this ID, that destination |
| 281 * will be automatically selected. This method must be called after the | 281 * will be automatically selected. This method must be called after the |
| 282 * print_preview.AppState has been initialized. | 282 * print_preview.AppState has been initialized. |
| 283 * @param {boolean} isInAppKioskMode Whether the print preview is in App | 283 * @param {boolean} isInAppKioskMode Whether the print preview is in App |
| 284 * Kiosk mode. | 284 * Kiosk mode. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 this, | 336 this, |
| 337 DestinationStore.EventType.CACHED_SELECTED_DESTINATION_INFO_READY); | 337 DestinationStore.EventType.CACHED_SELECTED_DESTINATION_INFO_READY); |
| 338 } else { | 338 } else { |
| 339 this.selectDefaultDestination_(); | 339 this.selectDefaultDestination_(); |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 }, | 342 }, |
| 343 | 343 |
| 344 /** | 344 /** |
| 345 * Sets the destination store's Google Cloud Print interface. | 345 * Sets the destination store's Google Cloud Print interface. |
| 346 * @param {!print_preview.CloudPrintInterface} cloudPrintInterface Interface | 346 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface |
| 347 * to set. | 347 * to set. |
| 348 */ | 348 */ |
| 349 setCloudPrintInterface: function(cloudPrintInterface) { | 349 setCloudPrintInterface: function(cloudPrintInterface) { |
| 350 this.cloudPrintInterface_ = cloudPrintInterface; | 350 this.cloudPrintInterface_ = cloudPrintInterface; |
| 351 this.tracker_.add( | 351 this.tracker_.add( |
| 352 this.cloudPrintInterface_, | 352 this.cloudPrintInterface_, |
| 353 cloudprint.CloudPrintInterface.EventType.SEARCH_DONE, | 353 cloudprint.CloudPrintInterface.EventType.SEARCH_DONE, |
| 354 this.onCloudPrintSearchDone_.bind(this)); | 354 this.onCloudPrintSearchDone_.bind(this)); |
| 355 this.tracker_.add( | 355 this.tracker_.add( |
| 356 this.cloudPrintInterface_, | 356 this.cloudPrintInterface_, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 377 hasOnlyDefaultCloudDestinations: function() { | 377 hasOnlyDefaultCloudDestinations: function() { |
| 378 // TODO: Move the logic to print_preview. | 378 // TODO: Move the logic to print_preview. |
| 379 return this.destinations_.every(function(dest) { | 379 return this.destinations_.every(function(dest) { |
| 380 return dest.isLocal || | 380 return dest.isLocal || |
| 381 dest.id == print_preview.Destination.GooglePromotedId.DOCS || | 381 dest.id == print_preview.Destination.GooglePromotedId.DOCS || |
| 382 dest.id == print_preview.Destination.GooglePromotedId.FEDEX; | 382 dest.id == print_preview.Destination.GooglePromotedId.FEDEX; |
| 383 }); | 383 }); |
| 384 }, | 384 }, |
| 385 | 385 |
| 386 /** | 386 /** |
| 387 * @param {!print_preview.Destination} destination Destination to select. | 387 * @param {print_preview.Destination} destination Destination to select. |
| 388 */ | 388 */ |
| 389 selectDestination: function(destination) { | 389 selectDestination: function(destination) { |
| 390 this.isInAutoSelectMode_ = false; | 390 this.isInAutoSelectMode_ = false; |
| 391 // When auto select expires, DESTINATION_SELECT event has to be dispatched | 391 // When auto select expires, DESTINATION_SELECT event has to be dispatched |
| 392 // anyway (see isAutoSelectDestinationInProgress() logic). | 392 // anyway (see isAutoSelectDestinationInProgress() logic). |
| 393 if (this.autoSelectTimeout_) { | 393 if (this.autoSelectTimeout_) { |
| 394 clearTimeout(this.autoSelectTimeout_); | 394 clearTimeout(this.autoSelectTimeout_); |
| 395 this.autoSelectTimeout_ = null; | 395 this.autoSelectTimeout_ = null; |
| 396 } else if (destination == this.selectedDestination_) { | 396 } else if (destination == this.selectedDestination_) { |
| 397 return; | 397 return; |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 * @private | 827 * @private |
| 828 */ | 828 */ |
| 829 onCloudPrintPrinterDone_: function(event) { | 829 onCloudPrintPrinterDone_: function(event) { |
| 830 this.updateDestination_(event.printer); | 830 this.updateDestination_(event.printer); |
| 831 }, | 831 }, |
| 832 | 832 |
| 833 /** | 833 /** |
| 834 * Called when the Google Cloud Print interface fails to lookup a | 834 * Called when the Google Cloud Print interface fails to lookup a |
| 835 * destination. Selects another destination if the failed destination was | 835 * destination. Selects another destination if the failed destination was |
| 836 * the initial destination. | 836 * the initial destination. |
| 837 * @param {object} event Contains the ID of the destination that was failed | 837 * @param {Object} event Contains the ID of the destination that was failed |
| 838 * to be looked up. | 838 * to be looked up. |
| 839 * @private | 839 * @private |
| 840 */ | 840 */ |
| 841 onCloudPrintPrinterFailed_: function(event) { | 841 onCloudPrintPrinterFailed_: function(event) { |
| 842 if (this.isInAutoSelectMode_ && | 842 if (this.isInAutoSelectMode_ && |
| 843 this.sameAsPersistedDestination_(event.destinationId, | 843 this.sameAsPersistedDestination_(event.destinationId, |
| 844 event.destinationOrigin)) { | 844 event.destinationOrigin)) { |
| 845 console.error( | 845 console.error( |
| 846 'Failed to fetch last used printer caps: ' + event.destinationId); | 846 'Failed to fetch last used printer caps: ' + event.destinationId); |
| 847 this.selectDefaultDestination_(); | 847 this.selectDefaultDestination_(); |
| 848 } | 848 } |
| 849 }, | 849 }, |
| 850 | 850 |
| 851 /** | 851 /** |
| 852 * Called when printer sharing invitation was processed successfully. | 852 * Called when printer sharing invitation was processed successfully. |
| 853 * @param {Event} event Contains detailed information about the invite and | 853 * @param {Event} event Contains detailed information about the invite and |
| 854 * newly accepted destination (if known). | 854 * newly accepted destination (if known). |
| 855 * @private | 855 * @private |
| 856 */ | 856 */ |
| 857 onCloudPrintProcessInviteDone_: function(event) { | 857 onCloudPrintProcessInviteDone_: function(event) { |
| 858 if (event.accept && event.printer) { | 858 if (event.accept && event.printer) { |
| 859 // Hint the destination list to promote this new destination. | 859 // Hint the destination list to promote this new destination. |
| 860 event.printer.isRecent = true; | 860 event.printer.isRecent = true; |
| 861 this.insertDestination_(event.printer); | 861 this.insertDestination_(event.printer); |
| 862 } | 862 } |
| 863 }, | 863 }, |
| 864 | 864 |
| 865 /** | 865 /** |
| 866 * Called when a Privet printer is added to the local network. | 866 * Called when a Privet printer is added to the local network. |
| 867 * @param {object} event Contains information about the added printer. | 867 * @param {Object} event Contains information about the added printer. |
| 868 * @private | 868 * @private |
| 869 */ | 869 */ |
| 870 onPrivetPrinterAdded_: function(event) { | 870 onPrivetPrinterAdded_: function(event) { |
| 871 if (event.printer.serviceName == this.waitForRegisterDestination_ && | 871 if (event.printer.serviceName == this.waitForRegisterDestination_ && |
| 872 !event.printer.isUnregistered) { | 872 !event.printer.isUnregistered) { |
| 873 this.waitForRegisterDestination_ = null; | 873 this.waitForRegisterDestination_ = null; |
| 874 this.onDestinationsReload_(); | 874 this.onDestinationsReload_(); |
| 875 } else { | 875 } else { |
| 876 this.insertDestinations_( | 876 this.insertDestinations_( |
| 877 print_preview.PrivetDestinationParser.parse(event.printer)); | 877 print_preview.PrivetDestinationParser.parse(event.printer)); |
| 878 } | 878 } |
| 879 }, | 879 }, |
| 880 | 880 |
| 881 /** | 881 /** |
| 882 * Called when capabilities for a privet printer are set. | 882 * Called when capabilities for a privet printer are set. |
| 883 * @param {object} event Contains the capabilities and printer ID. | 883 * @param {Object} event Contains the capabilities and printer ID. |
| 884 * @private | 884 * @private |
| 885 */ | 885 */ |
| 886 onPrivetCapabilitiesSet_: function(event) { | 886 onPrivetCapabilitiesSet_: function(event) { |
| 887 var destinationId = event.printerId; | 887 var destinationId = event.printerId; |
| 888 var destinations = | 888 var destinations = |
| 889 print_preview.PrivetDestinationParser.parse(event.printer); | 889 print_preview.PrivetDestinationParser.parse(event.printer); |
| 890 destinations.forEach(function(dest) { | 890 destinations.forEach(function(dest) { |
| 891 dest.capabilities = event.capabilities; | 891 dest.capabilities = event.capabilities; |
| 892 this.updateDestination_(dest); | 892 this.updateDestination_(dest); |
| 893 }, this); | 893 }, this); |
| 894 }, | 894 }, |
| 895 | 895 |
| 896 /** | 896 /** |
| 897 * Called from native layer after the user was requested to sign in, and did | 897 * Called from native layer after the user was requested to sign in, and did |
| 898 * so successfully. | 898 * so successfully. |
| 899 * @private | 899 * @private |
| 900 */ | 900 */ |
| 901 onDestinationsReload_: function() { | 901 onDestinationsReload_: function() { |
| 902 this.reset_(); | 902 this.reset_(); |
| 903 this.isInAutoSelectMode_ = true; | 903 this.isInAutoSelectMode_ = true; |
| 904 this.createLocalPdfPrintDestination_(); | 904 this.createLocalPdfPrintDestination_(); |
| 905 this.startLoadAllDestinations(); | 905 this.startLoadAllDestinations(); |
| 906 }, | 906 }, |
| 907 | 907 |
| 908 // TODO(vitalybuka): Remove three next functions replacing Destination.id | 908 // TODO(vitalybuka): Remove three next functions replacing Destination.id |
| 909 // and Destination.origin by complex ID. | 909 // and Destination.origin by complex ID. |
| 910 /** | 910 /** |
| 911 * Returns key to be used with {@code destinationMap_}. | 911 * Returns key to be used with {@code destinationMap_}. |
| 912 * @param {!print_preview.Destination.Origin} origin Destination origin. | 912 * @param {!print_preview.Destination.Origin} origin Destination origin. |
| 913 * @return {string} id Destination id. | 913 * @param {string} id Destination id. |
| 914 * @return {string} account User account destination is registered for. | 914 * @param {string} account User account destination is registered for. |
| 915 * @private | 915 * @private |
| 916 */ | 916 */ |
| 917 getDestinationKey_: function(origin, id, account) { | 917 getDestinationKey_: function(origin, id, account) { |
| 918 return origin + '/' + id + '/' + account; | 918 return origin + '/' + id + '/' + account; |
| 919 }, | 919 }, |
| 920 | 920 |
| 921 /** | 921 /** |
| 922 * Returns key to be used with {@code destinationMap_}. | 922 * Returns key to be used with {@code destinationMap_}. |
| 923 * @param {!print_preview.Destination} destination Destination. | 923 * @param {!print_preview.Destination} destination Destination. |
| 924 * @private | 924 * @private |
| (...skipping 26 matching lines...) Expand all Loading... |
| 951 return id == this.appState_.selectedDestinationId && | 951 return id == this.appState_.selectedDestinationId && |
| 952 origin == this.appState_.selectedDestinationOrigin; | 952 origin == this.appState_.selectedDestinationOrigin; |
| 953 } | 953 } |
| 954 }; | 954 }; |
| 955 | 955 |
| 956 // Export | 956 // Export |
| 957 return { | 957 return { |
| 958 DestinationStore: DestinationStore | 958 DestinationStore: DestinationStore |
| 959 }; | 959 }; |
| 960 }); | 960 }); |
| OLD | NEW |