| 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" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 unsigned int options) { | 254 unsigned int options) { |
| 259 #if defined(OS_WIN) | 255 #if defined(OS_WIN) |
| 260 return content::BrokerDuplicateHandle(source_handle, process_id, | 256 return content::BrokerDuplicateHandle(source_handle, process_id, |
| 261 target_handle, desired_access, | 257 target_handle, desired_access, |
| 262 options); | 258 options); |
| 263 #else | 259 #else |
| 264 return 0; | 260 return 0; |
| 265 #endif | 261 #endif |
| 266 } | 262 } |
| 267 | 263 |
| 268 int GetReadonlyPnaclFD(const char* filename) { | 264 PP_FileHandle GetReadonlyPnaclFD(const char* filename) { |
| 269 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | 265 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); |
| 270 IPC::Sender* sender = content::RenderThread::Get(); | 266 IPC::Sender* sender = content::RenderThread::Get(); |
| 271 if (sender == NULL) | 267 if (sender == NULL) |
| 272 sender = g_background_thread_sender.Pointer()->get(); | 268 sender = g_background_thread_sender.Pointer()->get(); |
| 273 | 269 |
| 274 if (!sender->Send(new ChromeViewHostMsg_GetReadonlyPnaclFD( | 270 if (!sender->Send(new ChromeViewHostMsg_GetReadonlyPnaclFD( |
| 275 std::string(filename), | 271 std::string(filename), |
| 276 &out_fd))) { | 272 &out_fd))) { |
| 277 return -1; | 273 return base::kInvalidPlatformFileValue; |
| 278 } | 274 } |
| 279 | 275 |
| 280 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | 276 if (out_fd == IPC::InvalidPlatformFileForTransit()) { |
| 281 return -1; | 277 return base::kInvalidPlatformFileValue; |
| 282 } | 278 } |
| 283 | 279 |
| 284 base::PlatformFile handle = | 280 base::PlatformFile handle = |
| 285 IPC::PlatformFileForTransitToPlatformFile(out_fd); | 281 IPC::PlatformFileForTransitToPlatformFile(out_fd); |
| 286 #if defined(OS_WIN) | 282 return handle; |
| 287 int posix_desc = _open_osfhandle(reinterpret_cast<intptr_t>(handle), | 283 } |
| 288 _O_RDONLY | _O_BINARY); | 284 |
| 289 if (posix_desc == -1) { | 285 PP_FileHandle CreateTemporaryFile(PP_Instance instance) { |
| 290 // Close the Windows HANDLE if it can't be converted. | 286 IPC::PlatformFileForTransit transit_fd = IPC::InvalidPlatformFileForTransit(); |
| 291 CloseHandle(handle); | 287 IPC::Sender* sender = content::RenderThread::Get(); |
| 292 return -1; | 288 if (sender == NULL) |
| 289 sender = g_background_thread_sender.Pointer()->get(); |
| 290 |
| 291 if (!sender->Send(new ChromeViewHostMsg_NaClCreateTemporaryFile( |
| 292 &transit_fd))) { |
| 293 return base::kInvalidPlatformFileValue; |
| 293 } | 294 } |
| 294 return posix_desc; | 295 |
| 295 #elif defined(OS_POSIX) | 296 if (transit_fd == IPC::InvalidPlatformFileForTransit()) { |
| 297 return base::kInvalidPlatformFileValue; |
| 298 } |
| 299 |
| 300 base::PlatformFile handle = IPC::PlatformFileForTransitToPlatformFile( |
| 301 transit_fd); |
| 296 return handle; | 302 return handle; |
| 297 #else | |
| 298 #error "GetReadonlyPnaclFD: Don't know how to convert FileDescriptor to native." | |
| 299 #endif | |
| 300 } | 303 } |
| 301 | 304 |
| 302 const PPB_NaCl_Private nacl_interface = { | 305 const PPB_NaCl_Private nacl_interface = { |
| 303 &LaunchSelLdr, | 306 &LaunchSelLdr, |
| 304 &StartPpapiProxy, | 307 &StartPpapiProxy, |
| 305 &UrandomFD, | 308 &UrandomFD, |
| 306 &Are3DInterfacesDisabled, | 309 &Are3DInterfacesDisabled, |
| 307 &EnableBackgroundSelLdrLaunch, | 310 &EnableBackgroundSelLdrLaunch, |
| 308 &BrokerDuplicateHandle, | 311 &BrokerDuplicateHandle, |
| 309 &GetReadonlyPnaclFD | 312 &GetReadonlyPnaclFD, |
| 313 &CreateTemporaryFile |
| 310 }; | 314 }; |
| 311 | 315 |
| 312 } // namespace | 316 } // namespace |
| 313 | 317 |
| 314 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { | 318 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { |
| 315 return &nacl_interface; | 319 return &nacl_interface; |
| 316 } | 320 } |
| 317 | 321 |
| 318 #endif // DISABLE_NACL | 322 #endif // DISABLE_NACL |
| OLD | NEW |