| 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 "chrome/renderer/pepper/ppb_nacl_private_impl.h" | 5 #include "chrome/renderer/pepper/ppb_nacl_private_impl.h" |
| 6 | 6 |
| 7 #ifndef DISABLE_NACL | 7 #ifndef DISABLE_NACL |
| 8 | 8 |
| 9 #if defined(OS_WIN) |
| 10 #include <fcntl.h> |
| 11 #include <io.h> |
| 12 #endif |
| 13 |
| 9 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 16 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 13 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 14 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
| 16 #include "content/public/common/content_client.h" | 21 #include "content/public/common/content_client.h" |
| 17 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 18 #include "content/public/common/sandbox_init.h" | 23 #include "content/public/common/sandbox_init.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 35 | 40 |
| 36 using content::RenderThread; | 41 using content::RenderThread; |
| 37 using content::RenderView; | 42 using content::RenderView; |
| 38 using webkit::ppapi::HostGlobals; | 43 using webkit::ppapi::HostGlobals; |
| 39 using webkit::ppapi::PluginInstance; | 44 using webkit::ppapi::PluginInstance; |
| 40 using webkit::ppapi::PluginDelegate; | 45 using webkit::ppapi::PluginDelegate; |
| 41 using WebKit::WebView; | 46 using WebKit::WebView; |
| 42 | 47 |
| 43 namespace { | 48 namespace { |
| 44 | 49 |
| 50 // This allows us to send requests from background threads. |
| 51 // E.g., to do LaunchSelLdr for helper nexes (which is done synchronously), |
| 52 // in a background thread, to avoid jank. |
| 45 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > | 53 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > |
| 46 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; | 54 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; |
| 47 | 55 |
| 48 typedef std::map<PP_Instance, IPC::ChannelHandle> ChannelHandleMap; | 56 typedef std::map<PP_Instance, IPC::ChannelHandle> ChannelHandleMap; |
| 49 | 57 |
| 50 base::LazyInstance<ChannelHandleMap> g_channel_handle_map = | 58 base::LazyInstance<ChannelHandleMap> g_channel_handle_map = |
| 51 LAZY_INSTANCE_INITIALIZER; | 59 LAZY_INSTANCE_INITIALIZER; |
| 52 | 60 |
| 53 // Launch NaCl's sel_ldr process. | 61 // Launch NaCl's sel_ldr process. |
| 54 PP_Bool LaunchSelLdr(PP_Instance instance, | 62 PP_Bool LaunchSelLdr(PP_Instance instance, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 unsigned int options) { | 258 unsigned int options) { |
| 251 #if defined(OS_WIN) | 259 #if defined(OS_WIN) |
| 252 return content::BrokerDuplicateHandle(source_handle, process_id, | 260 return content::BrokerDuplicateHandle(source_handle, process_id, |
| 253 target_handle, desired_access, | 261 target_handle, desired_access, |
| 254 options); | 262 options); |
| 255 #else | 263 #else |
| 256 return 0; | 264 return 0; |
| 257 #endif | 265 #endif |
| 258 } | 266 } |
| 259 | 267 |
| 268 int GetReadonlyPnaclFD(const char* filename) { |
| 269 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); |
| 270 IPC::Sender* sender = content::RenderThread::Get(); |
| 271 if (sender == NULL) |
| 272 sender = g_background_thread_sender.Pointer()->get(); |
| 273 |
| 274 if (!sender->Send(new ChromeViewHostMsg_GetReadonlyPnaclFD( |
| 275 std::string(filename), |
| 276 &out_fd))) { |
| 277 return -1; |
| 278 } |
| 279 |
| 280 if (out_fd == IPC::InvalidPlatformFileForTransit()) { |
| 281 return -1; |
| 282 } |
| 283 |
| 284 base::PlatformFile handle = |
| 285 IPC::PlatformFileForTransitToPlatformFile(out_fd); |
| 286 #if defined(OS_WIN) |
| 287 int posix_desc = _open_osfhandle(reinterpret_cast<intptr_t>(handle), |
| 288 _O_RDONLY | _O_BINARY); |
| 289 if (posix_desc == -1) { |
| 290 // Close the Windows HANDLE if it can't be converted. |
| 291 CloseHandle(handle); |
| 292 return -1; |
| 293 } |
| 294 return posix_desc; |
| 295 #elif defined(OS_POSIX) |
| 296 return handle; |
| 297 #else |
| 298 #error "GetReadonlyPnaclFD: Don't know how to convert FileDescriptor to native." |
| 299 #endif |
| 300 } |
| 301 |
| 260 const PPB_NaCl_Private nacl_interface = { | 302 const PPB_NaCl_Private nacl_interface = { |
| 261 &LaunchSelLdr, | 303 &LaunchSelLdr, |
| 262 &StartPpapiProxy, | 304 &StartPpapiProxy, |
| 263 &UrandomFD, | 305 &UrandomFD, |
| 264 &Are3DInterfacesDisabled, | 306 &Are3DInterfacesDisabled, |
| 265 &EnableBackgroundSelLdrLaunch, | 307 &EnableBackgroundSelLdrLaunch, |
| 266 &BrokerDuplicateHandle, | 308 &BrokerDuplicateHandle, |
| 309 &GetReadonlyPnaclFD |
| 267 }; | 310 }; |
| 268 | 311 |
| 269 } // namespace | 312 } // namespace |
| 270 | 313 |
| 271 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { | 314 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { |
| 272 return &nacl_interface; | 315 return &nacl_interface; |
| 273 } | 316 } |
| 274 | 317 |
| 275 #endif // DISABLE_NACL | 318 #endif // DISABLE_NACL |
| OLD | NEW |