OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_content_utility_client.h" | 5 #include "chrome/utility/chrome_content_utility_client.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 return false; | 163 return false; |
164 return get_pdf_doc_info_func_(pdf_buffer, buffer_size, page_count, | 164 return get_pdf_doc_info_func_(pdf_buffer, buffer_size, page_count, |
165 max_page_width); | 165 max_page_width); |
166 } | 166 } |
167 | 167 |
168 protected: | 168 protected: |
169 virtual bool PlatformInit( | 169 virtual bool PlatformInit( |
170 const base::FilePath& pdf_module_path, | 170 const base::FilePath& pdf_module_path, |
171 const base::ScopedNativeLibrary& pdf_lib) { | 171 const base::ScopedNativeLibrary& pdf_lib) { |
172 return true; | 172 return true; |
173 }; | 173 } |
174 | 174 |
175 private: | 175 private: |
176 // Exported by PDF plugin. | 176 // Exported by PDF plugin. |
177 typedef bool (*RenderPDFPageToBitmapProc)(const void* pdf_buffer, | 177 typedef bool (*RenderPDFPageToBitmapProc)(const void* pdf_buffer, |
178 int pdf_buffer_size, | 178 int pdf_buffer_size, |
179 int page_number, | 179 int page_number, |
180 void* bitmap_buffer, | 180 void* bitmap_buffer, |
181 int bitmap_width, | 181 int bitmap_width, |
182 int bitmap_height, | 182 int bitmap_height, |
183 int dpi_x, | 183 int dpi_x, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | 358 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
359 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) | 359 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) |
360 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackWebResource, | 360 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackWebResource, |
361 OnUnpackWebResource) | 361 OnUnpackWebResource) |
362 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, | 362 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, |
363 OnParseUpdateManifest) | 363 OnParseUpdateManifest) |
364 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) | 364 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) |
365 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) | 365 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) |
366 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, | 366 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, |
367 OnRenderPDFPagesToMetafile) | 367 OnRenderPDFPagesToMetafile) |
368 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFToMetafile, | |
369 OnRenderPDFToMetafile) | |
368 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToPWGRaster, | 370 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToPWGRaster, |
369 OnRenderPDFPagesToPWGRaster) | 371 OnRenderPDFPagesToPWGRaster) |
370 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, | 372 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, |
371 OnRobustJPEGDecodeImage) | 373 OnRobustJPEGDecodeImage) |
372 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) | 374 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) |
373 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, | 375 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, |
374 OnGetPrinterCapsAndDefaults) | 376 OnGetPrinterCapsAndDefaults) |
375 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults, | 377 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults, |
376 OnGetPrinterSemanticCapsAndDefaults) | 378 OnGetPrinterSemanticCapsAndDefaults) |
377 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, | 379 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
583 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Succeeded( | 585 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Succeeded( |
584 highest_rendered_page_number, scale_factor)); | 586 highest_rendered_page_number, scale_factor)); |
585 } | 587 } |
586 #endif // defined(OS_WIN) | 588 #endif // defined(OS_WIN) |
587 if (!succeeded) { | 589 if (!succeeded) { |
588 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed()); | 590 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed()); |
589 } | 591 } |
590 ReleaseProcessIfNeeded(); | 592 ReleaseProcessIfNeeded(); |
591 } | 593 } |
592 | 594 |
595 #if defined(OS_WIN) | |
596 void ChromeContentUtilityClient::OnRenderPDFToMetafile( | |
597 base::PlatformFile pdf_transit, | |
598 const base::FilePath& metafile_path, | |
599 const printing::PdfRenderSettings& settings) { | |
600 base::PlatformFile pdf_file = | |
601 IPC::PlatformFileForTransitToPlatformFile(pdf_transit); | |
602 bool succeeded = false; | |
603 int highest_rendered_page_number = -1; | |
604 double scale_factor = 1.0; | |
605 | |
606 if (!g_pdf_lib.Get().IsValid()) | |
607 return; | |
608 | |
609 DWORD length = ::GetFileSize(pdf_file, NULL); | |
610 if (length == INVALID_FILE_SIZE) | |
611 return; | |
612 | |
613 std::vector<uint8> buffer; | |
614 buffer.resize(length); | |
615 DWORD bytes_read = 0; | |
616 if (!ReadFile(pdf_file, &buffer.front(), length, &bytes_read, NULL) || | |
617 (bytes_read != length)) { | |
618 return; | |
619 } | |
620 | |
621 int total_page_count = 0; | |
622 if (!g_pdf_lib.Get().GetPDFDocInfo(&buffer.front(), buffer.size(), | |
623 &total_page_count, NULL)) { | |
624 return; | |
625 } | |
626 | |
627 for (int i = 0; i < total_page_count; ++i) { | |
628 printing::Emf metafile; | |
629 metafile.InitToFile( | |
630 metafile_path.InsertBeforeExtensionASCII(base::StringPrintf(".%d", i))); | |
631 scale_factor = gfx::CalculatePageScale( | |
632 metafile.context(), settings.area().right(), settings.area().bottom()); | |
633 gfx::ScaleDC(metafile.context(), scale_factor); | |
634 metafile.StartPage(gfx::Size(), gfx::Rect(), 1); | |
635 if (g_pdf_lib.Get().RenderPDFPageToDC( | |
636 &buffer.front(), buffer.size(), i, metafile.context(), | |
637 settings.dpi(), settings.dpi(), settings.area().x(), | |
638 settings.area().y(), settings.area().width(), | |
639 settings.area().height(), true, false, true, true, | |
640 settings.autorotate())) { | |
641 if (highest_rendered_page_number < i) | |
642 highest_rendered_page_number = i; | |
643 } | |
644 metafile.FinishPage(); | |
645 metafile.FinishDocument(); | |
646 } | |
647 | |
648 if (highest_rendered_page_number >= 0) { | |
649 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Succeeded( | |
650 highest_rendered_page_number, scale_factor)); | |
Vitaly Buka (NO REVIEWS)
2014/05/14 03:51:18
Actually with this approach we could send success
| |
651 } else { | |
652 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed()); | |
653 } | |
654 ReleaseProcessIfNeeded(); | |
655 } | |
656 #endif // defined(OS_WIN) | |
657 | |
593 void ChromeContentUtilityClient::OnRenderPDFPagesToPWGRaster( | 658 void ChromeContentUtilityClient::OnRenderPDFPagesToPWGRaster( |
594 IPC::PlatformFileForTransit pdf_transit, | 659 IPC::PlatformFileForTransit pdf_transit, |
595 const printing::PdfRenderSettings& settings, | 660 const printing::PdfRenderSettings& settings, |
596 const printing::PwgRasterSettings& bitmap_settings, | 661 const printing::PwgRasterSettings& bitmap_settings, |
597 IPC::PlatformFileForTransit bitmap_transit) { | 662 IPC::PlatformFileForTransit bitmap_transit) { |
598 base::PlatformFile pdf = | 663 base::PlatformFile pdf = |
599 IPC::PlatformFileForTransitToPlatformFile(pdf_transit); | 664 IPC::PlatformFileForTransitToPlatformFile(pdf_transit); |
600 base::PlatformFile bitmap = | 665 base::PlatformFile bitmap = |
601 IPC::PlatformFileForTransitToPlatformFile(bitmap_transit); | 666 IPC::PlatformFileForTransitToPlatformFile(bitmap_transit); |
602 if (RenderPDFPagesToPWGRaster(pdf, settings, bitmap_settings, bitmap)) { | 667 if (RenderPDFPagesToPWGRaster(pdf, settings, bitmap_settings, bitmap)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 return false; | 702 return false; |
638 } | 703 } |
639 | 704 |
640 int total_page_count = 0; | 705 int total_page_count = 0; |
641 if (!g_pdf_lib.Get().GetPDFDocInfo(&buffer.front(), buffer.size(), | 706 if (!g_pdf_lib.Get().GetPDFDocInfo(&buffer.front(), buffer.size(), |
642 &total_page_count, NULL)) { | 707 &total_page_count, NULL)) { |
643 return false; | 708 return false; |
644 } | 709 } |
645 | 710 |
646 printing::Emf metafile; | 711 printing::Emf metafile; |
647 metafile.InitToFile(metafile_path); | 712 metafile.InitToFile(metafile_path); |
Vitaly Buka (NO REVIEWS)
2014/05/13 23:54:33
maybe just update this function to use file per pa
scottmg
2014/05/14 00:34:48
At the moment, print_system_win.cc expects all pag
Vitaly Buka (NO REVIEWS)
2014/05/14 03:51:18
This sounds right.
You can fix this or just TODO
scottmg
2014/05/15 18:01:30
OK, I tried to merge the messages, cloud print and
| |
648 // We need to scale down DC to fit an entire page into DC available area. | 713 // We need to scale down DC to fit an entire page into DC available area. |
649 // Current metafile is based on screen DC and have current screen size. | 714 // Current metafile is based on screen DC and have current screen size. |
650 // Writing outside of those boundaries will result in the cut-off output. | 715 // Writing outside of those boundaries will result in the cut-off output. |
651 // On metafiles (this is the case here), scaling down will still record | 716 // On metafiles (this is the case here), scaling down will still record |
652 // original coordinates and we'll be able to print in full resolution. | 717 // original coordinates and we'll be able to print in full resolution. |
653 // Before playback we'll need to counter the scaling up that will happen | 718 // Before playback we'll need to counter the scaling up that will happen |
654 // in the service (print_system_win.cc). | 719 // in the service (print_system_win.cc). |
655 *scale_factor = gfx::CalculatePageScale(metafile.context(), | 720 *scale_factor = gfx::CalculatePageScale(metafile.context(), |
656 settings.area().right(), | 721 settings.area().right(), |
657 settings.area().bottom()); | 722 settings.area().bottom()); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1018 NetworkingPrivateCrypto crypto; | 1083 NetworkingPrivateCrypto crypto; |
1019 success = crypto.EncryptByteString(public_key, key_data, &ciphertext); | 1084 success = crypto.EncryptByteString(public_key, key_data, &ciphertext); |
1020 } | 1085 } |
1021 | 1086 |
1022 Send(new ChromeUtilityHostMsg_GotEncryptedWiFiCredentials(ciphertext, | 1087 Send(new ChromeUtilityHostMsg_GotEncryptedWiFiCredentials(ciphertext, |
1023 success)); | 1088 success)); |
1024 } | 1089 } |
1025 #endif // defined(OS_WIN) | 1090 #endif // defined(OS_WIN) |
1026 | 1091 |
1027 } // namespace chrome | 1092 } // namespace chrome |
OLD | NEW |