зеркало из https://github.com/electron/electron.git
fix: Save As PDF from PDF Preview (#25959)
This commit is contained in:
Родитель
708cf44d19
Коммит
eca53aaaf1
|
@ -14,6 +14,12 @@
|
|||
#include "shell/browser/extensions/electron_extension_web_contents_observer.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)
|
||||
#include "components/pdf/browser/pdf_web_contents_helper.h" // nogncheck
|
||||
#include "shell/browser/electron_pdf_web_contents_helper_client.h"
|
||||
|
@ -52,13 +58,18 @@ MessagingDelegate* ElectronExtensionsAPIClient::GetMessagingDelegate() {
|
|||
|
||||
void ElectronExtensionsAPIClient::AttachWebContentsHelpers(
|
||||
content::WebContents* web_contents) const {
|
||||
extensions::ElectronExtensionWebContentsObserver::CreateForWebContents(
|
||||
web_contents);
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
electron::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
|
||||
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
|
||||
web_contents, std::make_unique<ElectronPDFWebContentsHelperClient>());
|
||||
#endif
|
||||
|
||||
extensions::ElectronExtensionWebContentsObserver::CreateForWebContents(
|
||||
web_contents);
|
||||
}
|
||||
|
||||
ManagementAPIDelegate*
|
||||
|
|
|
@ -5,9 +5,14 @@
|
|||
#include "shell/renderer/printing/print_render_frame_helper_delegate.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_local_frame.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
||||
#include "extensions/common/constants.h"
|
||||
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
|
||||
|
||||
namespace electron {
|
||||
|
||||
PrintRenderFrameHelperDelegate::PrintRenderFrameHelperDelegate() = default;
|
||||
|
@ -17,6 +22,25 @@ PrintRenderFrameHelperDelegate::~PrintRenderFrameHelperDelegate() = default;
|
|||
// Return the PDF object element if |frame| is the out of process PDF extension.
|
||||
blink::WebElement PrintRenderFrameHelperDelegate::GetPdfElement(
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@
|
|||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
#include "chrome/renderer/pepper/chrome_pdf_print_client.h" // nogncheck
|
||||
#include "shell/common/electron_constants.h"
|
||||
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
|
||||
|
@ -173,7 +172,8 @@ void RendererClientBase::RenderThreadStarted() {
|
|||
|
||||
#if BUILDFLAG(ENABLE_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
|
||||
|
||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "content/public/renderer/content_renderer_client.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "printing/buildflags/buildflags.h"
|
||||
#include "third_party/blink/public/web/web_local_frame.h"
|
||||
// In SHARED_INTERMEDIATE_DIR.
|
||||
#include "widevine_cdm_version.h" // NOLINT(build/include_directory)
|
||||
|
@ -19,6 +20,10 @@
|
|||
#include "chrome/renderer/media/chrome_key_systems_provider.h" // nogncheck
|
||||
#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)
|
||||
#include "services/service_manager/public/cpp/binder_registry.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)
|
||||
std::unique_ptr<SpellCheck> spellcheck_;
|
||||
#endif
|
||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
std::unique_ptr<ChromePDFPrintClient> pdf_print_client_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace electron
|
||||
|
|
Загрузка…
Ссылка в новой задаче