Chromium Code Reviews| Index: chrome/browser/resources/print_preview/search/destination_search.js |
| diff --git a/chrome/browser/resources/print_preview/search/destination_search.js b/chrome/browser/resources/print_preview/search/destination_search.js |
| index cc59b37ebf07538fe18838f8b5858be29346c12e..169c8fcd3a4933b1006e0a6a10f2e899f7e58b25 100644 |
| --- a/chrome/browser/resources/print_preview/search/destination_search.js |
| +++ b/chrome/browser/resources/print_preview/search/destination_search.js |
| @@ -74,6 +74,12 @@ cr.define('print_preview', function() { |
| this.provisionalDestinationResolver_ = null; |
| /** |
| + * The destination that is currently in configuration. |
| + * @private {?print_preview.Destination} |
| + */ |
| + this.destinationInConfiguring_ = null; |
| + |
| + /** |
| * Search box used to search through the destination lists. |
| * @type {!print_preview.SearchBox} |
| * @private |
| @@ -223,6 +229,10 @@ cr.define('print_preview', function() { |
| this.onSearch_.bind(this)); |
| this.tracker.add( |
| this, |
| + print_preview.DestinationListItem.EventType.CONFIGURE_REQUEST, |
| + this.onDestinationConfigureRequest_.bind(this)); |
| + this.tracker.add( |
| + this, |
| print_preview.DestinationListItem.EventType.SELECT, |
| this.onDestinationSelect_.bind(this)); |
| this.tracker.add( |
| @@ -566,8 +576,66 @@ cr.define('print_preview', function() { |
| }, |
| /** |
| + * Handler for {@code print_preview.DestinationListItem.EventType. |
| + * CONFIGURE_REQUEST} event, which is called to check a destination list |
| + * item needs to be setup on Chrome OS before being selected. Note we do not |
| + * allow configure more than one destination at the same time. |
|
skau
2017/03/29 20:17:11
nit: s/configure/configuring/
xdai1
2017/03/30 17:48:19
Done.
|
| + * @param {Event} evt Contains the destination needs to be setup. |
| + * @private |
| + */ |
| + onDestinationConfigureRequest_: function(evt) { |
| + var destinationItem = evt.destination.isLocal |
| + ? this.localList_.getDestinationItem(evt.destination.id) |
| + : this.cloudList_.getDestinationItem(evt.destination.id); |
| + if (!destinationItem) |
| + return; |
| + |
| + // Another printer setup is in process or the printer doesn't need to be |
| + // set up. Reject the setup request directly. |
| + if (this.destinationInConfiguring_ != null || |
| + evt.destination.origin != print_preview.Destination.Origin.CROS || |
| + evt.destination.capabilities != null) { |
| + destinationItem.onConfigureRequestRejected( |
| + this.destinationInConfiguring_ != null); |
| + } else { |
| + destinationItem.onConfigureRequestAccepted(); |
| + this.handleConfigureDestination_(evt.destination); |
| + } |
| + }, |
| + |
| + /** |
| + * Called When a destination needs to be setup. |
| + * @param {!print_preview.Destination} destination The destination needs to |
| + * be setup. |
| + * @private |
| + */ |
| + handleConfigureDestination_: function(destination) { |
| + assert(destination.origin == print_preview.Destination.Origin.CROS, |
| + 'Only local printer on Chrome OS requires setup.'); |
| + this.destinationInConfiguring_ = destination; |
| + this.destinationStore_.resolveCrosDestination(destination).then( |
| + /** |
| + * Called when the Promise is fulfilled. |
| + * @param {!print_preview.PrinterSetupResponse} response. |
| + */ |
| + function(response) { |
| + this.localList_.getDestinationItem(destination.id) |
| + .onConfigureResolved(response); |
| + this.destinationInConfiguring_ = null; |
| + }.bind(this), |
| + /** |
| + * Called when the Promise is rejected. |
| + */ |
| + function() { |
| + this.localList_.getDestinationItem(destination.id) |
| + .onConfigureResolved({printerId: destination.id, success: false}); |
| + this.destinationInConfiguring_ = null; |
| + }.bind(this)); |
| + }, |
| + |
| + /** |
| * Handler for {@code print_preview.DestinationListItem.EventType.SELECT} |
| - * event, which is called when a destinationi list item is selected. |
| + * event, which is called when a destination list item is selected. |
| * @param {Event} evt Contains the selected destination. |
| * @private |
| */ |
| @@ -583,35 +651,6 @@ cr.define('print_preview', function() { |
| * @private |
| */ |
| handleOnDestinationSelect_: function(destination) { |
| - if (destination.origin == print_preview.Destination.Origin.CROS && |
| - !destination.capabilities) { |
| - // local printers on CrOS require setup. |
| - assert(!this.printerConfigurer_); |
| - this.printerConfigurer_ = new print_preview.CrosDestinationResolver( |
| - this.destinationStore_, destination); |
| - this.addChild(this.printerConfigurer_); |
| - this.printerConfigurer_.run(this.getElement()). |
| - then( |
| - /** |
| - * @param {!print_preview.PrinterSetupResponse} result |
| - * An object containing the printerId and capabilities. |
| - */ |
| - function(result) { |
| - assert(result.printerId == destination.id); |
| - destination.capabilities = result.capabilities; |
| - this.handleOnDestinationSelect_(destination); |
| - }.bind(this), |
| - function() { |
| - console.warn( |
| - 'Failed to setup destination: ' + destination.id); |
| - }). |
| - then(function() { |
| - this.removeChild(this.printerConfigurer_); |
| - this.printerConfigurer_ = null; |
| - }.bind(this)); |
| - return; |
| - } |
| - |
| if (destination.isProvisional) { |
| assert(!this.provisionalDestinationResolver_, |
| 'Provisional destination resolver already exists.'); |