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 "ppapi/proxy/resource_creation_proxy.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/pp_size.h"
9 #include "ppapi/proxy/audio_input_resource.h"
10 #include "ppapi/proxy/connection.h"
11 #include "ppapi/proxy/file_chooser_resource.h"
12 #include "ppapi/proxy/file_io_resource.h"
13 #include "ppapi/proxy/file_ref_resource.h"
14 #include "ppapi/proxy/file_system_resource.h"
15 #include "ppapi/proxy/flash_drm_resource.h"
16 #include "ppapi/proxy/flash_font_file_resource.h"
17 #include "ppapi/proxy/flash_menu_resource.h"
18 #include "ppapi/proxy/graphics_2d_resource.h"
19 #include "ppapi/proxy/host_resolver_private_resource.h"
20 #include "ppapi/proxy/host_resolver_resource.h"
21 #include "ppapi/proxy/net_address_resource.h"
22 #include "ppapi/proxy/network_monitor_resource.h"
23 #include "ppapi/proxy/output_protection_resource.h"
24 #include "ppapi/proxy/platform_verification_private_resource.h"
25 #include "ppapi/proxy/plugin_dispatcher.h"
26 #include "ppapi/proxy/plugin_globals.h"
27 #include "ppapi/proxy/plugin_resource_tracker.h"
28 #include "ppapi/proxy/ppapi_messages.h"
29 #include "ppapi/proxy/ppb_audio_proxy.h"
30 #include "ppapi/proxy/ppb_broker_proxy.h"
31 #include "ppapi/proxy/ppb_buffer_proxy.h"
32 #include "ppapi/proxy/ppb_flash_message_loop_proxy.h"
33 #include "ppapi/proxy/ppb_graphics_3d_proxy.h"
34 #include "ppapi/proxy/ppb_image_data_proxy.h"
35 #include "ppapi/proxy/ppb_video_decoder_proxy.h"
36 #include "ppapi/proxy/ppb_x509_certificate_private_proxy.h"
37 #include "ppapi/proxy/printing_resource.h"
38 #include "ppapi/proxy/talk_resource.h"
39 #include "ppapi/proxy/tcp_server_socket_private_resource.h"
40 #include "ppapi/proxy/tcp_socket_private_resource.h"
41 #include "ppapi/proxy/tcp_socket_resource.h"
42 #include "ppapi/proxy/truetype_font_resource.h"
43 #include "ppapi/proxy/udp_socket_private_resource.h"
44 #include "ppapi/proxy/udp_socket_resource.h"
45 #include "ppapi/proxy/url_loader_resource.h"
46 #include "ppapi/proxy/url_request_info_resource.h"
47 #include "ppapi/proxy/url_response_info_resource.h"
48 #include "ppapi/proxy/video_capture_resource.h"
49 #include "ppapi/proxy/video_destination_resource.h"
50 #include "ppapi/proxy/video_source_resource.h"
51 #include "ppapi/proxy/websocket_resource.h"
52 #include "ppapi/shared_impl/api_id.h"
53 #include "ppapi/shared_impl/host_resource.h"
54 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
55 #include "ppapi/shared_impl/ppb_audio_shared.h"
56 #include "ppapi/shared_impl/ppb_input_event_shared.h"
57 #include "ppapi/shared_impl/var.h"
58 #include "ppapi/thunk/enter.h"
59 #include "ppapi/thunk/ppb_image_data_api.h"
61 using ppapi::thunk::ResourceCreationAPI
;
66 ResourceCreationProxy::ResourceCreationProxy(Dispatcher
* dispatcher
)
67 : InterfaceProxy(dispatcher
) {
70 ResourceCreationProxy::~ResourceCreationProxy() {
74 InterfaceProxy
* ResourceCreationProxy::Create(Dispatcher
* dispatcher
) {
75 return new ResourceCreationProxy(dispatcher
);
78 PP_Resource
ResourceCreationProxy::CreateFileIO(PP_Instance instance
) {
79 return (new FileIOResource(GetConnection(), instance
))->GetReference();
82 PP_Resource
ResourceCreationProxy::CreateFileRef(
84 const FileRefCreateInfo
& create_info
) {
85 return FileRefResource::CreateFileRef(GetConnection(), instance
, create_info
);
88 PP_Resource
ResourceCreationProxy::CreateFileSystem(
90 PP_FileSystemType type
) {
91 return (new FileSystemResource(GetConnection(), instance
,
92 type
))->GetReference();
95 PP_Resource
ResourceCreationProxy::CreateIMEInputEvent(
97 PP_InputEvent_Type type
,
98 PP_TimeTicks time_stamp
,
100 uint32_t segment_number
,
101 const uint32_t* segment_offsets
,
102 int32_t target_segment
,
103 uint32_t selection_start
,
104 uint32_t selection_end
) {
105 return PPB_InputEvent_Shared::CreateIMEInputEvent(
106 OBJECT_IS_PROXY
, instance
, type
, time_stamp
, text
, segment_number
,
107 segment_offsets
, target_segment
, selection_start
, selection_end
);
110 PP_Resource
ResourceCreationProxy::CreateKeyboardInputEvent(
111 PP_Instance instance
,
112 PP_InputEvent_Type type
,
113 PP_TimeTicks time_stamp
,
116 struct PP_Var character_text
) {
117 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(
118 OBJECT_IS_PROXY
, instance
, type
, time_stamp
, modifiers
, key_code
,
122 PP_Resource
ResourceCreationProxy::CreateMouseInputEvent(
123 PP_Instance instance
,
124 PP_InputEvent_Type type
,
125 PP_TimeTicks time_stamp
,
127 PP_InputEvent_MouseButton mouse_button
,
128 const PP_Point
* mouse_position
,
130 const PP_Point
* mouse_movement
) {
131 return PPB_InputEvent_Shared::CreateMouseInputEvent(
132 OBJECT_IS_PROXY
, instance
, type
, time_stamp
, modifiers
,
133 mouse_button
, mouse_position
, click_count
, mouse_movement
);
136 PP_Resource
ResourceCreationProxy::CreateTouchInputEvent(
137 PP_Instance instance
,
138 PP_InputEvent_Type type
,
139 PP_TimeTicks time_stamp
,
140 uint32_t modifiers
) {
141 return PPB_InputEvent_Shared::CreateTouchInputEvent(
142 OBJECT_IS_PROXY
, instance
, type
, time_stamp
, modifiers
);
145 PP_Resource
ResourceCreationProxy::CreateTrueTypeFont(
146 PP_Instance instance
,
147 const PP_TrueTypeFontDesc_Dev
* desc
) {
148 return (new TrueTypeFontResource(GetConnection(),
149 instance
, *desc
))->GetReference();
153 PP_Resource
ResourceCreationProxy::CreateURLLoader(PP_Instance instance
) {
154 return (new URLLoaderResource(GetConnection(), instance
))->GetReference();
157 PP_Resource
ResourceCreationProxy::CreateURLRequestInfo(
158 PP_Instance instance
) {
159 return (new URLRequestInfoResource(
160 GetConnection(), instance
, URLRequestInfoData()))->GetReference();
163 PP_Resource
ResourceCreationProxy::CreateWheelInputEvent(
164 PP_Instance instance
,
165 PP_TimeTicks time_stamp
,
167 const PP_FloatPoint
* wheel_delta
,
168 const PP_FloatPoint
* wheel_ticks
,
169 PP_Bool scroll_by_page
) {
170 return PPB_InputEvent_Shared::CreateWheelInputEvent(
171 OBJECT_IS_PROXY
, instance
, time_stamp
, modifiers
,
172 wheel_delta
, wheel_ticks
, scroll_by_page
);
175 PP_Resource
ResourceCreationProxy::CreateAudio1_0(
176 PP_Instance instance
,
177 PP_Resource config_id
,
178 PPB_Audio_Callback_1_0 audio_callback
,
180 return PPB_Audio_Proxy::CreateProxyResource(
181 instance
, config_id
, AudioCallbackCombined(audio_callback
), user_data
);
184 PP_Resource
ResourceCreationProxy::CreateAudio(
185 PP_Instance instance
,
186 PP_Resource config_id
,
187 PPB_Audio_Callback audio_callback
,
189 return PPB_Audio_Proxy::CreateProxyResource(
190 instance
, config_id
, AudioCallbackCombined(audio_callback
), user_data
);
193 PP_Resource
ResourceCreationProxy::CreateAudioTrusted(PP_Instance instance
) {
194 // Proxied plugins can't create trusted audio devices.
198 PP_Resource
ResourceCreationProxy::CreateAudioConfig(
199 PP_Instance instance
,
200 PP_AudioSampleRate sample_rate
,
201 uint32_t sample_frame_count
) {
202 return PPB_AudioConfig_Shared::Create(
203 OBJECT_IS_PROXY
, instance
, sample_rate
, sample_frame_count
);
206 PP_Resource
ResourceCreationProxy::CreateFileChooser(
207 PP_Instance instance
,
208 PP_FileChooserMode_Dev mode
,
209 const PP_Var
& accept_types
) {
210 scoped_refptr
<StringVar
> string_var
= StringVar::FromPPVar(accept_types
);
211 std::string str
= string_var
.get() ? string_var
->value() : std::string();
212 return (new FileChooserResource(GetConnection(), instance
, mode
, str
.c_str()))
216 PP_Resource
ResourceCreationProxy::CreateGraphics2D(PP_Instance instance
,
218 PP_Bool is_always_opaque
) {
219 return (new Graphics2DResource(GetConnection(), instance
, *size
,
220 is_always_opaque
))->GetReference();
223 PP_Resource
ResourceCreationProxy::CreateGraphics3D(
224 PP_Instance instance
,
225 PP_Resource share_context
,
226 const int32_t* attrib_list
) {
227 return PPB_Graphics3D_Proxy::CreateProxyResource(
228 instance
, share_context
, attrib_list
);
231 PP_Resource
ResourceCreationProxy::CreateGraphics3DRaw(
232 PP_Instance instance
,
233 PP_Resource share_context
,
234 const int32_t* attrib_list
) {
235 // Not proxied. The raw creation function is used only in the implementation
236 // of the proxy on the host side.
240 PP_Resource
ResourceCreationProxy::CreateHostResolver(PP_Instance instance
) {
241 return (new HostResolverResource(GetConnection(), instance
))->GetReference();
244 PP_Resource
ResourceCreationProxy::CreateHostResolverPrivate(
245 PP_Instance instance
) {
246 return (new HostResolverPrivateResource(
247 GetConnection(), instance
))->GetReference();
250 PP_Resource
ResourceCreationProxy::CreateImageData(
251 PP_Instance instance
,
252 PP_ImageDataFormat format
,
254 PP_Bool init_to_zero
) {
255 // On the plugin side, we create PlatformImageData resources for trusted
256 // plugins and SimpleImageData resources for untrusted ones.
257 PPB_ImageData_Shared::ImageDataType type
=
258 #if !defined(OS_NACL)
259 PPB_ImageData_Shared::PLATFORM
;
261 PPB_ImageData_Shared::SIMPLE
;
263 return PPB_ImageData_Proxy::CreateProxyResource(
265 format
, *size
, init_to_zero
);
268 PP_Resource
ResourceCreationProxy::CreateImageDataSimple(
269 PP_Instance instance
,
270 PP_ImageDataFormat format
,
272 PP_Bool init_to_zero
) {
273 return PPB_ImageData_Proxy::CreateProxyResource(
275 PPB_ImageData_Shared::SIMPLE
,
276 format
, *size
, init_to_zero
);
279 PP_Resource
ResourceCreationProxy::CreateNetAddressFromIPv4Address(
280 PP_Instance instance
,
281 const PP_NetAddress_IPv4
* ipv4_addr
) {
282 return (new NetAddressResource(GetConnection(), instance
,
283 *ipv4_addr
))->GetReference();
286 PP_Resource
ResourceCreationProxy::CreateNetAddressFromIPv6Address(
287 PP_Instance instance
,
288 const PP_NetAddress_IPv6
* ipv6_addr
) {
289 return (new NetAddressResource(GetConnection(), instance
,
290 *ipv6_addr
))->GetReference();
293 PP_Resource
ResourceCreationProxy::CreateNetAddressFromNetAddressPrivate(
294 PP_Instance instance
,
295 const PP_NetAddress_Private
& private_addr
) {
296 return (new NetAddressResource(GetConnection(), instance
,
297 private_addr
))->GetReference();
300 PP_Resource
ResourceCreationProxy::CreateNetworkMonitor(
301 PP_Instance instance
) {
302 return (new NetworkMonitorResource(GetConnection(), instance
))->
306 PP_Resource
ResourceCreationProxy::CreateOutputProtectionPrivate(
307 PP_Instance instance
) {
308 return (new OutputProtectionResource(GetConnection(), instance
))->
312 PP_Resource
ResourceCreationProxy::CreatePrinting(PP_Instance instance
) {
313 return (new PrintingResource(GetConnection(), instance
))->GetReference();
316 PP_Resource
ResourceCreationProxy::CreateTCPServerSocketPrivate(
317 PP_Instance instance
) {
318 return (new TCPServerSocketPrivateResource(GetConnection(), instance
))->
322 PP_Resource
ResourceCreationProxy::CreateTCPSocket1_0(
323 PP_Instance instance
) {
324 return (new TCPSocketResource(GetConnection(), instance
,
325 TCP_SOCKET_VERSION_1_0
))->GetReference();
328 PP_Resource
ResourceCreationProxy::CreateTCPSocket(
329 PP_Instance instance
) {
330 return (new TCPSocketResource(
331 GetConnection(), instance
, TCP_SOCKET_VERSION_1_1_OR_ABOVE
))->
335 PP_Resource
ResourceCreationProxy::CreateTCPSocketPrivate(
336 PP_Instance instance
) {
337 return (new TCPSocketPrivateResource(GetConnection(), instance
))->
341 PP_Resource
ResourceCreationProxy::CreateUDPSocket(PP_Instance instance
) {
342 return (new UDPSocketResource(GetConnection(), instance
))->GetReference();
345 PP_Resource
ResourceCreationProxy::CreateUDPSocketPrivate(
346 PP_Instance instance
) {
347 return (new UDPSocketPrivateResource(
348 GetConnection(), instance
))->GetReference();
351 PP_Resource
ResourceCreationProxy::CreateVideoDestination(
352 PP_Instance instance
) {
353 return (new VideoDestinationResource(GetConnection(),
354 instance
))->GetReference();
357 PP_Resource
ResourceCreationProxy::CreateVideoSource(
358 PP_Instance instance
) {
359 return (new VideoSourceResource(GetConnection(), instance
))->GetReference();
362 PP_Resource
ResourceCreationProxy::CreateWebSocket(PP_Instance instance
) {
363 return (new WebSocketResource(GetConnection(), instance
))->GetReference();
366 PP_Resource
ResourceCreationProxy::CreateX509CertificatePrivate(
367 PP_Instance instance
) {
368 return PPB_X509Certificate_Private_Proxy::CreateProxyResource(instance
);
371 #if !defined(OS_NACL)
372 PP_Resource
ResourceCreationProxy::CreateAudioInput(
373 PP_Instance instance
) {
374 return (new AudioInputResource(GetConnection(), instance
))->GetReference();
377 PP_Resource
ResourceCreationProxy::CreateBroker(PP_Instance instance
) {
378 return PPB_Broker_Proxy::CreateProxyResource(instance
);
381 PP_Resource
ResourceCreationProxy::CreateBrowserFont(
382 PP_Instance instance
,
383 const PP_BrowserFont_Trusted_Description
* description
) {
384 PluginDispatcher
* dispatcher
= PluginDispatcher::GetForInstance(instance
);
387 return PluginGlobals::Get()->CreateBrowserFont(
388 GetConnection(), instance
, *description
, dispatcher
->preferences());
391 PP_Resource
ResourceCreationProxy::CreateBuffer(PP_Instance instance
,
393 return PPB_Buffer_Proxy::CreateProxyResource(instance
, size
);
396 PP_Resource
ResourceCreationProxy::CreateFlashDRM(PP_Instance instance
) {
397 return (new FlashDRMResource(GetConnection(), instance
))->GetReference();
400 PP_Resource
ResourceCreationProxy::CreateFlashFontFile(
401 PP_Instance instance
,
402 const PP_BrowserFont_Trusted_Description
* description
,
403 PP_PrivateFontCharset charset
) {
404 return (new FlashFontFileResource(
405 GetConnection(), instance
, description
, charset
))->GetReference();
408 PP_Resource
ResourceCreationProxy::CreateFlashMenu(
409 PP_Instance instance
,
410 const PP_Flash_Menu
* menu_data
) {
411 scoped_refptr
<FlashMenuResource
> flash_menu(
412 new FlashMenuResource(GetConnection(), instance
));
413 if (!flash_menu
->Initialize(menu_data
))
415 return flash_menu
->GetReference();
418 PP_Resource
ResourceCreationProxy::CreateFlashMessageLoop(
419 PP_Instance instance
) {
420 return PPB_Flash_MessageLoop_Proxy::CreateProxyResource(instance
);
423 PP_Resource
ResourceCreationProxy::CreatePlatformVerificationPrivate(
424 PP_Instance instance
) {
425 return (new PlatformVerificationPrivateResource(GetConnection(), instance
))->
429 PP_Resource
ResourceCreationProxy::CreateScrollbar(PP_Instance instance
,
431 NOTIMPLEMENTED(); // Not proxied yet.
435 PP_Resource
ResourceCreationProxy::CreateTalk(PP_Instance instance
) {
436 return (new TalkResource(GetConnection(), instance
))->GetReference();
439 PP_Resource
ResourceCreationProxy::CreateVideoCapture(PP_Instance instance
) {
440 PluginDispatcher
* dispatcher
= PluginDispatcher::GetForInstance(instance
);
443 return (new VideoCaptureResource(GetConnection(), instance
, dispatcher
))
447 PP_Resource
ResourceCreationProxy::CreateVideoDecoder(
448 PP_Instance instance
,
449 PP_Resource context3d_id
,
450 PP_VideoDecoder_Profile profile
) {
451 return PPB_VideoDecoder_Proxy::CreateProxyResource(
452 instance
, context3d_id
, profile
);
455 #endif // !defined(OS_NACL)
457 bool ResourceCreationProxy::Send(IPC::Message
* msg
) {
458 return dispatcher()->Send(msg
);
461 bool ResourceCreationProxy::OnMessageReceived(const IPC::Message
& msg
) {
465 Connection
ResourceCreationProxy::GetConnection() {
466 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());