| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 358 |
| 359 bool handled = true; | 359 bool handled = true; |
| 360 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | 360 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
| 361 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) | 361 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) |
| 362 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackWebResource, | 362 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackWebResource, |
| 363 OnUnpackWebResource) | 363 OnUnpackWebResource) |
| 364 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, | 364 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, |
| 365 OnParseUpdateManifest) | 365 OnParseUpdateManifest) |
| 366 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) | 366 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) |
| 367 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) | 367 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) |
| 368 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, | 368 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles, |
| 369 OnRenderPDFPagesToMetafile) | 369 OnRenderPDFPagesToMetafile) |
| 370 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToPWGRaster, | 370 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToPWGRaster, |
| 371 OnRenderPDFPagesToPWGRaster) | 371 OnRenderPDFPagesToPWGRaster) |
| 372 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, | 372 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, |
| 373 OnRobustJPEGDecodeImage) | 373 OnRobustJPEGDecodeImage) |
| 374 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) | 374 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) |
| 375 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, | 375 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, |
| 376 OnGetPrinterCapsAndDefaults) | 376 OnGetPrinterCapsAndDefaults) |
| 377 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults, | 377 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults, |
| 378 OnGetPrinterSemanticCapsAndDefaults) | 378 OnGetPrinterSemanticCapsAndDefaults) |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 | 560 |
| 561 if (succeeded) | 561 if (succeeded) |
| 562 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded()); | 562 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded()); |
| 563 else | 563 else |
| 564 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed()); | 564 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed()); |
| 565 ReleaseProcessIfNeeded(); | 565 ReleaseProcessIfNeeded(); |
| 566 } | 566 } |
| 567 #endif // defined(OS_CHROMEOS) | 567 #endif // defined(OS_CHROMEOS) |
| 568 | 568 |
| 569 void ChromeContentUtilityClient::OnRenderPDFPagesToMetafile( | 569 void ChromeContentUtilityClient::OnRenderPDFPagesToMetafile( |
| 570 base::PlatformFile pdf_file, | 570 IPC::PlatformFileForTransit pdf_transit, |
| 571 const base::FilePath& metafile_path, | 571 const base::FilePath& metafile_path, |
| 572 const printing::PdfRenderSettings& settings, | 572 const printing::PdfRenderSettings& settings, |
| 573 const std::vector<printing::PageRange>& page_ranges) { | 573 const std::vector<printing::PageRange>& page_ranges_const) { |
| 574 bool succeeded = false; | 574 bool succeeded = false; |
| 575 #if defined(OS_WIN) | 575 #if defined(OS_WIN) |
| 576 base::PlatformFile pdf_file = |
| 577 IPC::PlatformFileForTransitToPlatformFile(pdf_transit); |
| 576 int highest_rendered_page_number = 0; | 578 int highest_rendered_page_number = 0; |
| 577 double scale_factor = 1.0; | 579 double scale_factor = 1.0; |
| 580 std::vector<printing::PageRange> page_ranges = page_ranges_const; |
| 578 succeeded = RenderPDFToWinMetafile(pdf_file, | 581 succeeded = RenderPDFToWinMetafile(pdf_file, |
| 579 metafile_path, | 582 metafile_path, |
| 580 settings, | 583 settings, |
| 581 page_ranges, | 584 &page_ranges, |
| 582 &highest_rendered_page_number, | 585 &highest_rendered_page_number, |
| 583 &scale_factor); | 586 &scale_factor); |
| 584 if (succeeded) { | 587 if (succeeded) { |
| 585 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Succeeded( | 588 // TODO(vitalybuka|scottmg): http://crbug.com/170859. These could |
| 586 highest_rendered_page_number, scale_factor)); | 589 // potentially be sent as each page is converted so that the spool could |
| 590 // start sooner. |
| 591 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_Succeeded( |
| 592 page_ranges, scale_factor)); |
| 587 } | 593 } |
| 588 #endif // defined(OS_WIN) | 594 #endif // defined(OS_WIN) |
| 589 if (!succeeded) { | 595 if (!succeeded) { |
| 590 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed()); | 596 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed()); |
| 591 } | 597 } |
| 592 ReleaseProcessIfNeeded(); | 598 ReleaseProcessIfNeeded(); |
| 593 } | 599 } |
| 594 | 600 |
| 595 void ChromeContentUtilityClient::OnRenderPDFPagesToPWGRaster( | 601 void ChromeContentUtilityClient::OnRenderPDFPagesToPWGRaster( |
| 596 IPC::PlatformFileForTransit pdf_transit, | 602 IPC::PlatformFileForTransit pdf_transit, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 607 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Failed()); | 613 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Failed()); |
| 608 } | 614 } |
| 609 ReleaseProcessIfNeeded(); | 615 ReleaseProcessIfNeeded(); |
| 610 } | 616 } |
| 611 | 617 |
| 612 #if defined(OS_WIN) | 618 #if defined(OS_WIN) |
| 613 bool ChromeContentUtilityClient::RenderPDFToWinMetafile( | 619 bool ChromeContentUtilityClient::RenderPDFToWinMetafile( |
| 614 base::PlatformFile pdf_file, | 620 base::PlatformFile pdf_file, |
| 615 const base::FilePath& metafile_path, | 621 const base::FilePath& metafile_path, |
| 616 const printing::PdfRenderSettings& settings, | 622 const printing::PdfRenderSettings& settings, |
| 617 const std::vector<printing::PageRange>& page_ranges, | 623 std::vector<printing::PageRange>* page_ranges, |
| 618 int* highest_rendered_page_number, | 624 int* highest_rendered_page_number, |
| 619 double* scale_factor) { | 625 double* scale_factor) { |
| 626 DCHECK(page_ranges); |
| 620 *highest_rendered_page_number = -1; | 627 *highest_rendered_page_number = -1; |
| 621 *scale_factor = 1.0; | 628 *scale_factor = 1.0; |
| 622 base::win::ScopedHandle file(pdf_file); | 629 base::win::ScopedHandle file(pdf_file); |
| 623 | 630 |
| 624 if (!g_pdf_lib.Get().IsValid()) | 631 if (!g_pdf_lib.Get().IsValid()) |
| 625 return false; | 632 return false; |
| 626 | 633 |
| 627 // TODO(sanjeevr): Add a method to the PDF DLL that takes in a file handle | 634 // TODO(sanjeevr): Add a method to the PDF DLL that takes in a file handle |
| 628 // and a page range array. That way we don't need to read the entire PDF into | 635 // and a page range array. That way we don't need to read the entire PDF into |
| 629 // memory. | 636 // memory. |
| 630 DWORD length = ::GetFileSize(file, NULL); | 637 DWORD length = ::GetFileSize(file, NULL); |
| 631 if (length == INVALID_FILE_SIZE) | 638 if (length == INVALID_FILE_SIZE) |
| 632 return false; | 639 return false; |
| 633 | 640 |
| 634 std::vector<uint8> buffer; | 641 std::vector<uint8> buffer; |
| 635 buffer.resize(length); | 642 buffer.resize(length); |
| 636 DWORD bytes_read = 0; | 643 DWORD bytes_read = 0; |
| 637 if (!ReadFile(pdf_file, &buffer.front(), length, &bytes_read, NULL) || | 644 if (!ReadFile(pdf_file, &buffer.front(), length, &bytes_read, NULL) || |
| 638 (bytes_read != length)) { | 645 (bytes_read != length)) { |
| 639 return false; | 646 return false; |
| 640 } | 647 } |
| 641 | 648 |
| 642 int total_page_count = 0; | 649 int total_page_count = 0; |
| 643 if (!g_pdf_lib.Get().GetPDFDocInfo(&buffer.front(), buffer.size(), | 650 if (!g_pdf_lib.Get().GetPDFDocInfo(&buffer.front(), buffer.size(), |
| 644 &total_page_count, NULL)) { | 651 &total_page_count, NULL)) { |
| 645 return false; | 652 return false; |
| 646 } | 653 } |
| 647 | 654 |
| 648 printing::Emf metafile; | 655 // If no range supplied, do all pages. |
| 649 metafile.InitToFile(metafile_path); | 656 if (page_ranges->empty()) { |
| 650 // We need to scale down DC to fit an entire page into DC available area. | 657 printing::PageRange page_range_all; |
| 651 // Current metafile is based on screen DC and have current screen size. | 658 page_range_all.from = 0; |
| 652 // Writing outside of those boundaries will result in the cut-off output. | 659 page_range_all.to = total_page_count - 1; |
| 653 // On metafiles (this is the case here), scaling down will still record | 660 page_ranges->push_back(page_range_all); |
| 654 // original coordinates and we'll be able to print in full resolution. | 661 } |
| 655 // Before playback we'll need to counter the scaling up that will happen | |
| 656 // in the service (print_system_win.cc). | |
| 657 *scale_factor = gfx::CalculatePageScale(metafile.context(), | |
| 658 settings.area().right(), | |
| 659 settings.area().bottom()); | |
| 660 gfx::ScaleDC(metafile.context(), *scale_factor); | |
| 661 | 662 |
| 662 bool ret = false; | 663 bool ret = false; |
| 663 std::vector<printing::PageRange>::const_iterator iter; | 664 std::vector<printing::PageRange>::const_iterator iter; |
| 664 for (iter = page_ranges.begin(); iter != page_ranges.end(); ++iter) { | 665 for (iter = page_ranges->begin(); iter != page_ranges->end(); ++iter) { |
| 665 for (int page_number = iter->from; page_number <= iter->to; ++page_number) { | 666 for (int page_number = iter->from; page_number <= iter->to; ++page_number) { |
| 666 if (page_number >= total_page_count) | 667 if (page_number >= total_page_count) |
| 667 break; | 668 break; |
| 669 |
| 670 printing::Emf metafile; |
| 671 metafile.InitToFile(metafile_path.InsertBeforeExtensionASCII( |
| 672 base::StringPrintf(".%d", page_number))); |
| 673 |
| 674 // We need to scale down DC to fit an entire page into DC available area. |
| 675 // Current metafile is based on screen DC and have current screen size. |
| 676 // Writing outside of those boundaries will result in the cut-off output. |
| 677 // On metafiles (this is the case here), scaling down will still record |
| 678 // original coordinates and we'll be able to print in full resolution. |
| 679 // Before playback we'll need to counter the scaling up that will happen |
| 680 // in the service (print_system_win.cc). |
| 681 *scale_factor = gfx::CalculatePageScale(metafile.context(), |
| 682 settings.area().right(), |
| 683 settings.area().bottom()); |
| 684 gfx::ScaleDC(metafile.context(), *scale_factor); |
| 685 |
| 668 // The underlying metafile is of type Emf and ignores the arguments passed | 686 // The underlying metafile is of type Emf and ignores the arguments passed |
| 669 // to StartPage. | 687 // to StartPage. |
| 670 metafile.StartPage(gfx::Size(), gfx::Rect(), 1); | 688 metafile.StartPage(gfx::Size(), gfx::Rect(), 1); |
| 671 if (g_pdf_lib.Get().RenderPDFPageToDC( | 689 if (g_pdf_lib.Get().RenderPDFPageToDC( |
| 672 &buffer.front(), buffer.size(), page_number, metafile.context(), | 690 &buffer.front(), buffer.size(), page_number, metafile.context(), |
| 673 settings.dpi(), settings.dpi(), settings.area().x(), | 691 settings.dpi(), settings.dpi(), settings.area().x(), |
| 674 settings.area().y(), settings.area().width(), | 692 settings.area().y(), settings.area().width(), |
| 675 settings.area().height(), true, false, true, true, | 693 settings.area().height(), true, false, true, true, |
| 676 settings.autorotate())) { | 694 settings.autorotate())) { |
| 677 if (*highest_rendered_page_number < page_number) | 695 if (*highest_rendered_page_number < page_number) |
| 678 *highest_rendered_page_number = page_number; | 696 *highest_rendered_page_number = page_number; |
| 679 ret = true; | 697 ret = true; |
| 680 } | 698 } |
| 681 metafile.FinishPage(); | 699 metafile.FinishPage(); |
| 700 metafile.FinishDocument(); |
| 682 } | 701 } |
| 683 } | 702 } |
| 684 metafile.FinishDocument(); | |
| 685 return ret; | 703 return ret; |
| 686 } | 704 } |
| 687 #endif // defined(OS_WIN) | 705 #endif // defined(OS_WIN) |
| 688 | 706 |
| 689 bool ChromeContentUtilityClient::RenderPDFPagesToPWGRaster( | 707 bool ChromeContentUtilityClient::RenderPDFPagesToPWGRaster( |
| 690 base::PlatformFile pdf_file, | 708 base::PlatformFile pdf_file, |
| 691 const printing::PdfRenderSettings& settings, | 709 const printing::PdfRenderSettings& settings, |
| 692 const printing::PwgRasterSettings& bitmap_settings, | 710 const printing::PwgRasterSettings& bitmap_settings, |
| 693 base::PlatformFile bitmap_file) { | 711 base::PlatformFile bitmap_file) { |
| 694 bool autoupdate = true; | 712 bool autoupdate = true; |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 NetworkingPrivateCrypto crypto; | 1037 NetworkingPrivateCrypto crypto; |
| 1020 success = crypto.EncryptByteString(public_key, key_data, &ciphertext); | 1038 success = crypto.EncryptByteString(public_key, key_data, &ciphertext); |
| 1021 } | 1039 } |
| 1022 | 1040 |
| 1023 Send(new ChromeUtilityHostMsg_GotEncryptedWiFiCredentials(ciphertext, | 1041 Send(new ChromeUtilityHostMsg_GotEncryptedWiFiCredentials(ciphertext, |
| 1024 success)); | 1042 success)); |
| 1025 } | 1043 } |
| 1026 #endif // defined(OS_WIN) | 1044 #endif // defined(OS_WIN) |
| 1027 | 1045 |
| 1028 } // namespace chrome | 1046 } // namespace chrome |
| OLD | NEW |