Android NTP: Most visited tile clicks should have PageTransition.AUTO_BOOKMARK
[chromium-blink-merge.git] / ppapi / proxy / resource_creation_proxy.cc
blobaa522ee01393bcb8ab13ec7f47ad25f492899f95
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/tcp_server_socket_private_resource.h"
42 #include "ppapi/proxy/tcp_socket_private_resource.h"
43 #include "ppapi/proxy/tcp_socket_resource.h"
44 #include "ppapi/proxy/truetype_font_resource.h"
45 #include "ppapi/proxy/udp_socket_private_resource.h"
46 #include "ppapi/proxy/udp_socket_resource.h"
47 #include "ppapi/proxy/url_loader_resource.h"
48 #include "ppapi/proxy/url_request_info_resource.h"
49 #include "ppapi/proxy/url_response_info_resource.h"
50 #include "ppapi/proxy/video_capture_resource.h"
51 #include "ppapi/proxy/video_decoder_resource.h"
52 #include "ppapi/proxy/video_destination_resource.h"
53 #include "ppapi/proxy/video_encoder_resource.h"
54 #include "ppapi/proxy/video_source_resource.h"
55 #include "ppapi/proxy/websocket_resource.h"
56 #include "ppapi/shared_impl/api_id.h"
57 #include "ppapi/shared_impl/host_resource.h"
58 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
59 #include "ppapi/shared_impl/ppb_audio_shared.h"
60 #include "ppapi/shared_impl/ppb_input_event_shared.h"
61 #include "ppapi/shared_impl/var.h"
62 #include "ppapi/thunk/enter.h"
63 #include "ppapi/thunk/ppb_image_data_api.h"
65 using ppapi::thunk::ResourceCreationAPI;
67 namespace ppapi {
68 namespace proxy {
70 ResourceCreationProxy::ResourceCreationProxy(Dispatcher* dispatcher)
71 : InterfaceProxy(dispatcher) {
74 ResourceCreationProxy::~ResourceCreationProxy() {
77 // static
78 InterfaceProxy* ResourceCreationProxy::Create(Dispatcher* dispatcher) {
79 return new ResourceCreationProxy(dispatcher);
82 PP_Resource ResourceCreationProxy::CreateFileIO(PP_Instance instance) {
83 return (new FileIOResource(GetConnection(), instance))->GetReference();
86 PP_Resource ResourceCreationProxy::CreateFileRef(
87 PP_Instance instance,
88 const FileRefCreateInfo& create_info) {
89 return FileRefResource::CreateFileRef(GetConnection(), instance, create_info);
92 PP_Resource ResourceCreationProxy::CreateFileSystem(
93 PP_Instance instance,
94 PP_FileSystemType type) {
95 return (new FileSystemResource(GetConnection(), instance,
96 type))->GetReference();
99 PP_Resource ResourceCreationProxy::CreateIMEInputEvent(
100 PP_Instance instance,
101 PP_InputEvent_Type type,
102 PP_TimeTicks time_stamp,
103 struct PP_Var text,
104 uint32_t segment_number,
105 const uint32_t* segment_offsets,
106 int32_t target_segment,
107 uint32_t selection_start,
108 uint32_t selection_end) {
109 return PPB_InputEvent_Shared::CreateIMEInputEvent(
110 OBJECT_IS_PROXY, instance, type, time_stamp, text, segment_number,
111 segment_offsets, target_segment, selection_start, selection_end);
114 PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent_1_0(
115 PP_Instance instance,
116 PP_InputEvent_Type type,
117 PP_TimeTicks time_stamp,
118 uint32_t modifiers,
119 uint32_t key_code,
120 struct PP_Var character_text) {
121 PP_Var code = StringVar::StringToPPVar("");
122 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(
123 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers, key_code,
124 character_text, code);
127 PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent_1_2(
128 PP_Instance instance,
129 PP_InputEvent_Type type,
130 PP_TimeTicks time_stamp,
131 uint32_t modifiers,
132 uint32_t key_code,
133 struct PP_Var character_text,
134 struct PP_Var code) {
135 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(
136 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers, key_code,
137 character_text, code);
140 PP_Resource ResourceCreationProxy::CreateMouseInputEvent(
141 PP_Instance instance,
142 PP_InputEvent_Type type,
143 PP_TimeTicks time_stamp,
144 uint32_t modifiers,
145 PP_InputEvent_MouseButton mouse_button,
146 const PP_Point* mouse_position,
147 int32_t click_count,
148 const PP_Point* mouse_movement) {
149 return PPB_InputEvent_Shared::CreateMouseInputEvent(
150 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers,
151 mouse_button, mouse_position, click_count, mouse_movement);
154 PP_Resource ResourceCreationProxy::CreateTouchInputEvent(
155 PP_Instance instance,
156 PP_InputEvent_Type type,
157 PP_TimeTicks time_stamp,
158 uint32_t modifiers) {
159 return PPB_InputEvent_Shared::CreateTouchInputEvent(
160 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers);
163 PP_Resource ResourceCreationProxy::CreateTrueTypeFont(
164 PP_Instance instance,
165 const PP_TrueTypeFontDesc_Dev* desc) {
166 return (new TrueTypeFontResource(GetConnection(),
167 instance, *desc))->GetReference();
171 PP_Resource ResourceCreationProxy::CreateURLLoader(PP_Instance instance) {
172 return (new URLLoaderResource(GetConnection(), instance))->GetReference();
175 PP_Resource ResourceCreationProxy::CreateURLRequestInfo(
176 PP_Instance instance) {
177 return (new URLRequestInfoResource(
178 GetConnection(), instance, URLRequestInfoData()))->GetReference();
181 PP_Resource ResourceCreationProxy::CreateWheelInputEvent(
182 PP_Instance instance,
183 PP_TimeTicks time_stamp,
184 uint32_t modifiers,
185 const PP_FloatPoint* wheel_delta,
186 const PP_FloatPoint* wheel_ticks,
187 PP_Bool scroll_by_page) {
188 return PPB_InputEvent_Shared::CreateWheelInputEvent(
189 OBJECT_IS_PROXY, instance, time_stamp, modifiers,
190 wheel_delta, wheel_ticks, scroll_by_page);
193 PP_Resource ResourceCreationProxy::CreateAudio1_0(
194 PP_Instance instance,
195 PP_Resource config_id,
196 PPB_Audio_Callback_1_0 audio_callback,
197 void* user_data) {
198 return PPB_Audio_Proxy::CreateProxyResource(
199 instance, config_id, AudioCallbackCombined(audio_callback), user_data);
202 PP_Resource ResourceCreationProxy::CreateAudio(
203 PP_Instance instance,
204 PP_Resource config_id,
205 PPB_Audio_Callback audio_callback,
206 void* user_data) {
207 return PPB_Audio_Proxy::CreateProxyResource(
208 instance, config_id, AudioCallbackCombined(audio_callback), user_data);
211 PP_Resource ResourceCreationProxy::CreateAudioTrusted(PP_Instance instance) {
212 // Proxied plugins can't create trusted audio devices.
213 return 0;
216 PP_Resource ResourceCreationProxy::CreateAudioConfig(
217 PP_Instance instance,
218 PP_AudioSampleRate sample_rate,
219 uint32_t sample_frame_count) {
220 return PPB_AudioConfig_Shared::Create(
221 OBJECT_IS_PROXY, instance, sample_rate, sample_frame_count);
224 PP_Resource ResourceCreationProxy::CreateCameraDevicePrivate(
225 PP_Instance instance) {
226 return (new CameraDeviceResource(GetConnection(), instance))->GetReference();
229 PP_Resource ResourceCreationProxy::CreateCompositor(PP_Instance instance) {
230 return (new CompositorResource(GetConnection(), instance))->GetReference();
233 PP_Resource ResourceCreationProxy::CreateFileChooser(
234 PP_Instance instance,
235 PP_FileChooserMode_Dev mode,
236 const PP_Var& accept_types) {
237 scoped_refptr<StringVar> string_var = StringVar::FromPPVar(accept_types);
238 std::string str = string_var.get() ? string_var->value() : std::string();
239 return (new FileChooserResource(GetConnection(), instance, mode, str.c_str()))
240 ->GetReference();
243 PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance,
244 const PP_Size* size,
245 PP_Bool is_always_opaque) {
246 return (new Graphics2DResource(GetConnection(), instance, *size,
247 is_always_opaque))->GetReference();
250 PP_Resource ResourceCreationProxy::CreateGraphics3D(
251 PP_Instance instance,
252 PP_Resource share_context,
253 const int32_t* attrib_list) {
254 return PPB_Graphics3D_Proxy::CreateProxyResource(
255 instance, share_context, attrib_list);
258 PP_Resource ResourceCreationProxy::CreateGraphics3DRaw(
259 PP_Instance instance,
260 PP_Resource share_context,
261 const int32_t* attrib_list,
262 gpu::Capabilities* capabilities,
263 base::SharedMemoryHandle* shared_state) {
264 // Not proxied. The raw creation function is used only in the implementation
265 // of the proxy on the host side.
266 return 0;
269 PP_Resource ResourceCreationProxy::CreateHostResolver(PP_Instance instance) {
270 return (new HostResolverResource(GetConnection(), instance))->GetReference();
273 PP_Resource ResourceCreationProxy::CreateHostResolverPrivate(
274 PP_Instance instance) {
275 return (new HostResolverPrivateResource(
276 GetConnection(), instance))->GetReference();
279 PP_Resource ResourceCreationProxy::CreateImageData(
280 PP_Instance instance,
281 PP_ImageDataFormat format,
282 const PP_Size* size,
283 PP_Bool init_to_zero) {
284 // On the plugin side, we create PlatformImageData resources for trusted
285 // plugins and SimpleImageData resources for untrusted ones.
286 PPB_ImageData_Shared::ImageDataType type =
287 #if !defined(OS_NACL)
288 PPB_ImageData_Shared::PLATFORM;
289 #else
290 PPB_ImageData_Shared::SIMPLE;
291 #endif
292 return PPB_ImageData_Proxy::CreateProxyResource(
293 instance, type,
294 format, *size, init_to_zero);
297 PP_Resource ResourceCreationProxy::CreateImageDataSimple(
298 PP_Instance instance,
299 PP_ImageDataFormat format,
300 const PP_Size* size,
301 PP_Bool init_to_zero) {
302 return PPB_ImageData_Proxy::CreateProxyResource(
303 instance,
304 PPB_ImageData_Shared::SIMPLE,
305 format, *size, init_to_zero);
308 PP_Resource ResourceCreationProxy::CreateMediaStreamVideoTrack(
309 PP_Instance instance) {
310 return (new MediaStreamVideoTrackResource(GetConnection(),
311 instance))->GetReference();
314 PP_Resource ResourceCreationProxy::CreateNetAddressFromIPv4Address(
315 PP_Instance instance,
316 const PP_NetAddress_IPv4* ipv4_addr) {
317 return (new NetAddressResource(GetConnection(), instance,
318 *ipv4_addr))->GetReference();
321 PP_Resource ResourceCreationProxy::CreateNetAddressFromIPv6Address(
322 PP_Instance instance,
323 const PP_NetAddress_IPv6* ipv6_addr) {
324 return (new NetAddressResource(GetConnection(), instance,
325 *ipv6_addr))->GetReference();
328 PP_Resource ResourceCreationProxy::CreateNetAddressFromNetAddressPrivate(
329 PP_Instance instance,
330 const PP_NetAddress_Private& private_addr) {
331 return (new NetAddressResource(GetConnection(), instance,
332 private_addr))->GetReference();
335 PP_Resource ResourceCreationProxy::CreateNetworkMonitor(
336 PP_Instance instance) {
337 return (new NetworkMonitorResource(GetConnection(), instance))->
338 GetReference();
341 PP_Resource ResourceCreationProxy::CreateOutputProtectionPrivate(
342 PP_Instance instance) {
343 return (new OutputProtectionResource(GetConnection(), instance))->
344 GetReference();
347 PP_Resource ResourceCreationProxy::CreatePrinting(PP_Instance instance) {
348 return (new PrintingResource(GetConnection(), instance))->GetReference();
351 PP_Resource ResourceCreationProxy::CreateTCPServerSocketPrivate(
352 PP_Instance instance) {
353 return (new TCPServerSocketPrivateResource(GetConnection(), instance))->
354 GetReference();
357 PP_Resource ResourceCreationProxy::CreateTCPSocket1_0(
358 PP_Instance instance) {
359 return (new TCPSocketResource(GetConnection(), instance,
360 TCP_SOCKET_VERSION_1_0))->GetReference();
363 PP_Resource ResourceCreationProxy::CreateTCPSocket(
364 PP_Instance instance) {
365 return (new TCPSocketResource(
366 GetConnection(), instance, TCP_SOCKET_VERSION_1_1_OR_ABOVE))->
367 GetReference();
370 PP_Resource ResourceCreationProxy::CreateTCPSocketPrivate(
371 PP_Instance instance) {
372 return (new TCPSocketPrivateResource(GetConnection(), instance))->
373 GetReference();
376 PP_Resource ResourceCreationProxy::CreateUDPSocket(PP_Instance instance) {
377 return (new UDPSocketResource(GetConnection(), instance))->GetReference();
380 PP_Resource ResourceCreationProxy::CreateUDPSocketPrivate(
381 PP_Instance instance) {
382 return (new UDPSocketPrivateResource(
383 GetConnection(), instance))->GetReference();
386 PP_Resource ResourceCreationProxy::CreateVideoDecoder(PP_Instance instance) {
387 return (new VideoDecoderResource(GetConnection(), instance))->GetReference();
390 PP_Resource ResourceCreationProxy::CreateVideoDestination(
391 PP_Instance instance) {
392 return (new VideoDestinationResource(GetConnection(),
393 instance))->GetReference();
396 PP_Resource ResourceCreationProxy::CreateVideoEncoder(PP_Instance instance) {
397 return (new VideoEncoderResource(GetConnection(), instance))->GetReference();
400 PP_Resource ResourceCreationProxy::CreateVideoSource(
401 PP_Instance instance) {
402 return (new VideoSourceResource(GetConnection(), instance))->GetReference();
405 PP_Resource ResourceCreationProxy::CreateWebSocket(PP_Instance instance) {
406 return (new WebSocketResource(GetConnection(), instance))->GetReference();
409 PP_Resource ResourceCreationProxy::CreateX509CertificatePrivate(
410 PP_Instance instance) {
411 return PPB_X509Certificate_Private_Proxy::CreateProxyResource(instance);
414 #if !defined(OS_NACL)
415 PP_Resource ResourceCreationProxy::CreateAudioInput(
416 PP_Instance instance) {
417 return (new AudioInputResource(GetConnection(), instance))->GetReference();
420 PP_Resource ResourceCreationProxy::CreateBroker(PP_Instance instance) {
421 return PPB_Broker_Proxy::CreateProxyResource(instance);
424 PP_Resource ResourceCreationProxy::CreateBrowserFont(
425 PP_Instance instance,
426 const PP_BrowserFont_Trusted_Description* description) {
427 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
428 if (!dispatcher)
429 return 0;
430 return PluginGlobals::Get()->CreateBrowserFont(
431 GetConnection(), instance, *description, dispatcher->preferences());
434 PP_Resource ResourceCreationProxy::CreateBuffer(PP_Instance instance,
435 uint32_t size) {
436 return PPB_Buffer_Proxy::CreateProxyResource(instance, size);
439 PP_Resource ResourceCreationProxy::CreateFlashDRM(PP_Instance instance) {
440 return (new FlashDRMResource(GetConnection(), instance))->GetReference();
443 PP_Resource ResourceCreationProxy::CreateFlashFontFile(
444 PP_Instance instance,
445 const PP_BrowserFont_Trusted_Description* description,
446 PP_PrivateFontCharset charset) {
447 return (new FlashFontFileResource(
448 GetConnection(), instance, description, charset))->GetReference();
451 PP_Resource ResourceCreationProxy::CreateFlashMenu(
452 PP_Instance instance,
453 const PP_Flash_Menu* menu_data) {
454 scoped_refptr<FlashMenuResource> flash_menu(
455 new FlashMenuResource(GetConnection(), instance));
456 if (!flash_menu->Initialize(menu_data))
457 return 0;
458 return flash_menu->GetReference();
461 PP_Resource ResourceCreationProxy::CreateFlashMessageLoop(
462 PP_Instance instance) {
463 return PPB_Flash_MessageLoop_Proxy::CreateProxyResource(instance);
466 PP_Resource ResourceCreationProxy::CreatePlatformVerificationPrivate(
467 PP_Instance instance) {
468 return (new PlatformVerificationPrivateResource(GetConnection(), instance))->
469 GetReference();
472 PP_Resource ResourceCreationProxy::CreateVideoCapture(PP_Instance instance) {
473 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
474 if (!dispatcher)
475 return 0;
476 return (new VideoCaptureResource(GetConnection(), instance, dispatcher))
477 ->GetReference();
480 PP_Resource ResourceCreationProxy::CreateVideoDecoderDev(
481 PP_Instance instance,
482 PP_Resource context3d_id,
483 PP_VideoDecoder_Profile profile) {
484 return PPB_VideoDecoder_Proxy::CreateProxyResource(
485 instance, context3d_id, profile);
488 #endif // !defined(OS_NACL)
490 bool ResourceCreationProxy::Send(IPC::Message* msg) {
491 return dispatcher()->Send(msg);
494 bool ResourceCreationProxy::OnMessageReceived(const IPC::Message& msg) {
495 return false;
498 Connection ResourceCreationProxy::GetConnection() {
499 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
502 } // namespace proxy
503 } // namespace ppapi