Skip to content

Commit 5fafd43

Browse files
codebyterepatchup[bot]
authored andcommitted
fix: silent print settings (electron#31489)
* fix: silent print settings * chore: update patches Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
1 parent 9071bb4 commit 5fafd43

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

patches/chromium/printing.patch

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ index 51ebcb4ae399018d3fd8566656596a7ef1f148af..5f2b807fc364131f4c3e6a1646ec522d
442442
// Tells the RenderFrame to switch the CSS to print media type, render every
443443
// requested page using the print preview document's frame/node, and then
444444
diff --git a/components/printing/renderer/print_render_frame_helper.cc b/components/printing/renderer/print_render_frame_helper.cc
445-
index 2760a694a946eb2e4dba1ee228dc5fc13a2fc98e..769976022186037d8e75e244bdb0450c5670b5c0 100644
445+
index 2760a694a946eb2e4dba1ee228dc5fc13a2fc98e..29760a87ba5103792518562722dd69d8d168e464 100644
446446
--- a/components/printing/renderer/print_render_frame_helper.cc
447447
+++ b/components/printing/renderer/print_render_frame_helper.cc
448448
@@ -38,6 +38,7 @@
@@ -547,18 +547,52 @@ index 2760a694a946eb2e4dba1ee228dc5fc13a2fc98e..769976022186037d8e75e244bdb0450c
547547
// Check if |this| is still valid.
548548
if (!self)
549549
return;
550-
@@ -2173,7 +2188,9 @@ void PrintRenderFrameHelper::IPCProcessed() {
550+
@@ -2173,36 +2188,51 @@ void PrintRenderFrameHelper::IPCProcessed() {
551551
}
552552
}
553553

554554
-bool PrintRenderFrameHelper::InitPrintSettings(bool fit_to_paper_size) {
555+
- mojom::PrintPagesParams settings;
556+
- settings.params = mojom::PrintParams::New();
557+
- GetPrintManagerHost()->GetDefaultPrintSettings(&settings.params);
555558
+bool PrintRenderFrameHelper::InitPrintSettings(
556559
+ bool fit_to_paper_size,
557560
+ const base::DictionaryValue& new_settings) {
558-
mojom::PrintPagesParams settings;
559-
settings.params = mojom::PrintParams::New();
560-
GetPrintManagerHost()->GetDefaultPrintSettings(&settings.params);
561-
@@ -2197,12 +2214,14 @@ bool PrintRenderFrameHelper::InitPrintSettings(bool fit_to_paper_size) {
561+
+ mojom::PrintPagesParamsPtr settings;
562+
+
563+
+ if (new_settings.DictEmpty()) {
564+
+ settings = mojom::PrintPagesParams::New();
565+
+ settings->params = mojom::PrintParams::New();
566+
+ GetPrintManagerHost()->GetDefaultPrintSettings(&settings->params);
567+
+ } else {
568+
+ bool canceled = false;
569+
+ int cookie =
570+
+ print_pages_params_ ? print_pages_params_->params->document_cookie : 0;
571+
+ GetPrintManagerHost()->UpdatePrintSettings(cookie, new_settings.Clone(), &settings, &canceled);
572+
+ if (canceled)
573+
+ return false;
574+
+ }
575+
576+
// Check if the printer returned any settings, if the settings is empty, we
577+
// can safely assume there are no printer drivers configured. So we safely
578+
// terminate.
579+
bool result = true;
580+
- if (!PrintMsg_Print_Params_IsValid(*settings.params))
581+
+ if (!PrintMsg_Print_Params_IsValid(*settings->params))
582+
result = false;
583+
584+
// Reset to default values.
585+
ignore_css_margins_ = false;
586+
- settings.pages.clear();
587+
+ settings->pages.clear();
588+
589+
- settings.params->print_scaling_option =
590+
+ settings->params->print_scaling_option =
591+
fit_to_paper_size ? mojom::PrintScalingOption::kFitToPrintableArea
592+
: mojom::PrintScalingOption::kSourceSize;
593+
594+
- SetPrintPagesParams(settings);
595+
+ SetPrintPagesParams(*settings);
562596
return result;
563597
}
564598

@@ -577,7 +611,7 @@ index 2760a694a946eb2e4dba1ee228dc5fc13a2fc98e..769976022186037d8e75e244bdb0450c
577611
notify_browser_of_print_failure_ = false;
578612
GetPrintManagerHost()->ShowInvalidPrinterSettingsError();
579613
return false;
580-
@@ -2573,18 +2592,7 @@ void PrintRenderFrameHelper::RequestPrintPreview(PrintPreviewRequestType type) {
614+
@@ -2573,18 +2603,7 @@ void PrintRenderFrameHelper::RequestPrintPreview(PrintPreviewRequestType type) {
581615
}
582616

583617
bool PrintRenderFrameHelper::CheckForCancel() {

0 commit comments

Comments
 (0)