OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/resource_creation_impl.h" | 5 #include "webkit/plugins/ppapi/resource_creation_impl.h" |
6 | 6 |
7 #include "ppapi/c/pp_size.h" | 7 #include "ppapi/c/pp_size.h" |
8 #include "ppapi/shared_impl/input_event_impl.h" | 8 #include "ppapi/shared_impl/input_event_impl.h" |
9 #include "ppapi/shared_impl/var.h" | 9 #include "ppapi/shared_impl/var.h" |
10 #include "webkit/plugins/ppapi/common.h" | 10 #include "webkit/plugins/ppapi/common.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "webkit/plugins/ppapi/ppb_video_capture_impl.h" | 32 #include "webkit/plugins/ppapi/ppb_video_capture_impl.h" |
33 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" | 33 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" |
34 #include "webkit/plugins/ppapi/ppb_video_layer_impl.h" | 34 #include "webkit/plugins/ppapi/ppb_video_layer_impl.h" |
35 | 35 |
36 using ppapi::InputEventData; | 36 using ppapi::InputEventData; |
37 using ppapi::StringVar; | 37 using ppapi::StringVar; |
38 | 38 |
39 namespace webkit { | 39 namespace webkit { |
40 namespace ppapi { | 40 namespace ppapi { |
41 | 41 |
42 ResourceCreationImpl::ResourceCreationImpl(PluginInstance* instance) | 42 ResourceCreationImpl::ResourceCreationImpl(PluginInstance* instance) { |
43 : instance_(instance) { | |
44 } | 43 } |
45 | 44 |
46 ResourceCreationImpl::~ResourceCreationImpl() { | 45 ResourceCreationImpl::~ResourceCreationImpl() { |
47 } | 46 } |
48 | 47 |
49 ::ppapi::thunk::ResourceCreationAPI* | 48 ::ppapi::thunk::ResourceCreationAPI* |
50 ResourceCreationImpl::AsResourceCreationAPI() { | 49 ResourceCreationImpl::AsResourceCreationAPI() { |
51 return this; | 50 return this; |
52 } | 51 } |
53 | 52 |
54 PP_Resource ResourceCreationImpl::CreateAudio( | 53 PP_Resource ResourceCreationImpl::CreateAudio( |
55 PP_Instance instance_id, | 54 PP_Instance instance, |
56 PP_Resource config_id, | 55 PP_Resource config_id, |
57 PPB_Audio_Callback audio_callback, | 56 PPB_Audio_Callback audio_callback, |
58 void* user_data) { | 57 void* user_data) { |
59 return PPB_Audio_Impl::Create(instance_, config_id, audio_callback, | 58 return PPB_Audio_Impl::Create(instance, config_id, audio_callback, |
60 user_data); | 59 user_data); |
61 } | 60 } |
62 | 61 |
63 PP_Resource ResourceCreationImpl::CreateAudioConfig( | 62 PP_Resource ResourceCreationImpl::CreateAudioConfig( |
64 PP_Instance instance_id, | 63 PP_Instance instance, |
65 PP_AudioSampleRate sample_rate, | 64 PP_AudioSampleRate sample_rate, |
66 uint32_t sample_frame_count) { | 65 uint32_t sample_frame_count) { |
67 return PPB_AudioConfig_Impl::Create(instance_, sample_rate, | 66 return PPB_AudioConfig_Impl::Create(instance, sample_rate, |
68 sample_frame_count); | 67 sample_frame_count); |
69 } | 68 } |
70 | 69 |
71 PP_Resource ResourceCreationImpl::CreateAudioTrusted( | 70 PP_Resource ResourceCreationImpl::CreateAudioTrusted( |
72 PP_Instance instance_id) { | 71 PP_Instance instance) { |
73 return (new PPB_Audio_Impl(instance_))->GetReference(); | 72 return (new PPB_Audio_Impl(instance))->GetReference(); |
74 } | 73 } |
75 | 74 |
76 PP_Resource ResourceCreationImpl::CreateBroker(PP_Instance instance) { | 75 PP_Resource ResourceCreationImpl::CreateBroker(PP_Instance instance) { |
77 return (new PPB_Broker_Impl(instance_))->GetReference(); | 76 return (new PPB_Broker_Impl(instance))->GetReference(); |
78 } | 77 } |
79 | 78 |
80 PP_Resource ResourceCreationImpl::CreateBuffer(PP_Instance instance, | 79 PP_Resource ResourceCreationImpl::CreateBuffer(PP_Instance instance, |
81 uint32_t size) { | 80 uint32_t size) { |
82 return PPB_Buffer_Impl::Create(instance_, size); | 81 return PPB_Buffer_Impl::Create(instance, size); |
83 } | 82 } |
84 | 83 |
85 PP_Resource ResourceCreationImpl::CreateContext3D( | 84 PP_Resource ResourceCreationImpl::CreateContext3D( |
86 PP_Instance instance, | 85 PP_Instance instance, |
87 PP_Config3D_Dev config, | 86 PP_Config3D_Dev config, |
88 PP_Resource share_context, | 87 PP_Resource share_context, |
89 const int32_t* attrib_list) { | 88 const int32_t* attrib_list) { |
90 return PPB_Context3D_Impl::Create(instance, config, share_context, | 89 return PPB_Context3D_Impl::Create(instance, config, share_context, |
91 attrib_list); | 90 attrib_list); |
92 } | 91 } |
93 | 92 |
94 PP_Resource ResourceCreationImpl::CreateContext3DRaw( | 93 PP_Resource ResourceCreationImpl::CreateContext3DRaw( |
95 PP_Instance instance, | 94 PP_Instance instance, |
96 PP_Config3D_Dev config, | 95 PP_Config3D_Dev config, |
97 PP_Resource share_context, | 96 PP_Resource share_context, |
98 const int32_t* attrib_list) { | 97 const int32_t* attrib_list) { |
99 return PPB_Context3D_Impl::CreateRaw(instance, config, share_context, | 98 return PPB_Context3D_Impl::CreateRaw(instance, config, share_context, |
100 attrib_list); | 99 attrib_list); |
101 } | 100 } |
102 | 101 |
103 PP_Resource ResourceCreationImpl::CreateDirectoryReader( | 102 PP_Resource ResourceCreationImpl::CreateDirectoryReader( |
104 PP_Resource directory_ref) { | 103 PP_Resource directory_ref) { |
105 return PPB_DirectoryReader_Impl::Create(directory_ref); | 104 return PPB_DirectoryReader_Impl::Create(directory_ref); |
106 } | 105 } |
107 | 106 |
108 PP_Resource ResourceCreationImpl::CreateFileChooser( | 107 PP_Resource ResourceCreationImpl::CreateFileChooser( |
109 PP_Instance instance, | 108 PP_Instance instance, |
110 PP_FileChooserMode_Dev mode, | 109 PP_FileChooserMode_Dev mode, |
111 const PP_Var& accept_mime_types) { | 110 const PP_Var& accept_mime_types) { |
112 return PPB_FileChooser_Impl::Create(instance_, mode, accept_mime_types); | 111 return PPB_FileChooser_Impl::Create(instance, mode, accept_mime_types); |
113 } | 112 } |
114 | 113 |
115 PP_Resource ResourceCreationImpl::CreateFileIO(PP_Instance instance) { | 114 PP_Resource ResourceCreationImpl::CreateFileIO(PP_Instance instance) { |
116 return (new PPB_FileIO_Impl(instance_))->GetReference(); | 115 return (new PPB_FileIO_Impl(instance))->GetReference(); |
117 } | 116 } |
118 | 117 |
119 PP_Resource ResourceCreationImpl::CreateFileRef(PP_Resource file_system, | 118 PP_Resource ResourceCreationImpl::CreateFileRef(PP_Resource file_system, |
120 const char* path) { | 119 const char* path) { |
121 return PPB_FileRef_Impl::Create(file_system, path); | 120 return PPB_FileRef_Impl::Create(file_system, path); |
122 } | 121 } |
123 | 122 |
124 PP_Resource ResourceCreationImpl::CreateFileSystem( | 123 PP_Resource ResourceCreationImpl::CreateFileSystem( |
125 PP_Instance instance, | 124 PP_Instance instance, |
126 PP_FileSystemType type) { | 125 PP_FileSystemType type) { |
127 return PPB_FileSystem_Impl::Create(instance_, type); | 126 return PPB_FileSystem_Impl::Create(instance, type); |
128 } | 127 } |
129 | 128 |
130 PP_Resource ResourceCreationImpl::CreateFlashMenu( | 129 PP_Resource ResourceCreationImpl::CreateFlashMenu( |
131 PP_Instance instance, | 130 PP_Instance instance, |
132 const PP_Flash_Menu* menu_data) { | 131 const PP_Flash_Menu* menu_data) { |
133 return PPB_Flash_Menu_Impl::Create(instance_, menu_data); | 132 return PPB_Flash_Menu_Impl::Create(instance, menu_data); |
134 } | 133 } |
135 | 134 |
136 PP_Resource ResourceCreationImpl::CreateFlashNetConnector( | 135 PP_Resource ResourceCreationImpl::CreateFlashNetConnector( |
137 PP_Instance instance) { | 136 PP_Instance instance) { |
138 return (new PPB_Flash_NetConnector_Impl(instance_))->GetReference(); | 137 return (new PPB_Flash_NetConnector_Impl(instance))->GetReference(); |
139 } | 138 } |
140 | 139 |
141 PP_Resource ResourceCreationImpl::CreateFlashTCPSocket( | 140 PP_Resource ResourceCreationImpl::CreateFlashTCPSocket( |
142 PP_Instance instance) { | 141 PP_Instance instance) { |
143 // Creating TCP socket resource at the renderer side is not supported. | 142 // Creating TCP socket resource at the renderer side is not supported. |
144 return 0; | 143 return 0; |
145 } | 144 } |
146 | 145 |
147 PP_Resource ResourceCreationImpl::CreateFontObject( | 146 PP_Resource ResourceCreationImpl::CreateFontObject( |
148 PP_Instance pp_instance, | 147 PP_Instance instance, |
149 const PP_FontDescription_Dev* description) { | 148 const PP_FontDescription_Dev* description) { |
150 return PPB_Font_Impl::Create(instance_, *description); | 149 return PPB_Font_Impl::Create(instance, *description); |
151 } | 150 } |
152 | 151 |
153 PP_Resource ResourceCreationImpl::CreateGraphics2D( | 152 PP_Resource ResourceCreationImpl::CreateGraphics2D( |
154 PP_Instance pp_instance, | 153 PP_Instance instance, |
155 const PP_Size& size, | 154 const PP_Size& size, |
156 PP_Bool is_always_opaque) { | 155 PP_Bool is_always_opaque) { |
157 return PPB_Graphics2D_Impl::Create(instance_, size, is_always_opaque); | 156 return PPB_Graphics2D_Impl::Create(instance, size, is_always_opaque); |
158 } | 157 } |
159 | 158 |
160 PP_Resource ResourceCreationImpl::CreateGraphics3D( | 159 PP_Resource ResourceCreationImpl::CreateGraphics3D( |
161 PP_Instance instance, | 160 PP_Instance instance, |
162 PP_Resource share_context, | 161 PP_Resource share_context, |
163 const int32_t* attrib_list) { | 162 const int32_t* attrib_list) { |
164 return PPB_Graphics3D_Impl::Create(instance_, share_context, attrib_list); | 163 return PPB_Graphics3D_Impl::Create(instance, share_context, attrib_list); |
165 } | 164 } |
166 | 165 |
167 PP_Resource ResourceCreationImpl::CreateGraphics3DRaw( | 166 PP_Resource ResourceCreationImpl::CreateGraphics3DRaw( |
168 PP_Instance instance, | 167 PP_Instance instance, |
169 PP_Resource share_context, | 168 PP_Resource share_context, |
170 const int32_t* attrib_list) { | 169 const int32_t* attrib_list) { |
171 return PPB_Graphics3D_Impl::CreateRaw(instance_, share_context, attrib_list); | 170 return PPB_Graphics3D_Impl::CreateRaw(instance, share_context, attrib_list); |
172 } | 171 } |
173 | 172 |
174 PP_Resource ResourceCreationImpl::CreateImageData(PP_Instance pp_instance, | 173 PP_Resource ResourceCreationImpl::CreateImageData(PP_Instance instance, |
175 PP_ImageDataFormat format, | 174 PP_ImageDataFormat format, |
176 const PP_Size& size, | 175 const PP_Size& size, |
177 PP_Bool init_to_zero) { | 176 PP_Bool init_to_zero) { |
178 return PPB_ImageData_Impl::Create(instance_, format, size, init_to_zero); | 177 return PPB_ImageData_Impl::Create(instance, format, size, init_to_zero); |
179 } | 178 } |
180 | 179 |
181 PP_Resource ResourceCreationImpl::CreateKeyboardInputEvent( | 180 PP_Resource ResourceCreationImpl::CreateKeyboardInputEvent( |
182 PP_Instance instance, | 181 PP_Instance instance, |
183 PP_InputEvent_Type type, | 182 PP_InputEvent_Type type, |
184 PP_TimeTicks time_stamp, | 183 PP_TimeTicks time_stamp, |
185 uint32_t modifiers, | 184 uint32_t modifiers, |
186 uint32_t key_code, | 185 uint32_t key_code, |
187 struct PP_Var character_text) { | 186 struct PP_Var character_text) { |
188 if (type != PP_INPUTEVENT_TYPE_RAWKEYDOWN && | 187 if (type != PP_INPUTEVENT_TYPE_RAWKEYDOWN && |
189 type != PP_INPUTEVENT_TYPE_KEYDOWN && | 188 type != PP_INPUTEVENT_TYPE_KEYDOWN && |
190 type != PP_INPUTEVENT_TYPE_KEYUP && | 189 type != PP_INPUTEVENT_TYPE_KEYUP && |
191 type != PP_INPUTEVENT_TYPE_CHAR) | 190 type != PP_INPUTEVENT_TYPE_CHAR) |
192 return 0; | 191 return 0; |
193 | 192 |
194 InputEventData data; | 193 InputEventData data; |
195 data.event_type = type; | 194 data.event_type = type; |
196 data.event_time_stamp = time_stamp; | 195 data.event_time_stamp = time_stamp; |
197 data.event_modifiers = modifiers; | 196 data.event_modifiers = modifiers; |
198 data.key_code = key_code; | 197 data.key_code = key_code; |
199 if (character_text.type == PP_VARTYPE_STRING) { | 198 if (character_text.type == PP_VARTYPE_STRING) { |
200 StringVar* string_var = StringVar::FromPPVar(character_text); | 199 StringVar* string_var = StringVar::FromPPVar(character_text); |
201 if (!string_var) | 200 if (!string_var) |
202 return 0; | 201 return 0; |
203 data.character_text = string_var->value(); | 202 data.character_text = string_var->value(); |
204 } | 203 } |
205 | 204 |
206 return PPB_InputEvent_Impl::Create(instance_, data); | 205 return (new PPB_InputEvent_Impl(instance, data))->GetReference(); |
viettrungluu
2011/08/23 17:28:13
I don't know how I feel about the use of the resul
| |
207 } | 206 } |
208 | 207 |
209 PP_Resource ResourceCreationImpl::CreateMouseInputEvent( | 208 PP_Resource ResourceCreationImpl::CreateMouseInputEvent( |
210 PP_Instance instance, | 209 PP_Instance instance, |
211 PP_InputEvent_Type type, | 210 PP_InputEvent_Type type, |
212 PP_TimeTicks time_stamp, | 211 PP_TimeTicks time_stamp, |
213 uint32_t modifiers, | 212 uint32_t modifiers, |
214 PP_InputEvent_MouseButton mouse_button, | 213 PP_InputEvent_MouseButton mouse_button, |
215 const PP_Point* mouse_position, | 214 const PP_Point* mouse_position, |
216 int32_t click_count) { | 215 int32_t click_count) { |
217 if (type != PP_INPUTEVENT_TYPE_MOUSEDOWN && | 216 if (type != PP_INPUTEVENT_TYPE_MOUSEDOWN && |
218 type != PP_INPUTEVENT_TYPE_MOUSEUP && | 217 type != PP_INPUTEVENT_TYPE_MOUSEUP && |
219 type != PP_INPUTEVENT_TYPE_MOUSEMOVE && | 218 type != PP_INPUTEVENT_TYPE_MOUSEMOVE && |
220 type != PP_INPUTEVENT_TYPE_MOUSEENTER && | 219 type != PP_INPUTEVENT_TYPE_MOUSEENTER && |
221 type != PP_INPUTEVENT_TYPE_MOUSELEAVE) | 220 type != PP_INPUTEVENT_TYPE_MOUSELEAVE) |
222 return 0; | 221 return 0; |
223 | 222 |
224 InputEventData data; | 223 InputEventData data; |
225 data.event_type = type; | 224 data.event_type = type; |
226 data.event_time_stamp = time_stamp; | 225 data.event_time_stamp = time_stamp; |
227 data.event_modifiers = modifiers; | 226 data.event_modifiers = modifiers; |
228 data.mouse_button = mouse_button; | 227 data.mouse_button = mouse_button; |
229 data.mouse_position = *mouse_position; | 228 data.mouse_position = *mouse_position; |
230 data.mouse_click_count = click_count; | 229 data.mouse_click_count = click_count; |
231 | 230 |
232 return PPB_InputEvent_Impl::Create(instance_, data); | 231 return (new PPB_InputEvent_Impl(instance, data))->GetReference(); |
233 } | 232 } |
234 | 233 |
235 PP_Resource ResourceCreationImpl::CreateScrollbar(PP_Instance instance, | 234 PP_Resource ResourceCreationImpl::CreateScrollbar(PP_Instance instance, |
236 PP_Bool vertical) { | 235 PP_Bool vertical) { |
237 return PPB_Scrollbar_Impl::Create(instance_, PP_ToBool(vertical)); | 236 return PPB_Scrollbar_Impl::Create(instance, PP_ToBool(vertical)); |
238 } | 237 } |
239 | 238 |
240 PP_Resource ResourceCreationImpl::CreateSurface3D( | 239 PP_Resource ResourceCreationImpl::CreateSurface3D( |
241 PP_Instance instance, | 240 PP_Instance instance, |
242 PP_Config3D_Dev config, | 241 PP_Config3D_Dev config, |
243 const int32_t* attrib_list) { | 242 const int32_t* attrib_list) { |
244 return PPB_Surface3D_Impl::Create(instance_, config, attrib_list); | 243 return PPB_Surface3D_Impl::Create(instance, config, attrib_list); |
245 } | 244 } |
246 | 245 |
247 PP_Resource ResourceCreationImpl::CreateTransport(PP_Instance instance, | 246 PP_Resource ResourceCreationImpl::CreateTransport(PP_Instance instance, |
248 const char* name, | 247 const char* name, |
249 const char* proto) { | 248 const char* proto) { |
250 return PPB_Transport_Impl::Create(instance_, name, proto); | 249 return PPB_Transport_Impl::Create(instance, name, proto); |
251 } | 250 } |
252 | 251 |
253 PP_Resource ResourceCreationImpl::CreateURLLoader(PP_Instance instance) { | 252 PP_Resource ResourceCreationImpl::CreateURLLoader(PP_Instance instance) { |
254 return (new PPB_URLLoader_Impl(instance_, false))->GetReference(); | 253 return (new PPB_URLLoader_Impl(instance, false))->GetReference(); |
255 } | 254 } |
256 | 255 |
257 PP_Resource ResourceCreationImpl::CreateURLRequestInfo(PP_Instance instance) { | 256 PP_Resource ResourceCreationImpl::CreateURLRequestInfo(PP_Instance instance) { |
258 return (new PPB_URLRequestInfo_Impl(instance_))->GetReference(); | 257 return (new PPB_URLRequestInfo_Impl(instance))->GetReference(); |
259 } | 258 } |
260 | 259 |
261 PP_Resource ResourceCreationImpl::CreateVideoCapture(PP_Instance instance) { | 260 PP_Resource ResourceCreationImpl::CreateVideoCapture(PP_Instance instance) { |
262 scoped_refptr<PPB_VideoCapture_Impl> video_capture = | 261 scoped_refptr<PPB_VideoCapture_Impl> video_capture = |
263 new PPB_VideoCapture_Impl(instance_); | 262 new PPB_VideoCapture_Impl(instance); |
264 if (!video_capture->Init()) | 263 if (!video_capture->Init()) |
265 return 0; | 264 return 0; |
266 return video_capture->GetReference(); | 265 return video_capture->GetReference(); |
267 } | 266 } |
268 | 267 |
269 PP_Resource ResourceCreationImpl::CreateVideoDecoder( | 268 PP_Resource ResourceCreationImpl::CreateVideoDecoder( |
270 PP_Instance instance, | 269 PP_Instance instance, |
271 PP_Resource context3d_id, | 270 PP_Resource context3d_id, |
272 const PP_VideoConfigElement* config) { | 271 const PP_VideoConfigElement* config) { |
273 return PPB_VideoDecoder_Impl::Create(instance_, context3d_id, config); | 272 return PPB_VideoDecoder_Impl::Create(instance, context3d_id, config); |
274 } | 273 } |
275 | 274 |
276 PP_Resource ResourceCreationImpl::CreateVideoLayer(PP_Instance instance, | 275 PP_Resource ResourceCreationImpl::CreateVideoLayer(PP_Instance instance, |
277 PP_VideoLayerMode_Dev mode) { | 276 PP_VideoLayerMode_Dev mode) { |
278 return PPB_VideoLayer_Impl::Create(instance_, mode); | 277 return PPB_VideoLayer_Impl::Create(instance, mode); |
279 } | 278 } |
280 | 279 |
281 PP_Resource ResourceCreationImpl::CreateWheelInputEvent( | 280 PP_Resource ResourceCreationImpl::CreateWheelInputEvent( |
282 PP_Instance instance, | 281 PP_Instance instance, |
283 PP_TimeTicks time_stamp, | 282 PP_TimeTicks time_stamp, |
284 uint32_t modifiers, | 283 uint32_t modifiers, |
285 const PP_FloatPoint* wheel_delta, | 284 const PP_FloatPoint* wheel_delta, |
286 const PP_FloatPoint* wheel_ticks, | 285 const PP_FloatPoint* wheel_ticks, |
287 PP_Bool scroll_by_page) { | 286 PP_Bool scroll_by_page) { |
288 InputEventData data; | 287 InputEventData data; |
289 data.event_type = PP_INPUTEVENT_TYPE_WHEEL; | 288 data.event_type = PP_INPUTEVENT_TYPE_WHEEL; |
290 data.event_time_stamp = time_stamp; | 289 data.event_time_stamp = time_stamp; |
291 data.event_modifiers = modifiers; | 290 data.event_modifiers = modifiers; |
292 data.wheel_delta = *wheel_delta; | 291 data.wheel_delta = *wheel_delta; |
293 data.wheel_ticks = *wheel_ticks; | 292 data.wheel_ticks = *wheel_ticks; |
294 data.wheel_scroll_by_page = PP_ToBool(scroll_by_page); | 293 data.wheel_scroll_by_page = PP_ToBool(scroll_by_page); |
295 | 294 |
296 return PPB_InputEvent_Impl::Create(instance_, data); | 295 return (new PPB_InputEvent_Impl(instance, data))->GetReference(); |
297 } | 296 } |
298 | 297 |
299 } // namespace ppapi | 298 } // namespace ppapi |
300 } // namespace webkit | 299 } // namespace webkit |
OLD | NEW |