2018-11-09 03:42:34 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/renderer/printing/print_render_frame_helper_delegate.h"
|
2018-11-09 03:42:34 +00:00
|
|
|
|
2022-06-22 17:37:58 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2018-11-09 03:42:34 +00:00
|
|
|
#include "content/public/renderer/render_frame.h"
|
2020-10-17 01:30:46 +00:00
|
|
|
#include "extensions/buildflags/buildflags.h"
|
2018-11-09 03:42:34 +00:00
|
|
|
#include "third_party/blink/public/web/web_element.h"
|
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
|
|
|
|
2020-10-17 01:30:46 +00:00
|
|
|
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
2022-05-13 00:20:45 +00:00
|
|
|
#include "chrome/common/pdf_util.h"
|
2020-10-17 01:30:46 +00:00
|
|
|
#include "extensions/common/constants.h"
|
2021-03-23 14:40:37 +00:00
|
|
|
#include "extensions/renderer/guest_view/mime_handler_view/post_message_support.h"
|
2020-10-17 01:30:46 +00:00
|
|
|
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
|
|
|
|
|
2018-11-09 03:42:34 +00:00
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
PrintRenderFrameHelperDelegate::PrintRenderFrameHelperDelegate() = default;
|
|
|
|
|
|
|
|
PrintRenderFrameHelperDelegate::~PrintRenderFrameHelperDelegate() = default;
|
|
|
|
|
|
|
|
// Return the PDF object element if |frame| is the out of process PDF extension.
|
|
|
|
blink::WebElement PrintRenderFrameHelperDelegate::GetPdfElement(
|
|
|
|
blink::WebLocalFrame* frame) {
|
2020-10-17 01:30:46 +00:00
|
|
|
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
2022-05-13 00:20:45 +00:00
|
|
|
if (frame->Parent() &&
|
|
|
|
IsPdfInternalPluginAllowedOrigin(frame->Parent()->GetSecurityOrigin())) {
|
|
|
|
auto plugin_element = frame->GetDocument().QuerySelector("embed");
|
|
|
|
DCHECK(!plugin_element.IsNull());
|
|
|
|
return plugin_element;
|
2020-10-17 01:30:46 +00:00
|
|
|
}
|
|
|
|
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
|
2018-11-09 03:42:34 +00:00
|
|
|
return blink::WebElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PrintRenderFrameHelperDelegate::IsPrintPreviewEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PrintRenderFrameHelperDelegate::OverridePrint(
|
|
|
|
blink::WebLocalFrame* frame) {
|
2021-03-23 14:40:37 +00:00
|
|
|
#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.
|
2022-06-22 17:37:58 +00:00
|
|
|
base::Value::Dict message;
|
|
|
|
message.Set("type", "print");
|
|
|
|
post_message_support->PostMessageFromValue(base::Value(std::move(message)));
|
2021-03-23 14:40:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
|
2018-11-09 03:42:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|