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

Unified Diff: chrome/browser/resources/print_preview/native_layer.js

Issue 2948723002: Print Preview: Change print to cr.sendWithPromise (Closed)
Patch Set: Address comments and add close_ param Created 3 years, 6 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/native_layer.js
diff --git a/chrome/browser/resources/print_preview/native_layer.js b/chrome/browser/resources/print_preview/native_layer.js
index 276cf72be6eb1b1d0cd06ba9856522e91aaac0a6..68e102d6706581d017af78d0ee4d7ffce49cf0f5 100644
--- a/chrome/browser/resources/print_preview/native_layer.js
+++ b/chrome/browser/resources/print_preview/native_layer.js
@@ -77,9 +77,6 @@ cr.define('print_preview', function() {
// Bind global handlers
global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this);
global.reloadPrintersList = this.onReloadPrintersList_.bind(this);
- global.printToCloud = this.onPrintToCloud_.bind(this);
- global.fileSelectionCancelled = this.onFileSelectionCancelled_.bind(this);
- global.fileSelectionCompleted = this.onFileSelectionCompleted_.bind(this);
global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this);
global.invalidPrinterSettings = this.onInvalidPrinterSettings_.bind(this);
global.onDidGetDefaultPageLayout =
@@ -132,9 +129,6 @@ cr.define('print_preview', function() {
CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE',
DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD',
DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING',
- FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL',
- FILE_SELECTION_COMPLETE:
- 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE',
MANIPULATE_SETTINGS_FOR_TEST:
'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST',
PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY',
@@ -144,7 +138,6 @@ cr.define('print_preview', function() {
'print_preview.NativeLayer.PREVIEW_GENERATION_DONE',
PREVIEW_GENERATION_FAIL:
'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL',
- PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD',
SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID',
PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS',
PROVISIONAL_DESTINATION_RESOLVED:
@@ -417,8 +410,10 @@ cr.define('print_preview', function() {
* system's preview application.
* @param {boolean=} opt_showSystemDialog Whether to open system dialog for
* advanced settings.
+ * @return {!Promise} Promise that will resolve when the print request is
+ * finished or rejected.
*/
- startPrint: function(
+ print: function(
destination, printTicketStore, cloudPrintInterface, documentInfo,
opt_isOpenPdfInPreview, opt_showSystemDialog) {
assert(
@@ -494,7 +489,7 @@ cr.define('print_preview', function() {
ticket['OpenPDFInPreview'] = true;
}
- chrome.send('print', [JSON.stringify(ticket)]);
+ return cr.sendWithPromise('print', JSON.stringify(ticket));
},
/** Requests that the current pending print request be cancelled. */
@@ -508,9 +503,16 @@ cr.define('print_preview', function() {
chrome.send('showSystemDialog');
},
- /** Closes the print preview dialog. */
- startCloseDialog: function() {
- chrome.send('closePrintPreviewDialog');
+ /**
+ * Closes the print preview dialog.
+ * If |isCancel| is true, also sends a message to Print Preview Handler in
+ * order to update UMA statistics.
+ * @param {boolean} isCancel whether this was called due to the user
+ * closing the dialog without printing.
+ */
+ startCloseDialog: function(isCancel) {
+ if (isCancel)
+ chrome.send('closePrintPreviewDialog');
dpapad 2017/06/23 23:17:26 Nit (optional): chrome.send(isCancel ? 'closePrin
rbpotter 2017/06/23 23:34:35 We want to send dialogClose either way though, so
dpapad 2017/06/23 23:45:01 Ah right, I misread the original code. Ignore my s
chrome.send('dialogClose');
},
@@ -569,41 +571,6 @@ cr.define('print_preview', function() {
this.eventTarget_, NativeLayer.EventType.DESTINATIONS_RELOAD);
},
- /**
- * Called from the C++ layer.
- * Take the PDF data handed to us and submit it to the cloud, closing the
- * print preview dialog once the upload is successful.
- * @param {string} data Data to send as the print job.
- * @private
- */
- onPrintToCloud_: function(data) {
- var printToCloudEvent = new Event(NativeLayer.EventType.PRINT_TO_CLOUD);
- printToCloudEvent.data = data;
- this.eventTarget_.dispatchEvent(printToCloudEvent);
- },
-
- /**
- * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print
- * preview dialog regarding the file selection cancel event.
- * @private
- */
- onFileSelectionCancelled_: function() {
- cr.dispatchSimpleEvent(
- this.eventTarget_, NativeLayer.EventType.FILE_SELECTION_CANCEL);
- },
-
- /**
- * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print
- * preview dialog regarding the file selection completed event.
- * @private
- */
- onFileSelectionCompleted_: function() {
- // If the file selection is completed and the dialog is not already closed
- // it means that a pending print to pdf request exists.
- cr.dispatchSimpleEvent(
- this.eventTarget_, NativeLayer.EventType.FILE_SELECTION_COMPLETE);
- },
-
/**
* Display an error message when print preview fails.
* Called from PrintPreviewMessageHandler::OnPrintPreviewFailed().

Powered by Google App Engine
This is Rietveld 408576698