fix: Save As PDF from PDF Preview (#25959)
This commit is contained in:
parent
708cf44d19
commit
eca53aaaf1
4 changed files with 47 additions and 4 deletions
|
@ -14,6 +14,12 @@
|
||||||
#include "shell/browser/extensions/electron_extension_web_contents_observer.h"
|
#include "shell/browser/extensions/electron_extension_web_contents_observer.h"
|
||||||
#include "shell/browser/extensions/electron_messaging_delegate.h"
|
#include "shell/browser/extensions/electron_messaging_delegate.h"
|
||||||
|
|
||||||
|
#if BUILDFLAG(ENABLE_PRINTING)
|
||||||
|
#include "chrome/browser/printing/print_view_manager_basic.h"
|
||||||
|
#include "components/printing/browser/print_manager_utils.h"
|
||||||
|
#include "shell/browser/printing/print_preview_message_handler.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||||
#include "components/pdf/browser/pdf_web_contents_helper.h" // nogncheck
|
#include "components/pdf/browser/pdf_web_contents_helper.h" // nogncheck
|
||||||
#include "shell/browser/electron_pdf_web_contents_helper_client.h"
|
#include "shell/browser/electron_pdf_web_contents_helper_client.h"
|
||||||
|
@ -52,13 +58,18 @@ MessagingDelegate* ElectronExtensionsAPIClient::GetMessagingDelegate() {
|
||||||
|
|
||||||
void ElectronExtensionsAPIClient::AttachWebContentsHelpers(
|
void ElectronExtensionsAPIClient::AttachWebContentsHelpers(
|
||||||
content::WebContents* web_contents) const {
|
content::WebContents* web_contents) const {
|
||||||
extensions::ElectronExtensionWebContentsObserver::CreateForWebContents(
|
#if BUILDFLAG(ENABLE_PRINTING)
|
||||||
web_contents);
|
electron::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
|
||||||
|
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||||
pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
|
pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
|
||||||
web_contents, std::make_unique<ElectronPDFWebContentsHelperClient>());
|
web_contents, std::make_unique<ElectronPDFWebContentsHelperClient>());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extensions::ElectronExtensionWebContentsObserver::CreateForWebContents(
|
||||||
|
web_contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
ManagementAPIDelegate*
|
ManagementAPIDelegate*
|
||||||
|
|
|
@ -5,9 +5,14 @@
|
||||||
#include "shell/renderer/printing/print_render_frame_helper_delegate.h"
|
#include "shell/renderer/printing/print_render_frame_helper_delegate.h"
|
||||||
|
|
||||||
#include "content/public/renderer/render_frame.h"
|
#include "content/public/renderer/render_frame.h"
|
||||||
|
#include "extensions/buildflags/buildflags.h"
|
||||||
#include "third_party/blink/public/web/web_element.h"
|
#include "third_party/blink/public/web/web_element.h"
|
||||||
#include "third_party/blink/public/web/web_local_frame.h"
|
#include "third_party/blink/public/web/web_local_frame.h"
|
||||||
|
|
||||||
|
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
||||||
|
#include "extensions/common/constants.h"
|
||||||
|
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
PrintRenderFrameHelperDelegate::PrintRenderFrameHelperDelegate() = default;
|
PrintRenderFrameHelperDelegate::PrintRenderFrameHelperDelegate() = default;
|
||||||
|
@ -17,6 +22,25 @@ PrintRenderFrameHelperDelegate::~PrintRenderFrameHelperDelegate() = default;
|
||||||
// Return the PDF object element if |frame| is the out of process PDF extension.
|
// Return the PDF object element if |frame| is the out of process PDF extension.
|
||||||
blink::WebElement PrintRenderFrameHelperDelegate::GetPdfElement(
|
blink::WebElement PrintRenderFrameHelperDelegate::GetPdfElement(
|
||||||
blink::WebLocalFrame* frame) {
|
blink::WebLocalFrame* frame) {
|
||||||
|
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
||||||
|
GURL url = frame->GetDocument().Url();
|
||||||
|
bool inside_pdf_extension =
|
||||||
|
url.SchemeIs(extensions::kExtensionScheme) &&
|
||||||
|
url.host_piece() == extension_misc::kPdfExtensionId;
|
||||||
|
if (inside_pdf_extension) {
|
||||||
|
// <object> with id="plugin" is created in
|
||||||
|
// chrome/browser/resources/pdf/pdf_viewer_base.js.
|
||||||
|
auto viewer_element = frame->GetDocument().GetElementById("viewer");
|
||||||
|
if (!viewer_element.IsNull() && !viewer_element.ShadowRoot().IsNull()) {
|
||||||
|
auto plugin_element =
|
||||||
|
viewer_element.ShadowRoot().QuerySelector("#plugin");
|
||||||
|
if (!plugin_element.IsNull()) {
|
||||||
|
return plugin_element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NOTREACHED();
|
||||||
|
}
|
||||||
|
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
|
||||||
return blink::WebElement();
|
return blink::WebElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||||
#include "chrome/renderer/pepper/chrome_pdf_print_client.h" // nogncheck
|
|
||||||
#include "shell/common/electron_constants.h"
|
#include "shell/common/electron_constants.h"
|
||||||
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||||
|
|
||||||
|
@ -173,7 +172,8 @@ void RendererClientBase::RenderThreadStarted() {
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||||
// Enables printing from Chrome PDF viewer.
|
// Enables printing from Chrome PDF viewer.
|
||||||
pdf::PepperPDFHost::SetPrintClient(new ChromePDFPrintClient());
|
pdf_print_client_.reset(new ChromePDFPrintClient());
|
||||||
|
pdf::PepperPDFHost::SetPrintClient(pdf_print_client_.get());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "content/public/renderer/content_renderer_client.h"
|
#include "content/public/renderer/content_renderer_client.h"
|
||||||
#include "electron/buildflags/buildflags.h"
|
#include "electron/buildflags/buildflags.h"
|
||||||
|
#include "printing/buildflags/buildflags.h"
|
||||||
#include "third_party/blink/public/web/web_local_frame.h"
|
#include "third_party/blink/public/web/web_local_frame.h"
|
||||||
// In SHARED_INTERMEDIATE_DIR.
|
// In SHARED_INTERMEDIATE_DIR.
|
||||||
#include "widevine_cdm_version.h" // NOLINT(build/include_directory)
|
#include "widevine_cdm_version.h" // NOLINT(build/include_directory)
|
||||||
|
@ -19,6 +20,10 @@
|
||||||
#include "chrome/renderer/media/chrome_key_systems_provider.h" // nogncheck
|
#include "chrome/renderer/media/chrome_key_systems_provider.h" // nogncheck
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||||
|
#include "chrome/renderer/pepper/chrome_pdf_print_client.h" // nogncheck
|
||||||
|
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
#include "services/service_manager/public/cpp/binder_registry.h"
|
#include "services/service_manager/public/cpp/binder_registry.h"
|
||||||
#include "services/service_manager/public/cpp/local_interface_provider.h"
|
#include "services/service_manager/public/cpp/local_interface_provider.h"
|
||||||
|
@ -146,6 +151,9 @@ class RendererClientBase : public content::ContentRendererClient
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
std::unique_ptr<SpellCheck> spellcheck_;
|
std::unique_ptr<SpellCheck> spellcheck_;
|
||||||
#endif
|
#endif
|
||||||
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||||
|
std::unique_ptr<ChromePDFPrintClient> pdf_print_client_;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
Loading…
Reference in a new issue