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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 #include "webkit/plugins/ppapi/common.h" | 73 #include "webkit/plugins/ppapi/common.h" |
74 #include "webkit/plugins/ppapi/event_conversion.h" | 74 #include "webkit/plugins/ppapi/event_conversion.h" |
75 #include "webkit/plugins/ppapi/fullscreen_container.h" | 75 #include "webkit/plugins/ppapi/fullscreen_container.h" |
76 #include "webkit/plugins/ppapi/gfx_conversion.h" | 76 #include "webkit/plugins/ppapi/gfx_conversion.h" |
77 #include "webkit/plugins/ppapi/host_globals.h" | 77 #include "webkit/plugins/ppapi/host_globals.h" |
78 #include "webkit/plugins/ppapi/message_channel.h" | 78 #include "webkit/plugins/ppapi/message_channel.h" |
79 #include "webkit/plugins/ppapi/npapi_glue.h" | 79 #include "webkit/plugins/ppapi/npapi_glue.h" |
80 #include "webkit/plugins/ppapi/plugin_module.h" | 80 #include "webkit/plugins/ppapi/plugin_module.h" |
81 #include "webkit/plugins/ppapi/plugin_object.h" | 81 #include "webkit/plugins/ppapi/plugin_object.h" |
82 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 82 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
83 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | |
84 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" | 83 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
85 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 84 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
86 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" | 85 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" |
87 #include "webkit/plugins/ppapi/url_request_info_util.h" | 86 #include "webkit/plugins/ppapi/url_request_info_util.h" |
88 #include "webkit/plugins/ppapi/ppp_pdf.h" | 87 #include "webkit/plugins/ppapi/ppp_pdf.h" |
89 #include "webkit/plugins/sad_plugin.h" | 88 #include "webkit/plugins/sad_plugin.h" |
90 | 89 |
91 #if defined(OS_MACOSX) | 90 #if defined(OS_MACOSX) |
92 #include "printing/metafile_impl.h" | 91 #include "printing/metafile_impl.h" |
93 #if !defined(USE_SKIA) | 92 #if !defined(USE_SKIA) |
(...skipping 15 matching lines...) Expand all Loading... |
109 #include "ui/gfx/codec/jpeg_codec.h" | 108 #include "ui/gfx/codec/jpeg_codec.h" |
110 #include "ui/gfx/gdi_util.h" | 109 #include "ui/gfx/gdi_util.h" |
111 #endif | 110 #endif |
112 | 111 |
113 using base::StringPrintf; | 112 using base::StringPrintf; |
114 using ppapi::InputEventData; | 113 using ppapi::InputEventData; |
115 using ppapi::PpapiGlobals; | 114 using ppapi::PpapiGlobals; |
116 using ppapi::PPB_InputEvent_Shared; | 115 using ppapi::PPB_InputEvent_Shared; |
117 using ppapi::PPB_View_Shared; | 116 using ppapi::PPB_View_Shared; |
118 using ppapi::PPP_Instance_Combined; | 117 using ppapi::PPP_Instance_Combined; |
| 118 using ppapi::Resource; |
119 using ppapi::ScopedPPResource; | 119 using ppapi::ScopedPPResource; |
120 using ppapi::StringVar; | 120 using ppapi::StringVar; |
121 using ppapi::TrackedCallback; | 121 using ppapi::TrackedCallback; |
122 using ppapi::thunk::EnterResourceNoLock; | 122 using ppapi::thunk::EnterResourceNoLock; |
123 using ppapi::thunk::PPB_Buffer_API; | 123 using ppapi::thunk::PPB_Buffer_API; |
124 using ppapi::thunk::PPB_Graphics2D_API; | 124 using ppapi::thunk::PPB_Graphics2D_API; |
125 using ppapi::thunk::PPB_Graphics3D_API; | 125 using ppapi::thunk::PPB_Graphics3D_API; |
126 using ppapi::thunk::PPB_ImageData_API; | 126 using ppapi::thunk::PPB_ImageData_API; |
127 using ppapi::Var; | 127 using ppapi::Var; |
128 using ppapi::ArrayBufferVar; | 128 using ppapi::ArrayBufferVar; |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 PluginModule* module, | 440 PluginModule* module, |
441 ::ppapi::PPP_Instance_Combined* instance_interface) | 441 ::ppapi::PPP_Instance_Combined* instance_interface) |
442 : delegate_(delegate), | 442 : delegate_(delegate), |
443 module_(module), | 443 module_(module), |
444 instance_interface_(instance_interface), | 444 instance_interface_(instance_interface), |
445 pp_instance_(0), | 445 pp_instance_(0), |
446 container_(NULL), | 446 container_(NULL), |
447 full_frame_(false), | 447 full_frame_(false), |
448 sent_initial_did_change_view_(false), | 448 sent_initial_did_change_view_(false), |
449 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 449 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 450 graphics_2d_platform_(NULL), |
450 has_webkit_focus_(false), | 451 has_webkit_focus_(false), |
451 has_content_area_focus_(false), | 452 has_content_area_focus_(false), |
452 find_identifier_(-1), | 453 find_identifier_(-1), |
453 plugin_decryption_interface_(NULL), | 454 plugin_decryption_interface_(NULL), |
454 plugin_find_interface_(NULL), | 455 plugin_find_interface_(NULL), |
455 plugin_input_event_interface_(NULL), | 456 plugin_input_event_interface_(NULL), |
456 plugin_messaging_interface_(NULL), | 457 plugin_messaging_interface_(NULL), |
457 plugin_mouse_lock_interface_(NULL), | 458 plugin_mouse_lock_interface_(NULL), |
458 plugin_pdf_interface_(NULL), | 459 plugin_pdf_interface_(NULL), |
459 plugin_private_interface_(NULL), | 460 plugin_private_interface_(NULL), |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); | 561 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); |
561 if (module()->is_crashed()) { | 562 if (module()->is_crashed()) { |
562 // Crashed plugin painting. | 563 // Crashed plugin painting. |
563 if (!sad_plugin_) // Lazily initialize bitmap. | 564 if (!sad_plugin_) // Lazily initialize bitmap. |
564 sad_plugin_ = delegate_->GetSadPluginBitmap(); | 565 sad_plugin_ = delegate_->GetSadPluginBitmap(); |
565 if (sad_plugin_) | 566 if (sad_plugin_) |
566 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_); | 567 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_); |
567 return; | 568 return; |
568 } | 569 } |
569 | 570 |
570 PPB_Graphics2D_Impl* bound_graphics_2d = GetBoundGraphics2D(); | 571 PluginDelegate::PlatformGraphics2D* bound_graphics_2d = GetBoundGraphics2D(); |
571 if (bound_graphics_2d) | 572 if (bound_graphics_2d) |
572 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect); | 573 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect); |
573 } | 574 } |
574 | 575 |
575 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { | 576 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { |
576 if (fullscreen_container_) { | 577 if (fullscreen_container_) { |
577 if (rect.IsEmpty()) | 578 if (rect.IsEmpty()) |
578 fullscreen_container_->Invalidate(); | 579 fullscreen_container_->Invalidate(); |
579 else | 580 else |
580 fullscreen_container_->InvalidateRect(rect); | 581 fullscreen_container_->InvalidateRect(rect); |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 } | 1020 } |
1020 | 1021 |
1021 bool PluginInstance::GetBitmapForOptimizedPluginPaint( | 1022 bool PluginInstance::GetBitmapForOptimizedPluginPaint( |
1022 const gfx::Rect& paint_bounds, | 1023 const gfx::Rect& paint_bounds, |
1023 TransportDIB** dib, | 1024 TransportDIB** dib, |
1024 gfx::Rect* location, | 1025 gfx::Rect* location, |
1025 gfx::Rect* clip, | 1026 gfx::Rect* clip, |
1026 float* scale_factor) { | 1027 float* scale_factor) { |
1027 if (!always_on_top_) | 1028 if (!always_on_top_) |
1028 return false; | 1029 return false; |
1029 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->is_always_opaque()) | 1030 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->IsAlwaysOpaque()) |
1030 return false; | 1031 return false; |
1031 | 1032 |
1032 // We specifically want to compare against the area covered by the backing | 1033 // We specifically want to compare against the area covered by the backing |
1033 // store when seeing if we cover the given paint bounds, since the backing | 1034 // store when seeing if we cover the given paint bounds, since the backing |
1034 // store could be smaller than the declared plugin area. | 1035 // store could be smaller than the declared plugin area. |
1035 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->image_data(); | 1036 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->ImageData(); |
1036 // ImageDatas created by NaCl don't have a PlatformImage, so can't be | 1037 // ImageDatas created by NaCl don't have a PlatformImage, so can't be |
1037 // optimized this way. | 1038 // optimized this way. |
1038 if (!image_data->PlatformImage()) | 1039 if (!image_data->PlatformImage()) |
1039 return false; | 1040 return false; |
1040 | 1041 |
1041 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point); | 1042 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point); |
1042 // Convert |paint_bounds| to be relative to the left-top corner of the plugin. | 1043 // Convert |paint_bounds| to be relative to the left-top corner of the plugin. |
1043 gfx::Rect relative_paint_bounds(paint_bounds); | 1044 gfx::Rect relative_paint_bounds(paint_bounds); |
1044 relative_paint_bounds.Offset(-plugin_origin.x(), -plugin_origin.y()); | 1045 relative_paint_bounds.Offset(-plugin_origin.x(), -plugin_origin.y()); |
1045 | 1046 |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1960 skia::EndPlatformPaint(canvas); | 1961 skia::EndPlatformPaint(canvas); |
1961 } | 1962 } |
1962 #endif // defined(OS_WIN) | 1963 #endif // defined(OS_WIN) |
1963 | 1964 |
1964 return ret; | 1965 return ret; |
1965 #else // defined(ENABLE_PRINTING) | 1966 #else // defined(ENABLE_PRINTING) |
1966 return false; | 1967 return false; |
1967 #endif | 1968 #endif |
1968 } | 1969 } |
1969 | 1970 |
1970 PPB_Graphics2D_Impl* PluginInstance::GetBoundGraphics2D() const { | 1971 PluginDelegate::PlatformGraphics2D* PluginInstance::GetBoundGraphics2D() const { |
1971 if (bound_graphics_.get() == NULL) | 1972 return graphics_2d_platform_; |
1972 return NULL; | |
1973 | |
1974 if (bound_graphics_->AsPPB_Graphics2D_API()) | |
1975 return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get()); | |
1976 return NULL; | |
1977 } | 1973 } |
1978 | 1974 |
1979 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { | 1975 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { |
1980 if (bound_graphics_.get() == NULL) | 1976 if (bound_graphics_3d_.get() == NULL) |
1981 return NULL; | 1977 return NULL; |
1982 | 1978 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_3d_.get()); |
1983 if (bound_graphics_->AsPPB_Graphics3D_API()) | |
1984 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_.get()); | |
1985 return NULL; | |
1986 } | 1979 } |
1987 | 1980 |
1988 void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) { | 1981 void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) { |
1989 // If we have a fullscreen_container_ (under PPB_FlashFullscreen) | 1982 // If we have a fullscreen_container_ (under PPB_FlashFullscreen) |
1990 // or desired_fullscreen_state is true (under PPB_Fullscreen), | 1983 // or desired_fullscreen_state is true (under PPB_Fullscreen), |
1991 // then the plugin is fullscreen or transitioning to fullscreen | 1984 // then the plugin is fullscreen or transitioning to fullscreen |
1992 // and the parent context is not the one for the browser page, | 1985 // and the parent context is not the one for the browser page, |
1993 // but for the fullscreen window, and so the parent texture ID | 1986 // but for the fullscreen window, and so the parent texture ID |
1994 // doesn't correspond to anything in the page's context. | 1987 // doesn't correspond to anything in the page's context. |
1995 // | 1988 // |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2122 // Do nothing so that the pending user gesture will stay open for | 2115 // Do nothing so that the pending user gesture will stay open for |
2123 // kUserGestureDurationInSeconds. | 2116 // kUserGestureDurationInSeconds. |
2124 // TODO(yzshen): remove the code for closing pending user gesture. | 2117 // TODO(yzshen): remove the code for closing pending user gesture. |
2125 } | 2118 } |
2126 | 2119 |
2127 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, | 2120 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, |
2128 PP_Resource device) { | 2121 PP_Resource device) { |
2129 TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics"); | 2122 TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics"); |
2130 // The Graphics3D instance can't be destroyed until we call | 2123 // The Graphics3D instance can't be destroyed until we call |
2131 // setBackingTextureId. | 2124 // setBackingTextureId. |
2132 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_; | 2125 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_3d_; |
2133 if (bound_graphics_.get()) { | 2126 if (bound_graphics_3d_.get()) { |
2134 if (GetBoundGraphics2D()) { | 2127 if (GetBoundGraphics3D()) { |
2135 GetBoundGraphics2D()->BindToInstance(NULL); | |
2136 } else if (GetBoundGraphics3D()) { | |
2137 GetBoundGraphics3D()->BindToInstance(false); | 2128 GetBoundGraphics3D()->BindToInstance(false); |
2138 } | 2129 } |
2139 bound_graphics_ = NULL; | 2130 bound_graphics_3d_ = NULL; |
| 2131 } |
| 2132 if (graphics_2d_platform_) { |
| 2133 GetBoundGraphics2D()->BindToInstance(NULL); |
| 2134 graphics_2d_platform_ = NULL; |
2140 } | 2135 } |
2141 | 2136 |
2142 // Special-case clearing the current device. | 2137 // Special-case clearing the current device. |
2143 if (!device) { | 2138 if (!device) { |
2144 setBackingTextureId(0, false); | 2139 setBackingTextureId(0, false); |
2145 InvalidateRect(gfx::Rect()); | 2140 InvalidateRect(gfx::Rect()); |
2146 return PP_TRUE; | 2141 return PP_TRUE; |
2147 } | 2142 } |
2148 | 2143 |
2149 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or | 2144 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or |
2150 // to/from fullscreen with PPB_Fullscreen. | 2145 // to/from fullscreen with PPB_Fullscreen. |
2151 if ((fullscreen_container_ && !flash_fullscreen_) || | 2146 if ((fullscreen_container_ && !flash_fullscreen_) || |
2152 desired_fullscreen_state_ != view_data_.is_fullscreen) | 2147 desired_fullscreen_state_ != view_data_.is_fullscreen) |
2153 return PP_FALSE; | 2148 return PP_FALSE; |
2154 | 2149 |
2155 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); | 2150 graphics_2d_platform_ = delegate_->GetGraphics2D(this, device); |
2156 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ? | |
2157 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL; | |
2158 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); | 2151 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); |
2159 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? | 2152 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? |
2160 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; | 2153 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; |
2161 | 2154 |
2162 if (graphics_2d) { | 2155 if (graphics_2d_platform_) { |
2163 if (graphics_2d->pp_instance() != pp_instance()) | 2156 if (!graphics_2d_platform_->BindToInstance(this)) |
2164 return PP_FALSE; // Can't bind other instance's contexts. | |
2165 if (!graphics_2d->BindToInstance(this)) | |
2166 return PP_FALSE; // Can't bind to more than one instance. | 2157 return PP_FALSE; // Can't bind to more than one instance. |
2167 | 2158 |
2168 bound_graphics_ = graphics_2d; | 2159 setBackingTextureId(0, graphics_2d_platform_->IsAlwaysOpaque()); |
2169 setBackingTextureId(0, graphics_2d->is_always_opaque()); | |
2170 // BindToInstance will have invalidated the plugin if necessary. | 2160 // BindToInstance will have invalidated the plugin if necessary. |
2171 } else if (graphics_3d) { | 2161 } else if (graphics_3d) { |
2172 // Make sure graphics can only be bound to the instance it is | 2162 // Make sure graphics can only be bound to the instance it is |
2173 // associated with. | 2163 // associated with. |
2174 if (graphics_3d->pp_instance() != pp_instance()) | 2164 if (graphics_3d->pp_instance() != pp_instance()) |
2175 return PP_FALSE; | 2165 return PP_FALSE; |
2176 if (!graphics_3d->BindToInstance(true)) | 2166 if (!graphics_3d->BindToInstance(true)) |
2177 return PP_FALSE; | 2167 return PP_FALSE; |
2178 | 2168 |
2179 bound_graphics_ = graphics_3d; | 2169 bound_graphics_3d_ = graphics_3d; |
2180 setBackingTextureId(graphics_3d->GetBackingTextureId(), | 2170 setBackingTextureId(graphics_3d->GetBackingTextureId(), |
2181 graphics_3d->IsOpaque()); | 2171 graphics_3d->IsOpaque()); |
2182 } else { | 2172 } else { |
2183 // The device is not a valid resource type. | 2173 // The device is not a valid resource type. |
2184 return PP_FALSE; | 2174 return PP_FALSE; |
2185 } | 2175 } |
2186 | 2176 |
2187 return PP_TRUE; | 2177 return PP_TRUE; |
2188 } | 2178 } |
2189 | 2179 |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2831 screen_size_for_fullscreen_ = gfx::Size(); | 2821 screen_size_for_fullscreen_ = gfx::Size(); |
2832 WebElement element = container_->element(); | 2822 WebElement element = container_->element(); |
2833 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2823 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2834 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2824 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2835 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2825 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2836 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2826 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2837 } | 2827 } |
2838 | 2828 |
2839 } // namespace ppapi | 2829 } // namespace ppapi |
2840 } // namespace webkit | 2830 } // namespace webkit |
OLD | NEW |