OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_UTILITY_PRINTING_HANDLER_H_ | 5 #ifndef CHROME_UTILITY_PRINTING_HANDLER_H_ |
6 #define CHROME_UTILITY_PRINTING_HANDLER_H_ | 6 #define CHROME_UTILITY_PRINTING_HANDLER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/utility/utility_message_handler.h" | 11 #include "chrome/utility/utility_message_handler.h" |
| 12 #include "components/printing/common/printing.mojom.h" |
12 #include "ipc/ipc_platform_file.h" | 13 #include "ipc/ipc_platform_file.h" |
| 14 #include "mojo/public/cpp/bindings/interface_request.h" |
13 #include "printing/features/features.h" | 15 #include "printing/features/features.h" |
14 #include "printing/pdf_render_settings.h" | 16 #include "printing/pdf_render_settings.h" |
15 | 17 |
16 #if !BUILDFLAG(ENABLE_PRINT_PREVIEW) && \ | 18 #if !BUILDFLAG(ENABLE_PRINT_PREVIEW) && \ |
17 !(BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) | 19 !(BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) |
18 #error "Windows basic printing or print preview must be enabled" | 20 #error "Windows basic printing or print preview must be enabled" |
19 #endif | 21 #endif |
20 | 22 |
21 namespace printing { | 23 namespace printing { |
22 | 24 |
23 struct PwgRasterSettings; | 25 struct PwgRasterSettings; |
24 | 26 |
25 // Dispatches IPCs for printing. | 27 // Dispatches IPCs for printing. |
26 class PrintingHandler : public UtilityMessageHandler { | 28 class PrintingHandler : public UtilityMessageHandler, public mojom::Printing { |
27 public: | 29 public: |
28 PrintingHandler(); | 30 explicit PrintingHandler(mojom::FontPreCachingPtr font_pre_caching); |
29 ~PrintingHandler() override; | 31 ~PrintingHandler() override; |
30 | 32 |
| 33 static void Create(mojom::PrintingFactoryRequest request); |
| 34 |
31 // IPC::Listener: | 35 // IPC::Listener: |
32 bool OnMessageReceived(const IPC::Message& message) override; | 36 bool OnMessageReceived(const IPC::Message& message) override; |
33 | 37 |
34 private: | 38 private: |
35 // IPC message handlers. | 39 class PrintingHandlerFactory : public mojom::PrintingFactory { |
36 #if defined(OS_WIN) | 40 public: |
37 void OnRenderPDFPagesToMetafile(IPC::PlatformFileForTransit pdf_transit, | 41 // mojom::PrintingFactory: |
38 const PdfRenderSettings& settings, | 42 void MakePrinting(mojom::PrintingRequest request, |
39 bool print_text_with_gdi); | 43 mojom::FontPreCachingPtr font_pre_caching) override; |
40 void OnRenderPDFPagesToMetafileGetPage( | 44 }; |
| 45 |
| 46 // mojom::Printing: |
| 47 void RenderPDFPagesToMetafiles( |
| 48 base::File pdf_file, |
| 49 const PdfRenderSettings& settings, |
| 50 bool print_text_with_gdi, |
| 51 const RenderPDFPagesToMetafilesCallback& callback) override; |
| 52 void RenderPDFPagesToMetafilesGetPage( |
41 int page_number, | 53 int page_number, |
42 IPC::PlatformFileForTransit output_file); | 54 base::File emf_file, |
43 void OnRenderPDFPagesToMetafileStop(); | 55 const RenderPDFPagesToMetafilesGetPageCallback& callback) override; |
44 #endif // OS_WIN | 56 void RenderPDFPagesToPWGRaster( |
45 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 57 base::File pdf, |
46 void OnRenderPDFPagesToPWGRaster(IPC::PlatformFileForTransit pdf_transit, | 58 const PdfRenderSettings& settings, |
47 const PdfRenderSettings& settings, | 59 const PwgRasterSettings& bitmap_settings, |
48 const PwgRasterSettings& bitmap_settings, | 60 base::File bitmap, |
49 IPC::PlatformFileForTransit bitmap_transit); | 61 const RenderPDFPagesToPWGRasterCallback& callback) override; |
50 #endif // ENABLE_PRINT_PREVIEW | 62 |
| 63 // Called when the Mojo connection is closed. Causes the utility process to |
| 64 // stop conversion and exit. |
| 65 void OnConnectionClosed(); |
51 | 66 |
52 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
53 int LoadPDF(base::File pdf_file); | 68 int LoadPDF(base::File pdf_file); |
54 bool RenderPdfPageToMetafile(int page_number, | 69 bool RenderPdfPageToMetafile(int page_number, |
55 base::File output_file, | 70 base::File output_file, |
56 float* scale_factor); | 71 float* scale_factor); |
57 #endif // OS_WIN | 72 #endif // OS_WIN |
58 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 73 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
59 bool RenderPDFPagesToPWGRaster(base::File pdf_file, | 74 bool RenderPDFPagesToPWGRaster(base::File pdf_file, |
60 const PdfRenderSettings& settings, | 75 const PdfRenderSettings& settings, |
61 const PwgRasterSettings& bitmap_settings, | 76 const PwgRasterSettings& bitmap_settings, |
62 base::File bitmap_file); | 77 base::File bitmap_file); |
| 78 #endif // ENABLE_PRINT_PREVIEW |
63 | 79 |
64 void OnGetPrinterCapsAndDefaults(const std::string& printer_name); | 80 // mojom::Printing: |
65 void OnGetPrinterSemanticCapsAndDefaults(const std::string& printer_name); | 81 void GetPrinterCapsAndDefaults( |
66 #endif // ENABLE_PRINT_PREVIEW | 82 const std::string& printer_name, |
| 83 const GetPrinterCapsAndDefaultsCallback& callback) override; |
| 84 void GetPrinterSemanticCapsAndDefaults( |
| 85 const std::string& printer_name, |
| 86 const GetPrinterSemanticCapsAndDefaultsCallback& callback) override; |
67 | 87 |
68 #if defined(OS_WIN) | 88 #if defined(OS_WIN) |
69 std::vector<char> pdf_data_; | 89 std::vector<char> pdf_data_; |
70 PdfRenderSettings pdf_rendering_settings_; | 90 PdfRenderSettings pdf_rendering_settings_; |
71 #endif | 91 #endif |
72 | 92 |
| 93 mojom::FontPreCachingPtr font_pre_caching_; |
| 94 |
73 DISALLOW_COPY_AND_ASSIGN(PrintingHandler); | 95 DISALLOW_COPY_AND_ASSIGN(PrintingHandler); |
74 }; | 96 }; |
75 | 97 |
76 } // namespace printing | 98 } // namespace printing |
77 | 99 |
78 #endif // CHROME_UTILITY_PRINTING_HANDLER_H_ | 100 #endif // CHROME_UTILITY_PRINTING_HANDLER_H_ |
OLD | NEW |