Make castv2 performance test work.
[chromium-blink-merge.git] / ppapi / proxy / resource_creation_proxy.cc
blobbcb044e972808bf945006461a90e47265efff1b9
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/camera_device_resource.h"
11 #include "ppapi/proxy/compositor_resource.h"
12 #include "ppapi/proxy/connection.h"
13 #include "ppapi/proxy/file_chooser_resource.h"
14 #include "ppapi/proxy/file_io_resource.h"
15 #include "ppapi/proxy/file_ref_resource.h"
16 #include "ppapi/proxy/file_system_resource.h"
17 #include "ppapi/proxy/flash_drm_resource.h"
18 #include "ppapi/proxy/flash_font_file_resource.h"
19 #include "ppapi/proxy/flash_menu_resource.h"
20 #include "ppapi/proxy/graphics_2d_resource.h"
21 #include "ppapi/proxy/host_resolver_private_resource.h"
22 #include "ppapi/proxy/host_resolver_resource.h"
23 #include "ppapi/proxy/media_stream_video_track_resource.h"
24 #include "ppapi/proxy/net_address_resource.h"
25 #include "ppapi/proxy/network_monitor_resource.h"
26 #include "ppapi/proxy/output_protection_resource.h"
27 #include "ppapi/proxy/platform_verification_private_resource.h"
28 #include "ppapi/proxy/plugin_dispatcher.h"
29 #include "ppapi/proxy/plugin_globals.h"
30 #include "ppapi/proxy/plugin_resource_tracker.h"
31 #include "ppapi/proxy/ppapi_messages.h"
32 #include "ppapi/proxy/ppb_audio_proxy.h"
33 #include "ppapi/proxy/ppb_broker_proxy.h"
34 #include "ppapi/proxy/ppb_buffer_proxy.h"
35 #include "ppapi/proxy/ppb_flash_message_loop_proxy.h"
36 #include "ppapi/proxy/ppb_graphics_3d_proxy.h"
37 #include "ppapi/proxy/ppb_image_data_proxy.h"
38 #include "ppapi/proxy/ppb_video_decoder_proxy.h"
39 #include "ppapi/proxy/ppb_x509_certificate_private_proxy.h"
40 #include "ppapi/proxy/printing_resource.h"
41 #include "ppapi/proxy/talk_resource.h"
42 #include "ppapi/proxy/tcp_server_socket_private_resource.h"
43 #include "ppapi/proxy/tcp_socket_private_resource.h"
44 #include "ppapi/proxy/tcp_socket_resource.h"
45 #include "ppapi/proxy/truetype_font_resource.h"
46 #include "ppapi/proxy/udp_socket_private_resource.h"
47 #include "ppapi/proxy/udp_socket_resource.h"
48 #include "ppapi/proxy/url_loader_resource.h"
49 #include "ppapi/proxy/url_request_info_resource.h"
50 #include "ppapi/proxy/url_response_info_resource.h"
51 #include "ppapi/proxy/video_capture_resource.h"
52 #include "ppapi/proxy/video_decoder_resource.h"
53 #include "ppapi/proxy/video_destination_resource.h"
54 #include "ppapi/proxy/video_encoder_resource.h"
55 #include "ppapi/proxy/video_source_resource.h"
56 #include "ppapi/proxy/websocket_resource.h"
57 #include "ppapi/shared_impl/api_id.h"
58 #include "ppapi/shared_impl/host_resource.h"
59 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
60 #include "ppapi/shared_impl/ppb_audio_shared.h"
61 #include "ppapi/shared_impl/ppb_input_event_shared.h"
62 #include "ppapi/shared_impl/var.h"
63 #include "ppapi/thunk/enter.h"
64 #include "ppapi/thunk/ppb_image_data_api.h"
66 using ppapi::thunk::ResourceCreationAPI;
68 namespace ppapi {
69 namespace proxy {
71 ResourceCreationProxy::ResourceCreationProxy(Dispatcher* dispatcher)
72 : InterfaceProxy(dispatcher) {
75 ResourceCreationProxy::~ResourceCreationProxy() {
78 // static
79 InterfaceProxy* ResourceCreationProxy::Create(Dispatcher* dispatcher) {
80 return new ResourceCreationProxy(dispatcher);
83 PP_Resource ResourceCreationProxy::CreateFileIO(PP_Instance instance) {
84 return (new FileIOResource(GetConnection(), instance))->GetReference();
87 PP_Resource ResourceCreationProxy::CreateFileRef(
88 PP_Instance instance,
89 const FileRefCreateInfo& create_info) {
90 return FileRefResource::CreateFileRef(GetConnection(), instance, create_info);
93 PP_Resource ResourceCreationProxy::CreateFileSystem(
94 PP_Instance instance,
95 PP_FileSystemType type) {
96 return (new FileSystemResource(GetConnection(), instance,
97 type))->GetReference();
100 PP_Resource ResourceCreationProxy::CreateIMEInputEvent(
101 PP_Instance instance,
102 PP_InputEvent_Type type,
103 PP_TimeTicks time_stamp,
104 struct PP_Var text,
105 uint32_t segment_number,
106 const uint32_t* segment_offsets,
107 int32_t target_segment,
108 uint32_t selection_start,
109 uint32_t selection_end) {
110 return PPB_InputEvent_Shared::CreateIMEInputEvent(
111 OBJECT_IS_PROXY, instance, type, time_stamp, text, segment_number,
112 segment_offsets, target_segment, selection_start, selection_end);
115 PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent_1_0(
116 PP_Instance instance,
117 PP_InputEvent_Type type,
118 PP_TimeTicks time_stamp,
119 uint32_t modifiers,
120 uint32_t key_code,
121 struct PP_Var character_text) {
122 PP_Var code = StringVar::StringToPPVar("");
123 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(
124 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers, key_code,
125 character_text, code);
128 PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent_1_2(
129 PP_Instance instance,
130 PP_InputEvent_Type type,
131 PP_TimeTicks time_stamp,
132 uint32_t modifiers,
133 uint32_t key_code,
134 struct PP_Var character_text,
135 struct PP_Var code) {
136 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(
137 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers, key_code,
138 character_text, code);
141 PP_Resource ResourceCreationProxy::CreateMouseInputEvent(
142 PP_Instance instance,
143 PP_InputEvent_Type type,
144 PP_TimeTicks time_stamp,
145 uint32_t modifiers,
146 PP_InputEvent_MouseButton mouse_button,
147 const PP_Point* mouse_position,
148 int32_t click_count,
149 const PP_Point* mouse_movement) {
150 return PPB_InputEvent_Shared::CreateMouseInputEvent(
151 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers,
152 mouse_button, mouse_position, click_count, mouse_movement);
155 PP_Resource ResourceCreationProxy::CreateTouchInputEvent(
156 PP_Instance instance,
157 PP_InputEvent_Type type,
158 PP_TimeTicks time_stamp,
159 uint32_t modifiers) {
160 return PPB_InputEvent_Shared::CreateTouchInputEvent(
161 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers);
164 PP_Resource ResourceCreationProxy::CreateTrueTypeFont(
165 PP_Instance instance,
166 const PP_TrueTypeFontDesc_Dev* desc) {
167 return (new TrueTypeFontResource(GetConnection(),
168 instance, *desc))->GetReference();
172 PP_Resource ResourceCreationProxy::CreateURLLoader(PP_Instance instance) {
173 return (new URLLoaderResource(GetConnection(), instance))->GetReference();
176 PP_Resource ResourceCreationProxy::CreateURLRequestInfo(
177 PP_Instance instance) {
178 return (new URLRequestInfoResource(
179 GetConnection(), instance, URLRequestInfoData()))->GetReference();
182 PP_Resource ResourceCreationProxy::CreateWheelInputEvent(
183 PP_Instance instance,
184 PP_TimeTicks time_stamp,
185 uint32_t modifiers,
186 const PP_FloatPoint* wheel_delta,
187 const PP_FloatPoint* wheel_ticks,
188 PP_Bool scroll_by_page) {
189 return PPB_InputEvent_Shared::CreateWheelInputEvent(
190 OBJECT_IS_PROXY, instance, time_stamp, modifiers,
191 wheel_delta, wheel_ticks, scroll_by_page);
194 PP_Resource ResourceCreationProxy::CreateAudio1_0(
195 PP_Instance instance,
196 PP_Resource config_id,
197 PPB_Audio_Callback_1_0 audio_callback,
198 void* user_data) {
199 return PPB_Audio_Proxy::CreateProxyResource(
200 instance, config_id, AudioCallbackCombined(audio_callback), user_data);
203 PP_Resource ResourceCreationProxy::CreateAudio(
204 PP_Instance instance,
205 PP_Resource config_id,
206 PPB_Audio_Callback audio_callback,
207 void* user_data) {
208 return PPB_Audio_Proxy::CreateProxyResource(
209 instance, config_id, AudioCallbackCombined(audio_callback), user_data);
212 PP_Resource ResourceCreationProxy::CreateAudioTrusted(PP_Instance instance) {
213 // Proxied plugins can't create trusted audio devices.
214 return 0;
217 PP_Resource ResourceCreationProxy::CreateAudioConfig(
218 PP_Instance instance,
219 PP_AudioSampleRate sample_rate,
220 uint32_t sample_frame_count) {
221 return PPB_AudioConfig_Shared::Create(
222 OBJECT_IS_PROXY, instance, sample_rate, sample_frame_count);
225 PP_Resource ResourceCreationProxy::CreateCameraDevicePrivate(
226 PP_Instance instance) {
227 return (new CameraDeviceResource(GetConnection(), instance))->GetReference();
230 PP_Resource ResourceCreationProxy::CreateCompositor(PP_Instance instance) {
231 return (new CompositorResource(GetConnection(), instance))->GetReference();
234 PP_Resource ResourceCreationProxy::CreateFileChooser(
235 PP_Instance instance,
236 PP_FileChooserMode_Dev mode,
237 const PP_Var& accept_types) {
238 scoped_refptr<StringVar> string_var = StringVar::FromPPVar(accept_types);
239 std::string str = string_var.get() ? string_var->value() : std::string();
240 return (new FileChooserResource(GetConnection(), instance, mode, str.c_str()))
241 ->GetReference();
244 PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance,
245 const PP_Size* size,
246 PP_Bool is_always_opaque) {
247 return (new Graphics2DResource(GetConnection(), instance, *size,
248 is_always_opaque))->GetReference();
251 PP_Resource ResourceCreationProxy::CreateGraphics3D(
252 PP_Instance instance,
253 PP_Resource share_context,
254 const int32_t* attrib_list) {
255 return PPB_Graphics3D_Proxy::CreateProxyResource(
256 instance, share_context, attrib_list);
259 PP_Resource ResourceCreationProxy::CreateGraphics3DRaw(
260 PP_Instance instance,
261 PP_Resource share_context,
262 const int32_t* attrib_list,
263 gpu::Capabilities* capabilities,
264 base::SharedMemoryHandle* shared_state) {
265 // Not proxied. The raw creation function is used only in the implementation
266 // of the proxy on the host side.
267 return 0;
270 PP_Resource ResourceCreationProxy::CreateHostResolver(PP_Instance instance) {
271 return (new HostResolverResource(GetConnection(), instance))->GetReference();
274 PP_Resource ResourceCreationProxy::CreateHostResolverPrivate(
275 PP_Instance instance) {
276 return (new HostResolverPrivateResource(
277 GetConnection(), instance))->GetReference();
280 PP_Resource ResourceCreationProxy::CreateImageData(
281 PP_Instance instance,
282 PP_ImageDataFormat format,
283 const PP_Size* size,
284 PP_Bool init_to_zero) {
285 // On the plugin side, we create PlatformImageData resources for trusted
286 // plugins and SimpleImageData resources for untrusted ones.
287 PPB_ImageData_Shared::ImageDataType type =
288 #if !defined(OS_NACL)
289 PPB_ImageData_Shared::PLATFORM;
290 #else
291 PPB_ImageData_Shared::SIMPLE;
292 #endif
293 return PPB_ImageData_Proxy::CreateProxyResource(
294 instance, type,
295 format, *size, init_to_zero);
298 PP_Resource ResourceCreationProxy::CreateImageDataSimple(
299 PP_Instance instance,
300 PP_ImageDataFormat format,
301 const PP_Size* size,
302 PP_Bool init_to_zero) {
303 return PPB_ImageData_Proxy::CreateProxyResource(
304 instance,
305 PPB_ImageData_Shared::SIMPLE,
306 format, *size, init_to_zero);
309 PP_Resource ResourceCreationProxy::CreateMediaStreamVideoTrack(
310 PP_Instance instance) {
311 return (new MediaStreamVideoTrackResource(GetConnection(),
312 instance))->GetReference();
315 PP_Resource ResourceCreationProxy::CreateNetAddressFromIPv4Address(
316 PP_Instance instance,
317 const PP_NetAddress_IPv4* ipv4_addr) {
318 return (new NetAddressResource(GetConnection(), instance,
319 *ipv4_addr))->GetReference();
322 PP_Resource ResourceCreationProxy::CreateNetAddressFromIPv6Address(
323 PP_Instance instance,
324 const PP_NetAddress_IPv6* ipv6_addr) {
325 return (new NetAddressResource(GetConnection(), instance,
326 *ipv6_addr))->GetReference();
329 PP_Resource ResourceCreationProxy::CreateNetAddressFromNetAddressPrivate(
330 PP_Instance instance,
331 const PP_NetAddress_Private& private_addr) {
332 return (new NetAddressResource(GetConnection(), instance,
333 private_addr))->GetReference();
336 PP_Resource ResourceCreationProxy::CreateNetworkMonitor(
337 PP_Instance instance) {
338 return (new NetworkMonitorResource(GetConnection(), instance))->
339 GetReference();
342 PP_Resource ResourceCreationProxy::CreateOutputProtectionPrivate(
343 PP_Instance instance) {
344 return (new OutputProtectionResource(GetConnection(), instance))->
345 GetReference();
348 PP_Resource ResourceCreationProxy::CreatePrinting(PP_Instance instance) {
349 return (new PrintingResource(GetConnection(), instance))->GetReference();
352 PP_Resource ResourceCreationProxy::CreateTCPServerSocketPrivate(
353 PP_Instance instance) {
354 return (new TCPServerSocketPrivateResource(GetConnection(), instance))->
355 GetReference();
358 PP_Resource ResourceCreationProxy::CreateTCPSocket1_0(
359 PP_Instance instance) {
360 return (new TCPSocketResource(GetConnection(), instance,
361 TCP_SOCKET_VERSION_1_0))->GetReference();
364 PP_Resource ResourceCreationProxy::CreateTCPSocket(
365 PP_Instance instance) {
366 return (new TCPSocketResource(
367 GetConnection(), instance, TCP_SOCKET_VERSION_1_1_OR_ABOVE))->
368 GetReference();
371 PP_Resource ResourceCreationProxy::CreateTCPSocketPrivate(
372 PP_Instance instance) {
373 return (new TCPSocketPrivateResource(GetConnection(), instance))->
374 GetReference();
377 PP_Resource ResourceCreationProxy::CreateUDPSocket(PP_Instance instance) {
378 return (new UDPSocketResource(GetConnection(), instance))->GetReference();
381 PP_Resource ResourceCreationProxy::CreateUDPSocketPrivate(
382 PP_Instance instance) {
383 return (new UDPSocketPrivateResource(
384 GetConnection(), instance))->GetReference();
387 PP_Resource ResourceCreationProxy::CreateVideoDecoder(PP_Instance instance) {
388 return (new VideoDecoderResource(GetConnection(), instance))->GetReference();
391 PP_Resource ResourceCreationProxy::CreateVideoDestination(
392 PP_Instance instance) {
393 return (new VideoDestinationResource(GetConnection(),
394 instance))->GetReference();
397 PP_Resource ResourceCreationProxy::CreateVideoEncoder(PP_Instance instance) {
398 return (new VideoEncoderResource(GetConnection(), instance))->GetReference();
401 PP_Resource ResourceCreationProxy::CreateVideoSource(
402 PP_Instance instance) {
403 return (new VideoSourceResource(GetConnection(), instance))->GetReference();
406 PP_Resource ResourceCreationProxy::CreateWebSocket(PP_Instance instance) {
407 return (new WebSocketResource(GetConnection(), instance))->GetReference();
410 PP_Resource ResourceCreationProxy::CreateX509CertificatePrivate(
411 PP_Instance instance) {
412 return PPB_X509Certificate_Private_Proxy::CreateProxyResource(instance);
415 #if !defined(OS_NACL)
416 PP_Resource ResourceCreationProxy::CreateAudioInput(
417 PP_Instance instance) {
418 return (new AudioInputResource(GetConnection(), instance))->GetReference();
421 PP_Resource ResourceCreationProxy::CreateBroker(PP_Instance instance) {
422 return PPB_Broker_Proxy::CreateProxyResource(instance);
425 PP_Resource ResourceCreationProxy::CreateBrowserFont(
426 PP_Instance instance,
427 const PP_BrowserFont_Trusted_Description* description) {
428 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
429 if (!dispatcher)
430 return 0;
431 return PluginGlobals::Get()->CreateBrowserFont(
432 GetConnection(), instance, *description, dispatcher->preferences());
435 PP_Resource ResourceCreationProxy::CreateBuffer(PP_Instance instance,
436 uint32_t size) {
437 return PPB_Buffer_Proxy::CreateProxyResource(instance, size);
440 PP_Resource ResourceCreationProxy::CreateFlashDRM(PP_Instance instance) {
441 return (new FlashDRMResource(GetConnection(), instance))->GetReference();
444 PP_Resource ResourceCreationProxy::CreateFlashFontFile(
445 PP_Instance instance,
446 const PP_BrowserFont_Trusted_Description* description,
447 PP_PrivateFontCharset charset) {
448 return (new FlashFontFileResource(
449 GetConnection(), instance, description, charset))->GetReference();
452 PP_Resource ResourceCreationProxy::CreateFlashMenu(
453 PP_Instance instance,
454 const PP_Flash_Menu* menu_data) {
455 scoped_refptr<FlashMenuResource> flash_menu(
456 new FlashMenuResource(GetConnection(), instance));
457 if (!flash_menu->Initialize(menu_data))
458 return 0;
459 return flash_menu->GetReference();
462 PP_Resource ResourceCreationProxy::CreateFlashMessageLoop(
463 PP_Instance instance) {
464 return PPB_Flash_MessageLoop_Proxy::CreateProxyResource(instance);
467 PP_Resource ResourceCreationProxy::CreatePlatformVerificationPrivate(
468 PP_Instance instance) {
469 return (new PlatformVerificationPrivateResource(GetConnection(), instance))->
470 GetReference();
473 PP_Resource ResourceCreationProxy::CreateScrollbar(PP_Instance instance,
474 PP_Bool vertical) {
475 NOTIMPLEMENTED(); // Not proxied yet.
476 return 0;
479 PP_Resource ResourceCreationProxy::CreateTalk(PP_Instance instance) {
480 return (new TalkResource(GetConnection(), instance))->GetReference();
483 PP_Resource ResourceCreationProxy::CreateVideoCapture(PP_Instance instance) {
484 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
485 if (!dispatcher)
486 return 0;
487 return (new VideoCaptureResource(GetConnection(), instance, dispatcher))
488 ->GetReference();
491 PP_Resource ResourceCreationProxy::CreateVideoDecoderDev(
492 PP_Instance instance,
493 PP_Resource context3d_id,
494 PP_VideoDecoder_Profile profile) {
495 return PPB_VideoDecoder_Proxy::CreateProxyResource(
496 instance, context3d_id, profile);
499 #endif // !defined(OS_NACL)
501 bool ResourceCreationProxy::Send(IPC::Message* msg) {
502 return dispatcher()->Send(msg);
505 bool ResourceCreationProxy::OnMessageReceived(const IPC::Message& msg) {
506 return false;
509 Connection ResourceCreationProxy::GetConnection() {
510 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
513 } // namespace proxy
514 } // namespace ppapi