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

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: Address the offline comments from weifangsun@ and skau@. 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..feaa4e7b665b99b67eaed0d631b46de71af5eb1b 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,25 @@ 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() {
skau 2017/03/29 20:17:11 If we're not on ChromeOS, we don't need to check f
xdai1 2017/03/30 17:48:19 If we're not on Chrome OS, the check in line 596 i
+ // 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) {

Powered by Google App Engine
This is Rietveld 408576698