| Index: chrome/browser/resources/print_preview/search/destination_list_item.js
|
| diff --git a/chrome/browser/resources/print_preview/search/destination_list_item.js b/chrome/browser/resources/print_preview/search/destination_list_item.js
|
| index 8b529d45acc919b3f3d5aec44328569b9268b49c..91424f9f6f05e19cf7bc410610f16eafbc59728c 100644
|
| --- a/chrome/browser/resources/print_preview/search/destination_list_item.js
|
| +++ b/chrome/browser/resources/print_preview/search/destination_list_item.js
|
| @@ -53,6 +53,8 @@ cr.define('print_preview', function() {
|
| * @enum {string}
|
| */
|
| DestinationListItem.EventType = {
|
| + // Dispatched to check the printer needs to be configured before activation.
|
| + CONFIGURE_REQUEST: 'print_preview.DestinationListItem.CONFIGURE_REQUEST',
|
| // Dispatched when the list item is activated.
|
| SELECT: 'print_preview.DestinationListItem.SELECT',
|
| REGISTER_PROMO_CLICKED:
|
| @@ -99,6 +101,49 @@ cr.define('print_preview', function() {
|
| },
|
|
|
| /**
|
| + * Called if the printer configuration request is accepted. Show the waiting
|
| + * message to the user as the configuration might take longer than expected.
|
| + */
|
| + onConfigureRequestAccepted: function() {
|
| + // It must be a Chrome OS CUPS printer which hasn't been set up before.
|
| + assert(
|
| + this.destination_.origin == print_preview.Destination.Origin.CROS &&
|
| + !this.destination_.capabilities);
|
| + this.updateConfiguringMessage_(true);
|
| + },
|
| +
|
| + /**
|
| + * Called if the printer configuration request is rejected. The request is
|
| + * rejected if another printer is setting up in process or the current
|
| + * printer doesn't need to be setup.
|
| + * @param {boolean} otherPrinterSetupInProgress
|
| + */
|
| + onConfigureRequestRejected: function(otherPrinterSetupInProgress) {
|
| + // If another printer setup is in progress, the printer should not be
|
| + // activated.
|
| + if (!otherPrinterSetupInProgress)
|
| + this.onDestinationActivated_();
|
| + },
|
| +
|
| + /**
|
| + * Called when the printer configuration request is resolved successful or
|
| + * failed.
|
| + * @param response {!print_preview.PrinterSetupResponse}
|
| + */
|
| + onConfigureResolved: function(response) {
|
| + assert(response.printerId == this.destination_.id);
|
| + if (response.success) {
|
| + this.updateConfiguringMessage_(false);
|
| + this.destination_.capabilities = response.capabilities;
|
| + this.onDestinationActivated_();
|
| + } else {
|
| + this.updateConfiguringMessage_(false);
|
| + setIsVisible(
|
| + this.getChildElement('.configuring-failed-text'), true);
|
| + }
|
| + },
|
| +
|
| + /**
|
| * Initializes the element with destination's info.
|
| * @private
|
| */
|
| @@ -171,6 +216,13 @@ cr.define('print_preview', function() {
|
| this.getChildElement('.register-promo'),
|
| this.destination_.connectionStatus ==
|
| print_preview.Destination.ConnectionStatus.UNREGISTERED);
|
| +
|
| + if (cr.isChromeOS) {
|
| + // Reset the configuring messages for CUPS printers.
|
| + this.updateConfiguringMessage_(false);
|
| + setIsVisible(
|
| + this.getChildElement('.configuring-failed-text'), false);
|
| + }
|
| },
|
|
|
| /**
|
| @@ -195,11 +247,43 @@ cr.define('print_preview', function() {
|
| },
|
|
|
| /**
|
| - * Called when the destination item is activated. Dispatches a SELECT event
|
| - * on the given event target.
|
| + * Shows/Hides the configuring in progress message and starts/stops its
|
| + * animation accordingly.
|
| + * @param {bool} show If the message and animation should be shown.
|
| + * @private
|
| + */
|
| + updateConfiguringMessage_: function(show) {
|
| + setIsVisible(
|
| + this.getChildElement('.configuring-in-progress-text'), show);
|
| + this.getChildElement('.configuring-text-jumping-dots')
|
| + .classList.toggle('jumping-dots', show);
|
| + },
|
| +
|
| + /**
|
| + * Called when the destination item is activated. Check if the printer needs
|
| + * to be set up first before activation.
|
| * @private
|
| */
|
| onActivate_: function() {
|
| + if (!cr.isChromeOS) {
|
| + onDestinationActivated_();
|
| + return;
|
| + }
|
| +
|
| + // Check if the printer needs configuration before using. The user is only
|
| + // allowed to set up one printer at one time.
|
| + var configureEvent = new CustomEvent(
|
| + DestinationListItem.EventType.CONFIGURE_REQUEST,
|
| + {detail: {destination: this.destination_}});
|
| + this.eventTarget_.dispatchEvent(configureEvent);
|
| + },
|
| +
|
| + /**
|
| + * Called when the destination has been resolved successfully and needs to
|
| + * be activated. Dispatches a SELECT event on the given event target.
|
| + * @private
|
| + */
|
| + onDestinationActivated_: function() {
|
| if (this.destination_.id ==
|
| print_preview.Destination.GooglePromotedId.FEDEX &&
|
| !this.destination_.isTosAccepted) {
|
|
|