Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 2524143003: Print Preview: Add option to rasterize PDFs and add JPEG compression. (Closed)
Patch Set: Clean up JS Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/renderer/pepper/pepper_plugin_instance_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bit_cast.h" 10 #include "base/bit_cast.h"
(...skipping 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 1760
1761 void PepperPluginInstanceImpl::ReportGeometry() { 1761 void PepperPluginInstanceImpl::ReportGeometry() {
1762 // If this call was delayed, we may have transitioned back to fullscreen in 1762 // If this call was delayed, we may have transitioned back to fullscreen in
1763 // the mean time, so only report the geometry if we are actually in normal 1763 // the mean time, so only report the geometry if we are actually in normal
1764 // mode. 1764 // mode.
1765 if (container_ && !fullscreen_container_ && !flash_fullscreen_) 1765 if (container_ && !fullscreen_container_ && !flash_fullscreen_)
1766 container_->reportGeometry(); 1766 container_->reportGeometry();
1767 } 1767 }
1768 1768
1769 bool PepperPluginInstanceImpl::GetPreferredPrintOutputFormat( 1769 bool PepperPluginInstanceImpl::GetPreferredPrintOutputFormat(
1770 PP_PrintOutputFormat_Dev* format) { 1770 PP_PrintOutputFormat_Dev* format,
1771 const WebPrintParams& print_params) {
1771 // Keep a reference on the stack. See NOTE above. 1772 // Keep a reference on the stack. See NOTE above.
1772 scoped_refptr<PepperPluginInstanceImpl> ref(this); 1773 scoped_refptr<PepperPluginInstanceImpl> ref(this);
1773 if (!LoadPrintInterface()) 1774 if (!LoadPrintInterface())
1774 return false; 1775 return false;
1775 uint32_t supported_formats = 1776 uint32_t supported_formats =
1776 plugin_print_interface_->QuerySupportedFormats(pp_instance()); 1777 plugin_print_interface_->QuerySupportedFormats(pp_instance());
1777 if (supported_formats & PP_PRINTOUTPUTFORMAT_PDF) { 1778 if ((supported_formats & PP_PRINTOUTPUTFORMAT_PDF) &&
1779 !print_params.rasterizePDF) {
1778 *format = PP_PRINTOUTPUTFORMAT_PDF; 1780 *format = PP_PRINTOUTPUTFORMAT_PDF;
1779 return true; 1781 return true;
1780 } 1782 }
1783 if (supported_formats & PP_PRINTOUTPUTFORMAT_RASTER) {
1784 *format = PP_PRINTOUTPUTFORMAT_RASTER;
1785 return true;
1786 }
1781 return false; 1787 return false;
1782 } 1788 }
1783 1789
1784 bool PepperPluginInstanceImpl::SupportsPrintInterface() { 1790 bool PepperPluginInstanceImpl::SupportsPrintInterface() {
1785 PP_PrintOutputFormat_Dev format; 1791 PP_PrintOutputFormat_Dev format;
1786 return GetPreferredPrintOutputFormat(&format); 1792 WebPrintParams params;
1793 params.rasterizePDF = false;
Lei Zhang 2017/02/25 01:01:16 BTW, this is already initialized to false in the m
1794 return GetPreferredPrintOutputFormat(&format, params);
1787 } 1795 }
1788 1796
1789 bool PepperPluginInstanceImpl::IsPrintScalingDisabled() { 1797 bool PepperPluginInstanceImpl::IsPrintScalingDisabled() {
1790 DCHECK(plugin_print_interface_); 1798 DCHECK(plugin_print_interface_);
1791 if (!plugin_print_interface_) 1799 if (!plugin_print_interface_)
1792 return false; 1800 return false;
1793 return plugin_print_interface_->IsScalingDisabled(pp_instance()) == PP_TRUE; 1801 return plugin_print_interface_->IsScalingDisabled(pp_instance()) == PP_TRUE;
1794 } 1802 }
1795 1803
1796 int PepperPluginInstanceImpl::PrintBegin(const WebPrintParams& print_params) { 1804 int PepperPluginInstanceImpl::PrintBegin(const WebPrintParams& print_params) {
1797 // Keep a reference on the stack. See NOTE above. 1805 // Keep a reference on the stack. See NOTE above.
1798 scoped_refptr<PepperPluginInstanceImpl> ref(this); 1806 scoped_refptr<PepperPluginInstanceImpl> ref(this);
1799 PP_PrintOutputFormat_Dev format; 1807 PP_PrintOutputFormat_Dev format;
1800 if (!GetPreferredPrintOutputFormat(&format)) { 1808 if (!GetPreferredPrintOutputFormat(&format, print_params)) {
1801 // PrintBegin should not have been called since SupportsPrintInterface 1809 // PrintBegin should not have been called since SupportsPrintInterface
1802 // would have returned false; 1810 // would have returned false;
1803 NOTREACHED(); 1811 NOTREACHED();
1804 return 0; 1812 return 0;
1805 } 1813 }
1806 int num_pages = 0; 1814 int num_pages = 0;
1807 PP_PrintSettings_Dev print_settings; 1815 PP_PrintSettings_Dev print_settings;
1808 print_settings.printable_area = PP_FromGfxRect(print_params.printableArea); 1816 print_settings.printable_area = PP_FromGfxRect(print_params.printableArea);
1809 print_settings.content_area = PP_FromGfxRect(print_params.printContentArea); 1817 print_settings.content_area = PP_FromGfxRect(print_params.printContentArea);
1810 print_settings.paper_size = PP_FromGfxSize(print_params.paperSize); 1818 print_settings.paper_size = PP_FromGfxSize(print_params.paperSize);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1852 // Keep a reference on the stack. See NOTE above. 1860 // Keep a reference on the stack. See NOTE above.
1853 scoped_refptr<PepperPluginInstanceImpl> ref(this); 1861 scoped_refptr<PepperPluginInstanceImpl> ref(this);
1854 DCHECK(plugin_print_interface_); 1862 DCHECK(plugin_print_interface_);
1855 if (!plugin_print_interface_) 1863 if (!plugin_print_interface_)
1856 return; 1864 return;
1857 PP_Resource print_output = plugin_print_interface_->PrintPages( 1865 PP_Resource print_output = plugin_print_interface_->PrintPages(
1858 pp_instance(), page_ranges, num_ranges); 1866 pp_instance(), page_ranges, num_ranges);
1859 if (!print_output) 1867 if (!print_output)
1860 return; 1868 return;
1861 1869
1862 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) 1870 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF ||
1871 current_print_settings_.format == PP_PRINTOUTPUTFORMAT_RASTER)
1863 PrintPDFOutput(print_output, metafile); 1872 PrintPDFOutput(print_output, metafile);
1864 1873
1865 // Now we need to release the print output resource. 1874 // Now we need to release the print output resource.
1866 PluginModule::GetCore()->ReleaseResource(print_output); 1875 PluginModule::GetCore()->ReleaseResource(print_output);
1867 } 1876 }
1868 1877
1869 void PepperPluginInstanceImpl::PrintEnd() { 1878 void PepperPluginInstanceImpl::PrintEnd() {
1870 // Keep a reference on the stack. See NOTE above. 1879 // Keep a reference on the stack. See NOTE above.
1871 scoped_refptr<PepperPluginInstanceImpl> ref(this); 1880 scoped_refptr<PepperPluginInstanceImpl> ref(this);
1872 if (!ranges_.empty()) 1881 if (!ranges_.empty())
(...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after
3456 const cc::TextureMailbox& mailbox) const { 3465 const cc::TextureMailbox& mailbox) const {
3457 auto it = 3466 auto it =
3458 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), 3467 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(),
3459 [&mailbox](const TextureMailboxRefCount& ref_count) { 3468 [&mailbox](const TextureMailboxRefCount& ref_count) {
3460 return ref_count.first.mailbox() == mailbox.mailbox(); 3469 return ref_count.first.mailbox() == mailbox.mailbox();
3461 }); 3470 });
3462 return it != texture_ref_counts_.end(); 3471 return it != texture_ref_counts_.end();
3463 } 3472 }
3464 3473
3465 } // namespace content 3474 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698