| 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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 #include "webkit/plugins/ppapi/content_decryptor_delegate.h" | 70 #include "webkit/plugins/ppapi/content_decryptor_delegate.h" |
| 71 #include "webkit/plugins/ppapi/event_conversion.h" | 71 #include "webkit/plugins/ppapi/event_conversion.h" |
| 72 #include "webkit/plugins/ppapi/fullscreen_container.h" | 72 #include "webkit/plugins/ppapi/fullscreen_container.h" |
| 73 #include "webkit/plugins/ppapi/gfx_conversion.h" | 73 #include "webkit/plugins/ppapi/gfx_conversion.h" |
| 74 #include "webkit/plugins/ppapi/host_globals.h" | 74 #include "webkit/plugins/ppapi/host_globals.h" |
| 75 #include "webkit/plugins/ppapi/message_channel.h" | 75 #include "webkit/plugins/ppapi/message_channel.h" |
| 76 #include "webkit/plugins/ppapi/npapi_glue.h" | 76 #include "webkit/plugins/ppapi/npapi_glue.h" |
| 77 #include "webkit/plugins/ppapi/plugin_module.h" | 77 #include "webkit/plugins/ppapi/plugin_module.h" |
| 78 #include "webkit/plugins/ppapi/plugin_object.h" | 78 #include "webkit/plugins/ppapi/plugin_object.h" |
| 79 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 79 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
| 80 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | |
| 81 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" | 80 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
| 82 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 81 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 83 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" | 82 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" |
| 84 #include "webkit/plugins/ppapi/ppp_pdf.h" | 83 #include "webkit/plugins/ppapi/ppp_pdf.h" |
| 85 #include "webkit/plugins/ppapi/url_request_info_util.h" | 84 #include "webkit/plugins/ppapi/url_request_info_util.h" |
| 86 #include "webkit/plugins/sad_plugin.h" | 85 #include "webkit/plugins/sad_plugin.h" |
| 87 | 86 |
| 88 #if defined(OS_MACOSX) | 87 #if defined(OS_MACOSX) |
| 89 #include "printing/metafile_impl.h" | 88 #include "printing/metafile_impl.h" |
| 90 #if !defined(USE_SKIA) | 89 #if !defined(USE_SKIA) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 106 #include "ui/gfx/codec/jpeg_codec.h" | 105 #include "ui/gfx/codec/jpeg_codec.h" |
| 107 #include "ui/gfx/gdi_util.h" | 106 #include "ui/gfx/gdi_util.h" |
| 108 #endif | 107 #endif |
| 109 | 108 |
| 110 using base::StringPrintf; | 109 using base::StringPrintf; |
| 111 using ppapi::InputEventData; | 110 using ppapi::InputEventData; |
| 112 using ppapi::PpapiGlobals; | 111 using ppapi::PpapiGlobals; |
| 113 using ppapi::PPB_InputEvent_Shared; | 112 using ppapi::PPB_InputEvent_Shared; |
| 114 using ppapi::PPB_View_Shared; | 113 using ppapi::PPB_View_Shared; |
| 115 using ppapi::PPP_Instance_Combined; | 114 using ppapi::PPP_Instance_Combined; |
| 115 using ppapi::Resource; |
| 116 using ppapi::ScopedPPResource; | 116 using ppapi::ScopedPPResource; |
| 117 using ppapi::StringVar; | 117 using ppapi::StringVar; |
| 118 using ppapi::TrackedCallback; | 118 using ppapi::TrackedCallback; |
| 119 using ppapi::thunk::EnterResourceNoLock; | 119 using ppapi::thunk::EnterResourceNoLock; |
| 120 using ppapi::thunk::PPB_Buffer_API; | 120 using ppapi::thunk::PPB_Buffer_API; |
| 121 using ppapi::thunk::PPB_Graphics2D_API; | 121 using ppapi::thunk::PPB_Graphics2D_API; |
| 122 using ppapi::thunk::PPB_Graphics3D_API; | 122 using ppapi::thunk::PPB_Graphics3D_API; |
| 123 using ppapi::thunk::PPB_ImageData_API; | 123 using ppapi::thunk::PPB_ImageData_API; |
| 124 using ppapi::Var; | 124 using ppapi::Var; |
| 125 using ppapi::ArrayBufferVar; | 125 using ppapi::ArrayBufferVar; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 PluginModule* module, | 333 PluginModule* module, |
| 334 ::ppapi::PPP_Instance_Combined* instance_interface) | 334 ::ppapi::PPP_Instance_Combined* instance_interface) |
| 335 : delegate_(delegate), | 335 : delegate_(delegate), |
| 336 module_(module), | 336 module_(module), |
| 337 instance_interface_(instance_interface), | 337 instance_interface_(instance_interface), |
| 338 pp_instance_(0), | 338 pp_instance_(0), |
| 339 container_(NULL), | 339 container_(NULL), |
| 340 full_frame_(false), | 340 full_frame_(false), |
| 341 sent_initial_did_change_view_(false), | 341 sent_initial_did_change_view_(false), |
| 342 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 342 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 343 bound_graphics_2d_platform_(NULL), |
| 343 has_webkit_focus_(false), | 344 has_webkit_focus_(false), |
| 344 has_content_area_focus_(false), | 345 has_content_area_focus_(false), |
| 345 find_identifier_(-1), | 346 find_identifier_(-1), |
| 346 plugin_find_interface_(NULL), | 347 plugin_find_interface_(NULL), |
| 347 plugin_input_event_interface_(NULL), | 348 plugin_input_event_interface_(NULL), |
| 348 plugin_messaging_interface_(NULL), | 349 plugin_messaging_interface_(NULL), |
| 349 plugin_mouse_lock_interface_(NULL), | 350 plugin_mouse_lock_interface_(NULL), |
| 350 plugin_pdf_interface_(NULL), | 351 plugin_pdf_interface_(NULL), |
| 351 plugin_private_interface_(NULL), | 352 plugin_private_interface_(NULL), |
| 352 plugin_selection_interface_(NULL), | 353 plugin_selection_interface_(NULL), |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); | 451 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); |
| 451 if (module()->is_crashed()) { | 452 if (module()->is_crashed()) { |
| 452 // Crashed plugin painting. | 453 // Crashed plugin painting. |
| 453 if (!sad_plugin_) // Lazily initialize bitmap. | 454 if (!sad_plugin_) // Lazily initialize bitmap. |
| 454 sad_plugin_ = delegate_->GetSadPluginBitmap(); | 455 sad_plugin_ = delegate_->GetSadPluginBitmap(); |
| 455 if (sad_plugin_) | 456 if (sad_plugin_) |
| 456 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_); | 457 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_); |
| 457 return; | 458 return; |
| 458 } | 459 } |
| 459 | 460 |
| 460 PPB_Graphics2D_Impl* bound_graphics_2d = GetBoundGraphics2D(); | 461 PluginDelegate::PlatformGraphics2D* bound_graphics_2d = GetBoundGraphics2D(); |
| 461 if (bound_graphics_2d) | 462 if (bound_graphics_2d) |
| 462 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect); | 463 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect); |
| 463 } | 464 } |
| 464 | 465 |
| 465 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { | 466 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { |
| 466 if (fullscreen_container_) { | 467 if (fullscreen_container_) { |
| 467 if (rect.IsEmpty()) | 468 if (rect.IsEmpty()) |
| 468 fullscreen_container_->Invalidate(); | 469 fullscreen_container_->Invalidate(); |
| 469 else | 470 else |
| 470 fullscreen_container_->InvalidateRect(rect); | 471 fullscreen_container_->InvalidateRect(rect); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 } | 914 } |
| 914 | 915 |
| 915 bool PluginInstance::GetBitmapForOptimizedPluginPaint( | 916 bool PluginInstance::GetBitmapForOptimizedPluginPaint( |
| 916 const gfx::Rect& paint_bounds, | 917 const gfx::Rect& paint_bounds, |
| 917 TransportDIB** dib, | 918 TransportDIB** dib, |
| 918 gfx::Rect* location, | 919 gfx::Rect* location, |
| 919 gfx::Rect* clip, | 920 gfx::Rect* clip, |
| 920 float* scale_factor) { | 921 float* scale_factor) { |
| 921 if (!always_on_top_) | 922 if (!always_on_top_) |
| 922 return false; | 923 return false; |
| 923 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->is_always_opaque()) | 924 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->IsAlwaysOpaque()) |
| 924 return false; | 925 return false; |
| 925 | 926 |
| 926 // We specifically want to compare against the area covered by the backing | 927 // We specifically want to compare against the area covered by the backing |
| 927 // store when seeing if we cover the given paint bounds, since the backing | 928 // store when seeing if we cover the given paint bounds, since the backing |
| 928 // store could be smaller than the declared plugin area. | 929 // store could be smaller than the declared plugin area. |
| 929 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->image_data(); | 930 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->ImageData(); |
| 930 // ImageDatas created by NaCl don't have a PlatformImage, so can't be | 931 // ImageDatas created by NaCl don't have a PlatformImage, so can't be |
| 931 // optimized this way. | 932 // optimized this way. |
| 932 if (!image_data->PlatformImage()) | 933 if (!image_data->PlatformImage()) |
| 933 return false; | 934 return false; |
| 934 | 935 |
| 935 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point); | 936 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point); |
| 936 gfx::Vector2d plugin_offset = plugin_origin.OffsetFromOrigin(); | 937 gfx::Vector2d plugin_offset = plugin_origin.OffsetFromOrigin(); |
| 937 // Convert |paint_bounds| to be relative to the left-top corner of the plugin. | 938 // Convert |paint_bounds| to be relative to the left-top corner of the plugin. |
| 938 gfx::Rect relative_paint_bounds(paint_bounds); | 939 gfx::Rect relative_paint_bounds(paint_bounds); |
| 939 relative_paint_bounds.Offset(-plugin_offset); | 940 relative_paint_bounds.Offset(-plugin_offset); |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1674 skia::EndPlatformPaint(canvas); | 1675 skia::EndPlatformPaint(canvas); |
| 1675 } | 1676 } |
| 1676 #endif // defined(OS_WIN) | 1677 #endif // defined(OS_WIN) |
| 1677 | 1678 |
| 1678 return ret; | 1679 return ret; |
| 1679 #else // defined(ENABLE_PRINTING) | 1680 #else // defined(ENABLE_PRINTING) |
| 1680 return false; | 1681 return false; |
| 1681 #endif | 1682 #endif |
| 1682 } | 1683 } |
| 1683 | 1684 |
| 1684 PPB_Graphics2D_Impl* PluginInstance::GetBoundGraphics2D() const { | 1685 PluginDelegate::PlatformGraphics2D* PluginInstance::GetBoundGraphics2D() const { |
| 1685 if (bound_graphics_.get() == NULL) | 1686 return bound_graphics_2d_platform_; |
| 1686 return NULL; | |
| 1687 | |
| 1688 if (bound_graphics_->AsPPB_Graphics2D_API()) | |
| 1689 return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get()); | |
| 1690 return NULL; | |
| 1691 } | 1687 } |
| 1692 | 1688 |
| 1693 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { | 1689 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { |
| 1694 if (bound_graphics_.get() == NULL) | 1690 if (bound_graphics_3d_.get() == NULL) |
| 1695 return NULL; | 1691 return NULL; |
| 1696 | 1692 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_3d_.get()); |
| 1697 if (bound_graphics_->AsPPB_Graphics3D_API()) | |
| 1698 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_.get()); | |
| 1699 return NULL; | |
| 1700 } | 1693 } |
| 1701 | 1694 |
| 1702 void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) { | 1695 void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) { |
| 1703 // If we have a fullscreen_container_ (under PPB_FlashFullscreen) | 1696 // If we have a fullscreen_container_ (under PPB_FlashFullscreen) |
| 1704 // or desired_fullscreen_state is true (under PPB_Fullscreen), | 1697 // or desired_fullscreen_state is true (under PPB_Fullscreen), |
| 1705 // then the plugin is fullscreen or transitioning to fullscreen | 1698 // then the plugin is fullscreen or transitioning to fullscreen |
| 1706 // and the parent context is not the one for the browser page, | 1699 // and the parent context is not the one for the browser page, |
| 1707 // but for the fullscreen window, and so the parent texture ID | 1700 // but for the fullscreen window, and so the parent texture ID |
| 1708 // doesn't correspond to anything in the page's context. | 1701 // doesn't correspond to anything in the page's context. |
| 1709 // | 1702 // |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 // Do nothing so that the pending user gesture will stay open for | 1843 // Do nothing so that the pending user gesture will stay open for |
| 1851 // kUserGestureDurationInSeconds. | 1844 // kUserGestureDurationInSeconds. |
| 1852 // TODO(yzshen): remove the code for closing pending user gesture. | 1845 // TODO(yzshen): remove the code for closing pending user gesture. |
| 1853 } | 1846 } |
| 1854 | 1847 |
| 1855 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, | 1848 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, |
| 1856 PP_Resource device) { | 1849 PP_Resource device) { |
| 1857 TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics"); | 1850 TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics"); |
| 1858 // The Graphics3D instance can't be destroyed until we call | 1851 // The Graphics3D instance can't be destroyed until we call |
| 1859 // setBackingTextureId. | 1852 // setBackingTextureId. |
| 1860 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_; | 1853 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_3d_; |
| 1861 if (bound_graphics_.get()) { | 1854 if (bound_graphics_3d_.get()) { |
| 1862 if (GetBoundGraphics2D()) { | 1855 if (GetBoundGraphics3D()) { |
| 1863 GetBoundGraphics2D()->BindToInstance(NULL); | |
| 1864 } else if (GetBoundGraphics3D()) { | |
| 1865 GetBoundGraphics3D()->BindToInstance(false); | 1856 GetBoundGraphics3D()->BindToInstance(false); |
| 1866 } | 1857 } |
| 1867 bound_graphics_ = NULL; | 1858 bound_graphics_3d_ = NULL; |
| 1859 } |
| 1860 if (bound_graphics_2d_platform_) { |
| 1861 GetBoundGraphics2D()->BindToInstance(NULL); |
| 1862 bound_graphics_2d_platform_ = NULL; |
| 1868 } | 1863 } |
| 1869 | 1864 |
| 1870 // Special-case clearing the current device. | 1865 // Special-case clearing the current device. |
| 1871 if (!device) { | 1866 if (!device) { |
| 1872 setBackingTextureId(0, false); | 1867 setBackingTextureId(0, false); |
| 1873 InvalidateRect(gfx::Rect()); | 1868 InvalidateRect(gfx::Rect()); |
| 1874 return PP_TRUE; | 1869 return PP_TRUE; |
| 1875 } | 1870 } |
| 1876 | 1871 |
| 1877 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or | 1872 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or |
| 1878 // to/from fullscreen with PPB_Fullscreen. | 1873 // to/from fullscreen with PPB_Fullscreen. |
| 1879 if ((fullscreen_container_ && !flash_fullscreen_) || | 1874 if ((fullscreen_container_ && !flash_fullscreen_) || |
| 1880 desired_fullscreen_state_ != view_data_.is_fullscreen) | 1875 desired_fullscreen_state_ != view_data_.is_fullscreen) |
| 1881 return PP_FALSE; | 1876 return PP_FALSE; |
| 1882 | 1877 |
| 1883 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); | 1878 bound_graphics_2d_platform_ = delegate_->GetGraphics2D(this, device); |
| 1884 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ? | |
| 1885 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL; | |
| 1886 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); | 1879 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); |
| 1887 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? | 1880 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? |
| 1888 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; | 1881 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; |
| 1889 | 1882 |
| 1890 if (graphics_2d) { | 1883 if (bound_graphics_2d_platform_) { |
| 1891 if (graphics_2d->pp_instance() != pp_instance()) | 1884 if (!bound_graphics_2d_platform_->BindToInstance(this)) |
| 1892 return PP_FALSE; // Can't bind other instance's contexts. | |
| 1893 if (!graphics_2d->BindToInstance(this)) | |
| 1894 return PP_FALSE; // Can't bind to more than one instance. | 1885 return PP_FALSE; // Can't bind to more than one instance. |
| 1895 | 1886 |
| 1896 bound_graphics_ = graphics_2d; | 1887 setBackingTextureId(0, bound_graphics_2d_platform_->IsAlwaysOpaque()); |
| 1897 setBackingTextureId(0, graphics_2d->is_always_opaque()); | |
| 1898 // BindToInstance will have invalidated the plugin if necessary. | 1888 // BindToInstance will have invalidated the plugin if necessary. |
| 1899 } else if (graphics_3d) { | 1889 } else if (graphics_3d) { |
| 1900 // Make sure graphics can only be bound to the instance it is | 1890 // Make sure graphics can only be bound to the instance it is |
| 1901 // associated with. | 1891 // associated with. |
| 1902 if (graphics_3d->pp_instance() != pp_instance()) | 1892 if (graphics_3d->pp_instance() != pp_instance()) |
| 1903 return PP_FALSE; | 1893 return PP_FALSE; |
| 1904 if (!graphics_3d->BindToInstance(true)) | 1894 if (!graphics_3d->BindToInstance(true)) |
| 1905 return PP_FALSE; | 1895 return PP_FALSE; |
| 1906 | 1896 |
| 1907 bound_graphics_ = graphics_3d; | 1897 bound_graphics_3d_ = graphics_3d; |
| 1908 setBackingTextureId(graphics_3d->GetBackingTextureId(), | 1898 setBackingTextureId(graphics_3d->GetBackingTextureId(), |
| 1909 graphics_3d->IsOpaque()); | 1899 graphics_3d->IsOpaque()); |
| 1910 } else { | 1900 } else { |
| 1911 // The device is not a valid resource type. | 1901 // The device is not a valid resource type. |
| 1912 return PP_FALSE; | 1902 return PP_FALSE; |
| 1913 } | 1903 } |
| 1914 | 1904 |
| 1915 return PP_TRUE; | 1905 return PP_TRUE; |
| 1916 } | 1906 } |
| 1917 | 1907 |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2470 screen_size_for_fullscreen_ = gfx::Size(); | 2460 screen_size_for_fullscreen_ = gfx::Size(); |
| 2471 WebElement element = container_->element(); | 2461 WebElement element = container_->element(); |
| 2472 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2462 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
| 2473 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2463 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
| 2474 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2464 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
| 2475 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2465 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
| 2476 } | 2466 } |
| 2477 | 2467 |
| 2478 } // namespace ppapi | 2468 } // namespace ppapi |
| 2479 } // namespace webkit | 2469 } // namespace webkit |
| OLD | NEW |