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 fe4a016fbe2b54f099df8ac07386e45b2438f202..03ce8f7240580a69aa658d3cf082c4864a428c89 100644 |
--- a/chrome/browser/resources/print_preview/print_preview.js |
+++ b/chrome/browser/resources/print_preview/print_preview.js |
@@ -6,10 +6,32 @@ |
// <include src="component.js"> |
// <include src="print_preview_focus_manager.js"> |
+// |
+ |
+cr.exportPath('print_preview'); |
+ |
+/** |
+ * States of the print preview. |
+ * @enum {string} |
+ * @private |
+ */ |
+print_preview.PrintPreviewUiState_ = { |
+ INITIALIZING: 'initializing', |
+ READY: 'ready', |
+ OPENING_PDF_PREVIEW: 'opening-pdf-preview', |
+ OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog', |
+ PRINTING: 'printing', |
+ FILE_SELECTION: 'file-selection', |
+ CLOSING: 'closing', |
+ ERROR: 'error' |
+}; |
+ |
cr.define('print_preview', function() { |
'use strict'; |
+ var PrintPreviewUiState_ = print_preview.PrintPreviewUiState_; |
+ |
/** |
* Container class for Chromium's print preview. |
* @constructor |
@@ -270,10 +292,10 @@ cr.define('print_preview', function() { |
/** |
* State of the print preview UI. |
- * @type {print_preview.PrintPreview.UiState_} |
+ * @type {print_preview.PrintPreviewUiState_} |
* @private |
*/ |
- this.uiState_ = PrintPreview.UiState_.INITIALIZING; |
+ this.uiState_ = PrintPreviewUiState_.INITIALIZING; |
/** |
* Whether document preview generation is in progress. |
@@ -288,23 +310,7 @@ cr.define('print_preview', function() { |
* @private |
*/ |
this.showSystemDialogBeforeNextPrint_ = false; |
- }; |
- |
- /** |
- * States of the print preview. |
- * @enum {string} |
- * @private |
- */ |
- PrintPreview.UiState_ = { |
- INITIALIZING: 'initializing', |
- READY: 'ready', |
- OPENING_PDF_PREVIEW: 'opening-pdf-preview', |
- OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog', |
- PRINTING: 'printing', |
- FILE_SELECTION: 'file-selection', |
- CLOSING: 'closing', |
- ERROR: 'error' |
- }; |
+ } |
/** |
* What can happen when print preview tries to print. |
@@ -377,13 +383,13 @@ cr.define('print_preview', function() { |
if ($('system-dialog-link')) { |
this.tracker.add( |
- $('system-dialog-link'), |
+ getRequiredElement('system-dialog-link'), |
'click', |
this.openSystemPrintDialog_.bind(this)); |
} |
if ($('open-pdf-in-preview-link')) { |
this.tracker.add( |
- $('open-pdf-in-preview-link'), |
+ getRequiredElement('open-pdf-in-preview-link'), |
'click', |
this.onOpenPdfInPreviewLinkClick_.bind(this)); |
} |
@@ -529,16 +535,16 @@ cr.define('print_preview', function() { |
* @private |
*/ |
printDocumentOrOpenPdfPreview_: function(isPdfPreview) { |
- assert(this.uiState_ == PrintPreview.UiState_.READY, |
+ assert(this.uiState_ == PrintPreviewUiState_.READY, |
'Print document request received when not in ready state: ' + |
this.uiState_); |
if (isPdfPreview) { |
- this.uiState_ = PrintPreview.UiState_.OPENING_PDF_PREVIEW; |
+ this.uiState_ = PrintPreviewUiState_.OPENING_PDF_PREVIEW; |
} else if (this.destinationStore_.selectedDestination.id == |
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
- this.uiState_ = PrintPreview.UiState_.FILE_SELECTION; |
+ this.uiState_ = PrintPreviewUiState_.FILE_SELECTION; |
} else { |
- this.uiState_ = PrintPreview.UiState_.PRINTING; |
+ this.uiState_ = PrintPreviewUiState_.PRINTING; |
} |
this.setIsEnabled_(false); |
this.printHeader_.isCancelButtonEnabled = true; |
@@ -551,7 +557,7 @@ cr.define('print_preview', function() { |
!this.destinationStore_.selectedDestination.isExtension && |
this.destinationStore_.selectedDestination.id != |
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) || |
- this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW) { |
+ this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW) { |
// Hide the dialog for now. The actual print command will be issued |
// when the preview generation is done. |
this.nativeLayer_.startHideDialog(); |
@@ -566,9 +572,9 @@ cr.define('print_preview', function() { |
*/ |
printIfReady_: function() { |
var okToPrint = |
- (this.uiState_ == PrintPreview.UiState_.PRINTING || |
- this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW || |
- this.uiState_ == PrintPreview.UiState_.FILE_SELECTION || |
+ (this.uiState_ == PrintPreviewUiState_.PRINTING || |
+ this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW || |
+ this.uiState_ == PrintPreviewUiState_.FILE_SELECTION || |
this.isInKioskAutoPrintMode_) && |
this.destinationStore_.selectedDestination && |
this.destinationStore_.selectedDestination.capabilities; |
@@ -589,11 +595,11 @@ cr.define('print_preview', function() { |
PRINT_WITH_SETTINGS_COLLAPSED); |
} |
this.nativeLayer_.startPrint( |
- this.destinationStore_.selectedDestination, |
+ assert(this.destinationStore_.selectedDestination), |
this.printTicketStore_, |
this.cloudPrintInterface_, |
this.documentInfo_, |
- this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW, |
+ this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, |
this.showSystemDialogBeforeNextPrint_); |
this.showSystemDialogBeforeNextPrint_ = false; |
return PrintPreview.PrintAttemptResult_.PRINTED; |
@@ -605,7 +611,7 @@ cr.define('print_preview', function() { |
*/ |
close_: function() { |
this.exitDocument(); |
- this.uiState_ = PrintPreview.UiState_.CLOSING; |
+ this.uiState_ = PrintPreviewUiState_.CLOSING; |
this.nativeLayer_.startCloseDialog(); |
}, |
@@ -625,7 +631,7 @@ cr.define('print_preview', function() { |
} |
setIsVisible(getRequiredElement('system-dialog-throbber'), true); |
this.setIsEnabled_(false); |
- this.uiState_ = PrintPreview.UiState_.OPENING_NATIVE_PRINT_DIALOG; |
+ this.uiState_ = PrintPreviewUiState_.OPENING_NATIVE_PRINT_DIALOG; |
this.nativeLayer_.startShowSystemDialog(); |
}, |
@@ -638,10 +644,10 @@ cr.define('print_preview', function() { |
* @private |
*/ |
onInitialSettingsSet_: function(event) { |
- assert(this.uiState_ == PrintPreview.UiState_.INITIALIZING, |
+ assert(this.uiState_ == PrintPreviewUiState_.INITIALIZING, |
'Updating initial settings when not in initializing state: ' + |
this.uiState_); |
- this.uiState_ = PrintPreview.UiState_.READY; |
+ this.uiState_ = PrintPreviewUiState_.READY; |
var settings = event.initialSettings; |
this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode; |
@@ -667,7 +673,7 @@ cr.define('print_preview', function() { |
$('document-title').innerText = settings.documentTitle; |
this.hideSystemDialogLink_ = settings.isInAppKioskMode; |
if ($('system-dialog-link')) { |
- setIsVisible($('system-dialog-link'), |
+ setIsVisible(getRequiredElement('system-dialog-link'), |
this.shouldShowSystemDialogLink_()); |
} |
}, |
@@ -687,19 +693,19 @@ cr.define('print_preview', function() { |
event.appKioskMode); |
this.tracker.add( |
this.cloudPrintInterface_, |
- cloudprint.CloudPrintInterface.EventType.SUBMIT_DONE, |
+ cloudprint.CloudPrintInterfaceEventType.SUBMIT_DONE, |
this.onCloudPrintSubmitDone_.bind(this)); |
this.tracker.add( |
this.cloudPrintInterface_, |
- cloudprint.CloudPrintInterface.EventType.SEARCH_FAILED, |
+ cloudprint.CloudPrintInterfaceEventType.SEARCH_FAILED, |
this.onCloudPrintError_.bind(this)); |
this.tracker.add( |
this.cloudPrintInterface_, |
- cloudprint.CloudPrintInterface.EventType.SUBMIT_FAILED, |
+ cloudprint.CloudPrintInterfaceEventType.SUBMIT_FAILED, |
this.onCloudPrintError_.bind(this)); |
this.tracker.add( |
this.cloudPrintInterface_, |
- cloudprint.CloudPrintInterface.EventType.PRINTER_FAILED, |
+ cloudprint.CloudPrintInterfaceEventType.PRINTER_FAILED, |
this.onCloudPrintError_.bind(this)); |
this.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_); |
@@ -716,11 +722,12 @@ cr.define('print_preview', function() { |
* @private |
*/ |
onPrintToCloud_: function(event) { |
- assert(this.uiState_ == PrintPreview.UiState_.PRINTING, |
+ assert(this.uiState_ == PrintPreviewUiState_.PRINTING, |
'Document ready to be sent to the cloud when not in printing ' + |
'state: ' + this.uiState_); |
assert(this.cloudPrintInterface_ != null, |
'Google Cloud Print is not enabled'); |
+ assert(this.destinationStore_.selectedDestination != null); |
this.cloudPrintInterface_.submit( |
this.destinationStore_.selectedDestination, |
this.printTicketStore_, |
@@ -734,11 +741,11 @@ cr.define('print_preview', function() { |
* @private |
*/ |
onFileSelectionCancel_: function() { |
- assert(this.uiState_ == PrintPreview.UiState_.FILE_SELECTION, |
+ assert(this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, |
'File selection cancelled when not in file-selection state: ' + |
this.uiState_); |
this.setIsEnabled_(true); |
- this.uiState_ = PrintPreview.UiState_.READY; |
+ this.uiState_ = PrintPreviewUiState_.READY; |
}, |
/** |
@@ -746,12 +753,12 @@ cr.define('print_preview', function() { |
* @private |
*/ |
onFileSelectionComplete_: function() { |
- assert(this.uiState_ == PrintPreview.UiState_.FILE_SELECTION, |
+ assert(this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, |
'File selection completed when not in file-selection state: ' + |
this.uiState_); |
this.previewArea_.showCustomMessage( |
loadTimeData.getString('printingToPDFInProgress')); |
- this.uiState_ = PrintPreview.UiState_.PRINTING; |
+ this.uiState_ = PrintPreviewUiState_.PRINTING; |
}, |
/** |
@@ -760,7 +767,7 @@ cr.define('print_preview', function() { |
* @private |
*/ |
onCloudPrintSubmitDone_: function(event) { |
- assert(this.uiState_ == PrintPreview.UiState_.PRINTING, |
+ assert(this.uiState_ == PrintPreviewUiState_.PRINTING, |
'Submited job to Google Cloud Print but not in printing state ' + |
this.uiState_); |
this.close_(); |
@@ -817,7 +824,7 @@ cr.define('print_preview', function() { |
onPreviewGenerationFail_: function() { |
this.isPreviewGenerationInProgress_ = false; |
this.printHeader_.isPrintButtonEnabled = false; |
- if (this.uiState_ == PrintPreview.UiState_.PRINTING) |
+ if (this.uiState_ == PrintPreviewUiState_.PRINTING) |
this.nativeLayer_.startCancelPendingPrint(); |
}, |
@@ -829,7 +836,7 @@ cr.define('print_preview', function() { |
onOpenPdfInPreviewLinkClick_: function() { |
if ($('open-pdf-in-preview-link').classList.contains('disabled')) |
return; |
- assert(this.uiState_ == PrintPreview.UiState_.READY, |
+ assert(this.uiState_ == PrintPreviewUiState_.READY, |
'Trying to open pdf in preview when not in ready state: ' + |
this.uiState_); |
setIsVisible(getRequiredElement('open-preview-app-throbber'), true); |
@@ -844,7 +851,7 @@ cr.define('print_preview', function() { |
* @private |
*/ |
onPrintButtonClick_: function() { |
- assert(this.uiState_ == PrintPreview.UiState_.READY, |
+ assert(this.uiState_ == PrintPreviewUiState_.READY, |
'Trying to print when not in ready state: ' + this.uiState_); |
this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); |
}, |
@@ -911,7 +918,7 @@ cr.define('print_preview', function() { |
this.destinationStore_.selectedDestination && |
this.printTicketStore_.isTicketValid() && |
this.printHeader_.isPrintButtonEnabled) { |
- assert(this.uiState_ == PrintPreview.UiState_.READY, |
+ assert(this.uiState_ == PrintPreviewUiState_.READY, |
'Trying to print when not in ready state: ' + this.uiState_); |
var activeElementTag = document.activeElement.tagName.toUpperCase(); |
if (activeElementTag != 'BUTTON' && activeElementTag != 'SELECT' && |
@@ -931,7 +938,7 @@ cr.define('print_preview', function() { |
* @private |
*/ |
onSettingsInvalid_: function() { |
- this.uiState_ = PrintPreview.UiState_.ERROR; |
+ this.uiState_ = PrintPreviewUiState_.ERROR; |
this.isPreviewGenerationInProgress_ = false; |
this.printHeader_.isPrintButtonEnabled = false; |
this.previewArea_.cancelTimeout(); |
@@ -1196,13 +1203,13 @@ cr.define('print_preview', function() { |
*/ |
onDestinationSelect_: function() { |
if ($('system-dialog-link')) { |
- setIsVisible($('system-dialog-link'), |
+ setIsVisible(getRequiredElement('system-dialog-link'), |
this.shouldShowSystemDialogLink_()); |
} |
// Reset if we had a bad settings fetch since the user selected a new |
// printer. |
- if (this.uiState_ == PrintPreview.UiState_.ERROR) |
- this.uiState_ = PrintPreview.UiState_.READY; |
+ if (this.uiState_ == PrintPreviewUiState_.ERROR) |
+ this.uiState_ = PrintPreviewUiState_.READY; |
if (this.destinationStore_.selectedDestination && |
this.isInKioskAutoPrintMode_) { |
this.onPrintButtonClick_(); |