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

Unified Diff: chrome/renderer/print_web_view_helper.cc

Issue 7831041: Fix print preview workflow to reflect settings of selected printer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Update per code review Created 9 years, 3 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/renderer/print_web_view_helper.cc
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index 784fc1042bc478e36746cb5ea3cff2c192878de8..06a9a9a547e265db1fa7777a1955b62e77d95c7a 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -567,19 +567,19 @@ void PrintWebViewHelper::OnPrintForPrintPreview(
return;
}
- WebFrame* pdf_frame = pdf_element.document().frame();
- scoped_ptr<PrepareFrameAndViewForPrint> prepare;
- if (!InitPrintSettingsAndPrepareFrame(pdf_frame, &pdf_element, &prepare)) {
- LOG(ERROR) << "Failed to initialize print page settings";
- return;
- }
-
if (!UpdatePrintSettings(job_settings, false)) {
LOG(ERROR) << "UpdatePrintSettings failed";
DidFinishPrinting(FAIL_PRINT);
return;
}
+ WebFrame* pdf_frame = pdf_element.document().frame();
+ scoped_ptr<PrepareFrameAndViewForPrint> prepare;
+ prepare.reset(new PrepareFrameAndViewForPrint(print_pages_params_->params,
+ pdf_frame, &pdf_element));
+ UpdatePrintableSizeInPrintParameters(pdf_frame, &pdf_element, prepare.get(),
+ &print_pages_params_->params);
+
// Render Pages for printing.
if (!RenderPagesForPrint(pdf_frame, &pdf_element, prepare.get())) {
LOG(ERROR) << "RenderPagesForPrint failed";
@@ -629,17 +629,12 @@ void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) {
DCHECK(is_preview_);
print_preview_context_.OnPrintPreview();
- if (!InitPrintSettings(print_preview_context_.frame(),
- print_preview_context_.node(),
- true)) {
- Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings(
- routing_id(),
- print_pages_params_->params.document_cookie));
- return;
- }
-
if (!UpdatePrintSettings(settings, true)) {
- LOG(ERROR) << "UpdatePrintSettings failed";
+ if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) {
+ Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings(
+ routing_id(), print_pages_params_->params.document_cookie));
+ notify_browser_of_print_failure_ = false; // Already sent.
+ }
DidFinishPrinting(FAIL_PREVIEW);
return;
}
@@ -804,8 +799,10 @@ void PrintWebViewHelper::Print(WebKit::WebFrame* frame, WebKit::WebNode* node) {
// Initialize print settings.
scoped_ptr<PrepareFrameAndViewForPrint> prepare;
- if (!InitPrintSettingsAndPrepareFrame(frame, node, &prepare))
+ if (!InitPrintSettingsAndPrepareFrame(frame, node, &prepare)) {
+ DidFinishPrinting(FAIL_PRINT);
return; // Failed to init print page settings.
+ }
int expected_page_count = 0;
bool use_browser_overlays = true;
@@ -851,7 +848,8 @@ void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) {
} else if (result == FAIL_PREVIEW) {
DCHECK(is_preview_);
store_print_pages_params = false;
- int cookie = print_pages_params_->params.document_cookie;
+ int cookie = print_pages_params_.get() ?
+ print_pages_params_->params.document_cookie : 0;
if (notify_browser_of_print_failure_)
Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie));
else
@@ -1054,9 +1052,7 @@ void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters(
prepare->UpdatePrintParams(*params);
}
-bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame,
- WebKit::WebNode* node,
- bool is_preview) {
+bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame) {
DCHECK(frame);
PrintMsg_PrintPages_Params settings;
@@ -1067,12 +1063,10 @@ bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame,
// terminate.
bool result = true;
if (PrintMsg_Print_Params_IsEmpty(settings.params)) {
- if (!is_preview) {
- render_view()->runModalAlertDialog(
- frame,
- l10n_util::GetStringUTF16(
- IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
- }
+ render_view()->runModalAlertDialog(
+ frame,
+ l10n_util::GetStringUTF16(
+ IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
result = false;
}
@@ -1091,7 +1085,7 @@ bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame,
bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame(
WebKit::WebFrame* frame, WebKit::WebNode* node,
scoped_ptr<PrepareFrameAndViewForPrint>* prepare) {
- if (!InitPrintSettings(frame, node, false))
+ if (!InitPrintSettings(frame))
return false;
DCHECK(!prepare->get());
@@ -1106,10 +1100,37 @@ bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame(
bool PrintWebViewHelper::UpdatePrintSettings(
const DictionaryValue& job_settings, bool is_preview) {
- PrintMsg_PrintPages_Params settings;
+ if (job_settings.empty()) {
+ if (is_preview)
+ print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING);
+ return false;
+ }
+ // Send the cookie so that UpdatePrintSettings can reuse PrintQuery when
Lei Zhang 2011/09/21 03:56:04 nit: s/PrintQuery/PrinterQuery/
arthurhsu 2011/09/22 00:01:26 Done.
+ // possible.
+ int cookie = print_pages_params_.get() ?
+ print_pages_params_->params.document_cookie : 0;
Lei Zhang 2011/09/21 03:56:04 nit: indentation
arthurhsu 2011/09/22 00:01:26 Done.
+ PrintMsg_PrintPages_Params settings;
Send(new PrintHostMsg_UpdatePrintSettings(routing_id(),
- print_pages_params_->params.document_cookie, job_settings, &settings));
+ cookie, job_settings, &settings));
+ print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
+
+ if (PrintMsg_Print_Params_IsEmpty(settings.params)) {
+ if (!is_preview) {
Lei Zhang 2011/09/21 03:56:04 nit: I would do: if (is_preview) { ... } else { .
arthurhsu 2011/09/22 00:01:26 Done.
+ WebKit::WebFrame* frame = print_preview_context_.frame();
+ if (!frame)
+ GetPrintFrame(&frame);
+ DCHECK(frame);
Lei Zhang 2011/09/21 03:56:04 GetPrintFrame() can fail. Thus I don't know if thi
arthurhsu 2011/09/22 00:01:26 Done.
+ render_view()->runModalAlertDialog(
+ frame,
+ l10n_util::GetStringUTF16(
+ IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
+ } else {
+ print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
+ }
+ return false;
+ }
+
if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) {
print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS);
return false;
@@ -1545,6 +1566,10 @@ PrintWebViewHelper::PrintPreviewContext::print_params() const {
return *print_params_;
}
+int PrintWebViewHelper::PrintPreviewContext::last_error() const {
+ return error_;
+}
+
const gfx::Size&
PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const {
return prep_frame_view_->GetPrintCanvasSize();

Powered by Google App Engine
This is Rietveld 408576698