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 27f716a1d608e47c77e1f7aa7715c2056a34a65e..2bdaf56e70d581a6203a1bd05710d789db8cf58b 100644 |
--- a/chrome/renderer/print_web_view_helper.cc |
+++ b/chrome/renderer/print_web_view_helper.cc |
@@ -568,19 +568,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"; |
@@ -630,17 +630,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; |
} |
@@ -805,8 +800,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; |
@@ -852,7 +849,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 |
@@ -1055,9 +1053,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; |
@@ -1068,12 +1064,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; |
} |
@@ -1092,7 +1086,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()); |
@@ -1107,10 +1101,39 @@ bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( |
bool PrintWebViewHelper::UpdatePrintSettings( |
const DictionaryValue& job_settings, bool is_preview) { |
- PrintMsg_PrintPages_Params settings; |
+ if (is_preview && job_settings.empty()) { |
kmadhusu
2011/09/20 00:42:41
In the preview printing workflow, we still want to
arthurhsu
2011/09/20 18:41:19
Yes, but it shall send back BAD_SETTINGS instead o
|
+ print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); |
+ return false; |
+ } |
+ // Send the cookie so that UpdatePrintSettings can reuse PrintQuery when |
+ // possible. |
+ int cookie = print_pages_params_.get() ? |
+ print_pages_params_->params.document_cookie : 0; |
+ PrintMsg_PrintPages_Params settings; |
Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), |
- print_pages_params_->params.document_cookie, job_settings, &settings)); |
+ cookie, job_settings, &settings)); |
+ |
+ // Setup an empty default param so that document cookie can be propagated |
+ // in case of error. |
+ print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
kmadhusu
2011/09/20 00:42:41
Do you still need the code in line 1119?
arthurhsu
2011/09/20 18:41:19
Removed misleading comments. Basically the page p
|
+ |
+ if (PrintMsg_Print_Params_IsEmpty(settings.params)) { |
+ if (!is_preview) { |
+ WebKit::WebFrame* frame = print_preview_context_.frame(); |
+ if (!frame) |
+ GetPrintFrame(&frame); |
+ DCHECK(frame); |
+ 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; |
@@ -1546,6 +1569,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(); |