| 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 #include "chrome/utility/printing_handler.h" | 5 #include "chrome/utility/printing_handler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/common/chrome_utility_printing_messages.h" | 13 #include "chrome/common/chrome_utility_printing_messages.h" |
| 14 #include "chrome/utility/cloud_print/bitmap_image.h" | 14 #include "chrome/utility/cloud_print/bitmap_image.h" |
| 15 #include "chrome/utility/cloud_print/pwg_encoder.h" | 15 #include "chrome/utility/cloud_print/pwg_encoder.h" |
| 16 #include "content/public/utility/utility_thread.h" | 16 #include "content/public/utility/utility_thread.h" |
| 17 #include "pdf/pdf.h" | 17 #include "pdf/pdf.h" |
| 18 #include "printing/features/features.h" |
| 18 #include "printing/page_range.h" | 19 #include "printing/page_range.h" |
| 19 #include "printing/pdf_render_settings.h" | 20 #include "printing/pdf_render_settings.h" |
| 20 | 21 |
| 21 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 22 #include "printing/emf_win.h" | 23 #include "printing/emf_win.h" |
| 23 #include "ui/gfx/gdi_util.h" | 24 #include "ui/gfx/gdi_util.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 #if defined(ENABLE_PRINT_PREVIEW) | 27 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 27 #include "chrome/common/crash_keys.h" | 28 #include "chrome/common/crash_keys.h" |
| 28 #include "printing/backend/print_backend.h" | 29 #include "printing/backend/print_backend.h" |
| 29 #endif | 30 #endif |
| 30 | 31 |
| 31 namespace printing { | 32 namespace printing { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 bool Send(IPC::Message* message) { | 36 bool Send(IPC::Message* message) { |
| 36 return content::UtilityThread::Get()->Send(message); | 37 return content::UtilityThread::Get()->Send(message); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 63 bool handled = true; | 64 bool handled = true; |
| 64 IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message) | 65 IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message) |
| 65 #if defined(OS_WIN) | 66 #if defined(OS_WIN) |
| 66 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles, | 67 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles, |
| 67 OnRenderPDFPagesToMetafile) | 68 OnRenderPDFPagesToMetafile) |
| 68 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage, | 69 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage, |
| 69 OnRenderPDFPagesToMetafileGetPage) | 70 OnRenderPDFPagesToMetafileGetPage) |
| 70 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop, | 71 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop, |
| 71 OnRenderPDFPagesToMetafileStop) | 72 OnRenderPDFPagesToMetafileStop) |
| 72 #endif // OS_WIN | 73 #endif // OS_WIN |
| 73 #if defined(ENABLE_PRINT_PREVIEW) | 74 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 74 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToPWGRaster, | 75 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToPWGRaster, |
| 75 OnRenderPDFPagesToPWGRaster) | 76 OnRenderPDFPagesToPWGRaster) |
| 76 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, | 77 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, |
| 77 OnGetPrinterCapsAndDefaults) | 78 OnGetPrinterCapsAndDefaults) |
| 78 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults, | 79 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults, |
| 79 OnGetPrinterSemanticCapsAndDefaults) | 80 OnGetPrinterSemanticCapsAndDefaults) |
| 80 #endif // ENABLE_PRINT_PREVIEW | 81 #endif // ENABLE_PRINT_PREVIEW |
| 81 IPC_MESSAGE_UNHANDLED(handled = false) | 82 IPC_MESSAGE_UNHANDLED(handled = false) |
| 82 IPC_END_MESSAGE_MAP() | 83 IPC_END_MESSAGE_MAP() |
| 83 return handled; | 84 return handled; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 106 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone( | 107 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone( |
| 107 success, scale_factor)); | 108 success, scale_factor)); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void PrintingHandler::OnRenderPDFPagesToMetafileStop() { | 111 void PrintingHandler::OnRenderPDFPagesToMetafileStop() { |
| 111 ReleaseProcessIfNeeded(); | 112 ReleaseProcessIfNeeded(); |
| 112 } | 113 } |
| 113 | 114 |
| 114 #endif // OS_WIN | 115 #endif // OS_WIN |
| 115 | 116 |
| 116 #if defined(ENABLE_PRINT_PREVIEW) | 117 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 117 void PrintingHandler::OnRenderPDFPagesToPWGRaster( | 118 void PrintingHandler::OnRenderPDFPagesToPWGRaster( |
| 118 IPC::PlatformFileForTransit pdf_transit, | 119 IPC::PlatformFileForTransit pdf_transit, |
| 119 const PdfRenderSettings& settings, | 120 const PdfRenderSettings& settings, |
| 120 const PwgRasterSettings& bitmap_settings, | 121 const PwgRasterSettings& bitmap_settings, |
| 121 IPC::PlatformFileForTransit bitmap_transit) { | 122 IPC::PlatformFileForTransit bitmap_transit) { |
| 122 base::File pdf = IPC::PlatformFileForTransitToFile(pdf_transit); | 123 base::File pdf = IPC::PlatformFileForTransitToFile(pdf_transit); |
| 123 base::File bitmap = IPC::PlatformFileForTransitToFile(bitmap_transit); | 124 base::File bitmap = IPC::PlatformFileForTransitToFile(bitmap_transit); |
| 124 if (RenderPDFPagesToPWGRaster(std::move(pdf), settings, bitmap_settings, | 125 if (RenderPDFPagesToPWGRaster(std::move(pdf), settings, bitmap_settings, |
| 125 std::move(bitmap))) { | 126 std::move(bitmap))) { |
| 126 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Succeeded()); | 127 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Succeeded()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 pdf_rendering_settings_.autorotate())) { | 190 pdf_rendering_settings_.autorotate())) { |
| 190 return false; | 191 return false; |
| 191 } | 192 } |
| 192 metafile.FinishPage(); | 193 metafile.FinishPage(); |
| 193 metafile.FinishDocument(); | 194 metafile.FinishDocument(); |
| 194 return metafile.SaveTo(&output_file); | 195 return metafile.SaveTo(&output_file); |
| 195 } | 196 } |
| 196 | 197 |
| 197 #endif // OS_WIN | 198 #endif // OS_WIN |
| 198 | 199 |
| 199 #if defined(ENABLE_PRINT_PREVIEW) | 200 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 200 bool PrintingHandler::RenderPDFPagesToPWGRaster( | 201 bool PrintingHandler::RenderPDFPagesToPWGRaster( |
| 201 base::File pdf_file, | 202 base::File pdf_file, |
| 202 const PdfRenderSettings& settings, | 203 const PdfRenderSettings& settings, |
| 203 const PwgRasterSettings& bitmap_settings, | 204 const PwgRasterSettings& bitmap_settings, |
| 204 base::File bitmap_file) { | 205 base::File bitmap_file) { |
| 205 bool autoupdate = true; | 206 bool autoupdate = true; |
| 206 base::File::Info info; | 207 base::File::Info info; |
| 207 if (!pdf_file.GetInfo(&info) || info.size <= 0 || | 208 if (!pdf_file.GetInfo(&info) || info.size <= 0 || |
| 208 info.size > std::numeric_limits<int>::max()) | 209 info.size > std::numeric_limits<int>::max()) |
| 209 return false; | 210 return false; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 printer_name, printer_info)); | 320 printer_name, printer_info)); |
| 320 } else { | 321 } else { |
| 321 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed( | 322 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed( |
| 322 printer_name)); | 323 printer_name)); |
| 323 } | 324 } |
| 324 ReleaseProcessIfNeeded(); | 325 ReleaseProcessIfNeeded(); |
| 325 } | 326 } |
| 326 #endif // ENABLE_PRINT_PREVIEW | 327 #endif // ENABLE_PRINT_PREVIEW |
| 327 | 328 |
| 328 } // namespace printing | 329 } // namespace printing |
| OLD | NEW |