| 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 "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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 #include "ppapi/shared_impl/ppb_view_shared.h" | 86 #include "ppapi/shared_impl/ppb_view_shared.h" |
| 87 #include "ppapi/shared_impl/ppp_instance_combined.h" | 87 #include "ppapi/shared_impl/ppp_instance_combined.h" |
| 88 #include "ppapi/shared_impl/resource.h" | 88 #include "ppapi/shared_impl/resource.h" |
| 89 #include "ppapi/shared_impl/scoped_pp_resource.h" | 89 #include "ppapi/shared_impl/scoped_pp_resource.h" |
| 90 #include "ppapi/shared_impl/scoped_pp_var.h" | 90 #include "ppapi/shared_impl/scoped_pp_var.h" |
| 91 #include "ppapi/shared_impl/time_conversion.h" | 91 #include "ppapi/shared_impl/time_conversion.h" |
| 92 #include "ppapi/shared_impl/url_request_info_data.h" | 92 #include "ppapi/shared_impl/url_request_info_data.h" |
| 93 #include "ppapi/shared_impl/var.h" | 93 #include "ppapi/shared_impl/var.h" |
| 94 #include "ppapi/thunk/enter.h" | 94 #include "ppapi/thunk/enter.h" |
| 95 #include "ppapi/thunk/ppb_buffer_api.h" | 95 #include "ppapi/thunk/ppb_buffer_api.h" |
| 96 #include "printing/features/features.h" | |
| 97 #include "skia/ext/platform_canvas.h" | 96 #include "skia/ext/platform_canvas.h" |
| 98 #include "third_party/WebKit/public/platform/URLConversion.h" | 97 #include "third_party/WebKit/public/platform/URLConversion.h" |
| 99 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 98 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
| 100 #include "third_party/WebKit/public/platform/WebFloatRect.h" | 99 #include "third_party/WebKit/public/platform/WebFloatRect.h" |
| 101 #include "third_party/WebKit/public/platform/WebGamepads.h" | 100 #include "third_party/WebKit/public/platform/WebGamepads.h" |
| 102 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 101 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 103 #include "third_party/WebKit/public/platform/WebRect.h" | 102 #include "third_party/WebKit/public/platform/WebRect.h" |
| 104 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 103 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 105 #include "third_party/WebKit/public/platform/WebString.h" | 104 #include "third_party/WebKit/public/platform/WebString.h" |
| 106 #include "third_party/WebKit/public/platform/WebURL.h" | 105 #include "third_party/WebKit/public/platform/WebURL.h" |
| (...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1767 } | 1766 } |
| 1768 | 1767 |
| 1769 bool PepperPluginInstanceImpl::IsPrintScalingDisabled() { | 1768 bool PepperPluginInstanceImpl::IsPrintScalingDisabled() { |
| 1770 DCHECK(plugin_print_interface_); | 1769 DCHECK(plugin_print_interface_); |
| 1771 if (!plugin_print_interface_) | 1770 if (!plugin_print_interface_) |
| 1772 return false; | 1771 return false; |
| 1773 return plugin_print_interface_->IsScalingDisabled(pp_instance()) == PP_TRUE; | 1772 return plugin_print_interface_->IsScalingDisabled(pp_instance()) == PP_TRUE; |
| 1774 } | 1773 } |
| 1775 | 1774 |
| 1776 int PepperPluginInstanceImpl::PrintBegin(const WebPrintParams& print_params) { | 1775 int PepperPluginInstanceImpl::PrintBegin(const WebPrintParams& print_params) { |
| 1776 #if BUILDFLAG(ENABLE_PRINTING) |
| 1777 // Keep a reference on the stack. See NOTE above. | 1777 // Keep a reference on the stack. See NOTE above. |
| 1778 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1778 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 1779 PP_PrintOutputFormat_Dev format; | 1779 PP_PrintOutputFormat_Dev format; |
| 1780 if (!GetPreferredPrintOutputFormat(&format)) { | 1780 if (!GetPreferredPrintOutputFormat(&format)) { |
| 1781 // PrintBegin should not have been called since SupportsPrintInterface | 1781 // PrintBegin should not have been called since SupportsPrintInterface |
| 1782 // would have returned false; | 1782 // would have returned false; |
| 1783 NOTREACHED(); | 1783 NOTREACHED(); |
| 1784 return 0; | 1784 return 0; |
| 1785 } | 1785 } |
| 1786 int num_pages = 0; | 1786 int num_pages = 0; |
| 1787 PP_PrintSettings_Dev print_settings; | 1787 PP_PrintSettings_Dev print_settings; |
| 1788 print_settings.printable_area = PP_FromGfxRect(print_params.printableArea); | 1788 print_settings.printable_area = PP_FromGfxRect(print_params.printableArea); |
| 1789 print_settings.content_area = PP_FromGfxRect(print_params.printContentArea); | 1789 print_settings.content_area = PP_FromGfxRect(print_params.printContentArea); |
| 1790 print_settings.paper_size = PP_FromGfxSize(print_params.paperSize); | 1790 print_settings.paper_size = PP_FromGfxSize(print_params.paperSize); |
| 1791 print_settings.dpi = print_params.printerDPI; | 1791 print_settings.dpi = print_params.printerDPI; |
| 1792 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; | 1792 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; |
| 1793 print_settings.grayscale = PP_FALSE; | 1793 print_settings.grayscale = PP_FALSE; |
| 1794 print_settings.print_scaling_option = | 1794 print_settings.print_scaling_option = |
| 1795 static_cast<PP_PrintScalingOption_Dev>(print_params.printScalingOption); | 1795 static_cast<PP_PrintScalingOption_Dev>(print_params.printScalingOption); |
| 1796 print_settings.format = format; | 1796 print_settings.format = format; |
| 1797 num_pages = plugin_print_interface_->Begin(pp_instance(), &print_settings); | 1797 num_pages = plugin_print_interface_->Begin(pp_instance(), &print_settings); |
| 1798 if (!num_pages) | 1798 if (!num_pages) |
| 1799 return 0; | 1799 return 0; |
| 1800 current_print_settings_ = print_settings; | 1800 current_print_settings_ = print_settings; |
| 1801 canvas_ = nullptr; | 1801 metafile_wrapper_.reset(); |
| 1802 ranges_.clear(); | 1802 ranges_.clear(); |
| 1803 return num_pages; | 1803 return num_pages; |
| 1804 #else |
| 1805 NOTREACHED(); |
| 1806 return 0; |
| 1807 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 1804 } | 1808 } |
| 1805 | 1809 |
| 1806 void PepperPluginInstanceImpl::PrintPage(int page_number, | 1810 void PepperPluginInstanceImpl::PrintPage(int page_number, |
| 1807 blink::WebCanvas* canvas) { | 1811 blink::WebCanvas* canvas) { |
| 1808 #if BUILDFLAG(ENABLE_PRINTING) | 1812 #if BUILDFLAG(ENABLE_PRINTING) |
| 1809 DCHECK(plugin_print_interface_); | 1813 DCHECK(plugin_print_interface_); |
| 1810 PP_PrintPageNumberRange_Dev page_range; | 1814 PP_PrintPageNumberRange_Dev page_range; |
| 1811 page_range.first_page_number = page_range.last_page_number = page_number; | 1815 page_range.first_page_number = page_range.last_page_number = page_number; |
| 1812 // The canvas only has a metafile on it for print preview. | 1816 // The canvas only has a metafile on it for print preview. |
| 1813 bool save_for_later = | 1817 sk_sp<printing::MetafileSkiaWrapper> wrapper = |
| 1814 (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas) != NULL); | 1818 printing::MetafileSkiaWrapper::RefFromCanvas(*canvas); |
| 1819 bool save_for_later = wrapper && wrapper->metafile(); |
| 1815 #if defined(OS_MACOSX) | 1820 #if defined(OS_MACOSX) |
| 1816 save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas); | 1821 save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas); |
| 1817 #endif // defined(OS_MACOSX) | 1822 #endif // defined(OS_MACOSX) |
| 1823 |
| 1818 if (save_for_later) { | 1824 if (save_for_later) { |
| 1819 ranges_.push_back(page_range); | 1825 ranges_.push_back(page_range); |
| 1820 canvas_ = canvas; | 1826 metafile_wrapper_ = wrapper; |
| 1821 } else { | 1827 } else { |
| 1822 PrintPageHelper(&page_range, 1, canvas); | 1828 PrintPageHelper(&page_range, 1, wrapper.get()); |
| 1823 } | 1829 } |
| 1824 #endif | 1830 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 1825 } | 1831 } |
| 1826 | 1832 |
| 1833 #if BUILDFLAG(ENABLE_PRINTING) |
| 1827 void PepperPluginInstanceImpl::PrintPageHelper( | 1834 void PepperPluginInstanceImpl::PrintPageHelper( |
| 1828 PP_PrintPageNumberRange_Dev* page_ranges, | 1835 PP_PrintPageNumberRange_Dev* page_ranges, |
| 1829 int num_ranges, | 1836 int num_ranges, |
| 1830 blink::WebCanvas* canvas) { | 1837 printing::MetafileSkiaWrapper* wrapper) { |
| 1831 // Keep a reference on the stack. See NOTE above. | 1838 // Keep a reference on the stack. See NOTE above. |
| 1832 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1839 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 1833 DCHECK(plugin_print_interface_); | 1840 DCHECK(plugin_print_interface_); |
| 1834 if (!plugin_print_interface_) | 1841 if (!plugin_print_interface_) |
| 1835 return; | 1842 return; |
| 1836 PP_Resource print_output = plugin_print_interface_->PrintPages( | 1843 PP_Resource print_output = plugin_print_interface_->PrintPages( |
| 1837 pp_instance(), page_ranges, num_ranges); | 1844 pp_instance(), page_ranges, num_ranges); |
| 1838 if (!print_output) | 1845 if (!print_output) |
| 1839 return; | 1846 return; |
| 1840 | 1847 |
| 1841 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) | 1848 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) |
| 1842 PrintPDFOutput(print_output, canvas); | 1849 PrintPDFOutput(print_output, wrapper); |
| 1843 | 1850 |
| 1844 // Now we need to release the print output resource. | 1851 // Now we need to release the print output resource. |
| 1845 PluginModule::GetCore()->ReleaseResource(print_output); | 1852 PluginModule::GetCore()->ReleaseResource(print_output); |
| 1846 } | 1853 } |
| 1854 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 1847 | 1855 |
| 1848 void PepperPluginInstanceImpl::PrintEnd() { | 1856 void PepperPluginInstanceImpl::PrintEnd() { |
| 1857 #if BUILDFLAG(ENABLE_PRINTING) |
| 1849 // Keep a reference on the stack. See NOTE above. | 1858 // Keep a reference on the stack. See NOTE above. |
| 1850 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1859 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 1851 if (!ranges_.empty()) | 1860 if (!ranges_.empty()) { |
| 1852 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_); | 1861 PrintPageHelper(&(ranges_.front()), ranges_.size(), |
| 1853 canvas_ = nullptr; | 1862 metafile_wrapper_.get()); |
| 1863 } |
| 1864 metafile_wrapper_.reset(); |
| 1854 ranges_.clear(); | 1865 ranges_.clear(); |
| 1855 | 1866 |
| 1856 DCHECK(plugin_print_interface_); | 1867 DCHECK(plugin_print_interface_); |
| 1857 if (plugin_print_interface_) | 1868 if (plugin_print_interface_) |
| 1858 plugin_print_interface_->End(pp_instance()); | 1869 plugin_print_interface_->End(pp_instance()); |
| 1859 | 1870 |
| 1860 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 1871 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 1861 #if defined(OS_MACOSX) | 1872 #if defined(OS_MACOSX) |
| 1862 last_printed_page_ = NULL; | 1873 last_printed_page_ = NULL; |
| 1863 #endif // defined(OS_MACOSX) | 1874 #endif // defined(OS_MACOSX) |
| 1875 #else |
| 1876 NOTREACHED(); |
| 1877 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 1864 } | 1878 } |
| 1865 | 1879 |
| 1866 bool PepperPluginInstanceImpl::GetPrintPresetOptionsFromDocument( | 1880 bool PepperPluginInstanceImpl::GetPrintPresetOptionsFromDocument( |
| 1867 blink::WebPrintPresetOptions* preset_options) { | 1881 blink::WebPrintPresetOptions* preset_options) { |
| 1868 // Keep a reference on the stack. See NOTE above. | 1882 // Keep a reference on the stack. See NOTE above. |
| 1869 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1883 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 1870 if (!LoadPdfInterface()) | 1884 if (!LoadPdfInterface()) |
| 1871 return false; | 1885 return false; |
| 1872 | 1886 |
| 1873 PP_PdfPrintPresetOptions_Dev options; | 1887 PP_PdfPrintPresetOptions_Dev options; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2010 WebLocalFrame* frame = document.frame(); | 2024 WebLocalFrame* frame = document.frame(); |
| 2011 if (!frame) | 2025 if (!frame) |
| 2012 return false; | 2026 return false; |
| 2013 WebView* view = frame->view(); | 2027 WebView* view = frame->view(); |
| 2014 if (!view) | 2028 if (!view) |
| 2015 return false; | 2029 return false; |
| 2016 | 2030 |
| 2017 return view->isAcceleratedCompositingActive(); | 2031 return view->isAcceleratedCompositingActive(); |
| 2018 } | 2032 } |
| 2019 | 2033 |
| 2020 bool PepperPluginInstanceImpl::PrintPDFOutput(PP_Resource print_output, | 2034 bool PepperPluginInstanceImpl::PrintPDFOutput( |
| 2021 blink::WebCanvas* canvas) { | 2035 PP_Resource print_output, |
| 2036 printing::MetafileSkiaWrapper* wrapper) { |
| 2022 #if BUILDFLAG(ENABLE_PRINTING) | 2037 #if BUILDFLAG(ENABLE_PRINTING) |
| 2023 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true); | 2038 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true); |
| 2024 if (enter.failed()) | 2039 if (enter.failed()) |
| 2025 return false; | 2040 return false; |
| 2026 | 2041 |
| 2027 BufferAutoMapper mapper(enter.object()); | 2042 BufferAutoMapper mapper(enter.object()); |
| 2028 if (!mapper.data() || !mapper.size()) { | 2043 if (!mapper.data() || !mapper.size()) { |
| 2029 NOTREACHED(); | 2044 NOTREACHED(); |
| 2030 return false; | 2045 return false; |
| 2031 } | 2046 } |
| 2032 | 2047 |
| 2033 printing::PdfMetafileSkia* metafile = | 2048 if (wrapper && wrapper->metafile()) |
| 2034 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); | 2049 return wrapper->metafile()->InitFromData(mapper.data(), mapper.size()); |
| 2035 if (metafile) | |
| 2036 return metafile->InitFromData(mapper.data(), mapper.size()); | |
| 2037 | 2050 |
| 2038 NOTREACHED(); | 2051 NOTREACHED(); |
| 2039 #endif // ENABLE_PRINTING | 2052 #endif // BUILDFLAG(ENABLE_PRINTING) |
| 2040 return false; | 2053 return false; |
| 2041 } | 2054 } |
| 2042 | 2055 |
| 2043 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { | 2056 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { |
| 2044 if (!container_) | 2057 if (!container_) |
| 2045 return; | 2058 return; |
| 2046 | 2059 |
| 2047 bool want_3d_layer = !!bound_graphics_3d_.get(); | 2060 bool want_3d_layer = !!bound_graphics_3d_.get(); |
| 2048 bool want_2d_layer = !!bound_graphics_2d_platform_; | 2061 bool want_2d_layer = !!bound_graphics_2d_platform_; |
| 2049 bool want_texture_layer = want_3d_layer || want_2d_layer; | 2062 bool want_texture_layer = want_3d_layer || want_2d_layer; |
| (...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3436 const cc::TextureMailbox& mailbox) const { | 3449 const cc::TextureMailbox& mailbox) const { |
| 3437 auto it = | 3450 auto it = |
| 3438 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), | 3451 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), |
| 3439 [&mailbox](const TextureMailboxRefCount& ref_count) { | 3452 [&mailbox](const TextureMailboxRefCount& ref_count) { |
| 3440 return ref_count.first.mailbox() == mailbox.mailbox(); | 3453 return ref_count.first.mailbox() == mailbox.mailbox(); |
| 3441 }); | 3454 }); |
| 3442 return it != texture_ref_counts_.end(); | 3455 return it != texture_ref_counts_.end(); |
| 3443 } | 3456 } |
| 3444 | 3457 |
| 3445 } // namespace content | 3458 } // namespace content |
| OLD | NEW |