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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/containers/scoped_ptr_hash_map.h" | 10 #include "base/containers/scoped_ptr_hash_map.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 157 } |
158 | 158 |
159 private: | 159 private: |
160 int num_remaining_calls_; | 160 int num_remaining_calls_; |
161 PP_CompletionCallback callback_; | 161 PP_CompletionCallback callback_; |
162 int32_t result_; | 162 int32_t result_; |
163 | 163 |
164 DISALLOW_COPY_AND_ASSIGN(ChannelConnectedCallback); | 164 DISALLOW_COPY_AND_ASSIGN(ChannelConnectedCallback); |
165 }; | 165 }; |
166 | 166 |
167 // Thin adapter from PP_ManifestService to ManifestServiceChannel::Delegate. | 167 // Thin adapter from PPP_ManifestService to ManifestServiceChannel::Delegate. |
168 // Note that user_data is managed by the caller of LaunchSelLdr. Please see | 168 // Note that user_data is managed by the caller of LaunchSelLdr. Please see |
169 // also PP_ManifestService's comment for more details about resource | 169 // also PP_ManifestService's comment for more details about resource |
170 // management. | 170 // management. |
171 class ManifestServiceProxy : public ManifestServiceChannel::Delegate { | 171 class ManifestServiceProxy : public ManifestServiceChannel::Delegate { |
172 public: | 172 public: |
173 ManifestServiceProxy(const PP_ManifestService* manifest_service, | 173 ManifestServiceProxy(const PPP_ManifestService* manifest_service, |
174 void* user_data) | 174 void* user_data) |
175 : manifest_service_(*manifest_service), | 175 : manifest_service_(*manifest_service), |
176 user_data_(user_data) { | 176 user_data_(user_data) { |
177 } | 177 } |
178 | 178 |
179 virtual ~ManifestServiceProxy() { | 179 virtual ~ManifestServiceProxy() { |
180 Quit(); | 180 Quit(); |
181 } | 181 } |
182 | 182 |
183 virtual void StartupInitializationComplete() OVERRIDE { | 183 virtual void StartupInitializationComplete() OVERRIDE { |
184 if (!user_data_) | 184 if (!user_data_) |
185 return; | 185 return; |
186 | 186 |
187 if (!PP_ToBool( | 187 if (!PP_ToBool( |
188 manifest_service_.StartupInitializationComplete(user_data_))) { | 188 manifest_service_.StartupInitializationComplete(user_data_))) { |
189 user_data_ = NULL; | 189 user_data_ = NULL; |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
| 193 virtual void OpenResource( |
| 194 const std::string& key, |
| 195 const ManifestServiceChannel::OpenResourceCallback& callback) OVERRIDE { |
| 196 if (!user_data_) |
| 197 return; |
| 198 |
| 199 // The allocated callback will be freed in DidOpenResource, which is always |
| 200 // called regardless whether OpenResource() succeeds or fails. |
| 201 if (!PP_ToBool(manifest_service_.OpenResource( |
| 202 user_data_, |
| 203 key.c_str(), |
| 204 DidOpenResource, |
| 205 new ManifestServiceChannel::OpenResourceCallback(callback)))) { |
| 206 user_data_ = NULL; |
| 207 } |
| 208 } |
| 209 |
193 private: | 210 private: |
| 211 static void DidOpenResource(void* user_data, PP_FileHandle file_handle) { |
| 212 scoped_ptr<ManifestServiceChannel::OpenResourceCallback> callback( |
| 213 static_cast<ManifestServiceChannel::OpenResourceCallback*>(user_data)); |
| 214 callback->Run(file_handle); |
| 215 } |
| 216 |
194 void Quit() { | 217 void Quit() { |
195 if (!user_data_) | 218 if (!user_data_) |
196 return; | 219 return; |
197 | 220 |
198 bool result = PP_ToBool(manifest_service_.Quit(user_data_)); | 221 bool result = PP_ToBool(manifest_service_.Quit(user_data_)); |
199 DCHECK(!result); | 222 DCHECK(!result); |
200 user_data_ = NULL; | 223 user_data_ = NULL; |
201 } | 224 } |
202 | 225 |
203 PP_ManifestService manifest_service_; | 226 PPP_ManifestService manifest_service_; |
204 void* user_data_; | 227 void* user_data_; |
205 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); | 228 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); |
206 }; | 229 }; |
207 | 230 |
208 // Launch NaCl's sel_ldr process. | 231 // Launch NaCl's sel_ldr process. |
209 void LaunchSelLdr(PP_Instance instance, | 232 void LaunchSelLdr(PP_Instance instance, |
210 const char* alleged_url, | 233 const char* alleged_url, |
211 PP_Bool uses_irt, | 234 PP_Bool uses_irt, |
212 PP_Bool uses_ppapi, | 235 PP_Bool uses_ppapi, |
213 PP_Bool uses_nonsfi_mode, | 236 PP_Bool uses_nonsfi_mode, |
214 PP_Bool enable_ppapi_dev, | 237 PP_Bool enable_ppapi_dev, |
215 PP_Bool enable_dyncode_syscalls, | 238 PP_Bool enable_dyncode_syscalls, |
216 PP_Bool enable_exception_handling, | 239 PP_Bool enable_exception_handling, |
217 PP_Bool enable_crash_throttling, | 240 PP_Bool enable_crash_throttling, |
218 const PP_ManifestService* manifest_service_interface, | 241 const PPP_ManifestService* manifest_service_interface, |
219 void* manifest_service_user_data, | 242 void* manifest_service_user_data, |
220 void* imc_handle, | 243 void* imc_handle, |
221 struct PP_Var* error_message, | 244 struct PP_Var* error_message, |
222 PP_CompletionCallback callback) { | 245 PP_CompletionCallback callback) { |
223 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | 246 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> |
224 BelongsToCurrentThread()); | 247 BelongsToCurrentThread()); |
225 | 248 |
226 // Create the manifest service proxy here, so on error case, it will be | 249 // Create the manifest service proxy here, so on error case, it will be |
227 // destructed (without passing it to ManifestServiceChannel), and QUIT | 250 // destructed (without passing it to ManifestServiceChannel), and QUIT |
228 // will be called in its destructor so that the caller of this function | 251 // will be called in its destructor so that the caller of this function |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 new TrustedPluginChannel( | 343 new TrustedPluginChannel( |
321 launch_result.trusted_ipc_channel_handle, | 344 launch_result.trusted_ipc_channel_handle, |
322 connected_callback, | 345 connected_callback, |
323 content::RenderThread::Get()->GetShutdownEvent())); | 346 content::RenderThread::Get()->GetShutdownEvent())); |
324 load_manager->set_trusted_plugin_channel(trusted_plugin_channel.Pass()); | 347 load_manager->set_trusted_plugin_channel(trusted_plugin_channel.Pass()); |
325 } else { | 348 } else { |
326 connected_callback.Run(PP_ERROR_FAILED); | 349 connected_callback.Run(PP_ERROR_FAILED); |
327 } | 350 } |
328 | 351 |
329 // Stash the manifest service handle as well. | 352 // Stash the manifest service handle as well. |
| 353 // For security hardening, disable the IPCs for open_resource() when they |
| 354 // aren't needed. PNaCl doesn't expose open_resource(), and the new |
| 355 // open_resource() IPCs are currently only used for Non-SFI NaCl so far, |
| 356 // not SFI NaCl. Note that enable_dyncode_syscalls is true if and only if |
| 357 // the plugin is a non-PNaCl plugin. |
330 if (load_manager && | 358 if (load_manager && |
| 359 enable_dyncode_syscalls && |
| 360 uses_nonsfi_mode && |
331 IsValidChannelHandle( | 361 IsValidChannelHandle( |
332 launch_result.manifest_service_ipc_channel_handle)) { | 362 launch_result.manifest_service_ipc_channel_handle)) { |
333 scoped_ptr<ManifestServiceChannel> manifest_service_channel( | 363 scoped_ptr<ManifestServiceChannel> manifest_service_channel( |
334 new ManifestServiceChannel( | 364 new ManifestServiceChannel( |
335 launch_result.manifest_service_ipc_channel_handle, | 365 launch_result.manifest_service_ipc_channel_handle, |
336 connected_callback, | 366 connected_callback, |
337 manifest_service_proxy.Pass(), | 367 manifest_service_proxy.Pass(), |
338 content::RenderThread::Get()->GetShutdownEvent())); | 368 content::RenderThread::Get()->GetShutdownEvent())); |
339 load_manager->set_manifest_service_channel( | 369 load_manager->set_manifest_service_channel( |
340 manifest_service_channel.Pass()); | 370 manifest_service_channel.Pass()); |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 &DownloadManifestToBuffer | 1033 &DownloadManifestToBuffer |
1004 }; | 1034 }; |
1005 | 1035 |
1006 } // namespace | 1036 } // namespace |
1007 | 1037 |
1008 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1038 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1009 return &nacl_interface; | 1039 return &nacl_interface; |
1010 } | 1040 } |
1011 | 1041 |
1012 } // namespace nacl | 1042 } // namespace nacl |
OLD | NEW |