From 24e21467b91b4facb554cbbbc32a13ed4426f25b Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 20 Mar 2020 09:46:13 -0700 Subject: [PATCH] fix: print from PDF viewer not working (#22760) --- chromium_src/BUILD.gn | 2 ++ .../api/resources_private/resources_private_api.cc | 5 +---- shell/renderer/renderer_client_base.cc | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/chromium_src/BUILD.gn b/chromium_src/BUILD.gn index 6b87ce686626..decd34a25af9 100644 --- a/chromium_src/BUILD.gn +++ b/chromium_src/BUILD.gn @@ -242,6 +242,8 @@ static_library("chrome") { "//chrome/renderer/extensions/extension_hooks_delegate.h", "//chrome/renderer/extensions/tabs_hooks_delegate.cc", "//chrome/renderer/extensions/tabs_hooks_delegate.h", + "//chrome/renderer/pepper/chrome_pdf_print_client.cc", + "//chrome/renderer/pepper/chrome_pdf_print_client.h", ] } } diff --git a/shell/browser/extensions/api/resources_private/resources_private_api.cc b/shell/browser/extensions/api/resources_private/resources_private_api.cc index 8540f68c62d5..cb404f09f3e8 100644 --- a/shell/browser/extensions/api/resources_private/resources_private_api.cc +++ b/shell/browser/extensions/api/resources_private/resources_private_api.cc @@ -74,10 +74,7 @@ void AddAdditionalDataForPdf(base::DictionaryValue* dict) { dict->SetKey("pdfTwoUpViewEnabled", base::Value(base::FeatureList::IsEnabled( chrome_pdf::features::kPDFTwoUpView))); - - // TODO(nornagon): enable printing once it works. - bool enable_printing = false; - dict->SetKey("printingEnabled", base::Value(enable_printing)); + dict->SetKey("printingEnabled", base::Value(true)); #endif // BUILDFLAG(ENABLE_PDF) } diff --git a/shell/renderer/renderer_client_base.cc b/shell/renderer/renderer_client_base.cc index be19ec6615b3..20a0b11fcf76 100644 --- a/shell/renderer/renderer_client_base.cc +++ b/shell/renderer/renderer_client_base.cc @@ -68,6 +68,7 @@ #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) #include "base/strings/utf_string_conversions.h" +#include "chrome/renderer/pepper/chrome_pdf_print_client.h" #include "content/public/common/webplugininfo.h" #include "extensions/common/constants.h" #include "extensions/common/extensions_client.h" @@ -156,6 +157,9 @@ void RendererClientBase::RenderThreadStarted() { extensions_renderer_client_.reset(new ElectronExtensionsRendererClient); extensions::ExtensionsRendererClient::Set(extensions_renderer_client_.get()); + // Enables printing from Chrome PDF viewer. + pdf::PepperPDFHost::SetPrintClient(new ChromePDFPrintClient()); + thread->AddObserver(extensions_renderer_client_->GetDispatcher()); #endif