| 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 18 matching lines...) Expand all Loading... |
| 29 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 29 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // This allows us to send requests from background threads. | 33 // This allows us to send requests from background threads. |
| 34 // E.g., to do LaunchSelLdr for helper nexes (which is done synchronously), | 34 // E.g., to do LaunchSelLdr for helper nexes (which is done synchronously), |
| 35 // in a background thread, to avoid jank. | 35 // in a background thread, to avoid jank. |
| 36 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > | 36 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > |
| 37 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; | 37 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; |
| 38 | 38 |
| 39 typedef std::map<PP_Instance, IPC::ChannelHandle> ChannelHandleMap; | 39 struct InstanceInfo { |
| 40 InstanceInfo() : plugin_child_id(0) {} |
| 41 GURL url; |
| 42 int plugin_child_id; |
| 43 IPC::ChannelHandle channel_handle; |
| 44 }; |
| 40 | 45 |
| 41 base::LazyInstance<ChannelHandleMap> g_channel_handle_map = | 46 typedef std::map<PP_Instance, InstanceInfo> InstanceInfoMap; |
| 47 |
| 48 base::LazyInstance<InstanceInfoMap> g_instance_info = |
| 42 LAZY_INSTANCE_INITIALIZER; | 49 LAZY_INSTANCE_INITIALIZER; |
| 43 | 50 |
| 44 // Launch NaCl's sel_ldr process. | 51 // Launch NaCl's sel_ldr process. |
| 45 PP_Bool LaunchSelLdr(PP_Instance instance, | 52 PP_Bool LaunchSelLdr(PP_Instance instance, |
| 46 const char* alleged_url, | 53 const char* alleged_url, |
| 47 int socket_count, | 54 int socket_count, |
| 48 void* imc_handles) { | 55 void* imc_handles) { |
| 49 std::vector<nacl::FileDescriptor> sockets; | 56 std::vector<nacl::FileDescriptor> sockets; |
| 50 IPC::Sender* sender = content::RenderThread::Get(); | 57 IPC::Sender* sender = content::RenderThread::Get(); |
| 51 if (sender == NULL) | 58 if (sender == NULL) |
| 52 sender = g_background_thread_sender.Pointer()->get(); | 59 sender = g_background_thread_sender.Pointer()->get(); |
| 53 | 60 |
| 54 IPC::ChannelHandle channel_handle; | 61 InstanceInfo instance_info; |
| 62 instance_info.url = GURL(alleged_url); |
| 55 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( | 63 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( |
| 56 GURL(alleged_url), socket_count, &sockets, | 64 instance_info.url, socket_count, &sockets, |
| 57 &channel_handle))) { | 65 &instance_info.channel_handle, |
| 66 &instance_info.plugin_child_id))) { |
| 58 return PP_FALSE; | 67 return PP_FALSE; |
| 59 } | 68 } |
| 60 | 69 |
| 61 // Don't save invalid channel handles. | 70 // Don't save instance_info if channel handle is invalid. |
| 62 bool invalid_handle = channel_handle.name.empty(); | 71 bool invalid_handle = instance_info.channel_handle.name.empty(); |
| 63 | |
| 64 #if defined(OS_POSIX) | 72 #if defined(OS_POSIX) |
| 65 if (!invalid_handle) | 73 if (!invalid_handle) |
| 66 invalid_handle = (channel_handle.socket.fd == -1); | 74 invalid_handle = (instance_info.channel_handle.socket.fd == -1); |
| 67 #endif | 75 #endif |
| 68 | |
| 69 if (!invalid_handle) | 76 if (!invalid_handle) |
| 70 g_channel_handle_map.Get()[instance] = channel_handle; | 77 g_instance_info.Get()[instance] = instance_info; |
| 71 | 78 |
| 72 CHECK(static_cast<int>(sockets.size()) == socket_count); | 79 CHECK(static_cast<int>(sockets.size()) == socket_count); |
| 73 for (int i = 0; i < socket_count; i++) { | 80 for (int i = 0; i < socket_count; i++) { |
| 74 static_cast<nacl::Handle*>(imc_handles)[i] = | 81 static_cast<nacl::Handle*>(imc_handles)[i] = |
| 75 nacl::ToNativeHandle(sockets[i]); | 82 nacl::ToNativeHandle(sockets[i]); |
| 76 } | 83 } |
| 77 | 84 |
| 78 return PP_TRUE; | 85 return PP_TRUE; |
| 79 } | 86 } |
| 80 | 87 |
| 81 PP_Bool StartPpapiProxy(PP_Instance instance) { | 88 PP_Bool StartPpapiProxy(PP_Instance instance, |
| 89 bool allow_dev_interfaces) { |
| 82 if (CommandLine::ForCurrentProcess()->HasSwitch( | 90 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 83 switches::kEnableNaClIPCProxy)) { | 91 switches::kEnableNaClIPCProxy)) { |
| 84 ChannelHandleMap& map = g_channel_handle_map.Get(); | 92 InstanceInfoMap& map = g_instance_info.Get(); |
| 85 ChannelHandleMap::iterator it = map.find(instance); | 93 InstanceInfoMap::iterator it = map.find(instance); |
| 86 if (it == map.end()) | 94 if (it == map.end()) |
| 87 return PP_FALSE; | 95 return PP_FALSE; |
| 88 IPC::ChannelHandle channel_handle = it->second; | 96 InstanceInfo instance_info = it->second; |
| 89 map.erase(it); | 97 map.erase(it); |
| 90 | 98 |
| 91 webkit::ppapi::PluginInstance* plugin_instance = | 99 webkit::ppapi::PluginInstance* plugin_instance = |
| 92 content::GetHostGlobals()->GetInstance(instance); | 100 content::GetHostGlobals()->GetInstance(instance); |
| 93 if (!plugin_instance) | 101 if (!plugin_instance) |
| 94 return PP_FALSE; | 102 return PP_FALSE; |
| 95 | 103 |
| 96 // Create a new module for each instance of the NaCl plugin that is using | 104 // Create a new module for each instance of the NaCl plugin that is using |
| 97 // the IPC based out-of-process proxy. We can't use the existing module, | 105 // the IPC based out-of-process proxy. We can't use the existing module, |
| 98 // because it is configured for the in-process NaCl plugin, and we must | 106 // because it is configured for the in-process NaCl plugin, and we must |
| 99 // keep it that way to allow the page to create other instances. | 107 // keep it that way to allow the page to create other instances. |
| 100 webkit::ppapi::PluginModule* plugin_module = plugin_instance->module(); | 108 webkit::ppapi::PluginModule* plugin_module = plugin_instance->module(); |
| 101 scoped_refptr<webkit::ppapi::PluginModule> nacl_plugin_module( | 109 scoped_refptr<webkit::ppapi::PluginModule> nacl_plugin_module( |
| 102 plugin_module->CreateModuleForNaClInstance()); | 110 plugin_module->CreateModuleForNaClInstance()); |
| 103 | 111 |
| 104 // TODO(brettw) bug 153036 set NaCl permissions to allow dev interface | 112 ppapi::PpapiPermissions permissions( |
| 105 // usage when necessary. | 113 allow_dev_interfaces ? ppapi::PERMISSION_DEV : 0); |
| 106 ppapi::PpapiPermissions permissions; | |
| 107 // TODO(bbudge) fill in place-holder params below with the nexe URL and | |
| 108 // NaCl process id. | |
| 109 content::RendererPpapiHost* renderer_ppapi_host = | 114 content::RendererPpapiHost* renderer_ppapi_host = |
| 110 content::RendererPpapiHost::CreateExternalPluginModule( | 115 content::RendererPpapiHost::CreateExternalPluginModule( |
| 111 nacl_plugin_module, | 116 nacl_plugin_module, |
| 112 plugin_instance, | 117 plugin_instance, |
| 113 FilePath(FILE_PATH_LITERAL("NaCl")), | 118 FilePath().AppendASCII(instance_info.url.spec()), |
| 114 permissions, | 119 permissions, |
| 115 channel_handle, | 120 instance_info.channel_handle, |
| 116 0); // plugin_child_id | 121 instance_info.plugin_child_id); |
| 117 if (renderer_ppapi_host) { | 122 if (renderer_ppapi_host) { |
| 118 // Allow the module to reset the instance to the new proxy. | 123 // Allow the module to reset the instance to the new proxy. |
| 119 nacl_plugin_module->InitAsProxiedNaCl(plugin_instance); | 124 nacl_plugin_module->InitAsProxiedNaCl(plugin_instance); |
| 120 return PP_TRUE; | 125 return PP_TRUE; |
| 121 } | 126 } |
| 122 } | 127 } |
| 123 return PP_FALSE; | 128 return PP_FALSE; |
| 124 } | 129 } |
| 125 | 130 |
| 126 int UrandomFD(void) { | 131 int UrandomFD(void) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 &IsPnaclEnabled | 222 &IsPnaclEnabled |
| 218 }; | 223 }; |
| 219 | 224 |
| 220 } // namespace | 225 } // namespace |
| 221 | 226 |
| 222 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { | 227 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { |
| 223 return &nacl_interface; | 228 return &nacl_interface; |
| 224 } | 229 } |
| 225 | 230 |
| 226 #endif // DISABLE_NACL | 231 #endif // DISABLE_NACL |
| OLD | NEW |