Chromium Code Reviews| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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" | 96 #include "printing/features/features.h" |
| 97 #include "printing/metafile_skia_wrapper.h" | |
|
Lei Zhang
2016/11/18 02:25:53
BTW, this is already on line 135.
| |
| 97 #include "skia/ext/platform_canvas.h" | 98 #include "skia/ext/platform_canvas.h" |
| 98 #include "third_party/WebKit/public/platform/URLConversion.h" | 99 #include "third_party/WebKit/public/platform/URLConversion.h" |
| 99 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 100 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
| 100 #include "third_party/WebKit/public/platform/WebFloatRect.h" | 101 #include "third_party/WebKit/public/platform/WebFloatRect.h" |
| 101 #include "third_party/WebKit/public/platform/WebGamepads.h" | 102 #include "third_party/WebKit/public/platform/WebGamepads.h" |
| 102 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 103 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 103 #include "third_party/WebKit/public/platform/WebRect.h" | 104 #include "third_party/WebKit/public/platform/WebRect.h" |
| 104 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 105 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 105 #include "third_party/WebKit/public/platform/WebString.h" | 106 #include "third_party/WebKit/public/platform/WebString.h" |
| 106 #include "third_party/WebKit/public/platform/WebURL.h" | 107 #include "third_party/WebKit/public/platform/WebURL.h" |
| (...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1791 print_settings.dpi = print_params.printerDPI; | 1792 print_settings.dpi = print_params.printerDPI; |
| 1792 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; | 1793 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; |
| 1793 print_settings.grayscale = PP_FALSE; | 1794 print_settings.grayscale = PP_FALSE; |
| 1794 print_settings.print_scaling_option = | 1795 print_settings.print_scaling_option = |
| 1795 static_cast<PP_PrintScalingOption_Dev>(print_params.printScalingOption); | 1796 static_cast<PP_PrintScalingOption_Dev>(print_params.printScalingOption); |
| 1796 print_settings.format = format; | 1797 print_settings.format = format; |
| 1797 num_pages = plugin_print_interface_->Begin(pp_instance(), &print_settings); | 1798 num_pages = plugin_print_interface_->Begin(pp_instance(), &print_settings); |
| 1798 if (!num_pages) | 1799 if (!num_pages) |
| 1799 return 0; | 1800 return 0; |
| 1800 current_print_settings_ = print_settings; | 1801 current_print_settings_ = print_settings; |
| 1801 canvas_ = nullptr; | 1802 metafile_wrapper_.reset(); |
|
bbudge
2016/11/17 22:37:00
Would a DCHECK(!metafile_wrapper_) make sense here
| |
| 1802 ranges_.clear(); | 1803 ranges_.clear(); |
| 1803 return num_pages; | 1804 return num_pages; |
| 1804 } | 1805 } |
| 1805 | 1806 |
| 1806 void PepperPluginInstanceImpl::PrintPage(int page_number, | 1807 void PepperPluginInstanceImpl::PrintPage(int page_number, |
| 1807 blink::WebCanvas* canvas) { | 1808 blink::WebCanvas* canvas) { |
| 1808 #if BUILDFLAG(ENABLE_PRINTING) | 1809 #if BUILDFLAG(ENABLE_PRINTING) |
| 1809 DCHECK(plugin_print_interface_); | 1810 DCHECK(plugin_print_interface_); |
| 1810 PP_PrintPageNumberRange_Dev page_range; | 1811 PP_PrintPageNumberRange_Dev page_range; |
| 1811 page_range.first_page_number = page_range.last_page_number = page_number; | 1812 page_range.first_page_number = page_range.last_page_number = page_number; |
| 1812 // The canvas only has a metafile on it for print preview. | 1813 // The canvas only has a metafile on it for print preview. |
| 1813 bool save_for_later = | 1814 sk_sp<printing::MetafileSkiaWrapper> wrapper = |
| 1814 (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas) != NULL); | 1815 printing::MetafileSkiaWrapper::RefFromCanvas(*canvas); |
| 1816 bool save_for_later = wrapper && wrapper->getMetafile(); | |
| 1815 #if defined(OS_MACOSX) | 1817 #if defined(OS_MACOSX) |
| 1816 save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas); | 1818 save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas); |
| 1817 #endif // defined(OS_MACOSX) | 1819 #endif // defined(OS_MACOSX) |
| 1820 | |
| 1818 if (save_for_later) { | 1821 if (save_for_later) { |
| 1819 ranges_.push_back(page_range); | 1822 ranges_.push_back(page_range); |
| 1820 canvas_ = canvas; | 1823 metafile_wrapper_ = wrapper; |
| 1821 } else { | 1824 } else { |
| 1822 PrintPageHelper(&page_range, 1, canvas); | 1825 PrintPageHelper(&page_range, 1, wrapper.get()); |
| 1823 } | 1826 } |
| 1824 #endif | 1827 #endif |
| 1825 } | 1828 } |
| 1826 | 1829 |
| 1827 void PepperPluginInstanceImpl::PrintPageHelper( | 1830 void PepperPluginInstanceImpl::PrintPageHelper( |
| 1828 PP_PrintPageNumberRange_Dev* page_ranges, | 1831 PP_PrintPageNumberRange_Dev* page_ranges, |
| 1829 int num_ranges, | 1832 int num_ranges, |
| 1830 blink::WebCanvas* canvas) { | 1833 printing::MetafileSkiaWrapper* wrapper) { |
| 1831 // Keep a reference on the stack. See NOTE above. | 1834 // Keep a reference on the stack. See NOTE above. |
| 1832 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1835 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 1833 DCHECK(plugin_print_interface_); | 1836 DCHECK(plugin_print_interface_); |
| 1834 if (!plugin_print_interface_) | 1837 if (!plugin_print_interface_) |
| 1835 return; | 1838 return; |
| 1836 PP_Resource print_output = plugin_print_interface_->PrintPages( | 1839 PP_Resource print_output = plugin_print_interface_->PrintPages( |
| 1837 pp_instance(), page_ranges, num_ranges); | 1840 pp_instance(), page_ranges, num_ranges); |
| 1838 if (!print_output) | 1841 if (!print_output) |
| 1839 return; | 1842 return; |
| 1840 | 1843 |
| 1841 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) | 1844 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) |
| 1842 PrintPDFOutput(print_output, canvas); | 1845 PrintPDFOutput(print_output, wrapper); |
| 1843 | 1846 |
| 1844 // Now we need to release the print output resource. | 1847 // Now we need to release the print output resource. |
| 1845 PluginModule::GetCore()->ReleaseResource(print_output); | 1848 PluginModule::GetCore()->ReleaseResource(print_output); |
| 1846 } | 1849 } |
| 1847 | 1850 |
| 1848 void PepperPluginInstanceImpl::PrintEnd() { | 1851 void PepperPluginInstanceImpl::PrintEnd() { |
| 1849 // Keep a reference on the stack. See NOTE above. | 1852 // Keep a reference on the stack. See NOTE above. |
| 1850 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1853 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 1851 if (!ranges_.empty()) | 1854 if (!ranges_.empty()) |
|
Lei Zhang
2016/11/18 01:53:37
nit: needs curly braces now.
| |
| 1852 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_); | 1855 PrintPageHelper(&(ranges_.front()), ranges_.size(), |
| 1853 canvas_ = nullptr; | 1856 metafile_wrapper_.get()); |
| 1857 metafile_wrapper_.reset(); | |
| 1854 ranges_.clear(); | 1858 ranges_.clear(); |
| 1855 | 1859 |
| 1856 DCHECK(plugin_print_interface_); | 1860 DCHECK(plugin_print_interface_); |
| 1857 if (plugin_print_interface_) | 1861 if (plugin_print_interface_) |
| 1858 plugin_print_interface_->End(pp_instance()); | 1862 plugin_print_interface_->End(pp_instance()); |
| 1859 | 1863 |
| 1860 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 1864 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 1861 #if defined(OS_MACOSX) | 1865 #if defined(OS_MACOSX) |
| 1862 last_printed_page_ = NULL; | 1866 last_printed_page_ = NULL; |
| 1863 #endif // defined(OS_MACOSX) | 1867 #endif // defined(OS_MACOSX) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2010 WebLocalFrame* frame = document.frame(); | 2014 WebLocalFrame* frame = document.frame(); |
| 2011 if (!frame) | 2015 if (!frame) |
| 2012 return false; | 2016 return false; |
| 2013 WebView* view = frame->view(); | 2017 WebView* view = frame->view(); |
| 2014 if (!view) | 2018 if (!view) |
| 2015 return false; | 2019 return false; |
| 2016 | 2020 |
| 2017 return view->isAcceleratedCompositingActive(); | 2021 return view->isAcceleratedCompositingActive(); |
| 2018 } | 2022 } |
| 2019 | 2023 |
| 2020 bool PepperPluginInstanceImpl::PrintPDFOutput(PP_Resource print_output, | 2024 bool PepperPluginInstanceImpl::PrintPDFOutput( |
| 2021 blink::WebCanvas* canvas) { | 2025 PP_Resource print_output, |
| 2026 printing::MetafileSkiaWrapper* wrapper) { | |
| 2022 #if BUILDFLAG(ENABLE_PRINTING) | 2027 #if BUILDFLAG(ENABLE_PRINTING) |
| 2023 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true); | 2028 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true); |
| 2024 if (enter.failed()) | 2029 if (enter.failed()) |
| 2025 return false; | 2030 return false; |
| 2026 | 2031 |
| 2027 BufferAutoMapper mapper(enter.object()); | 2032 BufferAutoMapper mapper(enter.object()); |
| 2028 if (!mapper.data() || !mapper.size()) { | 2033 if (!mapper.data() || !mapper.size()) { |
| 2029 NOTREACHED(); | 2034 NOTREACHED(); |
| 2030 return false; | 2035 return false; |
| 2031 } | 2036 } |
| 2032 | 2037 |
| 2033 printing::PdfMetafileSkia* metafile = | 2038 printing::PdfMetafileSkia* metafile = |
| 2034 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); | 2039 wrapper ? wrapper->getMetafile() : nullptr; |
| 2035 if (metafile) | 2040 if (metafile) |
|
bbudge
2016/11/17 22:37:00
How about:
if (wrapper) {
printing::PdfMetafileS
| |
| 2036 return metafile->InitFromData(mapper.data(), mapper.size()); | 2041 return metafile->InitFromData(mapper.data(), mapper.size()); |
| 2037 | 2042 |
| 2038 NOTREACHED(); | 2043 NOTREACHED(); |
| 2039 #endif // ENABLE_PRINTING | 2044 #endif // ENABLE_PRINTING |
| 2040 return false; | 2045 return false; |
| 2041 } | 2046 } |
| 2042 | 2047 |
| 2043 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { | 2048 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { |
| 2044 if (!container_) | 2049 if (!container_) |
| 2045 return; | 2050 return; |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3436 const cc::TextureMailbox& mailbox) const { | 3441 const cc::TextureMailbox& mailbox) const { |
| 3437 auto it = | 3442 auto it = |
| 3438 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), | 3443 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), |
| 3439 [&mailbox](const TextureMailboxRefCount& ref_count) { | 3444 [&mailbox](const TextureMailboxRefCount& ref_count) { |
| 3440 return ref_count.first.mailbox() == mailbox.mailbox(); | 3445 return ref_count.first.mailbox() == mailbox.mailbox(); |
| 3441 }); | 3446 }); |
| 3442 return it != texture_ref_counts_.end(); | 3447 return it != texture_ref_counts_.end(); |
| 3443 } | 3448 } |
| 3444 | 3449 |
| 3445 } // namespace content | 3450 } // namespace content |
| OLD | NEW |