| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/nacl_host_messages.h" |
| 15 #include "chrome/renderer/chrome_render_process_observer.h" | 15 #include "chrome/renderer/chrome_render_process_observer.h" |
| 16 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 18 #include "content/public/common/sandbox_init.h" | 18 #include "content/public/common/sandbox_init.h" |
| 19 #include "content/public/renderer/renderer_ppapi_host.h" | 19 #include "content/public/renderer/renderer_ppapi_host.h" |
| 20 #include "content/public/renderer/render_thread.h" | 20 #include "content/public/renderer/render_thread.h" |
| 21 #include "content/public/renderer/render_view.h" | 21 #include "content/public/renderer/render_view.h" |
| 22 #include "ipc/ipc_sync_message_filter.h" | 22 #include "ipc/ipc_sync_message_filter.h" |
| 23 #include "ppapi/c/pp_bool.h" | 23 #include "ppapi/c/pp_bool.h" |
| 24 #include "ppapi/c/private/pp_file_handle.h" | 24 #include "ppapi/c/private/pp_file_handle.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 uint32_t perm_bits = ppapi::PERMISSION_NONE; | 97 uint32_t perm_bits = ppapi::PERMISSION_NONE; |
| 98 // Conditionally block 'Dev' interfaces. We do this for the NaCl process, so | 98 // Conditionally block 'Dev' interfaces. We do this for the NaCl process, so |
| 99 // it's clearer to developers when they are using 'Dev' inappropriately. We | 99 // it's clearer to developers when they are using 'Dev' inappropriately. We |
| 100 // must also check on the trusted side of the proxy. | 100 // must also check on the trusted side of the proxy. |
| 101 if (enable_ppapi_dev) | 101 if (enable_ppapi_dev) |
| 102 perm_bits |= ppapi::PERMISSION_DEV; | 102 perm_bits |= ppapi::PERMISSION_DEV; |
| 103 instance_info.permissions = | 103 instance_info.permissions = |
| 104 ppapi::PpapiPermissions::GetForCommandLine(perm_bits); | 104 ppapi::PpapiPermissions::GetForCommandLine(perm_bits); |
| 105 | 105 |
| 106 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( | 106 if (!sender->Send(new NaClHostMsg_LaunchNaCl( |
| 107 nacl::NaClLaunchParams(instance_info.url.spec(), | 107 nacl::NaClLaunchParams(instance_info.url.spec(), |
| 108 routing_id, | 108 routing_id, |
| 109 perm_bits, | 109 perm_bits, |
| 110 PP_ToBool(uses_irt), | 110 PP_ToBool(uses_irt), |
| 111 PP_ToBool(enable_dyncode_syscalls), | 111 PP_ToBool(enable_dyncode_syscalls), |
| 112 PP_ToBool(enable_exception_handling)), | 112 PP_ToBool(enable_exception_handling)), |
| 113 &result_socket, | 113 &result_socket, |
| 114 &instance_info.channel_handle, | 114 &instance_info.channel_handle, |
| 115 &instance_info.plugin_pid, | 115 &instance_info.plugin_pid, |
| 116 &instance_info.plugin_child_id))) { | 116 &instance_info.plugin_child_id))) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return 0; | 206 return 0; |
| 207 #endif | 207 #endif |
| 208 } | 208 } |
| 209 | 209 |
| 210 PP_FileHandle GetReadonlyPnaclFD(const char* filename) { | 210 PP_FileHandle GetReadonlyPnaclFD(const char* filename) { |
| 211 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | 211 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); |
| 212 IPC::Sender* sender = content::RenderThread::Get(); | 212 IPC::Sender* sender = content::RenderThread::Get(); |
| 213 if (sender == NULL) | 213 if (sender == NULL) |
| 214 sender = g_background_thread_sender.Pointer()->get(); | 214 sender = g_background_thread_sender.Pointer()->get(); |
| 215 | 215 |
| 216 if (!sender->Send(new ChromeViewHostMsg_GetReadonlyPnaclFD( | 216 if (!sender->Send(new NaClHostMsg_GetReadonlyPnaclFD( |
| 217 std::string(filename), | 217 std::string(filename), |
| 218 &out_fd))) { | 218 &out_fd))) { |
| 219 return base::kInvalidPlatformFileValue; | 219 return base::kInvalidPlatformFileValue; |
| 220 } | 220 } |
| 221 | 221 |
| 222 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | 222 if (out_fd == IPC::InvalidPlatformFileForTransit()) { |
| 223 return base::kInvalidPlatformFileValue; | 223 return base::kInvalidPlatformFileValue; |
| 224 } | 224 } |
| 225 | 225 |
| 226 base::PlatformFile handle = | 226 base::PlatformFile handle = |
| 227 IPC::PlatformFileForTransitToPlatformFile(out_fd); | 227 IPC::PlatformFileForTransitToPlatformFile(out_fd); |
| 228 return handle; | 228 return handle; |
| 229 } | 229 } |
| 230 | 230 |
| 231 PP_FileHandle CreateTemporaryFile(PP_Instance instance) { | 231 PP_FileHandle CreateTemporaryFile(PP_Instance instance) { |
| 232 IPC::PlatformFileForTransit transit_fd = IPC::InvalidPlatformFileForTransit(); | 232 IPC::PlatformFileForTransit transit_fd = IPC::InvalidPlatformFileForTransit(); |
| 233 IPC::Sender* sender = content::RenderThread::Get(); | 233 IPC::Sender* sender = content::RenderThread::Get(); |
| 234 if (sender == NULL) | 234 if (sender == NULL) |
| 235 sender = g_background_thread_sender.Pointer()->get(); | 235 sender = g_background_thread_sender.Pointer()->get(); |
| 236 | 236 |
| 237 if (!sender->Send(new ChromeViewHostMsg_NaClCreateTemporaryFile( | 237 if (!sender->Send(new NaClHostMsg_NaClCreateTemporaryFile( |
| 238 &transit_fd))) { | 238 &transit_fd))) { |
| 239 return base::kInvalidPlatformFileValue; | 239 return base::kInvalidPlatformFileValue; |
| 240 } | 240 } |
| 241 | 241 |
| 242 if (transit_fd == IPC::InvalidPlatformFileForTransit()) { | 242 if (transit_fd == IPC::InvalidPlatformFileForTransit()) { |
| 243 return base::kInvalidPlatformFileValue; | 243 return base::kInvalidPlatformFileValue; |
| 244 } | 244 } |
| 245 | 245 |
| 246 base::PlatformFile handle = IPC::PlatformFileForTransitToPlatformFile( | 246 base::PlatformFile handle = IPC::PlatformFileForTransitToPlatformFile( |
| 247 transit_fd); | 247 transit_fd); |
| 248 return handle; | 248 return handle; |
| 249 } | 249 } |
| 250 | 250 |
| 251 PP_Bool IsOffTheRecord() { | 251 PP_Bool IsOffTheRecord() { |
| 252 return PP_FromBool(ChromeRenderProcessObserver::is_incognito_process()); | 252 return PP_FromBool(ChromeRenderProcessObserver::is_incognito_process()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 PP_Bool IsPnaclEnabled() { | 255 PP_Bool IsPnaclEnabled() { |
| 256 return PP_FromBool( | 256 return PP_FromBool( |
| 257 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePnacl)); | 257 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePnacl)); |
| 258 } | 258 } |
| 259 | 259 |
| 260 PP_NaClResult ReportNaClError(PP_Instance instance, | 260 PP_NaClResult ReportNaClError(PP_Instance instance, |
| 261 PP_NaClError error_id) { | 261 PP_NaClError error_id) { |
| 262 IPC::Sender* sender = content::RenderThread::Get(); | 262 IPC::Sender* sender = content::RenderThread::Get(); |
| 263 | 263 |
| 264 if (!sender->Send( | 264 if (!sender->Send( |
| 265 new ChromeViewHostMsg_NaClErrorStatus( | 265 new NaClHostMsg_NaClErrorStatus( |
| 266 // TODO(dschuff): does this enum need to be sent as an int, | 266 // TODO(dschuff): does this enum need to be sent as an int, |
| 267 // or is it safe to include the appropriate headers in | 267 // or is it safe to include the appropriate headers in |
| 268 // render_messages.h? | 268 // render_messages.h? |
| 269 GetRoutingID(instance), static_cast<int>(error_id)))) { | 269 GetRoutingID(instance), static_cast<int>(error_id)))) { |
| 270 return PP_NACL_FAILED; | 270 return PP_NACL_FAILED; |
| 271 } | 271 } |
| 272 return PP_NACL_OK; | 272 return PP_NACL_OK; |
| 273 } | 273 } |
| 274 | 274 |
| 275 PP_FileHandle OpenNaClExecutable(PP_Instance instance, | 275 PP_FileHandle OpenNaClExecutable(PP_Instance instance, |
| 276 const char* file_url, | 276 const char* file_url, |
| 277 uint64_t* nonce_lo, | 277 uint64_t* nonce_lo, |
| 278 uint64_t* nonce_hi) { | 278 uint64_t* nonce_hi) { |
| 279 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | 279 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); |
| 280 IPC::Sender* sender = content::RenderThread::Get(); | 280 IPC::Sender* sender = content::RenderThread::Get(); |
| 281 if (sender == NULL) | 281 if (sender == NULL) |
| 282 sender = g_background_thread_sender.Pointer()->get(); | 282 sender = g_background_thread_sender.Pointer()->get(); |
| 283 | 283 |
| 284 *nonce_lo = 0; | 284 *nonce_lo = 0; |
| 285 *nonce_hi = 0; | 285 *nonce_hi = 0; |
| 286 base::FilePath file_path; | 286 base::FilePath file_path; |
| 287 if (!sender->Send( | 287 if (!sender->Send( |
| 288 new ChromeViewHostMsg_OpenNaClExecutable(GetRoutingID(instance), | 288 new NaClHostMsg_OpenNaClExecutable(GetRoutingID(instance), |
| 289 GURL(file_url), | 289 GURL(file_url), |
| 290 &out_fd, | 290 &out_fd, |
| 291 nonce_lo, | 291 nonce_lo, |
| 292 nonce_hi))) { | 292 nonce_hi))) { |
| 293 return base::kInvalidPlatformFileValue; | 293 return base::kInvalidPlatformFileValue; |
| 294 } | 294 } |
| 295 | 295 |
| 296 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | 296 if (out_fd == IPC::InvalidPlatformFileForTransit()) { |
| 297 return base::kInvalidPlatformFileValue; | 297 return base::kInvalidPlatformFileValue; |
| 298 } | 298 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 317 &OpenNaClExecutable | 317 &OpenNaClExecutable |
| 318 }; | 318 }; |
| 319 | 319 |
| 320 } // namespace | 320 } // namespace |
| 321 | 321 |
| 322 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { | 322 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { |
| 323 return &nacl_interface; | 323 return &nacl_interface; |
| 324 } | 324 } |
| 325 | 325 |
| 326 #endif // DISABLE_NACL | 326 #endif // DISABLE_NACL |
| OLD | NEW |