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