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)); |
| 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 415 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 |