| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" | 5 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "content/common/content_switches_internal.h" | 13 #include "content/common/content_switches_internal.h" |
| 13 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
| 14 #include "content/public/renderer/content_renderer_client.h" | 15 #include "content/public/renderer/content_renderer_client.h" |
| 15 #include "content/renderer/pepper/pepper_audio_encoder_host.h" | 16 #include "content/renderer/pepper/pepper_audio_encoder_host.h" |
| 16 #include "content/renderer/pepper/pepper_audio_input_host.h" | 17 #include "content/renderer/pepper/pepper_audio_input_host.h" |
| 17 #include "content/renderer/pepper/pepper_camera_device_host.h" | 18 #include "content/renderer/pepper/pepper_camera_device_host.h" |
| 18 #include "content/renderer/pepper/pepper_compositor_host.h" | 19 #include "content/renderer/pepper/pepper_compositor_host.h" |
| 19 #include "content/renderer/pepper/pepper_file_chooser_host.h" | 20 #include "content/renderer/pepper/pepper_file_chooser_host.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 95 } |
| 95 | 96 |
| 96 } // namespace | 97 } // namespace |
| 97 | 98 |
| 98 ContentRendererPepperHostFactory::ContentRendererPepperHostFactory( | 99 ContentRendererPepperHostFactory::ContentRendererPepperHostFactory( |
| 99 RendererPpapiHostImpl* host) | 100 RendererPpapiHostImpl* host) |
| 100 : host_(host) {} | 101 : host_(host) {} |
| 101 | 102 |
| 102 ContentRendererPepperHostFactory::~ContentRendererPepperHostFactory() {} | 103 ContentRendererPepperHostFactory::~ContentRendererPepperHostFactory() {} |
| 103 | 104 |
| 104 scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost( | 105 std::unique_ptr<ResourceHost> |
| 106 ContentRendererPepperHostFactory::CreateResourceHost( |
| 105 ppapi::host::PpapiHost* host, | 107 ppapi::host::PpapiHost* host, |
| 106 PP_Resource resource, | 108 PP_Resource resource, |
| 107 PP_Instance instance, | 109 PP_Instance instance, |
| 108 const IPC::Message& message) { | 110 const IPC::Message& message) { |
| 109 DCHECK(host == host_->GetPpapiHost()); | 111 DCHECK(host == host_->GetPpapiHost()); |
| 110 | 112 |
| 111 // Make sure the plugin is giving us a valid instance for this resource. | 113 // Make sure the plugin is giving us a valid instance for this resource. |
| 112 if (!host_->IsValidInstance(instance)) | 114 if (!host_->IsValidInstance(instance)) |
| 113 return scoped_ptr<ResourceHost>(); | 115 return nullptr; |
| 114 | 116 |
| 115 PepperPluginInstanceImpl* instance_impl = | 117 PepperPluginInstanceImpl* instance_impl = |
| 116 host_->GetPluginInstanceImpl(instance); | 118 host_->GetPluginInstanceImpl(instance); |
| 117 if (!instance_impl->render_frame()) | 119 if (!instance_impl->render_frame()) |
| 118 return scoped_ptr<ResourceHost>(); | 120 return nullptr; |
| 119 | 121 |
| 120 // Public interfaces. | 122 // Public interfaces. |
| 121 switch (message.type()) { | 123 switch (message.type()) { |
| 122 case PpapiHostMsg_Compositor_Create::ID: { | 124 case PpapiHostMsg_Compositor_Create::ID: { |
| 123 if (!CanUseCompositorAPI(host_, instance)) | 125 if (!CanUseCompositorAPI(host_, instance)) |
| 124 return scoped_ptr<ResourceHost>(); | 126 return nullptr; |
| 125 return scoped_ptr<ResourceHost>( | 127 return base::WrapUnique( |
| 126 new PepperCompositorHost(host_, instance, resource)); | 128 new PepperCompositorHost(host_, instance, resource)); |
| 127 } | 129 } |
| 128 case PpapiHostMsg_FileRef_CreateForFileAPI::ID: { | 130 case PpapiHostMsg_FileRef_CreateForFileAPI::ID: { |
| 129 PP_Resource file_system; | 131 PP_Resource file_system; |
| 130 std::string internal_path; | 132 std::string internal_path; |
| 131 if (!UnpackMessage<PpapiHostMsg_FileRef_CreateForFileAPI>( | 133 if (!UnpackMessage<PpapiHostMsg_FileRef_CreateForFileAPI>( |
| 132 message, &file_system, &internal_path)) { | 134 message, &file_system, &internal_path)) { |
| 133 NOTREACHED(); | 135 NOTREACHED(); |
| 134 return scoped_ptr<ResourceHost>(); | 136 return nullptr; |
| 135 } | 137 } |
| 136 return scoped_ptr<ResourceHost>(new PepperFileRefRendererHost( | 138 return base::WrapUnique(new PepperFileRefRendererHost( |
| 137 host_, instance, resource, file_system, internal_path)); | 139 host_, instance, resource, file_system, internal_path)); |
| 138 } | 140 } |
| 139 case PpapiHostMsg_FileSystem_Create::ID: { | 141 case PpapiHostMsg_FileSystem_Create::ID: { |
| 140 PP_FileSystemType file_system_type; | 142 PP_FileSystemType file_system_type; |
| 141 if (!UnpackMessage<PpapiHostMsg_FileSystem_Create>(message, | 143 if (!UnpackMessage<PpapiHostMsg_FileSystem_Create>(message, |
| 142 &file_system_type)) { | 144 &file_system_type)) { |
| 143 NOTREACHED(); | 145 NOTREACHED(); |
| 144 return scoped_ptr<ResourceHost>(); | 146 return nullptr; |
| 145 } | 147 } |
| 146 return scoped_ptr<ResourceHost>(new PepperFileSystemHost( | 148 return base::WrapUnique(new PepperFileSystemHost( |
| 147 host_, instance, resource, file_system_type)); | 149 host_, instance, resource, file_system_type)); |
| 148 } | 150 } |
| 149 case PpapiHostMsg_Graphics2D_Create::ID: { | 151 case PpapiHostMsg_Graphics2D_Create::ID: { |
| 150 PP_Size size; | 152 PP_Size size; |
| 151 PP_Bool is_always_opaque; | 153 PP_Bool is_always_opaque; |
| 152 if (!UnpackMessage<PpapiHostMsg_Graphics2D_Create>( | 154 if (!UnpackMessage<PpapiHostMsg_Graphics2D_Create>( |
| 153 message, &size, &is_always_opaque)) { | 155 message, &size, &is_always_opaque)) { |
| 154 NOTREACHED(); | 156 NOTREACHED(); |
| 155 return scoped_ptr<ResourceHost>(); | 157 return nullptr; |
| 156 } | 158 } |
| 157 ppapi::PPB_ImageData_Shared::ImageDataType image_type = | 159 ppapi::PPB_ImageData_Shared::ImageDataType image_type = |
| 158 ppapi::PPB_ImageData_Shared::PLATFORM; | 160 ppapi::PPB_ImageData_Shared::PLATFORM; |
| 159 #if defined(OS_WIN) | 161 #if defined(OS_WIN) |
| 160 // If Win32K lockdown mitigations are enabled for Windows 8 and beyond | 162 // If Win32K lockdown mitigations are enabled for Windows 8 and beyond |
| 161 // we use the SIMPLE image data type as the PLATFORM image data type | 163 // we use the SIMPLE image data type as the PLATFORM image data type |
| 162 // calls GDI functions to create DIB sections etc which fail in Win32K | 164 // calls GDI functions to create DIB sections etc which fail in Win32K |
| 163 // lockdown mode. | 165 // lockdown mode. |
| 164 // TODO(ananta) | 166 // TODO(ananta) |
| 165 // Look into whether this causes a loss of functionality. From cursory | 167 // Look into whether this causes a loss of functionality. From cursory |
| 166 // testing things seem to work well. | 168 // testing things seem to work well. |
| 167 if (IsWin32kRendererLockdownEnabled()) | 169 if (IsWin32kRendererLockdownEnabled()) |
| 168 image_type = ppapi::PPB_ImageData_Shared::SIMPLE; | 170 image_type = ppapi::PPB_ImageData_Shared::SIMPLE; |
| 169 #endif | 171 #endif |
| 170 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl( | 172 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl( |
| 171 instance, image_type)); | 173 instance, image_type)); |
| 172 return scoped_ptr<ResourceHost>(PepperGraphics2DHost::Create( | 174 return base::WrapUnique(PepperGraphics2DHost::Create( |
| 173 host_, instance, resource, size, is_always_opaque, image_data)); | 175 host_, instance, resource, size, is_always_opaque, image_data)); |
| 174 } | 176 } |
| 175 case PpapiHostMsg_URLLoader_Create::ID: | 177 case PpapiHostMsg_URLLoader_Create::ID: |
| 176 return scoped_ptr<ResourceHost>( | 178 return base::WrapUnique( |
| 177 new PepperURLLoaderHost(host_, false, instance, resource)); | 179 new PepperURLLoaderHost(host_, false, instance, resource)); |
| 178 case PpapiHostMsg_VideoDecoder_Create::ID: | 180 case PpapiHostMsg_VideoDecoder_Create::ID: |
| 179 return scoped_ptr<ResourceHost>( | 181 return base::WrapUnique( |
| 180 new PepperVideoDecoderHost(host_, instance, resource)); | 182 new PepperVideoDecoderHost(host_, instance, resource)); |
| 181 case PpapiHostMsg_VideoEncoder_Create::ID: | 183 case PpapiHostMsg_VideoEncoder_Create::ID: |
| 182 return scoped_ptr<ResourceHost>( | 184 return base::WrapUnique( |
| 183 new PepperVideoEncoderHost(host_, instance, resource)); | 185 new PepperVideoEncoderHost(host_, instance, resource)); |
| 184 case PpapiHostMsg_WebSocket_Create::ID: | 186 case PpapiHostMsg_WebSocket_Create::ID: |
| 185 return scoped_ptr<ResourceHost>( | 187 return base::WrapUnique( |
| 186 new PepperWebSocketHost(host_, instance, resource)); | 188 new PepperWebSocketHost(host_, instance, resource)); |
| 187 #if defined(ENABLE_WEBRTC) | 189 #if defined(ENABLE_WEBRTC) |
| 188 case PpapiHostMsg_MediaStreamVideoTrack_Create::ID: | 190 case PpapiHostMsg_MediaStreamVideoTrack_Create::ID: |
| 189 return scoped_ptr<ResourceHost>( | 191 return base::WrapUnique( |
| 190 new PepperMediaStreamVideoTrackHost(host_, instance, resource)); | 192 new PepperMediaStreamVideoTrackHost(host_, instance, resource)); |
| 191 // These private MediaStream interfaces are exposed as if they were public | 193 // These private MediaStream interfaces are exposed as if they were public |
| 192 // so they can be used by NaCl plugins. However, they are available only | 194 // so they can be used by NaCl plugins. However, they are available only |
| 193 // for whitelisted apps. | 195 // for whitelisted apps. |
| 194 case PpapiHostMsg_VideoDestination_Create::ID: | 196 case PpapiHostMsg_VideoDestination_Create::ID: |
| 195 if (CanUseMediaStreamAPI(host_, instance)) | 197 if (CanUseMediaStreamAPI(host_, instance)) |
| 196 return scoped_ptr<ResourceHost>( | 198 return base::WrapUnique( |
| 197 new PepperVideoDestinationHost(host_, instance, resource)); | 199 new PepperVideoDestinationHost(host_, instance, resource)); |
| 198 case PpapiHostMsg_VideoSource_Create::ID: | 200 case PpapiHostMsg_VideoSource_Create::ID: |
| 199 if (CanUseMediaStreamAPI(host_, instance)) | 201 if (CanUseMediaStreamAPI(host_, instance)) |
| 200 return scoped_ptr<ResourceHost>( | 202 return base::WrapUnique( |
| 201 new PepperVideoSourceHost(host_, instance, resource)); | 203 new PepperVideoSourceHost(host_, instance, resource)); |
| 202 #endif // defined(ENABLE_WEBRTC) | 204 #endif // defined(ENABLE_WEBRTC) |
| 203 } | 205 } |
| 204 | 206 |
| 205 // Dev interfaces. | 207 // Dev interfaces. |
| 206 if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) { | 208 if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) { |
| 207 switch (message.type()) { | 209 switch (message.type()) { |
| 208 case PpapiHostMsg_AudioEncoder_Create::ID: | 210 case PpapiHostMsg_AudioEncoder_Create::ID: |
| 209 return scoped_ptr<ResourceHost>( | 211 return base::WrapUnique( |
| 210 new PepperAudioEncoderHost(host_, instance, resource)); | 212 new PepperAudioEncoderHost(host_, instance, resource)); |
| 211 case PpapiHostMsg_AudioInput_Create::ID: | 213 case PpapiHostMsg_AudioInput_Create::ID: |
| 212 return scoped_ptr<ResourceHost>( | 214 return base::WrapUnique( |
| 213 new PepperAudioInputHost(host_, instance, resource)); | 215 new PepperAudioInputHost(host_, instance, resource)); |
| 214 case PpapiHostMsg_FileChooser_Create::ID: | 216 case PpapiHostMsg_FileChooser_Create::ID: |
| 215 return scoped_ptr<ResourceHost>( | 217 return base::WrapUnique( |
| 216 new PepperFileChooserHost(host_, instance, resource)); | 218 new PepperFileChooserHost(host_, instance, resource)); |
| 217 case PpapiHostMsg_VideoCapture_Create::ID: { | 219 case PpapiHostMsg_VideoCapture_Create::ID: { |
| 218 PepperVideoCaptureHost* host = | 220 std::unique_ptr<PepperVideoCaptureHost> host( |
| 219 new PepperVideoCaptureHost(host_, instance, resource); | 221 new PepperVideoCaptureHost(host_, instance, resource)); |
| 220 if (!host->Init()) { | 222 return host->Init() ? std::move(host) : nullptr; |
| 221 delete host; | |
| 222 return scoped_ptr<ResourceHost>(); | |
| 223 } | |
| 224 return scoped_ptr<ResourceHost>(host); | |
| 225 } | 223 } |
| 226 } | 224 } |
| 227 } | 225 } |
| 228 | 226 |
| 229 // Permissions of the following interfaces are available for whitelisted apps | 227 // Permissions of the following interfaces are available for whitelisted apps |
| 230 // which may not have access to the other private interfaces. | 228 // which may not have access to the other private interfaces. |
| 231 if (message.type() == PpapiHostMsg_CameraDevice_Create::ID) { | 229 if (message.type() == PpapiHostMsg_CameraDevice_Create::ID) { |
| 232 if (!GetPermissions().HasPermission(ppapi::PERMISSION_PRIVATE) && | 230 if (!GetPermissions().HasPermission(ppapi::PERMISSION_PRIVATE) && |
| 233 !CanUseCameraDeviceAPI(host_, instance)) | 231 !CanUseCameraDeviceAPI(host_, instance)) |
| 234 return nullptr; | 232 return nullptr; |
| 235 scoped_ptr<PepperCameraDeviceHost> host( | 233 std::unique_ptr<PepperCameraDeviceHost> host( |
| 236 new PepperCameraDeviceHost(host_, instance, resource)); | 234 new PepperCameraDeviceHost(host_, instance, resource)); |
| 237 return host->Init() ? std::move(host) : nullptr; | 235 return host->Init() ? std::move(host) : nullptr; |
| 238 } | 236 } |
| 239 | 237 |
| 240 return scoped_ptr<ResourceHost>(); | 238 return nullptr; |
| 241 } | 239 } |
| 242 | 240 |
| 243 const ppapi::PpapiPermissions& | 241 const ppapi::PpapiPermissions& |
| 244 ContentRendererPepperHostFactory::GetPermissions() const { | 242 ContentRendererPepperHostFactory::GetPermissions() const { |
| 245 return host_->GetPpapiHost()->permissions(); | 243 return host_->GetPpapiHost()->permissions(); |
| 246 } | 244 } |
| 247 | 245 |
| 248 } // namespace content | 246 } // namespace content |
| OLD | NEW |