Refactor android test results logging.
[chromium-blink-merge.git] / ppapi / proxy / resource_creation_proxy.cc
blob90a23bb844eee8d1f83ca4308bfec8581551706e
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/c/trusted/ppb_image_data_trusted.h"
10 #include "ppapi/proxy/audio_input_resource.h"
11 #include "ppapi/proxy/browser_font_resource_trusted.h"
12 #include "ppapi/proxy/connection.h"
13 #include "ppapi/proxy/file_chooser_resource.h"
14 #include "ppapi/proxy/flash_device_id_resource.h"
15 #include "ppapi/proxy/flash_font_file_resource.h"
16 #include "ppapi/proxy/flash_menu_resource.h"
17 #include "ppapi/proxy/graphics_2d_resource.h"
18 #include "ppapi/proxy/plugin_dispatcher.h"
19 #include "ppapi/proxy/plugin_globals.h"
20 #include "ppapi/proxy/plugin_resource_tracker.h"
21 #include "ppapi/proxy/ppapi_messages.h"
22 #include "ppapi/proxy/ppb_audio_proxy.h"
23 #include "ppapi/proxy/ppb_broker_proxy.h"
24 #include "ppapi/proxy/ppb_buffer_proxy.h"
25 #include "ppapi/proxy/ppb_file_io_proxy.h"
26 #include "ppapi/proxy/ppb_file_ref_proxy.h"
27 #include "ppapi/proxy/ppb_file_system_proxy.h"
28 #include "ppapi/proxy/ppb_flash_message_loop_proxy.h"
29 #include "ppapi/proxy/ppb_graphics_3d_proxy.h"
30 #include "ppapi/proxy/ppb_host_resolver_private_proxy.h"
31 #include "ppapi/proxy/ppb_image_data_proxy.h"
32 #include "ppapi/proxy/ppb_network_monitor_private_proxy.h"
33 #include "ppapi/proxy/ppb_tcp_server_socket_private_proxy.h"
34 #include "ppapi/proxy/ppb_tcp_socket_private_proxy.h"
35 #include "ppapi/proxy/ppb_udp_socket_private_proxy.h"
36 #include "ppapi/proxy/ppb_url_loader_proxy.h"
37 #include "ppapi/proxy/ppb_video_decoder_proxy.h"
38 #include "ppapi/proxy/ppb_x509_certificate_private_proxy.h"
39 #include "ppapi/proxy/printing_resource.h"
40 #include "ppapi/proxy/talk_resource.h"
41 #include "ppapi/proxy/url_request_info_resource.h"
42 #include "ppapi/proxy/url_response_info_resource.h"
43 #include "ppapi/proxy/video_capture_resource.h"
44 #include "ppapi/proxy/websocket_resource.h"
45 #include "ppapi/shared_impl/api_id.h"
46 #include "ppapi/shared_impl/host_resource.h"
47 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
48 #include "ppapi/shared_impl/ppb_input_event_shared.h"
49 #include "ppapi/shared_impl/ppb_resource_array_shared.h"
50 #include "ppapi/shared_impl/var.h"
51 #include "ppapi/thunk/enter.h"
52 #include "ppapi/thunk/ppb_image_data_api.h"
54 using ppapi::thunk::ResourceCreationAPI;
56 namespace ppapi {
57 namespace proxy {
59 ResourceCreationProxy::ResourceCreationProxy(Dispatcher* dispatcher)
60 : InterfaceProxy(dispatcher) {
63 ResourceCreationProxy::~ResourceCreationProxy() {
66 // static
67 InterfaceProxy* ResourceCreationProxy::Create(Dispatcher* dispatcher) {
68 return new ResourceCreationProxy(dispatcher);
71 PP_Resource ResourceCreationProxy::CreateFileIO(PP_Instance instance) {
72 return PPB_FileIO_Proxy::CreateProxyResource(instance);
75 PP_Resource ResourceCreationProxy::CreateFileRef(PP_Resource file_system,
76 const char* path) {
77 return PPB_FileRef_Proxy::CreateProxyResource(file_system, path);
80 PP_Resource ResourceCreationProxy::CreateFileSystem(
81 PP_Instance instance,
82 PP_FileSystemType type) {
83 return PPB_FileSystem_Proxy::CreateProxyResource(instance, type);
86 PP_Resource ResourceCreationProxy::CreateIMEInputEvent(
87 PP_Instance instance,
88 PP_InputEvent_Type type,
89 PP_TimeTicks time_stamp,
90 struct PP_Var text,
91 uint32_t segment_number,
92 const uint32_t* segment_offsets,
93 int32_t target_segment,
94 uint32_t selection_start,
95 uint32_t selection_end) {
96 return PPB_InputEvent_Shared::CreateIMEInputEvent(
97 OBJECT_IS_PROXY, instance, type, time_stamp, text, segment_number,
98 segment_offsets, target_segment, selection_start, selection_end);
101 PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent(
102 PP_Instance instance,
103 PP_InputEvent_Type type,
104 PP_TimeTicks time_stamp,
105 uint32_t modifiers,
106 uint32_t key_code,
107 struct PP_Var character_text) {
108 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(
109 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers, key_code,
110 character_text);
113 PP_Resource ResourceCreationProxy::CreateMouseInputEvent(
114 PP_Instance instance,
115 PP_InputEvent_Type type,
116 PP_TimeTicks time_stamp,
117 uint32_t modifiers,
118 PP_InputEvent_MouseButton mouse_button,
119 const PP_Point* mouse_position,
120 int32_t click_count,
121 const PP_Point* mouse_movement) {
122 return PPB_InputEvent_Shared::CreateMouseInputEvent(
123 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers,
124 mouse_button, mouse_position, click_count, mouse_movement);
127 PP_Resource ResourceCreationProxy::CreateTouchInputEvent(
128 PP_Instance instance,
129 PP_InputEvent_Type type,
130 PP_TimeTicks time_stamp,
131 uint32_t modifiers) {
132 return PPB_InputEvent_Shared::CreateTouchInputEvent(
133 OBJECT_IS_PROXY, instance, type, time_stamp, modifiers);
136 PP_Resource ResourceCreationProxy::CreateResourceArray(
137 PP_Instance instance,
138 const PP_Resource elements[],
139 uint32_t size) {
140 PPB_ResourceArray_Shared* object = new PPB_ResourceArray_Shared(
141 OBJECT_IS_PROXY, instance, elements, size);
142 return object->GetReference();
145 PP_Resource ResourceCreationProxy::CreateURLLoader(PP_Instance instance) {
146 return PPB_URLLoader_Proxy::CreateProxyResource(instance);
149 PP_Resource ResourceCreationProxy::CreateURLRequestInfo(
150 PP_Instance instance,
151 const URLRequestInfoData& data) {
152 return (new URLRequestInfoResource(GetConnection(),
153 instance, data))->GetReference();
156 PP_Resource ResourceCreationProxy::CreateURLResponseInfo(
157 PP_Instance instance,
158 const URLResponseInfoData& data,
159 PP_Resource file_ref_resource) {
160 return (new URLResponseInfoResource(GetConnection(), instance,
161 data,
162 file_ref_resource))->GetReference();
165 PP_Resource ResourceCreationProxy::CreateWheelInputEvent(
166 PP_Instance instance,
167 PP_TimeTicks time_stamp,
168 uint32_t modifiers,
169 const PP_FloatPoint* wheel_delta,
170 const PP_FloatPoint* wheel_ticks,
171 PP_Bool scroll_by_page) {
172 return PPB_InputEvent_Shared::CreateWheelInputEvent(
173 OBJECT_IS_PROXY, instance, time_stamp, modifiers,
174 wheel_delta, wheel_ticks, scroll_by_page);
177 PP_Resource ResourceCreationProxy::CreateAudio(
178 PP_Instance instance,
179 PP_Resource config_id,
180 PPB_Audio_Callback audio_callback,
181 void* user_data) {
182 return PPB_Audio_Proxy::CreateProxyResource(instance, config_id,
183 audio_callback, user_data);
186 PP_Resource ResourceCreationProxy::CreateAudioTrusted(PP_Instance instance) {
187 // Proxied plugins can't create trusted audio devices.
188 return 0;
191 PP_Resource ResourceCreationProxy::CreateAudioConfig(
192 PP_Instance instance,
193 PP_AudioSampleRate sample_rate,
194 uint32_t sample_frame_count) {
195 return PPB_AudioConfig_Shared::Create(
196 OBJECT_IS_PROXY, instance, sample_rate, sample_frame_count);
199 PP_Resource ResourceCreationProxy::CreateFileChooser(
200 PP_Instance instance,
201 PP_FileChooserMode_Dev mode,
202 const char* accept_types) {
203 return (new FileChooserResource(GetConnection(), instance, mode,
204 accept_types))->GetReference();
207 PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance,
208 const PP_Size& size,
209 PP_Bool is_always_opaque) {
210 return (new Graphics2DResource(GetConnection(), instance, size,
211 is_always_opaque))->GetReference();
214 PP_Resource ResourceCreationProxy::CreateGraphics3D(
215 PP_Instance instance,
216 PP_Resource share_context,
217 const int32_t* attrib_list) {
218 return PPB_Graphics3D_Proxy::CreateProxyResource(
219 instance, share_context, attrib_list);
222 PP_Resource ResourceCreationProxy::CreateGraphics3DRaw(
223 PP_Instance instance,
224 PP_Resource share_context,
225 const int32_t* attrib_list) {
226 // Not proxied. The raw creation function is used only in the implementation
227 // of the proxy on the host side.
228 return 0;
231 PP_Resource ResourceCreationProxy::CreateHostResolverPrivate(
232 PP_Instance instance) {
233 return PPB_HostResolver_Private_Proxy::CreateProxyResource(instance);
236 PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance,
237 PP_ImageDataFormat format,
238 const PP_Size& size,
239 PP_Bool init_to_zero) {
240 return PPB_ImageData_Proxy::CreateProxyResource(instance, format, size,
241 init_to_zero);
244 PP_Resource ResourceCreationProxy::CreateImageDataNaCl(
245 PP_Instance instance,
246 PP_ImageDataFormat format,
247 const PP_Size& size,
248 PP_Bool init_to_zero) {
249 // These really only are different on the host side. On the plugin side, we
250 // always request a "platform" ImageData if we're trusted, or a "NaCl" one
251 // if we're untrusted (see PPB_ImageData_Proxy::CreateProxyResource()).
252 return CreateImageData(instance, format, size, init_to_zero);
255 PP_Resource ResourceCreationProxy::CreateNetworkMonitor(
256 PP_Instance instance,
257 PPB_NetworkMonitor_Callback callback,
258 void* user_data) {
259 return PPB_NetworkMonitor_Private_Proxy::CreateProxyResource(
260 instance, callback, user_data);
263 PP_Resource ResourceCreationProxy::CreatePrinting(PP_Instance instance) {
264 return (new PrintingResource(GetConnection(), instance))->GetReference();
267 PP_Resource ResourceCreationProxy::CreateTCPServerSocketPrivate(
268 PP_Instance instance) {
269 return PPB_TCPServerSocket_Private_Proxy::CreateProxyResource(instance);
272 PP_Resource ResourceCreationProxy::CreateTCPSocketPrivate(
273 PP_Instance instance) {
274 return PPB_TCPSocket_Private_Proxy::CreateProxyResource(instance);
277 PP_Resource ResourceCreationProxy::CreateUDPSocketPrivate(
278 PP_Instance instance) {
279 return PPB_UDPSocket_Private_Proxy::CreateProxyResource(instance);
282 PP_Resource ResourceCreationProxy::CreateWebSocket(PP_Instance instance) {
283 return (new WebSocketResource(GetConnection(), instance))->GetReference();
286 PP_Resource ResourceCreationProxy::CreateX509CertificatePrivate(
287 PP_Instance instance) {
288 return PPB_X509Certificate_Private_Proxy::CreateProxyResource(instance);
291 #if !defined(OS_NACL)
292 PP_Resource ResourceCreationProxy::CreateAudioInput(
293 PP_Instance instance) {
294 return (new AudioInputResource(GetConnection(), instance))->GetReference();
297 PP_Resource ResourceCreationProxy::CreateBroker(PP_Instance instance) {
298 return PPB_Broker_Proxy::CreateProxyResource(instance);
301 PP_Resource ResourceCreationProxy::CreateBrowserFont(
302 PP_Instance instance,
303 const PP_BrowserFont_Trusted_Description* description) {
304 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
305 if (!dispatcher)
306 return 0;
307 if (!BrowserFontResource_Trusted::IsPPFontDescriptionValid(*description))
308 return 0;
309 return (new BrowserFontResource_Trusted(GetConnection(), instance,
310 *description, dispatcher->preferences()))->GetReference();
313 PP_Resource ResourceCreationProxy::CreateBuffer(PP_Instance instance,
314 uint32_t size) {
315 return PPB_Buffer_Proxy::CreateProxyResource(instance, size);
318 PP_Resource ResourceCreationProxy::CreateDirectoryReader(
319 PP_Resource directory_ref) {
320 NOTIMPLEMENTED(); // Not proxied yet.
321 return 0;
324 PP_Resource ResourceCreationProxy::CreateFlashDeviceID(PP_Instance instance) {
325 return (new FlashDeviceIDResource(GetConnection(), instance))->GetReference();
328 PP_Resource ResourceCreationProxy::CreateFlashFontFile(
329 PP_Instance instance,
330 const PP_BrowserFont_Trusted_Description* description,
331 PP_PrivateFontCharset charset) {
332 return (new FlashFontFileResource(
333 GetConnection(), instance, description, charset))->GetReference();
336 PP_Resource ResourceCreationProxy::CreateFlashMenu(
337 PP_Instance instance,
338 const PP_Flash_Menu* menu_data) {
339 scoped_refptr<FlashMenuResource> flash_menu(
340 new FlashMenuResource(GetConnection(), instance));
341 if (!flash_menu->Initialize(menu_data))
342 return 0;
343 return flash_menu->GetReference();
346 PP_Resource ResourceCreationProxy::CreateFlashMessageLoop(
347 PP_Instance instance) {
348 return PPB_Flash_MessageLoop_Proxy::CreateProxyResource(instance);
351 PP_Resource ResourceCreationProxy::CreateScrollbar(PP_Instance instance,
352 PP_Bool vertical) {
353 NOTIMPLEMENTED(); // Not proxied yet.
354 return 0;
357 PP_Resource ResourceCreationProxy::CreateTalk(PP_Instance instance) {
358 return (new TalkResource(GetConnection(), instance))->GetReference();
361 PP_Resource ResourceCreationProxy::CreateVideoCapture(PP_Instance instance) {
362 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
363 if (!dispatcher)
364 return 0;
365 return (new VideoCaptureResource(GetConnection(), instance, dispatcher))
366 ->GetReference();
369 PP_Resource ResourceCreationProxy::CreateVideoDecoder(
370 PP_Instance instance,
371 PP_Resource context3d_id,
372 PP_VideoDecoder_Profile profile) {
373 return PPB_VideoDecoder_Proxy::CreateProxyResource(
374 instance, context3d_id, profile);
377 #endif // !defined(OS_NACL)
379 bool ResourceCreationProxy::Send(IPC::Message* msg) {
380 return dispatcher()->Send(msg);
383 bool ResourceCreationProxy::OnMessageReceived(const IPC::Message& msg) {
384 return false;
387 Connection ResourceCreationProxy::GetConnection() {
388 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher());
391 } // namespace proxy
392 } // namespace ppapi