2013-10-23 21:30:47 +02:00
|
|
|
// 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"
|
2019-07-17 20:47:27 +02:00
|
|
|
|
2017-05-19 11:06:00 +02:00
|
|
|
#include "include/internal/cef_types_wrappers.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#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"
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
|
|
|
|
#include <map>
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
2013-10-23 21:30:47 +02:00
|
|
|
|
|
|
|
#include "base/bind.h"
|
|
|
|
#include "base/lazy_instance.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "base/memory/ptr_util.h"
|
2016-10-17 20:14:44 +02:00
|
|
|
#include "base/memory/ref_counted_memory.h"
|
2018-10-02 14:14:11 +02:00
|
|
|
#include "base/task/post_task.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
#include "chrome/browser/browser_process.h"
|
|
|
|
#include "chrome/browser/printing/print_job_manager.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "chrome/browser/printing/print_preview_dialog_controller.h"
|
2015-03-24 16:40:08 +01:00
|
|
|
#include "chrome/browser/printing/printer_query.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "chrome/browser/profiles/profile.h"
|
|
|
|
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
|
2019-11-12 17:11:44 +01:00
|
|
|
#include "components/printing/common/print.mojom.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "content/browser/download/download_manager_impl.h"
|
|
|
|
#include "content/public/browser/browser_context.h"
|
2018-10-02 14:14:11 +02:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "content/public/browser/download_manager.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
#include "content/public/browser/web_contents.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
2019-11-12 17:11:44 +01:00
|
|
|
#include "mojo/public/cpp/bindings/associated_remote.h"
|
2018-09-04 11:43:21 +02:00
|
|
|
#include "printing/metafile_skia.h"
|
2019-11-12 17:11:44 +01:00
|
|
|
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "libcef/browser/printing/print_dialog_linux.h"
|
|
|
|
#endif
|
2018-03-20 21:15:08 +01:00
|
|
|
|
2013-10-23 21:30:47 +02:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
|
|
|
namespace printing {
|
|
|
|
|
2015-03-24 16:40:08 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const int PREVIEW_UIID = 12345678;
|
|
|
|
|
|
|
|
// Convert CefPdfPrintSettings into base::DictionaryValue.
|
|
|
|
void FillInDictionaryFromPdfPrintSettings(
|
|
|
|
const CefPdfPrintSettings& pdf_settings,
|
|
|
|
int request_id,
|
|
|
|
base::DictionaryValue& print_settings) {
|
|
|
|
// Fixed settings.
|
2020-06-09 19:48:00 +02:00
|
|
|
print_settings.SetIntKey(kSettingPrinterType,
|
2021-07-23 18:40:13 +02:00
|
|
|
static_cast<int>(mojom::PrinterType::kPdf));
|
2020-08-29 00:39:23 +02:00
|
|
|
print_settings.SetInteger(kSettingColor,
|
|
|
|
static_cast<int>(mojom::ColorModel::kGray));
|
2020-06-09 19:48:00 +02:00
|
|
|
print_settings.SetInteger(kSettingDuplexMode,
|
|
|
|
static_cast<int>(mojom::DuplexMode::kSimplex));
|
2015-03-24 16:40:08 +01:00
|
|
|
print_settings.SetInteger(kSettingCopies, 1);
|
|
|
|
print_settings.SetBoolean(kSettingCollate, false);
|
|
|
|
print_settings.SetString(kSettingDeviceName, "");
|
2017-04-06 17:20:07 +02:00
|
|
|
print_settings.SetBoolean(kSettingRasterizePdf, false);
|
2015-03-24 16:40:08 +01:00
|
|
|
print_settings.SetBoolean(kSettingPreviewModifiable, false);
|
2017-04-20 21:28:17 +02:00
|
|
|
print_settings.SetInteger(kSettingDpiHorizontal, 0);
|
|
|
|
print_settings.SetInteger(kSettingDpiVertical, 0);
|
2019-01-17 10:56:52 +01:00
|
|
|
print_settings.SetInteger(kSettingPagesPerSheet, 1);
|
2015-03-24 16:40:08 +01:00
|
|
|
|
|
|
|
// User defined settings.
|
|
|
|
print_settings.SetBoolean(kSettingLandscape, !!pdf_settings.landscape);
|
|
|
|
print_settings.SetBoolean(kSettingShouldPrintSelectionOnly,
|
|
|
|
!!pdf_settings.selection_only);
|
|
|
|
print_settings.SetBoolean(kSettingShouldPrintBackgrounds,
|
|
|
|
!!pdf_settings.backgrounds_enabled);
|
|
|
|
print_settings.SetBoolean(kSettingHeaderFooterEnabled,
|
|
|
|
!!pdf_settings.header_footer_enabled);
|
2017-05-17 11:29:28 +02:00
|
|
|
print_settings.SetInteger(kSettingScaleFactor, pdf_settings.scale_factor > 0
|
|
|
|
? pdf_settings.scale_factor
|
|
|
|
: 100);
|
2015-03-24 16:40:08 +01:00
|
|
|
|
|
|
|
if (pdf_settings.header_footer_enabled) {
|
2017-05-17 11:29:28 +02:00
|
|
|
print_settings.SetString(
|
|
|
|
kSettingHeaderFooterTitle,
|
2015-03-24 16:40:08 +01:00
|
|
|
CefString(&pdf_settings.header_footer_title).ToString16());
|
2017-05-17 11:29:28 +02:00
|
|
|
print_settings.SetString(
|
|
|
|
kSettingHeaderFooterURL,
|
2015-03-24 16:40:08 +01:00
|
|
|
CefString(&pdf_settings.header_footer_url).ToString16());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdf_settings.page_width > 0 && pdf_settings.page_height > 0) {
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
|
2015-03-24 16:40:08 +01:00
|
|
|
dict->SetInteger(kSettingMediaSizeWidthMicrons, pdf_settings.page_width);
|
|
|
|
dict->SetInteger(kSettingMediaSizeHeightMicrons, pdf_settings.page_height);
|
2016-01-06 20:20:54 +01:00
|
|
|
print_settings.Set(kSettingMediaSize, std::move(dict));
|
2015-03-24 16:40:08 +01:00
|
|
|
}
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
auto margin_type = printing::mojom::MarginType::kDefaultMargins;
|
2015-03-24 16:40:08 +01:00
|
|
|
switch (pdf_settings.margin_type) {
|
|
|
|
case PDF_PRINT_MARGIN_NONE:
|
2020-08-29 00:39:23 +02:00
|
|
|
margin_type = printing::mojom::MarginType::kNoMargins;
|
2015-03-24 16:40:08 +01:00
|
|
|
break;
|
|
|
|
case PDF_PRINT_MARGIN_MINIMUM:
|
2020-08-29 00:39:23 +02:00
|
|
|
margin_type = printing::mojom::MarginType::kPrintableAreaMargins;
|
2015-03-24 16:40:08 +01:00
|
|
|
break;
|
|
|
|
case PDF_PRINT_MARGIN_CUSTOM:
|
2020-08-29 00:39:23 +02:00
|
|
|
margin_type = printing::mojom::MarginType::kCustomMargins;
|
2015-03-24 16:40:08 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
print_settings.SetInteger(kSettingMarginsType, static_cast<int>(margin_type));
|
|
|
|
if (margin_type == printing::mojom::MarginType::kCustomMargins) {
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
|
2020-04-21 20:44:52 +02:00
|
|
|
dict->SetInteger(kSettingMarginTop, pdf_settings.margin_top);
|
|
|
|
dict->SetInteger(kSettingMarginRight, pdf_settings.margin_right);
|
|
|
|
dict->SetInteger(kSettingMarginBottom, pdf_settings.margin_bottom);
|
|
|
|
dict->SetInteger(kSettingMarginLeft, pdf_settings.margin_left);
|
2016-01-06 20:20:54 +01:00
|
|
|
print_settings.Set(kSettingMarginsCustom, std::move(dict));
|
2015-03-24 16:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Service settings.
|
|
|
|
print_settings.SetInteger(kPreviewUIID, PREVIEW_UIID);
|
|
|
|
print_settings.SetInteger(kPreviewRequestID, request_id);
|
|
|
|
print_settings.SetBoolean(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();
|
2019-09-04 17:13:32 +02:00
|
|
|
std::unique_ptr<PrinterQuery> printer_query =
|
2015-03-24 16:40:08 +01:00
|
|
|
queue->PopPrinterQuery(document_cookie);
|
|
|
|
if (printer_query.get()) {
|
2020-07-08 19:23:29 +02:00
|
|
|
content::GetIOThreadTaskRunner({})->PostTask(
|
|
|
|
FROM_HERE,
|
2019-09-04 17:13:32 +02:00
|
|
|
base::BindOnce(&PrinterQuery::StopWorker, std::move(printer_query)));
|
2015-03-24 16:40:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the PDF file to disk.
|
2018-10-02 14:14:11 +02:00
|
|
|
void SavePdfFile(scoped_refptr<base::RefCountedSharedMemoryMapping> data,
|
2015-03-24 16:40:08 +01:00
|
|
|
const base::FilePath& path,
|
2021-06-04 03:34:56 +02:00
|
|
|
CefPrintViewManager::PdfPrintCallback callback) {
|
2018-03-20 21:15:08 +01:00
|
|
|
CEF_REQUIRE_BLOCKING();
|
2015-03-24 16:40:08 +01:00
|
|
|
DCHECK_GT(data->size(), 0U);
|
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
MetafileSkia metafile;
|
2020-04-14 21:31:00 +02:00
|
|
|
metafile.InitFromData(*data);
|
2015-03-24 16:40:08 +01:00
|
|
|
|
|
|
|
base::File file(path,
|
|
|
|
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
|
|
|
|
bool ok = file.IsValid() && metafile.SaveTo(&file);
|
|
|
|
|
|
|
|
if (!callback.is_null()) {
|
2021-06-04 03:34:56 +02:00
|
|
|
content::GetUIThreadTaskRunner({})->PostTask(
|
|
|
|
FROM_HERE, base::BindOnce(std::move(callback), ok));
|
2015-03-24 16:40:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
struct CefPrintViewManager::PdfPrintState {
|
|
|
|
content::RenderFrameHost* printing_rfh_ = nullptr;
|
|
|
|
base::FilePath output_path_;
|
|
|
|
base::DictionaryValue settings_;
|
|
|
|
PdfPrintCallback callback_;
|
|
|
|
};
|
|
|
|
|
2016-07-14 03:35:07 +02:00
|
|
|
CefPrintViewManager::CefPrintViewManager(content::WebContents* web_contents)
|
2021-03-04 23:36:57 +01:00
|
|
|
: PrintViewManager(web_contents) {}
|
2013-10-23 21:30:47 +02:00
|
|
|
|
2016-07-14 03:35:07 +02:00
|
|
|
CefPrintViewManager::~CefPrintViewManager() {
|
2015-03-24 16:40:08 +01:00
|
|
|
TerminatePdfPrintJob();
|
2013-10-23 21:30:47 +02:00
|
|
|
}
|
|
|
|
|
2021-08-20 01:40:49 +02:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
bool CefPrintViewManager::PrintToPDF(content::RenderFrameHost* rfh,
|
|
|
|
const base::FilePath& path,
|
|
|
|
const CefPdfPrintSettings& settings,
|
2021-06-04 03:34:56 +02:00
|
|
|
PdfPrintCallback callback) {
|
2016-11-23 21:54:29 +01:00
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
2013-10-23 21:30:47 +02:00
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
// Don't start print again while printing is currently in progress.
|
|
|
|
if (pdf_print_state_)
|
|
|
|
return false;
|
|
|
|
|
2020-07-08 19:23:29 +02:00
|
|
|
// Don't print crashed tabs.
|
2022-01-25 21:26:51 +01:00
|
|
|
if (!web_contents() || web_contents()->IsCrashed() || !rfh->IsRenderFrameLive()) {
|
2016-11-23 21:54:29 +01:00
|
|
|
return false;
|
|
|
|
}
|
2013-10-23 21:30:47 +02:00
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
pdf_print_state_.reset(new PdfPrintState);
|
|
|
|
pdf_print_state_->printing_rfh_ = rfh;
|
|
|
|
pdf_print_state_->output_path_ = path;
|
2021-06-04 03:34:56 +02:00
|
|
|
pdf_print_state_->callback_ = std::move(callback);
|
2016-11-23 21:54:29 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
FillInDictionaryFromPdfPrintSettings(settings, ++next_pdf_request_id_,
|
2016-11-23 21:54:29 +01:00
|
|
|
pdf_print_state_->settings_);
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
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);
|
2016-11-23 21:54:29 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
void CefPrintViewManager::GetDefaultPrintSettings(
|
|
|
|
GetDefaultPrintSettingsCallback callback) {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2020-10-08 21:54:42 +02:00
|
|
|
// 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();
|
2019-07-17 20:47:27 +02:00
|
|
|
}
|
|
|
|
|
2021-01-28 00:13:12 +01:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
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_;
|
2021-06-04 03:34:56 +02:00
|
|
|
PdfPrintCallback print_callback = std::move(pdf_print_state_->callback_);
|
2021-03-04 23:36:57 +01:00
|
|
|
|
|
|
|
// Reset state information.
|
|
|
|
pdf_print_state_.reset();
|
|
|
|
pdf_print_receiver_.reset();
|
|
|
|
|
|
|
|
// Save the PDF file to disk and then execute the callback.
|
2021-06-04 03:34:56 +02:00
|
|
|
CEF_POST_USER_VISIBLE_TASK(base::BindOnce(
|
|
|
|
&SavePdfFile, shared_buf, output_path, std::move(print_callback)));
|
2021-03-04 23:36:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
void CefPrintViewManager::RenderFrameDeleted(
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
|
|
|
if (pdf_print_state_ &&
|
|
|
|
render_frame_host == pdf_print_state_->printing_rfh_) {
|
|
|
|
TerminatePdfPrintJob();
|
|
|
|
}
|
2020-10-08 21:54:42 +02:00
|
|
|
PrintViewManager::RenderFrameDeleted(render_frame_host);
|
2013-10-23 21:30:47 +02:00
|
|
|
}
|
|
|
|
|
2016-07-14 03:35:07 +02:00
|
|
|
void CefPrintViewManager::NavigationStopped() {
|
2015-03-24 16:40:08 +01:00
|
|
|
TerminatePdfPrintJob();
|
2020-10-08 21:54:42 +02:00
|
|
|
PrintViewManager::NavigationStopped();
|
2015-03-24 16:40:08 +01:00
|
|
|
}
|
|
|
|
|
2021-11-10 22:57:31 +01:00
|
|
|
void CefPrintViewManager::PrimaryMainFrameRenderProcessGone(
|
|
|
|
base::TerminationStatus status) {
|
2015-03-24 16:40:08 +01:00
|
|
|
TerminatePdfPrintJob();
|
2021-11-10 22:57:31 +01:00
|
|
|
PrintViewManager::PrimaryMainFrameRenderProcessGone(status);
|
2015-03-24 16:40:08 +01:00
|
|
|
}
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
// 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()));
|
|
|
|
}
|
|
|
|
|
2016-07-14 03:35:07 +02:00
|
|
|
void CefPrintViewManager::TerminatePdfPrintJob() {
|
2015-03-24 16:40:08 +01:00
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
2016-11-23 21:54:29 +01:00
|
|
|
if (!pdf_print_state_)
|
2015-03-24 16:40:08 +01:00
|
|
|
return;
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
if (!pdf_print_state_->callback_.is_null()) {
|
2015-03-24 16:40:08 +01:00
|
|
|
// Execute the callback.
|
2020-07-08 19:23:29 +02:00
|
|
|
content::GetUIThreadTaskRunner({})->PostTask(
|
2021-06-04 03:34:56 +02:00
|
|
|
FROM_HERE,
|
|
|
|
base::BindOnce(std::move(pdf_print_state_->callback_), false));
|
2015-03-24 16:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset state information.
|
2016-11-23 21:54:29 +01:00
|
|
|
pdf_print_state_.reset();
|
2021-03-04 23:36:57 +01:00
|
|
|
pdf_print_receiver_.reset();
|
2015-03-24 16:40:08 +01:00
|
|
|
}
|
|
|
|
|
2013-10-23 21:30:47 +02:00
|
|
|
} // namespace printing
|