Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2437)

Unified Diff: chrome/browser/resources/print_preview/search/destination_list_item.js

Issue 2760753002: [CUPS] Implement the local CUPS printer setup waiting UI. (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ec85e3feda269204a3be21d0ec0f30693bf695a4 100644
--- a/chrome/browser/resources/print_preview/search/destination_list_item.js
+++ b/chrome/browser/resources/print_preview/search/destination_list_item.js
@@ -9,13 +9,17 @@ cr.define('print_preview', function() {
* Component that renders a destination item in a destination list.
* @param {!cr.EventTarget} eventTarget Event target to dispatch selection
* events to.
+ * @param {!print_preview.DestinationStore} destinationStore Data store
+ * containing the destinations to search through. Used as a proxy to
+ * native layer for resolving the destination.
* @param {!print_preview.Destination} destination Destination data object to
* render.
* @param {RegExp} query Active filter query.
* @constructor
* @extends {print_preview.Component}
*/
- function DestinationListItem(eventTarget, destination, query) {
+ function DestinationListItem(
+ eventTarget, destinationStore, destination, query) {
print_preview.Component.call(this);
/**
@@ -26,6 +30,13 @@ cr.define('print_preview', function() {
this.eventTarget_ = eventTarget;
/**
+ * Data store containing all the destinations.
+ * @type {!print_preview.DestinationStore}
+ * @private
+ */
+ this.destinationStore_ = destinationStore;
+
+ /**
* Destination that the list item renders.
* @type {!print_preview.Destination}
* @private
@@ -171,6 +182,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 +212,48 @@ 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. Resolve the destination
+ * first if necessary (i.e., the printer needs to be setup on Chrome OS).
* @private
*/
onActivate_: function() {
+ if (this.destination_.origin == print_preview.Destination.Origin.CROS &&
+ !this.destination_.capabilities) {
+ setIsVisible(
+ this.getChildElement('.configuring-in-progress-text'), true);
+ setIsVisible(
+ this.getChildElement('.configuring-failed-text'), false);
+
+ this.destinationStore_.resolveCrosDestination(this.destination_).then(
+ /**
+ * Called when the Promise is fulfilled.
+ * @param {!print_preview.PrinterSetupResponse} response.
+ */
+ function(response) {
+ if (response.success) {
+ setIsVisible(
+ this.getChildElement('.configuring-in-progress-text'), false);
+ this.destination_.capabilities = response.capabilities;
+ this.onDestinationResolved_();
skau 2017/03/20 22:16:01 This component is not designed to have this called
+ } else {
+ this.onResolveDestinationFailed_();
+ }
+ }.bind(this),
+ /**
+ * Called when the Promise is rejected.
+ */
+ this.onResolveDestinationFailed_.bind(this));
+ } else {
+ this.onDestinationResolved_();
+ }
+ },
+
+ /**
+ * Called when the destination has been resolved successfully. Dispatches a
+ * SELECT event on the given event target.
+ * @private
+ */
+ onDestinationResolved_: function() {
if (this.destination_.id ==
print_preview.Destination.GooglePromotedId.FEDEX &&
!this.destination_.isTosAccepted) {
@@ -221,6 +275,17 @@ cr.define('print_preview', function() {
},
/**
+ * Called when the destination resolve was failed.
+ * @private
+ */
+ onResolveDestinationFailed_: function() {
+ setIsVisible(
+ this.getChildElement('.configuring-in-progress-text'), false);
+ setIsVisible(
+ this.getChildElement('.configuring-failed-text'), true);
+ },
+
+ /**
* Called when the key is pressed on the destination item. Dispatches a
* SELECT event when Enter is pressed.
* @param {KeyboardEvent} e Keyboard event to process.

Powered by Google App Engine
This is Rietveld 408576698