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 "content/renderer/pepper/resource_creation_impl.h"
7 #include "content/common/content_switches_internal.h"
8 #include "content/renderer/pepper/ppb_audio_impl.h"
9 #include "content/renderer/pepper/ppb_broker_impl.h"
10 #include "content/renderer/pepper/ppb_buffer_impl.h"
11 #include "content/renderer/pepper/ppb_flash_message_loop_impl.h"
12 #include "content/renderer/pepper/ppb_graphics_3d_impl.h"
13 #include "content/renderer/pepper/ppb_image_data_impl.h"
14 #include "content/renderer/pepper/ppb_scrollbar_impl.h"
15 #include "content/renderer/pepper/ppb_video_decoder_impl.h"
16 #include "ppapi/c/pp_bool.h"
17 #include "ppapi/c/pp_size.h"
18 #include "ppapi/c/pp_var.h"
19 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
20 #include "ppapi/shared_impl/ppb_audio_shared.h"
21 #include "ppapi/shared_impl/ppb_image_data_shared.h"
22 #include "ppapi/shared_impl/ppb_input_event_shared.h"
23 #include "ppapi/shared_impl/var.h"
26 #include "base/command_line.h"
27 #include "base/win/windows_version.h"
30 using ppapi::InputEventData
;
31 using ppapi::PPB_InputEvent_Shared
;
32 using ppapi::StringVar
;
36 ResourceCreationImpl::ResourceCreationImpl(PepperPluginInstanceImpl
* instance
) {
39 ResourceCreationImpl::~ResourceCreationImpl() {}
41 PP_Resource
ResourceCreationImpl::CreateAudio1_0(
43 PP_Resource config_id
,
44 PPB_Audio_Callback_1_0 audio_callback
,
46 return 0; // Not supported in-process.
49 PP_Resource
ResourceCreationImpl::CreateAudio(PP_Instance instance
,
50 PP_Resource config_id
,
51 PPB_Audio_Callback audio_callback
,
53 return 0; // Not supported in-process.
56 PP_Resource
ResourceCreationImpl::CreateAudioConfig(
58 PP_AudioSampleRate sample_rate
,
59 uint32_t sample_frame_count
) {
60 return ppapi::PPB_AudioConfig_Shared::Create(
61 ppapi::OBJECT_IS_IMPL
, instance
, sample_rate
, sample_frame_count
);
64 PP_Resource
ResourceCreationImpl::CreateAudioTrusted(PP_Instance instance
) {
65 return (new PPB_Audio_Impl(instance
))->GetReference();
68 PP_Resource
ResourceCreationImpl::CreateAudioInput(PP_Instance instance
) {
69 return 0; // Not supported in-process.
72 PP_Resource
ResourceCreationImpl::CreateCompositor(PP_Instance instance
) {
73 return 0; // Not supported in-process.
76 PP_Resource
ResourceCreationImpl::CreateBroker(PP_Instance instance
) {
77 return (new PPB_Broker_Impl(instance
))->GetReference();
80 PP_Resource
ResourceCreationImpl::CreateBuffer(PP_Instance instance
,
82 return PPB_Buffer_Impl::Create(instance
, size
);
85 PP_Resource
ResourceCreationImpl::CreateFlashDRM(PP_Instance instance
) {
86 return 0; // Not supported in-process.
89 PP_Resource
ResourceCreationImpl::CreateFlashFontFile(
91 const PP_BrowserFont_Trusted_Description
* description
,
92 PP_PrivateFontCharset charset
) {
93 return 0; // Not supported in-process.
96 PP_Resource
ResourceCreationImpl::CreateFlashMenu(
98 const PP_Flash_Menu
* menu_data
) {
99 return 0; // Not supported in-process.
102 PP_Resource
ResourceCreationImpl::CreateFlashMessageLoop(PP_Instance instance
) {
103 return PPB_Flash_MessageLoop_Impl::Create(instance
);
106 PP_Resource
ResourceCreationImpl::CreateGraphics3D(PP_Instance instance
,
107 PP_Resource share_context
,
108 const int32_t* attrib_list
) {
109 return PPB_Graphics3D_Impl::Create(instance
, share_context
, attrib_list
);
112 PP_Resource
ResourceCreationImpl::CreateGraphics3DRaw(
113 PP_Instance instance
,
114 PP_Resource share_context
,
115 const int32_t* attrib_list
,
116 gpu::Capabilities
* capabilities
,
117 base::SharedMemoryHandle
* shared_state
) {
118 return PPB_Graphics3D_Impl::CreateRaw(instance
, share_context
, attrib_list
,
119 capabilities
, shared_state
);
122 PP_Resource
ResourceCreationImpl::CreateHostResolver(PP_Instance instance
) {
123 return 0; // Not supported in-process.
126 PP_Resource
ResourceCreationImpl::CreateHostResolverPrivate(
127 PP_Instance instance
) {
128 return 0; // Not supported in-process.
131 PP_Resource
ResourceCreationImpl::CreateImageData(PP_Instance instance
,
132 PP_ImageDataFormat format
,
134 PP_Bool init_to_zero
) {
136 // If Win32K lockdown mitigations are enabled for Windows 8 and beyond,
137 // we use the SIMPLE image data type as the PLATFORM image data type
138 // calls GDI functions to create DIB sections etc which fail in Win32K
141 // Look into whether this causes a loss of functionality. From cursory
142 // testing things seem to work well.
143 if (IsWin32kRendererLockdownEnabled())
144 return CreateImageDataSimple(instance
, format
, size
, init_to_zero
);
146 return PPB_ImageData_Impl::Create(instance
,
147 ppapi::PPB_ImageData_Shared::PLATFORM
,
153 PP_Resource
ResourceCreationImpl::CreateImageDataSimple(
154 PP_Instance instance
,
155 PP_ImageDataFormat format
,
157 PP_Bool init_to_zero
) {
158 return PPB_ImageData_Impl::Create(instance
,
159 ppapi::PPB_ImageData_Shared::SIMPLE
,
165 PP_Resource
ResourceCreationImpl::CreateIMEInputEvent(
166 PP_Instance instance
,
167 PP_InputEvent_Type type
,
168 PP_TimeTicks time_stamp
,
170 uint32_t segment_number
,
171 const uint32_t* segment_offsets
,
172 int32_t target_segment
,
173 uint32_t selection_start
,
174 uint32_t selection_end
) {
175 return PPB_InputEvent_Shared::CreateIMEInputEvent(ppapi::OBJECT_IS_IMPL
,
187 PP_Resource
ResourceCreationImpl::CreateKeyboardInputEvent_1_0(
188 PP_Instance instance
,
189 PP_InputEvent_Type type
,
190 PP_TimeTicks time_stamp
,
193 struct PP_Var character_text
) {
194 PP_Var code
= StringVar::StringToPPVar("");
195 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(ppapi::OBJECT_IS_IMPL
,
205 PP_Resource
ResourceCreationImpl::CreateKeyboardInputEvent_1_2(
206 PP_Instance instance
,
207 PP_InputEvent_Type type
,
208 PP_TimeTicks time_stamp
,
211 struct PP_Var character_text
,
212 struct PP_Var code
) {
213 return PPB_InputEvent_Shared::CreateKeyboardInputEvent(ppapi::OBJECT_IS_IMPL
,
223 PP_Resource
ResourceCreationImpl::CreateMediaStreamVideoTrack(
224 PP_Instance instance
) {
225 return 0; // Not supported in-process.
228 PP_Resource
ResourceCreationImpl::CreateMouseInputEvent(
229 PP_Instance instance
,
230 PP_InputEvent_Type type
,
231 PP_TimeTicks time_stamp
,
233 PP_InputEvent_MouseButton mouse_button
,
234 const PP_Point
* mouse_position
,
236 const PP_Point
* mouse_movement
) {
237 return PPB_InputEvent_Shared::CreateMouseInputEvent(ppapi::OBJECT_IS_IMPL
,
248 PP_Resource
ResourceCreationImpl::CreateNetAddressFromIPv4Address(
249 PP_Instance instance
,
250 const PP_NetAddress_IPv4
* ipv4_addr
) {
251 return 0; // Not supported in-process.
254 PP_Resource
ResourceCreationImpl::CreateNetAddressFromIPv6Address(
255 PP_Instance instance
,
256 const PP_NetAddress_IPv6
* ipv6_addr
) {
257 return 0; // Not supported in-process.
260 PP_Resource
ResourceCreationImpl::CreateNetAddressFromNetAddressPrivate(
261 PP_Instance instance
,
262 const PP_NetAddress_Private
& private_addr
) {
263 return 0; // Not supported in-process.
266 PP_Resource
ResourceCreationImpl::CreateNetworkMonitor(PP_Instance instance
) {
267 return 0; // Not supported in-process.
270 PP_Resource
ResourceCreationImpl::CreateOutputProtectionPrivate(
271 PP_Instance instance
) {
272 return 0; // Not supported in-process.
275 PP_Resource
ResourceCreationImpl::CreatePlatformVerificationPrivate(
276 PP_Instance instance
) {
277 return 0; // Not supported in-process.
280 PP_Resource
ResourceCreationImpl::CreateScrollbar(PP_Instance instance
,
282 return PPB_Scrollbar_Impl::Create(instance
, PP_ToBool(vertical
));
285 PP_Resource
ResourceCreationImpl::CreateTalk(PP_Instance
/* instance */) {
286 return 0; // Not supported in-process.
289 PP_Resource
ResourceCreationImpl::CreateTCPServerSocketPrivate(
290 PP_Instance instance
) {
291 return 0; // Not supported in-process.
294 PP_Resource
ResourceCreationImpl::CreateTCPSocket1_0(PP_Instance instance
) {
295 return 0; // Not supported in-process.
298 PP_Resource
ResourceCreationImpl::CreateTCPSocket(PP_Instance instance
) {
299 return 0; // Not supported in-process.
302 PP_Resource
ResourceCreationImpl::CreateTCPSocketPrivate(PP_Instance instance
) {
303 return 0; // Not supported in-process.
306 PP_Resource
ResourceCreationImpl::CreateTouchInputEvent(PP_Instance instance
,
307 PP_InputEvent_Type type
,
308 PP_TimeTicks time_stamp
,
309 uint32_t modifiers
) {
310 return PPB_InputEvent_Shared::CreateTouchInputEvent(
311 ppapi::OBJECT_IS_IMPL
, instance
, type
, time_stamp
, modifiers
);
314 PP_Resource
ResourceCreationImpl::CreateUDPSocket(PP_Instance instance
) {
315 return 0; // Not supported in-process.
318 PP_Resource
ResourceCreationImpl::CreateUDPSocketPrivate(PP_Instance instance
) {
319 return 0; // Not supported in-process.
322 PP_Resource
ResourceCreationImpl::CreateVideoCapture(PP_Instance instance
) {
323 return 0; // Not supported in-process.
326 PP_Resource
ResourceCreationImpl::CreateVideoDecoder(PP_Instance instance
) {
327 return 0; // Not supported in-process.
330 PP_Resource
ResourceCreationImpl::CreateVideoDecoderDev(
331 PP_Instance instance
,
332 PP_Resource graphics3d_id
,
333 PP_VideoDecoder_Profile profile
) {
334 return PPB_VideoDecoder_Impl::Create(instance
, graphics3d_id
, profile
);
337 PP_Resource
ResourceCreationImpl::CreateVideoDestination(PP_Instance instance
) {
338 return 0; // Not supported in-process.
341 PP_Resource
ResourceCreationImpl::CreateVideoSource(PP_Instance instance
) {
342 return 0; // Not supported in-process.
345 PP_Resource
ResourceCreationImpl::CreateWheelInputEvent(
346 PP_Instance instance
,
347 PP_TimeTicks time_stamp
,
349 const PP_FloatPoint
* wheel_delta
,
350 const PP_FloatPoint
* wheel_ticks
,
351 PP_Bool scroll_by_page
) {
352 return PPB_InputEvent_Shared::CreateWheelInputEvent(ppapi::OBJECT_IS_IMPL
,
361 PP_Resource
ResourceCreationImpl::CreateX509CertificatePrivate(
362 PP_Instance instance
) {
363 return 0; // Not supported in-process.
366 } // namespace content