Chromium Code Reviews| 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 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 } | 1071 } |
| 1072 } | 1072 } |
| 1073 } | 1073 } |
| 1074 this.selectPdfDestination_(); | 1074 this.selectPdfDestination_(); |
| 1075 }, | 1075 }, |
| 1076 | 1076 |
| 1077 /** Initiates loading of local print destinations. */ | 1077 /** Initiates loading of local print destinations. */ |
| 1078 startLoadLocalDestinations: function() { | 1078 startLoadLocalDestinations: function() { |
| 1079 if (!this.hasLoadedAllLocalDestinations_) { | 1079 if (!this.hasLoadedAllLocalDestinations_) { |
| 1080 this.hasLoadedAllLocalDestinations_ = true; | 1080 this.hasLoadedAllLocalDestinations_ = true; |
| 1081 this.nativeLayer_.startGetLocalDestinations(); | 1081 this.nativeLayer_.getPrinters().then( |
|
dpapad
2017/06/01 19:01:53
Isn't this equivalent to
this.nativeLayer_.getPri
rbpotter
2017/06/01 22:31:12
Done.
| |
| 1082 /** | |
| 1083 * @param {Array<print_preview.LocalDestinationInfo>} | |
| 1084 * destinationInfos A list of the local destinations retrieved. | |
| 1085 */ | |
| 1086 function(destinationInfos) { | |
| 1087 this.onLocalDestinationsSet_(destinationInfos); | |
| 1088 }.bind(this)); | |
| 1082 this.isLocalDestinationSearchInProgress_ = true; | 1089 this.isLocalDestinationSearchInProgress_ = true; |
|
dpapad
2017/06/01 19:01:53
Not for this CL, mostly brainstorming:
I am seein
rbpotter
2017/06/01 22:31:12
Acknowledged.
| |
| 1083 cr.dispatchSimpleEvent( | 1090 cr.dispatchSimpleEvent( |
| 1084 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); | 1091 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); |
| 1085 } | 1092 } |
| 1086 }, | 1093 }, |
| 1087 | 1094 |
| 1088 /** Initiates loading of privet print destinations. */ | 1095 /** Initiates loading of privet print destinations. */ |
| 1089 startLoadPrivetDestinations: function() { | 1096 startLoadPrivetDestinations: function() { |
| 1090 if (!this.hasLoadedAllPrivetDestinations_) { | 1097 if (!this.hasLoadedAllPrivetDestinations_) { |
| 1091 if (this.privetDestinationSearchInProgress_) | 1098 if (this.privetDestinationSearchInProgress_) |
| 1092 clearTimeout(this.privetSearchTimeout_); | 1099 clearTimeout(this.privetSearchTimeout_); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1355 }, | 1362 }, |
| 1356 | 1363 |
| 1357 /** | 1364 /** |
| 1358 * Binds handlers to events. | 1365 * Binds handlers to events. |
| 1359 * @private | 1366 * @private |
| 1360 */ | 1367 */ |
| 1361 addEventListeners_: function() { | 1368 addEventListeners_: function() { |
| 1362 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget(); | 1369 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget(); |
| 1363 this.tracker_.add( | 1370 this.tracker_.add( |
| 1364 nativeLayerEventTarget, | 1371 nativeLayerEventTarget, |
| 1365 print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET, | |
| 1366 this.onLocalDestinationsSet_.bind(this)); | |
| 1367 this.tracker_.add( | |
| 1368 nativeLayerEventTarget, | |
| 1369 print_preview.NativeLayer.EventType.CAPABILITIES_SET, | 1372 print_preview.NativeLayer.EventType.CAPABILITIES_SET, |
| 1370 this.onLocalDestinationCapabilitiesSet_.bind(this)); | 1373 this.onLocalDestinationCapabilitiesSet_.bind(this)); |
| 1371 this.tracker_.add( | 1374 this.tracker_.add( |
| 1372 nativeLayerEventTarget, | 1375 nativeLayerEventTarget, |
| 1373 print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL, | 1376 print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL, |
| 1374 this.onGetCapabilitiesFail_.bind(this)); | 1377 this.onGetCapabilitiesFail_.bind(this)); |
| 1375 this.tracker_.add( | 1378 this.tracker_.add( |
| 1376 nativeLayerEventTarget, | 1379 nativeLayerEventTarget, |
| 1377 print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD, | 1380 print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD, |
| 1378 this.onDestinationsReload_.bind(this)); | 1381 this.onDestinationsReload_.bind(this)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1430 this.hasLoadedAllExtensionDestinations_ = false; | 1433 this.hasLoadedAllExtensionDestinations_ = false; |
| 1431 | 1434 |
| 1432 clearTimeout(this.autoSelectTimeout_); | 1435 clearTimeout(this.autoSelectTimeout_); |
| 1433 this.autoSelectTimeout_ = setTimeout( | 1436 this.autoSelectTimeout_ = setTimeout( |
| 1434 this.selectDefaultDestination_.bind(this), | 1437 this.selectDefaultDestination_.bind(this), |
| 1435 DestinationStore.AUTO_SELECT_TIMEOUT_); | 1438 DestinationStore.AUTO_SELECT_TIMEOUT_); |
| 1436 }, | 1439 }, |
| 1437 | 1440 |
| 1438 /** | 1441 /** |
| 1439 * Called when the local destinations have been got from the native layer. | 1442 * Called when the local destinations have been got from the native layer. |
| 1440 * @param {Event} event Contains the local destinations. | 1443 * @param {Array<print_preview.LocalDestinationInfo>} destinationInfos A |
|
dpapad
2017/06/01 19:01:53
Should this be !Array<!print_preview.LocalDestinat
rbpotter
2017/06/01 22:31:12
Done.
| |
| 1444 * list of the local destinations retrieved. | |
| 1441 * @private | 1445 * @private |
| 1442 */ | 1446 */ |
| 1443 onLocalDestinationsSet_: function(event) { | 1447 onLocalDestinationsSet_: function(destinationInfos) { |
| 1444 var localDestinations = event.destinationInfos.map(function(destInfo) { | 1448 var localDestinations = destinationInfos.map(function(destInfo) { |
| 1445 return print_preview.LocalDestinationParser.parse(destInfo); | 1449 return print_preview.LocalDestinationParser.parse(destInfo); |
| 1446 }); | 1450 }); |
| 1447 this.insertDestinations_(localDestinations); | 1451 this.insertDestinations_(localDestinations); |
| 1448 this.isLocalDestinationSearchInProgress_ = false; | 1452 this.isLocalDestinationSearchInProgress_ = false; |
| 1449 cr.dispatchSimpleEvent( | 1453 cr.dispatchSimpleEvent( |
| 1450 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); | 1454 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); |
| 1451 }, | 1455 }, |
| 1452 | 1456 |
| 1453 /** | 1457 /** |
| 1454 * Called when the native layer retrieves the capabilities for the selected | 1458 * Called when the native layer retrieves the capabilities for the selected |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1697 return this.getDestinationKey_( | 1701 return this.getDestinationKey_( |
| 1698 destination.origin, destination.id, destination.account); | 1702 destination.origin, destination.id, destination.account); |
| 1699 } | 1703 } |
| 1700 }; | 1704 }; |
| 1701 | 1705 |
| 1702 // Export | 1706 // Export |
| 1703 return { | 1707 return { |
| 1704 DestinationStore: DestinationStore | 1708 DestinationStore: DestinationStore |
| 1705 }; | 1709 }; |
| 1706 }); | 1710 }); |
| OLD | NEW |