| Index: chrome/browser/printing/pdf_to_emf_converter.cc
|
| diff --git a/chrome/browser/printing/pdf_to_emf_converter.cc b/chrome/browser/printing/pdf_to_emf_converter.cc
|
| index 72671c0feeef1b0a939de7b2f3650e2bb320c913..bf73cb05a1252da73c05a7b6ab4cc9f7116f6522 100644
|
| --- a/chrome/browser/printing/pdf_to_emf_converter.cc
|
| +++ b/chrome/browser/printing/pdf_to_emf_converter.cc
|
| @@ -91,6 +91,20 @@ class LazyEmf : public MetafilePlayer {
|
| DISALLOW_COPY_AND_ASSIGN(LazyEmf);
|
| };
|
|
|
| +// Postscript metafile subclass to override SafePlayback.
|
| +class PostScriptMetaFile : public LazyEmf {
|
| + public:
|
| + PostScriptMetaFile(const scoped_refptr<RefCountedTempDir>& temp_dir,
|
| + ScopedTempFile file)
|
| + : LazyEmf(temp_dir, std::move(file)) {}
|
| +
|
| + protected:
|
| + // MetafilePlayer:
|
| + bool SafePlayback(HDC hdc) const override;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(PostScriptMetaFile);
|
| +};
|
| +
|
| // Class for converting PDF to another format for printing (Emf, Postscript).
|
| // Class uses 3 threads: UI, IO and FILE.
|
| // Internal workflow is following:
|
| @@ -158,20 +172,19 @@ class PdfConverterUtilityProcessHostClient
|
| DISALLOW_COPY_AND_ASSIGN(GetPageCallbackData);
|
| };
|
|
|
| - ~PdfConverterUtilityProcessHostClient() override;
|
| + bool OnMessageReceived(const IPC::Message& message) override;
|
|
|
| // Helper functions: must be overridden by subclasses
|
| // Set the process name
|
| - virtual base::string16 GetName() const = 0;
|
| + base::string16 GetName() const;
|
| // Create a metafileplayer subclass file from a temporary file.
|
| - virtual std::unique_ptr<MetafilePlayer> GetFileFromTemp(
|
| + std::unique_ptr<MetafilePlayer> GetFileFromTemp(
|
| std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
|
| - temp_file) = 0;
|
| + temp_file);
|
| // Send the messages to Start, GetPage, and Stop.
|
| - virtual void SendStartMessage(IPC::PlatformFileForTransit transit) = 0;
|
| - virtual void SendGetPageMessage(int page_number,
|
| - IPC::PlatformFileForTransit transit) = 0;
|
| - virtual void SendStopMessage() = 0;
|
| + void SendStartMessage(IPC::PlatformFileForTransit transit);
|
| + void SendGetPageMessage(int page_number, IPC::PlatformFileForTransit transit);
|
| + void SendStopMessage();
|
|
|
| // Message handlers:
|
| void OnPageCount(int page_count);
|
| @@ -182,6 +195,10 @@ class PdfConverterUtilityProcessHostClient
|
| void OnTempFileReady(GetPageCallbackData* callback_data,
|
| ScopedTempFile temp_file);
|
|
|
| + // Additional message handler needed for Pdf to Emf
|
| + void OnPreCacheFontCharacters(const LOGFONT& log_font,
|
| + const base::string16& characters);
|
| +
|
| scoped_refptr<RefCountedTempDir> temp_dir_;
|
|
|
| // Used to suppress callbacks after PdfConverter is deleted.
|
| @@ -199,65 +216,21 @@ class PdfConverterUtilityProcessHostClient
|
| // Use containers that keeps element pointers valid after push() and pop().
|
| using GetPageCallbacks = std::queue<GetPageCallbackData>;
|
| GetPageCallbacks get_page_callbacks_;
|
| -};
|
| -
|
| -// Converts PDF into Emf.
|
| -class PdfToEmfUtilityProcessHostClient
|
| - : public PdfConverterUtilityProcessHostClient {
|
| - public:
|
| - PdfToEmfUtilityProcessHostClient(base::WeakPtr<PdfConverterImpl> converter,
|
| - const PdfRenderSettings& settings)
|
| - : PdfConverterUtilityProcessHostClient(converter, settings) {}
|
| -
|
| - bool OnMessageReceived(const IPC::Message& message) override;
|
| -
|
| - private:
|
| - ~PdfToEmfUtilityProcessHostClient() override;
|
| - // Helpers to send messages and set process name
|
| - base::string16 GetName() const override;
|
| - std::unique_ptr<MetafilePlayer> GetFileFromTemp(
|
| - std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
|
| - temp_file) override;
|
| - void SendStartMessage(IPC::PlatformFileForTransit transit) override;
|
| - void SendGetPageMessage(int page_number,
|
| - IPC::PlatformFileForTransit transit) override;
|
| - void SendStopMessage() override;
|
|
|
| - // Additional message handler needed for Pdf to Emf
|
| - void OnPreCacheFontCharacters(const LOGFONT& log_font,
|
| - const base::string16& characters);
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(PdfToEmfUtilityProcessHostClient);
|
| + DISALLOW_COPY_AND_ASSIGN(PdfConverterUtilityProcessHostClient);
|
| };
|
|
|
| -// Converts PDF into PostScript.
|
| -class PdfToPostScriptUtilityProcessHostClient
|
| - : public PdfConverterUtilityProcessHostClient {
|
| - public:
|
| - PdfToPostScriptUtilityProcessHostClient(
|
| - base::WeakPtr<PdfConverterImpl> converter,
|
| - const PdfRenderSettings& settings)
|
| - : PdfConverterUtilityProcessHostClient(converter, settings) {}
|
| -
|
| - // UtilityProcessHostClient implementation.
|
| - bool OnMessageReceived(const IPC::Message& message) override;
|
| -
|
| - private:
|
| - // Helpers to send messages and set process name
|
| - base::string16 GetName() const override;
|
| - std::unique_ptr<MetafilePlayer> GetFileFromTemp(
|
| - std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
|
| - temp_file) override;
|
| - void SendStartMessage(IPC::PlatformFileForTransit transit) override;
|
| - void SendGetPageMessage(int page_number,
|
| - IPC::PlatformFileForTransit transit) override;
|
| - void SendStopMessage() override;
|
| -
|
| - // Additional message handler needed for Pdf to PostScript
|
| - void OnPageDone(bool success);
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(PdfToPostScriptUtilityProcessHostClient);
|
| -};
|
| +std::unique_ptr<MetafilePlayer>
|
| +PdfConverterUtilityProcessHostClient::GetFileFromTemp(
|
| + std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
|
| + temp_file) {
|
| + if (settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 ||
|
| + settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3) {
|
| + return base::MakeUnique<PostScriptMetaFile>(temp_dir_,
|
| + std::move(temp_file));
|
| + }
|
| + return base::MakeUnique<LazyEmf>(temp_dir_, std::move(temp_file));
|
| +}
|
|
|
| class PdfConverterImpl : public PdfConverter {
|
| public:
|
| @@ -368,23 +341,6 @@ bool LazyEmf::LoadEmf(Emf* emf) const {
|
| return emf->InitFromData(data.data(), data.size());
|
| }
|
|
|
| -// Postscript metafile subclass to override SafePlayback.
|
| -class PostScriptMetaFile : public LazyEmf {
|
| - public:
|
| - PostScriptMetaFile(const scoped_refptr<RefCountedTempDir>& temp_dir,
|
| - ScopedTempFile file)
|
| - : LazyEmf(temp_dir, std::move(file)) {}
|
| - ~PostScriptMetaFile() override;
|
| -
|
| - protected:
|
| - // MetafilePlayer:
|
| - bool SafePlayback(HDC hdc) const override;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(PostScriptMetaFile);
|
| -};
|
| -
|
| -PostScriptMetaFile::~PostScriptMetaFile() {}
|
| -
|
| bool PostScriptMetaFile::SafePlayback(HDC hdc) const {
|
| // TODO(thestig): Fix destruction of metafiles. For some reasons
|
| // instances of Emf are not deleted. https://crbug.com/260806
|
| @@ -421,8 +377,6 @@ PdfConverterUtilityProcessHostClient::PdfConverterUtilityProcessHostClient(
|
| const PdfRenderSettings& settings)
|
| : converter_(converter), settings_(settings) {}
|
|
|
| -PdfConverterUtilityProcessHostClient::~PdfConverterUtilityProcessHostClient() {}
|
| -
|
| void PdfConverterUtilityProcessHostClient::Start(
|
| const scoped_refptr<base::RefCountedMemory>& data,
|
| const PdfConverter::StartCallback& start_callback) {
|
| @@ -564,10 +518,7 @@ void PdfConverterUtilityProcessHostClient::OnFailed() {
|
| utility_process_host_.reset();
|
| }
|
|
|
| -// PDF to Emf
|
| -PdfToEmfUtilityProcessHostClient::~PdfToEmfUtilityProcessHostClient() {}
|
| -
|
| -void PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters(
|
| +void PdfConverterUtilityProcessHostClient::OnPreCacheFontCharacters(
|
| const LOGFONT& font,
|
| const base::string16& str) {
|
| // TODO(scottmg): pdf/ppapi still require the renderer to be able to precache
|
| @@ -599,10 +550,10 @@ void PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters(
|
| DeleteEnhMetaFile(metafile);
|
| }
|
|
|
| -bool PdfToEmfUtilityProcessHostClient::OnMessageReceived(
|
| +bool PdfConverterUtilityProcessHostClient::OnMessageReceived(
|
| const IPC::Message& message) {
|
| bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(PdfToEmfUtilityProcessHostClient, message)
|
| + IPC_BEGIN_MESSAGE_MAP(PdfConverterUtilityProcessHostClient, message)
|
| IPC_MESSAGE_HANDLER(
|
| ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, OnPageCount)
|
| IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone,
|
| @@ -614,84 +565,30 @@ bool PdfToEmfUtilityProcessHostClient::OnMessageReceived(
|
| return handled;
|
| }
|
|
|
| -base::string16 PdfToEmfUtilityProcessHostClient::GetName() const {
|
| - return l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_EMF_CONVERTOR_NAME);
|
| -}
|
| -
|
| -std::unique_ptr<MetafilePlayer>
|
| -PdfToEmfUtilityProcessHostClient::GetFileFromTemp(
|
| - std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
|
| - temp_file) {
|
| - return base::MakeUnique<LazyEmf>(temp_dir_, std::move(temp_file));
|
| +base::string16 PdfConverterUtilityProcessHostClient::GetName() const {
|
| + return l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PDF_CONVERTOR_NAME);
|
| }
|
|
|
| -void PdfToEmfUtilityProcessHostClient::SendGetPageMessage(
|
| +void PdfConverterUtilityProcessHostClient::SendGetPageMessage(
|
| int page_number,
|
| IPC::PlatformFileForTransit transit) {
|
| Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage(page_number,
|
| transit));
|
| }
|
|
|
| -void PdfToEmfUtilityProcessHostClient::SendStartMessage(
|
| +void PdfConverterUtilityProcessHostClient::SendStartMessage(
|
| IPC::PlatformFileForTransit transit) {
|
| Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles(transit, settings_));
|
| }
|
|
|
| -void PdfToEmfUtilityProcessHostClient::SendStopMessage() {
|
| +void PdfConverterUtilityProcessHostClient::SendStopMessage() {
|
| Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop());
|
| }
|
|
|
| -// Pdf to PostScript
|
| -bool PdfToPostScriptUtilityProcessHostClient::OnMessageReceived(
|
| - const IPC::Message& message) {
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(PdfToPostScriptUtilityProcessHostClient, message)
|
| - IPC_MESSAGE_HANDLER(
|
| - ChromeUtilityHostMsg_RenderPDFPagesToPostScript_PageCount, OnPageCount)
|
| - IPC_MESSAGE_HANDLER(
|
| - ChromeUtilityHostMsg_RenderPDFPagesToPostScript_PageDone, OnPageDone)
|
| - IPC_MESSAGE_UNHANDLED(handled = false)
|
| - IPC_END_MESSAGE_MAP()
|
| - return handled;
|
| -}
|
| -
|
| -base::string16 PdfToPostScriptUtilityProcessHostClient::GetName() const {
|
| - return l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PS_CONVERTOR_NAME);
|
| -}
|
| -
|
| -std::unique_ptr<MetafilePlayer>
|
| -PdfToPostScriptUtilityProcessHostClient::GetFileFromTemp(
|
| - std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
|
| - temp_file) {
|
| - return base::MakeUnique<PostScriptMetaFile>(temp_dir_, std::move(temp_file));
|
| -}
|
| -
|
| -void PdfToPostScriptUtilityProcessHostClient::SendGetPageMessage(
|
| - int page_number,
|
| - IPC::PlatformFileForTransit transit) {
|
| - Send(new ChromeUtilityMsg_RenderPDFPagesToPostScript_GetPage(page_number,
|
| - transit));
|
| -}
|
| -
|
| -void PdfToPostScriptUtilityProcessHostClient::SendStartMessage(
|
| - IPC::PlatformFileForTransit transit) {
|
| - Send(new ChromeUtilityMsg_RenderPDFPagesToPostScript_Start(transit,
|
| - settings_));
|
| -}
|
| -
|
| -void PdfToPostScriptUtilityProcessHostClient::SendStopMessage() {
|
| - Send(new ChromeUtilityMsg_RenderPDFPagesToPostScript_Stop());
|
| -}
|
| -
|
| -void PdfToPostScriptUtilityProcessHostClient::OnPageDone(bool success) {
|
| - PdfConverterUtilityProcessHostClient::OnPageDone(success, 0.0f);
|
| -}
|
| -
|
| void PdfConverterImpl::GetPage(int page_number,
|
| const GetPageCallback& get_page_callback) {
|
| utility_client_->GetPage(page_number, get_page_callback);
|
| }
|
| -
|
| void PdfConverterImpl::RunCallback(const base::Closure& callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| callback.Run();
|
| @@ -702,26 +599,13 @@ void PdfConverterImpl::RunCallback(const base::Closure& callback) {
|
| PdfConverter::~PdfConverter() {}
|
|
|
| // static
|
| -std::unique_ptr<PdfConverter> PdfConverter::StartPdfToEmfConverter(
|
| - const scoped_refptr<base::RefCountedMemory>& data,
|
| - const PdfRenderSettings& conversion_settings,
|
| - const StartCallback& start_callback) {
|
| - std::unique_ptr<PdfConverterImpl> converter =
|
| - base::MakeUnique<PdfConverterImpl>();
|
| - converter->Start(new PdfToEmfUtilityProcessHostClient(converter->GetWeakPtr(),
|
| - conversion_settings),
|
| - data, start_callback);
|
| - return std::move(converter);
|
| -}
|
| -
|
| -// static
|
| -std::unique_ptr<PdfConverter> PdfConverter::StartPdfToPostScriptConverter(
|
| +std::unique_ptr<PdfConverter> PdfConverter::StartConverter(
|
| const scoped_refptr<base::RefCountedMemory>& data,
|
| const PdfRenderSettings& conversion_settings,
|
| const StartCallback& start_callback) {
|
| std::unique_ptr<PdfConverterImpl> converter =
|
| base::MakeUnique<PdfConverterImpl>();
|
| - converter->Start(new PdfToPostScriptUtilityProcessHostClient(
|
| + converter->Start(new PdfConverterUtilityProcessHostClient(
|
| converter->GetWeakPtr(), conversion_settings),
|
| data, start_callback);
|
| return std::move(converter);
|
|
|