OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/ppb_widget_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_widget_impl.h" |
6 | 6 |
7 #include "base/logging.h" | |
8 #include "ppapi/c/dev/ppb_widget_dev.h" | |
9 #include "ppapi/c/dev/ppp_widget_dev.h" | 7 #include "ppapi/c/dev/ppp_widget_dev.h" |
10 #include "ppapi/c/pp_completion_callback.h" | 8 #include "ppapi/thunk/enter.h" |
11 #include "ppapi/c/pp_errors.h" | |
12 #include "webkit/plugins/ppapi/common.h" | |
13 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 9 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
15 #include "webkit/plugins/ppapi/plugin_module.h" | 11 #include "webkit/plugins/ppapi/plugin_module.h" |
16 | 12 |
| 13 using ppapi::thunk::EnterResourceNoLock; |
| 14 using ppapi::thunk::PPB_ImageData_API; |
| 15 using ppapi::thunk::PPB_Widget_API; |
| 16 |
17 namespace webkit { | 17 namespace webkit { |
18 namespace ppapi { | 18 namespace ppapi { |
19 | 19 |
20 namespace { | |
21 | |
22 PP_Bool IsWidget(PP_Resource resource) { | |
23 return BoolToPPBool(!!Resource::GetAs<PPB_Widget_Impl>(resource)); | |
24 } | |
25 | |
26 PP_Bool Paint(PP_Resource resource, | |
27 const PP_Rect* rect, | |
28 PP_Resource image_id) { | |
29 scoped_refptr<PPB_Widget_Impl> widget( | |
30 Resource::GetAs<PPB_Widget_Impl>(resource)); | |
31 if (!widget) | |
32 return PP_FALSE; | |
33 | |
34 scoped_refptr<PPB_ImageData_Impl> image( | |
35 Resource::GetAs<PPB_ImageData_Impl>(image_id)); | |
36 if (!image) | |
37 return PP_FALSE; | |
38 | |
39 return BoolToPPBool(widget->Paint(rect, image)); | |
40 } | |
41 | |
42 PP_Bool HandleEvent(PP_Resource resource, const PP_InputEvent* event) { | |
43 scoped_refptr<PPB_Widget_Impl> widget( | |
44 Resource::GetAs<PPB_Widget_Impl>(resource)); | |
45 return BoolToPPBool(widget && widget->HandleEvent(event)); | |
46 } | |
47 | |
48 PP_Bool GetLocation(PP_Resource resource, PP_Rect* location) { | |
49 scoped_refptr<PPB_Widget_Impl> widget( | |
50 Resource::GetAs<PPB_Widget_Impl>(resource)); | |
51 return BoolToPPBool(widget && widget->GetLocation(location)); | |
52 } | |
53 | |
54 void SetLocation(PP_Resource resource, const PP_Rect* location) { | |
55 scoped_refptr<PPB_Widget_Impl> widget( | |
56 Resource::GetAs<PPB_Widget_Impl>(resource)); | |
57 if (widget) | |
58 widget->SetLocation(location); | |
59 } | |
60 | |
61 const PPB_Widget_Dev ppb_widget = { | |
62 &IsWidget, | |
63 &Paint, | |
64 &HandleEvent, | |
65 &GetLocation, | |
66 &SetLocation, | |
67 }; | |
68 | |
69 } // namespace | |
70 | |
71 PPB_Widget_Impl::PPB_Widget_Impl(PluginInstance* instance) | 20 PPB_Widget_Impl::PPB_Widget_Impl(PluginInstance* instance) |
72 : Resource(instance) { | 21 : Resource(instance) { |
73 } | 22 } |
74 | 23 |
75 PPB_Widget_Impl::~PPB_Widget_Impl() { | 24 PPB_Widget_Impl::~PPB_Widget_Impl() { |
76 } | 25 } |
77 | 26 |
78 // static | 27 PPB_Widget_API* PPB_Widget_Impl::AsPPB_Widget_API() { |
79 const PPB_Widget_Dev* PPB_Widget_Impl::GetInterface() { | |
80 return &ppb_widget; | |
81 } | |
82 | |
83 PPB_Widget_Impl* PPB_Widget_Impl::AsPPB_Widget_Impl() { | |
84 return this; | 28 return this; |
85 } | 29 } |
86 | 30 |
87 bool PPB_Widget_Impl::GetLocation(PP_Rect* location) { | 31 PP_Bool PPB_Widget_Impl::Paint(const PP_Rect* rect, PP_Resource image_id) { |
| 32 EnterResourceNoLock<PPB_ImageData_API> enter(image_id, true); |
| 33 if (enter.failed()) |
| 34 return PP_FALSE; |
| 35 return PaintInternal(gfx::Rect(rect->point.x, rect->point.y, |
| 36 rect->size.width, rect->size.height), |
| 37 static_cast<PPB_ImageData_Impl*>(enter.object())); |
| 38 } |
| 39 |
| 40 PP_Bool PPB_Widget_Impl::GetLocation(PP_Rect* location) { |
88 *location = location_; | 41 *location = location_; |
89 return true; | 42 return PP_TRUE; |
90 } | 43 } |
91 | 44 |
92 void PPB_Widget_Impl::SetLocation(const PP_Rect* location) { | 45 void PPB_Widget_Impl::SetLocation(const PP_Rect* location) { |
93 location_ = *location; | 46 location_ = *location; |
94 SetLocationInternal(location); | 47 SetLocationInternal(location); |
95 } | 48 } |
96 | 49 |
97 void PPB_Widget_Impl::Invalidate(const PP_Rect* dirty) { | 50 void PPB_Widget_Impl::Invalidate(const PP_Rect* dirty) { |
98 const PPP_Widget_Dev* widget = static_cast<const PPP_Widget_Dev*>( | 51 const PPP_Widget_Dev* widget = static_cast<const PPP_Widget_Dev*>( |
99 instance()->module()->GetPluginInterface(PPP_WIDGET_DEV_INTERFACE)); | 52 instance()->module()->GetPluginInterface(PPP_WIDGET_DEV_INTERFACE)); |
100 if (!widget) | 53 if (!widget) |
101 return; | 54 return; |
102 ScopedResourceId resource(this); | 55 ScopedResourceId resource(this); |
103 widget->Invalidate(instance()->pp_instance(), resource.id, dirty); | 56 widget->Invalidate(instance()->pp_instance(), resource.id, dirty); |
104 } | 57 } |
105 | 58 |
106 } // namespace ppapi | 59 } // namespace ppapi |
107 } // namespace webkit | 60 } // namespace webkit |
108 | 61 |
OLD | NEW |