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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 #include "webkit/plugins/ppapi/common.h" | 71 #include "webkit/plugins/ppapi/common.h" |
72 #include "webkit/plugins/ppapi/event_conversion.h" | 72 #include "webkit/plugins/ppapi/event_conversion.h" |
73 #include "webkit/plugins/ppapi/fullscreen_container.h" | 73 #include "webkit/plugins/ppapi/fullscreen_container.h" |
74 #include "webkit/plugins/ppapi/gfx_conversion.h" | 74 #include "webkit/plugins/ppapi/gfx_conversion.h" |
75 #include "webkit/plugins/ppapi/host_globals.h" | 75 #include "webkit/plugins/ppapi/host_globals.h" |
76 #include "webkit/plugins/ppapi/message_channel.h" | 76 #include "webkit/plugins/ppapi/message_channel.h" |
77 #include "webkit/plugins/ppapi/npapi_glue.h" | 77 #include "webkit/plugins/ppapi/npapi_glue.h" |
78 #include "webkit/plugins/ppapi/plugin_module.h" | 78 #include "webkit/plugins/ppapi/plugin_module.h" |
79 #include "webkit/plugins/ppapi/plugin_object.h" | 79 #include "webkit/plugins/ppapi/plugin_object.h" |
80 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 80 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
81 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | |
82 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" | 81 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
83 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 82 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
84 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" | 83 #include "webkit/plugins/ppapi/ppb_url_loader_impl.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/ppapi/ppp_pdf.h" | 85 #include "webkit/plugins/ppapi/ppp_pdf.h" |
87 #include "webkit/plugins/sad_plugin.h" | 86 #include "webkit/plugins/sad_plugin.h" |
88 | 87 |
89 #if defined(OS_MACOSX) | 88 #if defined(OS_MACOSX) |
90 #include "printing/metafile_impl.h" | 89 #include "printing/metafile_impl.h" |
91 #if !defined(USE_SKIA) | 90 #if !defined(USE_SKIA) |
(...skipping 15 matching lines...) Expand all Loading... | |
107 #include "ui/gfx/codec/jpeg_codec.h" | 106 #include "ui/gfx/codec/jpeg_codec.h" |
108 #include "ui/gfx/gdi_util.h" | 107 #include "ui/gfx/gdi_util.h" |
109 #endif | 108 #endif |
110 | 109 |
111 using base::StringPrintf; | 110 using base::StringPrintf; |
112 using ppapi::InputEventData; | 111 using ppapi::InputEventData; |
113 using ppapi::PpapiGlobals; | 112 using ppapi::PpapiGlobals; |
114 using ppapi::PPB_InputEvent_Shared; | 113 using ppapi::PPB_InputEvent_Shared; |
115 using ppapi::PPB_View_Shared; | 114 using ppapi::PPB_View_Shared; |
116 using ppapi::PPP_Instance_Combined; | 115 using ppapi::PPP_Instance_Combined; |
116 using ppapi::Resource; | |
117 using ppapi::ScopedPPResource; | 117 using ppapi::ScopedPPResource; |
118 using ppapi::StringVar; | 118 using ppapi::StringVar; |
119 using ppapi::TrackedCallback; | 119 using ppapi::TrackedCallback; |
120 using ppapi::thunk::EnterResourceNoLock; | 120 using ppapi::thunk::EnterResourceNoLock; |
121 using ppapi::thunk::PPB_Buffer_API; | 121 using ppapi::thunk::PPB_Buffer_API; |
122 using ppapi::thunk::PPB_Graphics2D_API; | 122 using ppapi::thunk::PPB_Graphics2D_API; |
123 using ppapi::thunk::PPB_Graphics3D_API; | 123 using ppapi::thunk::PPB_Graphics3D_API; |
124 using ppapi::thunk::PPB_ImageData_API; | 124 using ppapi::thunk::PPB_ImageData_API; |
125 using ppapi::Var; | 125 using ppapi::Var; |
126 using ppapi::ArrayBufferVar; | 126 using ppapi::ArrayBufferVar; |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 PluginModule* module, | 411 PluginModule* module, |
412 ::ppapi::PPP_Instance_Combined* instance_interface) | 412 ::ppapi::PPP_Instance_Combined* instance_interface) |
413 : delegate_(delegate), | 413 : delegate_(delegate), |
414 module_(module), | 414 module_(module), |
415 instance_interface_(instance_interface), | 415 instance_interface_(instance_interface), |
416 pp_instance_(0), | 416 pp_instance_(0), |
417 container_(NULL), | 417 container_(NULL), |
418 full_frame_(false), | 418 full_frame_(false), |
419 sent_initial_did_change_view_(false), | 419 sent_initial_did_change_view_(false), |
420 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 420 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
421 graphics_2d_platform_(NULL), | |
421 has_webkit_focus_(false), | 422 has_webkit_focus_(false), |
422 has_content_area_focus_(false), | 423 has_content_area_focus_(false), |
423 find_identifier_(-1), | 424 find_identifier_(-1), |
424 plugin_decryption_interface_(NULL), | 425 plugin_decryption_interface_(NULL), |
425 plugin_find_interface_(NULL), | 426 plugin_find_interface_(NULL), |
426 plugin_input_event_interface_(NULL), | 427 plugin_input_event_interface_(NULL), |
427 plugin_messaging_interface_(NULL), | 428 plugin_messaging_interface_(NULL), |
428 plugin_mouse_lock_interface_(NULL), | 429 plugin_mouse_lock_interface_(NULL), |
429 plugin_pdf_interface_(NULL), | 430 plugin_pdf_interface_(NULL), |
430 plugin_private_interface_(NULL), | 431 plugin_private_interface_(NULL), |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); | 532 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); |
532 if (module()->is_crashed()) { | 533 if (module()->is_crashed()) { |
533 // Crashed plugin painting. | 534 // Crashed plugin painting. |
534 if (!sad_plugin_) // Lazily initialize bitmap. | 535 if (!sad_plugin_) // Lazily initialize bitmap. |
535 sad_plugin_ = delegate_->GetSadPluginBitmap(); | 536 sad_plugin_ = delegate_->GetSadPluginBitmap(); |
536 if (sad_plugin_) | 537 if (sad_plugin_) |
537 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_); | 538 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_); |
538 return; | 539 return; |
539 } | 540 } |
540 | 541 |
541 PPB_Graphics2D_Impl* bound_graphics_2d = GetBoundGraphics2D(); | 542 PluginDelegate::PlatformGraphics2D* bound_graphics_2d = GetBoundGraphics2D(); |
542 if (bound_graphics_2d) | 543 if (bound_graphics_2d) |
543 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect); | 544 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect); |
544 } | 545 } |
545 | 546 |
546 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { | 547 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { |
547 if (fullscreen_container_) { | 548 if (fullscreen_container_) { |
548 if (rect.IsEmpty()) | 549 if (rect.IsEmpty()) |
549 fullscreen_container_->Invalidate(); | 550 fullscreen_container_->Invalidate(); |
550 else | 551 else |
551 fullscreen_container_->InvalidateRect(rect); | 552 fullscreen_container_->InvalidateRect(rect); |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
990 } | 991 } |
991 | 992 |
992 bool PluginInstance::GetBitmapForOptimizedPluginPaint( | 993 bool PluginInstance::GetBitmapForOptimizedPluginPaint( |
993 const gfx::Rect& paint_bounds, | 994 const gfx::Rect& paint_bounds, |
994 TransportDIB** dib, | 995 TransportDIB** dib, |
995 gfx::Rect* location, | 996 gfx::Rect* location, |
996 gfx::Rect* clip, | 997 gfx::Rect* clip, |
997 float* scale_factor) { | 998 float* scale_factor) { |
998 if (!always_on_top_) | 999 if (!always_on_top_) |
999 return false; | 1000 return false; |
1000 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->is_always_opaque()) | 1001 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->IsAlwaysOpaque()) |
1001 return false; | 1002 return false; |
1002 | 1003 |
1003 // We specifically want to compare against the area covered by the backing | 1004 // We specifically want to compare against the area covered by the backing |
1004 // store when seeing if we cover the given paint bounds, since the backing | 1005 // store when seeing if we cover the given paint bounds, since the backing |
1005 // store could be smaller than the declared plugin area. | 1006 // store could be smaller than the declared plugin area. |
1006 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->image_data(); | 1007 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->ImageData(); |
1007 // ImageDatas created by NaCl don't have a PlatformImage, so can't be | 1008 // ImageDatas created by NaCl don't have a PlatformImage, so can't be |
1008 // optimized this way. | 1009 // optimized this way. |
1009 if (!image_data->PlatformImage()) | 1010 if (!image_data->PlatformImage()) |
1010 return false; | 1011 return false; |
1011 | 1012 |
1012 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point); | 1013 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point); |
1013 // Convert |paint_bounds| to be relative to the left-top corner of the plugin. | 1014 // Convert |paint_bounds| to be relative to the left-top corner of the plugin. |
1014 gfx::Rect relative_paint_bounds(paint_bounds); | 1015 gfx::Rect relative_paint_bounds(paint_bounds); |
1015 relative_paint_bounds.Offset(-plugin_origin.x(), -plugin_origin.y()); | 1016 relative_paint_bounds.Offset(-plugin_origin.x(), -plugin_origin.y()); |
1016 | 1017 |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1878 skia::EndPlatformPaint(canvas); | 1879 skia::EndPlatformPaint(canvas); |
1879 } | 1880 } |
1880 #endif // defined(OS_WIN) | 1881 #endif // defined(OS_WIN) |
1881 | 1882 |
1882 return ret; | 1883 return ret; |
1883 #else // defined(ENABLE_PRINTING) | 1884 #else // defined(ENABLE_PRINTING) |
1884 return false; | 1885 return false; |
1885 #endif | 1886 #endif |
1886 } | 1887 } |
1887 | 1888 |
1888 PPB_Graphics2D_Impl* PluginInstance::GetBoundGraphics2D() const { | 1889 PluginDelegate::PlatformGraphics2D* PluginInstance::GetBoundGraphics2D() const { |
1889 if (bound_graphics_.get() == NULL) | 1890 return graphics_2d_platform_; |
1891 } | |
1892 | |
1893 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { | |
1894 if (bound_graphics_3d_.get() == NULL) | |
1890 return NULL; | 1895 return NULL; |
1891 | 1896 |
1892 if (bound_graphics_->AsPPB_Graphics2D_API()) | 1897 if (bound_graphics_3d_->AsPPB_Graphics3D_API()) |
brettw
2012/10/09 20:47:13
This if shouldn't be necessary since it should't g
victorhsieh
2012/10/11 22:56:23
Done.
| |
1893 return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get()); | 1898 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_3d_.get()); |
1894 return NULL; | 1899 return NULL; |
1895 } | 1900 } |
1896 | 1901 |
1897 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { | |
1898 if (bound_graphics_.get() == NULL) | |
1899 return NULL; | |
1900 | |
1901 if (bound_graphics_->AsPPB_Graphics3D_API()) | |
1902 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_.get()); | |
1903 return NULL; | |
1904 } | |
1905 | |
1906 void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) { | 1902 void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) { |
1907 // If we have a fullscreen_container_ (under PPB_FlashFullscreen) | 1903 // If we have a fullscreen_container_ (under PPB_FlashFullscreen) |
1908 // or desired_fullscreen_state is true (under PPB_Fullscreen), | 1904 // or desired_fullscreen_state is true (under PPB_Fullscreen), |
1909 // then the plugin is fullscreen or transitioning to fullscreen | 1905 // then the plugin is fullscreen or transitioning to fullscreen |
1910 // and the parent context is not the one for the browser page, | 1906 // and the parent context is not the one for the browser page, |
1911 // but for the fullscreen window, and so the parent texture ID | 1907 // but for the fullscreen window, and so the parent texture ID |
1912 // doesn't correspond to anything in the page's context. | 1908 // doesn't correspond to anything in the page's context. |
1913 // | 1909 // |
1914 // TODO(alokp): It would be better at some point to have the equivalent | 1910 // TODO(alokp): It would be better at some point to have the equivalent |
1915 // in the FullscreenContainer so that we don't need to poll | 1911 // in the FullscreenContainer so that we don't need to poll |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2040 // Do nothing so that the pending user gesture will stay open for | 2036 // Do nothing so that the pending user gesture will stay open for |
2041 // kUserGestureDurationInSeconds. | 2037 // kUserGestureDurationInSeconds. |
2042 // TODO(yzshen): remove the code for closing pending user gesture. | 2038 // TODO(yzshen): remove the code for closing pending user gesture. |
2043 } | 2039 } |
2044 | 2040 |
2045 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, | 2041 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, |
2046 PP_Resource device) { | 2042 PP_Resource device) { |
2047 TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics"); | 2043 TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics"); |
2048 // The Graphics3D instance can't be destroyed until we call | 2044 // The Graphics3D instance can't be destroyed until we call |
2049 // setBackingTextureId. | 2045 // setBackingTextureId. |
2050 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_; | 2046 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_3d_; |
2051 if (bound_graphics_.get()) { | 2047 if (bound_graphics_3d_.get()) { |
2052 if (GetBoundGraphics2D()) { | 2048 if (GetBoundGraphics3D()) { |
2053 GetBoundGraphics2D()->BindToInstance(NULL); | |
2054 } else if (GetBoundGraphics3D()) { | |
2055 GetBoundGraphics3D()->BindToInstance(false); | 2049 GetBoundGraphics3D()->BindToInstance(false); |
2056 } | 2050 } |
2057 bound_graphics_ = NULL; | 2051 bound_graphics_3d_ = NULL; |
2052 } | |
2053 if (graphics_2d_platform_) { | |
2054 GetBoundGraphics2D()->BindToInstance(NULL); | |
2055 graphics_2d_platform_ = NULL; | |
2058 } | 2056 } |
2059 | 2057 |
2060 // Special-case clearing the current device. | 2058 // Special-case clearing the current device. |
2061 if (!device) { | 2059 if (!device) { |
2062 setBackingTextureId(0, false); | 2060 setBackingTextureId(0, false); |
2063 InvalidateRect(gfx::Rect()); | 2061 InvalidateRect(gfx::Rect()); |
2064 return PP_TRUE; | 2062 return PP_TRUE; |
2065 } | 2063 } |
2066 | 2064 |
2067 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or | 2065 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or |
2068 // to/from fullscreen with PPB_Fullscreen. | 2066 // to/from fullscreen with PPB_Fullscreen. |
2069 if ((fullscreen_container_ && !flash_fullscreen_) || | 2067 if ((fullscreen_container_ && !flash_fullscreen_) || |
2070 desired_fullscreen_state_ != view_data_.is_fullscreen) | 2068 desired_fullscreen_state_ != view_data_.is_fullscreen) |
2071 return PP_FALSE; | 2069 return PP_FALSE; |
2072 | 2070 |
2073 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); | 2071 graphics_2d_platform_ = delegate_->GetGraphics2D(this, device); |
2074 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ? | |
2075 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL; | |
2076 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); | 2072 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); |
2077 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? | 2073 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? |
2078 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; | 2074 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; |
2079 | 2075 |
2080 if (graphics_2d) { | 2076 if (graphics_2d_platform_) { |
2081 if (graphics_2d->pp_instance() != pp_instance()) | 2077 if (!graphics_2d_platform_->BindToInstance(this)) |
2082 return PP_FALSE; // Can't bind other instance's contexts. | |
2083 if (!graphics_2d->BindToInstance(this)) | |
2084 return PP_FALSE; // Can't bind to more than one instance. | 2078 return PP_FALSE; // Can't bind to more than one instance. |
2085 | 2079 |
2086 bound_graphics_ = graphics_2d; | 2080 setBackingTextureId(0, graphics_2d_platform_->IsAlwaysOpaque()); |
2087 setBackingTextureId(0, graphics_2d->is_always_opaque()); | |
2088 // BindToInstance will have invalidated the plugin if necessary. | 2081 // BindToInstance will have invalidated the plugin if necessary. |
2089 } else if (graphics_3d) { | 2082 } else if (graphics_3d) { |
2090 // Make sure graphics can only be bound to the instance it is | 2083 // Make sure graphics can only be bound to the instance it is |
2091 // associated with. | 2084 // associated with. |
2092 if (graphics_3d->pp_instance() != pp_instance()) | 2085 if (graphics_3d->pp_instance() != pp_instance()) |
2093 return PP_FALSE; | 2086 return PP_FALSE; |
2094 if (!graphics_3d->BindToInstance(true)) | 2087 if (!graphics_3d->BindToInstance(true)) |
2095 return PP_FALSE; | 2088 return PP_FALSE; |
2096 | 2089 |
2097 bound_graphics_ = graphics_3d; | 2090 bound_graphics_3d_ = graphics_3d; |
2098 setBackingTextureId(graphics_3d->GetBackingTextureId(), | 2091 setBackingTextureId(graphics_3d->GetBackingTextureId(), |
2099 graphics_3d->IsOpaque()); | 2092 graphics_3d->IsOpaque()); |
2100 } else { | 2093 } else { |
2101 // The device is not a valid resource type. | 2094 // The device is not a valid resource type. |
2102 return PP_FALSE; | 2095 return PP_FALSE; |
2103 } | 2096 } |
2104 | 2097 |
2105 return PP_TRUE; | 2098 return PP_TRUE; |
2106 } | 2099 } |
2107 | 2100 |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2708 screen_size_for_fullscreen_ = gfx::Size(); | 2701 screen_size_for_fullscreen_ = gfx::Size(); |
2709 WebElement element = container_->element(); | 2702 WebElement element = container_->element(); |
2710 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2703 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2711 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2704 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2712 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2705 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2713 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2706 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2714 } | 2707 } |
2715 | 2708 |
2716 } // namespace ppapi | 2709 } // namespace ppapi |
2717 } // namespace webkit | 2710 } // namespace webkit |
OLD | NEW |