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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/command_line.h" | |
9 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_offset_string_conversions.h" | 16 #include "base/strings/utf_offset_string_conversions.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "cc/layers/texture_layer.h" | 19 #include "cc/layers/texture_layer.h" |
19 #include "content/common/content_constants_internal.h" | 20 #include "content/common/content_constants_internal.h" |
21 #include "content/public/common/content_switches.h" | |
20 #include "content/public/common/page_zoom.h" | 22 #include "content/public/common/page_zoom.h" |
21 #include "content/public/renderer/content_renderer_client.h" | 23 #include "content/public/renderer/content_renderer_client.h" |
22 #include "content/renderer/pepper/common.h" | 24 #include "content/renderer/pepper/common.h" |
23 #include "content/renderer/pepper/content_decryptor_delegate.h" | 25 #include "content/renderer/pepper/content_decryptor_delegate.h" |
24 #include "content/renderer/pepper/event_conversion.h" | 26 #include "content/renderer/pepper/event_conversion.h" |
25 #include "content/renderer/pepper/fullscreen_container.h" | 27 #include "content/renderer/pepper/fullscreen_container.h" |
26 #include "content/renderer/pepper/gfx_conversion.h" | 28 #include "content/renderer/pepper/gfx_conversion.h" |
27 #include "content/renderer/pepper/host_dispatcher_wrapper.h" | 29 #include "content/renderer/pepper/host_dispatcher_wrapper.h" |
28 #include "content/renderer/pepper/host_globals.h" | 30 #include "content/renderer/pepper/host_globals.h" |
29 #include "content/renderer/pepper/message_channel.h" | 31 #include "content/renderer/pepper/message_channel.h" |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 520 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
519 | 521 |
520 if (GetContentClient()->renderer() && // NULL in unit tests. | 522 if (GetContentClient()->renderer() && // NULL in unit tests. |
521 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 523 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
522 external_document_load_ = true; | 524 external_document_load_ = true; |
523 } | 525 } |
524 | 526 |
525 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 527 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
526 DCHECK(!fullscreen_container_); | 528 DCHECK(!fullscreen_container_); |
527 | 529 |
528 // Force-unbind any Graphics. In the case of Graphics2D, if the plugin | |
529 // leaks the graphics 2D, it may actually get cleaned up after our | |
530 // destruction, so we need its pointers to be up-to-date. | |
531 BindGraphics(pp_instance(), 0); | |
532 | |
533 // Free all the plugin objects. This will automatically clear the back- | 530 // Free all the plugin objects. This will automatically clear the back- |
534 // pointer from the NPObject so WebKit can't call into the plugin any more. | 531 // pointer from the NPObject so WebKit can't call into the plugin any more. |
535 // | 532 // |
536 // Swap out the set so we can delete from it (the objects will try to | 533 // Swap out the set so we can delete from it (the objects will try to |
537 // unregister themselves inside the delete call). | 534 // unregister themselves inside the delete call). |
538 PluginObjectSet plugin_object_copy; | 535 PluginObjectSet plugin_object_copy; |
539 live_plugin_objects_.swap(plugin_object_copy); | 536 live_plugin_objects_.swap(plugin_object_copy); |
540 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); | 537 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); |
541 i != plugin_object_copy.end(); ++i) | 538 i != plugin_object_copy.end(); ++i) |
542 delete *i; | 539 delete *i; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 else | 583 else |
587 instance_interface_->DidDestroy(pp_instance()); | 584 instance_interface_->DidDestroy(pp_instance()); |
588 // Ensure we don't attempt to call functions on the destroyed instance. | 585 // Ensure we don't attempt to call functions on the destroyed instance. |
589 original_instance_interface_.reset(); | 586 original_instance_interface_.reset(); |
590 instance_interface_.reset(); | 587 instance_interface_.reset(); |
591 | 588 |
592 if (fullscreen_container_) { | 589 if (fullscreen_container_) { |
593 fullscreen_container_->Destroy(); | 590 fullscreen_container_->Destroy(); |
594 fullscreen_container_ = NULL; | 591 fullscreen_container_ = NULL; |
595 } | 592 } |
596 bound_graphics_3d_ = NULL; | 593 |
597 UpdateLayer(); | 594 // Force-unbind any Graphics. In the case of Graphics2D, if the plugin |
595 // leaks the graphics 2D, it may actually get cleaned up after our | |
596 // destruction, so we need its pointers to be up-to-date. | |
597 BindGraphics(pp_instance(), 0); | |
598 container_ = NULL; | 598 container_ = NULL; |
599 } | 599 } |
600 | 600 |
601 void PepperPluginInstanceImpl::Paint(WebCanvas* canvas, | 601 void PepperPluginInstanceImpl::Paint(WebCanvas* canvas, |
602 const gfx::Rect& plugin_rect, | 602 const gfx::Rect& plugin_rect, |
603 const gfx::Rect& paint_rect) { | 603 const gfx::Rect& paint_rect) { |
604 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); | 604 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); |
605 if (module()->is_crashed()) { | 605 if (module()->is_crashed()) { |
606 // Crashed plugin painting. | 606 // Crashed plugin painting. |
607 if (!sad_plugin_) // Lazily initialize bitmap. | 607 if (!sad_plugin_) // Lazily initialize bitmap. |
(...skipping 15 matching lines...) Expand all Loading... | |
623 fullscreen_container_->InvalidateRect(rect); | 623 fullscreen_container_->InvalidateRect(rect); |
624 } else { | 624 } else { |
625 if (!container_ || | 625 if (!container_ || |
626 view_data_.rect.size.width == 0 || view_data_.rect.size.height == 0) | 626 view_data_.rect.size.width == 0 || view_data_.rect.size.height == 0) |
627 return; // Nothing to do. | 627 return; // Nothing to do. |
628 if (rect.IsEmpty()) | 628 if (rect.IsEmpty()) |
629 container_->invalidate(); | 629 container_->invalidate(); |
630 else | 630 else |
631 container_->invalidateRect(rect); | 631 container_->invalidateRect(rect); |
632 } | 632 } |
633 if (texture_layer_) | |
634 texture_layer_->SetNeedsDisplay(); | |
piman
2013/09/09 20:42:53
could we do SetNeedsDisplayRect when !rect.IsEmpty
| |
633 } | 635 } |
634 | 636 |
635 void PepperPluginInstanceImpl::ScrollRect(int dx, | 637 void PepperPluginInstanceImpl::ScrollRect(int dx, |
636 int dy, | 638 int dy, |
637 const gfx::Rect& rect) { | 639 const gfx::Rect& rect) { |
638 if (fullscreen_container_) { | 640 if (fullscreen_container_) { |
639 fullscreen_container_->ScrollRect(dx, dy, rect); | 641 fullscreen_container_->ScrollRect(dx, dy, rect); |
640 } else { | 642 } else { |
641 if (full_frame_ && !IsViewAccelerated()) { | 643 if (full_frame_ && !IsViewAccelerated()) { |
642 container_->scrollRect(dx, dy, rect); | 644 container_->scrollRect(dx, dy, rect); |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1658 bool flash_fullscreen) { | 1660 bool flash_fullscreen) { |
1659 bool is_mouselock_pending = TrackedCallback::IsPending(lock_mouse_callback_); | 1661 bool is_mouselock_pending = TrackedCallback::IsPending(lock_mouse_callback_); |
1660 | 1662 |
1661 if (flash_fullscreen == flash_fullscreen_) { | 1663 if (flash_fullscreen == flash_fullscreen_) { |
1662 // Manually clear callback when fullscreen fails with mouselock pending. | 1664 // Manually clear callback when fullscreen fails with mouselock pending. |
1663 if (!flash_fullscreen && is_mouselock_pending) | 1665 if (!flash_fullscreen && is_mouselock_pending) |
1664 lock_mouse_callback_->Run(PP_ERROR_FAILED); | 1666 lock_mouse_callback_->Run(PP_ERROR_FAILED); |
1665 return; | 1667 return; |
1666 } | 1668 } |
1667 | 1669 |
1668 PPB_Graphics3D_Impl* graphics_3d = bound_graphics_3d_.get(); | 1670 UpdateLayer(); |
1669 if (graphics_3d) | |
1670 UpdateLayer(); | |
1671 | 1671 |
1672 bool old_plugin_focus = PluginHasFocus(); | 1672 bool old_plugin_focus = PluginHasFocus(); |
1673 flash_fullscreen_ = flash_fullscreen; | 1673 flash_fullscreen_ = flash_fullscreen; |
1674 if (is_mouselock_pending && !IsMouseLocked()) { | 1674 if (is_mouselock_pending && !IsMouseLocked()) { |
1675 if (!IsProcessingUserGesture() && | 1675 if (!IsProcessingUserGesture() && |
1676 !module_->permissions().HasPermission( | 1676 !module_->permissions().HasPermission( |
1677 ppapi::PERMISSION_BYPASS_USER_GESTURE)) { | 1677 ppapi::PERMISSION_BYPASS_USER_GESTURE)) { |
1678 lock_mouse_callback_->Run(PP_ERROR_NO_USER_GESTURE); | 1678 lock_mouse_callback_->Run(PP_ERROR_NO_USER_GESTURE); |
1679 } else { | 1679 } else { |
1680 // Open a user gesture here so the Webkit user gesture checks will succeed | 1680 // Open a user gesture here so the Webkit user gesture checks will succeed |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1800 | 1800 |
1801 void PepperPluginInstanceImpl::UpdateLayer() { | 1801 void PepperPluginInstanceImpl::UpdateLayer() { |
1802 if (!container_) | 1802 if (!container_) |
1803 return; | 1803 return; |
1804 | 1804 |
1805 gpu::Mailbox mailbox; | 1805 gpu::Mailbox mailbox; |
1806 if (bound_graphics_3d_.get()) { | 1806 if (bound_graphics_3d_.get()) { |
1807 PlatformContext3D* context = bound_graphics_3d_->platform_context(); | 1807 PlatformContext3D* context = bound_graphics_3d_->platform_context(); |
1808 context->GetBackingMailbox(&mailbox); | 1808 context->GetBackingMailbox(&mailbox); |
1809 } | 1809 } |
1810 bool want_layer = !mailbox.IsZero(); | 1810 bool want_3d_layer = !mailbox.IsZero(); |
1811 bool want_2d_layer = bound_graphics_2d_platform_ && | |
1812 CommandLine::ForCurrentProcess()->HasSwitch( | |
1813 switches::kEnableSoftwareCompositing); | |
1814 bool want_layer = want_3d_layer || want_2d_layer; | |
1811 | 1815 |
1812 if (want_layer == !!texture_layer_.get() && | 1816 if ((want_layer == !!texture_layer_.get()) && |
1817 (want_3d_layer == layer_is_hardware_) && | |
1813 layer_bound_to_fullscreen_ == !!fullscreen_container_) | 1818 layer_bound_to_fullscreen_ == !!fullscreen_container_) |
1814 return; | 1819 return; |
1815 | 1820 |
1816 if (texture_layer_.get()) { | 1821 if (texture_layer_) { |
1817 if (!layer_bound_to_fullscreen_) | 1822 if (!layer_bound_to_fullscreen_) |
1818 container_->setWebLayer(NULL); | 1823 container_->setWebLayer(NULL); |
1819 else if (fullscreen_container_) | 1824 else if (fullscreen_container_) |
1820 fullscreen_container_->SetLayer(NULL); | 1825 fullscreen_container_->SetLayer(NULL); |
1821 web_layer_.reset(); | 1826 web_layer_.reset(); |
1822 texture_layer_ = NULL; | 1827 texture_layer_ = NULL; |
1823 } | 1828 } |
1824 if (want_layer) { | 1829 if (want_layer) { |
1825 DCHECK(bound_graphics_3d_.get()); | 1830 bool opaque; |
piman
2013/09/09 20:42:53
nit: = false
| |
1826 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); | 1831 if (want_3d_layer) { |
1832 DCHECK(bound_graphics_3d_.get()); | |
1833 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); | |
1834 opaque = bound_graphics_3d_->IsOpaque(); | |
1835 texture_layer_->SetTextureMailbox( | |
1836 cc::TextureMailbox(mailbox, base::Bind(&IgnoreCallback), 0)); | |
1837 } else { | |
1838 DCHECK(bound_graphics_2d_platform_); | |
1839 texture_layer_ = cc::TextureLayer::CreateForMailbox(this); | |
1840 bound_graphics_2d_platform_->AttachedToNewLayer(); | |
1841 opaque = bound_graphics_2d_platform_->IsAlwaysOpaque(); | |
1842 texture_layer_->SetFlipped(false); | |
1843 } | |
1827 web_layer_.reset(new webkit::WebLayerImpl(texture_layer_)); | 1844 web_layer_.reset(new webkit::WebLayerImpl(texture_layer_)); |
1828 if (fullscreen_container_) { | 1845 if (fullscreen_container_) { |
1829 fullscreen_container_->SetLayer(web_layer_.get()); | 1846 fullscreen_container_->SetLayer(web_layer_.get()); |
1830 // Ignore transparency in fullscreen, since that's what Flash always | 1847 // Ignore transparency in fullscreen, since that's what Flash always |
1831 // wants to do, and that lets it not recreate a context if | 1848 // wants to do, and that lets it not recreate a context if |
1832 // wmode=transparent was specified. | 1849 // wmode=transparent was specified. |
1833 texture_layer_->SetContentsOpaque(true); | 1850 texture_layer_->SetContentsOpaque(true); |
1834 } else { | 1851 } else { |
1835 container_->setWebLayer(web_layer_.get()); | 1852 container_->setWebLayer(web_layer_.get()); |
1836 texture_layer_->SetContentsOpaque(bound_graphics_3d_->IsOpaque()); | 1853 texture_layer_->SetContentsOpaque(opaque); |
1837 } | 1854 } |
1838 texture_layer_->SetTextureMailbox( | |
1839 cc::TextureMailbox(mailbox, base::Bind(&IgnoreCallback), 0)); | |
1840 } | 1855 } |
1841 layer_bound_to_fullscreen_ = !!fullscreen_container_; | 1856 layer_bound_to_fullscreen_ = !!fullscreen_container_; |
1857 layer_is_hardware_ = want_3d_layer; | |
1858 } | |
1859 | |
1860 unsigned PepperPluginInstanceImpl::PrepareTexture() { | |
1861 return 0; | |
1862 } | |
1863 | |
1864 WebKit::WebGraphicsContext3D* PepperPluginInstanceImpl::Context3d() { | |
1865 return NULL; | |
1866 } | |
1867 | |
1868 bool PepperPluginInstanceImpl::PrepareTextureMailbox( | |
1869 cc::TextureMailbox* mailbox, | |
1870 bool use_shared_memory) { | |
1871 if (!bound_graphics_2d_platform_) | |
1872 return false; | |
1873 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox); | |
1842 } | 1874 } |
1843 | 1875 |
1844 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) { | 1876 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) { |
1845 DCHECK(live_plugin_objects_.find(plugin_object) == | 1877 DCHECK(live_plugin_objects_.find(plugin_object) == |
1846 live_plugin_objects_.end()); | 1878 live_plugin_objects_.end()); |
1847 live_plugin_objects_.insert(plugin_object); | 1879 live_plugin_objects_.insert(plugin_object); |
1848 } | 1880 } |
1849 | 1881 |
1850 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) { | 1882 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) { |
1851 // Don't actually verify that the object is in the set since during module | 1883 // Don't actually verify that the object is in the set since during module |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2906 // Running out-of-process. Initiate an IPC call to notify the plugin | 2938 // Running out-of-process. Initiate an IPC call to notify the plugin |
2907 // process. | 2939 // process. |
2908 ppapi::proxy::HostDispatcher* dispatcher = | 2940 ppapi::proxy::HostDispatcher* dispatcher = |
2909 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 2941 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
2910 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 2942 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
2911 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); | 2943 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); |
2912 } | 2944 } |
2913 } | 2945 } |
2914 | 2946 |
2915 } // namespace content | 2947 } // namespace content |
OLD | NEW |