Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / ppapi / proxy / resource_creation_proxy.cc
blobeda6308c1d574b0498218806d6cf53e8e157d3dd
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/media_stream_video_track_resource.h"
22 #include "ppapi/proxy/net_address_resource.h"
23 #include "ppapi/proxy/network_monitor_resource.h"
24 #include "ppapi/proxy/output_protection_resource.h"
25 #include "ppapi/proxy/platform_verification_private_resource.h"
26 #include "ppapi/proxy/plugin_dispatcher.h"
27 #include "ppapi/proxy/plugin_globals.h"
28 #include "ppapi/proxy/plugin_resource_tracker.h"
29 #include "ppapi/proxy/ppapi_messages.h"
30 #include "ppapi/proxy/ppb_audio_proxy.h"
31 #include "ppapi/proxy/ppb_broker_proxy.h"
32 #include "ppapi/proxy/ppb_buffer_proxy.h"
33 #include "ppapi/proxy/ppb_flash_message_loop_proxy.h"
34 #include "ppapi/proxy/ppb_graphics_3d_proxy.h"
35 #include "ppapi/proxy/ppb_image_data_proxy.h"
36 #include "ppapi/proxy/ppb_video_decoder_proxy.h"
37 #include "ppapi/proxy/ppb_x509_certificate_private_proxy.h"
38 #include "ppapi/proxy/printing_resource.h"
39 #include "ppapi/proxy/talk_resource.h"
40 #include "ppapi/proxy/tcp_server_socket_private_resource.h"
41 #include "ppapi/proxy/tcp_socket_private_resource.h"
42 #include "ppapi/proxy/tcp_socket_resource.h"
43 #include "ppapi/proxy/truetype_font_resource.h"
44 #include "ppapi/proxy/udp_socket_private_resource.h"
45 #include "ppapi/proxy/udp_socket_resource.h"
46 #include "ppapi/proxy/url_loader_resource.h"
47 #include "ppapi/proxy/url_request_info_resource.h"
48 #include "ppapi/proxy/url_response_info_resource.h"
49 #include "ppapi/proxy/video_capture_resource.h"
50 #include "ppapi/proxy/video_destination_resource.h"
51 #include "ppapi/proxy/video_source_resource.h"
52 #include "ppapi/proxy/websocket_resource.h"
53 #include "ppapi/shared_impl/api_id.h"
54 #include "ppapi/shared_impl/host_resource.h"
55 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
56 #include "ppapi/shared_impl/ppb_audio_shared.h"
57 #include "ppapi/shared_impl/ppb_input_event_shared.h"
58 #include "ppapi/shared_impl/var.h"
59 #include "ppapi/thunk/enter.h"
60 #include "ppapi/thunk/ppb_image_data_api.h"
62 using ppapi::thunk::ResourceCreationAPI;
64 namespace ppapi {
65 namespace proxy {
67 ResourceCreationProxy::ResourceCreationProxy(Dispatcher* dispatcher)
68 : InterfaceProxy(dispatcher) {
71 ResourceCreationProxy::~ResourceCreationProxy() {
74 // static
75 InterfaceProxy* ResourceCreationProxy::Create(Dispatcher* dispatcher) {
76 return new ResourceCreationProxy(dispatcher);
79 PP_Resource ResourceCreationProxy::CreateFileIO(PP_Instance instance) {
80 return (new FileIOResource(GetConnection(), instance))->GetReference();
83 PP_Resource ResourceCreationProxy::CreateFileRef(
84 PP_Instance instance,
85 const FileRefCreateInfo& create_info) {
86 return FileRefResource::CreateFileRef(GetConnection(), instance, create_info);
89 PP_Resource ResourceCreationProxy::CreateFileSystem(
90 PP_Instance instance,
91 PP_FileSystemType type) {
92 return (new FileSystemResource(GetConnection(), instance,
93 type))->GetReference();
96 PP_Resource ResourceCreationProxy::CreateIMEInputEvent(
97 PP_Instance instance,
98 PP_InputEvent_Type type,
99 PP_TimeTicks time_stamp,
100 struct PP_Var text,
101 uint32_t segment_number,
102 const uint32_t* segment_offsets,
103 int32_t target_segment,
104 uint32_t selection_start,
105 uint32_t selection_end) {
106 return PPB_InputEvent_Shared::CreateIMEInputEvent(
107 OBJECT_IS_PROXY, instance, type, time_stamp, text, segment_number,
108 segment_offsets, target_segment, selection_start, selection_end);
111 PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent_1_0(
112 PP_Instance instance,
113 PP_InputEvent_Type type,
114 PP_TimeTicks time_stamp,
115 uint32_t modifiers,
116 uint32_t key_code,
117 struct PP_Var character_text) {
118 PP_Var code = StringVar::StringToPPVar("");
119 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(
120 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers, key_code,
121 character_text, code);
124 PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent_1_2(
125 PP_Instance instance,
126 PP_InputEvent_Type type,
127 PP_TimeTicks time_stamp,
128 uint32_t modifiers,
129 uint32_t key_code,
130 struct PP_Var character_text,
131 struct PP_Var code) {
132 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(
133 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers, key_code,
134 character_text, code);
137 PP_Resource ResourceCreationProxy::CreateMouseInputEvent(
138 PP_Instance instance,
139 PP_InputEvent_Type type,
140 PP_TimeTicks time_stamp,
141 uint32_t modifiers,
142 PP_InputEvent_MouseButton mouse_button,
143 const PP_Point* mouse_position,
144 int32_t click_count,
145 const PP_Point* mouse_movement) {
146 return PPB_InputEvent_Shared::CreateMouseInputEvent(
147 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers,
148 mouse_button, mouse_position, click_count, mouse_movement);
151 PP_Resource ResourceCreationProxy::CreateTouchInputEvent(
152 PP_Instance instance,
153 PP_InputEvent_Type type,
154 PP_TimeTicks time_stamp,
155 uint32_t modifiers) {
156 return PPB_InputEvent_Shared::CreateTouchInputEvent(
157 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers);
160 PP_Resource ResourceCreationProxy::CreateTrueTypeFont(
161 PP_Instance instance,
162 const PP_TrueTypeFontDesc_Dev* desc) {
163 return (new TrueTypeFontResource(GetConnection(),
164 instance, *desc))->GetReference();
168 PP_Resource ResourceCreationProxy::CreateURLLoader(PP_Instance instance) {
169 return (new URLLoaderResource(GetConnection(), instance))->GetReference();
172 PP_Resource ResourceCreationProxy::CreateURLRequestInfo(
173 PP_Instance instance) {
174 return (new URLRequestInfoResource(
175 GetConnection(), instance, URLRequestInfoData()))->GetReference();
178 PP_Resource ResourceCreationProxy::CreateWheelInputEvent(
179 PP_Instance instance,
180 PP_TimeTicks time_stamp,
181 uint32_t modifiers,
182 const PP_FloatPoint* wheel_delta,
183 const PP_FloatPoint* wheel_ticks,
184 PP_Bool scroll_by_page) {
185 return PPB_InputEvent_Shared::CreateWheelInputEvent(
186 OBJECT_IS_PROXY, instance, time_stamp, modifiers,
187 wheel_delta, wheel_ticks, scroll_by_page);
190 PP_Resource ResourceCreationProxy::CreateAudio1_0(
191 PP_Instance instance,
192 PP_Resource config_id,
193 PPB_Audio_Callback_1_0 audio_callback,
194 void* user_data) {
195 return PPB_Audio_Proxy::CreateProxyResource(
196 instance, config_id, AudioCallbackCombined(audio_callback), user_data);
199 PP_Resource ResourceCreationProxy::CreateAudio(
200 PP_Instance instance,
201 PP_Resource config_id,
202 PPB_Audio_Callback audio_callback,
203 void* user_data) {
204 return PPB_Audio_Proxy::CreateProxyResource(
205 instance, config_id, AudioCallbackCombined(audio_callback), user_data);
208 PP_Resource ResourceCreationProxy::CreateAudioTrusted(PP_Instance instance) {
209 // Proxied plugins can't create trusted audio devices.
210 return 0;
213 PP_Resource ResourceCreationProxy::CreateAudioConfig(
214 PP_Instance instance,
215 PP_AudioSampleRate sample_rate,
216 uint32_t sample_frame_count) {
217 return PPB_AudioConfig_Shared::Create(
218 OBJECT_IS_PROXY, instance, sample_rate, sample_frame_count);
221 PP_Resource ResourceCreationProxy::CreateFileChooser(
222 PP_Instance instance,
223 PP_FileChooserMode_Dev mode,
224 const PP_Var& accept_types) {
225 scoped_refptr<StringVar> string_var = StringVar::FromPPVar(accept_types);
226 std::string str = string_var.get() ? string_var->value() : std::string();
227 return (new FileChooserResource(GetConnection(), instance, mode, str.c_str()))
228 ->GetReference();
231 PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance,
232 const PP_Size* size,
233 PP_Bool is_always_opaque) {
234 return (new Graphics2DResource(GetConnection(), instance, *size,
235 is_always_opaque))->GetReference();
238 PP_Resource ResourceCreationProxy::CreateGraphics3D(
239 PP_Instance instance,
240 PP_Resource share_context,
241 const int32_t* attrib_list) {
242 return PPB_Graphics3D_Proxy::CreateProxyResource(
243 instance, share_context, attrib_list);
246 PP_Resource ResourceCreationProxy::CreateGraphics3DRaw(
247 PP_Instance instance,
248 PP_Resource share_context,
249 const int32_t* attrib_list) {
250 // Not proxied. The raw creation function is used only in the implementation
251 // of the proxy on the host side.
252 return 0;
255 PP_Resource ResourceCreationProxy::CreateHostResolver(PP_Instance instance) {
256 return (new HostResolverResource(GetConnection(), instance))->GetReference();
259 PP_Resource ResourceCreationProxy::CreateHostResolverPrivate(
260 PP_Instance instance) {
261 return (new HostResolverPrivateResource(
262 GetConnection(), instance))->GetReference();
265 PP_Resource ResourceCreationProxy::CreateImageData(
266 PP_Instance instance,
267 PP_ImageDataFormat format,
268 const PP_Size* size,
269 PP_Bool init_to_zero) {
270 // On the plugin side, we create PlatformImageData resources for trusted
271 // plugins and SimpleImageData resources for untrusted ones.
272 PPB_ImageData_Shared::ImageDataType type =
273 #if !defined(OS_NACL)
274 PPB_ImageData_Shared::PLATFORM;
275 #else
276 PPB_ImageData_Shared::SIMPLE;
277 #endif
278 return PPB_ImageData_Proxy::CreateProxyResource(
279 instance, type,
280 format, *size, init_to_zero);
283 PP_Resource ResourceCreationProxy::CreateImageDataSimple(
284 PP_Instance instance,
285 PP_ImageDataFormat format,
286 const PP_Size* size,
287 PP_Bool init_to_zero) {
288 return PPB_ImageData_Proxy::CreateProxyResource(
289 instance,
290 PPB_ImageData_Shared::SIMPLE,
291 format, *size, init_to_zero);
294 PP_Resource ResourceCreationProxy::CreateMediaStreamVideoTrack(
295 PP_Instance instance) {
296 return (new MediaStreamVideoTrackResource(GetConnection(),
297 instance))->GetReference();
300 PP_Resource ResourceCreationProxy::CreateNetAddressFromIPv4Address(
301 PP_Instance instance,
302 const PP_NetAddress_IPv4* ipv4_addr) {
303 return (new NetAddressResource(GetConnection(), instance,
304 *ipv4_addr))->GetReference();
307 PP_Resource ResourceCreationProxy::CreateNetAddressFromIPv6Address(
308 PP_Instance instance,
309 const PP_NetAddress_IPv6* ipv6_addr) {
310 return (new NetAddressResource(GetConnection(), instance,
311 *ipv6_addr))->GetReference();
314 PP_Resource ResourceCreationProxy::CreateNetAddressFromNetAddressPrivate(
315 PP_Instance instance,
316 const PP_NetAddress_Private& private_addr) {
317 return (new NetAddressResource(GetConnection(), instance,
318 private_addr))->GetReference();
321 PP_Resource ResourceCreationProxy::CreateNetworkMonitor(
322 PP_Instance instance) {
323 return (new NetworkMonitorResource(GetConnection(), instance))->
324 GetReference();
327 PP_Resource ResourceCreationProxy::CreateOutputProtectionPrivate(
328 PP_Instance instance) {
329 return (new OutputProtectionResource(GetConnection(), instance))->
330 GetReference();
333 PP_Resource ResourceCreationProxy::CreatePrinting(PP_Instance instance) {
334 return (new PrintingResource(GetConnection(), instance))->GetReference();
337 PP_Resource ResourceCreationProxy::CreateTCPServerSocketPrivate(
338 PP_Instance instance) {
339 return (new TCPServerSocketPrivateResource(GetConnection(), instance))->
340 GetReference();
343 PP_Resource ResourceCreationProxy::CreateTCPSocket1_0(
344 PP_Instance instance) {
345 return (new TCPSocketResource(GetConnection(), instance,
346 TCP_SOCKET_VERSION_1_0))->GetReference();
349 PP_Resource ResourceCreationProxy::CreateTCPSocket(
350 PP_Instance instance) {
351 return (new TCPSocketResource(
352 GetConnection(), instance, TCP_SOCKET_VERSION_1_1_OR_ABOVE))->
353 GetReference();
356 PP_Resource ResourceCreationProxy::CreateTCPSocketPrivate(
357 PP_Instance instance) {
358 return (new TCPSocketPrivateResource(GetConnection(), instance))->
359 GetReference();
362 PP_Resource ResourceCreationProxy::CreateUDPSocket(PP_Instance instance) {
363 return (new UDPSocketResource(GetConnection(), instance))->GetReference();
366 PP_Resource ResourceCreationProxy::CreateUDPSocketPrivate(
367 PP_Instance instance) {
368 return (new UDPSocketPrivateResource(
369 GetConnection(), instance))->GetReference();
372 PP_Resource ResourceCreationProxy::CreateVideoDestination(
373 PP_Instance instance) {
374 return (new VideoDestinationResource(GetConnection(),
375 instance))->GetReference();
378 PP_Resource ResourceCreationProxy::CreateVideoSource(
379 PP_Instance instance) {
380 return (new VideoSourceResource(GetConnection(), instance))->GetReference();
383 PP_Resource ResourceCreationProxy::CreateWebSocket(PP_Instance instance) {
384 return (new WebSocketResource(GetConnection(), instance))->GetReference();
387 PP_Resource ResourceCreationProxy::CreateX509CertificatePrivate(
388 PP_Instance instance) {
389 return PPB_X509Certificate_Private_Proxy::CreateProxyResource(instance);
392 #if !defined(OS_NACL)
393 PP_Resource ResourceCreationProxy::CreateAudioInput(
394 PP_Instance instance) {
395 return (new AudioInputResource(GetConnection(), instance))->GetReference();
398 PP_Resource ResourceCreationProxy::CreateBroker(PP_Instance instance) {
399 return PPB_Broker_Proxy::CreateProxyResource(instance);
402 PP_Resource ResourceCreationProxy::CreateBrowserFont(
403 PP_Instance instance,
404 const PP_BrowserFont_Trusted_Description* description) {
405 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
406 if (!dispatcher)
407 return 0;
408 return PluginGlobals::Get()->CreateBrowserFont(
409 GetConnection(), instance, *description, dispatcher->preferences());
412 PP_Resource ResourceCreationProxy::CreateBuffer(PP_Instance instance,
413 uint32_t size) {
414 return PPB_Buffer_Proxy::CreateProxyResource(instance, size);
417 PP_Resource ResourceCreationProxy::CreateFlashDRM(PP_Instance instance) {
418 return (new FlashDRMResource(GetConnection(), instance))->GetReference();
421 PP_Resource ResourceCreationProxy::CreateFlashFontFile(
422 PP_Instance instance,
423 const PP_BrowserFont_Trusted_Description* description,
424 PP_PrivateFontCharset charset) {
425 return (new FlashFontFileResource(
426 GetConnection(), instance, description, charset))->GetReference();
429 PP_Resource ResourceCreationProxy::CreateFlashMenu(
430 PP_Instance instance,
431 const PP_Flash_Menu* menu_data) {
432 scoped_refptr<FlashMenuResource> flash_menu(
433 new FlashMenuResource(GetConnection(), instance));
434 if (!flash_menu->Initialize(menu_data))
435 return 0;
436 return flash_menu->GetReference();
439 PP_Resource ResourceCreationProxy::CreateFlashMessageLoop(
440 PP_Instance instance) {
441 return PPB_Flash_MessageLoop_Proxy::CreateProxyResource(instance);
444 PP_Resource ResourceCreationProxy::CreatePlatformVerificationPrivate(
445 PP_Instance instance) {
446 return (new PlatformVerificationPrivateResource(GetConnection(), instance))->
447 GetReference();
450 PP_Resource ResourceCreationProxy::CreateScrollbar(PP_Instance instance,
451 PP_Bool vertical) {
452 NOTIMPLEMENTED(); // Not proxied yet.
453 return 0;
456 PP_Resource ResourceCreationProxy::CreateTalk(PP_Instance instance) {
457 return (new TalkResource(GetConnection(), instance))->GetReference();
460 PP_Resource ResourceCreationProxy::CreateVideoCapture(PP_Instance instance) {
461 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
462 if (!dispatcher)
463 return 0;
464 return (new VideoCaptureResource(GetConnection(), instance, dispatcher))
465 ->GetReference();
468 PP_Resource ResourceCreationProxy::CreateVideoDecoderDev(
469 PP_Instance instance,
470 PP_Resource context3d_id,
471 PP_VideoDecoder_Profile profile) {
472 return PPB_VideoDecoder_Proxy::CreateProxyResource(
473 instance, context3d_id, profile);
476 #endif // !defined(OS_NACL)
478 bool ResourceCreationProxy::Send(IPC::Message* msg) {
479 return dispatcher()->Send(msg);
482 bool ResourceCreationProxy::OnMessageReceived(const IPC::Message& msg) {
483 return false;
486 Connection ResourceCreationProxy::GetConnection() {
487 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
490 } // namespace proxy
491 } // namespace ppapi