Rename PrintHandler to PrintHandlerWin since only used on Windows.

This commit is contained in:
Haojian Wu 2015-05-11 20:57:07 +08:00
parent abd97a7513
commit 5ede62459c
4 changed files with 29 additions and 46 deletions

View file

@ -17,7 +17,7 @@
#if defined(OS_WIN)
#include "chrome/utility/printing_handler.h"
#include "chrome/utility/printing_handler_win.h"
#endif
@ -37,7 +37,7 @@ int64_t AtomContentUtilityClient::max_ipc_message_size_ =
AtomContentUtilityClient::AtomContentUtilityClient()
: filter_messages_(false) {
#if defined(OS_WIN)
handlers_.push_back(new PrintingHandler());
handlers_.push_back(new PrintingHandlerWin());
#endif
}
@ -73,7 +73,9 @@ void AtomContentUtilityClient::OnStartupPing() {
// static
void AtomContentUtilityClient::PreSandboxStartup() {
PrintingHandler::PreSandboxStartup();
#if defined(OS_WIN)
PrintingHandlerWin::PreSandboxStartup();
#endif
}
} // namespace atom

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/utility/printing_handler.h"
#include "chrome/utility/printing_handler_win.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
@ -10,14 +10,10 @@
#include "base/scoped_native_library.h"
#include "chrome/common/print_messages.h"
#include "content/public/utility/utility_thread.h"
#include "printing/emf_win.h"
#include "printing/page_range.h"
#include "printing/pdf_render_settings.h"
#if defined(OS_WIN)
#include "printing/emf_win.h"
#include "ui/gfx/gdi_util.h"
#endif
namespace {
@ -125,33 +121,30 @@ base::LazyInstance<PdfFunctions> g_pdf_lib = LAZY_INSTANCE_INITIALIZER;
} // namespace
PrintingHandler::PrintingHandler() {}
PrintingHandlerWin::PrintingHandlerWin() {}
PrintingHandler::~PrintingHandler() {}
PrintingHandlerWin::~PrintingHandlerWin() {}
// static
void PrintingHandler::PreSandboxStartup() {
void PrintingHandlerWin::PreSandboxStartup() {
g_pdf_lib.Get().Init();
}
bool PrintingHandler::OnMessageReceived(const IPC::Message& message) {
bool PrintingHandlerWin::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message)
#if defined(OS_WIN)
IPC_BEGIN_MESSAGE_MAP(PrintingHandlerWin, message)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles,
OnRenderPDFPagesToMetafile)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage,
OnRenderPDFPagesToMetafileGetPage)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop,
OnRenderPDFPagesToMetafileStop)
#endif // OS_WIN
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
#if defined(OS_WIN)
void PrintingHandler::OnRenderPDFPagesToMetafile(
void PrintingHandlerWin::OnRenderPDFPagesToMetafile(
IPC::PlatformFileForTransit pdf_transit,
const printing::PdfRenderSettings& settings) {
pdf_rendering_settings_ = settings;
@ -162,7 +155,7 @@ void PrintingHandler::OnRenderPDFPagesToMetafile(
new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount(page_count));
}
void PrintingHandler::OnRenderPDFPagesToMetafileGetPage(
void PrintingHandlerWin::OnRenderPDFPagesToMetafileGetPage(
int page_number,
IPC::PlatformFileForTransit output_file) {
base::File emf_file = IPC::PlatformFileForTransitToFile(output_file);
@ -173,11 +166,11 @@ void PrintingHandler::OnRenderPDFPagesToMetafileGetPage(
success, scale_factor));
}
void PrintingHandler::OnRenderPDFPagesToMetafileStop() {
void PrintingHandlerWin::OnRenderPDFPagesToMetafileStop() {
ReleaseProcessIfNeeded();
}
int PrintingHandler::LoadPDF(base::File pdf_file) {
int PrintingHandlerWin::LoadPDF(base::File pdf_file) {
if (!g_pdf_lib.Get().IsValid())
return 0;
@ -198,9 +191,9 @@ int PrintingHandler::LoadPDF(base::File pdf_file) {
return total_page_count;
}
bool PrintingHandler::RenderPdfPageToMetafile(int page_number,
base::File output_file,
float* scale_factor) {
bool PrintingHandlerWin::RenderPdfPageToMetafile(int page_number,
base::File output_file,
float* scale_factor) {
printing::Emf metafile;
metafile.Init();
@ -241,5 +234,3 @@ bool PrintingHandler::RenderPdfPageToMetafile(int page_number,
metafile.FinishDocument();
return metafile.SaveTo(&output_file);
}
#endif // OS_WIN

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_UTILITY_PRINTING_HANDLER_H_
#define CHROME_UTILITY_PRINTING_HANDLER_H_
#ifndef CHROME_UTILITY_PRINTING_HANDLER_WIN_H_
#define CHROME_UTILITY_PRINTING_HANDLER_WIN_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
@ -11,10 +11,6 @@
#include "ipc/ipc_platform_file.h"
#include "printing/pdf_render_settings.h"
#if !defined(ENABLE_PRINT_PREVIEW) && !defined(OS_WIN)
#error "Windows or full printing must be enabled"
#endif
namespace printing {
class PdfRenderSettings;
struct PwgRasterSettings;
@ -22,40 +18,34 @@ struct PageRange;
}
// Dispatches IPCs for printing.
class PrintingHandler : public UtilityMessageHandler {
class PrintingHandlerWin : public UtilityMessageHandler {
public:
PrintingHandler();
~PrintingHandler() override;
PrintingHandlerWin();
~PrintingHandlerWin() override;
// IPC::Listener:
bool OnMessageReceived(const IPC::Message& message) override;
static void PrintingHandler::PreSandboxStartup();
static void PrintingHandlerWin::PreSandboxStartup();
private:
// IPC message handlers.
#if defined(OS_WIN)
void OnRenderPDFPagesToMetafile(IPC::PlatformFileForTransit pdf_transit,
const printing::PdfRenderSettings& settings);
void OnRenderPDFPagesToMetafileGetPage(
int page_number,
IPC::PlatformFileForTransit output_file);
void OnRenderPDFPagesToMetafileStop();
#endif // OS_WIN
#if defined(OS_WIN)
int LoadPDF(base::File pdf_file);
bool RenderPdfPageToMetafile(int page_number,
base::File output_file,
float* scale_factor);
#endif // OS_WIN
#if defined(OS_WIN)
std::vector<char> pdf_data_;
printing::PdfRenderSettings pdf_rendering_settings_;
#endif
DISALLOW_COPY_AND_ASSIGN(PrintingHandler);
DISALLOW_COPY_AND_ASSIGN(PrintingHandlerWin);
};
#endif // CHROME_UTILITY_PRINTING_HANDLER_H_
#endif // CHROME_UTILITY_PRINTING_HANDLER_WIN_H_

View file

@ -381,8 +381,8 @@
'chromium_src/chrome/browser/ui/views/color_chooser_win.cc',
'chromium_src/chrome/browser/printing/pdf_to_emf_converter.cc',
'chromium_src/chrome/browser/printing/pdf_to_emf_converter.h',
'chromium_src/chrome/utility/printing_handler.cc',
'chromium_src/chrome/utility/printing_handler.h',
'chromium_src/chrome/utility/printing_handler_win.cc',
'chromium_src/chrome/utility/printing_handler_win.h',
],
'framework_sources': [
'atom/app/atom_library_main.h',