| 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..cfd64b8fc246fcb94806abc9b77affbfdcb48b9b 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,51 @@ 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);
|
| + setIsVisible(
|
| + this.getChildElement('.configuring-in-progress-text'), 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 {bool} shouldIgnore If true, which indicates another printer is
|
| + * setting up in process, the printer should not be activated.
|
| + */
|
| + onConfigureRequestRejected: function(shouldIgnore) {
|
| + if (!shouldIgnore)
|
| + 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) {
|
| + setIsVisible(
|
| + this.getChildElement('.configuring-in-progress-text'), false);
|
| + this.destination_.capabilities = response.capabilities;
|
| + this.onDestinationActivated_();
|
| + } else {
|
| + setIsVisible(
|
| + this.getChildElement('.configuring-in-progress-text'), false);
|
| + setIsVisible(
|
| + this.getChildElement('.configuring-failed-text'), true);
|
| + }
|
| + },
|
| +
|
| + /**
|
| * Initializes the element with destination's info.
|
| * @private
|
| */
|
| @@ -171,6 +218,12 @@ cr.define('print_preview', function() {
|
| this.getChildElement('.register-promo'),
|
| this.destination_.connectionStatus ==
|
| print_preview.Destination.ConnectionStatus.UNREGISTERED);
|
| +
|
| + // Reset the configuring messages for CUPS printers.
|
| + setIsVisible(
|
| + this.getChildElement('.configuring-in-progress-text'), false);
|
| + setIsVisible(
|
| + this.getChildElement('.configuring-failed-text'), false);
|
| },
|
|
|
| /**
|
| @@ -195,11 +248,30 @@ cr.define('print_preview', function() {
|
| },
|
|
|
| /**
|
| - * Called when the destination item is activated. Dispatches a SELECT event
|
| - * on the given event target.
|
| + * 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 configureEvt =
|
| + new Event(DestinationListItem.EventType.CONFIGURE_REQUEST);
|
| + configureEvt.destination = this.destination_;
|
| + this.eventTarget_.dispatchEvent(configureEvt);
|
| + },
|
| +
|
| + /**
|
| + * 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) {
|
|
|