summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/printing/print_preview_message_handler.cc6
-rw-r--r--chrome/browser/resources/print_preview/print_preview.js55
-rw-r--r--chrome/browser/ui/webui/print_preview_ui.cc6
-rw-r--r--chrome/browser/ui/webui/print_preview_ui.h4
-rw-r--r--chrome/common/print_messages.h5
-rw-r--r--chrome/renderer/print_web_view_helper.cc8
-rw-r--r--chrome/renderer/print_web_view_helper_browsertest.cc1
-rw-r--r--chrome/renderer/print_web_view_helper_linux.cc1
-rw-r--r--chrome/renderer/print_web_view_helper_mac.mm1
-rw-r--r--chrome/renderer/print_web_view_helper_win.cc1
-rw-r--r--printing/print_job_constants.cc3
-rw-r--r--printing/print_job_constants.h1
12 files changed, 70 insertions, 22 deletions
diff --git a/chrome/browser/printing/print_preview_message_handler.cc b/chrome/browser/printing/print_preview_message_handler.cc
index a712915..db57d77 100644
--- a/chrome/browser/printing/print_preview_message_handler.cc
+++ b/chrome/browser/printing/print_preview_message_handler.cc
@@ -119,7 +119,8 @@ void PrintPreviewMessageHandler::OnPagesReadyForPreview(
print_preview_ui->OnPreviewDataIsAvailable(
params.expected_pages_count,
wrapper->print_view_manager()->RenderSourceName(),
- params.modifiable);
+ params.modifiable,
+ params.preview_request_id);
return;
}
@@ -146,7 +147,8 @@ void PrintPreviewMessageHandler::OnPagesReadyForPreview(
print_preview_ui->OnPreviewDataIsAvailable(
params.expected_pages_count,
wrapper->print_view_manager()->RenderSourceName(),
- params.modifiable);
+ params.modifiable,
+ params.preview_request_id);
}
void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) {
diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js
index e26fcd8..2870e7b 100644
--- a/chrome/browser/resources/print_preview/print_preview.js
+++ b/chrome/browser/resources/print_preview/print_preview.js
@@ -33,6 +33,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;
@@ -341,31 +344,40 @@ 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);
- var settings = {'deviceName': deviceName,
- 'pageRange': pageSettings.selectedPageRanges,
- 'printAll': pageSettings.allPagesRadioButton.checked,
- 'duplex': getDuplexMode(),
- 'copies': copiesSettings.numberOfCopies,
- 'collate': isCollated(),
- 'landscape': isLandscape(),
- 'color': isColor(),
- 'printToPDF': printToPDF};
+ var settings =
+ {'deviceName': deviceName,
+ 'pageRange': pageSettings.selectedPageRanges,
+ 'printAll': pageSettings.allPagesRadioButton.checked,
+ 'duplex': getDuplexMode(),
+ 'copies': copiesSettings.numberOfCopies,
+ 'collate': isCollated(),
+ 'landscape': isLandscape(),
+ 'color': isColor(),
+ 'printToPDF': printToPDF,
+ 'requestID': 0};
+
var printerList = $('printer-list');
var selectedPrinter = printerList.selectedIndex;
if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) {
settings['cloudPrintID'] =
printerList.options[selectedPrinter].value;
}
+ return settings;
+}
- return JSON.stringify(settings);
+/**
+ * @return {number} The next unused preview request id.
+ */
+function generatePreviewRequestID() {
+ return ++lastPreviewRequestID;
}
/**
@@ -441,7 +453,7 @@ function sendPrintFileRequest() {
var printer = printerList[printerList.selectedIndex];
chrome.send('saveLastPrinter', [printer.textContent,
cloudprint.getData(printer)]);
- chrome.send('print', [getSettingsJSON(),
+ chrome.send('print', [JSON.stringify(getSettings()),
cloudprint.getPrintTicketJSON(printer)]);
}
@@ -455,7 +467,9 @@ function requestPrintPreview() {
if (!isTabHidden)
showLoadingAnimation();
- chrome.send('getPreview', [getSettingsJSON()]);
+ var settings = getSettings();
+ settings.requestID = generatePreviewRequestID();
+ chrome.send('getPreview', [JSON.stringify(settings)]);
}
/**
@@ -800,8 +814,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())
diff --git a/chrome/browser/ui/webui/print_preview_ui.cc b/chrome/browser/ui/webui/print_preview_ui.cc
index e5efdfa..f6de73c 100644
--- a/chrome/browser/ui/webui/print_preview_ui.cc
+++ b/chrome/browser/ui/webui/print_preview_ui.cc
@@ -68,7 +68,8 @@ void PrintPreviewUI::OnDidPreviewPage(int page_number) {
void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count,
const string16& job_title,
- bool modifiable) {
+ bool modifiable,
+ int preview_request_id) {
VLOG(1) << "Print preview request finished with "
<< expected_pages_count << " pages";
DecrementRequestCount();
@@ -84,8 +85,9 @@ void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count,
StringValue title(job_title);
FundamentalValue is_preview_modifiable(modifiable);
StringValue ui_identifier(preview_ui_addr_str_);
+ FundamentalValue ui_preview_request_id(preview_request_id);
CallJavascriptFunction("updatePrintPreview", title, is_preview_modifiable,
- ui_identifier);
+ ui_identifier, ui_preview_request_id);
}
void PrintPreviewUI::OnNavigation() {
diff --git a/chrome/browser/ui/webui/print_preview_ui.h b/chrome/browser/ui/webui/print_preview_ui.h
index f2d44ce..28a91ad 100644
--- a/chrome/browser/ui/webui/print_preview_ui.h
+++ b/chrome/browser/ui/webui/print_preview_ui.h
@@ -46,9 +46,11 @@ class PrintPreviewUI : public ChromeWebUI {
// |job_title| is the title of the page being previewed.
// |modifiable| indicates if the preview can be rerendered with different
// print settings.
+ // |preview_request_id| indicates wich request resulted in this response.
void OnPreviewDataIsAvailable(int expected_pages_count,
const string16& job_title,
- bool modifiable);
+ bool modifiable,
+ int preview_request_id);
// Notify the Web UI that a navigation has occurred in this tab. This is the
// last chance to communicate with the source tab before the assocation is
diff --git a/chrome/common/print_messages.h b/chrome/common/print_messages.h
index 0c8c48a..11547bc 100644
--- a/chrome/common/print_messages.h
+++ b/chrome/common/print_messages.h
@@ -48,6 +48,8 @@ IPC_STRUCT_BEGIN(PrintMsg_Print_Params)
// Does the printer support alpha blending?
IPC_STRUCT_MEMBER(bool, supports_alpha_blend)
+
+ IPC_STRUCT_MEMBER(int, preview_request_id)
IPC_STRUCT_END()
IPC_STRUCT_BEGIN(PrintMsg_PrintPage_Params)
@@ -89,6 +91,9 @@ IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params)
// Whether the preview can be modified.
IPC_STRUCT_MEMBER(bool, modifiable)
+
+ // The id of the preview request.
+ IPC_STRUCT_MEMBER(int, preview_request_id)
IPC_STRUCT_END()
// Parameters to describe a rendered page.
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index a1c3382..8302907 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -382,6 +382,8 @@ void PrintWebViewHelper::PrintPreview(WebKit::WebFrame* frame,
print_pages_params_->params.document_cookie;
preview_params.expected_pages_count = preview_page_count_;
preview_params.modifiable = IsModifiable(frame, node);
+ preview_params.preview_request_id =
+ print_pages_params_->params.preview_request_id;
Send(new PrintHostMsg_PagesReadyForPreview(routing_id(), preview_params));
return;
@@ -686,6 +688,12 @@ bool PrintWebViewHelper::UpdatePrintSettingsLocal(
if (settings.params.dpi < kMinDpi || !settings.params.document_cookie)
return false;
+ if (!job_settings.GetInteger(printing::kPreviewRequestID,
+ &settings.params.preview_request_id)) {
+ NOTREACHED();
+ return false;
+ }
+
print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
settings.params.document_cookie));
diff --git a/chrome/renderer/print_web_view_helper_browsertest.cc b/chrome/renderer/print_web_view_helper_browsertest.cc
index 1dd8e51..97873d6 100644
--- a/chrome/renderer/print_web_view_helper_browsertest.cc
+++ b/chrome/renderer/print_web_view_helper_browsertest.cc
@@ -41,6 +41,7 @@ void CreatePrintSettingsDictionary(DictionaryValue* dict) {
dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX);
dict->SetInteger(printing::kSettingCopies, 1);
dict->SetString(printing::kSettingDeviceName, "dummy");
+ dict->SetInteger(printing::kPreviewRequestID, 12345);
}
} // namespace
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc
index 9255a00..4947f14 100644
--- a/chrome/renderer/print_web_view_helper_linux.cc
+++ b/chrome/renderer/print_web_view_helper_linux.cc
@@ -49,6 +49,7 @@ bool PrintWebViewHelper::CreatePreviewDocument(
preview_params.document_cookie = params.params.document_cookie;
preview_params.expected_pages_count = preview_page_count_;
preview_params.modifiable = IsModifiable(frame, node);
+ preview_params.preview_request_id = params.params.preview_request_id;
if (!CopyMetafileDataToSharedMem(&metafile,
&(preview_params.metafile_data_handle))) {
diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm
index 54521ff..5878c20 100644
--- a/chrome/renderer/print_web_view_helper_mac.mm
+++ b/chrome/renderer/print_web_view_helper_mac.mm
@@ -127,6 +127,7 @@ bool PrintWebViewHelper::CreatePreviewDocument(
preview_params.document_cookie = params.params.document_cookie;
preview_params.expected_pages_count = preview_page_count_;
preview_params.modifiable = IsModifiable(frame, node);
+ preview_params.preview_request_id = params.params.preview_request_id;
// Ask the browser to create the shared memory for us.
if (!CopyMetafileDataToSharedMem(&metafile,
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc
index 9528797..36139be 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -199,6 +199,7 @@ bool PrintWebViewHelper::CreatePreviewDocument(
preview_params.document_cookie = params.params.document_cookie;
preview_params.expected_pages_count = preview_page_count_;
preview_params.modifiable = IsModifiable(frame, node);
+ preview_params.preview_request_id = params.params.preview_request_id;
if (!CopyMetafileDataToSharedMem(metafile.get(),
&(preview_params.metafile_data_handle))) {
diff --git a/printing/print_job_constants.cc b/printing/print_job_constants.cc
index 7e2f634..f0e5e77 100644
--- a/printing/print_job_constants.cc
+++ b/printing/print_job_constants.cc
@@ -6,6 +6,9 @@
namespace printing {
+// Unique ID sent along every preview request.
+const char kPreviewRequestID[] = "requestID";
+
// Print using cloud print: true if selected, false if not.
const char kSettingCloudPrintId[] = "cloudPrintID";
diff --git a/printing/print_job_constants.h b/printing/print_job_constants.h
index 40b9231..e877a01 100644
--- a/printing/print_job_constants.h
+++ b/printing/print_job_constants.h
@@ -7,6 +7,7 @@
namespace printing {
+extern const char kPreviewRequestID[];
extern const char kSettingCloudPrintId[];
extern const char kSettingCollate[];
extern const char kSettingColor[];