Chromium Code Reviews| 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..fd87b0daa42b675d27ad6011a4b749d10b26584c 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,43 @@ 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). |
| + then( |
|
dpapad
2017/01/12 19:32:50
Nit: You would avoid a lot of indentation if you p
skau
2017/01/12 23:24:04
Done.
|
| + /** |
| + * Handle the result of a successful PRINTER_SETUP request. |
| + * @param {!PrinterSetupResponse} response. |
| + */ |
| + function(response) { |
| + this.dispatchEvent(new CustomEvent( |
| + DestinationStore.EventType.PRINTER_CONFIGURED, { |
| + detail: { |
|
dpapad
2017/01/12 19:32:50
Why not the following?
detail: response
Instead
skau
2017/01/12 23:24:04
No particular reason.
|
| + printerId: response.printerId, |
| + capabilities: response.capabilities, |
| + success: response.success |
| + } |
| + })); |
| + }.bind(this), |
| + /** |
| + * Calling printer setup failed. |
| + */ |
| + function() { |
| + this.dispatchEvent(new CustomEvent( |
| + DestinationStore.EventType.PRINTER_CONFIGURED, { |
| + detail: { |
| + printerId: destination.id, |
| + success: false |
| + } |
| + })); |
| + }.bind(this)); |
| + }, |
| + |
| + /** |
| * Attempts to resolve a provisional destination. |
| * @param {!print_preview.Destination} destinaion Provisional destination |
| * that should be resolved. |
| @@ -1119,9 +1187,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*/, |
| @@ -1524,8 +1592,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]; |