From 5e113c87c502d1bfd6440b4a832f96f54568c496 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 18 May 2022 12:11:04 +0200 Subject: [PATCH 1/2] fix: DCHECK on webContents.print() --- patches/chromium/printing.patch | 56 +++++++------- .../browser/api/electron_api_web_contents.cc | 75 +++++++++---------- shell/browser/api/electron_api_web_contents.h | 2 +- 3 files changed, 66 insertions(+), 67 deletions(-) diff --git a/patches/chromium/printing.patch b/patches/chromium/printing.patch index ac87ae19ab3c7..2b9df64a7bf5e 100644 --- a/patches/chromium/printing.patch +++ b/patches/chromium/printing.patch @@ -113,7 +113,7 @@ index dd27bbf387718d6abda5080e7d2c609cd0eaff17..8837cf2aeaa2f87d51be8d00aa356c8a void PrintJobWorkerOop::UnregisterServiceManagerClient() { diff --git a/chrome/browser/printing/print_view_manager_base.cc b/chrome/browser/printing/print_view_manager_base.cc -index 3701853ada7f0ffe3cc8a798496f9f48541b4f47..a082dd9ee23b6d4918c194161386b973039d3ff6 100644 +index 3701853ada7f0ffe3cc8a798496f9f48541b4f47..973666a1315c8cbba0a2cefbe9195fdc9c122ae3 100644 --- a/chrome/browser/printing/print_view_manager_base.cc +++ b/chrome/browser/printing/print_view_manager_base.cc @@ -30,10 +30,10 @@ @@ -206,7 +206,7 @@ index 3701853ada7f0ffe3cc8a798496f9f48541b4f47..a082dd9ee23b6d4918c194161386b973 -bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh) { +bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh, + bool silent, -+ base::Value settings, ++ base::Value::Dict settings, + CompletionCallback callback) { // Remember the ID for `rfh`, to enable checking that the `RenderFrameHost` // is still valid after a possible inner message loop runs in @@ -402,12 +402,12 @@ index 3701853ada7f0ffe3cc8a798496f9f48541b4f47..a082dd9ee23b6d4918c194161386b973 void PrintViewManagerBase::CompletePrintNow(content::RenderFrameHost* rfh) { - GetPrintRenderFrame(rfh)->PrintRequestedPages(); -+ GetPrintRenderFrame(rfh)->PrintRequestedPages(true/*silent*/, base::Value{}/*job_settings*/); ++ GetPrintRenderFrame(rfh)->PrintRequestedPages(/*silent=*/true, /*job_settings=*/base::Value::Dict()); for (auto& observer : GetObservers()) observer.OnPrintNow(rfh); diff --git a/chrome/browser/printing/print_view_manager_base.h b/chrome/browser/printing/print_view_manager_base.h -index 746df417a23f7760818ba265d4a7d589dec8bf34..5566e7dc2929a2542c599fed91fb1eeeb866e7bb 100644 +index 746df417a23f7760818ba265d4a7d589dec8bf34..0027387d4717c59f2df3f279caf7aa0de6669400 100644 --- a/chrome/browser/printing/print_view_manager_base.h +++ b/chrome/browser/printing/print_view_manager_base.h @@ -41,6 +41,8 @@ namespace printing { @@ -426,7 +426,7 @@ index 746df417a23f7760818ba265d4a7d589dec8bf34..5566e7dc2929a2542c599fed91fb1eee - virtual bool PrintNow(content::RenderFrameHost* rfh); + virtual bool PrintNow(content::RenderFrameHost* rfh, + bool silent = true, -+ base::Value settings = {}, ++ base::Value::Dict settings = {}, + CompletionCallback callback = {}); #if BUILDFLAG(ENABLE_PRINT_PREVIEW) @@ -466,7 +466,7 @@ index 746df417a23f7760818ba265d4a7d589dec8bf34..5566e7dc2929a2542c599fed91fb1eee // This means we are _blocking_ until all the necessary pages have been // rendered or the print settings are being loaded. diff --git a/chrome/browser/ui/webui/print_preview/fake_print_render_frame.cc b/chrome/browser/ui/webui/print_preview/fake_print_render_frame.cc -index aa727261738698610fab5abd3618d0d0f0d29792..8f95dae637ce25a073872ecdf229f14cc6d0614c 100644 +index aa727261738698610fab5abd3618d0d0f0d29792..2793fbc33e66cf9d7e3fc5e10f0d01730f3b935d 100644 --- a/chrome/browser/ui/webui/print_preview/fake_print_render_frame.cc +++ b/chrome/browser/ui/webui/print_preview/fake_print_render_frame.cc @@ -21,7 +21,7 @@ FakePrintRenderFrame::FakePrintRenderFrame( @@ -474,12 +474,12 @@ index aa727261738698610fab5abd3618d0d0f0d29792..8f95dae637ce25a073872ecdf229f14c FakePrintRenderFrame::~FakePrintRenderFrame() = default; -void FakePrintRenderFrame::PrintRequestedPages() {} -+void FakePrintRenderFrame::PrintRequestedPages(bool /*silent*/, ::base::Value /*settings*/) {} ++void FakePrintRenderFrame::PrintRequestedPages(bool /*silent*/, ::base::Value::Dict /*settings*/) {} void FakePrintRenderFrame::PrintWithParams(mojom::PrintPagesParamsPtr params) { NOTREACHED(); diff --git a/chrome/browser/ui/webui/print_preview/fake_print_render_frame.h b/chrome/browser/ui/webui/print_preview/fake_print_render_frame.h -index 5f4d6e314b21351e3e5912e3a43ef87774343085..2a93fe0139025d1a40b3f8e81378ee4213ac27c1 100644 +index 5f4d6e314b21351e3e5912e3a43ef87774343085..8627c8305686654dca7cd9c26433592e934d4eb0 100644 --- a/chrome/browser/ui/webui/print_preview/fake_print_render_frame.h +++ b/chrome/browser/ui/webui/print_preview/fake_print_render_frame.h @@ -25,7 +25,7 @@ class FakePrintRenderFrame : public mojom::PrintRenderFrame { @@ -487,7 +487,7 @@ index 5f4d6e314b21351e3e5912e3a43ef87774343085..2a93fe0139025d1a40b3f8e81378ee42 private: // printing::mojom::PrintRenderFrame: - void PrintRequestedPages() override; -+ void PrintRequestedPages(bool silent, ::base::Value settings) override; ++ void PrintRequestedPages(bool silent, ::base::Value::Dict settings) override; void PrintWithParams(mojom::PrintPagesParamsPtr params) override; void PrintForSystemDialog() override; void SetPrintPreviewUI( @@ -515,7 +515,7 @@ index 82591f8c2abbc1a180ef62f7264a68ca279e9b9c..ad27a15ba3028af1046482192dec789d void PdfPrintManager::ShowInvalidPrinterSettingsError() { diff --git a/components/printing/common/print.mojom b/components/printing/common/print.mojom -index 8e5c441b3d0a2d35fc5c6f9d43b4a4ca167e09ca..fa53eb1c9dd4e7a6b321bdd4cda2164b95244323 100644 +index 8e5c441b3d0a2d35fc5c6f9d43b4a4ca167e09ca..2cfcd810c9507c434e673064b63e8fbc95172537 100644 --- a/components/printing/common/print.mojom +++ b/components/printing/common/print.mojom @@ -280,7 +280,7 @@ enum PrintFailureReason { @@ -523,7 +523,7 @@ index 8e5c441b3d0a2d35fc5c6f9d43b4a4ca167e09ca..fa53eb1c9dd4e7a6b321bdd4cda2164b // Tells the RenderFrame to switch the CSS to print media type, render every // requested page, and then switch back the CSS to display media type. - PrintRequestedPages(); -+ PrintRequestedPages(bool silent, mojo_base.mojom.DeprecatedDictionaryValue settings); ++ PrintRequestedPages(bool silent, mojo_base.mojom.DictionaryValue settings); // Requests the frame to be printed with specified parameters. This is used // to programmatically produce PDF by request from the browser (e.g. over @@ -537,7 +537,7 @@ index 8e5c441b3d0a2d35fc5c6f9d43b4a4ca167e09ca..fa53eb1c9dd4e7a6b321bdd4cda2164b // Tells the browser that there are invalid printer settings. ShowInvalidPrinterSettingsError(); diff --git a/components/printing/renderer/print_render_frame_helper.cc b/components/printing/renderer/print_render_frame_helper.cc -index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9567214a1 100644 +index db8913ae41d46d14fd15c6127e126e4b129dc4b8..ddbc3b0d5a00af9de84e1b0aadc44adb6ff84495 100644 --- a/components/printing/renderer/print_render_frame_helper.cc +++ b/components/printing/renderer/print_render_frame_helper.cc @@ -42,6 +42,7 @@ @@ -554,7 +554,7 @@ index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9 - Print(web_frame, blink::WebNode(), PrintRequestType::kScripted); + Print(web_frame, blink::WebNode(), PrintRequestType::kScripted, -+ false /* silent */, base::DictionaryValue() /* new_settings */); ++ false /* silent */, base::Value::Dict() /* new_settings */); if (!weak_this) return; @@ -563,7 +563,7 @@ index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9 } -void PrintRenderFrameHelper::PrintRequestedPages() { -+void PrintRenderFrameHelper::PrintRequestedPages(bool silent, base::Value settings) { ++void PrintRenderFrameHelper::PrintRequestedPages(bool silent, base::Value::Dict settings) { ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr()); if (ipc_nesting_level_ > kAllowedIpcDepthForPrint) return; @@ -582,7 +582,7 @@ index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9 Print(frame, print_preview_context_.source_node(), - PrintRequestType::kRegular); + PrintRequestType::kRegular, false, -+ base::DictionaryValue()); ++ base::Value::Dict()); if (!render_frame_gone_) print_preview_context_.DispatchAfterPrintEvent(); // WARNING: |this| may be gone at this point. Do not do any more work here and @@ -601,7 +601,7 @@ index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9 Print(duplicate_node.GetDocument().GetFrame(), duplicate_node, - PrintRequestType::kRegular); + PrintRequestType::kRegular, false /* silent */, -+ base::DictionaryValue() /* new_settings */); ++ base::Value::Dict() /* new_settings */); // Check if |this| is still valid. if (!weak_this) return; @@ -612,7 +612,7 @@ index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9 - PrintRequestType print_request_type) { + PrintRequestType print_request_type, + bool silent, -+ base::Value settings) { ++ base::Value::Dict settings) { // If still not finished with earlier print request simply ignore. if (prep_frame_view_) return; @@ -621,7 +621,7 @@ index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9 uint32_t expected_page_count = 0; - if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { -+ if (!CalculateNumberOfPages(frame, node, &expected_page_count, base::Value::AsDictionaryValue(settings))) { ++ if (!CalculateNumberOfPages(frame, node, &expected_page_count, std::move(settings))) { DidFinishPrinting(FAIL_PRINT_INIT); return; // Failed to init print page settings. } @@ -652,10 +652,10 @@ index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9 - GetPrintManagerHost()->GetDefaultPrintSettings(&settings.params); +bool PrintRenderFrameHelper::InitPrintSettings( + bool fit_to_paper_size, -+ const base::DictionaryValue& new_settings) { ++ base::Value::Dict new_settings) { + mojom::PrintPagesParamsPtr settings; + -+ if (new_settings.DictEmpty()) { ++ if (new_settings.empty()) { + settings = mojom::PrintPagesParams::New(); + settings->params = mojom::PrintParams::New(); + GetPrintManagerHost()->GetDefaultPrintSettings(&settings->params); @@ -664,7 +664,7 @@ index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9 + int cookie = + print_pages_params_ ? print_pages_params_->params->document_cookie : 0; + GetPrintManagerHost()->UpdatePrintSettings( -+ cookie, new_settings.GetDict().Clone(), &settings, &canceled); ++ cookie, std::move(new_settings), &settings, &canceled); + if (canceled) + return false; + } @@ -699,11 +699,11 @@ index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9 + blink::WebLocalFrame* frame, + const blink::WebNode& node, + uint32_t* number_of_pages, -+ const base::DictionaryValue& settings) { ++ base::Value::Dict settings) { DCHECK(frame); bool fit_to_paper_size = !IsPrintingPdfFrame(frame, node); - if (!InitPrintSettings(fit_to_paper_size)) { -+ if (!InitPrintSettings(fit_to_paper_size, settings)) { ++ if (!InitPrintSettings(fit_to_paper_size, std::move(settings))) { notify_browser_of_print_failure_ = false; GetPrintManagerHost()->ShowInvalidPrinterSettingsError(); return false; @@ -737,7 +737,7 @@ index db8913ae41d46d14fd15c6127e126e4b129dc4b8..64ee08e9091e4d67ff55097bc22177d9 bool PrintRenderFrameHelper::PreviewPageRendered( diff --git a/components/printing/renderer/print_render_frame_helper.h b/components/printing/renderer/print_render_frame_helper.h -index 220b28a7e63625fe8b76290f0d2f40dd32cae255..72801431a5d19f31c1a7db785b0cbaee8e65cca3 100644 +index 220b28a7e63625fe8b76290f0d2f40dd32cae255..cff9e35fab9df680c3c39467c50ddb033c2e6cba 100644 --- a/components/printing/renderer/print_render_frame_helper.h +++ b/components/printing/renderer/print_render_frame_helper.h @@ -255,7 +255,7 @@ class PrintRenderFrameHelper @@ -745,7 +745,7 @@ index 220b28a7e63625fe8b76290f0d2f40dd32cae255..72801431a5d19f31c1a7db785b0cbaee // printing::mojom::PrintRenderFrame: - void PrintRequestedPages() override; -+ void PrintRequestedPages(bool silent, base::Value settings) override; ++ void PrintRequestedPages(bool silent, base::Value::Dict settings) override; void PrintWithParams(mojom::PrintPagesParamsPtr params) override; #if BUILDFLAG(ENABLE_PRINT_PREVIEW) void PrintForSystemDialog() override; @@ -756,7 +756,7 @@ index 220b28a7e63625fe8b76290f0d2f40dd32cae255..72801431a5d19f31c1a7db785b0cbaee - PrintRequestType print_request_type); + PrintRequestType print_request_type, + bool silent, -+ base::Value settings); ++ base::Value::Dict settings); // Notification when printing is done - signal tear-down/free resources. void DidFinishPrinting(PrintingResult result); @@ -766,14 +766,14 @@ index 220b28a7e63625fe8b76290f0d2f40dd32cae255..72801431a5d19f31c1a7db785b0cbaee // Used only for native printing workflow. - bool InitPrintSettings(bool fit_to_paper_size); + bool InitPrintSettings(bool fit_to_paper_size, -+ const base::DictionaryValue& settings); ++ base::Value::Dict new_settings); // Calculate number of pages in source document. bool CalculateNumberOfPages(blink::WebLocalFrame* frame, const blink::WebNode& node, - uint32_t* number_of_pages); + uint32_t* number_of_pages, -+ const base::DictionaryValue& settings); ++ base::Value::Dict settings); #if BUILDFLAG(ENABLE_PRINT_PREVIEW) // Set options for print preset from source PDF document. diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 501e3cac4005d..96921b8d7c40c 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -2586,7 +2586,7 @@ bool WebContents::IsCurrentlyAudible() { #if BUILDFLAG(ENABLE_PRINTING) void WebContents::OnGetDefaultPrinter( - base::Value print_settings, + base::Value::Dict print_settings, printing::CompletionCallback print_callback, std::u16string device_name, bool silent, @@ -2616,7 +2616,7 @@ void WebContents::OnGetDefaultPrinter( return; } - print_settings.SetStringKey(printing::kSettingDeviceName, printer_name); + print_settings.Set(printing::kSettingDeviceName, printer_name); auto* print_view_manager = PrintViewManagerElectron::FromWebContents(web_contents()); @@ -2635,7 +2635,7 @@ void WebContents::OnGetDefaultPrinter( void WebContents::Print(gin::Arguments* args) { gin_helper::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate()); - base::Value settings(base::Value::Type::DICTIONARY); + base::Value::Dict settings; if (args->Length() >= 1 && !args->GetNext(&options)) { gin_helper::ErrorThrower(args->isolate()) @@ -2656,7 +2656,7 @@ void WebContents::Print(gin::Arguments* args) { bool print_background = false; options.Get("printBackground", &print_background); - settings.SetBoolKey(printing::kSettingShouldPrintBackgrounds, + settings.Set(printing::kSettingShouldPrintBackgrounds, print_background); // Set custom margin settings @@ -2666,28 +2666,27 @@ void WebContents::Print(gin::Arguments* args) { printing::mojom::MarginType margin_type = printing::mojom::MarginType::kDefaultMargins; margins.Get("marginType", &margin_type); - settings.SetIntKey(printing::kSettingMarginsType, + settings.Set(printing::kSettingMarginsType, static_cast(margin_type)); if (margin_type == printing::mojom::MarginType::kCustomMargins) { - base::Value custom_margins(base::Value::Type::DICTIONARY); + base::Value::Dict custom_margins; int top = 0; margins.Get("top", &top); - custom_margins.SetIntKey(printing::kSettingMarginTop, top); + custom_margins.Set(printing::kSettingMarginTop, top); int bottom = 0; margins.Get("bottom", &bottom); - custom_margins.SetIntKey(printing::kSettingMarginBottom, bottom); + custom_margins.Set(printing::kSettingMarginBottom, bottom); int left = 0; margins.Get("left", &left); - custom_margins.SetIntKey(printing::kSettingMarginLeft, left); + custom_margins.Set(printing::kSettingMarginLeft, left); int right = 0; margins.Get("right", &right); - custom_margins.SetIntKey(printing::kSettingMarginRight, right); - settings.SetPath(printing::kSettingMarginsCustom, - std::move(custom_margins)); + custom_margins.Set(printing::kSettingMarginRight, right); + settings.Set(printing::kSettingMarginsCustom, std::move(custom_margins)); } } else { - settings.SetIntKey( + settings.Set( printing::kSettingMarginsType, static_cast(printing::mojom::MarginType::kDefaultMargins)); } @@ -2697,12 +2696,12 @@ void WebContents::Print(gin::Arguments* args) { options.Get("color", &print_color); auto const color_model = print_color ? printing::mojom::ColorModel::kColor : printing::mojom::ColorModel::kGray; - settings.SetIntKey(printing::kSettingColor, static_cast(color_model)); + settings.Set(printing::kSettingColor, static_cast(color_model)); // Is the orientation landscape or portrait. bool landscape = false; options.Get("landscape", &landscape); - settings.SetBoolKey(printing::kSettingLandscape, landscape); + settings.Set(printing::kSettingLandscape, landscape); // We set the default to the system's default printer and only update // if at the Chromium level if the user overrides. @@ -2717,21 +2716,21 @@ void WebContents::Print(gin::Arguments* args) { int scale_factor = 100; options.Get("scaleFactor", &scale_factor); - settings.SetIntKey(printing::kSettingScaleFactor, scale_factor); + settings.Set(printing::kSettingScaleFactor, scale_factor); int pages_per_sheet = 1; options.Get("pagesPerSheet", &pages_per_sheet); - settings.SetIntKey(printing::kSettingPagesPerSheet, pages_per_sheet); + settings.Set(printing::kSettingPagesPerSheet, pages_per_sheet); // True if the user wants to print with collate. bool collate = true; options.Get("collate", &collate); - settings.SetBoolKey(printing::kSettingCollate, collate); + settings.Set(printing::kSettingCollate, collate); // The number of individual copies to print int copies = 1; options.Get("copies", &copies); - settings.SetIntKey(printing::kSettingCopies, copies); + settings.Set(printing::kSettingCopies, copies); // Strings to be printed as headers and footers if requested by the user. std::string header; @@ -2740,53 +2739,53 @@ void WebContents::Print(gin::Arguments* args) { options.Get("footer", &footer); if (!(header.empty() && footer.empty())) { - settings.SetBoolKey(printing::kSettingHeaderFooterEnabled, true); + settings.Set(printing::kSettingHeaderFooterEnabled, true); - settings.SetStringKey(printing::kSettingHeaderFooterTitle, header); - settings.SetStringKey(printing::kSettingHeaderFooterURL, footer); + settings.Set(printing::kSettingHeaderFooterTitle, header); + settings.Set(printing::kSettingHeaderFooterURL, footer); } else { - settings.SetBoolKey(printing::kSettingHeaderFooterEnabled, false); + settings.Set(printing::kSettingHeaderFooterEnabled, false); } // We don't want to allow the user to enable these settings // but we need to set them or a CHECK is hit. - settings.SetIntKey(printing::kSettingPrinterType, + settings.Set(printing::kSettingPrinterType, static_cast(printing::mojom::PrinterType::kLocal)); - settings.SetBoolKey(printing::kSettingShouldPrintSelectionOnly, false); - settings.SetBoolKey(printing::kSettingRasterizePdf, false); + settings.Set(printing::kSettingShouldPrintSelectionOnly, false); + settings.Set(printing::kSettingRasterizePdf, false); // Set custom page ranges to print std::vector page_ranges; if (options.Get("pageRanges", &page_ranges)) { - base::Value page_range_list(base::Value::Type::LIST); + base::Value::List page_range_list; for (auto& range : page_ranges) { int from, to; if (range.Get("from", &from) && range.Get("to", &to)) { - base::Value range(base::Value::Type::DICTIONARY); + base::Value::Dict range; // Chromium uses 1-based page ranges, so increment each by 1. - range.SetIntKey(printing::kSettingPageRangeFrom, from + 1); - range.SetIntKey(printing::kSettingPageRangeTo, to + 1); + range.Set(printing::kSettingPageRangeFrom, from + 1); + range.Set(printing::kSettingPageRangeTo, to + 1); page_range_list.Append(std::move(range)); } else { continue; } } - if (!page_range_list.GetListDeprecated().empty()) - settings.SetPath(printing::kSettingPageRange, std::move(page_range_list)); + if (!page_range_list.empty()) + settings.Set(printing::kSettingPageRange, std::move(page_range_list)); } // Duplex type user wants to use. printing::mojom::DuplexMode duplex_mode = printing::mojom::DuplexMode::kSimplex; options.Get("duplexMode", &duplex_mode); - settings.SetIntKey(printing::kSettingDuplexMode, + settings.Set(printing::kSettingDuplexMode, static_cast(duplex_mode)); // We've already done necessary parameter sanitization at the // JS level, so we can simply pass this through. base::Value media_size(base::Value::Type::DICTIONARY); if (options.Get("mediaSize", &media_size)) - settings.SetKey(printing::kSettingMediaSize, std::move(media_size)); + settings.Set(printing::kSettingMediaSize, std::move(media_size)); // Set custom dots per inch (dpi) gin_helper::Dictionary dpi_settings; @@ -2794,13 +2793,13 @@ void WebContents::Print(gin::Arguments* args) { if (options.Get("dpi", &dpi_settings)) { int horizontal = 72; dpi_settings.Get("horizontal", &horizontal); - settings.SetIntKey(printing::kSettingDpiHorizontal, horizontal); + settings.Set(printing::kSettingDpiHorizontal, horizontal); int vertical = 72; dpi_settings.Get("vertical", &vertical); - settings.SetIntKey(printing::kSettingDpiVertical, vertical); + settings.Set(printing::kSettingDpiVertical, vertical); } else { - settings.SetIntKey(printing::kSettingDpiHorizontal, dpi); - settings.SetIntKey(printing::kSettingDpiVertical, dpi); + settings.Set(printing::kSettingDpiHorizontal, dpi); + settings.Set(printing::kSettingDpiVertical, dpi); } print_task_runner_->PostTaskAndReplyWithResult( diff --git a/shell/browser/api/electron_api_web_contents.h b/shell/browser/api/electron_api_web_contents.h index 96940a3f32ea7..c4311007d34fe 100644 --- a/shell/browser/api/electron_api_web_contents.h +++ b/shell/browser/api/electron_api_web_contents.h @@ -223,7 +223,7 @@ class WebContents : public ExclusiveAccessContext, void HandleNewRenderFrame(content::RenderFrameHost* render_frame_host); #if BUILDFLAG(ENABLE_PRINTING) - void OnGetDefaultPrinter(base::Value print_settings, + void OnGetDefaultPrinter(base::Value::Dict print_settings, printing::CompletionCallback print_callback, std::u16string device_name, bool silent, From 07635fc4c7687e9af6091e22745e9ee80d4365c7 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 18 May 2022 14:26:12 +0200 Subject: [PATCH 2/2] chore: fix lint --- shell/browser/api/electron_api_web_contents.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 96921b8d7c40c..60a8a5846d60a 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -2656,8 +2656,7 @@ void WebContents::Print(gin::Arguments* args) { bool print_background = false; options.Get("printBackground", &print_background); - settings.Set(printing::kSettingShouldPrintBackgrounds, - print_background); + settings.Set(printing::kSettingShouldPrintBackgrounds, print_background); // Set custom margin settings gin_helper::Dictionary margins = @@ -2666,8 +2665,7 @@ void WebContents::Print(gin::Arguments* args) { printing::mojom::MarginType margin_type = printing::mojom::MarginType::kDefaultMargins; margins.Get("marginType", &margin_type); - settings.Set(printing::kSettingMarginsType, - static_cast(margin_type)); + settings.Set(printing::kSettingMarginsType, static_cast(margin_type)); if (margin_type == printing::mojom::MarginType::kCustomMargins) { base::Value::Dict custom_margins; @@ -2750,7 +2748,7 @@ void WebContents::Print(gin::Arguments* args) { // We don't want to allow the user to enable these settings // but we need to set them or a CHECK is hit. settings.Set(printing::kSettingPrinterType, - static_cast(printing::mojom::PrinterType::kLocal)); + static_cast(printing::mojom::PrinterType::kLocal)); settings.Set(printing::kSettingShouldPrintSelectionOnly, false); settings.Set(printing::kSettingRasterizePdf, false); @@ -2778,8 +2776,7 @@ void WebContents::Print(gin::Arguments* args) { printing::mojom::DuplexMode duplex_mode = printing::mojom::DuplexMode::kSimplex; options.Get("duplexMode", &duplex_mode); - settings.Set(printing::kSettingDuplexMode, - static_cast(duplex_mode)); + settings.Set(printing::kSettingDuplexMode, static_cast(duplex_mode)); // We've already done necessary parameter sanitization at the // JS level, so we can simply pass this through.