mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Use new PrintViewManagerBase::PrintToPdf method (fixes issue #3377)
This commit is contained in:
@@ -349,30 +349,6 @@ void AlloyBrowserHostImpl::SetZoomLevel(double zoomLevel) {
|
||||
}
|
||||
}
|
||||
|
||||
void AlloyBrowserHostImpl::Print() {
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::Print, this));
|
||||
return;
|
||||
}
|
||||
|
||||
if (platform_delegate_)
|
||||
platform_delegate_->Print();
|
||||
}
|
||||
|
||||
void AlloyBrowserHostImpl::PrintToPDF(const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback) {
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::PrintToPDF,
|
||||
this, path, settings, callback));
|
||||
return;
|
||||
}
|
||||
|
||||
if (platform_delegate_) {
|
||||
platform_delegate_->PrintToPDF(path, settings, callback);
|
||||
}
|
||||
}
|
||||
|
||||
void AlloyBrowserHostImpl::Find(const CefString& searchText,
|
||||
bool forward,
|
||||
bool matchCase,
|
||||
|
@@ -82,10 +82,6 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
|
||||
CefWindowHandle GetOpenerWindowHandle() override;
|
||||
double GetZoomLevel() override;
|
||||
void SetZoomLevel(double zoomLevel) override;
|
||||
void Print() override;
|
||||
void PrintToPDF(const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback) override;
|
||||
void Find(const CefString& searchText,
|
||||
bool forward,
|
||||
bool matchCase,
|
||||
|
@@ -32,7 +32,6 @@
|
||||
#include "libcef/browser/net_service/proxy_url_loader_factory.h"
|
||||
#include "libcef/browser/net_service/resource_request_handler_wrapper.h"
|
||||
#include "libcef/browser/prefs/renderer_prefs.h"
|
||||
#include "libcef/browser/printing/print_view_manager.h"
|
||||
#include "libcef/browser/speech_recognition_manager_delegate.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/browser/x509_certificate_impl.h"
|
||||
@@ -66,6 +65,7 @@
|
||||
#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
|
||||
#include "chrome/browser/plugins/plugin_utils.h"
|
||||
#include "chrome/browser/predictors/network_hints_handler_impl.h"
|
||||
#include "chrome/browser/printing/print_view_manager.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/profiles/renderer_updater.h"
|
||||
#include "chrome/browser/profiles/renderer_updater_factory.h"
|
||||
@@ -946,7 +946,7 @@ void AlloyContentBrowserClient::
|
||||
[](content::RenderFrameHost* render_frame_host,
|
||||
mojo::PendingAssociatedReceiver<printing::mojom::PrintManagerHost>
|
||||
receiver) {
|
||||
printing::CefPrintViewManager::BindPrintManagerHost(
|
||||
printing::PrintViewManager::BindPrintManagerHost(
|
||||
std::move(receiver), render_frame_host);
|
||||
},
|
||||
&render_frame_host));
|
||||
|
@@ -11,14 +11,12 @@
|
||||
#include "libcef/browser/extensions/extension_system.h"
|
||||
#include "libcef/browser/extensions/extension_view_host.h"
|
||||
#include "libcef/browser/extensions/extension_web_contents_observer.h"
|
||||
#include "libcef/browser/printing/print_view_manager.h"
|
||||
#include "libcef/common/extensions/extensions_util.h"
|
||||
#include "libcef/common/net/url_util.h"
|
||||
#include "libcef/features/runtime_checks.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "chrome/browser/printing/print_view_manager.h"
|
||||
#include "chrome/browser/printing/print_view_manager_common.h"
|
||||
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
|
||||
#include "components/find_in_page/find_tab_helper.h"
|
||||
#include "components/find_in_page/find_types.h"
|
||||
@@ -30,18 +28,8 @@
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "extensions/browser/process_manager.h"
|
||||
#include "pdf/pdf_features.h"
|
||||
#include "printing/mojom/print.mojom.h"
|
||||
#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
|
||||
|
||||
namespace {
|
||||
|
||||
printing::CefPrintViewManager* GetPrintViewManager(
|
||||
content::WebContents* web_contents) {
|
||||
return printing::CefPrintViewManager::FromWebContents(web_contents);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CefBrowserPlatformDelegateAlloy::CefBrowserPlatformDelegateAlloy()
|
||||
: weak_ptr_factory_(this) {}
|
||||
|
||||
@@ -181,7 +169,7 @@ void CefBrowserPlatformDelegateAlloy::BrowserCreated(
|
||||
|
||||
permissions::PermissionRequestManager::CreateForWebContents(web_contents_);
|
||||
PrefsTabHelper::CreateForWebContents(web_contents_);
|
||||
printing::CefPrintViewManager::CreateForWebContents(web_contents_);
|
||||
printing::PrintViewManager::CreateForWebContents(web_contents_);
|
||||
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
// Used by the tabs extension API.
|
||||
@@ -357,48 +345,6 @@ bool CefBrowserPlatformDelegateAlloy::IsPrintPreviewSupported() const {
|
||||
return cef_browser_context->IsPrintPreviewSupported();
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateAlloy::Print() {
|
||||
REQUIRE_ALLOY_RUNTIME();
|
||||
|
||||
auto contents_to_use = printing::GetWebContentsToUse(web_contents_);
|
||||
if (!contents_to_use)
|
||||
return;
|
||||
|
||||
auto rfh_to_use = printing::GetRenderFrameHostToUse(contents_to_use);
|
||||
if (!rfh_to_use)
|
||||
return;
|
||||
|
||||
if (IsPrintPreviewSupported()) {
|
||||
GetPrintViewManager(contents_to_use)->PrintPreviewNow(rfh_to_use, false);
|
||||
} else {
|
||||
GetPrintViewManager(contents_to_use)->PrintNow(rfh_to_use);
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateAlloy::PrintToPDF(
|
||||
const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback) {
|
||||
REQUIRE_ALLOY_RUNTIME();
|
||||
|
||||
auto contents_to_use = printing::GetWebContentsToUse(web_contents_);
|
||||
if (!contents_to_use)
|
||||
return;
|
||||
|
||||
auto rfh_to_use = printing::GetRenderFrameHostToUse(contents_to_use);
|
||||
if (!rfh_to_use)
|
||||
return;
|
||||
|
||||
printing::CefPrintViewManager::PdfPrintCallback pdf_callback;
|
||||
if (callback.get()) {
|
||||
pdf_callback = base::BindOnce(&CefPdfPrintCallback::OnPdfPrintFinished,
|
||||
callback.get(), path);
|
||||
}
|
||||
GetPrintViewManager(contents_to_use)
|
||||
->PrintToPDF(rfh_to_use, base::FilePath(path), settings,
|
||||
std::move(pdf_callback));
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateAlloy::Find(const CefString& searchText,
|
||||
bool forward,
|
||||
bool matchCase,
|
||||
|
@@ -56,10 +56,6 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
|
||||
const CefSize& max_size) override;
|
||||
void SetAccessibilityState(cef_state_t accessibility_state) override;
|
||||
bool IsPrintPreviewSupported() const override;
|
||||
void Print() override;
|
||||
void PrintToPDF(const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback) override;
|
||||
void Find(const CefString& searchText,
|
||||
bool forward,
|
||||
bool matchCase,
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include "libcef/browser/context.h"
|
||||
#include "libcef/browser/image_impl.h"
|
||||
#include "libcef/browser/navigation_entry_impl.h"
|
||||
#include "libcef/browser/printing/print_util.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/frame_util.h"
|
||||
#include "libcef/common/net/url_util.h"
|
||||
@@ -348,6 +349,37 @@ void CefBrowserHostBase::DownloadImage(
|
||||
max_image_size, callback));
|
||||
}
|
||||
|
||||
void CefBrowserHostBase::Print() {
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefBrowserHostBase::Print, this));
|
||||
return;
|
||||
}
|
||||
|
||||
auto web_contents = GetWebContents();
|
||||
if (!web_contents)
|
||||
return;
|
||||
|
||||
const bool print_preview_disabled =
|
||||
!platform_delegate_ || !platform_delegate_->IsPrintPreviewSupported();
|
||||
print_util::Print(web_contents, print_preview_disabled);
|
||||
}
|
||||
|
||||
void CefBrowserHostBase::PrintToPDF(const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback) {
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefBrowserHostBase::PrintToPDF, this,
|
||||
path, settings, callback));
|
||||
return;
|
||||
}
|
||||
|
||||
auto web_contents = GetWebContents();
|
||||
if (!web_contents)
|
||||
return;
|
||||
|
||||
print_util::PrintToPDF(web_contents, path, settings, callback);
|
||||
}
|
||||
|
||||
bool CefBrowserHostBase::SendDevToolsMessage(const void* message,
|
||||
size_t message_size) {
|
||||
if (!message || message_size == 0)
|
||||
|
@@ -181,6 +181,10 @@ class CefBrowserHostBase : public CefBrowserHost,
|
||||
uint32 max_image_size,
|
||||
bool bypass_cache,
|
||||
CefRefPtr<CefDownloadImageCallback> callback) override;
|
||||
void Print() override;
|
||||
void PrintToPDF(const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback) override;
|
||||
void ReplaceMisspelling(const CefString& word) override;
|
||||
void AddWordToDictionary(const CefString& word) override;
|
||||
void SendKeyEvent(const CefKeyEvent& event) override;
|
||||
|
@@ -390,17 +390,6 @@ bool CefBrowserPlatformDelegate::IsPrintPreviewSupported() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegate::Print() {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegate::PrintToPDF(
|
||||
const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegate::Find(const CefString& searchText,
|
||||
bool forward,
|
||||
bool matchCase,
|
||||
|
@@ -363,10 +363,6 @@ class CefBrowserPlatformDelegate {
|
||||
const CefSize& max_size);
|
||||
virtual void SetAccessibilityState(cef_state_t accessibility_state);
|
||||
virtual bool IsPrintPreviewSupported() const;
|
||||
virtual void Print();
|
||||
virtual void PrintToPDF(const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback);
|
||||
virtual void Find(const CefString& searchText,
|
||||
bool forward,
|
||||
bool matchCase,
|
||||
|
@@ -6,9 +6,11 @@
|
||||
|
||||
#include "libcef/browser/views/view_util.h"
|
||||
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/browser_window.h"
|
||||
#include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "ui/display/display.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/gfx/geometry/point.h"
|
||||
@@ -117,6 +119,11 @@ CefEventHandle CefBrowserPlatformDelegateChrome::GetEventHandle(
|
||||
return native_delegate_->GetEventHandle(event);
|
||||
}
|
||||
|
||||
bool CefBrowserPlatformDelegateChrome::IsPrintPreviewSupported() const {
|
||||
return chrome_browser_ && !chrome_browser_->profile()->GetPrefs()->GetBoolean(
|
||||
prefs::kPrintPreviewDisabled);
|
||||
}
|
||||
|
||||
CefWindowHandle CefBrowserPlatformDelegateChrome::GetParentWindowHandle()
|
||||
const {
|
||||
return GetHostWindowHandle();
|
||||
|
@@ -42,6 +42,7 @@ class CefBrowserPlatformDelegateChrome
|
||||
void ViewText(const std::string& text) override;
|
||||
CefEventHandle GetEventHandle(
|
||||
const content::NativeWebKeyboardEvent& event) const override;
|
||||
bool IsPrintPreviewSupported() const override;
|
||||
|
||||
// CefBrowserPlatformDelegateNative::WindowlessHandler methods:
|
||||
CefWindowHandle GetParentWindowHandle() const override;
|
||||
|
@@ -13,7 +13,6 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/notreached.h"
|
||||
#include "chrome/browser/printing/print_view_manager_common.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/browser_commands.h"
|
||||
@@ -185,30 +184,6 @@ void ChromeBrowserHostImpl::SetZoomLevel(double zoomLevel) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
void ChromeBrowserHostImpl::Print() {
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(CEF_UIT, base::BindOnce(&ChromeBrowserHostImpl::Print, this));
|
||||
return;
|
||||
}
|
||||
|
||||
if (browser_) {
|
||||
// Like chrome::Print() but specifying the WebContents.
|
||||
printing::StartPrint(GetWebContents(),
|
||||
/*print_renderer=*/mojo::NullAssociatedRemote(),
|
||||
browser_->profile()->GetPrefs()->GetBoolean(
|
||||
prefs::kPrintPreviewDisabled),
|
||||
/*has_selection=*/false);
|
||||
}
|
||||
}
|
||||
|
||||
void ChromeBrowserHostImpl::PrintToPDF(
|
||||
const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback) {
|
||||
NOTIMPLEMENTED();
|
||||
callback->OnPdfPrintFinished(CefString(), false);
|
||||
}
|
||||
|
||||
void ChromeBrowserHostImpl::Find(const CefString& searchText,
|
||||
bool forward,
|
||||
bool matchCase,
|
||||
|
@@ -66,10 +66,6 @@ class ChromeBrowserHostImpl : public CefBrowserHostBase {
|
||||
CefWindowHandle GetOpenerWindowHandle() override;
|
||||
double GetZoomLevel() override;
|
||||
void SetZoomLevel(double zoomLevel) override;
|
||||
void Print() override;
|
||||
void PrintToPDF(const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback) override;
|
||||
void Find(const CefString& searchText,
|
||||
bool forward,
|
||||
bool matchCase,
|
||||
|
@@ -11,9 +11,9 @@
|
||||
#include "libcef/browser/extensions/api/storage/sync_value_store_cache.h"
|
||||
#include "libcef/browser/extensions/extension_web_contents_observer.h"
|
||||
#include "libcef/browser/extensions/mime_handler_view_guest_delegate.h"
|
||||
#include "libcef/browser/printing/print_view_manager.h"
|
||||
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "chrome/browser/printing/print_view_manager.h"
|
||||
#include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
|
||||
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
|
||||
#include "components/pdf/browser/pdf_web_contents_helper.h"
|
||||
@@ -51,7 +51,7 @@ CefExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate(
|
||||
void CefExtensionsAPIClient::AttachWebContentsHelpers(
|
||||
content::WebContents* web_contents) const {
|
||||
PrefsTabHelper::CreateForWebContents(web_contents);
|
||||
printing::CefPrintViewManager::CreateForWebContents(web_contents);
|
||||
printing::PrintViewManager::CreateForWebContents(web_contents);
|
||||
|
||||
// Used by the PDF extension.
|
||||
pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
|
||||
|
@@ -34,6 +34,10 @@ namespace {
|
||||
|
||||
CefRefPtr<CefBrowserHostBase> GetBrowserForContext(
|
||||
printing::PrintingContextLinux* context) {
|
||||
// The print preview dialog won't have a valid child ID.
|
||||
if (!frame_util::IsValidChildId(context->render_process_id()))
|
||||
return nullptr;
|
||||
|
||||
return extensions::GetOwnerBrowserForGlobalId(
|
||||
frame_util::MakeGlobalId(context->render_process_id(),
|
||||
context->render_frame_id()),
|
||||
@@ -192,27 +196,19 @@ void CefPrintingContextLinuxDelegate::SetDefaultDelegate(
|
||||
default_delegate_ = delegate;
|
||||
}
|
||||
|
||||
// static
|
||||
void CefPrintDialogLinux::OnPrintStart(CefRefPtr<CefBrowserHostBase> browser) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(browser);
|
||||
if (browser && browser->GetClient()) {
|
||||
if (auto handler = browser->GetClient()->GetPrintHandler()) {
|
||||
handler->OnPrintStart(browser.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CefPrintDialogLinux::CefPrintDialogLinux(PrintingContextLinux* context,
|
||||
CefRefPtr<CefBrowserHostBase> browser,
|
||||
CefRefPtr<CefPrintHandler> handler)
|
||||
: context_(context), browser_(browser), handler_(handler) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(context_);
|
||||
DCHECK(browser_);
|
||||
DCHECK(handler_);
|
||||
|
||||
// Paired with the ReleaseDialog() call.
|
||||
AddRef();
|
||||
|
||||
handler->OnPrintStart(browser_.get());
|
||||
}
|
||||
|
||||
CefPrintDialogLinux::~CefPrintDialogLinux() {
|
||||
|
@@ -52,9 +52,6 @@ class CefPrintDialogLinux : public printing::PrintDialogLinuxInterface,
|
||||
CefPrintDialogLinux(const CefPrintDialogLinux&) = delete;
|
||||
CefPrintDialogLinux& operator=(const CefPrintDialogLinux&) = delete;
|
||||
|
||||
// Notify the client when printing has started.
|
||||
static void OnPrintStart(CefRefPtr<CefBrowserHostBase> browser);
|
||||
|
||||
// PrintDialogLinuxInterface implementation.
|
||||
void UseDefaultSettings() override;
|
||||
void UpdateSettings(
|
||||
|
143
libcef/browser/printing/print_util.cc
Normal file
143
libcef/browser/printing/print_util.cc
Normal file
@@ -0,0 +1,143 @@
|
||||
// Copyright (c) 2022 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "libcef/browser/printing/print_util.h"
|
||||
|
||||
#include "libcef/browser/thread_util.h"
|
||||
|
||||
#include "base/files/file_util.h"
|
||||
#include "chrome/browser/printing/print_view_manager.h"
|
||||
#include "chrome/browser/printing/print_view_manager_common.h"
|
||||
#include "components/printing/browser/print_to_pdf/pdf_print_utils.h"
|
||||
|
||||
namespace print_util {
|
||||
|
||||
namespace {
|
||||
|
||||
// Write the PDF file to disk.
|
||||
void SavePdfFile(const CefString& path,
|
||||
CefRefPtr<CefPdfPrintCallback> callback,
|
||||
scoped_refptr<base::RefCountedMemory> data) {
|
||||
CEF_REQUIRE_BLOCKING();
|
||||
DCHECK_GT(data->size(), 0U);
|
||||
|
||||
const bool ok =
|
||||
base::WriteFile(path, reinterpret_cast<const char*>(data->data()),
|
||||
data->size()) == static_cast<int>(data->size());
|
||||
|
||||
if (callback) {
|
||||
CEF_POST_TASK(CEF_UIT,
|
||||
base::BindOnce(&CefPdfPrintCallback::OnPdfPrintFinished,
|
||||
callback, path, ok));
|
||||
}
|
||||
}
|
||||
|
||||
void OnPDFCreated(const CefString& path,
|
||||
CefRefPtr<CefPdfPrintCallback> callback,
|
||||
print_to_pdf::PdfPrintResult print_result,
|
||||
scoped_refptr<base::RefCountedMemory> data) {
|
||||
if (print_result != print_to_pdf::PdfPrintResult::kPrintSuccess) {
|
||||
LOG(ERROR) << "PrintToPDF failed with error: "
|
||||
<< print_to_pdf::PdfPrintResultToString(print_result);
|
||||
callback->OnPdfPrintFinished(CefString(), false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the PDF file to disk and then execute the callback.
|
||||
CEF_POST_USER_VISIBLE_TASK(
|
||||
base::BindOnce(&SavePdfFile, path, callback, std::move(data)));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void Print(content::WebContents* web_contents, bool print_preview_disabled) {
|
||||
// Like chrome::Print() but specifying the WebContents.
|
||||
printing::StartPrint(web_contents,
|
||||
/*print_renderer=*/mojo::NullAssociatedRemote(),
|
||||
print_preview_disabled,
|
||||
/*has_selection=*/false);
|
||||
}
|
||||
|
||||
// Implementation based on PageHandler::PrintToPDF.
|
||||
void PrintToPDF(content::WebContents* web_contents,
|
||||
const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback) {
|
||||
const bool display_header_footer = !!settings.display_header_footer;
|
||||
|
||||
// Defaults to no header/footer.
|
||||
absl::optional<std::string> header_template, footer_template;
|
||||
if (display_header_footer) {
|
||||
if (settings.header_template.length > 0)
|
||||
header_template = CefString(&settings.header_template);
|
||||
if (settings.footer_template.length > 0)
|
||||
footer_template = CefString(&settings.footer_template);
|
||||
}
|
||||
|
||||
// Defaults to 1.0.
|
||||
absl::optional<double> scale;
|
||||
if (settings.scale > 0) {
|
||||
scale = settings.scale;
|
||||
}
|
||||
|
||||
// Defaults to letter size.
|
||||
absl::optional<double> paper_width, paper_height;
|
||||
if (settings.paper_width > 0 && settings.paper_height > 0) {
|
||||
paper_width = settings.paper_width;
|
||||
paper_height = settings.paper_height;
|
||||
}
|
||||
|
||||
// Defaults to kDefaultMarginInInches.
|
||||
absl::optional<double> margin_top, margin_bottom, margin_left, margin_right;
|
||||
if (settings.margin_type == PDF_PRINT_MARGIN_NONE) {
|
||||
margin_top = 0;
|
||||
margin_bottom = 0;
|
||||
margin_left = 0;
|
||||
margin_right = 0;
|
||||
} else if (settings.margin_type == PDF_PRINT_MARGIN_CUSTOM) {
|
||||
if (settings.margin_top >= 0)
|
||||
margin_top = settings.margin_top;
|
||||
if (settings.margin_bottom >= 0)
|
||||
margin_bottom = settings.margin_bottom;
|
||||
if (settings.margin_left >= 0)
|
||||
margin_left = settings.margin_left;
|
||||
if (settings.margin_right >= 0)
|
||||
margin_right = settings.margin_right;
|
||||
}
|
||||
|
||||
absl::variant<printing::mojom::PrintPagesParamsPtr, std::string>
|
||||
print_pages_params = print_to_pdf::GetPrintPagesParams(
|
||||
web_contents->GetPrimaryMainFrame()->GetLastCommittedURL(),
|
||||
!!settings.landscape, display_header_footer,
|
||||
!!settings.print_background, scale, paper_width, paper_height,
|
||||
margin_top, margin_bottom, margin_left, margin_right,
|
||||
CefString(&settings.header_template),
|
||||
CefString(&settings.footer_template),
|
||||
!!settings.prefer_css_page_size);
|
||||
|
||||
if (absl::holds_alternative<std::string>(print_pages_params)) {
|
||||
LOG(ERROR) << "PrintToPDF failed with error: "
|
||||
<< absl::get<std::string>(print_pages_params);
|
||||
callback->OnPdfPrintFinished(CefString(), false);
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(absl::holds_alternative<printing::mojom::PrintPagesParamsPtr>(
|
||||
print_pages_params));
|
||||
|
||||
if (auto* print_manager =
|
||||
printing::PrintViewManager::FromWebContents(web_contents)) {
|
||||
print_manager->PrintToPdf(
|
||||
web_contents->GetPrimaryMainFrame(), CefString(&settings.page_ranges),
|
||||
std::move(absl::get<printing::mojom::PrintPagesParamsPtr>(
|
||||
print_pages_params)),
|
||||
base::BindOnce(&OnPDFCreated, path, callback));
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(ERROR) << "PrintToPDF was not handled.";
|
||||
callback->OnPdfPrintFinished(CefString(), false);
|
||||
}
|
||||
|
||||
} // namespace print_util
|
28
libcef/browser/printing/print_util.h
Normal file
28
libcef/browser/printing/print_util.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2022 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_PRINTING_PRINT_UTIL_H_
|
||||
#define CEF_LIBCEF_BROWSER_PRINTING_PRINT_UTIL_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_browser.h"
|
||||
|
||||
namespace content {
|
||||
class WebContents;
|
||||
}
|
||||
|
||||
namespace print_util {
|
||||
|
||||
// Called from CefBrowserHostBase::Print.
|
||||
void Print(content::WebContents* web_contents, bool print_preview_disabled);
|
||||
|
||||
// Called from CefBrowserHostBase::PrintToPDF.
|
||||
void PrintToPDF(content::WebContents* web_contents,
|
||||
const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback);
|
||||
|
||||
} // namespace print_util
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_PRINTING_PRINT_UTIL_H_
|
@@ -1,373 +0,0 @@
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
#include "libcef/browser/printing/print_view_manager.h"
|
||||
|
||||
#include "include/internal/cef_types_wrappers.h"
|
||||
#include "libcef/browser/browser_info.h"
|
||||
#include "libcef/browser/browser_info_manager.h"
|
||||
#include "libcef/browser/download_manager_delegate.h"
|
||||
#include "libcef/browser/extensions/extension_web_contents_observer.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/memory/ref_counted_memory.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/printing/print_job_manager.h"
|
||||
#include "chrome/browser/printing/print_preview_dialog_controller.h"
|
||||
#include "chrome/browser/printing/printer_query.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
|
||||
#include "components/printing/common/print.mojom.h"
|
||||
#include "content/browser/download/download_manager_impl.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/download_manager.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "mojo/public/cpp/bindings/associated_remote.h"
|
||||
#include "printing/metafile_skia.h"
|
||||
#include "printing/units.h"
|
||||
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
#include "libcef/browser/printing/print_dialog_linux.h"
|
||||
#endif
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace printing {
|
||||
|
||||
namespace {
|
||||
|
||||
const int PREVIEW_UIID = 12345678;
|
||||
|
||||
// Convert CefPdfPrintSettings into base::Value::Dict.
|
||||
void FillInDictionaryFromPdfPrintSettings(
|
||||
const CefPdfPrintSettings& pdf_settings,
|
||||
int request_id,
|
||||
base::Value::Dict& print_settings) {
|
||||
// Fixed settings.
|
||||
print_settings.Set(kSettingPrinterType,
|
||||
static_cast<int>(mojom::PrinterType::kPdf));
|
||||
print_settings.Set(kSettingColor, static_cast<int>(mojom::ColorModel::kGray));
|
||||
print_settings.Set(kSettingDuplexMode,
|
||||
static_cast<int>(mojom::DuplexMode::kSimplex));
|
||||
print_settings.Set(kSettingCopies, 1);
|
||||
print_settings.Set(kSettingCollate, false);
|
||||
print_settings.Set(kSettingDeviceName, "");
|
||||
print_settings.Set(kSettingRasterizePdf, false);
|
||||
print_settings.Set(kSettingPreviewModifiable, false);
|
||||
print_settings.Set(kSettingDpiHorizontal, printing::kDefaultPdfDpi);
|
||||
print_settings.Set(kSettingDpiVertical, printing::kDefaultPdfDpi);
|
||||
print_settings.Set(kSettingPagesPerSheet, 1);
|
||||
|
||||
// User defined settings.
|
||||
print_settings.Set(kSettingLandscape, !!pdf_settings.landscape);
|
||||
print_settings.Set(kSettingShouldPrintSelectionOnly,
|
||||
!!pdf_settings.selection_only);
|
||||
print_settings.Set(kSettingShouldPrintBackgrounds,
|
||||
!!pdf_settings.backgrounds_enabled);
|
||||
print_settings.Set(kSettingHeaderFooterEnabled,
|
||||
!!pdf_settings.header_footer_enabled);
|
||||
print_settings.Set(kSettingScaleFactor, pdf_settings.scale_factor > 0
|
||||
? pdf_settings.scale_factor
|
||||
: 100);
|
||||
|
||||
if (pdf_settings.header_footer_enabled) {
|
||||
print_settings.Set(
|
||||
kSettingHeaderFooterTitle,
|
||||
CefString(&pdf_settings.header_footer_title).ToString16());
|
||||
print_settings.Set(kSettingHeaderFooterURL,
|
||||
CefString(&pdf_settings.header_footer_url).ToString16());
|
||||
}
|
||||
|
||||
if (pdf_settings.page_width > 0 && pdf_settings.page_height > 0) {
|
||||
base::Value::Dict dict;
|
||||
dict.Set(kSettingMediaSizeWidthMicrons, pdf_settings.page_width);
|
||||
dict.Set(kSettingMediaSizeHeightMicrons, pdf_settings.page_height);
|
||||
print_settings.Set(kSettingMediaSize, std::move(dict));
|
||||
}
|
||||
|
||||
auto margin_type = printing::mojom::MarginType::kDefaultMargins;
|
||||
switch (pdf_settings.margin_type) {
|
||||
case PDF_PRINT_MARGIN_NONE:
|
||||
margin_type = printing::mojom::MarginType::kNoMargins;
|
||||
break;
|
||||
case PDF_PRINT_MARGIN_MINIMUM:
|
||||
margin_type = printing::mojom::MarginType::kPrintableAreaMargins;
|
||||
break;
|
||||
case PDF_PRINT_MARGIN_CUSTOM:
|
||||
margin_type = printing::mojom::MarginType::kCustomMargins;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
print_settings.Set(kSettingMarginsType, static_cast<int>(margin_type));
|
||||
if (margin_type == printing::mojom::MarginType::kCustomMargins) {
|
||||
base::Value::Dict dict;
|
||||
dict.Set(kSettingMarginTop, pdf_settings.margin_top);
|
||||
dict.Set(kSettingMarginRight, pdf_settings.margin_right);
|
||||
dict.Set(kSettingMarginBottom, pdf_settings.margin_bottom);
|
||||
dict.Set(kSettingMarginLeft, pdf_settings.margin_left);
|
||||
print_settings.Set(kSettingMarginsCustom, std::move(dict));
|
||||
}
|
||||
|
||||
// Service settings.
|
||||
print_settings.Set(kPreviewUIID, PREVIEW_UIID);
|
||||
print_settings.Set(kPreviewRequestID, request_id);
|
||||
print_settings.Set(kIsFirstRequest, request_id != 0);
|
||||
}
|
||||
|
||||
void StopWorker(int document_cookie) {
|
||||
if (document_cookie <= 0)
|
||||
return;
|
||||
scoped_refptr<PrintQueriesQueue> queue =
|
||||
g_browser_process->print_job_manager()->queue();
|
||||
std::unique_ptr<PrinterQuery> printer_query =
|
||||
queue->PopPrinterQuery(document_cookie);
|
||||
if (printer_query.get()) {
|
||||
printer_query->StopWorker();
|
||||
}
|
||||
}
|
||||
|
||||
// Write the PDF file to disk.
|
||||
void SavePdfFile(scoped_refptr<base::RefCountedSharedMemoryMapping> data,
|
||||
const base::FilePath& path,
|
||||
CefPrintViewManager::PdfPrintCallback callback) {
|
||||
CEF_REQUIRE_BLOCKING();
|
||||
DCHECK_GT(data->size(), 0U);
|
||||
|
||||
MetafileSkia metafile;
|
||||
metafile.InitFromData(*data);
|
||||
|
||||
base::File file(path,
|
||||
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
|
||||
bool ok = file.IsValid() && metafile.SaveTo(&file);
|
||||
|
||||
if (!callback.is_null()) {
|
||||
content::GetUIThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE, base::BindOnce(std::move(callback), ok));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
struct CefPrintViewManager::PdfPrintState {
|
||||
content::RenderFrameHost* printing_rfh_ = nullptr;
|
||||
base::FilePath output_path_;
|
||||
base::Value::Dict settings_;
|
||||
PdfPrintCallback callback_;
|
||||
};
|
||||
|
||||
CefPrintViewManager::CefPrintViewManager(content::WebContents* web_contents)
|
||||
: PrintViewManager(web_contents) {}
|
||||
|
||||
CefPrintViewManager::~CefPrintViewManager() {
|
||||
TerminatePdfPrintJob();
|
||||
}
|
||||
|
||||
// static
|
||||
void CefPrintViewManager::BindPrintManagerHost(
|
||||
mojo::PendingAssociatedReceiver<mojom::PrintManagerHost> receiver,
|
||||
content::RenderFrameHost* rfh) {
|
||||
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
|
||||
if (!web_contents)
|
||||
return;
|
||||
auto* print_manager = CefPrintViewManager::FromWebContents(web_contents);
|
||||
if (!print_manager)
|
||||
return;
|
||||
print_manager->BindReceiver(std::move(receiver), rfh);
|
||||
}
|
||||
|
||||
bool CefPrintViewManager::PrintToPDF(content::RenderFrameHost* rfh,
|
||||
const base::FilePath& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
PdfPrintCallback callback) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
||||
// Don't start print again while printing is currently in progress.
|
||||
if (pdf_print_state_)
|
||||
return false;
|
||||
|
||||
// Don't print crashed tabs.
|
||||
if (!web_contents() || web_contents()->IsCrashed() ||
|
||||
!rfh->IsRenderFrameLive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pdf_print_state_.reset(new PdfPrintState);
|
||||
pdf_print_state_->printing_rfh_ = rfh;
|
||||
pdf_print_state_->output_path_ = path;
|
||||
pdf_print_state_->callback_ = std::move(callback);
|
||||
|
||||
FillInDictionaryFromPdfPrintSettings(settings, ++next_pdf_request_id_,
|
||||
pdf_print_state_->settings_);
|
||||
|
||||
auto& print_render_frame = GetPrintRenderFrame(rfh);
|
||||
if (!pdf_print_receiver_.is_bound()) {
|
||||
print_render_frame->SetPrintPreviewUI(
|
||||
pdf_print_receiver_.BindNewEndpointAndPassRemote());
|
||||
}
|
||||
|
||||
print_render_frame->InitiatePrintPreview({}, !!settings.selection_only);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CefPrintViewManager::GetDefaultPrintSettings(
|
||||
GetDefaultPrintSettingsCallback callback) {
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
// Send notification to the client.
|
||||
auto browser = CefBrowserHostBase::GetBrowserForContents(web_contents());
|
||||
if (browser) {
|
||||
CefPrintDialogLinux::OnPrintStart(browser);
|
||||
}
|
||||
#endif
|
||||
PrintViewManager::GetDefaultPrintSettings(std::move(callback));
|
||||
}
|
||||
|
||||
void CefPrintViewManager::DidShowPrintDialog() {
|
||||
if (pdf_print_state_)
|
||||
return;
|
||||
PrintViewManager::DidShowPrintDialog();
|
||||
}
|
||||
|
||||
void CefPrintViewManager::RequestPrintPreview(
|
||||
mojom::RequestPrintPreviewParamsPtr params) {
|
||||
if (!pdf_print_state_) {
|
||||
PrintViewManager::RequestPrintPreview(std::move(params));
|
||||
return;
|
||||
}
|
||||
|
||||
GetPrintRenderFrame(pdf_print_state_->printing_rfh_)
|
||||
->PrintPreview(pdf_print_state_->settings_.Clone());
|
||||
}
|
||||
|
||||
void CefPrintViewManager::CheckForCancel(int32_t preview_ui_id,
|
||||
int32_t request_id,
|
||||
CheckForCancelCallback callback) {
|
||||
if (!pdf_print_state_) {
|
||||
return PrintViewManager::CheckForCancel(preview_ui_id, request_id,
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
std::move(callback).Run(/*cancel=*/false);
|
||||
}
|
||||
|
||||
void CefPrintViewManager::MetafileReadyForPrinting(
|
||||
mojom::DidPreviewDocumentParamsPtr params,
|
||||
int32_t request_id) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
StopWorker(params->document_cookie);
|
||||
|
||||
if (!pdf_print_state_)
|
||||
return;
|
||||
|
||||
GetPrintRenderFrame(pdf_print_state_->printing_rfh_)
|
||||
->OnPrintPreviewDialogClosed();
|
||||
|
||||
auto shared_buf = base::RefCountedSharedMemoryMapping::CreateFromWholeRegion(
|
||||
params->content->metafile_data_region);
|
||||
if (!shared_buf) {
|
||||
TerminatePdfPrintJob();
|
||||
return;
|
||||
}
|
||||
|
||||
const base::FilePath output_path = pdf_print_state_->output_path_;
|
||||
PdfPrintCallback print_callback = std::move(pdf_print_state_->callback_);
|
||||
|
||||
// Reset state information.
|
||||
pdf_print_state_.reset();
|
||||
pdf_print_receiver_.reset();
|
||||
|
||||
// Save the PDF file to disk and then execute the callback.
|
||||
CEF_POST_USER_VISIBLE_TASK(base::BindOnce(
|
||||
&SavePdfFile, shared_buf, output_path, std::move(print_callback)));
|
||||
}
|
||||
|
||||
void CefPrintViewManager::PrintPreviewFailed(int32_t document_cookie,
|
||||
int32_t request_id) {
|
||||
TerminatePdfPrintJob();
|
||||
}
|
||||
|
||||
void CefPrintViewManager::PrintPreviewCancelled(int32_t document_cookie,
|
||||
int32_t request_id) {
|
||||
// Should never be canceled by CheckForCancel().
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
void CefPrintViewManager::RenderFrameDeleted(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
if (pdf_print_state_ &&
|
||||
render_frame_host == pdf_print_state_->printing_rfh_) {
|
||||
TerminatePdfPrintJob();
|
||||
}
|
||||
PrintViewManager::RenderFrameDeleted(render_frame_host);
|
||||
}
|
||||
|
||||
void CefPrintViewManager::NavigationStopped() {
|
||||
TerminatePdfPrintJob();
|
||||
PrintViewManager::NavigationStopped();
|
||||
}
|
||||
|
||||
void CefPrintViewManager::PrimaryMainFrameRenderProcessGone(
|
||||
base::TerminationStatus status) {
|
||||
TerminatePdfPrintJob();
|
||||
PrintViewManager::PrimaryMainFrameRenderProcessGone(status);
|
||||
}
|
||||
|
||||
// static
|
||||
void CefPrintViewManager::CreateForWebContents(content::WebContents* contents) {
|
||||
DCHECK(contents);
|
||||
if (!FromWebContents(contents)) {
|
||||
contents->SetUserData(PrintViewManager::UserDataKey(),
|
||||
base::WrapUnique(new CefPrintViewManager(contents)));
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
CefPrintViewManager* CefPrintViewManager::FromWebContents(
|
||||
content::WebContents* contents) {
|
||||
DCHECK(contents);
|
||||
return static_cast<CefPrintViewManager*>(
|
||||
contents->GetUserData(PrintViewManager::UserDataKey()));
|
||||
}
|
||||
|
||||
// static
|
||||
const CefPrintViewManager* CefPrintViewManager::FromWebContents(
|
||||
const content::WebContents* contents) {
|
||||
DCHECK(contents);
|
||||
return static_cast<const CefPrintViewManager*>(
|
||||
contents->GetUserData(PrintViewManager::UserDataKey()));
|
||||
}
|
||||
|
||||
void CefPrintViewManager::TerminatePdfPrintJob() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
if (!pdf_print_state_)
|
||||
return;
|
||||
|
||||
if (!pdf_print_state_->callback_.is_null()) {
|
||||
// Execute the callback.
|
||||
content::GetUIThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(std::move(pdf_print_state_->callback_), false));
|
||||
}
|
||||
|
||||
// Reset state information.
|
||||
pdf_print_state_.reset();
|
||||
pdf_print_receiver_.reset();
|
||||
}
|
||||
|
||||
} // namespace printing
|
@@ -1,107 +0,0 @@
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
|
||||
#define CEF_LIBCEF_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
|
||||
|
||||
#include "include/internal/cef_types_wrappers.h"
|
||||
|
||||
#include "base/callback_forward.h"
|
||||
#include "chrome/browser/printing/print_view_manager.h"
|
||||
#include "components/printing/common/print.mojom-forward.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "content/public/browser/web_contents_user_data.h"
|
||||
#include "printing/mojom/print.mojom.h"
|
||||
|
||||
namespace content {
|
||||
class RenderFrameHost;
|
||||
class RenderProcessHost;
|
||||
class WebContentsObserver;
|
||||
} // namespace content
|
||||
|
||||
class CefBrowserInfo;
|
||||
|
||||
namespace printing {
|
||||
|
||||
// CEF handler for print commands.
|
||||
class CefPrintViewManager : public PrintViewManager,
|
||||
public mojom::PrintPreviewUI {
|
||||
public:
|
||||
CefPrintViewManager(const CefPrintViewManager&) = delete;
|
||||
CefPrintViewManager& operator=(const CefPrintViewManager&) = delete;
|
||||
|
||||
~CefPrintViewManager() override;
|
||||
|
||||
static void BindPrintManagerHost(
|
||||
mojo::PendingAssociatedReceiver<mojom::PrintManagerHost> receiver,
|
||||
content::RenderFrameHost* rfh);
|
||||
|
||||
// Callback executed on PDF printing completion.
|
||||
using PdfPrintCallback = base::OnceCallback<void(bool /*ok*/)>;
|
||||
|
||||
// Print the current document to a PDF file. Execute |callback| on completion.
|
||||
bool PrintToPDF(content::RenderFrameHost* rfh,
|
||||
const base::FilePath& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
PdfPrintCallback callback);
|
||||
|
||||
// mojom::PrintManagerHost methods:
|
||||
void GetDefaultPrintSettings(
|
||||
GetDefaultPrintSettingsCallback callback) override;
|
||||
void DidShowPrintDialog() override;
|
||||
void RequestPrintPreview(mojom::RequestPrintPreviewParamsPtr params) override;
|
||||
void CheckForCancel(int32_t preview_ui_id,
|
||||
int32_t request_id,
|
||||
CheckForCancelCallback callback) override;
|
||||
|
||||
// printing::mojo::PrintPreviewUI methods:
|
||||
void SetOptionsFromDocument(const mojom::OptionsFromDocumentParamsPtr params,
|
||||
int32_t request_id) override {}
|
||||
void DidPrepareDocumentForPreview(int32_t document_cookie,
|
||||
int32_t request_id) override {}
|
||||
void DidPreviewPage(mojom::DidPreviewPageParamsPtr params,
|
||||
int32_t request_id) override {}
|
||||
void MetafileReadyForPrinting(mojom::DidPreviewDocumentParamsPtr params,
|
||||
int32_t request_id) override;
|
||||
void PrintPreviewFailed(int32_t document_cookie, int32_t request_id) override;
|
||||
void PrintPreviewCancelled(int32_t document_cookie,
|
||||
int32_t request_id) override;
|
||||
void PrinterSettingsInvalid(int32_t document_cookie,
|
||||
int32_t request_id) override {}
|
||||
void DidGetDefaultPageLayout(mojom::PageSizeMarginsPtr page_layout_in_points,
|
||||
const gfx::Rect& printable_area_in_points,
|
||||
bool has_custom_page_size_style,
|
||||
int32_t request_id) override {}
|
||||
void DidStartPreview(mojom::DidStartPreviewParamsPtr params,
|
||||
int32_t request_id) override {}
|
||||
|
||||
// content::WebContentsObserver methods:
|
||||
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
|
||||
void NavigationStopped() override;
|
||||
void PrimaryMainFrameRenderProcessGone(
|
||||
base::TerminationStatus status) override;
|
||||
|
||||
// Inline versions of the content::WebContentsUserData methods to avoid
|
||||
// ambiguous warnings due to the PrintViewManager base class also extending
|
||||
// WebContentsUserData.
|
||||
static void CreateForWebContents(content::WebContents* contents);
|
||||
static CefPrintViewManager* FromWebContents(content::WebContents* contents);
|
||||
static const CefPrintViewManager* FromWebContents(
|
||||
const content::WebContents* contents);
|
||||
|
||||
private:
|
||||
explicit CefPrintViewManager(content::WebContents* web_contents);
|
||||
|
||||
void TerminatePdfPrintJob();
|
||||
|
||||
// Used for printing to PDF. Only accessed on the browser process UI thread.
|
||||
int next_pdf_request_id_ = content::RenderFrameHost::kNoFrameTreeNodeId;
|
||||
struct PdfPrintState;
|
||||
std::unique_ptr<PdfPrintState> pdf_print_state_;
|
||||
mojo::AssociatedReceiver<mojom::PrintPreviewUI> pdf_print_receiver_{this};
|
||||
};
|
||||
|
||||
} // namespace printing
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
|
Reference in New Issue
Block a user