| Index: chrome/browser/printing/print_view_manager_base.cc
|
| diff --git a/chrome/browser/printing/print_view_manager_base.cc b/chrome/browser/printing/print_view_manager_base.cc
|
| index 17961d3a7c468ec5aa2785907a6d97656476577a..42fc0e93a5e6c97b0f021e696d692bd77c8c2d5b 100644
|
| --- a/chrome/browser/printing/print_view_manager_base.cc
|
| +++ b/chrome/browser/printing/print_view_manager_base.cc
|
| @@ -11,6 +11,8 @@
|
| #include "base/bind.h"
|
| #include "base/location.h"
|
| #include "base/memory/ptr_util.h"
|
| +#include "base/memory/shared_memory.h"
|
| +#include "base/memory/shared_memory_handle.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| #include "base/single_thread_task_runner.h"
|
| @@ -28,6 +30,8 @@
|
| #include "chrome/common/pref_names.h"
|
| #include "chrome/grit/generated_resources.h"
|
| #include "components/prefs/pref_service.h"
|
| +#include "components/printing/browser/print_composite_client.h"
|
| +#include "components/printing/browser/print_manager_utils.h"
|
| #include "components/printing/common/print_messages.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/notification_details.h"
|
| @@ -38,6 +42,7 @@
|
| #include "content/public/browser/web_contents.h"
|
| #include "printing/features/features.h"
|
| #include "printing/pdf_metafile_skia.h"
|
| +#include "printing/print_settings.h"
|
| #include "printing/printed_document.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| @@ -127,8 +132,24 @@ void PrintViewManagerBase::OnDidGetPrintedPagesCount(int cookie,
|
| OpportunisticallyCreatePrintJob(cookie);
|
| }
|
|
|
| +void PrintViewManagerBase::OnComposePdfDone(
|
| + const PrintHostMsg_DidPrintPage_Params& params,
|
| + mojom::PdfCompositor::Status status,
|
| + mojo::ScopedSharedBufferHandle handle) {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + if (status != mojom::PdfCompositor::Status::SUCCESS) {
|
| + NOTREACHED() << "Compositing pdf failed";
|
| + return;
|
| + }
|
| +
|
| + UpdateForPrintedPage(
|
| + params, true,
|
| + PrintCompositeClient::GetShmFromMojoHandle(std::move(handle)));
|
| +}
|
| +
|
| void PrintViewManagerBase::OnDidPrintPage(
|
| - const PrintHostMsg_DidPrintPage_Params& params) {
|
| + const PrintHostMsg_DidPrintPage_Params& params) {
|
| + // Ready to composite. Starting a print job.
|
| if (!OpportunisticallyCreatePrintJob(params.document_cookie))
|
| return;
|
|
|
| @@ -154,12 +175,24 @@ void PrintViewManagerBase::OnDidPrintPage(
|
| web_contents()->Stop();
|
| return;
|
| }
|
| - shared_buf =
|
| - base::MakeUnique<base::SharedMemory>(params.metafile_data_handle, true);
|
| - if (!shared_buf->Map(params.data_size)) {
|
| - NOTREACHED() << "couldn't map";
|
| - web_contents()->Stop();
|
| - return;
|
| +
|
| + if (IsOopifEnabled()) {
|
| + if (auto* client =
|
| + PrintCompositeClient::FromWebContents(web_contents())) {
|
| + client->DoComposite(
|
| + params.metafile_data_handle, params.data_size,
|
| + base::BindOnce(&PrintViewManagerBase::OnComposePdfDone,
|
| + base::Unretained(this), params),
|
| + base::ThreadTaskRunnerHandle::Get());
|
| + }
|
| + } else {
|
| + shared_buf = base::MakeUnique<base::SharedMemory>(
|
| + params.metafile_data_handle, true);
|
| + if (!shared_buf->Map(params.data_size)) {
|
| + NOTREACHED() << "couldn't map";
|
| + web_contents()->Stop();
|
| + return;
|
| + }
|
| }
|
| } else {
|
| if (base::SharedMemory::IsHandleValid(params.metafile_data_handle)) {
|
| @@ -170,22 +203,25 @@ void PrintViewManagerBase::OnDidPrintPage(
|
| }
|
| }
|
|
|
| - std::unique_ptr<PdfMetafileSkia> metafile(
|
| - new PdfMetafileSkia(PDF_SKIA_DOCUMENT_TYPE));
|
| - if (metafile_must_be_valid) {
|
| - if (!metafile->InitFromData(shared_buf->memory(), params.data_size)) {
|
| - NOTREACHED() << "Invalid metafile header";
|
| - web_contents()->Stop();
|
| - return;
|
| - }
|
| - }
|
| + if (!IsOopifEnabled())
|
| + UpdateForPrintedPage(params, metafile_must_be_valid, std::move(shared_buf));
|
| +}
|
| +
|
| +void PrintViewManagerBase::UpdateForPrintedPage(
|
| + const PrintHostMsg_DidPrintPage_Params& params,
|
| + bool has_valid_page_data,
|
| + std::unique_ptr<base::SharedMemory> shared_buf) {
|
| + PrintedDocument* document = print_job_->document();
|
| + if (!document)
|
| + return;
|
|
|
| #if defined(OS_WIN)
|
| print_job_->AppendPrintedPage(params.page_number);
|
| - if (metafile_must_be_valid) {
|
| - scoped_refptr<base::RefCountedBytes> bytes = new base::RefCountedBytes(
|
| + if (has_valid_page_data) {
|
| + scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(
|
| reinterpret_cast<const unsigned char*>(shared_buf->memory()),
|
| - params.data_size);
|
| + shared_buf->mapped_size()));
|
| +
|
| document->DebugDumpData(bytes.get(), FILE_PATH_LITERAL(".pdf"));
|
|
|
| const auto& settings = document->settings();
|
| @@ -203,22 +239,27 @@ void PrintViewManagerBase::OnDidPrintPage(
|
| // Update : The missing letters seem to have been caused by the same
|
| // problem as https://crbug.com/659604 which was resolved. GDI printing
|
| // seems to work with the fix for this bug applied.
|
| - bool print_text_with_gdi = settings.print_text_with_gdi() &&
|
| - !settings.printer_is_xps() &&
|
| - base::FeatureList::IsEnabled(
|
| - features::kGdiTextPrinting);
|
| + bool print_text_with_gdi =
|
| + settings.print_text_with_gdi() && !settings.printer_is_xps() &&
|
| + base::FeatureList::IsEnabled(features::kGdiTextPrinting);
|
| print_job_->StartPdfToEmfConversion(
|
| bytes, params.page_size, params.content_area, print_text_with_gdi);
|
| }
|
| }
|
| #else
|
| + std::unique_ptr<PdfMetafileSkia> metafile =
|
| + base::MakeUnique<PdfMetafileSkia>(SkiaDocumentType::PDF);
|
| + if (has_valid_page_data) {
|
| + if (!metafile->InitFromData(shared_buf->memory(),
|
| + shared_buf->mapped_size())) {
|
| + NOTREACHED() << "Invalid metafile header";
|
| + web_contents()->Stop();
|
| + return;
|
| + }
|
| + }
|
| +
|
| // Update the rendered document. It will send notifications to the listener.
|
| - document->SetPage(params.page_number,
|
| - std::move(metafile),
|
| -#if defined(OS_WIN)
|
| - 0.0f /* dummy shrink_factor */,
|
| -#endif
|
| - params.page_size,
|
| + document->SetPage(params.page_number, std::move(metafile), params.page_size,
|
| params.content_area);
|
|
|
| ShouldQuitFromInnerMessageLoop();
|
|
|