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

Unified Diff: chrome/browser/resources/print_preview/data/destination_store.js

Issue 2606043004: Perform printer setup on Chrome OS before selecting printer. (Closed)
Patch Set: fix unit test Created 3 years, 11 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/data/destination_store.js
diff --git a/chrome/browser/resources/print_preview/data/destination_store.js b/chrome/browser/resources/print_preview/data/destination_store.js
index dafd6553b237f3a68c0e279e159bd63c44167ed7..04bc44fdb5188179b7252705df1cdebd9f9f95d7 100644
--- a/chrome/browser/resources/print_preview/data/destination_store.js
+++ b/chrome/browser/resources/print_preview/data/destination_store.js
@@ -280,11 +280,30 @@ cr.define('print_preview', function() {
*/
this.waitForRegisterDestination_ = null;
+ /**
+ * Local destinations are CROS destinations on ChromeOS because they require
+ * extra setup.
+ * @type {!print_preview.Destination.Origin}
+ * @private
+ */
+ this.platformOrigin_ = cr.isChromeOS ?
+ print_preview.Destination.Origin.CROS :
+ print_preview.Destination.Origin.LOCAL;
+
this.addEventListeners_();
this.reset_();
};
/**
+ * @typedef {{
+ * printerId: string,
+ * success: boolean,
+ * capabilities: Object,
+ * }}
+ */
+ var PrinterSetupResponse;
+
+ /**
* Event types dispatched by the data store.
* @enum {string}
*/
@@ -301,7 +320,9 @@ cr.define('print_preview', function() {
CACHED_SELECTED_DESTINATION_INFO_READY:
'print_preview.DestinationStore.CACHED_SELECTED_DESTINATION_INFO_READY',
SELECTED_DESTINATION_CAPABILITIES_READY:
- 'print_preview.DestinationStore.SELECTED_DESTINATION_CAPABILITIES_READY'
+ 'print_preview.DestinationStore.SELECTED_DESTINATION_CAPABILITIES_READY',
+ PRINTER_CONFIGURED:
+ 'print_preview.DestinationStore.PRINTER_CONFIGURED',
};
/**
@@ -690,8 +711,8 @@ cr.define('print_preview', function() {
return;
}
- var origin = print_preview.Destination.Origin.LOCAL;
- var id = this.systemDefaultDestinationId_;
+ var origin = null;
+ var id = '';
var account = '';
var name = '';
var capabilities = null;
@@ -735,7 +756,13 @@ cr.define('print_preview', function() {
}
}
if (foundDestination) return;
+
// Try the system default
+ id = this.systemDefaultDestinationId_;
+ origin = id == print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ?
+ print_preview.Destination.Origin.LOCAL :
+ this.platformOrigin_;
+ account = '';
var candidate =
this.destinationMap_[this.getDestinationKey_(origin, id, account)];
if (candidate != null) {
@@ -776,7 +803,8 @@ cr.define('print_preview', function() {
this.autoSelectMatchingDestination_ =
this.createExactDestinationMatch_(origin, id);
- if (origin == print_preview.Destination.Origin.LOCAL) {
+ if (origin == print_preview.Destination.Origin.LOCAL ||
+ origin == print_preview.Destination.Origin.CROS) {
this.nativeLayer_.startGetLocalDestinationCapabilities(id);
return true;
}
@@ -847,7 +875,9 @@ cr.define('print_preview', function() {
this.autoSelectMatchingDestination_ = destinationMatch;
if (destinationMatch.matchOrigin(
- print_preview.Destination.Origin.LOCAL)) {
+ print_preview.Destination.Origin.LOCAL) ||
+ destinationMatch.matchOrigin(
+ print_preview.Destination.Origin.CROS)) {
this.startLoadLocalDestinations();
}
if (destinationMatch.matchOrigin(
@@ -902,6 +932,7 @@ cr.define('print_preview', function() {
origins.push(print_preview.Destination.Origin.LOCAL);
origins.push(print_preview.Destination.Origin.PRIVET);
origins.push(print_preview.Destination.Origin.EXTENSION);
+ origins.push(print_preview.Destination.Origin.CROS);
}
if (isCloud) {
origins.push(print_preview.Destination.Origin.COOKIES);
@@ -947,7 +978,7 @@ cr.define('print_preview', function() {
}
if (this.systemDefaultDestinationId_) {
return this.createExactDestinationMatch_(
- print_preview.Destination.Origin.LOCAL,
+ this.platformOrigin_,
this.systemDefaultDestinationId_);
}
return null;
@@ -1084,6 +1115,18 @@ cr.define('print_preview', function() {
},
/**
+ * Attempt to resolve the capabilities for a Chrome OS printer.
+ * @param {!print_preview.Destination} destination The destination which
+ * requires resolution.
+ */
+ resolveCrosDestination: function(destination) {
+ assert(destination.origin == print_preview.Destination.Origin.CROS);
+ this.nativeLayer_.setupPrinter(destination.id).
dpapad 2017/01/12 01:18:10 There is no need to call both then and catch. then
skau 2017/01/12 02:17:17 Done.
+ then(this.onPrinterSetup_.bind(this)).
+ catch(this.onPrinterFailure_.bind(this));
+ },
+
+ /**
* Attempts to resolve a provisional destination.
* @param {!print_preview.Destination} destinaion Provisional destination
* that should be resolved.
@@ -1119,9 +1162,9 @@ cr.define('print_preview', function() {
if (this.autoSelectMatchingDestination_ &&
!this.autoSelectMatchingDestination_.matchIdAndOrigin(
this.systemDefaultDestinationId_,
- print_preview.Destination.Origin.LOCAL)) {
+ this.plaformOrigin_)) {
if (this.fetchPreselectedDestination_(
- print_preview.Destination.Origin.LOCAL,
+ this.platformOrigin_,
this.systemDefaultDestinationId_,
'' /*account*/,
'' /*name*/,
@@ -1272,6 +1315,32 @@ cr.define('print_preview', function() {
},
/**
+ * Handle the result of a PRINTER_SETUP request.
+ * @param {!PrinterSetupResponse} response.
+ * @private
+ */
+ onPrinterSetup_: function(response) {
+ var event = new Event(
dpapad 2017/01/12 01:18:10 Technically, we should not be augmenting a native
skau 2017/01/12 02:17:17 It seems to lead to much cleaner code. I'll use i
+ DestinationStore.EventType.PRINTER_CONFIGURED);
+ event.printerId = response.printerId;
+ event.capabilities = response.capabilities;
+ event.success = response.success;
+ this.dispatchEvent(event);
+ },
+
+ /**
+ * Calling printer setup failed.
+ * @param {string} printerId The printer for which the request failed.
+ */
+ onPrinterFailure_: function(printerId) {
+ var event = new Event(
+ DestinationStore.EventType.PRINTER_CONFIGURED);
+ event.printerId = printerId;
+ event.success = false;
+ this.dispatchEvent(event);
+ },
+
+ /**
* Inserts {@code destination} to the data store and dispatches a
* DESTINATIONS_INSERTED event.
* @param {!print_preview.Destination} destination Print destination to
@@ -1524,8 +1593,13 @@ cr.define('print_preview', function() {
var destinationId = event.settingsInfo['printerId'];
var printerName = event.settingsInfo['printerName'];
var printerDescription = event.settingsInfo['printerDescription'];
+ // PDF is special since we don't need to query the device for
+ // capabilities.
+ var origin = destinationId ==
+ print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ?
+ print_preview.Destination.Origin.LOCAL : this.platformOrigin_;
var key = this.getDestinationKey_(
- print_preview.Destination.Origin.LOCAL,
+ origin,
destinationId,
'');
var destination = this.destinationMap_[key];

Powered by Google App Engine
This is Rietveld 408576698