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

Unified Diff: chrome/renderer/printing/print_web_view_helper.cc

Issue 480303002: Use document from preview for System Dialog printing on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tue 08/19/2014 11:17:57.84 Created 6 years, 4 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/printing/print_web_view_helper.cc
diff --git a/chrome/renderer/printing/print_web_view_helper.cc b/chrome/renderer/printing/print_web_view_helper.cc
index 5e1328f2ab0bb6fc846b9c6fc9333530c264119b..1b12b03d37754080b4b34139ccb8997f3a0744e9 100644
--- a/chrome/renderer/printing/print_web_view_helper.cc
+++ b/chrome/renderer/printing/print_web_view_helper.cc
@@ -1,5 +1,5 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
Noam Samuel 2014/08/20 00:04:17 ??? Pretty sure this line doesn't need to be moved
Vitaly Buka (NO REVIEWS) 2014/08/20 02:42:55 Done.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// found in the LICENSE file.
#include "chrome/renderer/printing/print_web_view_helper.h"
@@ -91,7 +91,8 @@ bool PrintMsg_Print_Params_IsValid(const PrintMsg_Print_Params& params) {
return !params.content_size.IsEmpty() && !params.page_size.IsEmpty() &&
!params.printable_area.IsEmpty() && params.document_cookie &&
params.desired_dpi && params.max_shrink && params.min_shrink &&
- params.dpi && (params.margin_top >= 0) && (params.margin_left >= 0);
+ params.dpi && (params.margin_top >= 0) && (params.margin_left >= 0) &&
+ params.dpi > kMinDpi && params.document_cookie != 0;
}
PrintMsg_Print_Params GetCssPrintParams(
@@ -1020,8 +1021,8 @@ void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) {
if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) {
Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings(
routing_id(),
- print_pages_params_ ?
- print_pages_params_->params.document_cookie : 0));
+ print_pages_params() ? print_pages_params()->params.document_cookie
+ : 0));
notify_browser_of_print_failure_ = false; // Already sent.
}
DidFinishPrinting(FAIL_PREVIEW);
@@ -1030,7 +1031,7 @@ void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) {
// Set the options from document if we are previewing a pdf and send a
// message to browser.
- if (print_pages_params_->params.is_first_request &&
+ if (print_pages_params()->params.is_first_request &&
!print_preview_context_.IsModifiable()) {
PrintHostMsg_SetOptionsFromDocument_Params params;
SetOptionsFromDocument(params);
@@ -1055,7 +1056,7 @@ void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) {
void PrintWebViewHelper::PrepareFrameForPreviewDocument() {
reset_prep_frame_view_ = false;
- if (!print_pages_params_ || CheckForCancel()) {
+ if (!print_pages_params() || CheckForCancel()) {
DidFinishPrinting(FAIL_PREVIEW);
return;
}
@@ -1067,7 +1068,7 @@ void PrintWebViewHelper::PrepareFrameForPreviewDocument() {
return;
}
- const PrintMsg_Print_Params& print_params = print_pages_params_->params;
+ const PrintMsg_Print_Params& print_params = print_pages_params()->params;
prep_frame_view_.reset(
new PrepareFrameAndViewForPrint(print_params,
print_preview_context_.source_frame(),
@@ -1088,14 +1089,14 @@ void PrintWebViewHelper::OnFramePreparedForPreviewDocument() {
}
bool PrintWebViewHelper::CreatePreviewDocument() {
- if (!print_pages_params_ || CheckForCancel())
+ if (!print_pages_params() || CheckForCancel())
return false;
UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent",
PREVIEW_EVENT_CREATE_DOCUMENT, PREVIEW_EVENT_MAX);
- const PrintMsg_Print_Params& print_params = print_pages_params_->params;
- const std::vector<int>& pages = print_pages_params_->pages;
+ const PrintMsg_Print_Params& print_params = print_pages_params()->params;
+ const std::vector<int>& pages = print_pages_params()->pages;
if (!print_preview_context_.CreatePreviewDocument(prep_frame_view_.release(),
pages)) {
@@ -1175,12 +1176,12 @@ bool PrintWebViewHelper::FinalizePrintReadyDocument() {
PrintHostMsg_DidPreviewDocument_Params preview_params;
preview_params.data_size = buf_size;
- preview_params.document_cookie = print_pages_params_->params.document_cookie;
+ preview_params.document_cookie = print_pages_params()->params.document_cookie;
preview_params.expected_pages_count =
print_preview_context_.total_page_count();
preview_params.modifiable = print_preview_context_.IsModifiable();
preview_params.preview_request_id =
- print_pages_params_->params.preview_request_id;
+ print_pages_params()->params.preview_request_id;
// Ask the browser to create the shared memory for us.
if (!CopyMetafileDataToSharedMem(metafile,
@@ -1297,16 +1298,17 @@ void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) {
break;
case FAIL_PRINT:
- if (notify_browser_of_print_failure_ && print_pages_params_) {
- int cookie = print_pages_params_->params.document_cookie;
+ if (notify_browser_of_print_failure_ && print_pages_params()) {
+ int cookie = print_pages_params()->params.document_cookie;
Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie));
}
break;
case FAIL_PREVIEW:
DCHECK(is_preview_enabled_);
- int cookie = print_pages_params_ ?
- print_pages_params_->params.document_cookie : 0;
+ int cookie = print_pages_params()
+ ? print_pages_params()->params.document_cookie
+ : 0;
if (notify_browser_of_print_failure_) {
LOG(ERROR) << "CreatePreviewDocument failed";
Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie));
@@ -1337,7 +1339,7 @@ void PrintWebViewHelper::PrintPages() {
return DidFinishPrinting(FAIL_PRINT);
}
- const PrintMsg_PrintPages_Params& params = *print_pages_params_;
+ const PrintMsg_PrintPages_Params& params = *print_pages_params();
const PrintMsg_Print_Params& print_params = params.params;
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
@@ -1376,7 +1378,7 @@ void PrintWebViewHelper::FinishFramePrinting() {
bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
int page_count,
const gfx::Size& canvas_size) {
- const PrintMsg_PrintPages_Params& params = *print_pages_params_;
+ const PrintMsg_PrintPages_Params& params = *print_pages_params();
const PrintMsg_Print_Params& print_params = params.params;
PrintMsg_PrintPage_Params page_params;
@@ -1426,13 +1428,6 @@ bool PrintWebViewHelper::InitPrintSettings(bool fit_to_paper_size) {
if (!PrintMsg_Print_Params_IsValid(settings.params))
result = false;
- if (result &&
- (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) {
- // Invalid print page settings.
- NOTREACHED();
- result = false;
- }
-
// Reset to default values.
ignore_css_margins_ = false;
settings.pages.clear();
@@ -1444,7 +1439,7 @@ bool PrintWebViewHelper::InitPrintSettings(bool fit_to_paper_size) {
blink::WebPrintScalingOptionFitToPrintableArea;
}
- print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
+ SetPrintPagesParams(settings);
return result;
}
@@ -1459,12 +1454,10 @@ bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebLocalFrame* frame,
return false;
}
- const PrintMsg_Print_Params& params = print_pages_params_->params;
+ const PrintMsg_Print_Params& params = print_pages_params()->params;
PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_);
prepare.StartPrinting();
- Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
- params.document_cookie));
*number_of_pages = prepare.GetExpectedPageCount();
return true;
}
@@ -1509,24 +1502,14 @@ bool PrintWebViewHelper::UpdatePrintSettings(
// Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when
// possible.
- int cookie = print_pages_params_ ?
- print_pages_params_->params.document_cookie : 0;
+ int cookie =
+ print_pages_params() ? print_pages_params()->params.document_cookie : 0;
PrintMsg_PrintPages_Params settings;
- Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings,
- &settings));
- print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
-
- if (!PrintMsg_Print_Params_IsValid(settings.params)) {
- if (!print_for_preview_)
- print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
- else
- Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id()));
-
- return false;
- }
-
- if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) {
- print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS);
+ bool canceled = false;
+ Send(new PrintHostMsg_UpdatePrintSettings(
+ routing_id(), cookie, *job_settings, &settings, &canceled));
+ if (canceled) {
+ notify_browser_of_print_failure_ = false;
return false;
}
@@ -1546,7 +1529,9 @@ bool PrintWebViewHelper::UpdatePrintSettings(
print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING);
return false;
}
+ }
+ if (!print_for_preview_) {
Noam Samuel 2014/08/20 00:04:17 Why separate two of the same if?
Vitaly Buka (NO REVIEWS) 2014/08/20 02:42:55 Done.
settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings);
UpdateFrameMarginsCssInfo(*job_settings);
settings.params.print_scaling_option = GetPrintScalingOption(
@@ -1564,9 +1549,19 @@ bool PrintWebViewHelper::UpdatePrintSettings(
}
}
- print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
- Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
- settings.params.document_cookie));
+ SetPrintPagesParams(settings);
+
+ if (CheckForCancel())
+ return false;
+
+ if (!PrintMsg_Print_Params_IsValid(settings.params)) {
+ if (!print_for_preview_)
+ print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
+ else
+ Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id()));
+
+ return false;
+ }
return true;
}
@@ -1577,7 +1572,7 @@ bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame,
PrintHostMsg_ScriptedPrint_Params params;
PrintMsg_PrintPages_Params print_settings;
- params.cookie = print_pages_params_->params.document_cookie;
+ params.cookie = print_pages_params()->params.document_cookie;
params.has_selection = frame->hasSelection();
params.expected_pages_count = expected_pages_count;
MarginType margin_type = DEFAULT_MARGINS;
@@ -1590,16 +1585,15 @@ bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame,
// PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the
// value before and restore it afterwards.
blink::WebPrintScalingOption scaling_option =
- print_pages_params_->params.print_scaling_option;
+ print_pages_params()->params.print_scaling_option;
print_pages_params_.reset();
IPC::SyncMessage* msg =
new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings);
msg->EnableMessagePumping();
Send(msg);
- print_pages_params_.reset(new PrintMsg_PrintPages_Params(print_settings));
-
- print_pages_params_->params.print_scaling_option = scaling_option;
+ print_settings.params.print_scaling_option = scaling_option;
+ SetPrintPagesParams(print_settings);
return (print_settings.params.dpi && print_settings.params.document_cookie);
}
@@ -1607,12 +1601,12 @@ bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame,
const blink::WebNode& node) {
if (!frame || prep_frame_view_)
return false;
- const PrintMsg_PrintPages_Params& params = *print_pages_params_;
+ const PrintMsg_PrintPages_Params& params = *print_pages_params();
const PrintMsg_Print_Params& print_params = params.params;
prep_frame_view_.reset(new PrepareFrameAndViewForPrint(
print_params, frame, node, ignore_css_margins_));
- DCHECK(!print_pages_params_->params.selection_only ||
- print_pages_params_->pages.empty());
+ DCHECK(!print_pages_params()->params.selection_only ||
+ print_pages_params()->pages.empty());
prep_frame_view_->CopySelectionIfNeeded(
render_view()->GetWebkitPreferences(),
base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages,
@@ -1771,7 +1765,7 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) {
}
bool PrintWebViewHelper::CheckForCancel() {
- const PrintMsg_Print_Params& print_params = print_pages_params_->params;
+ const PrintMsg_Print_Params& print_params = print_pages_params()->params;
bool cancel = false;
Send(new PrintHostMsg_CheckForCancel(routing_id(),
print_params.preview_ui_id,
@@ -1815,7 +1809,7 @@ bool PrintWebViewHelper::PreviewPageRendered(int page_number,
preview_page_params.data_size = buf_size;
preview_page_params.page_number = page_number;
preview_page_params.preview_request_id =
- print_pages_params_->params.preview_request_id;
+ print_pages_params()->params.preview_request_id;
Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params));
return true;
@@ -2063,4 +2057,11 @@ void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
error_ = PREVIEW_ERROR_NONE;
}
+void PrintWebViewHelper::SetPrintPagesParams(
+ const PrintMsg_PrintPages_Params& settings) {
+ print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
+ Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
+ settings.params.document_cookie));
+}
+
} // namespace printing

Powered by Google App Engine
This is Rietveld 408576698