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 bf0e573411fb4c7e9c97e1770e30397b080262f4..ca2d9a632436fb741d2c469e76d8d1a370164d3b 100644 |
--- a/chrome/browser/resources/print_preview/print_preview.js |
+++ b/chrome/browser/resources/print_preview/print_preview.js |
@@ -23,6 +23,9 @@ var defaultOrLastUsedPrinterName = ''; |
// True when a pending print preview request exists. |
var hasPendingPreviewRequest = false; |
+// The ID of the last preview request. |
+var lastPreviewRequestID = -1; |
+ |
// True when a pending print file request exists. |
var hasPendingPrintFileRequest = false; |
@@ -257,15 +260,15 @@ function getDuplexMode() { |
} |
/** |
- * Creates a JSON string based on the values in the printer settings. |
+ * Creates an object based on the values in the printer settings. |
* |
- * @return {string} JSON string with print job settings. |
+ * @return {Object} Object containing print job settings. |
*/ |
-function getSettingsJSON() { |
+function getSettings() { |
var deviceName = getSelectedPrinterName(); |
var printToPDF = (deviceName == PRINT_TO_PDF); |
- return JSON.stringify( |
+ var settings = |
{'deviceName': deviceName, |
'pageRange': pageSettings.selectedPageRanges, |
'printAll': pageSettings.allPagesRadioButton.checked, |
@@ -274,7 +277,16 @@ function getSettingsJSON() { |
'collate': isCollated(), |
'landscape': isLandscape(), |
'color': isColor(), |
- 'printToPDF': printToPDF}); |
+ 'printToPDF': printToPDF, |
+ 'requestID': 0}; |
+ return settings; |
+} |
+ |
+/** |
+ * @return {number} The next unused preview request id. |
+ */ |
+function generatePreviewRequestID() { |
+ return ++lastPreviewRequestID; |
} |
/** |
@@ -345,7 +357,7 @@ function cancelPendingPrintRequest() { |
* Sends a message to initiate print workflow. |
*/ |
function sendPrintFileRequest() { |
- chrome.send('print', [getSettingsJSON()]); |
+ chrome.send('print', [JSON.stringify(getSettings())]); |
} |
/** |
@@ -358,7 +370,9 @@ function requestPrintPreview() { |
if (!isTabHidden) |
showLoadingAnimation(); |
- chrome.send('getPreview', [getSettingsJSON()]); |
+ var settings = getSettings(); |
+ settings.requestID = generatePreviewRequestID(); |
+ chrome.send('getPreview', [JSON.stringify(settings)]); |
} |
/** |
@@ -545,8 +559,15 @@ function onDidPreviewPage(pageNumber) { |
* @param {string} jobTitle The print job title. |
* @param {boolean} modifiable If the preview is modifiable. |
* @param {string} previewUid Preview unique identifier. |
- */ |
-function updatePrintPreview(jobTitle, modifiable, previewUid) { |
+ * @param {number} previewRequestId The preview request id that resulted in this |
+ * response. |
+ */ |
+function updatePrintPreview(jobTitle, |
+ modifiable, |
+ previewUid, |
+ previewRequestId) { |
+ if (lastPreviewRequestID != previewRequestId) |
+ return; |
hasPendingPreviewRequest = false; |
if (checkIfSettingsChangedAndRegeneratePreview()) |