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 <numeric> | 7 #include <numeric> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 std::string* full_url, | 158 std::string* full_url, |
159 PP_PNaClOptions* pnacl_options); | 159 PP_PNaClOptions* pnacl_options); |
160 | 160 |
161 typedef base::Callback<void(int32_t, const PP_NaClFileInfo&)> | 161 typedef base::Callback<void(int32_t, const PP_NaClFileInfo&)> |
162 DownloadFileCallback; | 162 DownloadFileCallback; |
163 | 163 |
164 void DownloadFile(PP_Instance instance, | 164 void DownloadFile(PP_Instance instance, |
165 const std::string& url, | 165 const std::string& url, |
166 const DownloadFileCallback& callback); | 166 const DownloadFileCallback& callback); |
167 | 167 |
| 168 PP_Bool StartPpapiProxy(PP_Instance instance); |
| 169 |
168 // Thin adapter from PPP_ManifestService to ManifestServiceChannel::Delegate. | 170 // Thin adapter from PPP_ManifestService to ManifestServiceChannel::Delegate. |
169 // Note that user_data is managed by the caller of LaunchSelLdr. Please see | 171 // Note that user_data is managed by the caller of LaunchSelLdr. Please see |
170 // also PP_ManifestService's comment for more details about resource | 172 // also PP_ManifestService's comment for more details about resource |
171 // management. | 173 // management. |
172 class ManifestServiceProxy : public ManifestServiceChannel::Delegate { | 174 class ManifestServiceProxy : public ManifestServiceChannel::Delegate { |
173 public: | 175 public: |
174 ManifestServiceProxy(PP_Instance pp_instance, | 176 ManifestServiceProxy(PP_Instance pp_instance) |
175 const PPP_ManifestService* manifest_service, | 177 : pp_instance_(pp_instance) { |
176 void* user_data) | |
177 : pp_instance_(pp_instance), | |
178 manifest_service_(*manifest_service), | |
179 user_data_(user_data) { | |
180 } | 178 } |
181 | 179 |
182 virtual ~ManifestServiceProxy() { | 180 virtual ~ManifestServiceProxy() { } |
183 Quit(); | |
184 } | |
185 | 181 |
186 virtual void StartupInitializationComplete() OVERRIDE { | 182 virtual void StartupInitializationComplete() OVERRIDE { |
187 if (!user_data_) | 183 if (StartPpapiProxy(pp_instance_) == PP_TRUE) { |
188 return; | 184 JsonManifest* manifest = GetJsonManifest(pp_instance_); |
189 | 185 NexeLoadManager* load_manager = GetNexeLoadManager(pp_instance_); |
190 if (!PP_ToBool( | 186 if (load_manager && manifest) { |
191 manifest_service_.StartupInitializationComplete(user_data_))) { | 187 std::string full_url; |
192 user_data_ = NULL; | 188 PP_PNaClOptions pnacl_options; |
| 189 bool uses_nonsfi_mode; |
| 190 JsonManifest::ErrorInfo error_info; |
| 191 if (manifest->GetProgramURL(&full_url, |
| 192 &pnacl_options, |
| 193 &uses_nonsfi_mode, |
| 194 &error_info)) { |
| 195 int64_t nexe_size = load_manager->nexe_size(); |
| 196 load_manager->ReportLoadSuccess(full_url, nexe_size, nexe_size); |
| 197 } |
| 198 } |
193 } | 199 } |
194 } | 200 } |
195 | 201 |
196 virtual void OpenResource( | 202 virtual void OpenResource( |
197 const std::string& key, | 203 const std::string& key, |
198 const ManifestServiceChannel::OpenResourceCallback& callback) OVERRIDE { | 204 const ManifestServiceChannel::OpenResourceCallback& callback) OVERRIDE { |
199 DCHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | 205 DCHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> |
200 BelongsToCurrentThread()); | 206 BelongsToCurrentThread()); |
201 | 207 |
202 if (!user_data_) | |
203 return; | |
204 | |
205 std::string url; | 208 std::string url; |
206 // TODO(teravest): Clean up pnacl_options logic in JsonManifest so we don't | 209 // TODO(teravest): Clean up pnacl_options logic in JsonManifest so we don't |
207 // have to initialize it like this here. | 210 // have to initialize it like this here. |
208 PP_PNaClOptions pnacl_options; | 211 PP_PNaClOptions pnacl_options; |
209 pnacl_options.translate = PP_FALSE; | 212 pnacl_options.translate = PP_FALSE; |
210 pnacl_options.is_debug = PP_FALSE; | 213 pnacl_options.is_debug = PP_FALSE; |
211 pnacl_options.opt_level = 2; | 214 pnacl_options.opt_level = 2; |
212 if (!ManifestResolveKey(pp_instance_, false, key, &url, &pnacl_options)) { | 215 if (!ManifestResolveKey(pp_instance_, false, key, &url, &pnacl_options)) { |
213 base::MessageLoop::current()->PostTask( | 216 base::MessageLoop::current()->PostTask( |
214 FROM_HERE, | 217 FROM_HERE, |
(...skipping 17 matching lines...) Expand all Loading... |
232 ManifestServiceChannel::OpenResourceCallback callback, | 235 ManifestServiceChannel::OpenResourceCallback callback, |
233 int32_t pp_error, | 236 int32_t pp_error, |
234 const PP_NaClFileInfo& file_info) { | 237 const PP_NaClFileInfo& file_info) { |
235 if (pp_error != PP_OK) { | 238 if (pp_error != PP_OK) { |
236 callback.Run(base::File()); | 239 callback.Run(base::File()); |
237 return; | 240 return; |
238 } | 241 } |
239 callback.Run(base::File(file_info.handle)); | 242 callback.Run(base::File(file_info.handle)); |
240 } | 243 } |
241 | 244 |
242 void Quit() { | |
243 if (!user_data_) | |
244 return; | |
245 | |
246 bool result = PP_ToBool(manifest_service_.Quit(user_data_)); | |
247 DCHECK(!result); | |
248 user_data_ = NULL; | |
249 } | |
250 | |
251 PP_Instance pp_instance_; | 245 PP_Instance pp_instance_; |
252 PPP_ManifestService manifest_service_; | |
253 void* user_data_; | |
254 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); | 246 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); |
255 }; | 247 }; |
256 | 248 |
257 blink::WebURLLoader* CreateWebURLLoader(const blink::WebDocument& document, | 249 blink::WebURLLoader* CreateWebURLLoader(const blink::WebDocument& document, |
258 const GURL& gurl) { | 250 const GURL& gurl) { |
259 blink::WebURLLoaderOptions options; | 251 blink::WebURLLoaderOptions options; |
260 options.untrustedHTTP = true; | 252 options.untrustedHTTP = true; |
261 | 253 |
262 // Options settings here follow the original behavior in the trusted | 254 // Options settings here follow the original behavior in the trusted |
263 // plugin and PepperURLLoaderHost. | 255 // plugin and PepperURLLoaderHost. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 PP_Bool main_service_runtime, | 290 PP_Bool main_service_runtime, |
299 const char* alleged_url, | 291 const char* alleged_url, |
300 const PP_NaClFileInfo* nexe_file_info, | 292 const PP_NaClFileInfo* nexe_file_info, |
301 PP_Bool uses_irt, | 293 PP_Bool uses_irt, |
302 PP_Bool uses_ppapi, | 294 PP_Bool uses_ppapi, |
303 PP_Bool uses_nonsfi_mode, | 295 PP_Bool uses_nonsfi_mode, |
304 PP_Bool enable_ppapi_dev, | 296 PP_Bool enable_ppapi_dev, |
305 PP_Bool enable_dyncode_syscalls, | 297 PP_Bool enable_dyncode_syscalls, |
306 PP_Bool enable_exception_handling, | 298 PP_Bool enable_exception_handling, |
307 PP_Bool enable_crash_throttling, | 299 PP_Bool enable_crash_throttling, |
308 const PPP_ManifestService* manifest_service_interface, | |
309 void* manifest_service_user_data, | |
310 void* imc_handle, | 300 void* imc_handle, |
311 PP_CompletionCallback callback) { | 301 PP_CompletionCallback callback) { |
312 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | 302 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> |
313 BelongsToCurrentThread()); | 303 BelongsToCurrentThread()); |
314 | 304 |
315 // Create the manifest service proxy here, so on error case, it will be | 305 // Create the manifest service proxy here, so on error case, it will be |
316 // destructed (without passing it to ManifestServiceChannel), and QUIT | 306 // destructed (without passing it to ManifestServiceChannel). |
317 // will be called in its destructor so that the caller of this function | |
318 // can free manifest_service_user_data properly. | |
319 scoped_ptr<ManifestServiceChannel::Delegate> manifest_service_proxy( | 307 scoped_ptr<ManifestServiceChannel::Delegate> manifest_service_proxy( |
320 new ManifestServiceProxy(instance, | 308 new ManifestServiceProxy(instance)); |
321 manifest_service_interface, | |
322 manifest_service_user_data)); | |
323 | 309 |
324 FileDescriptor result_socket; | 310 FileDescriptor result_socket; |
325 IPC::Sender* sender = content::RenderThread::Get(); | 311 IPC::Sender* sender = content::RenderThread::Get(); |
326 DCHECK(sender); | 312 DCHECK(sender); |
327 int routing_id = 0; | 313 int routing_id = 0; |
328 // If the nexe uses ppapi APIs, we need a routing ID. | 314 // If the nexe uses ppapi APIs, we need a routing ID. |
329 // To get the routing ID, we must be on the main thread. | 315 // To get the routing ID, we must be on the main thread. |
330 // Some nexes do not use ppapi and launch from the background thread, | 316 // Some nexes do not use ppapi and launch from the background thread, |
331 // so those nexes can skip finding a routing_id. | 317 // so those nexes can skip finding a routing_id. |
332 if (uses_ppapi) { | 318 if (uses_ppapi) { |
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1638 &SetPNaClStartTime | 1624 &SetPNaClStartTime |
1639 }; | 1625 }; |
1640 | 1626 |
1641 } // namespace | 1627 } // namespace |
1642 | 1628 |
1643 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1629 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1644 return &nacl_interface; | 1630 return &nacl_interface; |
1645 } | 1631 } |
1646 | 1632 |
1647 } // namespace nacl | 1633 } // namespace nacl |
OLD | NEW |