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 namespace { | |
43 | |
44 // We use two methods for creating resources. When the resource initialization | |
45 // is simple and can't fail, just do | |
46 // return ReturnResource(new PPB_Foo_Impl(instance_, ...)); | |
47 // This will set up everything necessary. | |
48 // | |
49 // If the resource is more complex, generally the best thing is to write a | |
50 // static "Create" function on the resource class that returns a PP_Resource | |
51 // or 0 on failure. That helps keep the resource-specific stuff localized and | |
52 // this class very simple. | |
53 PP_Resource ReturnResource(Resource* resource) { | |
54 // We actually have to keep a ref here since the argument will not be ref'ed | |
55 // at all if it was just passed in with new (the expected usage). The | |
56 // returned PP_Resource created by GetReference will hold onto a ref on | |
57 // behalf of the plugin which will outlive this function. So the end result | |
58 // will be a Resource with one ref. | |
59 scoped_refptr<Resource> ref(resource); | |
60 return resource->GetReference(); | |
61 } | |
62 | |
63 } // namespace | |
64 | |
65 | |
66 ResourceCreationImpl::ResourceCreationImpl(PluginInstance* instance) | 42 ResourceCreationImpl::ResourceCreationImpl(PluginInstance* instance) |
67 : instance_(instance) { | 43 : instance_(instance) { |
68 } | 44 } |
69 | 45 |
70 ResourceCreationImpl::~ResourceCreationImpl() { | 46 ResourceCreationImpl::~ResourceCreationImpl() { |
71 } | 47 } |
72 | 48 |
73 ::ppapi::thunk::ResourceCreationAPI* | 49 ::ppapi::thunk::ResourceCreationAPI* |
74 ResourceCreationImpl::AsResourceCreationAPI() { | 50 ResourceCreationImpl::AsResourceCreationAPI() { |
75 return this; | 51 return this; |
(...skipping 11 matching lines...) Expand all Loading... |
87 PP_Resource ResourceCreationImpl::CreateAudioConfig( | 63 PP_Resource ResourceCreationImpl::CreateAudioConfig( |
88 PP_Instance instance_id, | 64 PP_Instance instance_id, |
89 PP_AudioSampleRate sample_rate, | 65 PP_AudioSampleRate sample_rate, |
90 uint32_t sample_frame_count) { | 66 uint32_t sample_frame_count) { |
91 return PPB_AudioConfig_Impl::Create(instance_, sample_rate, | 67 return PPB_AudioConfig_Impl::Create(instance_, sample_rate, |
92 sample_frame_count); | 68 sample_frame_count); |
93 } | 69 } |
94 | 70 |
95 PP_Resource ResourceCreationImpl::CreateAudioTrusted( | 71 PP_Resource ResourceCreationImpl::CreateAudioTrusted( |
96 PP_Instance instance_id) { | 72 PP_Instance instance_id) { |
97 return ReturnResource(new PPB_Audio_Impl(instance_)); | 73 return (new PPB_Audio_Impl(instance_))->GetReference(); |
98 } | 74 } |
99 | 75 |
100 PP_Resource ResourceCreationImpl::CreateBroker(PP_Instance instance) { | 76 PP_Resource ResourceCreationImpl::CreateBroker(PP_Instance instance) { |
101 return ReturnResource(new PPB_Broker_Impl(instance_)); | 77 return (new PPB_Broker_Impl(instance_))->GetReference(); |
102 } | 78 } |
103 | 79 |
104 PP_Resource ResourceCreationImpl::CreateBuffer(PP_Instance instance, | 80 PP_Resource ResourceCreationImpl::CreateBuffer(PP_Instance instance, |
105 uint32_t size) { | 81 uint32_t size) { |
106 return PPB_Buffer_Impl::Create(instance_, size); | 82 return PPB_Buffer_Impl::Create(instance_, size); |
107 } | 83 } |
108 | 84 |
109 PP_Resource ResourceCreationImpl::CreateContext3D( | 85 PP_Resource ResourceCreationImpl::CreateContext3D( |
110 PP_Instance instance, | 86 PP_Instance instance, |
111 PP_Config3D_Dev config, | 87 PP_Config3D_Dev config, |
(...skipping 17 matching lines...) Expand all Loading... |
129 return PPB_DirectoryReader_Impl::Create(directory_ref); | 105 return PPB_DirectoryReader_Impl::Create(directory_ref); |
130 } | 106 } |
131 | 107 |
132 PP_Resource ResourceCreationImpl::CreateFileChooser( | 108 PP_Resource ResourceCreationImpl::CreateFileChooser( |
133 PP_Instance instance, | 109 PP_Instance instance, |
134 const PP_FileChooserOptions_Dev* options) { | 110 const PP_FileChooserOptions_Dev* options) { |
135 return PPB_FileChooser_Impl::Create(instance_, options); | 111 return PPB_FileChooser_Impl::Create(instance_, options); |
136 } | 112 } |
137 | 113 |
138 PP_Resource ResourceCreationImpl::CreateFileIO(PP_Instance instance) { | 114 PP_Resource ResourceCreationImpl::CreateFileIO(PP_Instance instance) { |
139 return ReturnResource(new PPB_FileIO_Impl(instance_)); | 115 return (new PPB_FileIO_Impl(instance_))->GetReference(); |
140 } | 116 } |
141 | 117 |
142 PP_Resource ResourceCreationImpl::CreateFileRef(PP_Resource file_system, | 118 PP_Resource ResourceCreationImpl::CreateFileRef(PP_Resource file_system, |
143 const char* path) { | 119 const char* path) { |
144 return PPB_FileRef_Impl::Create(file_system, path); | 120 return PPB_FileRef_Impl::Create(file_system, path); |
145 } | 121 } |
146 | 122 |
147 PP_Resource ResourceCreationImpl::CreateFileSystem( | 123 PP_Resource ResourceCreationImpl::CreateFileSystem( |
148 PP_Instance instance, | 124 PP_Instance instance, |
149 PP_FileSystemType type) { | 125 PP_FileSystemType type) { |
150 return PPB_FileSystem_Impl::Create(instance_, type); | 126 return PPB_FileSystem_Impl::Create(instance_, type); |
151 } | 127 } |
152 | 128 |
153 PP_Resource ResourceCreationImpl::CreateFlashMenu( | 129 PP_Resource ResourceCreationImpl::CreateFlashMenu( |
154 PP_Instance instance, | 130 PP_Instance instance, |
155 const PP_Flash_Menu* menu_data) { | 131 const PP_Flash_Menu* menu_data) { |
156 return PPB_Flash_Menu_Impl::Create(instance_, menu_data); | 132 return PPB_Flash_Menu_Impl::Create(instance_, menu_data); |
157 } | 133 } |
158 | 134 |
159 PP_Resource ResourceCreationImpl::CreateFlashNetConnector( | 135 PP_Resource ResourceCreationImpl::CreateFlashNetConnector( |
160 PP_Instance instance) { | 136 PP_Instance instance) { |
161 return ReturnResource(new PPB_Flash_NetConnector_Impl(instance_)); | 137 return (new PPB_Flash_NetConnector_Impl(instance_))->GetReference(); |
162 } | 138 } |
163 | 139 |
164 PP_Resource ResourceCreationImpl::CreateFlashTCPSocket( | 140 PP_Resource ResourceCreationImpl::CreateFlashTCPSocket( |
165 PP_Instance instance) { | 141 PP_Instance instance) { |
166 // Creating TCP socket resource at the renderer side is not supported. | 142 // Creating TCP socket resource at the renderer side is not supported. |
167 return 0; | 143 return 0; |
168 } | 144 } |
169 | 145 |
170 PP_Resource ResourceCreationImpl::CreateFontObject( | 146 PP_Resource ResourceCreationImpl::CreateFontObject( |
171 PP_Instance pp_instance, | 147 PP_Instance pp_instance, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 return PPB_Surface3D_Impl::Create(instance_, config, attrib_list); | 243 return PPB_Surface3D_Impl::Create(instance_, config, attrib_list); |
268 } | 244 } |
269 | 245 |
270 PP_Resource ResourceCreationImpl::CreateTransport(PP_Instance instance, | 246 PP_Resource ResourceCreationImpl::CreateTransport(PP_Instance instance, |
271 const char* name, | 247 const char* name, |
272 const char* proto) { | 248 const char* proto) { |
273 return PPB_Transport_Impl::Create(instance_, name, proto); | 249 return PPB_Transport_Impl::Create(instance_, name, proto); |
274 } | 250 } |
275 | 251 |
276 PP_Resource ResourceCreationImpl::CreateURLLoader(PP_Instance instance) { | 252 PP_Resource ResourceCreationImpl::CreateURLLoader(PP_Instance instance) { |
277 return ReturnResource(new PPB_URLLoader_Impl(instance_, false)); | 253 return (new PPB_URLLoader_Impl(instance_, false))->GetReference(); |
278 } | 254 } |
279 | 255 |
280 PP_Resource ResourceCreationImpl::CreateURLRequestInfo(PP_Instance instance) { | 256 PP_Resource ResourceCreationImpl::CreateURLRequestInfo(PP_Instance instance) { |
281 return ReturnResource(new PPB_URLRequestInfo_Impl(instance_)); | 257 return (new PPB_URLRequestInfo_Impl(instance_))->GetReference(); |
282 } | 258 } |
283 | 259 |
284 PP_Resource ResourceCreationImpl::CreateVideoCapture(PP_Instance instance) { | 260 PP_Resource ResourceCreationImpl::CreateVideoCapture(PP_Instance instance) { |
285 scoped_refptr<PPB_VideoCapture_Impl> video_capture = | 261 scoped_refptr<PPB_VideoCapture_Impl> video_capture = |
286 new PPB_VideoCapture_Impl(instance_); | 262 new PPB_VideoCapture_Impl(instance_); |
287 if (!video_capture->Init()) | 263 if (!video_capture->Init()) |
288 return 0; | 264 return 0; |
289 return ReturnResource(video_capture); | 265 return video_capture->GetReference(); |
290 } | 266 } |
291 | 267 |
292 PP_Resource ResourceCreationImpl::CreateVideoDecoder( | 268 PP_Resource ResourceCreationImpl::CreateVideoDecoder( |
293 PP_Instance instance, | 269 PP_Instance instance, |
294 PP_Resource context3d_id, | 270 PP_Resource context3d_id, |
295 const PP_VideoConfigElement* config) { | 271 const PP_VideoConfigElement* config) { |
296 return PPB_VideoDecoder_Impl::Create(instance_, context3d_id, config); | 272 return PPB_VideoDecoder_Impl::Create(instance_, context3d_id, config); |
297 } | 273 } |
298 | 274 |
299 PP_Resource ResourceCreationImpl::CreateVideoLayer(PP_Instance instance, | 275 PP_Resource ResourceCreationImpl::CreateVideoLayer(PP_Instance instance, |
(...skipping 14 matching lines...) Expand all Loading... |
314 data.event_modifiers = modifiers; | 290 data.event_modifiers = modifiers; |
315 data.wheel_delta = *wheel_delta; | 291 data.wheel_delta = *wheel_delta; |
316 data.wheel_ticks = *wheel_ticks; | 292 data.wheel_ticks = *wheel_ticks; |
317 data.wheel_scroll_by_page = PP_ToBool(scroll_by_page); | 293 data.wheel_scroll_by_page = PP_ToBool(scroll_by_page); |
318 | 294 |
319 return PPB_InputEvent_Impl::Create(instance_, data); | 295 return PPB_InputEvent_Impl::Create(instance_, data); |
320 } | 296 } |
321 | 297 |
322 } // namespace ppapi | 298 } // namespace ppapi |
323 } // namespace webkit | 299 } // namespace webkit |
OLD | NEW |