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 #if defined(OS_WIN) | |
| 10 #include <fcntl.h> | |
| 11 #include <io.h> | |
| 12 #endif | |
| 13 | |
| 14 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 15 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 11 #include "base/logging.h" |
| 17 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 18 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 19 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
| 21 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 22 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/common/sandbox_init.h" | 18 #include "content/public/common/sandbox_init.h" |
| 24 #include "content/public/renderer/render_thread.h" | 19 #include "content/public/renderer/render_thread.h" |
| 25 #include "content/public/renderer/render_view.h" | 20 #include "content/public/renderer/render_view.h" |
| 26 #include "ipc/ipc_sync_message_filter.h" | 21 #include "ipc/ipc_sync_message_filter.h" |
| 22 #include "ppapi/c/private/pp_file_handle.h" | |
| 27 #include "ppapi/c/private/ppb_nacl_private.h" | 23 #include "ppapi/c/private/ppb_nacl_private.h" |
| 28 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" | 24 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" |
| 29 #include "ppapi/proxy/host_dispatcher.h" | 25 #include "ppapi/proxy/host_dispatcher.h" |
| 30 #include "ppapi/proxy/proxy_channel.h" | 26 #include "ppapi/proxy/proxy_channel.h" |
| 31 #include "ppapi/shared_impl/ppapi_preferences.h" | 27 #include "ppapi/shared_impl/ppapi_preferences.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 37 #include "webkit/plugins/ppapi/host_globals.h" | 33 #include "webkit/plugins/ppapi/host_globals.h" |
| 38 #include "webkit/plugins/ppapi/plugin_module.h" | 34 #include "webkit/plugins/ppapi/plugin_module.h" |
| 39 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 35 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 40 | 36 |
|
brettw
2012/07/27 22:38:17
Got an extra blank in here.
jvoung - send to chromium...
2012/07/28 01:30:05
Done.
| |
| 37 | |
| 41 using content::RenderThread; | 38 using content::RenderThread; |
| 42 using content::RenderView; | 39 using content::RenderView; |
| 43 using webkit::ppapi::HostGlobals; | 40 using webkit::ppapi::HostGlobals; |
| 44 using webkit::ppapi::PluginInstance; | 41 using webkit::ppapi::PluginInstance; |
| 45 using webkit::ppapi::PluginDelegate; | 42 using webkit::ppapi::PluginDelegate; |
| 46 using WebKit::WebView; | 43 using WebKit::WebView; |
| 47 | 44 |
| 48 namespace { | 45 namespace { |
| 49 | 46 |
| 50 // This allows us to send requests from background threads. | 47 // This allows us to send requests from background threads. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 unsigned int options) { | 255 unsigned int options) { |
| 259 #if defined(OS_WIN) | 256 #if defined(OS_WIN) |
| 260 return content::BrokerDuplicateHandle(source_handle, process_id, | 257 return content::BrokerDuplicateHandle(source_handle, process_id, |
| 261 target_handle, desired_access, | 258 target_handle, desired_access, |
| 262 options); | 259 options); |
| 263 #else | 260 #else |
| 264 return 0; | 261 return 0; |
| 265 #endif | 262 #endif |
| 266 } | 263 } |
| 267 | 264 |
| 268 int GetReadonlyPnaclFD(const char* filename) { | 265 PP_FileHandle GetReadonlyPnaclFD(const char* filename) { |
| 269 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | 266 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); |
| 270 IPC::Sender* sender = content::RenderThread::Get(); | 267 IPC::Sender* sender = content::RenderThread::Get(); |
| 271 if (sender == NULL) | 268 if (sender == NULL) |
| 272 sender = g_background_thread_sender.Pointer()->get(); | 269 sender = g_background_thread_sender.Pointer()->get(); |
| 273 | 270 |
| 274 if (!sender->Send(new ChromeViewHostMsg_GetReadonlyPnaclFD( | 271 if (!sender->Send(new ChromeViewHostMsg_GetReadonlyPnaclFD( |
| 275 std::string(filename), | 272 std::string(filename), |
| 276 &out_fd))) { | 273 &out_fd))) { |
| 277 return -1; | 274 return base::kInvalidPlatformFileValue; |
| 278 } | 275 } |
| 279 | 276 |
| 280 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | 277 if (out_fd == IPC::InvalidPlatformFileForTransit()) { |
| 281 return -1; | 278 return base::kInvalidPlatformFileValue; |
| 282 } | 279 } |
| 283 | 280 |
| 284 base::PlatformFile handle = | 281 base::PlatformFile handle = |
| 285 IPC::PlatformFileForTransitToPlatformFile(out_fd); | 282 IPC::PlatformFileForTransitToPlatformFile(out_fd); |
| 286 #if defined(OS_WIN) | 283 return handle; |
| 287 int posix_desc = _open_osfhandle(reinterpret_cast<intptr_t>(handle), | 284 } |
| 288 _O_RDONLY | _O_BINARY); | 285 |
| 289 if (posix_desc == -1) { | 286 PP_FileHandle CreateTemporaryFile(PP_Instance instance) { |
| 290 // Close the Windows HANDLE if it can't be converted. | 287 IPC::PlatformFileForTransit transit_fd = IPC::InvalidPlatformFileForTransit(); |
| 291 CloseHandle(handle); | 288 IPC::Sender* sender = content::RenderThread::Get(); |
| 292 return -1; | 289 if (sender == NULL) |
| 290 sender = g_background_thread_sender.Pointer()->get(); | |
| 291 | |
| 292 if (!sender->Send(new ChromeViewHostMsg_NaClCreateTemporaryFile( | |
| 293 &transit_fd))) { | |
| 294 return base::kInvalidPlatformFileValue; | |
| 293 } | 295 } |
| 294 return posix_desc; | 296 |
| 295 #elif defined(OS_POSIX) | 297 if (transit_fd == IPC::InvalidPlatformFileForTransit()) { |
| 298 return base::kInvalidPlatformFileValue; | |
| 299 } | |
| 300 | |
| 301 base::PlatformFile handle = IPC::PlatformFileForTransitToPlatformFile( | |
| 302 transit_fd); | |
| 296 return handle; | 303 return handle; |
| 297 #else | |
| 298 #error "GetReadonlyPnaclFD: Don't know how to convert FileDescriptor to native." | |
| 299 #endif | |
| 300 } | 304 } |
| 301 | 305 |
| 302 const PPB_NaCl_Private nacl_interface = { | 306 const PPB_NaCl_Private nacl_interface = { |
| 303 &LaunchSelLdr, | 307 &LaunchSelLdr, |
| 304 &StartPpapiProxy, | 308 &StartPpapiProxy, |
| 305 &UrandomFD, | 309 &UrandomFD, |
| 306 &Are3DInterfacesDisabled, | 310 &Are3DInterfacesDisabled, |
| 307 &EnableBackgroundSelLdrLaunch, | 311 &EnableBackgroundSelLdrLaunch, |
| 308 &BrokerDuplicateHandle, | 312 &BrokerDuplicateHandle, |
| 309 &GetReadonlyPnaclFD | 313 &GetReadonlyPnaclFD, |
| 314 &CreateTemporaryFile | |
| 310 }; | 315 }; |
| 311 | 316 |
| 312 } // namespace | 317 } // namespace |
| 313 | 318 |
| 314 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { | 319 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { |
| 315 return &nacl_interface; | 320 return &nacl_interface; |
| 316 } | 321 } |
| 317 | 322 |
| 318 #endif // DISABLE_NACL | 323 #endif // DISABLE_NACL |
| OLD | NEW |