Chromium Code Reviews| 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 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "ppapi/shared_impl/ppapi_preferences.h" | 26 #include "ppapi/shared_impl/ppapi_preferences.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 32 #include "webkit/plugins/ppapi/host_globals.h" | 32 #include "webkit/plugins/ppapi/host_globals.h" |
| 33 #include "webkit/plugins/ppapi/plugin_module.h" | 33 #include "webkit/plugins/ppapi/plugin_module.h" |
| 34 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 34 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 35 | 35 |
| 36 #if defined(OS_WIN) | |
| 37 #include <fcntl.h> | |
| 38 #include <io.h> | |
| 39 #endif | |
| 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 |
| 45 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > | 50 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > |
|
brettw
2012/07/12 19:55:16
Can you add a comment here about what this is for?
jvoung (off chromium)
2012/07/12 23:06:09
Added a comment for the original goal (to send syn
| |
| 46 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; | 51 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; |
| 47 | 52 |
| 48 typedef std::map<PP_Instance, IPC::ChannelHandle> ChannelHandleMap; | 53 typedef std::map<PP_Instance, IPC::ChannelHandle> ChannelHandleMap; |
| 49 | 54 |
| 50 base::LazyInstance<ChannelHandleMap> g_channel_handle_map = | 55 base::LazyInstance<ChannelHandleMap> g_channel_handle_map = |
| 51 LAZY_INSTANCE_INITIALIZER; | 56 LAZY_INSTANCE_INITIALIZER; |
| 52 | 57 |
| 53 // Launch NaCl's sel_ldr process. | 58 // Launch NaCl's sel_ldr process. |
| 54 PP_Bool LaunchSelLdr(PP_Instance instance, | 59 PP_Bool LaunchSelLdr(PP_Instance instance, |
| 55 const char* alleged_url, | 60 const char* alleged_url, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 unsigned int options) { | 255 unsigned int options) { |
| 251 #if defined(OS_WIN) | 256 #if defined(OS_WIN) |
| 252 return content::BrokerDuplicateHandle(source_handle, process_id, | 257 return content::BrokerDuplicateHandle(source_handle, process_id, |
| 253 target_handle, desired_access, | 258 target_handle, desired_access, |
| 254 options); | 259 options); |
| 255 #else | 260 #else |
| 256 return 0; | 261 return 0; |
| 257 #endif | 262 #endif |
| 258 } | 263 } |
| 259 | 264 |
| 265 int GetReadonlyPnaclFD(const char* filename) { | |
| 266 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | |
| 267 IPC::Sender* sender = content::RenderThread::Get(); | |
| 268 if (sender == NULL) | |
| 269 sender = g_background_thread_sender.Pointer()->get(); | |
| 270 | |
| 271 if (!sender->Send(new ChromeViewHostMsg_GetReadonlyPnaclFD( | |
| 272 std::string(filename), | |
| 273 &out_fd))) { | |
| 274 return -1; | |
| 275 } | |
| 276 | |
| 277 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | |
| 278 return -1; | |
| 279 } | |
| 280 | |
| 281 base::PlatformFile handle = IPC::PlatformFileForTransitToPlatformFile( | |
| 282 out_fd); | |
| 283 #if defined(OS_WIN) | |
| 284 int posix_desc = _open_osfhandle(reinterpret_cast<intptr_t>(handle), | |
| 285 _O_RDONLY | _O_BINARY); | |
| 286 if (posix_desc == -1) { | |
| 287 // Close the Windows HANDLE if it can't be converted. | |
| 288 CloseHandle(handle); | |
| 289 return -1; | |
| 290 } | |
| 291 return posix_desc; | |
| 292 #elif defined(OS_POSIX) | |
| 293 return handle; | |
| 294 #else | |
| 295 #error "GetReadonlyPnaclFD: Don't know how to convert FileDescriptor to native." | |
| 296 #endif | |
| 297 } | |
| 298 | |
| 260 const PPB_NaCl_Private nacl_interface = { | 299 const PPB_NaCl_Private nacl_interface = { |
| 261 &LaunchSelLdr, | 300 &LaunchSelLdr, |
| 262 &StartPpapiProxy, | 301 &StartPpapiProxy, |
| 263 &UrandomFD, | 302 &UrandomFD, |
| 264 &Are3DInterfacesDisabled, | 303 &Are3DInterfacesDisabled, |
| 265 &EnableBackgroundSelLdrLaunch, | 304 &EnableBackgroundSelLdrLaunch, |
| 266 &BrokerDuplicateHandle, | 305 &BrokerDuplicateHandle, |
| 306 &GetReadonlyPnaclFD | |
| 267 }; | 307 }; |
| 268 | 308 |
| 269 } // namespace | 309 } // namespace |
| 270 | 310 |
| 271 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { | 311 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { |
| 272 return &nacl_interface; | 312 return &nacl_interface; |
| 273 } | 313 } |
| 274 | 314 |
| 275 #endif // DISABLE_NACL | 315 #endif // DISABLE_NACL |
| OLD | NEW |