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
3 // found in the LICENSE file.
5 #include "webkit/plugins/ppapi/resource_creation_impl.h"
7 #include "ppapi/c/pp_size.h"
8 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
9 #include "ppapi/shared_impl/ppb_input_event_shared.h"
10 #include "ppapi/shared_impl/ppb_resource_array_shared.h"
11 #include "ppapi/shared_impl/var.h"
12 #include "webkit/plugins/ppapi/common.h"
13 #include "webkit/plugins/ppapi/ppb_audio_impl.h"
14 #include "webkit/plugins/ppapi/ppb_broker_impl.h"
15 #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
16 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
17 #include "webkit/plugins/ppapi/ppb_file_system_impl.h"
18 #include "webkit/plugins/ppapi/ppb_flash_message_loop_impl.h"
19 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
20 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
21 #include "webkit/plugins/ppapi/ppb_network_monitor_private_impl.h"
22 #include "webkit/plugins/ppapi/ppb_scrollbar_impl.h"
23 #include "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h"
24 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h"
25 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
26 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h"
27 #include "webkit/plugins/ppapi/ppb_x509_certificate_private_impl.h"
28 #include "webkit/plugins/ppapi/resource_helper.h"
30 using ppapi::InputEventData
;
31 using ppapi::PPB_InputEvent_Shared
;
32 using ppapi::PPB_ResourceArray_Shared
;
33 using ppapi::StringVar
;
38 ResourceCreationImpl::ResourceCreationImpl(PluginInstance
* instance
) {
41 ResourceCreationImpl::~ResourceCreationImpl() {
44 PP_Resource
ResourceCreationImpl::CreateAudio(
46 PP_Resource config_id
,
47 PPB_Audio_Callback audio_callback
,
49 return PPB_Audio_Impl::Create(instance
, config_id
, audio_callback
,
53 PP_Resource
ResourceCreationImpl::CreateAudioConfig(
55 PP_AudioSampleRate sample_rate
,
56 uint32_t sample_frame_count
) {
57 return ::ppapi::PPB_AudioConfig_Shared::Create(
58 ::ppapi::OBJECT_IS_IMPL
, instance
, sample_rate
, sample_frame_count
);
61 PP_Resource
ResourceCreationImpl::CreateAudioTrusted(
62 PP_Instance instance
) {
63 return (new PPB_Audio_Impl(instance
))->GetReference();
66 PP_Resource
ResourceCreationImpl::CreateAudioInput(PP_Instance instance
) {
67 return 0; // Not supported in-process.
70 PP_Resource
ResourceCreationImpl::CreateBroker(PP_Instance instance
) {
71 return (new PPB_Broker_Impl(instance
))->GetReference();
74 PP_Resource
ResourceCreationImpl::CreateBuffer(PP_Instance instance
,
76 return PPB_Buffer_Impl::Create(instance
, size
);
79 PP_Resource
ResourceCreationImpl::CreateDirectoryReader(
81 PP_Resource directory_ref
) {
82 return 0; // Not supported in-process.
85 PP_Resource
ResourceCreationImpl::CreateFileRef(PP_Resource file_system
,
87 PPB_FileRef_Impl
* res
= PPB_FileRef_Impl::CreateInternal(file_system
, path
);
88 return res
? res
->GetReference() : 0;
91 PP_Resource
ResourceCreationImpl::CreateFileSystem(
93 PP_FileSystemType type
) {
94 return PPB_FileSystem_Impl::Create(instance
, type
);
97 PP_Resource
ResourceCreationImpl::CreateFlashDeviceID(PP_Instance instance
) {
98 return 0; // Not supported in-process.
101 PP_Resource
ResourceCreationImpl::CreateFlashFontFile(
102 PP_Instance instance
,
103 const PP_BrowserFont_Trusted_Description
* description
,
104 PP_PrivateFontCharset charset
) {
105 return 0; // Not supported in-process.
108 PP_Resource
ResourceCreationImpl::CreateFlashMenu(
109 PP_Instance instance
,
110 const PP_Flash_Menu
* menu_data
) {
111 return 0; // Not supported in-process.
114 PP_Resource
ResourceCreationImpl::CreateFlashMessageLoop(PP_Instance instance
) {
115 return PPB_Flash_MessageLoop_Impl::Create(instance
);
118 PP_Resource
ResourceCreationImpl::CreateGraphics3D(
119 PP_Instance instance
,
120 PP_Resource share_context
,
121 const int32_t* attrib_list
) {
122 return PPB_Graphics3D_Impl::Create(instance
, share_context
, attrib_list
);
125 PP_Resource
ResourceCreationImpl::CreateGraphics3DRaw(
126 PP_Instance instance
,
127 PP_Resource share_context
,
128 const int32_t* attrib_list
) {
129 return PPB_Graphics3D_Impl::CreateRaw(instance
, share_context
, attrib_list
);
132 PP_Resource
ResourceCreationImpl::CreateHostResolverPrivate(
133 PP_Instance instance
) {
134 return 0; // Not supported in-process.
137 PP_Resource
ResourceCreationImpl::CreateImageData(PP_Instance instance
,
138 PP_ImageDataFormat format
,
140 PP_Bool init_to_zero
) {
141 return PPB_ImageData_Impl::CreatePlatform(instance
, format
, size
,
145 PP_Resource
ResourceCreationImpl::CreateImageDataNaCl(PP_Instance instance
,
146 PP_ImageDataFormat format
,
148 PP_Bool init_to_zero
) {
149 return PPB_ImageData_Impl::CreateNaCl(instance
, format
, size
, init_to_zero
);
152 PP_Resource
ResourceCreationImpl::CreateIMEInputEvent(
153 PP_Instance instance
,
154 PP_InputEvent_Type type
,
155 PP_TimeTicks time_stamp
,
157 uint32_t segment_number
,
158 const uint32_t* segment_offsets
,
159 int32_t target_segment
,
160 uint32_t selection_start
,
161 uint32_t selection_end
) {
162 return PPB_InputEvent_Shared::CreateIMEInputEvent(
163 ::ppapi::OBJECT_IS_IMPL
, instance
, type
, time_stamp
, text
, segment_number
,
164 segment_offsets
, target_segment
, selection_start
, selection_end
);
167 PP_Resource
ResourceCreationImpl::CreateKeyboardInputEvent(
168 PP_Instance instance
,
169 PP_InputEvent_Type type
,
170 PP_TimeTicks time_stamp
,
173 struct PP_Var character_text
) {
174 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(
175 ::ppapi::OBJECT_IS_IMPL
, instance
, type
, time_stamp
, modifiers
, key_code
,
179 PP_Resource
ResourceCreationImpl::CreateMouseInputEvent(
180 PP_Instance instance
,
181 PP_InputEvent_Type type
,
182 PP_TimeTicks time_stamp
,
184 PP_InputEvent_MouseButton mouse_button
,
185 const PP_Point
* mouse_position
,
187 const PP_Point
* mouse_movement
) {
188 return PPB_InputEvent_Shared::CreateMouseInputEvent(
189 ::ppapi::OBJECT_IS_IMPL
, instance
, type
, time_stamp
, modifiers
,
190 mouse_button
, mouse_position
, click_count
, mouse_movement
);
193 PP_Resource
ResourceCreationImpl::CreateTouchInputEvent(
194 PP_Instance instance
,
195 PP_InputEvent_Type type
,
196 PP_TimeTicks time_stamp
,
197 uint32_t modifiers
) {
198 return PPB_InputEvent_Shared::CreateTouchInputEvent(
199 ::ppapi::OBJECT_IS_IMPL
, instance
, type
, time_stamp
, modifiers
);
202 PP_Resource
ResourceCreationImpl::CreateNetworkMonitor(
203 PP_Instance instance
,
204 PPB_NetworkMonitor_Callback callback
,
206 return PPB_NetworkMonitor_Private_Impl::Create(instance
, callback
, user_data
);
209 PP_Resource
ResourceCreationImpl::CreateScrollbar(PP_Instance instance
,
211 return PPB_Scrollbar_Impl::Create(instance
, PP_ToBool(vertical
));
214 PP_Resource
ResourceCreationImpl::CreateTalk(PP_Instance
/* instance */) {
215 // Not implemented in-process.
219 PP_Resource
ResourceCreationImpl::CreateResourceArray(
220 PP_Instance instance
,
221 const PP_Resource elements
[],
223 PPB_ResourceArray_Shared
* object
= new PPB_ResourceArray_Shared(
224 ::ppapi::OBJECT_IS_IMPL
, instance
, elements
, size
);
225 return object
->GetReference();
228 PP_Resource
ResourceCreationImpl::CreateTCPServerSocketPrivate(
229 PP_Instance instance
) {
230 return PPB_TCPServerSocket_Private_Impl::CreateResource(instance
);
233 PP_Resource
ResourceCreationImpl::CreateTCPSocketPrivate(PP_Instance instance
) {
234 return PPB_TCPSocket_Private_Impl::CreateResource(instance
);
237 PP_Resource
ResourceCreationImpl::CreateUDPSocketPrivate(PP_Instance instance
) {
238 return 0; // Not supported in-process.
241 PP_Resource
ResourceCreationImpl::CreateURLLoader(PP_Instance instance
) {
242 return (new PPB_URLLoader_Impl(instance
, false))->GetReference();
245 PP_Resource
ResourceCreationImpl::CreateVideoCapture(PP_Instance instance
) {
246 return 0; // VideoCapture is not supported in process now.
249 PP_Resource
ResourceCreationImpl::CreateVideoDecoder(
250 PP_Instance instance
,
251 PP_Resource graphics3d_id
,
252 PP_VideoDecoder_Profile profile
) {
253 return PPB_VideoDecoder_Impl::Create(instance
, graphics3d_id
, profile
);
256 PP_Resource
ResourceCreationImpl::CreateWheelInputEvent(
257 PP_Instance instance
,
258 PP_TimeTicks time_stamp
,
260 const PP_FloatPoint
* wheel_delta
,
261 const PP_FloatPoint
* wheel_ticks
,
262 PP_Bool scroll_by_page
) {
263 return PPB_InputEvent_Shared::CreateWheelInputEvent(
264 ::ppapi::OBJECT_IS_IMPL
, instance
, time_stamp
, modifiers
,
265 wheel_delta
, wheel_ticks
, scroll_by_page
);
268 PP_Resource
ResourceCreationImpl::CreateX509CertificatePrivate(
269 PP_Instance instance
) {
270 return PPB_X509Certificate_Private_Impl::CreateResource(instance
);
274 } // namespace webkit