2015-07-16 23:40:01 +02:00
|
|
|
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
#include "libcef/renderer/extensions/print_render_frame_helper_delegate.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
|
|
|
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/strings/string_util.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
|
|
|
#include "chrome/common/extensions/extension_constants.h"
|
2021-11-10 22:57:31 +01:00
|
|
|
#include "chrome/common/pdf_util.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "chrome/common/url_constants.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "content/public/renderer/render_frame.h"
|
|
|
|
#include "extensions/common/constants.h"
|
2021-03-04 23:36:57 +01:00
|
|
|
#include "extensions/renderer/guest_view/mime_handler_view/post_message_support.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "services/service_manager/public/cpp/interface_provider.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/web/web_document.h"
|
|
|
|
#include "third_party/blink/public/web/web_element.h"
|
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
2019-07-17 20:47:27 +02:00
|
|
|
CefPrintRenderFrameHelperDelegate::CefPrintRenderFrameHelperDelegate(
|
|
|
|
bool is_windowless)
|
|
|
|
: is_windowless_(is_windowless) {}
|
|
|
|
|
2021-11-10 22:57:31 +01:00
|
|
|
CefPrintRenderFrameHelperDelegate::~CefPrintRenderFrameHelperDelegate() =
|
|
|
|
default;
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
// Return the PDF object element if |frame| is the out of process PDF extension.
|
2017-09-06 23:40:58 +02:00
|
|
|
blink::WebElement CefPrintRenderFrameHelperDelegate::GetPdfElement(
|
2017-05-17 11:29:28 +02:00
|
|
|
blink::WebLocalFrame* frame) {
|
2021-11-10 22:57:31 +01:00
|
|
|
if (frame->Parent() &&
|
|
|
|
IsPdfInternalPluginAllowedOrigin(frame->Parent()->GetSecurityOrigin())) {
|
|
|
|
auto plugin_element = frame->GetDocument().QuerySelector("embed");
|
|
|
|
DCHECK(!plugin_element.IsNull());
|
|
|
|
return plugin_element;
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
return blink::WebElement();
|
|
|
|
}
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
bool CefPrintRenderFrameHelperDelegate::IsPrintPreviewEnabled() {
|
2019-07-17 20:47:27 +02:00
|
|
|
return !is_windowless_ && PrintPreviewEnabled();
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2022-12-14 20:51:03 +01:00
|
|
|
bool CefPrintRenderFrameHelperDelegate::ShouldGenerateTaggedPDF() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
bool CefPrintRenderFrameHelperDelegate::OverridePrint(
|
|
|
|
blink::WebLocalFrame* frame) {
|
2019-07-16 19:59:21 +02:00
|
|
|
auto* post_message_support =
|
|
|
|
extensions::PostMessageSupport::FromWebLocalFrame(frame);
|
|
|
|
if (post_message_support) {
|
2015-07-16 23:40:01 +02:00
|
|
|
// This message is handled in chrome/browser/resources/pdf/pdf.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");
|
2019-07-16 19:59:21 +02:00
|
|
|
post_message_support->PostMessageFromValue(message);
|
2015-07-16 23:40:01 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace extensions
|