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

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

Issue 2760753002: [CUPS] Implement the local CUPS printer setup waiting UI. (Closed)
Patch Set: Address dpapad@'s comments. Fix failed test. 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_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..c9531b014aeff7d0d37cc3891d3c9e10a5e80b7c 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(
@@ -558,21 +568,77 @@ cr.define('print_preview', function() {
/**
* Called when a destination search should be executed. Filters the
* destination lists with the given query.
- * @param {Event} evt Contains the search query.
+ * @param {!Event} event Contains the search query.
* @private
*/
- onSearch_: function(evt) {
- this.filterLists_(evt.queryRegExp);
+ onSearch_: function(event) {
+ this.filterLists_(event.queryRegExp);
+ },
+
+ /**
+ * 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 configuring more than one destination at the same time.
+ * @param {!CustomEvent} event Contains the destination needs to be setup.
+ * @private
+ */
+ onDestinationConfigureRequest_: function(event) {
+ var destination = event.detail.destination;
+ var destinationItem = destination.isLocal ?
+ this.localList_.getDestinationItem(destination.id) :
+ this.cloudList_.getDestinationItem(destination.id);
+ assert(destinationItem != null,
+ 'User does not select a valid destination item.');
+
+ // 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 ||
+ destination.origin != print_preview.Destination.Origin.CROS ||
+ destination.capabilities != null) {
+ destinationItem.onConfigureRequestRejected(
+ this.destinationInConfiguring_ != null);
+ } else {
+ destinationItem.onConfigureRequestAccepted();
+ this.handleConfigureDestination_(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(
+ /**
+ * @param {!print_preview.PrinterSetupResponse} response.
+ */
+ function(response) {
+ this.destinationInConfiguring_ = null;
+ this.localList_.getDestinationItem(destination.id)
+ .onConfigureResolved(response);
+ }.bind(this),
+ function() {
+ this.destinationInConfiguring_ = null;
+ this.localList_.getDestinationItem(destination.id)
+ .onConfigureResolved({printerId: destination.id,
+ success: false});
+ }.bind(this));
},
/**
* Handler for {@code print_preview.DestinationListItem.EventType.SELECT}
- * event, which is called when a destinationi list item is selected.
- * @param {Event} evt Contains the selected destination.
+ * event, which is called when a destination list item is selected.
+ * @param {Event} event Contains the selected destination.
* @private
*/
- onDestinationSelect_: function(evt) {
- this.handleOnDestinationSelect_(evt.destination);
+ onDestinationSelect_: function(event) {
+ this.handleOnDestinationSelect_(event.destination);
},
/**
@@ -583,35 +649,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.');

Powered by Google App Engine
This is Rietveld 408576698