Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: content/renderer/pepper/content_renderer_pepper_host_factory.cc

Issue 2253053003: Re-write many calls to WrapUnique() with MakeUnique() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory/ptr_util.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 PepperPluginInstanceImpl* instance_impl = 116 PepperPluginInstanceImpl* instance_impl =
117 host_->GetPluginInstanceImpl(instance); 117 host_->GetPluginInstanceImpl(instance);
118 if (!instance_impl->render_frame()) 118 if (!instance_impl->render_frame())
119 return nullptr; 119 return nullptr;
120 120
121 // Public interfaces. 121 // Public interfaces.
122 switch (message.type()) { 122 switch (message.type()) {
123 case PpapiHostMsg_Compositor_Create::ID: { 123 case PpapiHostMsg_Compositor_Create::ID: {
124 if (!CanUseCompositorAPI(host_, instance)) 124 if (!CanUseCompositorAPI(host_, instance))
125 return nullptr; 125 return nullptr;
126 return base::WrapUnique( 126 return base::MakeUnique<PepperCompositorHost>(host_, instance, resource);
127 new PepperCompositorHost(host_, instance, resource));
128 } 127 }
129 case PpapiHostMsg_FileRef_CreateForFileAPI::ID: { 128 case PpapiHostMsg_FileRef_CreateForFileAPI::ID: {
130 PP_Resource file_system; 129 PP_Resource file_system;
131 std::string internal_path; 130 std::string internal_path;
132 if (!UnpackMessage<PpapiHostMsg_FileRef_CreateForFileAPI>( 131 if (!UnpackMessage<PpapiHostMsg_FileRef_CreateForFileAPI>(
133 message, &file_system, &internal_path)) { 132 message, &file_system, &internal_path)) {
134 NOTREACHED(); 133 NOTREACHED();
135 return nullptr; 134 return nullptr;
136 } 135 }
137 return base::WrapUnique(new PepperFileRefRendererHost( 136 return base::MakeUnique<PepperFileRefRendererHost>(
138 host_, instance, resource, file_system, internal_path)); 137 host_, instance, resource, file_system, internal_path);
139 } 138 }
140 case PpapiHostMsg_FileSystem_Create::ID: { 139 case PpapiHostMsg_FileSystem_Create::ID: {
141 PP_FileSystemType file_system_type; 140 PP_FileSystemType file_system_type;
142 if (!UnpackMessage<PpapiHostMsg_FileSystem_Create>(message, 141 if (!UnpackMessage<PpapiHostMsg_FileSystem_Create>(message,
143 &file_system_type)) { 142 &file_system_type)) {
144 NOTREACHED(); 143 NOTREACHED();
145 return nullptr; 144 return nullptr;
146 } 145 }
147 return base::WrapUnique(new PepperFileSystemHost( 146 return base::MakeUnique<PepperFileSystemHost>(host_, instance, resource,
148 host_, instance, resource, file_system_type)); 147 file_system_type);
149 } 148 }
150 case PpapiHostMsg_Graphics2D_Create::ID: { 149 case PpapiHostMsg_Graphics2D_Create::ID: {
151 PP_Size size; 150 PP_Size size;
152 PP_Bool is_always_opaque; 151 PP_Bool is_always_opaque;
153 if (!UnpackMessage<PpapiHostMsg_Graphics2D_Create>( 152 if (!UnpackMessage<PpapiHostMsg_Graphics2D_Create>(
154 message, &size, &is_always_opaque)) { 153 message, &size, &is_always_opaque)) {
155 NOTREACHED(); 154 NOTREACHED();
156 return nullptr; 155 return nullptr;
157 } 156 }
158 ppapi::PPB_ImageData_Shared::ImageDataType image_type = 157 ppapi::PPB_ImageData_Shared::ImageDataType image_type =
159 ppapi::PPB_ImageData_Shared::PLATFORM; 158 ppapi::PPB_ImageData_Shared::PLATFORM;
160 #if defined(OS_WIN) 159 #if defined(OS_WIN)
161 // If Win32K lockdown mitigations are enabled for Windows 8 and beyond 160 // If Win32K lockdown mitigations are enabled for Windows 8 and beyond
162 // we use the SIMPLE image data type as the PLATFORM image data type 161 // we use the SIMPLE image data type as the PLATFORM image data type
163 // calls GDI functions to create DIB sections etc which fail in Win32K 162 // calls GDI functions to create DIB sections etc which fail in Win32K
164 // lockdown mode. 163 // lockdown mode.
165 // TODO(ananta) 164 // TODO(ananta)
166 // Look into whether this causes a loss of functionality. From cursory 165 // Look into whether this causes a loss of functionality. From cursory
167 // testing things seem to work well. 166 // testing things seem to work well.
168 if (IsWin32kRendererLockdownEnabled()) 167 if (IsWin32kRendererLockdownEnabled())
169 image_type = ppapi::PPB_ImageData_Shared::SIMPLE; 168 image_type = ppapi::PPB_ImageData_Shared::SIMPLE;
170 #endif 169 #endif
171 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl( 170 scoped_refptr<PPB_ImageData_Impl> image_data(new PPB_ImageData_Impl(
172 instance, image_type)); 171 instance, image_type));
173 return base::WrapUnique(PepperGraphics2DHost::Create( 172 return base::WrapUnique(PepperGraphics2DHost::Create(
174 host_, instance, resource, size, is_always_opaque, image_data)); 173 host_, instance, resource, size, is_always_opaque, image_data));
175 } 174 }
176 case PpapiHostMsg_URLLoader_Create::ID: 175 case PpapiHostMsg_URLLoader_Create::ID:
177 return base::WrapUnique( 176 return base::MakeUnique<PepperURLLoaderHost>(host_, false, instance,
178 new PepperURLLoaderHost(host_, false, instance, resource)); 177 resource);
179 case PpapiHostMsg_VideoDecoder_Create::ID: 178 case PpapiHostMsg_VideoDecoder_Create::ID:
180 return base::WrapUnique( 179 return base::MakeUnique<PepperVideoDecoderHost>(host_, instance,
181 new PepperVideoDecoderHost(host_, instance, resource)); 180 resource);
182 case PpapiHostMsg_VideoEncoder_Create::ID: 181 case PpapiHostMsg_VideoEncoder_Create::ID:
183 return base::WrapUnique( 182 return base::MakeUnique<PepperVideoEncoderHost>(host_, instance,
184 new PepperVideoEncoderHost(host_, instance, resource)); 183 resource);
185 case PpapiHostMsg_WebSocket_Create::ID: 184 case PpapiHostMsg_WebSocket_Create::ID:
186 return base::WrapUnique( 185 return base::MakeUnique<PepperWebSocketHost>(host_, instance, resource);
187 new PepperWebSocketHost(host_, instance, resource));
188 #if defined(ENABLE_WEBRTC) 186 #if defined(ENABLE_WEBRTC)
189 case PpapiHostMsg_MediaStreamVideoTrack_Create::ID: 187 case PpapiHostMsg_MediaStreamVideoTrack_Create::ID:
190 return base::WrapUnique( 188 return base::MakeUnique<PepperMediaStreamVideoTrackHost>(host_, instance,
191 new PepperMediaStreamVideoTrackHost(host_, instance, resource)); 189 resource);
192 // These private MediaStream interfaces are exposed as if they were public 190 // These private MediaStream interfaces are exposed as if they were public
193 // so they can be used by NaCl plugins. However, they are available only 191 // so they can be used by NaCl plugins. However, they are available only
194 // for whitelisted apps. 192 // for whitelisted apps.
195 case PpapiHostMsg_VideoDestination_Create::ID: 193 case PpapiHostMsg_VideoDestination_Create::ID:
196 if (CanUseMediaStreamAPI(host_, instance)) 194 if (CanUseMediaStreamAPI(host_, instance))
197 return base::WrapUnique( 195 return base::MakeUnique<PepperVideoDestinationHost>(host_, instance,
198 new PepperVideoDestinationHost(host_, instance, resource)); 196 resource);
199 case PpapiHostMsg_VideoSource_Create::ID: 197 case PpapiHostMsg_VideoSource_Create::ID:
200 if (CanUseMediaStreamAPI(host_, instance)) 198 if (CanUseMediaStreamAPI(host_, instance))
201 return base::WrapUnique( 199 return base::MakeUnique<PepperVideoSourceHost>(host_, instance,
202 new PepperVideoSourceHost(host_, instance, resource)); 200 resource);
203 #endif // defined(ENABLE_WEBRTC) 201 #endif // defined(ENABLE_WEBRTC)
204 } 202 }
205 203
206 // Dev interfaces. 204 // Dev interfaces.
207 if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) { 205 if (GetPermissions().HasPermission(ppapi::PERMISSION_DEV)) {
208 switch (message.type()) { 206 switch (message.type()) {
209 case PpapiHostMsg_AudioEncoder_Create::ID: 207 case PpapiHostMsg_AudioEncoder_Create::ID:
210 return base::WrapUnique( 208 return base::MakeUnique<PepperAudioEncoderHost>(host_, instance,
211 new PepperAudioEncoderHost(host_, instance, resource)); 209 resource);
212 case PpapiHostMsg_AudioInput_Create::ID: 210 case PpapiHostMsg_AudioInput_Create::ID:
213 return base::WrapUnique( 211 return base::MakeUnique<PepperAudioInputHost>(host_, instance,
214 new PepperAudioInputHost(host_, instance, resource)); 212 resource);
215 case PpapiHostMsg_FileChooser_Create::ID: 213 case PpapiHostMsg_FileChooser_Create::ID:
216 return base::WrapUnique( 214 return base::MakeUnique<PepperFileChooserHost>(host_, instance,
217 new PepperFileChooserHost(host_, instance, resource)); 215 resource);
218 case PpapiHostMsg_VideoCapture_Create::ID: { 216 case PpapiHostMsg_VideoCapture_Create::ID: {
219 std::unique_ptr<PepperVideoCaptureHost> host( 217 std::unique_ptr<PepperVideoCaptureHost> host(
220 new PepperVideoCaptureHost(host_, instance, resource)); 218 new PepperVideoCaptureHost(host_, instance, resource));
221 return host->Init() ? std::move(host) : nullptr; 219 return host->Init() ? std::move(host) : nullptr;
222 } 220 }
223 } 221 }
224 } 222 }
225 223
226 // Permissions of the following interfaces are available for whitelisted apps 224 // Permissions of the following interfaces are available for whitelisted apps
227 // which may not have access to the other private interfaces. 225 // which may not have access to the other private interfaces.
228 if (message.type() == PpapiHostMsg_CameraDevice_Create::ID) { 226 if (message.type() == PpapiHostMsg_CameraDevice_Create::ID) {
229 if (!GetPermissions().HasPermission(ppapi::PERMISSION_PRIVATE) && 227 if (!GetPermissions().HasPermission(ppapi::PERMISSION_PRIVATE) &&
230 !CanUseCameraDeviceAPI(host_, instance)) 228 !CanUseCameraDeviceAPI(host_, instance))
231 return nullptr; 229 return nullptr;
232 std::unique_ptr<PepperCameraDeviceHost> host( 230 std::unique_ptr<PepperCameraDeviceHost> host(
233 new PepperCameraDeviceHost(host_, instance, resource)); 231 new PepperCameraDeviceHost(host_, instance, resource));
234 return host->Init() ? std::move(host) : nullptr; 232 return host->Init() ? std::move(host) : nullptr;
235 } 233 }
236 234
237 return nullptr; 235 return nullptr;
238 } 236 }
239 237
240 const ppapi::PpapiPermissions& 238 const ppapi::PpapiPermissions&
241 ContentRendererPepperHostFactory::GetPermissions() const { 239 ContentRendererPepperHostFactory::GetPermissions() const {
242 return host_->GetPpapiHost()->permissions(); 240 return host_->GetPpapiHost()->permissions();
243 } 241 }
244 242
245 } // namespace content 243 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_certificate_generator.cc ('k') | content/renderer/presentation/presentation_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698