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 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 GURL url; | |
| 41 int plugin_child_id; | |
| 42 IPC::ChannelHandle channel_handle; | |
|
dmichael (off chromium)
2012/10/23 19:05:30
How about a default constructor to make sure plugi
bbudge
2012/10/23 19:53:04
Done.
| |
| 43 }; | |
| 40 | 44 |
| 41 base::LazyInstance<ChannelHandleMap> g_channel_handle_map = | 45 typedef std::map<PP_Instance, InstanceInfo> InstanceInfoMap; |
| 46 | |
| 47 base::LazyInstance<InstanceInfoMap> g_instance_info = | |
| 42 LAZY_INSTANCE_INITIALIZER; | 48 LAZY_INSTANCE_INITIALIZER; |
| 43 | 49 |
| 44 // Launch NaCl's sel_ldr process. | 50 // Launch NaCl's sel_ldr process. |
| 45 PP_Bool LaunchSelLdr(PP_Instance instance, | 51 PP_Bool LaunchSelLdr(PP_Instance instance, |
| 46 const char* alleged_url, | 52 const char* alleged_url, |
| 47 int socket_count, | 53 int socket_count, |
| 48 void* imc_handles) { | 54 void* imc_handles) { |
| 49 std::vector<nacl::FileDescriptor> sockets; | 55 std::vector<nacl::FileDescriptor> sockets; |
| 50 IPC::Sender* sender = content::RenderThread::Get(); | 56 IPC::Sender* sender = content::RenderThread::Get(); |
| 51 if (sender == NULL) | 57 if (sender == NULL) |
| 52 sender = g_background_thread_sender.Pointer()->get(); | 58 sender = g_background_thread_sender.Pointer()->get(); |
| 53 | 59 |
| 54 IPC::ChannelHandle channel_handle; | 60 InstanceInfo instance_info; |
| 61 instance_info.url = GURL(alleged_url); | |
| 55 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( | 62 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( |
| 56 GURL(alleged_url), socket_count, &sockets, | 63 instance_info.url, socket_count, &sockets, |
| 57 &channel_handle))) { | 64 &instance_info.channel_handle, |
| 65 &instance_info.plugin_child_id))) { | |
| 58 return PP_FALSE; | 66 return PP_FALSE; |
| 59 } | 67 } |
| 60 | 68 |
| 61 // Don't save invalid channel handles. | 69 // Don't save instance_info if channel handle is invalid. |
| 62 bool invalid_handle = channel_handle.name.empty(); | 70 bool invalid_handle = instance_info.channel_handle.name.empty(); |
| 63 | |
| 64 #if defined(OS_POSIX) | 71 #if defined(OS_POSIX) |
| 65 if (!invalid_handle) | 72 if (!invalid_handle) |
| 66 invalid_handle = (channel_handle.socket.fd == -1); | 73 invalid_handle = (instance_info.channel_handle.socket.fd == -1); |
| 67 #endif | 74 #endif |
| 68 | |
| 69 if (!invalid_handle) | 75 if (!invalid_handle) |
| 70 g_channel_handle_map.Get()[instance] = channel_handle; | 76 g_instance_info.Get()[instance] = instance_info; |
| 71 | 77 |
| 72 CHECK(static_cast<int>(sockets.size()) == socket_count); | 78 CHECK(static_cast<int>(sockets.size()) == socket_count); |
| 73 for (int i = 0; i < socket_count; i++) { | 79 for (int i = 0; i < socket_count; i++) { |
| 74 static_cast<nacl::Handle*>(imc_handles)[i] = | 80 static_cast<nacl::Handle*>(imc_handles)[i] = |
| 75 nacl::ToNativeHandle(sockets[i]); | 81 nacl::ToNativeHandle(sockets[i]); |
| 76 } | 82 } |
| 77 | 83 |
| 78 return PP_TRUE; | 84 return PP_TRUE; |
| 79 } | 85 } |
| 80 | 86 |
| 81 PP_Bool StartPpapiProxy(PP_Instance instance) { | 87 PP_Bool StartPpapiProxy(PP_Instance instance, |
| 88 bool allow_dev_interfaces) { | |
| 82 if (CommandLine::ForCurrentProcess()->HasSwitch( | 89 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 83 switches::kEnableNaClIPCProxy)) { | 90 switches::kEnableNaClIPCProxy)) { |
| 84 ChannelHandleMap& map = g_channel_handle_map.Get(); | 91 InstanceInfoMap& map = g_instance_info.Get(); |
| 85 ChannelHandleMap::iterator it = map.find(instance); | 92 InstanceInfoMap::iterator it = map.find(instance); |
| 86 if (it == map.end()) | 93 if (it == map.end()) |
| 87 return PP_FALSE; | 94 return PP_FALSE; |
| 88 IPC::ChannelHandle channel_handle = it->second; | 95 InstanceInfo instance_info = it->second; |
| 89 map.erase(it); | 96 map.erase(it); |
| 90 | 97 |
| 91 webkit::ppapi::PluginInstance* plugin_instance = | 98 webkit::ppapi::PluginInstance* plugin_instance = |
| 92 content::GetHostGlobals()->GetInstance(instance); | 99 content::GetHostGlobals()->GetInstance(instance); |
| 93 if (!plugin_instance) | 100 if (!plugin_instance) |
| 94 return PP_FALSE; | 101 return PP_FALSE; |
| 95 | 102 |
| 96 // Create a new module for each instance of the NaCl plugin that is using | 103 // 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, | 104 // 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 | 105 // 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. | 106 // keep it that way to allow the page to create other instances. |
| 100 webkit::ppapi::PluginModule* plugin_module = plugin_instance->module(); | 107 webkit::ppapi::PluginModule* plugin_module = plugin_instance->module(); |
| 101 scoped_refptr<webkit::ppapi::PluginModule> nacl_plugin_module( | 108 scoped_refptr<webkit::ppapi::PluginModule> nacl_plugin_module( |
| 102 plugin_module->CreateModuleForNaClInstance()); | 109 plugin_module->CreateModuleForNaClInstance()); |
| 103 | 110 |
| 104 // TODO(brettw) bug 153036 set NaCl permissions to allow dev interface | 111 ppapi::PpapiPermissions permissions( |
| 105 // usage when necessary. | 112 allow_dev_interfaces ? ppapi::PERMISSION_DEV : 0); |
|
dmichael (off chromium)
2012/10/23 19:05:30
Just curious, how do we handle white-listed Privat
bbudge
2012/10/23 19:53:04
Right now, the plugin side returns NULL for 'Priva
| |
| 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 = | 113 content::RendererPpapiHost* renderer_ppapi_host = |
| 110 content::RendererPpapiHost::CreateExternalPluginModule( | 114 content::RendererPpapiHost::CreateExternalPluginModule( |
| 111 nacl_plugin_module, | 115 nacl_plugin_module, |
| 112 plugin_instance, | 116 plugin_instance, |
| 113 FilePath(FILE_PATH_LITERAL("NaCl")), | 117 FilePath().AppendASCII(instance_info.url.spec()), |
| 114 permissions, | 118 permissions, |
| 115 channel_handle, | 119 instance_info.channel_handle, |
| 116 0); // plugin_child_id | 120 instance_info.plugin_child_id); |
| 117 if (renderer_ppapi_host) { | 121 if (renderer_ppapi_host) { |
| 118 // Allow the module to reset the instance to the new proxy. | 122 // Allow the module to reset the instance to the new proxy. |
| 119 nacl_plugin_module->InitAsProxiedNaCl(plugin_instance); | 123 nacl_plugin_module->InitAsProxiedNaCl(plugin_instance); |
| 120 return PP_TRUE; | 124 return PP_TRUE; |
| 121 } | 125 } |
| 122 } | 126 } |
| 123 return PP_FALSE; | 127 return PP_FALSE; |
| 124 } | 128 } |
| 125 | 129 |
| 126 int UrandomFD(void) { | 130 int UrandomFD(void) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 &IsPnaclEnabled | 221 &IsPnaclEnabled |
| 218 }; | 222 }; |
| 219 | 223 |
| 220 } // namespace | 224 } // namespace |
| 221 | 225 |
| 222 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { | 226 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { |
| 223 return &nacl_interface; | 227 return &nacl_interface; |
| 224 } | 228 } |
| 225 | 229 |
| 226 #endif // DISABLE_NACL | 230 #endif // DISABLE_NACL |
| OLD | NEW |