Index: chrome/browser/resources/print_preview/print_preview.js |
diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js |
index 1162a515ad2b2c6464a9a079d9719258a26d9505..e620a71176c5492cde774accf2836b84cce3290e 100644 |
--- a/chrome/browser/resources/print_preview/print_preview.js |
+++ b/chrome/browser/resources/print_preview/print_preview.js |
@@ -350,18 +350,6 @@ cr.define('print_preview', function() { |
nativeLayerEventTarget, |
print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE, |
this.onCloudPrintEnable_.bind(this)); |
- this.tracker.add( |
- nativeLayerEventTarget, |
- print_preview.NativeLayer.EventType.PRINT_TO_CLOUD, |
- this.onPrintToCloud_.bind(this)); |
- this.tracker.add( |
- nativeLayerEventTarget, |
- print_preview.NativeLayer.EventType.FILE_SELECTION_CANCEL, |
- this.onFileSelectionCancel_.bind(this)); |
- this.tracker.add( |
- nativeLayerEventTarget, |
- print_preview.NativeLayer.EventType.FILE_SELECTION_COMPLETE, |
- this.onFileSelectionComplete_.bind(this)); |
this.tracker.add( |
nativeLayerEventTarget, |
print_preview.NativeLayer.EventType.SETTINGS_INVALID, |
@@ -544,9 +532,8 @@ cr.define('print_preview', function() { |
this.setIsEnabled_(false); |
this.printHeader_.isCancelButtonEnabled = true; |
var printAttemptResult = this.printIfReady_(); |
- if (printAttemptResult == print_preview.PrintAttemptResult_.PRINTED || |
- printAttemptResult == |
- print_preview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW) { |
+ if (printAttemptResult == |
+ print_preview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW) { |
if ((this.destinationStore_.selectedDestination.isLocal && |
!this.destinationStore_.selectedDestination.isPrivet && |
!this.destinationStore_.selectedDestination.isExtension && |
@@ -590,11 +577,52 @@ cr.define('print_preview', function() { |
print_preview.Metrics.PrintSettingsUiBucket |
.PRINT_WITH_SETTINGS_COLLAPSED); |
} |
- this.nativeLayer_.startPrint( |
- assert(this.destinationStore_.selectedDestination), |
- this.printTicketStore_, this.cloudPrintInterface_, this.documentInfo_, |
- this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, |
- this.showSystemDialogBeforeNextPrint_); |
+ var destination = assert(this.destinationStore_.selectedDestination); |
+ this.nativeLayer_ |
+ .print( |
+ destination, this.printTicketStore_, this.cloudPrintInterface_, |
+ this.documentInfo_, |
+ this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, |
+ this.showSystemDialogBeforeNextPrint_) |
+ /** |
+ * @param {?string=} data Data for cloud print if this is a cloud |
+ * printer, otherwise undefined. |
+ */ |
+ .then( |
+ function(data) { |
+ if (!destination.isLocal) { |
+ assert(data); |
+ this.onPrintToCloud_(data); |
+ } else if (destination.isPrivet || destination.isExtension) { |
+ this.close_(); |
+ } else if ( |
+ destination.id == |
+ print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
+ this.onFileSelectionComplete_(); |
+ } else { // local |
+ this.nativeLayer_.startHideDialog(); |
+ } |
+ }.bind(this), |
+ /** |
+ * @param {*} response The response indicating the type of error |
+ * for extension and privet printers, or undefined for PDF, |
+ * local, and cloud printers. |
+ */ |
+ function(response) { |
+ if (!destination.isLocal) { |
+ // Happens only if the ticket wasn't parsed. |
+ this.onSettingsInvalid_(); |
+ } else if (destination.isPrivet || destination.isExtension) { |
+ this.onPrintFailed_(response); |
+ } else if ( |
+ destination.id == |
+ print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
+ this.onFileSelectionCancel_(); |
+ } else { // local |
+ this.nativeLayer_.startHideDialog(); |
+ } |
+ }.bind(this)); |
+ |
this.showSystemDialogBeforeNextPrint_ = false; |
return print_preview.PrintAttemptResult_.PRINTED; |
}, |
@@ -707,10 +735,10 @@ cr.define('print_preview', function() { |
/** |
* Called from the native layer when ready to print to Google Cloud Print. |
- * @param {Event} event Contains the body to send in the HTTP request. |
+ * @param {string} data Contains the body to send in the HTTP request. |
* @private |
*/ |
- onPrintToCloud_: function(event) { |
+ onPrintToCloud_: function(data) { |
assert( |
this.uiState_ == PrintPreviewUiState_.PRINTING, |
'Document ready to be sent to the cloud when not in printing ' + |
@@ -721,7 +749,7 @@ cr.define('print_preview', function() { |
assert(this.destinationStore_.selectedDestination != null); |
this.cloudPrintInterface_.submit( |
this.destinationStore_.selectedDestination, this.printTicketStore_, |
- this.documentInfo_, event.data); |
+ this.documentInfo_, data); |
}, |
/** |
@@ -1027,8 +1055,8 @@ cr.define('print_preview', function() { |
/** |
* Called when printing to a privet or extension printer fails. |
- * @param {number | string} httpError The HTTP error code, or -1 if not an |
- * HTTP error. |
+ * @param {*} httpError The HTTP error code, or -1 or a string describing |
+ * the error, if not an HTTP error. |
* @private |
*/ |
onPrintFailed_: function(httpError) { |