Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: silent print settings #31615

Merged
merged 1 commit into from Oct 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 41 additions & 7 deletions patches/chromium/printing.patch
Expand Up @@ -442,7 +442,7 @@ index 51ebcb4ae399018d3fd8566656596a7ef1f148af..5f2b807fc364131f4c3e6a1646ec522d
// Tells the RenderFrame to switch the CSS to print media type, render every
// requested page using the print preview document's frame/node, and then
diff --git a/components/printing/renderer/print_render_frame_helper.cc b/components/printing/renderer/print_render_frame_helper.cc
index c16d8984805619f1f1382e1e5b932771fcc0f44b..7fe61be3b6139c73768d80bf9e8b6c8d4e38bb3b 100644
index c16d8984805619f1f1382e1e5b932771fcc0f44b..01c18d78221bbb7fa26638d778d4a7d33264d129 100644
--- a/components/printing/renderer/print_render_frame_helper.cc
+++ b/components/printing/renderer/print_render_frame_helper.cc
@@ -38,6 +38,7 @@
Expand Down Expand Up @@ -547,18 +547,52 @@ index c16d8984805619f1f1382e1e5b932771fcc0f44b..7fe61be3b6139c73768d80bf9e8b6c8d
// Check if |this| is still valid.
if (!self)
return;
@@ -2173,7 +2188,9 @@ void PrintRenderFrameHelper::IPCProcessed() {
@@ -2173,36 +2188,51 @@ void PrintRenderFrameHelper::IPCProcessed() {
}
}

-bool PrintRenderFrameHelper::InitPrintSettings(bool fit_to_paper_size) {
- mojom::PrintPagesParams settings;
- settings.params = mojom::PrintParams::New();
- GetPrintManagerHost()->GetDefaultPrintSettings(&settings.params);
+bool PrintRenderFrameHelper::InitPrintSettings(
+ bool fit_to_paper_size,
+ const base::DictionaryValue& new_settings) {
mojom::PrintPagesParams settings;
settings.params = mojom::PrintParams::New();
GetPrintManagerHost()->GetDefaultPrintSettings(&settings.params);
@@ -2197,12 +2214,14 @@ bool PrintRenderFrameHelper::InitPrintSettings(bool fit_to_paper_size) {
+ mojom::PrintPagesParamsPtr settings;
+
+ if (new_settings.DictEmpty()) {
+ settings = mojom::PrintPagesParams::New();
+ settings->params = mojom::PrintParams::New();
+ GetPrintManagerHost()->GetDefaultPrintSettings(&settings->params);
+ } else {
+ bool canceled = false;
+ int cookie =
+ print_pages_params_ ? print_pages_params_->params->document_cookie : 0;
+ GetPrintManagerHost()->UpdatePrintSettings(cookie, new_settings.Clone(), &settings, &canceled);
+ if (canceled)
+ return false;
+ }

// Check if the printer returned any settings, if the settings is empty, we
// can safely assume there are no printer drivers configured. So we safely
// terminate.
bool result = true;
- if (!PrintMsg_Print_Params_IsValid(*settings.params))
+ if (!PrintMsg_Print_Params_IsValid(*settings->params))
result = false;

// Reset to default values.
ignore_css_margins_ = false;
- settings.pages.clear();
+ settings->pages.clear();

- settings.params->print_scaling_option =
+ settings->params->print_scaling_option =
fit_to_paper_size ? mojom::PrintScalingOption::kFitToPrintableArea
: mojom::PrintScalingOption::kSourceSize;

- SetPrintPagesParams(settings);
+ SetPrintPagesParams(*settings);
return result;
}

Expand All @@ -577,7 +611,7 @@ index c16d8984805619f1f1382e1e5b932771fcc0f44b..7fe61be3b6139c73768d80bf9e8b6c8d
notify_browser_of_print_failure_ = false;
GetPrintManagerHost()->ShowInvalidPrinterSettingsError();
return false;
@@ -2573,18 +2592,7 @@ void PrintRenderFrameHelper::RequestPrintPreview(PrintPreviewRequestType type) {
@@ -2573,18 +2603,7 @@ void PrintRenderFrameHelper::RequestPrintPreview(PrintPreviewRequestType type) {
}

bool PrintRenderFrameHelper::CheckForCancel() {
Expand Down