OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/renderer/ppb_nacl_private_impl.h" | 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "components/nacl/common/nacl_host_messages.h" | 12 #include "components/nacl/common/nacl_host_messages.h" |
13 #include "components/nacl/common/nacl_messages.h" | 13 #include "components/nacl/common/nacl_messages.h" |
14 #include "components/nacl/common/nacl_switches.h" | 14 #include "components/nacl/common/nacl_switches.h" |
15 #include "components/nacl/common/nacl_types.h" | 15 #include "components/nacl/common/nacl_types.h" |
16 #include "components/nacl/renderer/embedder_service_channel.h" | |
16 #include "components/nacl/renderer/nexe_load_manager.h" | 17 #include "components/nacl/renderer/nexe_load_manager.h" |
17 #include "components/nacl/renderer/pnacl_translation_resource_host.h" | 18 #include "components/nacl/renderer/pnacl_translation_resource_host.h" |
18 #include "components/nacl/renderer/sandbox_arch.h" | 19 #include "components/nacl/renderer/sandbox_arch.h" |
19 #include "components/nacl/renderer/trusted_plugin_channel.h" | 20 #include "components/nacl/renderer/trusted_plugin_channel.h" |
20 #include "content/public/common/content_client.h" | 21 #include "content/public/common/content_client.h" |
21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
22 #include "content/public/common/sandbox_init.h" | 23 #include "content/public/common/sandbox_init.h" |
23 #include "content/public/renderer/pepper_plugin_instance.h" | 24 #include "content/public/renderer/pepper_plugin_instance.h" |
24 #include "content/public/renderer/render_thread.h" | 25 #include "content/public/renderer/render_thread.h" |
25 #include "content/public/renderer/render_view.h" | 26 #include "content/public/renderer/render_view.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 | 98 |
98 #if defined(OS_POSIX) | 99 #if defined(OS_POSIX) |
99 if (channel_handle.socket.fd == -1) { | 100 if (channel_handle.socket.fd == -1) { |
100 return false; | 101 return false; |
101 } | 102 } |
102 #endif | 103 #endif |
103 | 104 |
104 return true; | 105 return true; |
105 } | 106 } |
106 | 107 |
108 struct LaunchSelLdrCompletionCallbackData : | |
dmichael (off chromium)
2014/04/10 18:06:23
A brief description of what the class does might b
hidehiko
2014/04/10 19:02:08
Done.
| |
109 public base::RefCounted<LaunchSelLdrCompletionCallbackData> { | |
110 public: | |
111 LaunchSelLdrCompletionCallbackData(int num_expect_call) | |
dmichael (off chromium)
2014/04/10 18:06:23
nit: explicit
hidehiko
2014/04/10 19:02:08
Acknowledged.
| |
112 : num_remaining_call(num_expect_call), | |
113 result(PP_OK) { | |
114 } | |
115 int num_remaining_call; | |
dmichael (off chromium)
2014/04/10 18:06:23
nit: call->calls
hidehiko
2014/04/10 19:02:08
Done.
| |
116 int32_t result; | |
117 | |
118 private: | |
119 friend class base::RefCounted<LaunchSelLdrCompletionCallbackData>; | |
120 ~LaunchSelLdrCompletionCallbackData() { | |
121 } | |
122 }; | |
123 | |
124 void LaunchSelLdrCompletionCallback( | |
dmichael (off chromium)
2014/04/10 18:06:23
suggestion: It might simplify things a tiny bit to
hidehiko
2014/04/10 19:02:08
Good idea. How about this?
| |
125 scoped_refptr<LaunchSelLdrCompletionCallbackData> data, | |
126 PP_CompletionCallback callback, | |
127 int32_t result) { | |
128 if (data->result == PP_OK && result != PP_OK) | |
129 data->result = result; | |
130 | |
131 --data->num_remaining_call; | |
132 if (data->num_remaining_call > 0) { | |
133 // There still are some pending or on-going tasks. Wait for the results. | |
134 return; | |
135 } | |
136 | |
137 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | |
138 FROM_HERE, | |
139 base::Bind(callback.func, callback.user_data, data->result)); | |
140 } | |
141 | |
107 // Launch NaCl's sel_ldr process. | 142 // Launch NaCl's sel_ldr process. |
108 void LaunchSelLdr(PP_Instance instance, | 143 void LaunchSelLdr(PP_Instance instance, |
109 const char* alleged_url, | 144 const char* alleged_url, |
110 PP_Bool uses_irt, | 145 PP_Bool uses_irt, |
111 PP_Bool uses_ppapi, | 146 PP_Bool uses_ppapi, |
112 PP_Bool uses_nonsfi_mode, | 147 PP_Bool uses_nonsfi_mode, |
113 PP_Bool enable_ppapi_dev, | 148 PP_Bool enable_ppapi_dev, |
114 PP_Bool enable_dyncode_syscalls, | 149 PP_Bool enable_dyncode_syscalls, |
115 PP_Bool enable_exception_handling, | 150 PP_Bool enable_exception_handling, |
116 PP_Bool enable_crash_throttling, | 151 PP_Bool enable_crash_throttling, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 instance_info.plugin_pid = launch_result.plugin_pid; | 219 instance_info.plugin_pid = launch_result.plugin_pid; |
185 instance_info.plugin_child_id = launch_result.plugin_child_id; | 220 instance_info.plugin_child_id = launch_result.plugin_child_id; |
186 | 221 |
187 // Don't save instance_info if channel handle is invalid. | 222 // Don't save instance_info if channel handle is invalid. |
188 if (IsValidChannelHandle(instance_info.channel_handle)) | 223 if (IsValidChannelHandle(instance_info.channel_handle)) |
189 g_instance_info.Get()[instance] = instance_info; | 224 g_instance_info.Get()[instance] = instance_info; |
190 | 225 |
191 *(static_cast<NaClHandle*>(imc_handle)) = | 226 *(static_cast<NaClHandle*>(imc_handle)) = |
192 nacl::ToNativeHandle(result_socket); | 227 nacl::ToNativeHandle(result_socket); |
193 | 228 |
194 // TODO(hidehiko): We'll add EmbedderServiceChannel here, and it will wait | 229 // Here after we start to establish TrustedPluginChannel and |
195 // for the connection in parallel with TrustedPluginChannel. | 230 // EmbedderServiceChannel in parallel. So, we count the number of connections |
196 // Thus, the callback will wait for its second invocation to run callback, | 231 // (or errors), and invoke callback when all the connections are established. |
197 // then. | |
198 // Note that PP_CompletionCallback is not designed to be called twice or | 232 // Note that PP_CompletionCallback is not designed to be called twice or |
199 // more. Thus, it is necessary to create a function to handle multiple | 233 // more. Thus, it is necessary to create a function to handle multiple |
200 // invocation. | 234 // invocation. |
201 base::Callback<void(int32_t)> completion_callback = | 235 base::Callback<void(int32_t)> completion_callback = base::Bind( |
202 base::Bind(callback.func, callback.user_data); | 236 &LaunchSelLdrCompletionCallback, |
237 make_scoped_refptr(new LaunchSelLdrCompletionCallbackData(2)), | |
238 callback); | |
239 | |
203 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 240 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
204 DCHECK(load_manager); | 241 DCHECK(load_manager); |
205 | 242 |
206 // Stash the trusted handle as well. | 243 // Stash the trusted handle as well. |
207 if (load_manager && | 244 if (load_manager && |
208 IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) { | 245 IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) { |
209 scoped_ptr<nacl::TrustedPluginChannel> trusted_plugin_channel( | 246 scoped_ptr<nacl::TrustedPluginChannel> trusted_plugin_channel( |
210 new nacl::TrustedPluginChannel( | 247 new nacl::TrustedPluginChannel( |
211 launch_result.trusted_ipc_channel_handle, | 248 launch_result.trusted_ipc_channel_handle, |
212 completion_callback, | 249 completion_callback, |
213 content::RenderThread::Get()->GetShutdownEvent())); | 250 content::RenderThread::Get()->GetShutdownEvent())); |
214 load_manager->set_trusted_plugin_channel(trusted_plugin_channel.Pass()); | 251 load_manager->set_trusted_plugin_channel(trusted_plugin_channel.Pass()); |
215 } else { | 252 } else { |
216 completion_callback.Run(PP_ERROR_FAILED); | 253 completion_callback.Run(PP_ERROR_FAILED); |
217 } | 254 } |
255 | |
256 // Stash the embedder service handle as well. | |
257 if (load_manager && | |
258 IsValidChannelHandle( | |
259 launch_result.embedder_service_ipc_channel_handle)) { | |
260 scoped_ptr<nacl::EmbedderServiceChannel> embedder_service_channel( | |
261 new nacl::EmbedderServiceChannel( | |
262 launch_result.embedder_service_ipc_channel_handle, | |
263 completion_callback, | |
264 content::RenderThread::Get()->GetShutdownEvent())); | |
265 load_manager->set_embedder_service_channel( | |
266 embedder_service_channel.Pass()); | |
267 } else { | |
268 // Currently, embedder service works only on linux/non-SFI mode. | |
269 // On other platforms, the socket will not be created, and thus this | |
270 // condition needs to be handled as success. | |
271 completion_callback.Run(PP_OK); | |
272 } | |
218 } | 273 } |
219 | 274 |
220 // Forward declaration. | 275 // Forward declaration. |
221 void ReportLoadError(PP_Instance instance, | 276 void ReportLoadError(PP_Instance instance, |
222 PP_NaClError error, | 277 PP_NaClError error, |
223 const char* error_message, | 278 const char* error_message, |
224 const char* console_message); | 279 const char* console_message); |
225 | 280 |
226 PP_Bool StartPpapiProxy(PP_Instance instance) { | 281 PP_Bool StartPpapiProxy(PP_Instance instance) { |
227 InstanceInfoMap& map = g_instance_info.Get(); | 282 InstanceInfoMap& map = g_instance_info.Get(); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 | 730 |
676 } // namespace | 731 } // namespace |
677 | 732 |
678 namespace nacl { | 733 namespace nacl { |
679 | 734 |
680 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 735 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
681 return &nacl_interface; | 736 return &nacl_interface; |
682 } | 737 } |
683 | 738 |
684 } // namespace nacl | 739 } // namespace nacl |
OLD | NEW |