fix: window.print() in pdf plugin (#28328)

This commit is contained in:
Shelley Vohr 2021-03-23 14:40:37 +00:00 committed by GitHub
parent 6a0b03ba6a
commit 7c36463085
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -94,6 +94,7 @@ const defaultPrintingSetting = {
pagesPerSheet: 1,
isFirstRequest: false,
previewUIID: 0,
// True, if the document source is modifiable. e.g. HTML and not PDF.
previewModifiable: true,
printToPDF: true,
deviceName: 'Save as PDF',

View file

@ -11,6 +11,7 @@
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/common/constants.h"
#include "extensions/renderer/guest_view/mime_handler_view/post_message_support.h"
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
namespace electron {
@ -50,6 +51,20 @@ bool PrintRenderFrameHelperDelegate::IsPrintPreviewEnabled() {
bool PrintRenderFrameHelperDelegate::OverridePrint(
blink::WebLocalFrame* frame) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
auto* post_message_support =
extensions::PostMessageSupport::FromWebLocalFrame(frame);
if (post_message_support) {
// This message is handled in chrome/browser/resources/pdf/pdf_viewer.js and
// instructs the PDF plugin to print. This is to make window.print() on a
// PDF plugin document correctly print the PDF. See
// https://crbug.com/448720.
base::DictionaryValue message;
message.SetString("type", "print");
post_message_support->PostMessageFromValue(message);
return true;
}
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
return false;
}