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 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 #endif // defined(OS_WIN) | 574 #endif // defined(OS_WIN) |
575 if (!succeeded) { | 575 if (!succeeded) { |
576 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed()); | 576 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed()); |
577 } | 577 } |
578 ReleaseProcessIfNeeded(); | 578 ReleaseProcessIfNeeded(); |
579 } | 579 } |
580 | 580 |
581 void ChromeContentUtilityClient::OnRenderPDFPagesToPWGRaster( | 581 void ChromeContentUtilityClient::OnRenderPDFPagesToPWGRaster( |
582 IPC::PlatformFileForTransit pdf_transit, | 582 IPC::PlatformFileForTransit pdf_transit, |
583 const printing::PdfRenderSettings& settings, | 583 const printing::PdfRenderSettings& settings, |
| 584 const printing::PwgRasterSettings& bitmap_settings, |
584 IPC::PlatformFileForTransit bitmap_transit) { | 585 IPC::PlatformFileForTransit bitmap_transit) { |
585 base::PlatformFile pdf = | 586 base::PlatformFile pdf = |
586 IPC::PlatformFileForTransitToPlatformFile(pdf_transit); | 587 IPC::PlatformFileForTransitToPlatformFile(pdf_transit); |
587 base::PlatformFile bitmap = | 588 base::PlatformFile bitmap = |
588 IPC::PlatformFileForTransitToPlatformFile(bitmap_transit); | 589 IPC::PlatformFileForTransitToPlatformFile(bitmap_transit); |
589 if (RenderPDFPagesToPWGRaster(pdf, settings, bitmap)) { | 590 if (RenderPDFPagesToPWGRaster(pdf, settings, bitmap_settings, bitmap)) { |
590 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Succeeded()); | 591 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Succeeded()); |
591 } else { | 592 } else { |
592 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Failed()); | 593 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Failed()); |
593 } | 594 } |
594 ReleaseProcessIfNeeded(); | 595 ReleaseProcessIfNeeded(); |
595 } | 596 } |
596 | 597 |
597 #if defined(OS_WIN) | 598 #if defined(OS_WIN) |
598 bool ChromeContentUtilityClient::RenderPDFToWinMetafile( | 599 bool ChromeContentUtilityClient::RenderPDFToWinMetafile( |
599 base::PlatformFile pdf_file, | 600 base::PlatformFile pdf_file, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 } | 668 } |
668 } | 669 } |
669 metafile.FinishDocument(); | 670 metafile.FinishDocument(); |
670 return ret; | 671 return ret; |
671 } | 672 } |
672 #endif // defined(OS_WIN) | 673 #endif // defined(OS_WIN) |
673 | 674 |
674 bool ChromeContentUtilityClient::RenderPDFPagesToPWGRaster( | 675 bool ChromeContentUtilityClient::RenderPDFPagesToPWGRaster( |
675 base::PlatformFile pdf_file, | 676 base::PlatformFile pdf_file, |
676 const printing::PdfRenderSettings& settings, | 677 const printing::PdfRenderSettings& settings, |
| 678 const printing::PwgRasterSettings& bitmap_settings, |
677 base::PlatformFile bitmap_file) { | 679 base::PlatformFile bitmap_file) { |
678 bool autoupdate = true; | 680 bool autoupdate = true; |
679 if (!g_pdf_lib.Get().IsValid()) | 681 if (!g_pdf_lib.Get().IsValid()) |
680 return false; | 682 return false; |
681 | 683 |
682 base::PlatformFileInfo info; | 684 base::PlatformFileInfo info; |
683 if (!base::GetPlatformFileInfo(pdf_file, &info) || info.size <= 0) | 685 if (!base::GetPlatformFileInfo(pdf_file, &info) || info.size <= 0) |
684 return false; | 686 return false; |
685 | 687 |
686 std::string data(info.size, 0); | 688 std::string data(info.size, 0); |
(...skipping 12 matching lines...) Expand all Loading... |
699 encoder.EncodeDocumentHeader(&pwg_header); | 701 encoder.EncodeDocumentHeader(&pwg_header); |
700 int bytes_written = base::WritePlatformFileAtCurrentPos(bitmap_file, | 702 int bytes_written = base::WritePlatformFileAtCurrentPos(bitmap_file, |
701 pwg_header.data(), | 703 pwg_header.data(), |
702 pwg_header.size()); | 704 pwg_header.size()); |
703 if (bytes_written != static_cast<int>(pwg_header.size())) | 705 if (bytes_written != static_cast<int>(pwg_header.size())) |
704 return false; | 706 return false; |
705 | 707 |
706 cloud_print::BitmapImage image(settings.area().size(), | 708 cloud_print::BitmapImage image(settings.area().size(), |
707 cloud_print::BitmapImage::BGRA); | 709 cloud_print::BitmapImage::BGRA); |
708 for (int i = 0; i < total_page_count; ++i) { | 710 for (int i = 0; i < total_page_count; ++i) { |
709 if (!g_pdf_lib.Get().RenderPDFPageToBitmap( | 711 int page_number = i; |
710 data.data(), data.size(), i, image.pixel_data(), | 712 |
711 image.size().width(), image.size().height(), settings.dpi(), | 713 if (bitmap_settings.reverse_page_order) { |
712 settings.dpi(), autoupdate)) { | 714 page_number = total_page_count - 1 - page_number; |
| 715 } |
| 716 |
| 717 if (!g_pdf_lib.Get().RenderPDFPageToBitmap(data.data(), |
| 718 data.size(), |
| 719 page_number, |
| 720 image.pixel_data(), |
| 721 image.size().width(), |
| 722 image.size().height(), |
| 723 settings.dpi(), |
| 724 settings.dpi(), |
| 725 autoupdate)) { |
713 return false; | 726 return false; |
714 } | 727 } |
715 std::string pwg_page; | 728 std::string pwg_page; |
716 if (!encoder.EncodePage(image, settings.dpi(), total_page_count, &pwg_page)) | 729 if (!encoder.EncodePage(image, settings.dpi(), total_page_count, &pwg_page)) |
717 return false; | 730 return false; |
718 bytes_written = base::WritePlatformFileAtCurrentPos(bitmap_file, | 731 bytes_written = base::WritePlatformFileAtCurrentPos(bitmap_file, |
719 pwg_page.data(), | 732 pwg_page.data(), |
720 pwg_page.size()); | 733 pwg_page.size()); |
721 if (bytes_written != static_cast<int>(pwg_page.size())) | 734 if (bytes_written != static_cast<int>(pwg_page.size())) |
722 return false; | 735 return false; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 NetworkingPrivateCrypto crypto; | 943 NetworkingPrivateCrypto crypto; |
931 success = crypto.EncryptByteString(public_key, key_data, &ciphertext); | 944 success = crypto.EncryptByteString(public_key, key_data, &ciphertext); |
932 } | 945 } |
933 | 946 |
934 Send(new ChromeUtilityHostMsg_GotEncryptedWiFiCredentials(ciphertext, | 947 Send(new ChromeUtilityHostMsg_GotEncryptedWiFiCredentials(ciphertext, |
935 success)); | 948 success)); |
936 } | 949 } |
937 #endif // defined(OS_WIN) | 950 #endif // defined(OS_WIN) |
938 | 951 |
939 } // namespace chrome | 952 } // namespace chrome |
OLD | NEW |