| Index: chrome/utility/printing_handler.cc
|
| diff --git a/chrome/utility/printing_handler.cc b/chrome/utility/printing_handler.cc
|
| index 7dbae1a132df5b38ba8e615c28545bf39148fbd2..61c90174d86d9521b88e85a0bc3259964ccacc44 100644
|
| --- a/chrome/utility/printing_handler.cc
|
| +++ b/chrome/utility/printing_handler.cc
|
| @@ -10,10 +10,11 @@
|
| #include "base/files/file_util.h"
|
| #include "build/build_config.h"
|
| #include "chrome/common/chrome_paths.h"
|
| -#include "chrome/common/chrome_utility_printing_messages.h"
|
| #include "chrome/utility/cloud_print/bitmap_image.h"
|
| #include "chrome/utility/cloud_print/pwg_encoder.h"
|
| #include "content/public/utility/utility_thread.h"
|
| +#include "mojo/public/cpp/bindings/strong_binding.h"
|
| +#include "mojo/public/cpp/system/platform_handle.h"
|
| #include "pdf/pdf.h"
|
| #include "printing/features/features.h"
|
| #include "printing/page_range.h"
|
| @@ -33,104 +34,132 @@ namespace printing {
|
|
|
| namespace {
|
|
|
| -bool Send(IPC::Message* message) {
|
| - return content::UtilityThread::Get()->Send(message);
|
| -}
|
| -
|
| void ReleaseProcessIfNeeded() {
|
| content::UtilityThread::Get()->ReleaseProcessIfNeeded();
|
| }
|
|
|
| +static mojom::FontPreCaching* g_font_pre_caching;
|
| +
|
| #if defined(OS_WIN)
|
| void PreCacheFontCharacters(const LOGFONT* logfont,
|
| const wchar_t* text,
|
| size_t text_length) {
|
| - Send(new ChromeUtilityHostMsg_PreCacheFontCharacters(
|
| - *logfont, base::string16(text, text_length)));
|
| + if (g_font_pre_caching) {
|
| + g_font_pre_caching->PreCacheFontCharacters(
|
| + *logfont, base::string16(text, text_length));
|
| + }
|
| }
|
| #endif
|
|
|
| } // namespace
|
|
|
| -PrintingHandler::PrintingHandler() {
|
| +PrintingHandler::PrintingHandler(mojom::FontPreCachingPtr font_pre_caching)
|
| + : font_pre_caching_(std::move(font_pre_caching)) {
|
| + g_font_pre_caching = font_pre_caching_.get();
|
| #if defined(OS_WIN)
|
| chrome_pdf::SetPDFEnsureTypefaceCharactersAccessible(PreCacheFontCharacters);
|
| #endif
|
| }
|
|
|
| -PrintingHandler::~PrintingHandler() {}
|
| +PrintingHandler::~PrintingHandler() {
|
| + g_font_pre_caching = nullptr;
|
| +}
|
|
|
| bool PrintingHandler::OnMessageReceived(const IPC::Message& message) {
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message)
|
| -#if defined(OS_WIN)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles,
|
| - OnRenderPDFPagesToMetafile)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage,
|
| - OnRenderPDFPagesToMetafileGetPage)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop,
|
| - OnRenderPDFPagesToMetafileStop)
|
| -#endif // OS_WIN
|
| -#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToPWGRaster,
|
| - OnRenderPDFPagesToPWGRaster)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults,
|
| - OnGetPrinterCapsAndDefaults)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults,
|
| - OnGetPrinterSemanticCapsAndDefaults)
|
| -#endif // ENABLE_PRINT_PREVIEW
|
| - IPC_MESSAGE_UNHANDLED(handled = false)
|
| - IPC_END_MESSAGE_MAP()
|
| - return handled;
|
| + return false;
|
| }
|
|
|
| -#if defined(OS_WIN)
|
| -void PrintingHandler::OnRenderPDFPagesToMetafile(
|
| - IPC::PlatformFileForTransit pdf_transit,
|
| +namespace {
|
| +class PrintingHandlerFactory : public mojom::PrintingFactory {
|
| + public:
|
| + // mojom::PrintingFactory:
|
| + void MakePrinting(mojom::PrintingRequest request,
|
| + mojom::FontPreCachingPtr font_pre_caching) override {
|
| + mojo::MakeStrongBinding(
|
| + base::MakeUnique<PrintingHandler>(std::move(font_pre_caching)),
|
| + std::move(request));
|
| + }
|
| +};
|
| +} // namespace
|
| +
|
| +// static
|
| +void PrintingHandler::Create(mojom::PrintingFactoryRequest request) {
|
| + mojo::MakeStrongBinding(base::MakeUnique<PrintingHandlerFactory>(),
|
| + std::move(request));
|
| +}
|
| +
|
| +void PrintingHandler::RenderPDFPagesToMetafiles(
|
| + mojo::ScopedHandle pdf_transit,
|
| const PdfRenderSettings& settings,
|
| - bool print_text_with_gdi) {
|
| + bool print_text_with_gdi,
|
| + const RenderPDFPagesToMetafilesCallback& callback) {
|
| +#if defined(OS_WIN)
|
| pdf_rendering_settings_ = settings;
|
| chrome_pdf::SetPDFUseGDIPrinting(print_text_with_gdi);
|
| - base::File pdf_file = IPC::PlatformFileForTransitToFile(pdf_transit);
|
| + base::PlatformFile platform_file;
|
| + CHECK_EQ(mojo::UnwrapPlatformFile(std::move(pdf_transit), &platform_file),
|
| + MOJO_RESULT_OK);
|
| + base::File pdf_file(platform_file);
|
| int page_count = LoadPDF(std::move(pdf_file));
|
| - Send(
|
| - new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount(page_count));
|
| + callback.Run(page_count);
|
| +#else
|
| + NOTREACHED();
|
| +#endif
|
| }
|
|
|
| -void PrintingHandler::OnRenderPDFPagesToMetafileGetPage(
|
| +void PrintingHandler::RenderPDFPagesToMetafilesGetPage(
|
| int page_number,
|
| - IPC::PlatformFileForTransit output_file) {
|
| - base::File emf_file = IPC::PlatformFileForTransitToFile(output_file);
|
| + mojo::ScopedHandle output_file,
|
| + const RenderPDFPagesToMetafilesGetPageCallback& callback) {
|
| +#if defined(OS_WIN)
|
| + base::PlatformFile platform_file;
|
| + CHECK_EQ(mojo::UnwrapPlatformFile(std::move(output_file), &platform_file),
|
| + MOJO_RESULT_OK);
|
| + base::File emf_file(platform_file);
|
| float scale_factor = 1.0f;
|
| bool success =
|
| RenderPdfPageToMetafile(page_number, std::move(emf_file), &scale_factor);
|
| - Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone(
|
| - success, scale_factor));
|
| + callback.Run(success, scale_factor);
|
| +#else
|
| + NOTREACHED();
|
| +#endif
|
| }
|
|
|
| -void PrintingHandler::OnRenderPDFPagesToMetafileStop() {
|
| +void PrintingHandler::RenderPDFPagesToMetafilesStop() {
|
| +#if defined(OS_WIN)
|
| ReleaseProcessIfNeeded();
|
| +#else
|
| + NOTREACHED();
|
| +#endif
|
| }
|
|
|
| -#endif // OS_WIN
|
| -
|
| -#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
| -void PrintingHandler::OnRenderPDFPagesToPWGRaster(
|
| - IPC::PlatformFileForTransit pdf_transit,
|
| +void PrintingHandler::RenderPDFPagesToPWGRaster(
|
| + mojo::ScopedHandle pdf_transit,
|
| const PdfRenderSettings& settings,
|
| const PwgRasterSettings& bitmap_settings,
|
| - IPC::PlatformFileForTransit bitmap_transit) {
|
| - base::File pdf = IPC::PlatformFileForTransitToFile(pdf_transit);
|
| - base::File bitmap = IPC::PlatformFileForTransitToFile(bitmap_transit);
|
| + mojo::ScopedHandle bitmap_transit,
|
| + const RenderPDFPagesToPWGRasterCallback& callback) {
|
| +#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
| + base::PlatformFile pdf_platform_file;
|
| + CHECK_EQ(mojo::UnwrapPlatformFile(std::move(pdf_transit), &pdf_platform_file),
|
| + MOJO_RESULT_OK);
|
| + base::File pdf(pdf_platform_file);
|
| + base::PlatformFile bitmap_platform_file;
|
| + CHECK_EQ(mojo::UnwrapPlatformFile(std::move(bitmap_transit),
|
| + &bitmap_platform_file),
|
| + MOJO_RESULT_OK);
|
| + base::File bitmap(bitmap_platform_file);
|
| if (RenderPDFPagesToPWGRaster(std::move(pdf), settings, bitmap_settings,
|
| std::move(bitmap))) {
|
| - Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Succeeded());
|
| + callback.Run(true);
|
| } else {
|
| - Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Failed());
|
| + callback.Run(false);
|
| }
|
| ReleaseProcessIfNeeded();
|
| -}
|
| +#else
|
| + NOTREACHED();
|
| #endif // ENABLE_PRINT_PREVIEW
|
| +}
|
|
|
| #if defined(OS_WIN)
|
| int PrintingHandler::LoadPDF(base::File pdf_file) {
|
| @@ -270,9 +299,12 @@ bool PrintingHandler::RenderPDFPagesToPWGRaster(
|
| }
|
| return true;
|
| }
|
| +#endif // ENABLE_PRINT_PREVIEW
|
|
|
| -void PrintingHandler::OnGetPrinterCapsAndDefaults(
|
| - const std::string& printer_name) {
|
| +void PrintingHandler::GetPrinterCapsAndDefaults(
|
| + const std::string& printer_name,
|
| + const GetPrinterCapsAndDefaultsCallback& callback) {
|
| +#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
| scoped_refptr<PrintBackend> print_backend =
|
| PrintBackend::CreateInstance(nullptr);
|
| PrinterCapsAndDefaults printer_info;
|
| @@ -281,17 +313,20 @@ void PrintingHandler::OnGetPrinterCapsAndDefaults(
|
| print_backend->GetPrinterDriverInfo(printer_name));
|
|
|
| if (print_backend->GetPrinterCapsAndDefaults(printer_name, &printer_info)) {
|
| - Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded(
|
| - printer_name, printer_info));
|
| + callback.Run(printer_info);
|
| } else {
|
| - Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed(
|
| - printer_name));
|
| + callback.Run(base::nullopt);
|
| }
|
| ReleaseProcessIfNeeded();
|
| +#else
|
| + NOTREACHED();
|
| +#endif // ENABLE_PRINT_PREVIEW
|
| }
|
|
|
| -void PrintingHandler::OnGetPrinterSemanticCapsAndDefaults(
|
| - const std::string& printer_name) {
|
| +void PrintingHandler::GetPrinterSemanticCapsAndDefaults(
|
| + const std::string& printer_name,
|
| + const GetPrinterSemanticCapsAndDefaultsCallback& callback) {
|
| +#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
| scoped_refptr<PrintBackend> print_backend =
|
| PrintBackend::CreateInstance(nullptr);
|
| PrinterSemanticCapsAndDefaults printer_info;
|
| @@ -301,14 +336,14 @@ void PrintingHandler::OnGetPrinterSemanticCapsAndDefaults(
|
|
|
| if (print_backend->GetPrinterSemanticCapsAndDefaults(printer_name,
|
| &printer_info)) {
|
| - Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded(
|
| - printer_name, printer_info));
|
| + callback.Run(printer_info);
|
| } else {
|
| - Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed(
|
| - printer_name));
|
| + callback.Run(base::nullopt);
|
| }
|
| ReleaseProcessIfNeeded();
|
| -}
|
| +#else
|
| + NOTREACHED();
|
| #endif // ENABLE_PRINT_PREVIEW
|
| +}
|
|
|
| } // namespace printing
|
|
|