| 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 render_frame_(render_frame), | 471 render_frame_(render_frame), |
| 472 module_(module), | 472 module_(module), |
| 473 instance_interface_(instance_interface), | 473 instance_interface_(instance_interface), |
| 474 pp_instance_(0), | 474 pp_instance_(0), |
| 475 graphics2d_translation_(0, 0), | 475 graphics2d_translation_(0, 0), |
| 476 graphics2d_scale_(1.f), | 476 graphics2d_scale_(1.f), |
| 477 container_(container), | 477 container_(container), |
| 478 layer_bound_to_fullscreen_(false), | 478 layer_bound_to_fullscreen_(false), |
| 479 layer_is_hardware_(false), | 479 layer_is_hardware_(false), |
| 480 plugin_url_(plugin_url), | 480 plugin_url_(plugin_url), |
| 481 document_url_(container ? GURL(container->document().url()) | 481 document_url_(container ? GURL(container->document().url()) : GURL()), |
| 482 : GURL()), | |
| 483 is_flash_plugin_(module->name() == kFlashPluginName), | 482 is_flash_plugin_(module->name() == kFlashPluginName), |
| 484 has_been_clicked_(false), | 483 has_been_clicked_(false), |
| 485 javascript_used_(false), | 484 javascript_used_(false), |
| 486 full_frame_(false), | 485 full_frame_(false), |
| 487 viewport_to_dip_scale_(1.0f), | 486 viewport_to_dip_scale_(1.0f), |
| 488 sent_initial_did_change_view_(false), | 487 sent_initial_did_change_view_(false), |
| 489 bound_graphics_2d_platform_(NULL), | 488 bound_graphics_2d_platform_(NULL), |
| 490 bound_compositor_(NULL), | 489 bound_compositor_(NULL), |
| 491 has_webkit_focus_(false), | 490 has_webkit_focus_(false), |
| 492 has_content_area_focus_(false), | 491 has_content_area_focus_(false), |
| 493 find_identifier_(-1), | 492 find_identifier_(-1), |
| 494 plugin_find_interface_(NULL), | 493 plugin_find_interface_(NULL), |
| 495 plugin_input_event_interface_(NULL), | 494 plugin_input_event_interface_(NULL), |
| 496 plugin_mouse_lock_interface_(NULL), | 495 plugin_mouse_lock_interface_(NULL), |
| 497 plugin_pdf_interface_(NULL), | 496 plugin_pdf_interface_(NULL), |
| 498 plugin_private_interface_(NULL), | 497 plugin_private_interface_(NULL), |
| 499 plugin_textinput_interface_(NULL), | 498 plugin_textinput_interface_(NULL), |
| 500 checked_for_plugin_input_event_interface_(false), | 499 checked_for_plugin_input_event_interface_(false), |
| 501 checked_for_plugin_pdf_interface_(false), | 500 checked_for_plugin_pdf_interface_(false), |
| 501 metafile_(nullptr), |
| 502 gamepad_impl_(new GamepadImpl()), | 502 gamepad_impl_(new GamepadImpl()), |
| 503 uma_private_impl_(NULL), | 503 uma_private_impl_(NULL), |
| 504 plugin_print_interface_(NULL), | 504 plugin_print_interface_(NULL), |
| 505 always_on_top_(false), | 505 always_on_top_(false), |
| 506 fullscreen_container_(NULL), | 506 fullscreen_container_(NULL), |
| 507 flash_fullscreen_(false), | 507 flash_fullscreen_(false), |
| 508 desired_fullscreen_state_(false), | 508 desired_fullscreen_state_(false), |
| 509 message_channel_(NULL), | 509 message_channel_(NULL), |
| 510 sad_plugin_(NULL), | 510 sad_plugin_(NULL), |
| 511 input_event_mask_(0), | 511 input_event_mask_(0), |
| (...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_.reset(); | 1801 metafile_ = nullptr; |
| 1802 ranges_.clear(); | 1802 ranges_.clear(); |
| 1803 return num_pages; | 1803 return num_pages; |
| 1804 } | 1804 } |
| 1805 | 1805 |
| 1806 void PepperPluginInstanceImpl::PrintPage(int page_number, | 1806 void PepperPluginInstanceImpl::PrintPage(int page_number, |
| 1807 blink::WebCanvas* canvas) { | 1807 blink::WebCanvas* canvas) { |
| 1808 #if BUILDFLAG(ENABLE_PRINTING) | 1808 #if BUILDFLAG(ENABLE_PRINTING) |
| 1809 DCHECK(plugin_print_interface_); | 1809 DCHECK(plugin_print_interface_); |
| 1810 PP_PrintPageNumberRange_Dev page_range; | 1810 PP_PrintPageNumberRange_Dev page_range; |
| 1811 page_range.first_page_number = page_range.last_page_number = page_number; | 1811 page_range.first_page_number = page_range.last_page_number = page_number; |
| 1812 // The canvas only has a metafile on it for print preview. | 1812 // The canvas only has a metafile on it for print preview. |
| 1813 bool save_for_later = | 1813 printing::PdfMetafileSkia* metafile = |
| 1814 (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas) != NULL); | 1814 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); |
| 1815 bool save_for_later = (metafile != NULL); |
| 1815 #if defined(OS_MACOSX) | 1816 #if defined(OS_MACOSX) |
| 1816 save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas); | 1817 save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas); |
| 1817 #endif // defined(OS_MACOSX) | 1818 #endif // defined(OS_MACOSX) |
| 1818 if (save_for_later) { | 1819 if (save_for_later) { |
| 1819 ranges_.push_back(page_range); | 1820 ranges_.push_back(page_range); |
| 1820 canvas_ = sk_ref_sp(canvas); | 1821 metafile_ = metafile; |
| 1821 } else { | 1822 } else { |
| 1822 PrintPageHelper(&page_range, 1, canvas); | 1823 PrintPageHelper(&page_range, 1, metafile); |
| 1823 } | 1824 } |
| 1824 #endif | 1825 #endif |
| 1825 } | 1826 } |
| 1826 | 1827 |
| 1827 void PepperPluginInstanceImpl::PrintPageHelper( | 1828 void PepperPluginInstanceImpl::PrintPageHelper( |
| 1828 PP_PrintPageNumberRange_Dev* page_ranges, | 1829 PP_PrintPageNumberRange_Dev* page_ranges, |
| 1829 int num_ranges, | 1830 int num_ranges, |
| 1830 blink::WebCanvas* canvas) { | 1831 printing::PdfMetafileSkia* metafile) { |
| 1831 // Keep a reference on the stack. See NOTE above. | 1832 // Keep a reference on the stack. See NOTE above. |
| 1832 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1833 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 1833 DCHECK(plugin_print_interface_); | 1834 DCHECK(plugin_print_interface_); |
| 1834 if (!plugin_print_interface_) | 1835 if (!plugin_print_interface_) |
| 1835 return; | 1836 return; |
| 1836 PP_Resource print_output = plugin_print_interface_->PrintPages( | 1837 PP_Resource print_output = plugin_print_interface_->PrintPages( |
| 1837 pp_instance(), page_ranges, num_ranges); | 1838 pp_instance(), page_ranges, num_ranges); |
| 1838 if (!print_output) | 1839 if (!print_output) |
| 1839 return; | 1840 return; |
| 1840 | 1841 |
| 1841 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) | 1842 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) |
| 1842 PrintPDFOutput(print_output, canvas); | 1843 PrintPDFOutput(print_output, metafile); |
| 1843 | 1844 |
| 1844 // Now we need to release the print output resource. | 1845 // Now we need to release the print output resource. |
| 1845 PluginModule::GetCore()->ReleaseResource(print_output); | 1846 PluginModule::GetCore()->ReleaseResource(print_output); |
| 1846 } | 1847 } |
| 1847 | 1848 |
| 1848 void PepperPluginInstanceImpl::PrintEnd() { | 1849 void PepperPluginInstanceImpl::PrintEnd() { |
| 1849 // Keep a reference on the stack. See NOTE above. | 1850 // Keep a reference on the stack. See NOTE above. |
| 1850 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1851 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 1851 if (!ranges_.empty()) | 1852 if (!ranges_.empty()) |
| 1852 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get()); | 1853 PrintPageHelper(&(ranges_.front()), ranges_.size(), metafile_); |
| 1853 canvas_.reset(); | 1854 metafile_ = nullptr; |
| 1854 ranges_.clear(); | 1855 ranges_.clear(); |
| 1855 | 1856 |
| 1856 DCHECK(plugin_print_interface_); | 1857 DCHECK(plugin_print_interface_); |
| 1857 if (plugin_print_interface_) | 1858 if (plugin_print_interface_) |
| 1858 plugin_print_interface_->End(pp_instance()); | 1859 plugin_print_interface_->End(pp_instance()); |
| 1859 | 1860 |
| 1860 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 1861 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 1861 #if defined(OS_MACOSX) | 1862 #if defined(OS_MACOSX) |
| 1862 last_printed_page_ = NULL; | 1863 last_printed_page_ = NULL; |
| 1863 #endif // defined(OS_MACOSX) | 1864 #endif // defined(OS_MACOSX) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2010 WebLocalFrame* frame = document.frame(); | 2011 WebLocalFrame* frame = document.frame(); |
| 2011 if (!frame) | 2012 if (!frame) |
| 2012 return false; | 2013 return false; |
| 2013 WebView* view = frame->view(); | 2014 WebView* view = frame->view(); |
| 2014 if (!view) | 2015 if (!view) |
| 2015 return false; | 2016 return false; |
| 2016 | 2017 |
| 2017 return view->isAcceleratedCompositingActive(); | 2018 return view->isAcceleratedCompositingActive(); |
| 2018 } | 2019 } |
| 2019 | 2020 |
| 2020 bool PepperPluginInstanceImpl::PrintPDFOutput(PP_Resource print_output, | 2021 bool PepperPluginInstanceImpl::PrintPDFOutput( |
| 2021 blink::WebCanvas* canvas) { | 2022 PP_Resource print_output, |
| 2023 printing::PdfMetafileSkia* metafile) { |
| 2022 #if BUILDFLAG(ENABLE_PRINTING) | 2024 #if BUILDFLAG(ENABLE_PRINTING) |
| 2023 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true); | 2025 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true); |
| 2024 if (enter.failed()) | 2026 if (enter.failed()) |
| 2025 return false; | 2027 return false; |
| 2026 | 2028 |
| 2027 BufferAutoMapper mapper(enter.object()); | 2029 BufferAutoMapper mapper(enter.object()); |
| 2028 if (!mapper.data() || !mapper.size()) { | 2030 if (!mapper.data() || !mapper.size()) { |
| 2029 NOTREACHED(); | 2031 NOTREACHED(); |
| 2030 return false; | 2032 return false; |
| 2031 } | 2033 } |
| 2032 | 2034 |
| 2033 printing::PdfMetafileSkia* metafile = | |
| 2034 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); | |
| 2035 if (metafile) | 2035 if (metafile) |
| 2036 return metafile->InitFromData(mapper.data(), mapper.size()); | 2036 return metafile->InitFromData(mapper.data(), mapper.size()); |
| 2037 | 2037 |
| 2038 NOTREACHED(); | 2038 NOTREACHED(); |
| 2039 #endif // ENABLE_PRINTING | 2039 #endif // ENABLE_PRINTING |
| 2040 return false; | 2040 return false; |
| 2041 } | 2041 } |
| 2042 | 2042 |
| 2043 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { | 2043 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { |
| 2044 if (!container_) | 2044 if (!container_) |
| (...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3436 const cc::TextureMailbox& mailbox) const { | 3436 const cc::TextureMailbox& mailbox) const { |
| 3437 auto it = | 3437 auto it = |
| 3438 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), | 3438 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), |
| 3439 [&mailbox](const TextureMailboxRefCount& ref_count) { | 3439 [&mailbox](const TextureMailboxRefCount& ref_count) { |
| 3440 return ref_count.first.mailbox() == mailbox.mailbox(); | 3440 return ref_count.first.mailbox() == mailbox.mailbox(); |
| 3441 }); | 3441 }); |
| 3442 return it != texture_ref_counts_.end(); | 3442 return it != texture_ref_counts_.end(); |
| 3443 } | 3443 } |
| 3444 | 3444 |
| 3445 } // namespace content | 3445 } // namespace content |
| OLD | NEW |